//Below commands will suspend the execution on the running app, and waits for a debugger to connect to it on port 5045.
adb shell
// to get pid
root@generic_x86:/ # ps | grep <your-app-name>
u0_a54 6510 1196 800157 47442 ffffffff b662df1b S
<your-app-name>
root@generic_x86:/ # gdbserver :5045 --attach 6510 (PID)
Attached; pid = 6510
Listening on port 5045
//The process is now suspended, and gdbserver is listening for debugging clients on port 5045.
附加gdb调试器
//open a new terminal, e.g. terminal2, send below commands from this new terminal
//forward the above port to a local port on the host with the abd forward command
adb forward tcp:5045 tcp:5045
//launch gdb client from your android ndk folder
<your-ndk-home>/android-ndk-r16b/prebuilt/darwin-x86_64/bin/gdb
//Target the gdb to the remote sever
(gdb) target remote :5045
//now the process is successfully attached with the application for debugging, you can see below info from terminal 1.
Remote debugging from host 127.0.0.1
# Get the pid of the process you are trying to debug
adb shell run-as <package_name> ps
lldb
> platform select remote-android
> platform connect unix-abstract-connect:///data/data/<package_name>/debug.socket
> attach <pid>
在shell窗口3中
# You will again need the pid of the process you are trying to debug
adb shell run-as <package_name> ps
adb forward tcp:12345 jdwp:<pid>
jdb -attach localhost:12345
3条答案
按热度按时间rqcrx0a61#
大概你可以试试下面的:(本示例步骤基于macOS)
运行gdb服务器和附加进程
附加gdb调试器
ryhaxcpt2#
1.请确保您的android手机是root使用您的android手机上的
/data/local/tmp
目录。不需要Root权限。1.将NDK提供的
lldb-server
复制到您的Android手机,并通过以下方式启动它:10086是端口号,可以更改
1.通过运行以下命令转发端口:
1.通过
adb devices
获取设备名称。对我来说,它是39688bd9
1.使用适当的python安装LLVM(我使用LLVM-11.0和python3.6),然后打开lldb,键入以下命令:
1.现在,您已连接到lldb-server,因此只需像在本地一样使用lldb:
yrefmtwq3#
使用android-ndk-r25 b,我有一些运气与以下:
在shell窗口1中
在shell窗口2中
在shell窗口3中
然后返回到在窗口2中运行的lldb,并继续您的过程
我发现这个脚本很有用:https://github.com/iivke/flutter_android_lldb/blob/main/flutter_lldb.py