How do I use lldb to debug C++ code on Android on command line

為{幸葍}努か 提交于 2019-12-12 18:25:02

问题


I am trying to figure out to debug my Android ndk project in c++, using the lldb debugger.

I am trying achieve this by using the command line only.

I can not seem to find any articles or documentation on how to use lldb along with adb to debug an app from the command line.


回答1:


Probably you can try below: (This example steps are based on macOS)

run gdb server and attach process

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

attach gdb debugger

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


来源:https://stackoverflow.com/questions/53733781/how-do-i-use-lldb-to-debug-c-code-on-android-on-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!