我试图找出使用lldb调试器在c ++中调试Android ndk项目的方法。
我正在尝试仅通过命令行来实现这一目标。
我似乎找不到关于如何使用lldb和adb从命令行调试应用程序的文章或文档。
答案 0 :(得分:1)
可能您可以尝试以下操作:(此示例步骤基于 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
答案 1 :(得分:0)
确保您的Android手机已植根
将NDK提供的lldb-server
复制到您的Android手机上,并通过以下方式启动:
./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