|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ### 一、背景 调试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
相关推荐
PandaQue6 小时前
《怪物猎人:荒野》游戏可以键鼠直连吗白狐欧莱雅10 小时前
使用python中的pygame简单实现飞机大战游戏豆本-豆豆奶11 小时前
用 Python 写了一个天天酷跑(附源码)Leoysq14 小时前
【UGUI】实现点击注册按钮跳转游戏场景zsc_1181 天前
(C++回溯算法)微信小程序“开局托儿所”游戏中云DDoS CC防护蔡蔡2 天前
棋牌游戏防ddos攻击,高防IP好用吗?dangoxiba2 天前
[Unity Demo]从零开始制作空洞骑士Hollow Knight第十八集补充:制作空洞骑士独有的EventSystem和InputModuleToDesk_Daas2 天前
为什么越来越多人开始用云电脑?网友道出了真相虞书欣的62 天前
Python小游戏22——吃豆豆小游戏魔法自动机2 天前
Unity3D学习FPS游戏(9)武器音效添加、创建敌人模型和血条