Skip to content

Commit 7500267

Browse files
committed
Add "when-end" command to get the number of the last event
1 parent fb97ee8 commit 7500267

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/DebuggerExtensionCommand.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "DebuggerExtensionCommand.h"
44

55
#include "ReplayTask.h"
6+
#include "TraceFrame.h"
67
#include "log.h"
78

89
using namespace std;
@@ -56,6 +57,25 @@ static SimpleDebuggerExtensionCommand when_tid(
5657
return string("Current tid: ") + to_string(t->tid);
5758
});
5859

60+
static SimpleDebuggerExtensionCommand when_end(
61+
"when-end", "Print the number of the last rr event in the recording.",
62+
[](GdbServer&, Task* t, const vector<string>&) {
63+
if (!t->session().is_replaying()) {
64+
return DebuggerExtensionCommandHandler::cmd_end_diversion();
65+
}
66+
67+
auto task = static_cast<ReplayTask*>(t);
68+
auto seek_reader(task->session().as_replay()->trace_reader());
69+
FrameTime time;
70+
for (;;) {
71+
auto result = seek_reader.read_task_event(&time);
72+
if (result.type() == TraceTaskEvent::Type::NONE) {
73+
break;
74+
}
75+
}
76+
return string("Event at end of recording: ") + to_string(time);
77+
});
78+
5979
static std::vector<ReplayTimeline::Mark> back_stack;
6080
static ReplayTimeline::Mark current_history_cp;
6181
static std::vector<ReplayTimeline::Mark> forward_stack;

src/test/when.py

Lines changed: 26 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,21 @@
6574
if tid3 != tid2:
6675
failed('ERROR ... diversion changed tid')
6776

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

0 commit comments

Comments
 (0)