Learn with SHAKTI
Debugging a ASM Program with spike
Interactive Debugging Mode
Let us debug example.elf present inside spiking folder.
cd $HOME
cd spiking
make command is used to generate the executables for all the C and Assembly Programs hosted inside the spiking folder,
make
To invoke interactive debug mode, launch spike with -d:
$(which spike) -d $(which pk) example.elf
Note : Press Enter key, to advance by one instruction.
Commands
To see the contents of an integer register (0 is for core 0):
: reg 0 a0
To see the contents of a floating point register as Single precision:
: fregs 0 ft0
To see the contents of a floating point register as Double precision:
: fregd 0 ft0
To see the contents of a memory location (physical address in hex):
: mem 2020
To see the contents of memory with a virtual address (0 for core 0):
: mem 0 2020
You can execute till the desired instruction using the UNTIL command:
: until pc 0 10010004
Note: Use objdump to find the address of the required instruction
Debugging
: mem 1000 0x0202859300000297 : core 0: 0x0000000000001000 (0x00000297) auipc t0, 0x0 : core 0: 0x0000000000001004 (0x02028593) addi a1, t0, 32 : until pc 0 10010004 : core 0: 0x0000000010010004 (0x40105613) srai a2, zero, 1 : core 0: 0x0000000010010008 (0x40105513) srai a0, zero, 1 : core 0: 0x000000001001000c (0x40105793) srai a5, zero, 1 : core 0: 0x0000000010010010 (0x40105313) srai t1, zero, 1 : core 0: 0x0000000010010014 (0x00000505) c.addi a0, 1 : core 0: 0x0000000010010016 (0x00d50613) addi a2, a0, 13 : core 0: 0x000000001001001a (0x04050893) addi a7, a0, 64 : core 0: 0x000000001001001e (0x00000797) auipc a5, 0x0 : reg 0 a0 0x0000000000000001 : reg 0 a2 0x000000000000000e : reg 0 a7 0x0000000000000041 : fregs 0 ft0 0x0000000000000000
At any point during execution (even without -d), you can enter the interactive debug mode with <control>-<c>.
To end the simulation from the debug prompt, press <control>-<c> or
: q