Question

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.

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?

Examples

typedef struct {
    double doubleMember;
} structWithDouble;

@interface MyClass : NSObject {
    structWithDouble structAsIvar;
}
@end

@implementation

- (void)someMethod {
    structAsIvar.doubleMember = 200.0;
    double localDouble = structAsIvar.doubleMember;
}

Inside someMethod:, the debugger variable list shows the following values:

structAsIvar.doubleMember (double) 1.65865e-307
localDouble               (double) 200

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

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.

Était-ce utile?

La solution

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) 

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top