libipt: remove redundant variable

The flags variable in pt_cache_tnt() in pt_query.c is always zero.
Remove it.

This further allows us to remove the corresponding variable in
pt_query_cond_branch() in the same file.

Change-Id: I671926b058b6440338e90b71a99ecc03574b4541
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: split pt_status_flags()

The pt_status_flags() function is used for two purposes:
- to determine the status flags to return on a query
- to determine whether an event is pending when reading ahead

Add a new function to determine whether an event is pending.

Move pt_status_flags() into pt_query and change the linkage to internal.

Change-Id: I941b538b948c234fcf747513a3a6afe20ab0fa46
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: use const decoder parameter

Declare the decoder parameter of a few functions that should not modify
their decoder argument const.

Change-Id: If5e371c3f7134993c6ad05c20159e700a0ea47e5
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt, insn: update insn decoder state immediately

The insn decoder stores the status bits of the last query.
In pt_insn_next(), this state was held in a local variable and passed
around to event processing and proceed functions.

Update the state immediately and remove the status function parameter.

Change-Id: I2fc68b302bb6085e1d3ff522771deeabf5ab21c9
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt, insn: simplify event checking

Events are queried at various locations.

Add a function to check for pending events.  This function queries for
new events, if necessary.

Change-Id: I63794b3a7b9adb0ad843b79d60ec0e9d85c0bcb9
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt: fix TNT handling

Events should only be processed after consuming all TNT bits.  This ensures
that the decoder first navigates to the correct code region, e.g. the correct
iteration of a loop.

We achieve this already on the query layer by not signaling pending events
until the TNT cache is empty.

Remove two check_pt_use.c tests that assumed events are signaled with a
non-empty TNT cache.  Those tests no longer apply.

Update ptunit-query tests to avoid an extra TNT in the header assuming this
would be skipped and cached.

Add three new tests to cover the new functionality.

Change-Id: Icc3d140fb8eee0a51cfa29ac115a744a3bf3ba97
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
libipt, query: simplify query event processing

An event query with a non-empty TNT cache is bad.

The event should not have been signaled and users should first consume their
cached TNT bits before querying an event.

Diagnose such queries and simplify decoding.

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