如何从字符串中 return a gdb.Value()?

How to return a gdb.Value() from a string?

考虑以下输出相同文本字符串的 gdb 命令。

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

在这种情况下gdb.lookup_symbol() return如预期的那样是一个gdb.Value()实例,它的字符串化等同于默认的gdb字符串化。

但现在考虑以下等效情况:

(gdb) print *&foo

*& 是一个空洞,但尝试使用 gdb.lookup_symbol('*&foo') 不起作用。所以我的问题是是否可以使用 gdb 的命令行从 python 中取消引用解析器,然后在 return 中得到一个 gdb.Value?

trying to use gdb.lookup_symbol('*&foo') does not work.

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

whether it is possible to make use of gdb's command line dereferencing parser from python, and then get a gdb.Value in return?

你的问题不是很清楚,但我认为你问的是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.