【问题标题】:How to return a gdb.Value() from a string?如何从字符串返回 gdb.Value()?
【发布时间】:2017-12-03 09:45:05
【问题描述】:

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

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

在这种情况下gdb.lookup_symbol()按预期返回一个gdb.Value()实例,它的字符串化相当于默认的gdb字符串化。

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

(gdb) print *&foo

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

【问题讨论】:

    标签: gdb gdb-python


    【解决方案1】:

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

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

    是否可以利用gdb的命令行从python解引用解析器,然后得到一个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.
    

    【讨论】:

    • 这确实是我想要的。 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 2010-12-23
    • 2016-11-17
    • 2021-10-01
    相关资源
    最近更新 更多