2017-12-03 189 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

這的確是正是我一直在尋找。 :-) –