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调试技巧之image lookup)