LLDB调试技巧之image lookup

error: instance method 'methodName' has incompatible result types in different translation units ('methodName' (aka 'NSMutableDictionary *') vs. 'NSMutableDictionary *')
instance method 'methodName' also declared here

(lldb) po self
error: instance method 'operationDictionary' has incompatible result types in different translation units ('SDOperationsDictionary *' (aka 'NSMutableDictionary *') vs. 'NSMutableDictionary *')
instance method 'operationDictionary' also declared here
(lldb) 

开发过程中遇到一个调试问题。每次po 一个类及一个类的方法的时候总是给出上面的提示,导致命令不起作用。但是断点控制台能看到数据。就是LLDB po的时候出问题。

调用 image lookup –name methodName

(lldb) image lookup -name operationDictionary
        Summary: inke`-[UIView(NTalkerWebCacheOperation) operationDictionary] at UIView+NTalkerWebCacheOperation.m:16        Address: inke[0x000000010156ebc0] (inke.__TEXT.__text + 22446016)
        Summary: inke`-[UIView(WebCacheOperation) operationDictionary] at UIView+WebCacheOperation.m:25
(lldb) 

看到这个输出,就豁然明白了原因。是因为我们导入一个第三方库,这个库是静态库(.a库)。这个库里面也有一个UIView的分类叫NTalkerWebCacheOperation,里面有一个方法叫operationDictionary,但是这个分类没有暴露出来,完全是内部使用。然后我们导入了SDWebImage库,这个库里面也有一个分类

@implementation UIView (WebCacheOperation)

- (SDOperationsDictionary *)operationDictionary {
    SDOperationsDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
    if (operations) {
        return operations;
    }
    operations = [NSMutableDictionary dictionary];
    objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    return operations;
}

这两个分类方法重名了。隐藏在.a 静态库里面。

在这里介绍一个LLDB 一个调试命令----image lookup

  • image lookup –name,简写为image lookup -n。
  • 当我们想查找一个方法或者符号的信息,比如所在文件位置等。
  • image lookup –name,可以非常有效的定位由于导入某些第三方SDK或者静态库,出现了同名category方法(如果实现一样,此时问题不大。但是一旦两个行为不一致,会导致一些奇怪的bug)。顺便说下,如果某个类多个扩展,有相同方法的,app在启动的时候,会选择某个实现,一旦选择运行的过程中会一直都运行这个选择的实现。

感兴趣的话产考LLDB调试技巧

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • [转]浅谈LLDB调试器文章来源于:http://www.cocoachina.com/ios/20150126/...
    loveobjc阅读 2,617评论 2 6
  • 现在, 你已经有了坚实的调试基础.你可以找到并附加到你感兴趣的程序上, 高效的创建正则表达式断点来覆盖一个宽泛的范...
    股金杂谈阅读 1,381评论 0 1
  • LLDB的Xcode默认的调试器,它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能。平时用Xc...
    CoderSC阅读 1,401评论 0 2
  • 随着Xcode 5的发布,LLDB调试器已经取代了GDB,成为了Xcode工程中默认的调试器。它与LLVM编译器一...
    随风飘荡的小逗逼阅读 1,431评论 0 0
  • 壬辰秋月,余入太学之门,然习性刚正,与荒稽之徒为同以不堪,身处囹圄以难忍,且计簿之业非所好,盖去之。 癸巳蛇年春,...
    绘事后素2512阅读 415评论 5 1