4 ! Copyright (c) 2016-2018, Intel Corporation
6 ! Redistribution and use in source and binary forms, with or without
7 ! modification, are permitted provided that the following conditions are met:
9 ! * Redistributions of source code must retain the above copyright notice,
10 ! this list of conditions and the following disclaimer.
11 ! * Redistributions in binary form must reproduce the above copyright notice,
12 ! this list of conditions and the following disclaimer in the documentation
13 ! and/or other materials provided with the distribution.
14 ! * Neither the name of Intel Corporation nor the names of its contributors
15 ! may be used to endorse or promote products derived from this software
16 ! without specific prior written permission.
18 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 ! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ! ARE DISCLAIMED. IN NO NEXT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 ! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 ! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 ! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 ! POSSIBILITY OF SUCH DAMAGE.
33 pt_blk_next, pt_block - iterate over blocks of traced instructions
38 | **\#include `<intel-pt.h>`**
40 | **struct pt_block;**
42 | **int pt_blk_next(struct pt_blk_decoder \**decoder*,**
43 | **struct pt_blk \**blk*, size_t *size*);**
45 | **int pt_blk_next(struct pt_block_decoder \**decoder*,**
46 | **struct pt_block \**block*, size_t *size*);**
53 **pt_blk_next**() provides the next block of instructions in execution order,
54 which is described by the *pt_block* structure.
56 The *size* argument must be set to *sizeof(struct pt_block)*. The function will
57 provide at most *size* bytes of the *pt_block* structure. A newer decoder
58 library may truncate an extended *pt_block* object to *size* bytes.
60 An older decoder library may provide less *pt_block* fields. Fields that are
61 not provided will be zero-initialized. For fields where zero is a valid value
62 (e.g. for bit-fields), check the decoder library version to determine which
63 fields are valid. See **pt_library_version**(3).
65 On success, the next block of instructions is provided in the *pt_block* object
66 pointed to by the *block* argument. The *pt_block* structure is declared as:
69 /** A block of instructions.
71 * Instructions in this block are executed sequentially but are not necessarily
72 * contiguous in memory. Users are expected to follow direct branches.
75 /** The IP of the first instruction in this block. */
78 /** The IP of the last instruction in this block.
80 * This can be used for error-detection.
84 /** The image section that contains the instructions in this block.
86 * A value of zero means that the section did not have an identifier.
87 * The section was not added via an image section cache or the memory
88 * was read via the read memory callback.
92 /** The execution mode for all instructions in this block. */
93 enum pt_exec_mode mode;
95 /** The instruction class for the last instruction in this block.
97 * This field may be set to ptic_error to indicate that the instruction
98 * class is not available. The block decoder may choose to not provide
99 * the instruction class in some cases for performance reasons.
101 enum pt_insn_class iclass;
103 /** The number of instructions in this block. */
106 /** The raw bytes of the last instruction in this block in case the
107 * instruction does not fit entirely into this block's section.
109 * This field is only valid if \@truncated is set.
111 uint8_t raw[pt_max_insn_size];
113 /** The size of the last instruction in this block in bytes.
115 * This field is only valid if \@truncated is set.
119 /** A collection of flags giving additional information about the
120 * instructions in this block.
122 * - all instructions in this block were executed speculatively.
124 uint32_t speculative:1;
126 /** - the last instruction in this block is truncated.
128 * It starts in this block's section but continues in one or more
129 * other sections depending on how fragmented the memory image is.
131 * The raw bytes for the last instruction are provided in \@raw and
132 * its size in \@size in this case.
134 uint32_t truncated:1;
138 The fields of the *pt_block* structure are described in more detail below:
141 : The virtual address of the first instruction in the block. The address
142 should be interpreted in the current address space context.
145 : The virtual address of the last instruction in the block. The address
146 should be interpreted in the current address space context.
148 This can be used for error detection. Reconstruction of the instructions in
149 a block should end with the last instruction at *end_ip*.
152 : The image section identifier of the section from which the block of
153 instructions originated. This will be zero unless the instructions came
154 from a section that was added via an image section cache. See
155 **pt_image_add_cached**(3).
157 The image section identifier can be used for reading the memory containing
158 an instruction in order to decode it and for tracing an instruction back to
159 its binary file and from there to source code.
162 : The execution mode at which the instructions in the block were executed.
163 The *pt_exec_mode* enumeration is declared as:
166 /** An execution mode. */
176 : A coarse classification of the last instruction in the block. This may be
177 *ptic_error* to indicate that the classification is not available.
179 The block decoder knows the instruction class of the instruction that ended
180 the block most of the time. If it does, it provides this information to
181 save the caller the effort of decoding the instruction in some cases.
184 : The number of instructions contained in this block.
186 The instructions are sequential in the sense that no trace is required for
187 reconstructing them. They are not necessarily contiguous in memory.
189 The IP of the first instruction is given in the *ip* field and the IP of
190 other instructions can be determined by decoding and examining the previous
194 : If the last instruction of this block can not be read entirely from this
195 block's section, this field provides the instruction's raw bytes.
197 It is only valid if the *truncated* flag is set.
200 : If the last instruction of this block can not be read entirely from this
201 block's section, this field provides the instruction's size in bytes.
203 It is only valid if the *truncated* flag is set.
206 : A flag giving the speculative execution status of all instructions in the
207 block. If set, the instructions were executed speculatively. Otherwise,
208 the instructions were executed normally.
211 : A flag saying whether the last instruction in this block can not be read
212 entirely from this block's section. Some bytes need to be read from one or
213 more other sections. This can happen when an image section is partially
214 overwritten by another image section.
216 If set, the last instruction's memory is provided in *raw* and its size in
222 **pt_blk_next**() returns zero or a positive value on success or a negative
223 *pt_error_code* enumeration constant in case of an error.
225 On success, a bit-vector of *pt_status_flag* enumeration constants is returned.
226 The *pt_status_flag* enumeration is declared as:
229 /** Decoder status flags. */
230 enum pt_status_flag {
231 /** There is an event pending. */
232 pts_event_pending = 1 << 0,
234 /** The address has been suppressed. */
235 pts_ip_suppressed = 1 << 1,
237 /** There is no more trace data available. */
242 The *pts_event_pending* flag indicates that one or more events are pending. Use
243 **pt_blk_event**(3) to process pending events before calling **pt_blk_next**()
246 The *pt_eos* flag indicates that the information contained in the Intel PT
247 stream has been consumed. Further calls to **pt_blk_next**() will continue to
248 provide blocks for instructions as long as the instruction's addresses can be
249 determined without further trace.
255 : The *decoder* or *block* argument is NULL or the *size* argument is too
259 : Decode reached the end of the trace stream.
262 : The decoder has not been synchronized onto the trace stream. Use
263 **pt_blk_sync_forward**(3), **pt_blk_sync_backward**(3), or
264 **pt_blk_sync_set**(3) to synchronize *decoder*.
267 : The decoder encountered an unsupported Intel PT packet opcode.
270 : The decoder encountered an unsupported Intel PT packet payload.
273 : Execution flow reconstruction and trace got out of sync.
275 This typically means that, on its way to the virtual address of the next
276 event, the decoder encountered a conditional or indirect branch for which it
277 did not find guidance in the trace.
282 **pt_blk_alloc_decoder**(3), **pt_blk_free_decoder**(3),
283 **pt_blk_sync_forward**(3), **pt_blk_sync_backward**(3),
284 **pt_blk_sync_set**(3), **pt_blk_time**(3), **pt_blk_core_bus_ratio**(3),