|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ### 一、背景 调试ios程序经常使用gdb,但是gdb还未支持arm64,需要使用XCode的lldb调试IOS下64位程序。因为xcode默认调试工具是lldb,开始各种尝试在xcode中使用Debug-》Attach to Process 直接attach进程,但是只能看见进程却无法挂接。最终发现可以使用lldb命令行方式调试,lldb调试方法跟gdb最大的不同,在于前者是用OSX中的lldb远程连接debugserver,由debugserver作为lldb和iOS的中转,执行命令和返回结果;而后者是gdb直接运行在iOS上。但对于一般的开发、调试来说,区别不大。 ### 二、基本知识 首先了解下各个iphone对应的cpu类型,这些知识将在调试准备工作中用到: |-------------------------------|--------| | 设备 | Cpu类型 | | iPhone 4 | armv7 | | iPhone 4s | armv7 | | iPhone 5 | armv7s | | iPhone 5c | armv7s | | iPhone 5s | armv64 | | iPhone 6 | armv64 | | iPhone 6 Plus | armv64 | | iPad 2 | armv7 | | iPad mini | armv7 | | iPad with Retina display | armv7s | | iPad Air | armv64 | | iPad Air 2 | armv64 | | iPad mini with Retina display | armv64 | | iPad mini 2 | armv64 | | iPad mini 3 | armv64 | | iPad touch 5 | armvv7 | ### 三、lldb调试 #### 3.1 准备工作 #### 使用lldb调试需要准备服务端程序,即debugserver。在默认情况下,iOS上并没有安装debugserver,只有在设备连接过一次Xcode,并在Window-》Devices菜单中添加此设备后,debugserver才会被Xcode安装到iOS的"/Developer/usr/bin/"目录下。确定有了debugserver后再一次执行以下步骤: #### 1、拷贝debugserver到本地计算机中: scp root@iOSDeviceIP:/Developer/usr/bin/debugserver ~/debugserver 2、由于ldid不支持的fat二进制文件,所以要给debugserver瘦身,通过lipo指定要支持的指令类型,以arm64为例: lipo -thin arm64 ~/debugserver -output ~/debugserver 3、给debugserver添加task_for_pid权限,保存以下内容为ent.xml文件: com.apple.springboard.debugapplications get-task-allow task_for_pid-allow run-unsigned-code 然后执行以下命令添加权限: ldid -Sent.xml debugserver 4、给debugserver重新签名,保存以下内容为entitlements.plist文件: com.apple.springboard.debugapplications run-unsigned-code get-task-allow task_for_pid-allow 然后运行以下命令给的debugserver签名: codesign -s - --entitlements entitlements.plist -f debugserver 5、到此准备工作完成,重新拷贝debugserver回手机中: scp ~/debugserver root@iOSDeviceIP:/usr/bin/debugserver #### 3.2 调试 利用的lldb调试首先需要的启动debugserver的并,attach到要调试的进程,然后在通过lldb连接debugserver,具体步骤如下: 1、 从shell登录ios设备: ssh root@iOSDeviceIP 然后会提示输入root密码,输入即可,如下图所示: 2、 如果是第一次使用还需给debugserver添加可执行属性: chmod +x /usr/bin/debugserver 3、 接下来直接使用debugserver来attach一个进程,debugserver命令行格式如下: debugserver [] host: [ ...] 其中各个参数选项如下: |-------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Option | Effect | | -a process | Attach debugserver to process . The process can be a pid or executable name. | | -d integer | Assign the waitfor-duration. | | -f ? | ? | | -g | Turn on debugging. | | -i integer | Assign the waitfor-interval. | | -l filename | Log to file. Set filename to stdout to log to standard output. | | -t | Use task ID instead of process ID. | | -v | Verbose. | | -w ? | ? | | -x method --launch=method | How to launch the program. Can be one of: ·auto: Auto-detect the best launch method to use. ·fork: Launch program using fork(2) and exec(3). ·posix: Launch program using posix_spawn(2). ·backboard: Launch program via BackBoard Services. | | --lockdown | Obtain parameters from lockdown (?) | 其中最常用的参数为-a,后接进程名或进程pid,命令如下: debugserver *:1234 -a "Clover" debugserver *:1234 -a 444 至此ios设备端操作完毕。 4、 另打开一个shell,启动lldb客户端,直接输入lldb进入lldb命令行模式。 5、 在lldb命令行的连接debugserver: process connect connect://iOSDeviceIP:1234 在我实际使用过程中,此操作需要较长时间,连接成功后如下图所示: 6、 接下来就是一系列lldb相关命令操作: ### 四、lldb & gdb命令 可能大家使用较多的是gdb,对gdb命令更为熟悉,为了方便大家查阅、对比lldb和gdb命令,罗列出了一些常用命令供大家参考。 EXECUTION COMMANDS |---------------------------|-------------------------------------------------------| | GDB | LLDB | | Launch a process no arguments. || | (gdb) run (gdb) r | (lldb) process launch (lldb) run (lldb) r | | Launch a process with arguments . || | (gdb) run (gdb) r | (lldb) process launch -- (lldb) r | | Launch a process for with arguments a.out 1 2 3 without having to supply the args every time. || |
iOS 64位程序调试环境搭建
douluo9982024-04-24 15:38
相关推荐
螺旋天光极锐斩空闪壹式!15 分钟前
自制游戏:监狱逃亡天晟科技25 分钟前
GameFi的前景:游戏与金融的未来交汇点懷淰メ2 小时前
PyQt飞机大战游戏(附下载地址)/**书香门第*/6 小时前
Cocos creator 3.8 支持的动画 7九州ip动态9 小时前
做网络推广及游戏注册为什么要换IP向宇it20 小时前
【unity小技巧】unity 什么是反射?反射的作用?反射的使用场景?反射的缺点?常用的反射操作?反射常见示例九州ip动态1 天前
模拟器多开限制ip,如何设置单窗口单ip,每个窗口ip不同St_Ludwig1 天前
C语言 蓝桥杯某例题解决方案(查找完数)qq_428639612 天前
植物明星大乱斗15vir022 天前
好奇怪的游戏(BFS)