libipt, section: split struct pt_section

Split struct pt_section into struct pt_section and struct pt_mapped_section.
The former contains all fields except for the virtual address.  The latter
contains the virtual address and a pointer to a struct pt_section.

Struct pt_section now describes some part of a file.
Struct pt_mapped_section describes some section mapped into virtual memory.

This allows sharing sections that are mapped multiple times at different
virtual addresses, for example into different processes or into the same
process at different times.

In the current implementation, pt_image still owns the underlying pt_section;
it is freed when the section is removed from the image.  Subsequent patches
will change that.

Change-Id: Ifd86415045101dcf30b90559b0447ed962b4ddd1
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt, image: support multiple address spaces

When tracing more than one process, the traced image needs to be changed when
the process context is switched.  Add support for specifying multiple images
for different processes.

Add a struct pt_asid to identify an address-space when specifying the traced
image with calls to pt_insn_add_file() et.al.

Maintain the current pt_asid in the pt_insn_decoder based on the PIP packet and
use it when reading memory.

Change-Id: I92cac1bcbd5e301ac95084afa6bcb2ff839f558a
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt, ptxed: export pt_image

Allow the traced image to be changed while decoding.

This allows the image to be populated in advance, it allows multiple decoders
to use the same image (provided it doesn't change during decode), and it allows
switching between images.

This allows ptxed to accept --pt, --raw, and --elf in any order.

Change-Id: I1246685b41fcf529d21fe35bee5b404a0dc9a5fb
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt, image: support removing by asid

Add a function pt_image_remove_by_asid() to remove all sections corresponding
to a given address space identifier.

Change-Id: Ifbd22b75a4d3213d7f7b1409321c9e02fed37d66
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt, image: require non-NULL asid internally

Exported image functions translate a NULL asid argument into a
default-initialized non-NULL asid.  There is no need to support NULL asid
arguments internally.

Require the asid argument to internal image functions to be non-NULL.

Change-Id: Iec96822937957d2d54633556f8fb6eb396ba10d0
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: collect asid stuff into its own file

Asid functionality is currently located in pt_image.c.  Move it into its own
file pt_asid.c.

Further add asid to pt_msec_read().  We leave other functionality related to
adding and removing sections in pt_image for now.

Change-Id: Ic2758b7ca6f70e50dd07f7375e1afa445206de82
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>