Author Topic: How to debug with gdb and openocd?  (Read 2989 times)

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
How to debug with gdb and openocd?
« on: September 11, 2020, 05:46:49 PM »
Hi:

I'd like to debug a remote microcontroller with SlickEdit. I am currently able to do this debugging with eclipse and pure gdb, but not with SlickEdit. Looking for tips on how to do this.

I have a remote windows machine connected to a JTAG probe via USB, and the JTAG probe is connected to my target. On this windows machine, I run "openocd" which provides a gdb server.

Then on my host machine (linux), I am able to use pure gdb or eclipse to connect to this gdb server.

With gdb end eclipse, it connects to my remote server by first running the gdb command: "target extended-remote xx.yy.zz.aa:port"

After this I need to send a few "monitor" commands via gdb to get my target ready (reset related).

After the target is ready, then the executable is ready to be loaded via the gdb "load" command.

After the load is done, I would like to have a few more custom gdb commands executed to copy ram address 0 to the stack pointer, and set the vector table. After this I would like to start executing. Now this "after load" stuff can be optional, but it is nice to have. Eclipse does have a place in the debug configuration to insert these "after load" commands.

I tried to accomplish this by doing the following with SlickEdit:

1) Tools->Options->Debugging->Configurations
     Here I added my special gdb that is able to connect to my target and made it the default debugging configuration.
     For "Arguments" I gave it "-x gdbinit_file", where my "gdbinit_file" contains:

Code: [Select]
set verbose on
target extended-remote xxx.yyy.zzz.aaa:3336
monitor reset init
monitor halt

  2) I was hoping that SlickEdit would run this gdb which then does my gdbinit with the above, and then afterwards SlickEdit would run the "load" command to load the target, and then start executing it. As I said it would be nice if I could insert some gdb commands after the "load" before anything is done. Eclipse debug configs do give the opportunity to specify some gdb commands after the load.

So when I attempt to debug my build config to use gdb (Debug->Start), it didn't work and I got an error message: "Error continuing: GDB could not start application. Don't know how to run. Try "help target" ".

In the build tab it had:

Code: [Select]
vsdebugio -port 8001  -prog  my_program.axf=cmd-param-changed,param="verbose",value="on"
and in the Output tab it had:

Code: [Select]
Reading symbols from my_program.axf...
Reading in symbols for ../../my_program/src/main.c...
done.

I've seen some old messages on the forum about using openocd with slickedit, but I had trouble understanding them. There was mention of a "gdb proxy" but I don't know what this means.

SlickEdit offers options to "attach" to a remote target, but in this case I want to actually load my remote target from SE and start debugging it. My remote target is not running linux or anything you can ssh to, so not sure it applies.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: How to debug with gdb and openocd?
« Reply #1 on: September 11, 2020, 05:57:06 PM »
Got a little further because I made a silly error where my gdb server with openocd was not running. I suppose this openocd is the "gdb proxy". It is still failing, but I do see the connection to the gdb server is made. Trying to figure out what is going on.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: How to debug with gdb and openocd?
« Reply #2 on: September 11, 2020, 06:41:06 PM »
So now it seems to fail after my gdbinit is run. My gdbinit should leave the target in a "halted" state, but the SlickEdit Output tab, and my gdbserver (openocd) terminal are both showing that SE tried to resume when the processor wasn't halted. I also don't see my program loading in the gdb output. Here is what I see:

Code: [Select]
Enter ocd_process_reset_inner, mode=init
ocd_process_reset_inner: init processing
requesting target halt and executing a soft reset
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x6000052c msp: 0x00000cb8
Exit ocd_process_reset_inner
add5u.3: external reset detected
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x6000067c msp: 0x00000cb8
0x6000067c in ?? ()
Reading symbols from my_program.axf...
Reading in symbols for ../../my_program/src/main.c...
done.
target not halted
target add5u.3 was not halted when resume was requested


rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: How to debug with gdb and openocd?
« Reply #3 on: September 11, 2020, 06:53:24 PM »
Got past the "was not halted when resume was requested" by updating my openocd config file so that "reset halt" will halt the target.

But I still don't see where my program is getting loaded onto the target?

After fixing the above I get a new error in a window in SE:

Quote
Error continuous: GDB could not start the application
"Malformed response to offset query, 1

after clicking "OK" there I see in the Output tab:

Code: [Select]
Enter ocd_process_reset_inner, mode=init
ocd_process_reset_inner: init processing
requesting target halt and executing a soft reset
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x6000052c msp: 0x00000cb8
Exit ocd_process_reset_inner
add5u.3: external reset detected
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x60000680 msp: 0x00000cb8
0x6000067c in ?? ()
Reading symbols from my_program.axf...
Reading in symbols for ../../my_program/src/main.c...
done.
Ignoring packet error, continuing...

And in my gdbserver terminal I see:

Code: [Select]
Error: No symbols for FreeRTOS
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x6000067c msp: 0x00000cb8
Info : New GDB Connection: 1, Target add5u.3, state: halted
Enter ocd_process_reset_inner, mode=init
ocd_process_reset_inner: init processing
requesting target halt and executing a soft reset
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x6000052c msp: 0x00000cb8
Exit ocd_process_reset_inner
Info : add5u.3: external reset detected
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x60000680 msp: 0x00000cb8
Enter ocd_process_reset_inner, mode=halt
ocd_process_reset_inner: init processing
requesting target halt and executing a soft reset
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x6000052c msp: 0x00000cb8
halting due to halt mode
Info : add5u.3: external reset detected
Info : Halt timed out, wake up GDB.
Error: timed out while waiting for target halted
in procedure 'ocd_gdb_restart'
Warn : negative acknowledgment, but no packet pending
Warn : negative acknowledgment, but no packet pending
Warn : negative acknowledgment, but no packet pending

The "Enter/exit ocd_process_reset_inner" are prints I make from the config file. They happen when gdbserver gets the "reset" command. The first one with mode "init" is from my gdbinit file. The 2nd one with mode="halt" seems to be issued by SlickEdit.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: How to debug with gdb and openocd?
« Reply #4 on: September 11, 2020, 07:18:03 PM »
And now I have it working.

Looks like I needed to put the "load my_program.axf" into my gdbinit file.

I also modified by "reset halt" function on gdbserver side to do all the "post loading" things that I desired to have done after the load, without doing an "actual reset".

It might be nice if I could tell SE to do that load command with the same executable I specified for the debug.

My gdbinit now looks like:

Code: [Select]
set verbose on
target extended-remote www.xxx.yyy.zzz:3336
monitor reset init
monitor halt
load my_program.axf

Not sure if this is the best way to accomplish this, I'm open to feedback, but it does seem to work.