Skip to content

Commit 7816f1f

Browse files
committed
trace: improve a bit, fix bugs
1 parent b57cf38 commit 7816f1f

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

README.adoc

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8203,18 +8203,29 @@ The most interesting are events which show instructions that QEMU ran, for which
82038203

82048204
Under the hood, this uses QEMU's `-trace` option.
82058205

8206-
You can then inspect the instructions with:
8206+
You can then inspect the address of each instruction run:
82078207

82088208
....
82098209
less "$(./getvar --arch x86_64 run_dir)/trace.txt"
82108210
....
82118211

8212+
Sample output excerpt:
8213+
8214+
....
8215+
exec_tb 0.000 pid=10692 tb=0x7fb4f8000040 pc=0xfffffff0
8216+
exec_tb 35.391 pid=10692 tb=0x7fb4f8000180 pc=0xfe05b
8217+
exec_tb 21.047 pid=10692 tb=0x7fb4f8000340 pc=0xfe066
8218+
exec_tb 12.197 pid=10692 tb=0x7fb4f8000480 pc=0xfe06a
8219+
....
8220+
82128221
Get the list of available trace events:
82138222

82148223
....
82158224
./run --trace help
82168225
....
82178226

8227+
TODO: any way to show the actualy disassembled instruction executed directly from there? Possible with <<qemu-d-tracing>>.
8228+
82188229
Enable other specific trace events:
82198230

82208231
....
@@ -8276,7 +8287,25 @@ IN:
82768287

82778288
TODO: after `IN:`, symbol names are meant to show, which is awesome, but I don't get any. I do see them however when running a bare metal example from: https://github.com/cirosantilli/newlib-examples/tree/900a9725947b1f375323c7da54f69e8049158881
82788289

8279-
TODO: what is the point of having two mechanisms, `-trace` and `-d`? `-d` tracing is cool because it does not require a messy recompile, and it can also show symbols.
8290+
TODO: what is the point of having two mechanisms, `-trace` and `-d`? `-d` tracing is cool because it does not require a messy recompile, and it can also show symbols.
8291+
8292+
==== QEMU trace register values
8293+
8294+
TODO: is it possible to show the register values for each instruction?
8295+
8296+
This would include the memory values read into the registers.
8297+
8298+
Asked at: https://superuser.com/questions/1377764/how-to-trace-the-register-values-of-executed-instructions-in-qemu
8299+
8300+
Seems impossible due to optimizations that QEMU does:
8301+
8302+
* https://lists.gnu.org/archive/html/qemu-devel/2015-06/msg07479.html
8303+
* https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg02856.html
8304+
* https://lists.gnu.org/archive/html/qemu-devel/2012-08/msg03057.html
8305+
8306+
PANDA can list memory addresses, so I bet it can also decode the instructions: https://github.com/panda-re/panda/blob/883c85fa35f35e84a323ed3d464ff40030f06bd6/panda/docs/LINE_Censorship.md I wonder why they don't just upstream those things to QEMU's tracing: https://github.com/panda-re/panda/issues/290
8307+
8308+
gem5 can do it: <<gem5-tracing>>.
82808309

82818310
==== Trace source lines
82828311

@@ -8422,18 +8451,6 @@ TODO: is there any way to distinguish which instruction runs on each core? Doing
84228451

84238452
just appears to output both cores intertwined without any clear differentiation.
84248453

8425-
==== QEMU trace decode instructions
8426-
8427-
TODO: is is possible to show which instructions ran at each point in time, in addition to the address of the instruction with `exec_tb` shows? Hopefully dissembled, not just the instruction memory.
8428-
8429-
PANDA can list memory addresses, so I bet it can also decode the instructions: https://github.com/panda-re/panda/blob/883c85fa35f35e84a323ed3d464ff40030f06bd6/panda/docs/LINE_Censorship.md I wonder why they don't just upstream those things to QEMU's tracing: https://github.com/panda-re/panda/issues/290
8430-
8431-
Memory access on vanilla seem impossible due to optimizations that QEMU does:
8432-
8433-
* https://lists.gnu.org/archive/html/qemu-devel/2015-06/msg07479.html
8434-
* https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg02856.html
8435-
* https://lists.gnu.org/archive/html/qemu-devel/2012-08/msg03057.html
8436-
84378454
==== gem5 tracing
84388455

84398456
gem5 unlike QEMU is deterministic by default without needing to replay traces
@@ -10555,6 +10572,8 @@ Don't believe me? Then try:
1055510572

1055610573
and watch it hang forever.
1055710574

10575+
When GDB step debugging, switch between cores with the usual `thread` commands, see also: <<gdb-step-debug-multicore-userland>>.
10576+
1055810577
Bibliography:
1055910578

1056010579
* https://stackoverflow.com/questions/20055754/arm-start-wakeup-bringup-the-other-cpu-cores-aps-and-pass-execution-start-addre

common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def setup(parser):
794794
common.gem5_run_dir = os.path.join(common.run_dir_base, 'gem5', args.arch, str(args.run_id))
795795
common.m5out_dir = os.path.join(common.gem5_run_dir, 'm5out')
796796
common.stats_file = os.path.join(common.m5out_dir, 'stats.txt')
797-
common.trace_txt_file = os.path.join(common.m5out_dir, 'trace.txt')
797+
common.gem5_trace_txt_file = os.path.join(common.m5out_dir, 'trace.txt')
798798
common.gem5_guest_terminal_file = os.path.join(common.m5out_dir, 'system.terminal')
799799
common.gem5_readfile = os.path.join(common.gem5_run_dir, 'readfile')
800800
common.gem5_termout_file = os.path.join(common.gem5_run_dir, 'termout.txt')
@@ -841,11 +841,13 @@ def setup(parser):
841841
common.run_dir = common.gem5_run_dir
842842
common.termout_file = common.gem5_termout_file
843843
common.guest_terminal_file = gem5_guest_terminal_file
844+
common.trace_txt_file = gem5_trace_txt_file
844845
else:
845846
common.executable = common.qemu_executable
846847
common.run_dir = common.qemu_run_dir
847848
common.termout_file = common.qemu_termout_file
848849
common.guest_terminal_file = qemu_guest_terminal_file
850+
common.trace_txt_file = qemu_trace_txt_file
849851
common.gem5_config_dir = os.path.join(common.gem5_src_dir, 'configs')
850852
common.gem5_se_file = os.path.join(common.gem5_config_dir, 'example', 'se.py')
851853
common.gem5_fs_file = os.path.join(common.gem5_config_dir, 'example', 'fs.py')

trace-boot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if common.emulator == 'gem5':
3131
run.main(args, extra_args)
3232
else:
3333
extra_args.update({
34-
'kernel_cli_extra': 'init=/poweroff.out',
34+
'kernel_cli': 'init=/poweroff.out',
3535
'trace': 'exec_tb',
3636
})
3737
run.main(args, extra_args)

0 commit comments

Comments
 (0)