如何计算用于gdb monitor命令的表达式?

如何计算用于gdb monitor命令的表达式?,gdb,monitor,Gdb,Monitor,在一个脚本化的gdb会话中,我想使用monitor,其中cmd应该包含一个符号的地址。例如: monitor foobar &myVariable 应成为: monitor foobar 0x00004711 因为远程端无法计算表达式。无论我尝试了什么,都会发送字符串“&myVariable”,而不是地址 我使用了方便变量和其他东西,但这是我发现的唯一解决方法: # write the command into a file and execute this file # didn'

在一个脚本化的gdb会话中,我想使用
monitor
,其中cmd应该包含一个符号的地址。例如:

monitor foobar &myVariable
应成为:

monitor foobar 0x00004711
因为远程端无法计算表达式。无论我尝试了什么,都会发送字符串“&myVariable”,而不是地址

我使用了方便变量和其他东西,但这是我发现的唯一解决方法:

# write the command into a file and execute this file
# didn't find a direct way to include the address into the monitor command
set logging overwrite on
set logging on command.tmp
printf "monitor foobar 0x%08x\n", &myVariable
set logging off
source command.tmp

有没有更优雅的方法来解决这个问题呢?

最简单的方法就是使用gdb
eval
命令,这个命令就是为了这个目的而引入的。它的工作原理有点像
printf

(gdb) eval "monitor foobar %p", &myVariable
(我实际上没有试过,所以要小心。)

如果您的gdb没有
eval
,那么它是旧的。我建议升级

如果无法升级,那么也可以使用Python编写脚本

如果您的gdb没有Python,那么它要么非常旧(升级!),要么编译时不支持Python(重新编译!)


如果您无法获得这些功能中的任何一个,那么恐怕“编写脚本并
source
it”的方法就剩下了。

这正是我想要的
eval
有效,我想知道为什么我没有在文档中找到它。我找到了python绑定,但不想重新编译gdb。谢谢你的帮助!