Luk*_*rth 5 getter qt formatter lldb
我正在使用 LLDB 调试 Qt 应用程序。在断点处我可以写
(lldb) p myQString.toUtf8().data()
Run Code Online (Sandbox Code Playgroud)
并查看 myQString 中包含的字符串,因为 data() 返回 char*。我希望能够写
(lldb) p myQString
Run Code Online (Sandbox Code Playgroud)
并得到相同的输出。这对我不起作用:
(lldb) type summary add --summary-string "${var.toUtf8().data()}" QString
Run Code Online (Sandbox Code Playgroud)
是否可以编写一个像这样的简单格式化程序,或者我是否需要了解 QString 的内部结构并编写一个 python 脚本?
或者,我是否应该使用 LLDB 来以这种方式查看 QStrings?
小智 2
以下确实有效。
首先,注册您的摘要命令:
debugger.HandleCommand('type summary add -F set_sblldbbp.qstring_summary "QString"')
Run Code Online (Sandbox Code Playgroud)
这是一个实现
def make_string_from_pointer_with_offset(F,OFFS,L):
strval = 'u"'
try:
data_array = F.GetPointeeData(0, L).uint16
for X in range(OFFS, L):
V = data_array[X]
if V == 0:
break
strval += unichr(V)
except:
pass
strval = strval + '"'
return strval.encode('utf-8')
#qt5
def qstring_summary(value, unused):
try:
d = value.GetChildMemberWithName('d')
#have to divide by 2 (size of unsigned short = 2)
offset = d.GetChildMemberWithName('offset').GetValueAsUnsigned() / 2
size = get_max_size(value)
return make_string_from_pointer_with_offset(d, offset, size)
except:
print '?????????????????????????'
return value
def get_max_size(value):
_max_size_ = None
try:
debugger = value.GetTarget().GetDebugger()
_max_size_ = int(lldb.SBDebugger.GetInternalVariableValue('target.max-string-summary-length', debugger.GetInstanceName()).GetStringAtIndex(0))
except:
_max_size_ = 512
return _max_size_
Run Code Online (Sandbox Code Playgroud)