iOS 64位程序调试环境搭建

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ### 一、背景 调试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. || |

相关推荐
双叶83613 小时前
(C语言)单链表(1.0)(单链表教程)(数据结构,指针)
c语言·开发语言·数据结构·算法·游戏
二狗哈16 小时前
go游戏后端开发21:处理nats消息
开发语言·游戏·golang
前端菜鸟日常16 小时前
HMTL+JS+CSS实现贪吃蛇游戏,包含有一般模式,困难模式,还有无敌模式
javascript·css·游戏
火一线1 天前
【Framework-Client系列】UIGenerate介绍
游戏·unity
二狗哈1 天前
go游戏后端开发22:游戏房间功能
游戏·github
BingLin-Liu2 天前
蓝桥杯备考---》贪心算法之矩阵消除游戏
算法·游戏·贪心算法
苹果企业签名分发2 天前
游戏搭建云服务器配置推荐
运维·服务器·游戏
二狗哈3 天前
go游戏后端开发20:房间消息推送处理
开发语言·游戏·golang
fatiaozhang95273 天前
晶晨S905L3A(B)-安卓9.0-开启ADB和ROOT-支持IPTV6-支持外置游戏系统-支持多种无线芯片-支持救砖-完美通刷线刷固件包
android·游戏·adb·华为·电视盒子·机顶盒rom·魔百盒固件
腾讯安全应急响应中心3 天前
命悬生死线:当游戏遭遇DDoS围剿,如何用AI破局?
网络·人工智能·游戏·ddos