Skip to content

Commit 2a16ddc

Browse files
committed
run: trace to stdout
1 parent 2e9ffca commit 2a16ddc

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

README.adoc

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8351,7 +8351,7 @@ TODO do even more awesome offline post-mortem analysis things, such as:
83518351

83528352
==== QEMU record and replay
83538353

8354-
QEMU runs are not deterministic by default, however it does support a record and replay mechanism that allows you to replay a previous run deterministically:
8354+
QEMU runs, unlike gem5, are not deterministic by default, however it does support a record and replay mechanism that allows you to replay a previous run deterministically.
83558355

83568356
This awesome feature allows you to examine a single run as many times as you would like until you understand everything:
83578357

@@ -8410,8 +8410,8 @@ TODO `arm` and `aarch64` only seem to work with initrd since I cannot plug a wor
84108410
Then, when I tried with <<initrd>> and no disk:
84118411

84128412
....
8413-
./build-buildroot --arch aarch64 -i
8414-
./qemu-rr --arch aarch64 --eval-after '/rand_check.out;/poweroff.out;' -i
8413+
./build-buildroot --arch aarch64 --initrd
8414+
./qemu-rr --arch aarch64 --eval-after '/rand_check.out;/poweroff.out;' --initrd
84158415
....
84168416

84178417
QEMU crashes with:
@@ -8466,15 +8466,21 @@ just appears to output both cores intertwined without any clear differentiation.
84668466

84678467
==== gem5 tracing
84688468

8469-
gem5 unlike QEMU is deterministic by default without needing to replay traces
8470-
8471-
But it also provides a tracing mechanism documented at: link:http://www.gem5.org/Trace_Based_Debugging[] to allow easily inspecting certain aspects of the system:
8469+
gem5 provides also provides a tracing mechanism documented at: link:http://www.gem5.org/Trace_Based_Debugging[]:
84728470

84738471
....
84748472
./run --arch aarch64 --eval 'm5 exit' --gem5 --trace Exec
84758473
less "$(./getvar --arch aarch64 run_dir)/trace.txt"
84768474
....
84778475

8476+
Output the trace to stdout instead of a file:
8477+
8478+
....
8479+
./run --arch aarch64 --eval 'm5 exit' --gem5 --trace Exec --trace-stdout
8480+
....
8481+
8482+
This would produce a lot of output however, so you will likely not want that when tracing a Linux kernel boot instructions. But it can be very convenient for smaller traces.
8483+
84788484
List all available debug flags:
84798485

84808486
....
@@ -8488,6 +8494,8 @@ less "$(./getvar gem5_src_dir)/src/cpu/SConscript"
84888494
less "$(./getvar gem5_src_dir)/src/cpu/exetrace.cc"
84898495
....
84908496

8497+
The traces are generated from `DPRINTF(<trace-id>` calls scattered throughout the code.
8498+
84918499
As can be seen on the `Sconstruct`, `Exec` is just an alias that enables a set of flags.
84928500

84938501
Be warned, the trace is humongous, at 16Gb.
@@ -11779,6 +11787,11 @@ We have some link:https://github.com/pexpect/pexpect[pexpect] automated tests fo
1177911787
./test-gdb
1178011788
....
1178111789

11790+
Sources:
11791+
11792+
* link:build-test-gdb[]
11793+
* link:test-gdb[]
11794+
1178211795
Not all of them are passing right now due to: <<gem5-gdb-step-debug-kernel-aarch64>>.
1178311796

1178411797
If something goes wrong, re-run the test commands manually and use `--verbose` to understand what happened:
@@ -11794,10 +11807,19 @@ and possibly repeat the GDB steps manually with the usual:
1179411807
./run-gdb --arch arm --baremetal add --no-continue --verbose
1179511808
....
1179611809

11797-
Sources:
11810+
To debug GDB problems on gem5, you might want to enable the following <<gem5-tracing,tracing>> options:
1179811811

11799-
* link:build-test-gdb[]
11800-
* link:test-gdb[]
11812+
....
11813+
./run \
11814+
--arch arm \
11815+
--baremetal add \
11816+
--wait-gdb \
11817+
--trace GDBRecv,GDBSend \
11818+
--trace-stdout \
11819+
;
11820+
....
11821+
11822+
====== Test GDB Linux kernel
1180111823

1180211824
For the Linux kernel, do the following manual tests for now.
1180311825

run

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ defaults = {
3535
'terminal': False,
3636
'tmux': None,
3737
'trace': None,
38+
'trace_stdout': False,
3839
'userland': None,
3940
'userland_before': '',
4041
'vnc': False,
@@ -151,10 +152,14 @@ def main(args, extra_args=None):
151152
extra_env['M5_PATH'] = common.gem5_system_dir
152153
# https://stackoverflow.com/questions/52312070/how-to-modify-a-file-under-src-python-and-run-it-without-rebuilding-in-gem5/52312071#52312071
153154
extra_env['M5_OVERRIDE_PY_SOURCE'] = 'true'
155+
if args.trace_stdout:
156+
debug_file = 'cout'
157+
else:
158+
debug_file = 'trace.txt'
154159
cmd.extend(
155160
[
156161
common.executable, common.Newline,
157-
'--debug-file=trace.txt', common.Newline,
162+
'--debug-file', debug_file, common.Newline,
158163
'--listener-mode', 'on', common.Newline,
159164
'--outdir', common.m5out_dir, common.Newline,
160165
] +
@@ -553,6 +558,12 @@ disabled, while QEMU tracing is enabled but uses default traces that are very
553558
rare and don't affect performance, because `./configure
554559
--enable-trace-backends=simple` seems to enable some traces by default, e.g.
555560
`pr_manager_run`, and I don't know how to get rid of them.
561+
'''
562+
)
563+
parser.add_argument(
564+
'--trace-stdout', default=defaults['trace_stdout'], action='store_true',
565+
help='''\
566+
Output trace to stdout instead of a file. Only works for gem5 currently.
556567
'''
557568
)
558569
init_group.add_argument(

0 commit comments

Comments
 (0)