用于跟踪iOS设备上的Objective-C调用的GDB脚本 – 问题

用于跟踪iOS设备上的Objective-C调用的GDB脚本 – 问题,第1张

概述我有一个gdb脚本,我正在努力跟踪所有通过objc_msgSend的Objective-C方法调用,但我遇到了一个我似乎无法处理的问题.在查看了Objective-C运行时源代码之后,我开发了以下脚本,以便在objc_msgSend的每个中断处打印[].问题是在某些情况下data_NEVER_USE不是有效指针但也不是null.我可以找到关于类是否被初始化的唯一指标是id-> data_NEVER 我有一个gdb脚本,我正在努力跟踪所有通过objc_msgSend的Objective-C方法调用,但我遇到了一个我似乎无法处理的问题.在查看了Objective-C运行时源代码之后,我开发了以下脚本,以便在objc_msgSend的每个中断处打印[].问题是在某些情况下data_NEVER_USE不是有效指针但也不是null.我可以找到关于类是否被初始化的唯一指标是ID-> data_NEVER_USE-> flags& RW_REAliZED.我在这里遗漏的类初始化的哪个方面可以让我跳过这个案例?

b objc_msgSendccommandssilentif (*$r0 == 0)    continueendset $ID = (class_t *)$r0set $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    endendif ($sel != 0)    printf "%s",$selelse    printf "null"endprintf "]\n"continueend

我很感激任何帮助.谢谢.

解决方法 这两种方法对我来说效果相当不错.请注意,在我的示例中,我手动启动“SomeApp”以便在启动时立即对其进行监控.

gdb(gdb) attach --waitfor 'SomeApp'**this is where you manually start SomeApp on your device**call (voID)instrumentObjcmessageSends(YES)

“instrumentObjcmessageSends”启用/禁用运行时内的消息记录.这是一些more information on this method.

另一个选项,仍然在你的IDevice上使用GDB,就是写一个这样的小命令:

FooPad:~ root# gdb(gdb) attach SBSettingsAttaching to process 440.Reading symbols for shared librarIEs . doneReading symbols for shared librarIEs ............................. done0x35686004 in mach_msg_trap ()(gdb) break objc_msgSendBreakpoint 1 at 0x3323ef72(gdb) commandsType 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) cContinuing.// a ton of information will follow

只要按下“c”(右上方的行显示“继续.”),您的屏幕将填充函数名称和参数.

最后按照these instructions在你的IDevice上获得一个可用的GDB.对于后代,我会在这里发布简短说明:

GNU DeBUGger (gdb) is used to analyze the run time behavior of an iOS
application. In recent iOS versions,GNU DeBUGger directly downloaded
from the Cydia is broken and not functioning properly. Following the
Pod 2g blog post also dID not help me.

To get rID of this problem,add 07002 to cydia source and download the latest GNU DeBUGger (build 1708). GDB build 1708 is working for iOS 5.x.

总结

以上是内存溢出为你收集整理的用于跟踪iOS设备上的Objective-C调用的GDB脚本 – 问题全部内容,希望文章能够帮你解决用于跟踪iOS设备上的Objective-C调用的GDB脚本 – 问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1064489.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存