0

我是尖峰和 RISC V 的新手。我正在尝试使用尖峰进行一些动态指令跟踪。这些说明来自 sample.c 文件。我尝试了以下命令:

$ riscv64-unknown-elf-gcc simple.c -g -o simple.out
$ riscv64-unknown-elf-objdump -d --line-numbers -S simple.out

但是这些命令在输出文件中显示汇编指令,这不是我想要的。我需要在运行时跟踪动态执行的指令。我在尖峰主机选项中只找到两个相关命令:

  • -g- 跟踪 PC 的直方图

  • -l- 生成执行日志

我不确定结果是否符合我的预期。有谁知道如何在尖峰中进行动态指令跟踪?非常感谢!

4

1 回答 1

0

Yes, you can call spike with -l to get a trace of all executed instructions.

Example:

$ spike -l --isa=RV64gc ~/riscv/pk/riscv64-unknown-elf/bin/pk ./hello 2> ins.log

Note that this trace also contains all instructions executed by the proxy-kernel - rather than just the trace of your user program.

The trace can still be useful, e.g. you can search for the start address of your code (i.e. look it up in the objdump output) and consume the trace from there.

Also, when your program invokes a syscall you see something like this in the trace:

[.. inside your program ..]
core   0: 0x0000000000010088 (0x00000073) ecall
core   0: exception trap_user_ecall, epc 0x0000000000010088
core   0: 0x0000000080001938 (0x14011173) csrrw   sp, sscratch, sp
[.. inside the pk ..]
sret
[.. inside your program ..]

That means you can skip the sycall instruction (that are executed in the pk) by searching for the next sret.

Alternatively, you can call spike with -d to enter debug mode. Then you can set a breakpoint on the first instruction of interest in your program (until pc 0 YOURADDRESS - look up the address in the objdump output) and single step from there (by hitting return multiple times). See also the help screen by entering h at the spike prompt.

于 2020-03-21T15:15:30.787 回答