如何解决查找已陷入困境的方法
如果我正在使用lldb调试Mach-O二进制文件,那么可以检查内存中的哪些数据结构以确定是否有任何方法混乱?我可以执行任何步骤吗?
还有,有没有办法以编程方式确定是否有任何方法陷入困境?
解决方法
自从您提到lldb
以来,您可以在以下位置设置符号断点:
b method_exchangeImplementation
b method_setImplementation
b class_replaceMethod
当您达到以下条件的断点时:method_exchangeImplementations(Method _Nonnull m1,Method _Nonnull m2)
您可以像这样检查m1
m2
args选择器名称:
po (SEL)method_getName($arg1)
po (SEL)method_getName($arg2)
对于method_setImplementation(Method _Nonnull m,IMP _Nonnull imp)
:
po (SEL)method_getName($arg1)
对于class_replaceMethod(Class cls,SEL name,IMP imp,const char *types)
po $arg1
po (SEL)method_getName($arg2)
这些Method
可能是通过先前的调用产生的:
class_getInstanceMethod(Class _Nullable cls,SEL _Nonnull name)
class_getClassMethod(Class _Nullable cls,SEL _Nonnull name)
如此之后:
b class_getInstanceMethod
b class_getClassMethod
并击中各自的断点,以检查课程:
po $arg1
检查选择器:
po (SEL)method_getName($arg2)
设置这些符号断点的最佳位置是在这里:
__attribute__((constructor))
static void premain() {
int i = 0;
i++; // put xcode breakpoint here and when hit prep your lldb symbolic bps
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。