gdb:调用 NSManagedObject 子类的访问器方法?
我有一个类 Song,它是 NSManagedObject 的子类。我正在使用 GDB 来尝试解决我遇到的问题,并且很难使用 gdb 调用我的类上的访问器。
Song.h:
@property (nonatomic, retain) NSString * title;
Song.m:
@dynamic title;
在调试器中,我看到对象上的“标题”字段,当我尝试使用访问器打印值时(如果我理解正确的话,该值应该在运行时生成),它给了我一个错误:
(gdb) po aSong <Song: 0x59188d0>
(entity: Song; id: 0x59162d0
<x-coredata://99BE63F8-840A-47B5-A259-BCD74E1811C4/Song/p2>
; data: {
composers = "<relationship fault: 0x4d62f30 'composers'>";
dateCreated = nil;
songLists = "<relationship fault: 0x59243c0 'songLists'>";
title = "cancel?"; })
(gdb) p aSong.title There is no member named
title.
(gdb) p [aSong title]
Target does not respond to this message selector.
很可能我在这里做了一些非常愚蠢的事情,但是我做错了什么?有什么方法可以使用 GDB 内省对象并查看它将响应哪些消息?
I have a class, Song, which subclasses NSManagedObject. I'm using GDB to try and figure out a problem I'm having, and am having a hard time calling an accessor on my class using gdb.
Song.h:
@property (nonatomic, retain) NSString * title;
Song.m:
@dynamic title;
In the debugger, I see the "title" field on the object, when I try to print the value using the accessor, which should be generated at runtime if I understand correctly, it gives me an error:
(gdb) po aSong <Song: 0x59188d0>
(entity: Song; id: 0x59162d0
<x-coredata://99BE63F8-840A-47B5-A259-BCD74E1811C4/Song/p2>
; data: {
composers = "<relationship fault: 0x4d62f30 'composers'>";
dateCreated = nil;
songLists = "<relationship fault: 0x59243c0 'songLists'>";
title = "cancel?"; })
(gdb) p aSong.title There is no member named
title.
(gdb) p [aSong title]
Target does not respond to this message selector.
Chances are I'm doing something really stupid here, but what am I doing wrong? Is there any way to introspect an object and see what messages it will respond to using GDB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
valueForKey:
方法访问gdb
中动态生成的属性,如[aSong valueForKey:@"title"]
中所示。 (如果你是一个受虐狂,这种技术也适用于合成属性,但实际上它只有在检查 NSManagedObject 及其子类时才派上用场。)You can access dynamically generated properties in
gdb
using thevalueForKey:
method, as in[aSong valueForKey:@"title"]
. (This technique works for synthesized properties too, if you're a masochist, but really it only comes in handy when inspectingNSManagedObject
and its subclasses.)遗憾的是,这就是 gdb 的行为方式。它似乎不是询问对象是否会响应选择器,而是只是查看对象的实现现在或在编译时(我还没有弄清楚哪个然而)。因为 Core Data 属性是在消息转发过程中处理的,所以调试器不相信
NSManagedObject
会响应属性选择器。这可能值得作为错误报告给 Apple,以便他们可以修复调试器。
Sadly, this is how
gdb
behaves. Rather than asking the object whether it will respond to a selector, it seems to just look at the object's implementation either now or at compile time (I haven't worked out which yet). Because Core Data attributes are dealt with during the message forwarding process, the debugger doesn't believe thatNSManagedObject
will respond to the attribute selectors.This is probably worth reporting as a bug to Apple, so they can fix the debugger.