LLDB调试

Linux

通过sdkmanager来安装:sdkmanager  |  Android Studio  |  Android Developers

如何debug Android Native程序

Andoird  NDK 编译的Native 可执行程序的如何debug:主要是结合lldb和lldb-server来debug手机上的c++ native程序。

debugging - How do I use lldb to debug C++ code on Android on command line - Stack Overflow

除了上述的内容之外,如果要设置可执行程序的环境变量可以在lldb的交互式命令行下面执行

env LD_LIBRARY_PATH= ""

同时可执行程序编译的时候需要:加上-g

cmake 的方式如下:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
  1. Preparation
  • Prepare an android device(Root privilege is not required, we will use its /data/local/tmp directory).
  • Install NDK, CMake, Ninja, adb, lldb, and put them in PATH env var.
  1. Compile program with debugging info (i.e. keep the -g flag) After compilation, copy them to your device’s /data/local/tmp directory.
  2. Copy NDK provided lldb-server to device Copy NDK provided lldb-server to your android phone(prefer the 64bit one),
adb push ./toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/9.0.9/lib/linux/aarch64/lldb-server /data/local/tmp
# and start it by
./lldb-server platform --listen "*:10086"--server

10086 is port number, you may change it.

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

Install LLDB, adding its binary to PATH, typing these commands:

# 首先进入到交互式
lldb

# 随后执行platform连接remote.
platform select remote-android
platform connect connect://39688bd9:10086

Among whith, 39688bd9 is my device id, 10086 is the port that I choose in previous steps.

  1. Use LLDB

Now, you’re connected with lldb-server, thus just use lldb like locally:

env LD_LIBRARY_PATH="./"
file test_ControlNet
run --injected_file_path ./injected.controlnet.properties --prompt_list_file_path /data/local/tmp/ControlNetData/sample_prompt_list.txt
b main
r

VSCode远程调试

codelldb/MANUAL.md at v1.10.0 · vadimcn/codelldb (github.com)