2017-12-03 186 views
0

考虑以下输出相同文本字符串的gdb命令。如何从字符串返回gdb.Value()?

(gdb) print foo 
(gdb) python print(gdb.lookup_symbol('foo')) 

在这种情况下,预计gdb.lookup_symbol()返回gdb.Value()实例,它的字符串化等同于默认GDB字串。

但现在考虑以下情况相当于:

(gdb) print *&foo 

*&是一个空操作,但试图使用gdb.lookup_symbol('*&foo')不起作用。所以我的问题是,是否有可能使用python的gdb的命令行解引用解析器,然后得到一个gdb.Value作为回报?

回答

1

试图使用gdb.lookup_symbol('* & foo')不起作用。

这是因为二进制文件中没有名为*&foo的符号。

是否有可能使用gdb的命令行从蟒蛇提领分析器,然后作为回报获得gdb.Value?

你的问题不是很清楚,但我觉得所要求的parse_and_eval

Function: gdb.parse_and_eval (expression) 
Parse expression, which must be a string, as an expression in the current language, 
evaluate it, and return the result as a gdb.Value. 

This function can be useful when implementing a new command (see Commands In Python), 
as it provides a way to parse the command’s argument as an expression. 
It is also useful simply to compute values, for example, it is the only way to get 
the value of a convenience variable (see Convenience Vars) as a gdb.Value. 
+0

这的确是正是我一直在寻找。 :-) –