为什么DTrace有时会给我无效地址错误,但不总是? [英] Why does DTrace give me invalid-address errors sometimes but not always?

查看:302
本文介绍了为什么DTrace有时会给我无效地址错误,但不总是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程式:

  typedef struct objc_class {
struct objc_class * isa;
struct objc_class * super_class;
char * name;
long version;
long信息
long instance_size;
void * ivars;
void * methodLists;
void * cache;
void * protocols;
} * Class;
struct objc_object {
Class isa;
};

/ *根据Bill Bumgarner的代码段从arg0中提取类名的代码:http://friday.com/bbum/2008/01/26/objective-c-printing-class- name-from-dtrace / * /

objc $ target:NSObject:-init:entry {
printf(time:%llu\\\
,timestamp);
printf(arg0:%p \\\
,arg0);
obj =(struct objc_object *)copyin(arg0,sizeof(struct objc_object));
printf(obj:%p \\\
,obj);
printf(obj-> isa:%p \\\
,obj-> isa);
isa =(Class)copyin((user_addr_t)obj-> isa,sizeof(struct objc_class));
printf(isa:%p \\\
,obj-> isa);
classname = copyinstr((user_addr_t)(isa-> name));
printf(classname:%s\\\
,classname);
}

一些输出:

  dtrace:script'test.d'matched 1 probe 
dtrace:在启用的探测器ID 1上出现错误(ID 61630:objc5936:NSObject:-init:entry):invalid address (0x90206b98)在DIF偏移28处的动作#8中
dtrace:在启用的探测器ID 1上的错误(ID 61630:objc5936:NSObject:-init:entry):在DIF偏移28处的动作#8中的无效地址
dtrace:在DIF偏移28处的动作#8中启用的探针ID 1(ID 61630:objc5936:NSObject:-init:entry):无效地址(0x90206b98)错误
CPU ID功能:名称
0 61630 -init:entry time:28391086668386
arg0:1291ae10
obj:6f0a1158
obj-> isa:a023f360
isa:a023f360
classname:NSBitmapImageRep

1 61630 -init:entry time:28391586872297
arg0:12943560
obj:6f4a1158
obj-> isa:2fca0
isa:2fca0
classname:GrowlApplicationTicket

1 61630 -init:entry time:28391586897807
arg0:152060
obj:6f4a1280
obj-> isa:2fe20
isa:2fe20
classname:GrowlNotificationTicket

2 61630 -init:entry time:28391079142905
arg0:129482d0
obj:700a1128
obj-> ; isa:a0014140
isa:a0014140
classname:NSDistributedObjectsStatistics

2 61630 -init:输入时间:28391079252640
arg0:147840
obj:700a1250
obj-> isa:a0014780
isa:a0014780
classname: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不能从中读取。


My program:

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);
}

Some output:

dtrace: script 'test.d' matched 1 probe
dtrace: error on enabled probe ID 1 (ID 61630: objc5936:NSObject:-init:entry): invalid address (0x90206b98) in action #8 at DIF offset 28
dtrace: error on enabled probe ID 1 (ID 61630: objc5936:NSObject:-init:entry): invalid address (0x90206b98) in action #8 at DIF offset 28
dtrace: error on enabled probe ID 1 (ID 61630: objc5936:NSObject:-init:entry): invalid address (0x90206b98) in action #8 at DIF offset 28
CPU     ID                    FUNCTION:NAME
  0  61630                      -init:entry time: 28391086668386
arg0: 1291ae10
obj: 6f0a1158
obj->isa: a023f360
isa: a023f360
classname: NSBitmapImageRep

  1  61630                      -init:entry time: 28391586872297
arg0: 12943560
obj: 6f4a1158
obj->isa: 2fca0
isa: 2fca0
classname: GrowlApplicationTicket

  1  61630                      -init:entry time: 28391586897807
arg0: 152060
obj: 6f4a1280
obj->isa: 2fe20
isa: 2fe20
classname: GrowlNotificationTicket

  2  61630                      -init:entry time: 28391079142905
arg0: 129482d0
obj: 700a1128
obj->isa: a0014140
isa: a0014140
classname: NSDistributedObjectsStatistics

  2  61630                      -init:entry time: 28391079252640
arg0: 147840
obj: 700a1250
obj->isa: a0014780
isa: a0014780
classname: NSDistantObjectTableEntry

Why the errors? It seems to be the class name (that's the only %s, and I don't get any errors if I remove it), but why does it think some classes' names are invalid pointers?

Is there any way to get the error messages to actually tell me which line of my DTrace program caused a problem?

Is there a way to call object_getClassName instead of doing this structure-inspection dance?

For what it's worth, the program I'm tracing works fine—it's not crashing, so I don't believe that the classes really are broken.

解决方案

Colin is pretty close to correct.

See:

http://www.friday.com/bbum/2008/01/03/objective-c-using-dtrace-to-trace-messages-to-nil/

More likely than not, you need to set the DYLD_SHARED_REGION environment variable to avoid. dtrace only really works against mapped memory that is actually resident in physical memory.

You can figure out what is missing by using the vmmap command line tool.

Do a vmmap PID on your application after the above failure messages are generated. Looking at the output, see what region the addresses like 0x90206b98 fall into. Given that address, it is likely in a non-writeable shared chunk of memory that probably isn't resident and, thus, dtrace can't read from it.

这篇关于为什么DTrace有时会给我无效地址错误,但不总是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆