Skip to content

Commit e980a6d

Browse files
i#4915: label non-fetched instructions in drmemtrace view tool (#7810)
Instruction records with type TRACE_TYPE_INSTR_NO_FETCH were previously displayed as normal ifetch entries in the drmemtrace view tool when decoding was enabled, which was misleading for REP string expansion. This change updates the view tool output to label such records as non-fetched, without altering trace generation or expansion logic. Xref #4915.
1 parent 26c8fc1 commit e980a6d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

clients/drcachesim/tests/view_test.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,40 @@ run_chunk_tests(void *drcontext)
803803
return run_single_thread_chunk_test(drcontext) && run_serial_chunk_test(drcontext);
804804
}
805805

806+
#ifdef X86
807+
bool
808+
run_unfetched_rep_string_test(void *drcontext)
809+
{
810+
static constexpr addr_t BASE_ADDR = 0x123450;
811+
const memref_tid_t tid = 1;
812+
const uint64_t filetype = OFFLINE_FILE_TYPE_ENCODINGS;
813+
814+
instrlist_t *ilist = instrlist_create(drcontext);
815+
instr_t *rep_movs = INSTR_CREATE_rep_movs_1(drcontext);
816+
instrlist_append(ilist, rep_movs);
817+
818+
std::vector<memref_with_IR_t> memref_setup = {
819+
{ gen_marker(tid, TRACE_MARKER_TYPE_FILETYPE, static_cast<uintptr_t>(filetype)),
820+
nullptr },
821+
{ gen_instr_type(TRACE_TYPE_INSTR, tid), rep_movs },
822+
{ gen_instr_type(TRACE_TYPE_INSTR_NO_FETCH, tid), nullptr },
823+
};
824+
std::vector<memref_t> memrefs =
825+
add_encodings_to_memrefs(ilist, memref_setup, BASE_ADDR);
826+
827+
view_test_t view(drcontext, *ilist);
828+
std::string res = run_test_helper(view, memrefs);
829+
instrlist_clear_and_destroy(drcontext, ilist);
830+
831+
if (res.find("non-fetched") == std::string::npos) {
832+
std::cerr << "Missing non-fetched label for rep string unfetched record\n";
833+
std::cerr << "Output was: " << res << "\n";
834+
return false;
835+
}
836+
return true;
837+
}
838+
#endif
839+
806840
/* Test view tool on a OFFLINE_FILE_TYPE_ARCH_REGDEPS trace.
807841
* The trace hardcoded in entries is X64, so we only test on X64 architectures here.
808842
*/
@@ -883,6 +917,9 @@ test_main(int argc, const char *argv[])
883917
{
884918
void *drcontext = dr_standalone_init();
885919
if (run_limit_tests(drcontext) && run_chunk_tests(drcontext) &&
920+
#ifdef X86
921+
run_unfetched_rep_string_test(drcontext) &&
922+
#endif
886923
run_regdeps_test(drcontext)) {
887924
std::cerr << "view_test passed\n";
888925
return 0;

clients/drcachesim/tools/view.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref)
527527
if (trace_version_ == -1) {
528528
trace_version_ = static_cast<int>(serial_stream_->get_version());
529529
}
530-
std::cerr << std::left << std::setw(name_width) << "ifetch" << std::right
530+
const char *instr_name =
531+
(memref.instr.type == TRACE_TYPE_INSTR_NO_FETCH ? "non-fetched" : "ifetch");
532+
std::cerr << std::left << std::setw(name_width) << instr_name << std::right
531533
<< std::setw(2) << memref.instr.size << " byte(s) @ 0x" << std::hex
532534
<< std::setfill('0') << std::setw(sizeof(void *) * 2) << memref.instr.addr
533535
<< std::dec << std::setfill(' ');

0 commit comments

Comments
 (0)