Blame doc/man/pt_insn_next.3.md

Packit b1f7ae
% PT_INSN_NEXT(3)
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
 ! Copyright (c) 2015-2017, Intel Corporation
Packit b1f7ae
 !
Packit b1f7ae
 ! Redistribution and use in source and binary forms, with or without
Packit b1f7ae
 ! modification, are permitted provided that the following conditions are met:
Packit b1f7ae
 !
Packit b1f7ae
 !  * Redistributions of source code must retain the above copyright notice,
Packit b1f7ae
 !    this list of conditions and the following disclaimer.
Packit b1f7ae
 !  * Redistributions in binary form must reproduce the above copyright notice,
Packit b1f7ae
 !    this list of conditions and the following disclaimer in the documentation
Packit b1f7ae
 !    and/or other materials provided with the distribution.
Packit b1f7ae
 !  * Neither the name of Intel Corporation nor the names of its contributors
Packit b1f7ae
 !    may be used to endorse or promote products derived from this software
Packit b1f7ae
 !    without specific prior written permission.
Packit b1f7ae
 !
Packit b1f7ae
 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit b1f7ae
 ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit b1f7ae
 ! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit b1f7ae
 ! ARE DISCLAIMED. IN NO NEXT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit b1f7ae
 ! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit b1f7ae
 ! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit b1f7ae
 ! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit b1f7ae
 ! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit b1f7ae
 ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit b1f7ae
 ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit b1f7ae
 ! POSSIBILITY OF SUCH DAMAGE.
Packit b1f7ae
 !-->
Packit b1f7ae
Packit b1f7ae
# NAME
Packit b1f7ae
Packit b1f7ae
pt_insn_next, pt_insn - iterate over traced instructions
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# SYNOPSIS
Packit b1f7ae
Packit b1f7ae
| **\#include `<intel-pt.h>`**
Packit b1f7ae
|
Packit b1f7ae
| **struct pt_insn;**
Packit b1f7ae
|
Packit b1f7ae
| **int pt_insn_next(struct pt_insn_decoder \**decoder*,**
Packit b1f7ae
|                  **struct pt_insn \**insn*, size_t *size*);**
Packit b1f7ae
Packit b1f7ae
Link with *-lipt*.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# DESCRIPTION
Packit b1f7ae
Packit b1f7ae
**pt_insn_next**() provides the next instruction in execution order, which is
Packit b1f7ae
described by the *pt_insn* structure.
Packit b1f7ae
Packit b1f7ae
The *size* argument must be set to *sizeof(struct pt_insn)*.  The function will
Packit b1f7ae
provide at most *size* bytes of the *pt_insn* structure.  A newer decoder
Packit b1f7ae
library may truncate an extended *pt_insn* object to *size* bytes.
Packit b1f7ae
Packit b1f7ae
An older decoder library may provide less *pt_insn* fields.  Fields that are not
Packit b1f7ae
provided will be zero-initialized.  For fields where zero is a valid value
Packit b1f7ae
(e.g. for bit-fields), check the decoder library version to determine which
Packit b1f7ae
fields are valid.  See **pt_library_version**(3).
Packit b1f7ae
Packit b1f7ae
On success, the next instruction is provided in the *pt_insn* object pointed to
Packit b1f7ae
by the *insn* argument.  The *pt_insn* structure is declared as:
Packit b1f7ae
Packit b1f7ae
~~~{.c}
Packit b1f7ae
/** A single traced instruction. */
Packit b1f7ae
struct pt_insn {
Packit b1f7ae
	/** The virtual address in its process. */
Packit b1f7ae
	uint64_t ip;
Packit b1f7ae
Packit b1f7ae
	/** A coarse classification. */
Packit b1f7ae
	enum pt_insn_class iclass;
Packit b1f7ae
Packit b1f7ae
	/** The execution mode. */
Packit b1f7ae
	enum pt_exec_mode mode;
Packit b1f7ae
Packit b1f7ae
	/** The raw bytes. */
Packit b1f7ae
	uint8_t raw[pt_max_insn_size];
Packit b1f7ae
Packit b1f7ae
	/** The size in bytes. */
Packit b1f7ae
	uint8_t size;
Packit b1f7ae
Packit b1f7ae
	/** A collection of flags giving additional information:
Packit b1f7ae
	 *
Packit b1f7ae
	 * - the instruction was executed speculatively.
Packit b1f7ae
	 */
Packit b1f7ae
	uint32_t speculative:1;
Packit b1f7ae
Packit b1f7ae
	/** - speculative execution was aborted after this
Packit b1f7ae
	 * instruction.
Packit b1f7ae
	 */
Packit b1f7ae
	uint32_t aborted:1;
Packit b1f7ae
Packit b1f7ae
	/** - speculative execution was committed after this
Packit b1f7ae
	 * instruction.
Packit b1f7ae
	 */
Packit b1f7ae
	uint32_t committed:1;
Packit b1f7ae
Packit b1f7ae
	/** - tracing was disabled after this instruction. */
Packit b1f7ae
	uint32_t disabled:1;
Packit b1f7ae
Packit b1f7ae
	/** - tracing was enabled at this instruction. */
Packit b1f7ae
	uint32_t enabled:1;
Packit b1f7ae
Packit b1f7ae
	/** - tracing was resumed at this instruction.
Packit b1f7ae
	 *
Packit b1f7ae
	 *    In addition to tracing being enabled, it continues
Packit b1f7ae
	 *    from the IP at which tracing had been disabled before.
Packit b1f7ae
	 */
Packit b1f7ae
	uint32_t resumed:1;
Packit b1f7ae
Packit b1f7ae
	/** - normal execution flow was interrupted after this
Packit b1f7ae
	 * instruction.
Packit b1f7ae
	 */
Packit b1f7ae
	uint32_t interrupted:1;
Packit b1f7ae
Packit b1f7ae
	/** - tracing resumed at this instruction after an
Packit b1f7ae
	 * overflow.
Packit b1f7ae
	 */
Packit b1f7ae
	uint32_t resynced:1;
Packit b1f7ae
Packit b1f7ae
	/** - tracing was stopped after this instruction. */
Packit b1f7ae
	uint32_t stopped:1;
Packit b1f7ae
Packit b1f7ae
	/** - this instruction is truncated in its image section.
Packit b1f7ae
	 *
Packit b1f7ae
	 *    It starts in the image section identified by \@isid and continues
Packit b1f7ae
	 *    in one or more other sections.
Packit b1f7ae
	 */
Packit b1f7ae
	uint32_t truncated:1;
Packit b1f7ae
Packit b1f7ae
	/** The image section identifier for the section containing this
Packit b1f7ae
	 * instruction.
Packit b1f7ae
	 *
Packit b1f7ae
	 * A value of zero means that the section did not have an identifier.
Packit b1f7ae
	 * The section was not added via an image section cache or the memory
Packit b1f7ae
	 * was read via the read memory callback.
Packit b1f7ae
	 */
Packit b1f7ae
	int isid;
Packit b1f7ae
};
Packit b1f7ae
~~~
Packit b1f7ae
Packit b1f7ae
The fields of the *pt_insn* structure are described in more detail below:
Packit b1f7ae
Packit b1f7ae
ip
Packit b1f7ae
:   The virtual address of the instruction.  The address should be interpreted
Packit b1f7ae
    in the current address space context.
Packit b1f7ae
Packit b1f7ae
iclass
Packit b1f7ae
:   A coarse classification of the instruction suitable for constructing a call
Packit b1f7ae
    back trace.  The *pt_insn_class* enumeration is declared as:
Packit b1f7ae
Packit b1f7ae
~~~{.c}
Packit b1f7ae
/** The instruction class.
Packit b1f7ae
 *
Packit b1f7ae
 * We provide only a very coarse classification suitable for
Packit b1f7ae
 * reconstructing the execution flow.
Packit b1f7ae
 */
Packit b1f7ae
enum pt_insn_class {
Packit b1f7ae
	/* The instruction could not be classified. */
Packit b1f7ae
	ptic_error,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is something not listed below. */
Packit b1f7ae
	ptic_other,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is a near (function) call. */
Packit b1f7ae
	ptic_call,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is a near (function) return. */
Packit b1f7ae
	ptic_return,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is a near unconditional jump. */
Packit b1f7ae
	ptic_jump,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is a near conditional jump. */
Packit b1f7ae
	ptic_cond_jump,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is a call-like far transfer.
Packit b1f7ae
	 * E.g. SYSCALL, SYSENTER, or FAR CALL.
Packit b1f7ae
	 */
Packit b1f7ae
	ptic_far_call,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is a return-like far transfer.
Packit b1f7ae
	 * E.g. SYSRET, SYSEXIT, IRET, or FAR RET.
Packit b1f7ae
	 */
Packit b1f7ae
	ptic_far_return,
Packit b1f7ae
Packit b1f7ae
	/* The instruction is a jump-like far transfer.
Packit b1f7ae
	 * E.g. FAR JMP.
Packit b1f7ae
	 */
Packit b1f7ae
	ptic_far_jump
Packit b1f7ae
};
Packit b1f7ae
~~~
Packit b1f7ae
Packit b1f7ae
mode
Packit b1f7ae
:   The execution mode at which the instruction was executed.  The
Packit b1f7ae
    *pt_exec_mode* enumeration is declared as:
Packit b1f7ae
Packit b1f7ae
~~~{.c}
Packit b1f7ae
/** An execution mode. */
Packit b1f7ae
enum pt_exec_mode {
Packit b1f7ae
	ptem_unknown,
Packit b1f7ae
	ptem_16bit,
Packit b1f7ae
	ptem_32bit,
Packit b1f7ae
	ptem_64bit
Packit b1f7ae
};
Packit b1f7ae
~~~
Packit b1f7ae
Packit b1f7ae
raw
Packit b1f7ae
:   The memory containing the instruction.
Packit b1f7ae
Packit b1f7ae
size
Packit b1f7ae
:   The size of the instruction in bytes.
Packit b1f7ae
Packit b1f7ae
speculative
Packit b1f7ae
:   A flag giving the speculative execution status of the instruction.  If set,
Packit b1f7ae
    the instruction was executed speculatively.  Otherwise, the instruction was
Packit b1f7ae
    executed normally.
Packit b1f7ae
Packit b1f7ae
aborted
Packit b1f7ae
:   A flag saying whether speculative execution was aborted after this
Packit b1f7ae
    instruction.  If set, speculative execution was aborted and the effect of
Packit b1f7ae
    speculatively executed instructions prior to this was discarded.
Packit b1f7ae
Packit b1f7ae
committed
Packit b1f7ae
:   A flag saying whether the speculative execution state was committed.  If
Packit b1f7ae
    set, the effect of speculatively executed instructions prior to this was
Packit b1f7ae
    committed.
Packit b1f7ae
Packit b1f7ae
disabled
Packit b1f7ae
:   A flag saying that tracing was disabled after this instruction.  If set,
Packit b1f7ae
    tracing was disabled after this instruction retired.
Packit b1f7ae
Packit b1f7ae
enabled
Packit b1f7ae
:   A flag saying whether tracing was enabled at this instruction.  If set, this
Packit b1f7ae
    is the first instruction that retired after tracing was enabled.
Packit b1f7ae
Packit b1f7ae
resumed
Packit b1f7ae
:   A flag saying whether tracing was resumed at this instruction.  If set,
Packit b1f7ae
    tracing was previously disabled at this instruction's IP before executing
Packit b1f7ae
    this instruction and was then enabled at this instruction.
Packit b1f7ae
Packit b1f7ae
    A typical example would be a system call or interrupt when tracing only user
Packit b1f7ae
    space.  Tracing is disabled due to the context switch and is then resumed
Packit b1f7ae
    from the next instruction after returning to user space.
Packit b1f7ae
Packit b1f7ae
interrupted
Packit b1f7ae
:   A flag saying whether normal execution flow was interrupted after this
Packit b1f7ae
    instruction.  If set, the normal execution flow was interrupted.
Packit b1f7ae
Packit b1f7ae
    The next instruction, which is provided by another call to
Packit b1f7ae
    **pt_insn_next**(), is the next instruction that retired after the
Packit b1f7ae
    interrupt.  This is not necessarily the interrupt's destination.
Packit b1f7ae
Packit b1f7ae
resynced
Packit b1f7ae
:   A flag saying whether tracing resumed at this instruction after an
Packit b1f7ae
    overflow.  If set, there was an internal buffer overflow and packets were
Packit b1f7ae
    lost.  This was the first instruction to retire after the overflow resolved.
Packit b1f7ae
Packit b1f7ae
stopped
Packit b1f7ae
:   A flag saying whether tracing was stopped after this instruction.  If set,
Packit b1f7ae
    this is the last instruction that retired before tracing was stopped due to
Packit b1f7ae
    a TraceStop condition.
Packit b1f7ae
Packit b1f7ae
truncated
Packit b1f7ae
:   A flag saying whether this instruction spans more than one image section.
Packit b1f7ae
    If clear, this instruction originates from a single section identified by
Packit b1f7ae
    *isid*.  If set, the instruction overlaps two or more image sections.  In
Packit b1f7ae
    this case, *isid* identifies the section that contains the first byte.
Packit b1f7ae
Packit b1f7ae
isid
Packit b1f7ae
:   The image section identifier of the section from which the instruction
Packit b1f7ae
    originated.  This will be zero unless the instruction came from a section
Packit b1f7ae
    that was added via an image section cache.  See **pt_image_add_cached**(3).
Packit b1f7ae
Packit b1f7ae
    The image section identifier can be used to trace an instruction back to
Packit b1f7ae
    its binary file and from there to source code.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# RETURN VALUE
Packit b1f7ae
Packit b1f7ae
**pt_insn_next**() returns zero or a positive value on success or a negative
Packit b1f7ae
*pt_error_code* enumeration constant in case of an error.
Packit b1f7ae
Packit b1f7ae
On success, a bit-vector of *pt_status_flag* enumeration constants is returned.
Packit b1f7ae
The *pt_status_flag* enumeration is declared as:
Packit b1f7ae
Packit b1f7ae
~~~{.c}
Packit b1f7ae
/** Decoder status flags. */
Packit b1f7ae
enum pt_status_flag {
Packit b1f7ae
	/** There is an event pending. */
Packit b1f7ae
	pts_event_pending	= 1 << 0,
Packit b1f7ae
Packit b1f7ae
	/** The address has been suppressed. */
Packit b1f7ae
	pts_ip_suppressed	= 1 << 1,
Packit b1f7ae
Packit b1f7ae
	/** There is no more trace data available. */
Packit b1f7ae
	pts_eos				= 1 << 2
Packit b1f7ae
};
Packit b1f7ae
~~~
Packit b1f7ae
Packit b1f7ae
The *pt_eos* flag indicates that the information contained in the Intel PT
Packit b1f7ae
stream has been consumed.  Further calls to **pt_insn_next**() will continue to
Packit b1f7ae
provide instructions as long as the instruction's address can be determined
Packit b1f7ae
without further trace.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# ERRORS
Packit b1f7ae
Packit b1f7ae
pte_invalid
Packit b1f7ae
:   The *decoder* or *insn* argument is NULL or the *size* argument is too
Packit b1f7ae
    small.
Packit b1f7ae
Packit b1f7ae
pte_eos
Packit b1f7ae
:   Decode reached the end of the trace stream.
Packit b1f7ae
Packit b1f7ae
pte_nosync
Packit b1f7ae
:   The decoder has not been synchronized onto the trace stream.  Use
Packit b1f7ae
    **pt_insn_sync_forward**(3), **pt_insn_sync_backward**(3), or
Packit b1f7ae
    **pt_insn_sync_set**(3) to synchronize *decoder*.
Packit b1f7ae
Packit b1f7ae
pte_bad_opc
Packit b1f7ae
:   The decoder encountered an unsupported Intel PT packet opcode.
Packit b1f7ae
Packit b1f7ae
pte_bad_packet
Packit b1f7ae
:   The decoder encountered an unsupported Intel PT packet payload.
Packit b1f7ae
Packit b1f7ae
pte_bad_query
Packit b1f7ae
:   Execution flow reconstruction and trace got out of sync.
Packit b1f7ae
Packit b1f7ae
    This typically means that, on its way to the virtual address of the next
Packit b1f7ae
    event, the decoder encountered a conditional or indirect branch for which it
Packit b1f7ae
    did not find guidance in the trace.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# SEE ALSO
Packit b1f7ae
Packit b1f7ae
**pt_insn_alloc_decoder**(3), **pt_insn_free_decoder**(3),
Packit b1f7ae
**pt_insn_sync_forward**(3), **pt_insn_sync_backward**(3),
Packit b1f7ae
**pt_insn_sync_set**(3), **pt_insn_time**(3), **pt_insn_core_bus_ratio**(3)