compare-sections
コマンドはif
ステートメントで使用できる値を返さないが、次のようにしてもよい。
まず、GDBのコマンドを実行し、文字列としてその出力を返します$cmdeval
という名前convenience functionを定義します。
import gdb
class CmdEval(gdb.Function):
"""$cmdeval(str) - evaluate argument string as a gdb command
and return the result as a string.
"""
def __init__(self):
super(CmdEval, self).__init__("cmdeval")
def invoke(self, gdbcmd):
return gdb.execute(gdbcmd.string(), from_tty=False, to_string=True)
CmdEval()
あなたはcmdeval.py
という名前のファイルにこれを入れて、GDBにロードするために(gdb) source cmdeval.py
を入力することができます。
(gdb) if $_regex($cmdeval("compare-sections -r"),".*MIS-MATCHED.*")
>echo need to load again\n
>end
:
次は、変更された任意のセクションのためのcompare-sections
出力"MIS-MATCHED"
いるので、あなたはGDBの最近のバージョンに含まれている$_regex
便利な機能を使用して、その文字列を探すことができます