python - 使用 Python 脚本时 Xcode lldb 调试器中的空 lldb.frame 变量
问题描述
我目前正在研究 C++ 中自定义对象的绘图命令。我正在使用 Xcode v10.1。
我使用命令脚本 import test.py导入自己的命令,其中有以下功能:
import lldb
def test_function(debugger, command, result, dict):
obj = lldb.frame.FindVariable("custom_object")
print(obj)
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f test.test_function test')
其中自定义对象是我想在 Python 脚本中使用的对象。
如果我刚刚打开调试器,我会收到错误消息:
obj = lldb.frame.FindVariable("custom_object")
AttributeError: 'NoneType' object has no attribute 'FindVariable'
但是,当我直接在 Xcode 中打开嵌入式 Python 解释器并执行与上面相同的代码行时,我没有收到任何错误。
如果我现在再次执行我的自定义命令,它将成功执行调试器同一范围内的所有对象。
解决方案
lldb.frame
未在基于 lldb python 的命令中定义 - 这就是它的原因NoneType
。 lldb.{process, thread,frame}
只是为了方便交互式脚本解释器。但是对于一个命令——它可能在停止钩子、断点命令等中运行,依赖于它的进程和线程的一些全局状态是没有意义的。毕竟,您可以让两个线程同时到达同一个断点。所以没有唯一的“lldb.thread”。
最好使用将 SBExecutionContext 作为第三个参数的命令函数版本(请参阅:https ://lldb.llvm.org/use/python-reference.html )并从该参数中获取线程和框架。
推荐阅读
- javascript - 开玩笑:window.print 未实现
- azure - Asp.net Web Api(非核心)导入 Azure APIM
- c# - 无法在 WPF 项目 .net core 3.0 中添加 appsettings.json
- javascript - 使用菜单中的按钮隐藏和显示多个类元素
- html - 如何混合 grid 和 flex 并增长其中一个 flex 元素?
- html - 输入字段在移动视图中不可点击
- python - 为什么有时我几乎没有得到关于 Python (Jupyter) 中发生错误的位置的信息?
- html - 为什么 filter 属性会影响 ::after 元素的宽度?
- rest - 什么是构建端点以提供类似测验的功能的好方法?
- java - 我正在使用 volley 进行登录 api,但出现 ssl 握手错误