Skip to content Skip to sidebar Skip to footer

How Do I Use Lldb To Debug C++ Code On Android On Command Line

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 artic

Solution 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    6510119680015747442 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:5045tcp: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

Solution 2:

  1. make sure your android phone is rooted Use /data/local/tmp directory on your android phone. Root previledge is not required.

  2. copy NDK provided lldb-server to your android phone, and start it by:

./lldb-server platform --listen "*:10086" --server

10086 is port number, you may change it

  1. Forward port by running:
adb forward tcp:10086 tcp:10086
  1. get device name by adb devices. For me, it's 39688bd9

  2. install LLVM with proper python (I use LLVM-11.0 with python3.6), and open lldb, typing these commands:

platform select remote-android
platform connectconnect://39688bd9:10086
  1. Now, you're connected with lldb-server, thus just use lldb like locally:
file some_exeutable_file_with_debug_info
bmain
r

Post a Comment for "How Do I Use Lldb To Debug C++ Code On Android On Command Line"