远程目标的GDB脚本流控制 [英] GDB script flow control for remote target

查看:81
本文介绍了远程目标的GDB脚本流控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to do only flash the code on a remote gdb target if it has changed since last time gdb was run. I envisage something along the lines of the following in gdb script;

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

...但是,我看不到如何以命令输出为条件.

...however, I cannot see how to make a conditional on a command output.

任何人都可以帮忙吗?我想我可能错过了一些东西,但是我不知道是什么....

Can anyone help? I think I probably missed something, but I've no idea what....

推荐答案

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

The compare-sections command doesn't return a value that can be used in an if statement, but the following may do what you want.

首先,定义一个便捷功能名为 $ cmdeval 的代码,它将执行gdb命令并以字符串形式返回其输出:

First, define a convenience function named $cmdeval which will execute a gdb command and return its output as a string:

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中.

You can put this in a file named cmdeval.py and type (gdb) source cmdeval.py to load it into gdb.

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

Next, since compare-sections outputs "MIS-MATCHED" for any section that has been changed, you can look for that string using the $_regex convenience function, which is included in more recent versions of gdb:

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

这篇关于远程目标的GDB脚本流控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆