Debugging a program through openOCD

Hello everyone,

I am trying to debug a C program following the steps mentioned in https://github.com/riscv/riscv-isa-sim .

Files used for debugging are
-> rot13.c
rot13

-> spike.lds
spike_lds

-> spike.cfg
spike_cfg

In first shell when I use
$spike --rbb-port=9824 -m0x10000000:0x20000 rot13-64
it is listening to remote bitbang connection on port 9824

In second shell when I use
$ openocd -f spike.cfg
I get something like


remote bitbang interface quit, which prevents me from debugging my program

My questions are

  1. what does Error: failed read (NOP) at 0x11, status=2 this error mean ?
  2. Do I need to make any changes in spike.cfg file?

Hmm… it’s working for me. The error indicates that OpenOCD tried to perform a DMI read, and it got failure as a result. I don’t think I’ve ever seen that when connecting to spike, where these things always succeed. Is spike still running after OpenOCD exits? Can you try again but run spike as openocd -d -f spike.cfg. This should result in a lot more debug output, and at least we can see exactly what OpenOCD is seeing.

Tim

1 Like

Thanks for your reply @tim

–>Yes spike is still running even after the OpenOCD exits.

–>when I run openocd -d -f spike.cfg I get this

–>The error is riscv-013.c:547 dmi_op_timeout(): failed read (NOP) at 0x11, status=2

  1. After running spike there is warning : tohost and fromhost symbols not in ELF ; can’t communicate with target . Is it the reason for that error? If that is the reason how do I add tohost and fromhost symbols ?
  2. I removed the existing toolchain, updated and rebuilt everything. The error remains same, do I need to enable something while running build.sh ? If so what are the options that should be enabled ?

Thank you
Chakri

Looking at the spike source, I have no idea how this can happen. What version of spike are you using? Do you have a git hash for the source it was built from?

Tim

I don’t know the version of spike I am using but, yesterday I cloned it from [git clone https://github.com/riscv/riscv-tools.git](git clone https://github.com/riscv/riscv-tools.git). Followed the steps mentioned in https://riscv.org/software-tools/ for building toolchain.
Do we have to enable any option before building the toolchain, so that debugger works fine ?

Chakri

That version should work. riscv-tools hasn’t been updated in a few months, and every time it does it automatically runs tests which include testing gdb->openocd->spike. (You can see the latest results here.)

I think it’s fair to say that you’re running into some problem unique to your system. The next troubleshooting step I’d take is to rebuild spike, enabling debug printfs in riscv/debug_module.cc by changing #if 0 on line 12 to #if 1, then rerun and see what output shows up.

@tim as you said, the problem is unique to my machine as I am using toolchain on older version of ubuntu. Later I installed toolchain on ubuntu 18.04 and now openOCD is working fine.

Thank you for your time and help…:smiley:

Chakri

2 Likes

hi, i also have an issue with spike compiling, hope it’s ok that i am asking for help as a reply
when I try to compile a simple c program, i get this error:

rotemshahar@asic2-serv3:~$ ./rocket-chip/riscv-tools/bin/riscv64-unknown-elf-gcc -g -Og -o hello-64.o -c hello.c
rotemshahar@asic2-serv3:~$ ./rocket-chip/riscv-tools/bin/riscv64-unknown-elf-gcc -g -Og -T spike.lds -nostartfiles -o hello-64 hello-64.o
/home/rotemshahar/rocket-chip/riscv-tools/lib/gcc/riscv64-unknown-elf/7.2.0/…/…/…/…/riscv64-unknown-elf/bin/ld: cannot open linker script file spike.lds: No such file or directory
collect2: error: ld returned 1 exit status

can any of you guys can help me figure out what am I doing wrong here?

thanks
Shahar

Hello @sharinoz

your error says that there is no linker script file.
follow the steps mentioned in the following link. you will get it.
https://github.com/riscv/riscv-isa-sim

Chakri

Hi @chakri
I followed the instructions in the link you sent before I tried to compile
I can try to remove it all and then download & install again, but I am not sure if it will help

Make one separate directory outside and then follow the steps provided in link given by @chakri. Your spike.lds should be in same directory where you are compiling.

@Ayush_12d what does it mean exactly? In which directory should I compile my file?

@chakri @Ayush_12d I don’t have a spike.lds file anywhere
where should it be? should i create it somewhere? i feel a little lost

@sharinoz you have to create spike.lds file. If you follow this link https://github.com/riscv/riscv-isa-sim spike.lds and spike.cfg files are given under cat command. so follow those steps, create rot13.c, spike.lds, spike.cfg files and execute the commands. It will work.

Chakri

thanks @chakri, it is working now
but there is this message:

rotemshahar@asic2-serv3:~/riscv-isa-sim$ spike --rbb-port=9824 -m0x10000000:0x20000 rot13-64
Listening for remote bitbang connection on port 9824.
warning: tohost and fromhost symbols not in ELF; can’t communicate with target
Received nothing. Quitting.

why am i getting this error?
if i follow the readme in the rocket-chip git (https://github.com/freechipsproject/rocket-chip#-debugging-with-gdb) I don’t get this message. on the other hand, i can’t debug because the load command on the GDB failes

do you understand why is this happening?

thanks
Shahar

@sharinoz even I got same message Received nothing. Quitting . I don’t know exact reason but I installed toolchain on ubuntu 18.04 and now I am able to debug my program through openOCD.

Chakri

hi @chakri
do you know where I can find the files of rot13.c, spike.lds and spike.cfg, do I need to use the command “vim rot13.c”, "vim spike.lds ", “vim spike.cfg”?
thank you :grinning: