Skip to content

Commit 7217770

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

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/DebuggerExtensionCommand.cc

Lines changed: 16 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,21 @@ 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+
auto task = static_cast<ReplayTask*>(t);
64+
auto seek_reader(task->session().as_replay()->trace_reader());
65+
FrameTime time;
66+
for (;;) {
67+
auto result = seek_reader.read_task_event(&time);
68+
if (result.type() == TraceTaskEvent::Type::NONE) {
69+
break;
70+
}
71+
}
72+
return string("Event at end of recording: ") + to_string(time);
73+
});
74+
5975
static std::vector<ReplayTimeline::Mark> back_stack;
6076
static ReplayTimeline::Mark current_history_cp;
6177
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)