0-0*_*0-0 4 gdb objective-c objective-c-runtime ios
我有一个gdb脚本,我正在努力跟踪所有通过objc_msgSend的Objective-C方法调用,但我遇到了一个我似乎无法处理的问题.在查看了Objective-C运行时源代码之后,我开发了以下脚本,以便在objc_msgSend的每个中断处打印[].问题是在某些情况下data_NEVER_USE不是有效指针但也不是null.我能找到一个类是否被初始化的唯一指标是id-> data_NEVER_USE-> flags&RW_REALIZED.我在这里错过了类初始化的哪些方面,这将允许我跳过这种情况?
b objc_msgSend
c
commands
silent
if (*$r0 == 0)
continue
end
set $id = (class_t *)$r0
set $sel = $r1
print *$id
if($id->data_NEVER_USE != 0)
set $data = (class_ro_t *) ($id->data_NEVER_USE)
if (($data->flags & 0x80000000) && ($data->name))
set $classname = $data->name
printf "[%s ", $classname
else
continue
end
end
if ($sel != 0)
printf "%s", $sel
else
printf "null"
end
printf "]\n"
continue
end
Run Code Online (Sandbox Code Playgroud)
我很感激任何帮助.谢谢.
这两种方法对我来说效果相当不错.请注意,在我的示例中,我手动启动"SomeApp"以便在启动时立即对其进行监控.
gdb
(gdb) attach --waitfor 'SomeApp'
**this is where you manually start SomeApp on your device**
call (void)instrumentObjcMessageSends(YES)
Run Code Online (Sandbox Code Playgroud)
"instrumentObjcMessageSends"启用/禁用运行时内的消息记录.以下是有关此方法的更多信息.
另一个选项,仍然在你的iDevice上使用GDB,就是写一个这样的小命令:
FooPad:~ root# gdb
(gdb) attach SBSettings
Attaching to process 440.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ............................. done
0x35686004 in mach_msg_trap ()
(gdb) break objc_msgSend
Breakpoint 1 at 0x3323ef72
(gdb) commands
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>printf "-[%s %s]\n", (char *)class_getName(*(long *)$r0,$r1),$r1
>c
>end
(gdb) c
Continuing.
// a ton of information will follow
Run Code Online (Sandbox Code Playgroud)
只要按下"c"(右上方的行显示"继续."),您的屏幕将填充函数名称和参数.
最后按照这些说明在iDevice上获得一个可用的GDB.对于后代,我会在这里发布简短说明:
GNU Debugger(gdb)用于分析iOS应用程序的运行时行为.在最近的iOS版本中,直接从Cydia下载的GNU Debugger已损坏且无法正常运行.继Pod 2g博客文章后也没有帮助我.
要摆脱这个问题,请将http://cydia.radare.org添加到cydia源并下载最新的GNU Debugger(build 1708).GDB build 1708适用于iOS 5.x.
| 归档时间: |
|
| 查看次数: |
2294 次 |
| 最近记录: |