【问题标题】:GDB remote debugging: make GDB wait for gdbserver to be startedGDB 远程调试:让 GDB 等待 gdbserver 启动
【发布时间】:2015-04-29 23:49:02
【问题描述】:

我知道的远程调试的常规方法是在目标上启动 gdbserver,然后从 gdb 远程连接(使用目标远程)。

但是,是否有可能让 GDB 在某个端口上等待,直到 gdbserver 在该端口上出现?

【问题讨论】:

    标签: gdb gdbserver


    【解决方案1】:

    您可以使用一些 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
    

    【讨论】:

      【解决方案2】:

      没有内置任何东西,但我认为有几种方法可以让它发挥作用。

      一种是在目标上按需运行gdbserver,例如从inetd 或等效的。

      另一种方法是在目标上运行代理,让代理接受连接,否则在 gdbserver 准备好之前什么都不做。不过,我不确定这是否会在 gdb 端遇到超时问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-03
        • 2013-05-15
        • 2010-10-16
        • 2023-03-29
        • 2015-10-05
        • 2011-11-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多