Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate debug symbols for android native app?

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.

like image 507
drem1lin Avatar asked Jan 23 '17 17:01

drem1lin


Video Answer


2 Answers

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

like image 156
ch271828n Avatar answered Nov 13 '22 06:11

ch271828n


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

like image 24
drem1lin Avatar answered Nov 13 '22 07:11

drem1lin