Blame doc/man/pt_blk_next.3.md

Packit b1f7ae
% PT_BLK_NEXT(3)
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
 ! Copyright (c) 2016-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_blk_next, pt_block - iterate over blocks of traced instructions
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# SYNOPSIS
Packit b1f7ae
Packit b1f7ae
| **\#include `<intel-pt.h>`**
Packit b1f7ae
|
Packit b1f7ae
| **struct pt_block;**
Packit b1f7ae
|
Packit b1f7ae
| **int pt_blk_next(struct pt_blk_decoder \**decoder*,**
Packit b1f7ae
|                  **struct pt_blk \**blk*, size_t *size*);**
Packit b1f7ae
|
Packit b1f7ae
| **int pt_blk_next(struct pt_block_decoder \**decoder*,**
Packit b1f7ae
|                 **struct pt_block \**block*, size_t *size*);**
Packit b1f7ae
Packit b1f7ae
Link with *-lipt*.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# DESCRIPTION
Packit b1f7ae
Packit b1f7ae
**pt_blk_next**() provides the next block of instructions in execution order,
Packit b1f7ae
which is described by the *pt_block* structure.
Packit b1f7ae
Packit b1f7ae
The *size* argument must be set to *sizeof(struct pt_block)*.  The function will
Packit b1f7ae
provide at most *size* bytes of the *pt_block* structure.  A newer decoder
Packit b1f7ae
library may truncate an extended *pt_block* object to *size* bytes.
Packit b1f7ae
Packit b1f7ae
An older decoder library may provide less *pt_block* fields.  Fields that are
Packit b1f7ae
not 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 block of instructions is provided in the *pt_block* object
Packit b1f7ae
pointed to by the *block* argument.  The *pt_block* structure is declared as:
Packit b1f7ae
Packit b1f7ae
~~~{.c}
Packit b1f7ae
/** A block of instructions.
Packit b1f7ae
 *
Packit b1f7ae
 * Instructions in this block are executed sequentially but are not necessarily
Packit b1f7ae
 * contiguous in memory.  Users are expected to follow direct branches.
Packit b1f7ae
 */
Packit b1f7ae
struct pt_block {
Packit b1f7ae
    /** The IP of the first instruction in this block. */
Packit b1f7ae
    uint64_t ip;
Packit b1f7ae
Packit b1f7ae
    /** The IP of the last instruction in this block.
Packit b1f7ae
     *
Packit b1f7ae
     * This can be used for error-detection.
Packit b1f7ae
     */
Packit b1f7ae
    uint64_t end_ip;
Packit b1f7ae
Packit b1f7ae
    /** The image section that contains the instructions in this block.
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
    /** The execution mode for all instructions in this block. */
Packit b1f7ae
    enum pt_exec_mode mode;
Packit b1f7ae
Packit b1f7ae
    /** The instruction class for the last instruction in this block.
Packit b1f7ae
     *
Packit b1f7ae
     * This field may be set to ptic_error to indicate that the instruction
Packit b1f7ae
     * class is not available.  The block decoder may choose to not provide
Packit b1f7ae
     * the instruction class in some cases for performance reasons.
Packit b1f7ae
     */
Packit b1f7ae
    enum pt_insn_class iclass;
Packit b1f7ae
Packit b1f7ae
    /** The number of instructions in this block. */
Packit b1f7ae
    uint16_t ninsn;
Packit b1f7ae
Packit b1f7ae
    /** The raw bytes of the last instruction in this block in case the
Packit b1f7ae
     * instruction does not fit entirely into this block's section.
Packit b1f7ae
     *
Packit b1f7ae
     * This field is only valid if \@truncated is set.
Packit b1f7ae
     */
Packit b1f7ae
    uint8_t raw[pt_max_insn_size];
Packit b1f7ae
Packit b1f7ae
    /** The size of the last instruction in this block in bytes.
Packit b1f7ae
     *
Packit b1f7ae
     * This field is only valid if \@truncated is set.
Packit b1f7ae
     */
Packit b1f7ae
    uint8_t size;
Packit b1f7ae
Packit b1f7ae
    /** A collection of flags giving additional information about the
Packit b1f7ae
     * instructions in this block.
Packit b1f7ae
     *
Packit b1f7ae
     * - all instructions in this block were executed speculatively.
Packit b1f7ae
     */
Packit b1f7ae
    uint32_t speculative:1;
Packit b1f7ae
Packit b1f7ae
    /** - speculative execution was aborted after this block. */
Packit b1f7ae
    uint32_t aborted:1;
Packit b1f7ae
Packit b1f7ae
    /** - speculative execution was committed after this block. */
Packit b1f7ae
    uint32_t committed:1;
Packit b1f7ae
Packit b1f7ae
    /** - tracing was disabled after this block. */
Packit b1f7ae
    uint32_t disabled:1;
Packit b1f7ae
Packit b1f7ae
    /** - tracing was enabled at this block. */
Packit b1f7ae
    uint32_t enabled:1;
Packit b1f7ae
Packit b1f7ae
    /** - tracing was resumed at this block.
Packit b1f7ae
     *
Packit b1f7ae
     *    In addition to tracing being enabled, it continues from the IP
Packit b1f7ae
     *    at which tracing had been disabled before.
Packit b1f7ae
     *
Packit b1f7ae
     *    If tracing was disabled at a call instruction, we assume that
Packit b1f7ae
     *    tracing will be re-enabled after returning from the call at the
Packit b1f7ae
     *    instruction following the call instruction.
Packit b1f7ae
     */
Packit b1f7ae
    uint32_t resumed:1;
Packit b1f7ae
Packit b1f7ae
    /** - normal execution flow was interrupted after this block. */
Packit b1f7ae
    uint32_t interrupted:1;
Packit b1f7ae
Packit b1f7ae
    /** - tracing resumed at this block after an overflow. */
Packit b1f7ae
    uint32_t resynced:1;
Packit b1f7ae
Packit b1f7ae
    /** - tracing was stopped after this block. */
Packit b1f7ae
    uint32_t stopped:1;
Packit b1f7ae
Packit b1f7ae
    /** - the last instruction in this block is truncated.
Packit b1f7ae
     *
Packit b1f7ae
     *    It starts in this block's section but continues in one or more
Packit b1f7ae
     *    other sections depending on how fragmented the memory image is.
Packit b1f7ae
     *
Packit b1f7ae
     *    The raw bytes for the last instruction are provided in \@raw and
Packit b1f7ae
     *    its size in \@size in this case.
Packit b1f7ae
     */
Packit b1f7ae
    uint32_t truncated:1;
Packit b1f7ae
};
Packit b1f7ae
~~~
Packit b1f7ae
Packit b1f7ae
The fields of the *pt_block* structure are described in more detail below:
Packit b1f7ae
Packit b1f7ae
ip
Packit b1f7ae
:   The virtual address of the first instruction in the block.  The address
Packit b1f7ae
    should be interpreted in the current address space context.
Packit b1f7ae
Packit b1f7ae
end_ip
Packit b1f7ae
:   The virtual address of the last instruction in the block.  The address
Packit b1f7ae
    should be interpreted in the current address space context.
Packit b1f7ae
Packit b1f7ae
    This can be used for error detection.  Reconstruction of the instructions in
Packit b1f7ae
    a block should end with the last instruction at *end_ip*.
Packit b1f7ae
Packit b1f7ae
isid
Packit b1f7ae
:   The image section identifier of the section from which the block of
Packit b1f7ae
    instructions originated.  This will be zero unless the instructions came
Packit b1f7ae
    from a section that was added via an image section cache.  See
Packit b1f7ae
    **pt_image_add_cached**(3).
Packit b1f7ae
Packit b1f7ae
    The image section identifier can be used for reading the memory containing
Packit b1f7ae
    an instruction in order to decode it and for tracing an instruction back to
Packit b1f7ae
    its binary file and from there to source code.
Packit b1f7ae
Packit b1f7ae
mode
Packit b1f7ae
:   The execution mode at which the instructions in the block were executed.
Packit b1f7ae
    The *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
iclass
Packit b1f7ae
:   A coarse classification of the last instruction in the block.  This may be
Packit b1f7ae
    *ptic_error* to indicate that the classification is not available.
Packit b1f7ae
Packit b1f7ae
    The block decoder knows the instruction class of the instruction that ended
Packit b1f7ae
    the block most of the time.  If it does, it provides this information to
Packit b1f7ae
    save the caller the effort of decoding the instruction in some cases.
Packit b1f7ae
Packit b1f7ae
ninsn
Packit b1f7ae
:   The number of instructions contained in this block.
Packit b1f7ae
Packit b1f7ae
    The instructions are sequential in the sense that no trace is required for
Packit b1f7ae
    reconstructing them.  They are not necessarily contiguous in memory.
Packit b1f7ae
Packit b1f7ae
    The IP of the first instruction is given in the *ip* field and the IP of
Packit b1f7ae
    other instructions can be determined by decoding and examining the previous
Packit b1f7ae
    instruction.
Packit b1f7ae
Packit b1f7ae
raw
Packit b1f7ae
:   If the last instruction of this block can not be read entirely from this
Packit b1f7ae
    block's section, this field provides the instruction's raw bytes.
Packit b1f7ae
Packit b1f7ae
    It is only valid if the *truncated* flag is set.
Packit b1f7ae
Packit b1f7ae
size
Packit b1f7ae
:   If the last instruction of this block can not be read entirely from this
Packit b1f7ae
    block's section, this field provides the instruction's size in bytes.
Packit b1f7ae
Packit b1f7ae
    It is only valid if the *truncated* flag is set.
Packit b1f7ae
Packit b1f7ae
speculative
Packit b1f7ae
:   A flag giving the speculative execution status of all instructions in the
Packit b1f7ae
    block.  If set, the instructions were executed speculatively.  Otherwise,
Packit b1f7ae
    the instructions were executed normally.
Packit b1f7ae
Packit b1f7ae
aborted
Packit b1f7ae
:   A flag saying whether speculative execution was aborted after the last
Packit b1f7ae
    instruction in this block.  If set, speculative execution was aborted and
Packit b1f7ae
    the effect of speculatively executed instructions prior to and including
Packit b1f7ae
    this block was discarded.
Packit b1f7ae
Packit b1f7ae
committed
Packit b1f7ae
:   A flag saying whether the speculative execution state was committed after
Packit b1f7ae
    the last instruction in this block.  If set, the effect of speculatively
Packit b1f7ae
    executed instructions prior to and including this block was committed.
Packit b1f7ae
Packit b1f7ae
disabled
Packit b1f7ae
:   A flag saying that tracing was disabled after the last instruction in this
Packit b1f7ae
    block.  If set, tracing was disabled after the last instruction in this
Packit b1f7ae
    block retired.
Packit b1f7ae
Packit b1f7ae
enabled
Packit b1f7ae
:   A flag saying whether tracing was enabled at the first instruction in this
Packit b1f7ae
    block.  If set, this is the first block of instructions after tracing was
Packit b1f7ae
    enabled.
Packit b1f7ae
Packit b1f7ae
resumed
Packit b1f7ae
:   A flag saying whether tracing was resumed at the first instruction in this
Packit b1f7ae
    block.  If set, tracing was previously disabled at this block's IP before
Packit b1f7ae
    executing the instruction at that IP and was then enabled at the same IP.
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 the last
Packit b1f7ae
    instruction in this block.  If set, the normal execution flow was
Packit b1f7ae
    interrupted.
Packit b1f7ae
Packit b1f7ae
    The next instruction, which is provided by another call to
Packit b1f7ae
    **pt_blk_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 the fist instruction in this block
Packit b1f7ae
    after an overflow.  If set, there was an internal buffer overflow and
Packit b1f7ae
    packets were lost.  This was the first block of instructions to retire after
Packit b1f7ae
    the overflow resolved.
Packit b1f7ae
Packit b1f7ae
stopped
Packit b1f7ae
:   A flag saying whether tracing was stopped after the last instruction in this
Packit b1f7ae
    block.  If set, this is the last block of instructions that retired before
Packit b1f7ae
    tracing was stopped due to a TraceStop condition.
Packit b1f7ae
Packit b1f7ae
truncated
Packit b1f7ae
:   A flag saying whether the last instruction in this block can not be read
Packit b1f7ae
    entirely from this block's section.  Some bytes need to be read from one or
Packit b1f7ae
    more other sections.  This can happen when an image section is partially
Packit b1f7ae
    overwritten by another image section.
Packit b1f7ae
Packit b1f7ae
    If set, the last instruction's memory is provided in *raw* and its size in
Packit b1f7ae
    *size*.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# RETURN VALUE
Packit b1f7ae
Packit b1f7ae
**pt_blk_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_blk_next**() will continue to
Packit b1f7ae
provide blocks for instructions as long as the instruction's addresses can be
Packit b1f7ae
determined without further trace.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
# ERRORS
Packit b1f7ae
Packit b1f7ae
pte_invalid
Packit b1f7ae
:   The *decoder* or *block* 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_blk_sync_forward**(3), **pt_blk_sync_backward**(3), or
Packit b1f7ae
    **pt_blk_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_blk_alloc_decoder**(3), **pt_blk_free_decoder**(3),
Packit b1f7ae
**pt_blk_sync_forward**(3), **pt_blk_sync_backward**(3),
Packit b1f7ae
**pt_blk_sync_set**(3), **pt_blk_time**(3), **pt_blk_core_bus_ratio**(3)