我有一个使用常规 C89 初始化程序初始化的数组:
uint8_t data[] = {0x05,0x48,0x45,0x4c,0x4c,0x4f,0x01,0x00 ... }
当我在 lldb 中打印这个数组时,我得到了这个怪物:
(lldb) p data
(uint8_t [200]) $0 = {
[0] = '\x05'
[1] = 'H'
[2] = 'E'
[3] = 'L'
[4] = 'L'
[5] = 'O'
[6] = '\x01'
...
我试图将 lldb 的输出强制转换为原始 C89 语法,这样我就可以简单地将 lldb 中的数组内容粘贴回我的代码中(例如,这样我就可以编写使用在调试期间捕获的数组的单元测试)。
如何告诉 lldb 将其输出格式化为看起来像普通的 C89 初始化程序?
最佳答案
您可以编写一个Python摘要打印机来以正确的格式打印数组的内容,但传递到Python的SBValue
对象将没有可用变量的名称。
(lldb) type summ add uint8_t[] -P
[...]
print '{',
for i in xrange(0, valobj.GetNumChildren()):
print '0x%02x' % valobj.GetChildAtIndex(i).GetValueAsUnsigned(),
if (i != valobj.GetNumChildren() - 1):
print ',',
print '};'
DONE
(lldb) p data
{ 0x05 , 0x48 , 0x45 , 0x4c , 0x4c , 0x4f , 0x01 , 0x00 };
(uint8_t [8]) $1 = {
[0] = 0x05
[1] = 0x48
[2] = 0x45
[3] = 0x4c
[4] = 0x4c
[5] = 0x4f
[6] = 0x01
[7] = 0x00
}
关于c - 在 LLDB 中将字节数组格式化为 C-89 初始值设定项表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21794044/