Get trace of executed Instructions

163 views
Skip to first unread message

Vindhya Ejanthkar

unread,
Feb 29, 2024, 7:37:29 AM2/29/24
to RISC-V SW Dev

Please provide various methods to generate a trace of executed instructions for C code using the Spike simulator.

I have created a simple "Hello World" C file and generated hello.elf and then tried running this command : /home/vindhya/riscv-vector/riscv-isa-sim/build/spike -l /home/latitude-7390/rvv64/bin/riscv64-unknown-elf/bin/pk hello.elf

The output obtained after running the "Hello World" C program on a RISC-V architecture seems unusual. Instead of the expected simple output, the program execution shows a repetitive sequence of RISC-V instructions involving memory loading and branching.

So, suggest me where could have gone wrong and how to fix the error.

Tommy Murphy

unread,
Feb 29, 2024, 8:54:12 AM2/29/24
to Vindhya Ejanthkar, RISC-V SW Dev
> Instead of the expected simple output,

What exactly do you mean by "simple output"?

the program execution shows a repetitive sequence of RISC-V instructions involving memory loading and branching.

Remember that the startup code before `main()` is called has to do certain work such as setting up the stack, zeroising BSS memory, copying static initialised data to memory etc. Maybe that's what you're seeing at the start of the execution trace log before your program proper starts executing?

Can you provide the log and clarify what you think is unusual?

As far as I know `-l` is the only way to log execution in Spike.

Vindhya Ejanthkar

unread,
Feb 29, 2024, 11:03:39 PM2/29/24
to RISC-V SW Dev, tommy_...@hotmail.com, Vindhya Ejanthkar

By "simple output," I mean a concise and clear display of the instructions that were executed during the program's runtime.

Please find the attached output file for a clear understanding of the issue.
output.txt

Tommy Murphy

unread,
Mar 1, 2024, 2:24:02 AM3/1/24
to Vindhya Ejanthkar, RISC-V SW Dev, Vindhya Ejanthkar
> By "simple output," I mean a concise and clear display of the instructions that were executed during the program's runtime.

That's what you're getting in that log as far as I can see.
But for ALL of the code executed as part of the program including, for example, the startup code.

Vindhya Ejanthkar

unread,
Mar 1, 2024, 2:39:34 AM3/1/24
to Tommy Murphy, RISC-V SW Dev
But the output file has "329358 line" which seems unusual for a "Hello World" program 

Tommy Murphy

unread,
Mar 1, 2024, 2:44:40 AM3/1/24
to Vindhya Ejanthkar, RISC-V SW Dev
> But the output file has "329358 line" which seems unusual for a "Hello World" program 

Not necessarily.
As I said it will log ALL instructions executed as part of the execution of the program. Including startup code before `main()` is even called and that startup code can (and seemingly does in this case) involve the execution of many individual instructions in order to do basic C runtime setup and other initialisation.

Vindhya Ejanthkar

unread,
Mar 4, 2024, 7:56:41 AM3/4/24
to RISC-V SW Dev, tommy_...@hotmail.com, RISC-V SW Dev, Vindhya Ejanthkar
Can we restrict this runtime setup to only once and get only the trace of instructions later on for other programs?

Tommy Murphy

unread,
Mar 4, 2024, 8:09:08 AM3/4/24
to Vindhya Ejanthkar, RISC-V SW Dev, RISC-V SW Dev, Vindhya Ejanthkar
I don't see any options for doing that.
You could probably hack the Spike code to restrict logging/tracing to the non-startup code region of your program.
Or, better still, contribute a PR that provides options for more fine-grained control of the logging - e.g. only log instruction execution in a specified memory region(s).
Might be worth raising/discussing the issue on the Spike GitHub via the Issues or Discussions (if enabled) sections.

Vindhya Ejanthkar

unread,
Mar 4, 2024, 8:12:21 AM3/4/24
to Tommy Murphy, RISC-V SW Dev
Thanks, I'll look into it. 
Reply all
Reply to author
Forward
0 new messages