Skip to content

Commit d1912c7

Browse files
i#4138 samples: clarify why instrace does not expand REP string instructions (#7789)
Document the rationale for not expanding REP-prefixed string instructions in the instrace sample clients. instrace is a simple instruction tracer focused on instruction fetches, not per-iteration memory accesses. Expanding REP would emit multiple consecutive instances of the same instruction, which is often confusing in instrace output and differs from tools like perf that count only a single instance. Emulation-aware expansion of REP and scatter/gather instructions requires consuming emulation metadata via drmgr_orig_app_instr_for_fetch() and drmgr_orig_app_instr_for_operands(), as done in memtrace. That complexity is intentionally avoided in instrace and left to emulation-aware samples. Fixes #4138.
1 parent eb8c0c7 commit d1912c7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

api/samples/instrace_simple.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst
209209
if (!instr_is_app(instr))
210210
return DR_EMIT_DEFAULT;
211211

212+
/* We intentionally do not expand REP-prefixed string instructions here.
213+
* instrace is a simple instruction tracer: it is concerned only with
214+
* instruction fetches, not with per-iteration memory accesses.
215+
*
216+
* Expanding REP would emit multiple consecutive instances of the same
217+
* instruction (one per iteration), which is often confusing in instrace
218+
* output and differs from tools like perf that also count only a single
219+
* instance.
220+
*
221+
* Users who want to observe per-iteration behavior of REP instructions
222+
* should use emulation-aware samples such as memtrace, which consume the
223+
* emulation metadata via drmgr_orig_app_instr_for_fetch() /
224+
* drmgr_orig_app_instr_for_operands().
225+
*/
212226
/* insert code to add an entry to the buffer */
213227
instrument_instr(drcontext, bb, instr);
214228

api/samples/instrace_x86.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ event_bb_insert(void *drcontext, void *tag, instrlist_t *bb, instr_t *instr,
249249
{
250250
if (instr_get_app_pc(instr) == NULL || !instr_is_app(instr))
251251
return DR_EMIT_DEFAULT;
252+
253+
/* We intentionally do not expand REP-prefixed string instructions here.
254+
* instrace is a simple instruction tracer: it is concerned only with
255+
* instruction fetches, not with per-iteration memory accesses.
256+
*
257+
* Expanding REP would emit multiple consecutive instances of the same
258+
* instruction (one per iteration), which is often confusing in instrace
259+
* output and differs from tools like perf that also count only a single
260+
* instance.
261+
*
262+
* Users who want to observe per-iteration behavior of REP instructions
263+
* should use emulation-aware samples such as memtrace, which consume the
264+
* emulation metadata via drmgr_orig_app_instr_for_fetch() /
265+
* drmgr_orig_app_instr_for_operands().
266+
*/
252267
instrument_instr(drcontext, bb, instr);
253268
return DR_EMIT_DEFAULT;
254269
}

0 commit comments

Comments
 (0)