Gdb-port does not work in spike

After building risv-tools, tried

spike --gdb-port 9999 pk hello

the spike is supposed to be hanging there and waiting for gdb connection. But it runs through the whole program without stop, so that there is no way for gdb to connect with spike.

Does anyone know what is going on?

Thanks

If you want spike to hang right at the start, you need to add -H to your command line before pk. Eg:
spike --gdb-port 9999 -H pk hello

Tim

PS
Note that debugging the kernel things get pretty wonky as memory maps are set up etc. If you just want to debug a hello world program, I recommend adding:

volatile int i = 1;
while (1)
   ;

to the start of your program and running spike without -H. Then once you’ve attached, set i to 0 to start execution.

Tim

Thanks

After using -H, gdb can connect to spike. But the gdb commands can not be taken

(gdb) target remote localhost:9999
Remote debugging using localhost:9999
0x00001000 in ?? ()
(gdb) l
1 #include <stdio.h>
2
3 volatile int flag = 1;
4
5 int main()
6 {
7 int i=0;
8
9 while(flag) ;
10
(gdb) b 5
Breakpoint 1 at 0x10174: file hello.c, line 5.
(gdb) r
The “remote” target does not support “run”. Try “help target” or “continue”.
(gdb) step
Cannot find bounds of current function
(gdb)

Those commands look reasonable to me. Did you try ‘continue’? Or ‘stepi’?

stepi is working.

cont makes gdb hanging there without any progress

(gdb) target remote localhost:9999
Remote debugging using localhost:9999
0x00001000 in ?? ()
(gdb) l
1 #include <stdio.h>
2
3 volatile int flag = 1;
4
5 int main()
6 {
7 int i=0;
8
9 while(flag) ;
10
(gdb) b 5
Breakpoint 1 at 0x10174: file hello.c, line 5.
(gdb) r
The “remote” target does not support “run”. Try “help target” or “continue”.
(gdb) step
Cannot find bounds of current function
(gdb) stepi
0x00001004 in ?? ()
(gdb) stepi
0x80000000 in ?? ()
(gdb) cont
Continuing.

Your breakpoint was set at 0x10174, but you’re continuing from 0x80000000, so probably you are never hitting your breakpoint. What if you try b main ?

set “b main”

after cont, gdb is still hanging

(gdb) target remote localhost:9999
Remote debugging using localhost:9999
0x00001000 in ?? ()
(gdb) b main
Breakpoint 1 at 0x10174: file hello.c, line 7.
(gdb) l
1 #include <stdio.h>
2
3 volatile int flag = 1;
4
5 int main()
6 {
7 int i=0;
8
9 while(flag) ;
10
(gdb) cont
Continuing.

It is weird. The breakpoint never works.

After Ctrl-C, it stops at the while loop.

(gdb) target remote localhost:9999
Remote debugging using localhost:9999
0x00001000 in ?? ()
(gdb) b main
Breakpoint 1 at 0x121b0: file hello.c, line 7.
(gdb) l
1 #include <stdio.h>
2
3 volatile int flag = 1;
4
5 int main()
6 {
7 int i=0;
8
9 i=1;
10
(gdb) b 9
Breakpoint 2 at 0x121b4: file hello.c, line 9.
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x000121c0 in main () at hello.c:11
11 while(flag) ;

In addition, the local variable cannot be visited also. Global variable can be printed.

(gdb) target remote localhost:9999
Remote debugging using localhost:9999
0x00001000 in ?? ()
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x000121c0 in main () at hello.c:11
11 while(flag) ;
(gdb) p flag
$1 = 1
(gdb) p i
Cannot access memory at address 0x7ffffd8c
(gdb) l
6 {
7 int i=0;
8
9 i=1;
10
11 while(flag) ;
12
13 for(i=0; i<10; i++) ;
14 printf(“Hello world! %d\n”, i);
15

Just look into this

1 Like