image在Windows中称为镜像。
在lldb中为可执行文件和共享库查询命令。
1.如何查看image命令和相应子命令的描述
2.image list命令解析
3.image lookup命令解析
1.如何查看image命令和相应子命令的描述
lldb下通过image help 查看image命令描述

查看子命令描述
help <command> <subcommand>
如help image list

2.image list命令解析
image list用来查看工程中可执行image和依赖的共享库image。


image list在我的工程里列出了464条,第一条是我们的app的可执行文件,第二条和后面是相关的库。通过image list也可以看到相关库的内存地址。
3.image lookup命令解析

- image lookup 可以用来查找可执行文件或共享库的原始地址,当程序崩溃的时候,可以使用这条命令来查找崩溃所在的具体位置
如下代码
NSArray *array = @[@1, @2];
NSLog(@"item 3: %@", array[3]);
运行崩溃信息如下:

在模拟器崩溃到哪一行是可以看到的,在真机上和调试别人代码是看不到的,在真机上是一堆地址,如上图所示。
上述crash根据call调用栈信息如何定位到具体哪行代码出现问题:
image lookup -a 地址 = image lookup --address 地址

Address: RunLoop--ConfiguringRunloopSources[0x0000000100005974] (RunLoop--ConfiguringRunloopSources.__TEXT.__text + 588)
Summary: RunLoop--ConfiguringRunloopSources`-[ViewController memoryAnalyse] + 368 at ViewController.m:65
最后可以看到是ViewController.m的第65行导致的崩溃
- image lookup —type 类型 查看具体的类型 相当于把对应类型的头文件拿出来,快速查看类的所有信息

image命令还有许多其它功能,具体可以参考Executable and Shared Library Query Commands。
网友评论