Starting Ddd with Remote Gdbserver

Starting ddd with remote gdbserver

Choose one of:

  1. ddd --eval-command="target remote localhost:1234"
  2. put target remote localhost:1234 into a file and use --command
    to execute it
  3. put target remote localhost:1234 into your .gdbinit

Remote debugging using gnu DDD

Use gdbserver on the target (remote) machine as explained there.
Then follow the config steps for gdb remote debugging (look up the gdb doc), typing the commands in the ddd console window (it's a pass through to the gdb prompt).

This could be something like this (if your link to the target were an USB to serial link, for instance):

(gdb) set remotebaud 115200
(gdb) target remote /dev/ttyUSB0

or

(gdb) target remote the-target:2345

to debug the gdbserver on IP the-target,using TCP port 2345.

GDB remote debugging: make GDB wait for gdbserver to be started

You can do this with a bit of python code. gdb.execute("command ...") will raise a python exception if the command gets an error. So we can have python run the target remote host:port command repeatedly, for as long as it gets a timeout error (which should resemble host:port: Connection timed out.).

Put the following into a file and use gdb's source command to read it in. It will define a new subcommand target waitremote host:port .

define target waitremote
python connectwithwait("$arg0")
end

document target waitremote
Use a remote gdbserver, waiting until it's connected.
end

python
def connectwithwait(hostandport):
while 1:
try:
gdb.execute("target remote " + hostandport)
return True
except gdb.error, e:
if "Connection timed out" in str(e):
print "timed out, retrying"
continue
else:
print "Cannot connect: " + str(e)
return e
end

Run file with gdbserver --multi

What next?

(gdb) set remote exec-file a.out
(gdb) file a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x4015ab: file 1.cpp, line 60.
(gdb) r
  • set remote exec-file a.out is used to set the program which you
    want to debug in the target.
  • file a.out is used to load the debugging symbols from the program
    in the host.

See full example for gdbserver --multi here: https://www.thegeekstuff.com/2014/04/gdbserver-example//



Related Topics



Leave a reply



Submit