Skip to content

Commit 8bbb72c

Browse files
committed
"when-end" command that gives the last event number of the recording
1 parent 39e5c18 commit 8bbb72c

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎src/DebuggerExtensionCommand.cc‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ReplayTask.h"
66
#include "TraceFrame.h"
77
#include "log.h"
8+
#include "util.h"
89

910
using namespace std;
1011

@@ -68,6 +69,32 @@ static SimpleDebuggerExtensionCommand when_tid(
6869
return string("Current tid: ") + to_string(t->tid);
6970
});
7071

72+
static SimpleDebuggerExtensionCommand info_recording(
73+
"info recording",
74+
"Print the path of the recording RR is"
75+
" currently replaying.",
76+
[](GdbServer&, Task* t, const vector<string>&) {
77+
auto task = static_cast<ReplayTask*>(t);
78+
auto trace_dir = task->session().as_replay()->trace_reader().dir();
79+
80+
return string("Path of recording: \"") + json_escape(trace_dir) + string("\"");
81+
});
82+
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+
7198
static std::vector<ReplayTimeline::Mark> back_stack;
7299
static ReplayTimeline::Mark current_history_cp;
73100
static std::vector<ReplayTimeline::Mark> forward_stack;

‎src/test/info_recording.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from util import *
2+
3+
import re
4+
import json
5+
6+
send_gdb('info recording')
7+
expect_gdb(re.compile(r'(?<=Path of recording: ).*'))
8+
path_jsonstr = last_match().group(0)
9+
path_pystr = json.loads(path_jsonstr)
10+
11+
if len(path_pystr) < 6:
12+
failed("ERROR ... Unreasonably short path for recording file found in output")
13+
14+
# Inferior command also has the name of the binary at the end,
15+
# so the pattern matches opening but not closing paren.
16+
send_gdb("inferior")
17+
expect_gdb(f"\\({path_pystr}")
18+
19+
ok()

‎src/test/info_recording.run‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source `dirname $0`/util.sh
2+
record simple$bitness
3+
debug info_recording

‎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)