gpt4 book ai didi

python - GDB:如何从内置 python 更改便利变量

转载 作者:行者123 更新时间:2023-11-28 16:38:17 25 4
gpt4 key购买 nike

如何从其内置的 python 中为 gdb 便利变量 赋值?我认为它应该很简单,因为它在尝试实现用户定义的函数时自然会出现。但是我找不到任何东西。

更新:添加了一个简化的示例。不过,我的实际功能更为复杂。无论如何,将变量从 python 传输到 gdb 的方法会有很大帮助。

一个用法示例(achtung!——它会引发错误):

#accept a string, return it's lenght
define RetLenOfArg
py arg0 = gdb.parse_and_eval("$arg0")
set $Retrn = py len(arg0)
end

最佳答案

存在 gdb 的 python API 来获取/设置便利变量:来自 documentation

Function: gdb.convenience_variable (name) Return the value of theconvenience variable (see Convenience Vars) named name. name must be astring. The name should not include the ‘$’ that is used to mark aconvenience variable in an expression. If the convenience variabledoes not exist, then None is returned.

Function: gdb.set_convenience_variable (name, value) Set the value ofthe convenience variable (see Convenience Vars) named name. name mustbe a string. The name should not include the ‘$’ that is used to marka convenience variable in an expression. If value is None, then theconvenience variable is removed. Otherwise, if value is not agdb.Value (see Values From Inferior), it is is converted using thegdb.Value constructor.

关于python - GDB:如何从内置 python 更改便利变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23150124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com