android - 如何在命令行上使用 lldb 调试 Android 上的 C++ 代码

标签 android debugging android-ndk adb lldb

我正在尝试使用 lldb 调试器在 C++ 中调试我的 Android ndk 项目。

我试图通过仅使用命令行来实现这一点。

我似乎找不到任何关于如何使用 lldb 和 adb 从命令行调试应用程序的文章或文档。

最佳答案

也许您可以尝试以下方法:(此示例步骤基于 macOS )

运行 gdb 服务器并附加进程

//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

关于android - 如何在命令行上使用 lldb 调试 Android 上的 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53733781/

相关文章:

android - 在 Android 应用程序中存储 api-urls 的最佳方式是什么?

c# - 如何在 android xamarin 中动态地将按钮添加到 View ?

c++ - 如何获取调用方方法的名称或文件和行?

c - 使用 gdb 检查调用者帧

android - Android NDK 中的链接器错误(对 `__cxa_end_cleanup' 的 undefined reference )

android - Make.exe 访问被拒绝

Android - 自定义复合组件中的 View 未膨胀(findByView 返回 null)

android - 如何在编辑过程中更改 Android 中 Android EditText 的背景和字体颜色?

iphone - 使用通过 Dock 连接的外部配件调试 iOS 应用程序

java - Android studio启用方法建议并跳转到方法定义【NDK视角】