关于如何将自定义LLDB类型摘要添加到Xcode中的帖子a question。我发现我们可以通过加载Python脚本来实现。
但是,我想知道是否有办法加载多个Python文件?我使用许多不同的项目,所以我希望有1个摘要文件用于我所有项目中使用的常规类型,1个摘要文件用于项目特定类型。
〜/ MyGenericSummaries.py
import lldb
def __lldb_init_module(debugger, dictionary):
debugger.HandleCommand('type summary add --summary-string "these are words" MyGenericClass');
〜/ MyProjectSummaries.py
import lldb
def __lldb_init_module(debugger, dictionary):
debugger.HandleCommand('type summary add --summary-string "these are more words" MyProjectClass');
〜/ .lldbinit
command script import ~/MyGenericSummaries.py
command script import ~/MyProjectSummaries.py
这永远不会加载MyProjectSummaries.py的类型摘要 - LLDB只是告诉我
错误:模块导入失败:模块已导入
是否可以将通用摘要和项目摘要保存在单独的文件中?这确实会有所帮助,因为我有一些类型名称在不同的项目中发生冲突,所以我宁愿将它们分开。
非常感谢:)
答案 0 :(得分:2)
好的,我明白了......带着一些Python魔法:
<强>〜/ MyGenericSummaries.py 强>
import lldb
def doLoad(debugger, dictionary):
debugger.HandleCommand('type summary add --summary-string "these are words" MyGenericClass');
def __lldb_init_module(debugger, dictionary):
doLoad(debugger, dictionary);
<强>〜/ MyProjectSummaries.py 强>
import lldb
from MyGenericSummaries import doLoad
def __lldb_init_module(debugger, dictionary):
doLoad(debugger, dictionary);
debugger.HandleCommand('type summary add --summary-string "these are more words" MyProjectClass');
<强>〜/ .lldbinit 强>
command script import ~/MyProjectSummaries.py
唯一的缺点是我需要调整.lldbinit
并在每次切换项目时重启Xcode,但这是我可以忍受的。
答案 1 :(得分:1)
我不清楚为什么原始代码不起作用。从你引用的内容来看,我希望能够发挥作用。
您command script import
文件中肯定可以~/.lldbinit
多个Python文件 - 我一直这样做。从错误消息中,您的command script import ~/MyProjectSummaries.py
已经显示~/.lldbinit
。小心查找运行Xcode时也来源的~/.lldbinit-Xcode
(如果正在使用命令行lldb,则为~/.lldbinit-lldb
。对于正在使用的lldb,一般形式为~/.lldbinit-DRIVER_NAME
例如,如果只想在Xcode中使用lldb库时启用某些设置,则此功能非常有用。)
您可能希望将type summary
条目放在每个项目组中。如果您type summary list
,您会看到内置摘要已经分为libcxx
,VectorTypes
,CoreGraphics
等类别。这些摘要组可以启用或使用type category enable|disable|list|delete
停用。
命令行lldb还会读取运行它的当前工作目录中的.lldbinit
- 尽管这对Xcode案例没有帮助。对于你正在做的事情,你真的想要一个特定于项目的lldbinit文件。如果在~/.lldbinit
文件中添加了这些类型摘要,则项目特定的lldbinit可能只启用/禁用此项目的正确类型摘要。但是现在Xcode中没有这样的功能。