The normal way I know to remote debug is to start gdbserver on a target and then remotely connect from gdb (using target remote).
But, is it possible that GDB be made to wait on a port until gdbserver comes up on that port?
Thanks in advance.
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
There's nothing built in, but there are a couple ways I think you can make it work.
One is to run gdbserver
on demand on the target, say from inetd
or equivalent.
Another is to run a proxy on the target, and have the proxy accept a connection but otherwise do nothing until gdbserver is ready. I'm not sure offhand if this would run into timeout problems on the gdb side, though.