10

i do first steps in developing for Native Android and need some help. I copy armv7 gdbserver to my phone and compile "hello word" test app written with C++. And now i want to debug my app with gdb from android ndk package.

I start gdb and connect to phone by target remote command and get this messages and after "s" command gdb holds.

(gdb) target remote 192.168.1.157:1235
Remote debugging using 192.168.1.157:1235
Reading /data/local/Test from remote target...
warning: File transfers from remote targets can be slow. Use "set  sysroot" to access files locally instead.
Reading /data/local/Test from remote target...
Reading symbols from target:/data/local/Test...done.
Reading /system/bin/linker from remote target...
Reading /system/bin/linker from remote target...
Reading symbols from target:/system/bin/linker...(no debugging symbols found)...done.
0xb6fdf654 in __dl__start () from target:/system/bin/linker
(gdb) s
Single stepping until exit from function __dl__start,
which has no line number information.

What i'm doing wrong? Why it holds? And how generate symbols/debug info? I tried to set "set(CMAKE_BUILD_TYPE Debug)" but no new files were generated.

My CmakeLists.Txt

set(PROJECT_NAME Test)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_TOOLCHAIN_FILE android-cmake/android.toolchain.cmake)
set(ANDROID_NDK /home/drem1lin/Android/Sdk/ndk-bundle)


set(ANDROID_NATIVE_API_LEVEL "android-19")
set(ANDROID_TOOLCHAIN_NAME "arm-linux-androideabi-4.9")
set(ANDROID_ABI "armeabi-v7a")

project(${PROJECT_NAME}) 
cmake_minimum_required(VERSION 3.1)

include_directories(include)
file(GLOB SOURCES source/*.c*)
add_executable(${PROJECT_NAME} ${SOURCES})
foreach (module_src ${MODULES})
    get_filename_component(module ${module_src} NAME_WE)
    string(TOLOWER ${module} module)
    add_library(${module} SHARED ${module_src})
    set_target_properties(${module} PROPERTIES PREFIX "")
    set_target_properties(${module} PROPERTIES SUFFIX ".m")
    target_link_libraries(${module} ${LIBRARY_DEPS})
endforeach(module_src)

With best regards Paul.

drem1lin
  • 331
  • 1
  • 3
  • 14

4 Answers4

4

For those who uses the new NDK toolchain (not using Android.mk but add sections like externalNativeBuild in build.gradle), here is the steps:

Step1: Change build.gradle as follows.

NOTE: If your ndk is used in a library, then change your library's gradle file instead of your main application's.

android {
  defaultConfig {
    packagingOptions {
      doNotStrip '**.so'     // ADD THIS! #1
    }
    externalNativeBuild {
      cmake {
        cppFlags "-Wl,--build-id -g"     // ADD THIS! #2
      }
    }
  }
}

Step2: Build the project (for me it is flutter build apk --debug, but for native Android projects you know it).

Step3: Now your .so with symbols is here: (This is sample location, where the library name is vision_utils and my .so file name is libvision_utils.so)

./build/vision_utils/intermediates/cmake/debug/obj/arm64-v8a/libvision_utils.so

or

./build/vision_utils/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libvision_utils.so

Bonus1: If you want the "actual" .so file in apk, find it like unzip -p ./build/app/outputs/apk/debug/app-debug.apk lib/arm64-v8a/libvision_utils.so > ./build/temp-libvision_utils.so.

Bonus2: If you are using bloaty, you can run your command like: bloaty ./build/temp-libvision_utils.so --debug-file=./build/vision_utils/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libvision_utils.so -d compileunits

ch271828n
  • 15,854
  • 5
  • 53
  • 88
2

I have this trouble because I know linux build system very bad. Executible with symbols was created in {project}/obj/local/armeabi/ folder

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
drem1lin
  • 331
  • 1
  • 3
  • 14
0

If your compiler is gcc or clang, then simply pass the -g option when compiling to generate debug symbols.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • I have this -g compiler option set using clang 11 in NDK r22b but still Visual GDB not find debugging symbols... we have project generated in VS2022 building with Android NDK toolchain for ARM64. Not interested in using Gradle whatsoever, we use and for APK packaging, surely Ant has some doNotStrip thing also..... – Sixjac Mar 24 '22 at 04:58
0

I was able to add debug symbols to my ndk-build utility via the following lines:

LOCAL_CFLAGS := -g
LOCAL_STRIP_MODE := none
LOCAL_STRIP_MODULE := keep_symbols

I can confirm the symbols are there using objdump -Wi and gdb. Perhaps a set() on these variables with CMake will help under that build system.

reference: NOT strip debug symbols ndk-build

DraftyHat
  • 428
  • 1
  • 2
  • 6