【发布时间】:2015-04-29 23:49:02
【问题描述】:
我知道的远程调试的常规方法是在目标上启动 gdbserver,然后从 gdb 远程连接(使用目标远程)。
但是,是否有可能让 GDB 在某个端口上等待,直到 gdbserver 在该端口上出现?
【问题讨论】:
我知道的远程调试的常规方法是在目标上启动 gdbserver,然后从 gdb 远程连接(使用目标远程)。
但是,是否有可能让 GDB 在某个端口上等待,直到 gdbserver 在该端口上出现?
【问题讨论】:
您可以使用一些 Python 代码来完成此操作。如果命令出错,gdb.execute("command ...") 将引发 python 异常。所以我们可以让python重复运行target remote host:port命令,只要它得到一个超时错误(应该类似于host:port: Connection timed out.)。
将以下内容放入文件中,并使用gdb的source命令将其读入。它将定义一个新的子命令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
【讨论】:
没有内置任何东西,但我认为有几种方法可以让它发挥作用。
一种是在目标上按需运行gdbserver,例如从inetd 或等效的。
另一种方法是在目标上运行代理,让代理接受连接,否则在 gdbserver 准备好之前什么都不做。不过,我不确定这是否会在 gdb 端遇到超时问题。
【讨论】: