ptunit-query: use struct pt_query_decoder

The query unit tests use struct pt_decoder.  Use struct pt_query_decoder
instead.

Change-Id: I02f2cf7ee7a3d5562d046a2bf36c673dec19e88e
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: move packet unit tests to ptunit

Change-Id: I2e6c8cf4534a526da561b8d8a9d3b0bde65a328c
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: free pt_sync_*() of struct pt_decoder

Synchronizing onto the trace stream does not need a pt_decoder.  All that's
needed is the start position and the configuration.

Change the function parameters accordingly.
Move unit tests to ptunit.

Change-Id: I37a1c43fddbe3be4327dc320b947131d0b6dadcf
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: move packet payload reading into its own file

Move the extract_*() functions that read packet payloads from
pt_packet_decode.c into a new file pt_packet.[hc] and rename them to
pt_pkt_read_*().

Change-Id: Idb49dbf0bc46d7dd0f500dccd5f5dcb5cf777c56
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: remove pt_check_bounds()

pt_check_bounds() is unused.  Remove it.

Change-Id: Ie6e010572cc4157708c76e42f3a1ba74c1c783d5
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: rename packet decode functions

Rename all functions in pt_packet_decode.c to indicate whether they belong
to the packet decoder or the query decoder.

Also change the linkage to external.

Change-Id: Icecbf5aef286d10da42224487375ec857e8155e7
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: move decoder functions into their own file

Move the declaration of struct pt_decoder_function and pt_fetch_decoder()
into a new file pt_decoder_function.[hc].

Change-Id: Ia1bd8b320c4357f238a9e8ea690a27c1c92980cd
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: use pt_pkt_read_psb() for validating a sync point in pt_sync.c

In pt_sync.c, pt_find_psb() validates a PSB pattern.  So does
pt_pkt_read_psb() in pt_packet.c.

Change pt_find_psb() to use pt_pkt_read_psb().

Change-Id: I5a924821835664ac8c25584cbf9ab9442ee5233e
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: provoke fetch error

The pt_query_*() functions assume a current decoder function.  If none is
found, they assume a fetch error and try to reproduce the error code by
repeating the fetch.

Move this common code into a new function provoke_fetch_error().

Change-Id: Ia2277c198da4c68a9283aabebf951a3763a28ab0
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: change decoder fetching arguments

To fetch a decode function, we don't need a struct pt_decoder, we just
need the configuration and the current position in the buffer.

Change pt_fetch_decoder()'s arguments and rename it to pt_df_fetch().
Also move fetch unit tests to ptunit.

Change-Id: I346f565b3cb973f73b839ab499e0c741a4232c79
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: drop internal pt_decoder in struct pt_packet_decoder

The packet decoder is a more or less shallow wrapper around pt_decoder
which, in turn, is essentially a query decoder.  That's the wrong way
around.

Change-Id: Ic052b4a8b8231d4a4f952315980b0f452e81b0ac
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: reduce ptunit-packet dependencies

With packet and query decoders now relatively separate, we can remove most of
ptunit-packet's dependencies.  We fill query decoder function symbols with
error-returning dummy implementations.

As a nice side-effect, this will tell us when we need to extend the unit tests
to cover new packets.

Change-Id: Ida483957cae100dae440649c23b2e3cfd266d9e6
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: drop check_pt_use tests

The two test cases of check_pt_use are already covered by ptt tests, i.e.

  fup-tip.ptt
  fup-tip_pgd-tip_pge.ptt

Remove the check tests.

Change-Id: I9c6b04009722acc3e91a5478fe36e6705217281e
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: support manual sync of query and insn decoder

Add new API functions pt_qry_sync_set() and pt_insn_sync_set() to manually
synchronize respective decoders.  There must be a PSB packet at the
synchronization point.

This is useful if the packet stream has already been split into PSB
segments in a prior pass.

Change-Id: Ibcaff65de1f5c33140bfd49cc9d39670d58e7af5
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: outline bounds check in pt_sync_*() functions

Each pt_sync_*() function checks whether the starting position lies within
the bounds of the trace buffer.  Outline this check into a helper function.

Change-Id: Iba4ac493a322733b90cf1e2c281eaa47e28889c6
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: add missing enabled check in pt_insn_sync_backward()

After sync'ing backwards, the instruction flow decoder did not check whether
tracing is enabled.  This will very likely lead to decode errors shortly
after.

Change-Id: If38d760c9bfa94ee6378e2b31e97715c6d38ce90
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: move query functions into pt_query_decoder.c

The functions defined in pt_query.c are used solely by small wrappers
in pt_query_decoder.c.  Inline them into their respective wrapper.

Change the linkage of pt_qry_start() to internal and remove two
unit tests in ptunit-query.  The function is now only called after
a successful synchronization so the tests no longer make sense.

Change-Id: I831ed3c115f0e11c6c487822947dfb05c2434d10
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: inline pt_decoder_get_*() functions

pt_decoder_get_pos() and pt_decoder_get_sync() are used solely in
respecive wrappers in pt_query_decoder.c.  Inline them.

This futher allows us to remove pt_begin() and pt_end().
Drop unit tests for those functions.

Change-Id: Iac7d3b1d81b41841152895221136adac00710ac6
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: remove pt_alloc_decoder() and pt_free_decoder()

pt_alloc_decoder() and pt_free_decoder() are only used for unit testing.
Change unit tests to use pt_decoder_init() and pt_decoder_fini() instead.

Drop unit tests for those functions.

Change-Id: I1d4b32dd7da58d6914334a094e0db840982100f5
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: inline pt_decoder into pt_query_decoder

The only remaining user of struct pt_decoder is struct pt_query_decoder.
Inline it.

Also move query decoder functions into pt_query_decoder.c.

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