How to use riscv-unknown-elf-gdb ?

2,386 views
Skip to first unread message

x100...@gmail.com

unread,
Sep 2, 2016, 11:38:42 PM9/2/16
to sw-dev
Hi, 
I followed the instructions on https://github.com/riscv/riscv-isa-sim and ran by step:
$ riscv64-unknown-elf-gcc test.c
$ spike --gdb-port 9824 pk a.out

$ riscv64-unknown-elf-gdb a.out
    (gdb) target remote localhost:9824

but it seems not to work and shows "conection timed out".
Could  anybody tell me how to ues it ?

Many thanks !


Tim Newsome

unread,
Sep 3, 2016, 12:18:01 AM9/3/16
to x100...@gmail.com, sw-dev
Earlier today there was a bug in spike that broke debugging. I fixed it in https://github.com/riscv/riscv-isa-sim/commit/10d1bff0a1612685d08906a33b7eb87223f9d1c3

Do you have that change?

Tim

--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/2016090311384005051596%40gmail.com.

x100...@gmail.com

unread,
Sep 3, 2016, 1:10:42 AM9/3/16
to Tim Newsome, sorear2, sw-dev
I just pulled the newest version of riscv-isa-sim and ran the commonds again, but got the same error.

riscv-isa-sim commit: 3032e25
riscv-gnu-toolchain commit: 37fa673
And no riscv-qemu installed.


Tim Newsome

unread,
Sep 3, 2016, 2:46:20 PM9/3/16
to x100...@gmail.com, sorear2, sw-dev
On Fri, Sep 2, 2016 at 10:10 PM, x100...@gmail.com <x100...@gmail.com> wrote:
I just pulled the newest version of riscv-isa-sim and ran the commonds again, but got the same error.

riscv-isa-sim commit: 3032e25
riscv-gnu-toolchain commit: 37fa673

It's working for me with those exact commits. Did you remember to 'make install' spike after rebuilding it?
If not, can you run the same spike command but with -l added as an argument so it spits out what it executes, and then connect with gdb? The output will be large. If you can compress it and e-mail it, or stick it somewhere I can take a look at it then I will see if that points to anything.

Tim
 
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.

x100...@gmail.com

unread,
Sep 3, 2016, 9:44:24 PM9/3/16
to Tim Newsome, sorear2, sw-dev
I did make install.
The attachment is what spike spits out.
spike_gdb.rar

Tim Newsome

unread,
Sep 4, 2016, 3:59:44 PM9/4/16
to x100...@gmail.com, sorear2, sw-dev
Looking at your original e-mail again, is spike simply exiting and then you invoke gdb?
There is nothing in your original command line that causes spike to wait for gdb to connect. (If you want that, use -H.)

Tim

x100...@gmail.com

unread,
Sep 4, 2016, 9:55:57 PM9/4/16
to Tim Newsome, sorear2, sw-dev
Oh, I forgot the "-H" parameter !
Now, gdb connection is sucessful but when I input some commands, it seems out of order just as follows:

<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...done.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x0000000000001000 in ?? ()
(gdb) p i
No symbol "i" in current context.
(gdb) list 
1 /*
2  * Copyright (c) 1990 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7
8 /*
9 FUNCTION
10 <<atexit>>---request execution of functions at program exit
(gdb) b printf
Function "printf" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n


My test code is simple:
  1 #include <stdio.h>
  2 int main(int argc, const char *argv[])
  3 {
  4 
  5     int i=42;
  6     while (i) {
  7         /* code */
  8         //i-=6;
  9     }
 10     i=0;
 11     printf("hello!\n");
 12     return 0;
 13 }


I don't know what's wrong .

Tim Newsome

unread,
Sep 5, 2016, 12:04:23 PM9/5/16
to x100...@gmail.com, sorear2, sw-dev
This is expected behavior. When you use -H, then spike doesn't execute any instructions at all. That means when you connect with gdb, none of pk has executed either, which means your program hasn't been started in the simulation.

If you need system calls (eg. printf) you have 2 options:
1. Let pk run until it has started your program. There must be a place you can set a breakpoint (or maybe a sequence of breakpoints) to make that happen. I don't know enough about pk to have done this.
2. To the beginning of your main() function add:
volatile int wait=1;
while (wait) {}
Then you can let spike run without -H and it'll loop forever. While in the loop you can attach with gdb and it'll show you you're in that loop, and you can "p wait=0" to get out of the loop.

If you don't need system calls, then you can start spike with "-H pk" and without your binary name either, since you'll never let spike run. Once attached with gdb you can execute "load" and gdb will download your program into spike. Then you can set a breakpoint at main and run to it.

Tim
Reply all
Reply to author
Forward
0 new messages