Skip to content

Commit c98d073

Browse files
timorocallahan
authored andcommitted
"when-end" command that gives the last event number of the recording
1 parent a009e7e commit c98d073

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/DebuggerExtensionCommand.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ static SimpleDebuggerExtensionCommand info_recording(
8080
return string("Path of recording: \"") + json_escape(trace_dir) + string("\"");
8181
});
8282

83+
static SimpleDebuggerExtensionCommand when_end(
84+
"when-end", "Print the number of the last rr event in the recording.",
85+
[](GdbServer&, Task* t, const vector<string>&) {
86+
auto task = static_cast<ReplayTask*>(t);
87+
auto seek_reader(task->session().as_replay()->trace_reader());
88+
FrameTime time;
89+
for (;;) {
90+
auto result = seek_reader.read_task_event(&time);
91+
if (result.type() == TraceTaskEvent::Type::NONE) {
92+
break;
93+
}
94+
}
95+
return string("Event at end of recording: ") + to_string(time);
96+
});
97+
8398
static std::vector<ReplayTimeline::Mark> back_stack;
8499
static ReplayTimeline::Mark current_history_cp;
85100
static std::vector<ReplayTimeline::Mark> forward_stack;

src/test/when.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from util import *
22
import re
33

4+
send_custom_command('when-end')
5+
expect_debugger(re.compile(r'Event at end of recording: (\d+)'))
6+
first_when_end_result = int(last_match().group(1))
7+
# Check this value after running the program for a bit.
8+
49
send_custom_command('when')
510
expect_debugger(re.compile(r'Completed event: (\d+)'))
611
t = int(last_match().group(1))
@@ -43,6 +48,10 @@
4348
if tid2 != tid:
4449
failed('ERROR ... tid changed')
4550

51+
send_custom_command('when-end')
52+
expect_debugger(re.compile(r'Event at end of recording: (\d+)'))
53+
second_when_end_result = int(last_match().group(1))
54+
4655
# Ensure 'when' terminates a diversion
4756
expect_expression('(int)strlen("abcd")', 4)
4857
send_custom_command('when')
@@ -65,4 +74,22 @@
6574
if tid3 != tid2:
6675
failed('ERROR ... diversion changed tid')
6776

77+
stepi()
78+
79+
send_custom_command('when-end')
80+
expect_debugger(re.compile(r'Event at end of recording: (\d+)'))
81+
final_when_end_result = int(last_match().group(1))
82+
83+
if first_when_end_result != second_when_end_result:
84+
failed("ERROR ... first when-end result differs from second when-end result")
85+
if second_when_end_result != final_when_end_result:
86+
failed("ERROR ... second when-end result differs from final when-end result")
87+
88+
if t >= first_when_end_result:
89+
failed("ERROR ... First when result was after when-end")
90+
if t3 >= first_when_end_result:
91+
failed("ERROR ... Second when result was after when-end")
92+
if t3 >= first_when_end_result:
93+
failed("ERROR ... Third when result was after when-end")
94+
6895
ok()

0 commit comments

Comments
 (0)