Objective c 使用DTrace记录发送到剥离类的所有消息

Objective c 使用DTrace记录发送到剥离类的所有消息,objective-c,dtrace,Objective C,Dtrace,使用DTrace记录发送到类的所有消息通常很容易,例如,使用trace\u msg\u send.sh脚本从以下位置: 脚本不再有效 有没有办法告诉DTrace剥离类/消息实现的位置 可能使用类转储中提供的信息,如的答案 我创建了一个脚本,试图在运行时比较类名,但它似乎不起作用: #!/usr/sbin/dtrace -s #pragma D option quiet unsigned long long indention; int indentation_amount; BEGIN {

使用DTrace记录发送到类的所有消息通常很容易,例如,使用
trace\u msg\u send.sh
脚本从以下位置:

脚本不再有效

有没有办法告诉DTrace剥离类/消息实现的位置

可能使用
类转储
中提供的信息,如的答案


我创建了一个脚本,试图在运行时比较类名,但它似乎不起作用:

#!/usr/sbin/dtrace -s
#pragma D option quiet

unsigned long long indention;
int indentation_amount;

BEGIN {
  indentation_amount = 4;
}

objc$target:::entry
{
    // Assumes 64 bit executable
    isaptr = *(uint64_t *)copyin(arg0, 8);
    class_rw = *(uint64_t *)copyin(isaptr + 4*8, 8);
    class_ro = *(uint64_t *)copyin(class_rw + 8, 8);
    classnameptr = *(uint64_t *)copyin(class_ro + 4*4 + 8, 8);
    classname = copyinstr(classnameptr);

    type = classname == $$1? (string)&probefunc[0]: "";
    method = classname == $$1? (string)&probefunc[1]: "";

    arrow = classname == $$1? "->": "";
    space = classname == $$1? " ": "";
    bracket1 = classname == $$1? "[": "";
    bracket2 = classname == $$1? "]": "";
    current_indention = classname == $$1? indention: 0;
    indention = classname == $$1? indention + 1: indention;

    newline = classname == $$1? "\n": "";

    classname = classname == $$1? classname: "";

    printf("%*s%s%s%.1s%s%s%s%s%s%s", current_indention * indentation_amount, "", arrow, space, type, bracket1, classname, space, method, bracket2, newline);
}
运行
sudo./trace\u msg\u send2.d-c./testtestclass
打印:

num: 4
dtrace: error on enabled probe ID 179 (ID 13922: objc3517:NSObject:+load:entry): invalid address (0x7fff8204e03e) in action #5 at DIF offset 12
dtrace: error on enabled probe ID 186 (ID 13915: objc3517:__IncompleteProtocol:+load:entry): invalid address (0x7fff8204e01f) in action #5 at DIF offset 12
dtrace: error on enabled probe ID 195 (ID 13906: objc3517:Protocol:+load:entry): invalid address (0x7fff8204e034) in action #5 at DIF offset 12
-> +[TestClass initialize]

其中
->-[TestClass randomNum:
缺失。

即使我尝试将dtrace与剥离的二进制文件一起使用,dtrace也只是给出objective-c运行时类和函数。知道如何使用dtrace以剥离二进制实现函数名吗?
$ gcc test.m -lobjc -o test
$ ./test
num: 4
$ sudo ./trace_msg_send.d -c ./test TestClass
num: 4
-> +[TestClass randomNum]
<- +[TestClass randomNum]
$ strip test
$ sudo ./trace_msg_send.d -c ./test TestClass
dtrace: failed to compile script ./trace_msg_send.d: line 11: probe description objc49043:TestClass::entry does not match any probes
#!/usr/sbin/dtrace -s
#pragma D option quiet

unsigned long long indention;
int indentation_amount;

BEGIN {
  indentation_amount = 4;
}

objc$target:::entry
{
    // Assumes 64 bit executable
    isaptr = *(uint64_t *)copyin(arg0, 8);
    class_rw = *(uint64_t *)copyin(isaptr + 4*8, 8);
    class_ro = *(uint64_t *)copyin(class_rw + 8, 8);
    classnameptr = *(uint64_t *)copyin(class_ro + 4*4 + 8, 8);
    classname = copyinstr(classnameptr);

    type = classname == $$1? (string)&probefunc[0]: "";
    method = classname == $$1? (string)&probefunc[1]: "";

    arrow = classname == $$1? "->": "";
    space = classname == $$1? " ": "";
    bracket1 = classname == $$1? "[": "";
    bracket2 = classname == $$1? "]": "";
    current_indention = classname == $$1? indention: 0;
    indention = classname == $$1? indention + 1: indention;

    newline = classname == $$1? "\n": "";

    classname = classname == $$1? classname: "";

    printf("%*s%s%s%.1s%s%s%s%s%s%s", current_indention * indentation_amount, "", arrow, space, type, bracket1, classname, space, method, bracket2, newline);
}
num: 4
dtrace: error on enabled probe ID 179 (ID 13922: objc3517:NSObject:+load:entry): invalid address (0x7fff8204e03e) in action #5 at DIF offset 12
dtrace: error on enabled probe ID 186 (ID 13915: objc3517:__IncompleteProtocol:+load:entry): invalid address (0x7fff8204e01f) in action #5 at DIF offset 12
dtrace: error on enabled probe ID 195 (ID 13906: objc3517:Protocol:+load:entry): invalid address (0x7fff8204e034) in action #5 at DIF offset 12
-> +[TestClass initialize]