简体   繁体   English

如何在尖峰中跟踪动态指令(在 RISC-V 上)

[英]How to trace dynamic instruction in spike (on RISC-V)

I'm new for spike and RISC V. I'm trying to do some dynamic instruction trace with spike.我是尖峰和 RISC V 的新手。我正在尝试使用尖峰进行一些动态指令跟踪。 These instructions are from a sample.c file.这些说明来自 sample.c 文件。 I have tried the following commands:我尝试了以下命令:

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

But these commands display the assembled instructions in an out file, which is not I want.但是这些命令在输出文件中显示汇编指令,这不是我想要的。 I need to trace the dynamic executed instruction in runtime.我需要在运行时跟踪动态执行的指令。 I find only two relative commands in spike host option:我在尖峰主机选项中只找到两个相关命令:

  • -g - track histogram of PCs -g - 跟踪 PC 的直方图

  • -l - generate a log of execution -l - 生成执行日志

I'm not sure if the result is what I expected as above.我不确定结果是否符合我的预期。 Does anyone have an idea how to do the dynamic instruction trace in spike?有谁知道如何在尖峰中进行动态指令跟踪? Thanks a lot!非常感谢!

Yes, you can call spike with -l to get a trace of all executed instructions.是的,您可以使用-l调用尖峰来跟踪所有已执行的指令。

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, eg you can search for the start address of your code (ie look it up in the objdump output) and consume the trace from there.跟踪仍然有用,例如,您可以搜索代码的起始地址(即在 objdump 输出中查找)并从那里使用跟踪。

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 to the sycall instruction (that are executed in the pk) by searching for the next sret.这意味着您可以通过搜索下一个 sret 来跳到 sycall 指令(在 pk 中执行)。

Alternatively, you can call spike with -d to enter debug mode.或者,您可以调用带有-d的尖峰以进入调试模式。 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).然后,您可以在程序中感兴趣的第一条指令上设置断点( until pc 0 YOURADDRESS - 在 objdump 输出中查找地址)并从那里单步执行(通过多次返回)。 See also the help screen by entering h at the spike prompt.在尖峰提示符下输入h也可查看帮助屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM