一步一步用debugserver + lldb代替gdb进行动态调试

你试试用lldb-310.2.37调试时指令显示得对不对,我这边是有问题的,怀疑就是lldb的问题

换回Xcode 5.0.2后,lldb版本为300.2.53,问题解决。我猜测lldb-310.x.x有bug

~ root# debugserver *:1234 -a “SpringBoard”
debugserver-199 for armv7.
Listening to port 1234…
到这里touch 卡住了,不响应触摸,home键也没反应等了几分钟,白屏了一下,然后自己重启了

((lldb) process connect connect://iOSIP:1234
error: Connection refused
(lldb)
这是怎么回事?touch 4th,iOS 6.1.6

第一个问题,是因为你attach了SpringBoard,自然SpringBoard就卡住了。而SpringBoard响应一旦超时就要被watchdog给kill掉,所以造成了这种现象。解决这种现象的方法就是赶紧在OSX上用lldb连过去开始调试:tongue:
第二个问题,把这里的iOSIP换成你iOS的实际IP地址啊啊啊啊啊啊啊!不然连不过去,造成了第一个问题……

嗯,是这样的,谢谢

我用arm64瘦身就正常了

你说的指令不正确是指什么?我试试~

我用lldb打印指令,如x/10i 和IDA的差很多,这个好像是针对固定指令长度的~- -!

画瓢成功:lol:

我说的指令不正确就是arm和thumb混了,比如IDA里显示的是MOV R1, R5,lldb里显示的是一些不认识的thumb指令,还有一堆“unknown code”。结果我删了Xcode 5.1.1,装回5.0.X,把lldb版本降下来就好了

那5.1.1的lldb的确有问题。
我也是这样子的。不过其他应该正常,除了反汇编比较诡异~

((lldb) process connect connect://iOSIP:1234时,因为我是在虚拟机上连接iDevice进行调试的,没有wifi,是不是就不能进行调试了。

参考一下这个帖子,如果USB能识别应该就可以

我参考了你的那个用usbmuxd方法的帖子,但当执行到process connect connect://127.0.0.1:1234结果是Process 0 connected

等待监听端报得错是下面:
Incoming connection to 1234
Waiting for devices…
Connecting to device <MuxDevice: ID 5 ProdID 0x12a4 Serial ‘899b609353e8aa081f2ffa8444d7532393c21ce9’ Location 0x3100000>

Exception happened during processing of request from (‘127.0.0.1’, 49825)
Traceback (most recent call last):
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”, line 582, in process_request_thread
self.finish_request(request, client_address)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”, line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”, line 639, in init
self.handle()
File “./tcprelay.py”, line 82, in handle
dsock = mux.connect(dev, self.server.rport)
File “/opt/tool/usbmuxd/python-client/usbmux.py”, line 235, in connect
return connector.connect(device, port)
File “/opt/tool/usbmuxd/python-client/usbmux.py”, line 206, in connect
raise MuxError(“Connect failed: error %d”%ret)
MuxError: Connect failed: error 3

Incoming connection to 1234
Waiting for devices…
Connecting to device <MuxDevice: ID 5 ProdID 0x12a4 Serial ‘899b609353e8aa081f2ffa8444d7532393c21ce9’ Location 0x3100000>

Exception happened during processing of request from (‘127.0.0.1’, 49826)
Traceback (most recent call last):
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”, line 582, in process_request_thread
self.finish_request(request, client_address)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”, line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”, line 639, in init
self.handle()
File “./tcprelay.py”, line 82, in handle
dsock = mux.connect(dev, self.server.rport)
File “/opt/tool/usbmuxd/python-client/usbmux.py”, line 235, in connect
return connector.connect(device, port)
File “/opt/tool/usbmuxd/python-client/usbmux.py”, line 206, in connect
raise MuxError(“Connect failed: error %d”%ret)
MuxError: Connect failed: error 3

你能通过USB ssh到iOS去吗?

可以的,通过ssh连接上了iDevice,并运行的DebugServer

注意到这个报错

Exception happened during processing of request from ('127.0.0.1', 49825)

你指定的端口是1234,而显示的端口号49825,是不是说明真机连过来的端口还是错了?
那我觉得有可能是虚拟机的问题,因为虚拟机的USB接口也是模拟出来的,我不确定它是不是原封不动地转发真机USB接口上的数据。你可以查查看你用的虚拟机有没有这种设置端口转发的功能,我猜是这里的问题

我看了我的虚拟机有端口转发的功能,要怎么设置呢

我运行完debugserver *:1234 -a "SpringBoard"后显示是:
Administratormato-iPad:~ root# debugserver *:1234 -a “SpringBoard”
debugserver-64 for armv6 Copyright (c) 2007-2009 Apple, Inc. All Rights Reserved.

后面就什么都没有了,这里不对,是吧

22转22,1234转1234

应该有问题,我印象我的debugserver执行完之后输出不止一行

我把详细过程写下来:
1、lipo -thin armv7s /path/to/debugserver -output /path/to/debugserver
wls-Mac:tool wl$ lipo -thin armv7 debugserver -output /debug/debugserver
lipo: input file (debugserver) must be a fat file when the -thin option is specified
直接跳过瘦身,ldid应该支持
2、wls-Mac:tool wl$ ./ldid -S/ent.xml /debug/debugserver
minimal/mapping.h(54): _assert(false); errno=2
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
前面签名都过了,今天又冒出这个错,疯了