【问题标题】:GDB script flow control for remote target远程目标的 GDB 脚本流控制
【发布时间】:2017-08-30 08:31:34
【问题描述】:

如果自上次运行 gdb 以来它已更改,我只想刷新远程 gdb 目标上的代码。我在 gdb 脚本中设想了以下内容;

target extended-remote /dev/<device>
<Attach to Target>
file <Target Program>
if ![compare-sections -r]
    load
start

...但是,我看不到如何根据命令输出设置条件。

有人可以帮忙吗?我想我可能错过了什么,但我不知道是什么......

【问题讨论】:

    标签: gdb remote-debugging


    【解决方案1】:

    compare-sections 命令不会返回可在if 语句中使用的值,但以下命令可能会满足您的要求。

    首先,定义一个名为 $cmdevalconvenience function,它将执行 gdb 命令并将其输出作为字符串返回:

    import gdb
    
    class CmdEval(gdb.Function):
        """$cmdeval(str) - evaluate argument string as a gdb command
        and return the result as a string. Trailing newlines are removed.
        """
    
        def __init__(self):
            super(CmdEval, self).__init__("cmdeval")
    
        def invoke(self, gdbcmd):
            return gdb.execute(gdbcmd.string(), from_tty=False, to_string=True).rstrip('\n')
    
    CmdEval()
    

    你可以把它放在一个名为cmdeval.py的文件中,然后输入(gdb) source cmdeval.py把它加载到gdb中。

    接下来,由于compare-sections 为任何已更改的部分输出"MIS-MATCHED",您可以使用$_regex 便利函数查找该字符串,该函数包含在更新版本的gdb 中:

    (gdb) if $_regex($cmdeval("compare-sections -r"),".*MIS-MATCHED.*")
     >echo need to load again\n
     >end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 2012-01-09
      • 2017-06-13
      • 2010-10-19
      相关资源
      最近更新 更多