Starting ddd with remote gdbserver
Choose one of:
ddd --eval-command="target remote localhost:1234"
- put
target remote localhost:1234
into a file and use--command
to execute it - 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
Using Output of Previous Commands in Bash
Best Way to Build Cross Toolchains on MAC Os X
How to Open Another File in Background Vim from Bash Command-Line
What Is Eof!! in The Bash Script
Sudo User Not Using Same Node Version
Tab Completion in Emacs Shell-Mode Ssh Sessions
Os X Permission Denied for /Usr/Local/Lib
Is There a 'ssh-Add' Linux Alpine One Liner
Matlab - Run File Without Opening Gui, Then Quit
Openssl/Rsa - Using a Public Key to Decrypt
Application Counters in Linux? (And Osx)
On-The-Fly Output Redirection, Seeing The File Redirection Output While The Program Is Still Running
Bash Loop Through Directory Including Hidden File
How to Remember Multiple Tabs' Session in Terminal? (Alike Ff Session Manager)
Check If All Lines from One File Are Present Somewhere in Another File
How to Make Sure Only One Instance of a Bash Script Is Running at a Time
What Does "No More Variables Left in This Mib View" Mean (Linux)