打印双重类型struct成员时LLDB中的奇怪行为 [英] Strange behavior in LLDB when printing a double type struct member
问题描述
在某些iOS代码中,我在一个对象上有一个C struct
ivar.此结构的成员之一是double
类型.如果我在一个方法中分配给该struct
成员,则调试程序将在我打印struct
本身时(与变量的列表视图一样)报告此struct
成员的值的虚假值.直接打印struct
成员(p structWithDouble.doubleMember
),我得到正确的值.此外,如果我将此成员的值分配给本地的自动double
var,则在列表视图和打印时会看到正确的值.
In some iOS code, I have an C struct
ivar on an object. One of the members of this struct is of type double
. If I, within a method, assign to this struct
member, the debugger reports spurious values for the value of this struct
member when I print the struct
itself (as does the list view of variables), but when I print the struct
member directly, (p structWithDouble.doubleMember
), I get the right value. Furthermore, If I assign the value of this member to a local, automatic double
var, I see the correct value in the list view and when printing.
我认为这是LLDB的问题,但令人不安和沮丧.这是一个已知的问题?如果是这样,是否有解决方法?
I imagine this is an issue with LLDB, but it's unsettling and frustrating. Is this a known issue? If so, is there a workaround?
typedef struct {
double doubleMember;
} structWithDouble;
@interface MyClass : NSObject {
structWithDouble structAsIvar;
}
@end
@implementation
- (void)someMethod {
structAsIvar.doubleMember = 200.0;
double localDouble = structAsIvar.doubleMember;
}
在someMethod:
内部,调试器变量列表显示以下值:
Inside someMethod:
, the debugger variable list shows the following values:
structAsIvar.doubleMember (double) 1.65865e-307
localDouble (double) 200
在LLDB中,当进入someMethod:
时,我得到以下输出:
Over in LLDB, I get the following output when breaking in someMethod:
:
(lldb) p structAsIvar.doubleMember
(double) $4 = 200
(lldb) p structAsIvar
(structAsIvar) $5 = {
(double) doublemember = 1.17244e-312
}
(lldb) p localDouble
(double) 200
(lldb) p self->structAsIvar.doubleMember
(double) 200
更新
我发现在使用GDB时,这种行为没有发生.显然LLDB尚未准备好……不过,我仍然对LLDB的解决方法感兴趣.
Update
I've found that none of this behavior happens when using GDB. Apparently LLDB just isn't ready yet... I'm still be interested in a workaround for LLDB, though.
推荐答案
这似乎已在Xcode 4.5的lldb(lldb-167.2)中修复:
It looks like this is fixed in Xcode 4.5's lldb (lldb-167.2):
(lldb) p structAsIvar.doubleMember
(double) $5 = 200
(lldb) p structAsIvar
(structWithDouble) $6 = {
(double) doubleMember = 200
}
(lldb) p localDouble
(double) $7 = 200
(lldb) p self->structAsIvar.doubleMember
(double) $8 = 200
(lldb)
我不确定哪个版本有此修复程序; Xcode 4.4可能也可以正常工作,但我现在没有手头的东西可以进行测试.
I'm not sure exactly which release had the fix; it's likely Xcode 4.4 also works correctly but I don't have that at hand to test right now.
这篇关于打印双重类型struct成员时LLDB中的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!