typedef struct objc_class { struct objc_class *isa; struct objc_class *super_class; char *name; long version; long info; long instance_size; voID *ivars; voID *methodLists; voID *cache; voID *protocols;} *Class;struct objc_object { Class isa;};/* Code to extract the class name from arg0 based on a snippet by Bill Bumgarner: http://frIDay.com/bbum/2008/01/26/objective-c-printing-class-name-from-dtrace/ */objc$target:NSObject:-init:entry { printf("time: %llu\n",timestamp); printf("arg0: %p\n",arg0); obj = (struct objc_object *)copyin(arg0,sizeof(struct objc_object)); printf("obj: %p\n",obj); printf("obj->isa: %p\n",obj->isa); isa = (Class)copyin((user_addr_t)obj->isa,sizeof(struct objc_class)); printf("isa: %p\n",obj->isa); classname = copyinstr((user_addr_t)(isa->name)); printf("classname: %s\n",classname);}
一些输出:
dtrace: script 'test.d' matched 1 probedtrace: error on enabled probe ID 1 (ID 61630: objc5936:NSObject:-init:entry): invalID address (0x90206b98) in action #8 at DIF offset 28dtrace: error on enabled probe ID 1 (ID 61630: objc5936:NSObject:-init:entry): invalID address (0x90206b98) in action #8 at DIF offset 28dtrace: error on enabled probe ID 1 (ID 61630: objc5936:NSObject:-init:entry): invalID address (0x90206b98) in action #8 at DIF offset 28cpu ID FUNCTION:name 0 61630 -init:entry time: 28391086668386arg0: 1291ae10obj: 6f0a1158obj->isa: a023f360isa: a023f360classname: NSBitmAPImageRep 1 61630 -init:entry time: 28391586872297arg0: 12943560obj: 6f4a1158obj->isa: 2fca0isa: 2fca0classname: GrowlApplicationTicket 1 61630 -init:entry time: 28391586897807arg0: 152060obj: 6f4a1280obj->isa: 2fe20isa: 2fe20classname: GrowlNotificationTicket 2 61630 -init:entry time: 28391079142905arg0: 129482d0obj: 700a1128obj->isa: a0014140isa: a0014140classname: NSdistributedobjectsstatistics 2 61630 -init:entry time: 28391079252640arg0: 147840obj: 700a1250obj->isa: a0014780isa: a0014780classname: NSdistantObjecttableEntry
为什么错误?它似乎是类名(这是唯一的%s,如果我删除它,我不会得到任何错误),但为什么它认为某些类的名称是无效指针?
有没有办法让错误消息实际告诉我DTrace程序的哪一行导致了问题?
有没有办法调用object_getClassname而不是进行这种结构检查舞蹈?
对于它的价值,我追踪的程序运行良好 – 它不会崩溃,所以我不相信这些类真的被打破了.
解决方法 科林非常接近正确.看到:
http://www.friday.com/bbum/2008/01/03/objective-c-using-dtrace-to-trace-messages-to-nil/
更有可能的是,您需要设置DYLD_SHARED_REGION环境变量以避免. dtrace只对实际驻留在物理内存中的映射内存起作用.
您可以使用vmmap命令行工具找出缺少的内容.
生成上述故障消息后,在应用程序上执行vmmap PID.查看输出,查看0x90206b98等地址属于哪个区域.给定该地址,它可能在不可写的共享内存块中可能不是驻留的,因此,dtrace无法从中读取.
总结以上是内存溢出为你收集整理的objective-c – 为什么DTrace有时会给我无效地址错误但不总是?全部内容,希望文章能够帮你解决objective-c – 为什么DTrace有时会给我无效地址错误但不总是?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)