Skip to content

Commit

Permalink
i#6444 mid-rseq-exit: Handle at-exit trace exit (#6456)
Browse files Browse the repository at this point in the history
Augments the mid-rseq-trace-exit case to handle the rseq final instr
being reached but not passed. Adds a test case.

Issue: #6444
  • Loading branch information
derekbruening authored Nov 15, 2023
1 parent e046433 commit 77f62ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
17 changes: 14 additions & 3 deletions clients/drcachesim/tests/raw2trace_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,9 +1984,12 @@ test_rseq_side_exit_inverted_with_timestamp(void *drcontext)
check_entry(entries, idx, TRACE_TYPE_FOOTER, -1));
}

/* Tests a trace ending mid-rseq (i#6444). */
/* Tests a trace ending mid-rseq (i#6444).
* If at_end is true, tests the endpoint just being reached but not pased;
* else tests the endpoint not being reached.
*/
bool
test_midrseq_end(void *drcontext)
test_midrseq_end_helper(void *drcontext, bool at_end)
{
std::cerr << "\n===============\nTesting mid-rseq trace end\n";
instrlist_t *ilist = instrlist_create(drcontext);
Expand Down Expand Up @@ -2021,7 +2024,8 @@ test_midrseq_end(void *drcontext)
raw.push_back(make_line_size());
raw.push_back(make_timestamp());
raw.push_back(make_core());
raw.push_back(make_marker(TRACE_MARKER_TYPE_RSEQ_ENTRY, offs_move3));
raw.push_back(
make_marker(TRACE_MARKER_TYPE_RSEQ_ENTRY, at_end ? offs_move2 : offs_move3));
raw.push_back(make_block(offs_move1, 2));
raw.push_back(make_block(offs_store, 1));
raw.push_back(make_memref(42));
Expand Down Expand Up @@ -2060,6 +2064,13 @@ test_midrseq_end(void *drcontext)
check_entry(entries, idx, TRACE_TYPE_FOOTER, -1));
}

bool
test_midrseq_end(void *drcontext)
{
return test_midrseq_end_helper(drcontext, /*at_end=*/false) &&
test_midrseq_end_helper(drcontext, /*at_end=*/true);
}

/* Tests pre-OFFLINE_FILE_VERSION_XFER_ABS_PC (module offset) handling. */
bool
test_xfer_modoffs(void *drcontext)
Expand Down
20 changes: 15 additions & 5 deletions clients/drcachesim/tracer/raw2trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,21 @@ raw2trace_t::process_offline_entry(raw2trace_thread_data_t *tdata,
tdata->error = "Missing thread id";
return false;
}
if (tdata->rseq_buffering_enabled_ &&
// Deliberately pass 0 as the PC so it's treated as an instru
// exit and we just dump the buffer as-is.
!adjust_and_emit_rseq_buffer(tdata, 0, 0))
return false;
if (tdata->rseq_buffering_enabled_) {
// Finish off the rseq buffer.
addr_t next_pc;
if (tdata->rseq_past_end_) {
// The thread exited right as we hit the lst instr.
next_pc = tdata->rseq_end_pc_;
} else {
// We exited mid-sequence.
// Deliberately pass 0 as the PC so it's treated as an instru
// exit and we just dump the buffer as-is.
next_pc = 0;
}
if (!adjust_and_emit_rseq_buffer(tdata, next_pc, 0))
return false;
}
log(2, "Thread %d exit\n", (uint)tid);
buf += trace_metadata_writer_t::write_thread_exit(buf, tid);
*end_of_record = true;
Expand Down

0 comments on commit 77f62ea

Please sign in to comment.