I’ve noticed that custom NSManagedObject subclass instances do not respond to their accessors when calling them from gdb. I always have to call valueForKey: and setValue:forKey:.
I presume this has something to do with their property accessors being generated in runtime (NSManagedObject subclasses have @dynamic accessors for properties)? What exactly happens to ObjC runtime when the breakpoint is being hit in gdb?
Please note that I am trying to get object’s properties using simple messaging syntax, and not the dot syntax.
Gdb includes its own code to resolve message implementations. It knows about the object’s structure, walks its class hierarchy, resolves the selector to an IMP and calls that via its own mechanism. I believe it does that so it can do stuff like “step into”, i.e. jump into an implementation and stop there (instead of jumping into
objc_msgSendand stopping there, which you wouldn’t want).Since NSManagedObject doesn’t synthesize method IMPs, but rather uses dynamic dispatch and forwarding to resolve its setters/getters, gdb cannot find the IMPs, and so fails. The KVC methods are provided by NSObject, so they’re always there; since they execute natively, they’ll use the proper dispatch mechanism, which NSManagedObject then uses to resolve the proper accessors.