基本上,您可以使用下面这样的 python 脚本来获取与任何对象关联的任何自定义摘要
# filename : customSummaries.py
import lldb
def someClass_summary(valueObject, dictionary):
# get properties from object
ivar1 = valueObject.GetChildMemberWithName('_ivar')
ivar2 = valueObject.GetChildMemberWithName('_ivar2')
# convert values into python intrinsics
error = lldb.SBError()
var1 = ivar1.GetData().GetFloat(error, 0)
var2 = ivar2.GetData().GetDouble(error, 0)
# string generation we're gonna use for the summaries
valueRepr1 = str(var1)
valueRepr2 = str(var2)
return 'value1= ' + valueRepr1 + ', value2= ' + valueRepr2
# this function gets called by the lldb as this script is imported
def __lldb_init_module(debugger, dict):
# this adds automatically your summaries as the script gets imported
debugger.HandleCommand('type summary add Class -F customSummaries.someClass_summary')
要在 lldb 运行时加载自定义摘要,您应该通过运行导入上面的脚本,仅此而已command script import /path/to/customSummaries.py
。