【发布时间】:2019-05-13 00:18:11
【问题描述】:
我正在尝试使用 lldb 调试器在 C++ 中调试我的 Android ndk 项目。
我正在尝试仅使用命令行来实现这一点。
我似乎找不到任何关于如何使用 lldb 和 adb 从命令行调试应用程序的文章或文档。
【问题讨论】:
标签: android debugging android-ndk adb lldb
我正在尝试使用 lldb 调试器在 C++ 中调试我的 Android ndk 项目。
我正在尝试仅使用命令行来实现这一点。
我似乎找不到任何关于如何使用 lldb 和 adb 从命令行调试应用程序的文章或文档。
【问题讨论】:
标签: android debugging android-ndk adb lldb
或许您可以尝试以下方法:(此示例步骤基于 macOS)
//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.
//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
【讨论】:
target remote :5045的lldb命令是gdb-remote localhost:5045。 lldb 可以与通用 gdbserver 通信,因此 shizen 的说明应该可以正常工作,只需将 gdb 替换为 lldb 命令即可连接。
确保你的安卓手机已经root
在你的安卓手机上使用/data/local/tmp 目录。不需要 root 权限。
将 NDK 提供的lldb-server 复制到您的安卓手机,然后通过以下方式启动它:
./lldb-server platform --listen "*:10086" --server
10086是端口号,你可以改一下
adb forward tcp:10086 tcp:10086
通过adb devices 获取设备名称。对我来说,是39688bd9
用正确的 python 安装 LLVM(我使用 LLVM-11.0 和 python3.6),然后打开 lldb,输入以下命令:
platform select remote-android
platform connect connect://39688bd9:10086
file some_exeutable_file_with_debug_info
b main
r
【讨论】: