Debugging a program through openOCD


(chakravarthi) #1

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?

(Tim Newsome) #2

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


(chakravarthi) #3

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


(Tim Newsome) #4

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


(chakravarthi) #5

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


(Tim Newsome) #6

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.


(chakravarthi) #7

@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


#8

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


(chakravarthi) #9

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


#10

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


(Ayush Srivastava) #11

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.


#12

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


#13

@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


(chakravarthi) #14

@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


#15

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


(chakravarthi) #16

@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