Gdb depura el programa nativo (no jni) en android

No pude depurar el programa nativo con cadena de herramientas de NDK. Los siguientes son mis pasos detallados y la salida.

Env Ambiente:

NDK_ROOT=/opt/android/ndk SYSROOT=$NDK_ROOT/platforms/android-8/arch-arm TOOLCHAIN=$NDK_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin PATH=$TOOLCHAIN:$NDK_ROOT:$PATH 

Fuente: hello.c

  1 #include <stdio.h> 2 3 int main() { 4 printf("Hello World!\n"); 5 return 0; 6 } 

Construido por la cadena de herramientas independiente proporcionada por NDK.

 #arm-linux-androideabi-gcc -g hello.c -o hello --sysroot $SYSROOT 

Empuje al emulador y comience el gdbserver (yo remite el puerto ya)

 #adb push hello /data/hello #adb shell gdbserver 10.0.2.15:10000 /data/hello 

Depurar remotamente en otro terminal:

 #arm-linux-androideabi-gdb #(gdb) target remote localhost:10000 Remote debugging using :10000 0xb0001000 in ?? () ------------------------------------what is this? #(gdb) symbol-file hello Reading symbols from hello...done. #(gdb) l 1 #include <stdio.h> 2 3 int main() { 4 printf("Hello World!\n"); 5 return 0; 6 } #(gdb) b main Breakpoint 1 at 0x8318: file hello.c, line 4. #(gdb) c Continuing. Program received signal SIGSEGV, Segmentation fault. -------It should be break at main function, but segmentation falut. 0xafd0f5f0 in ?? () #(gdb) bt #0 0xafd0f5f0 in ?? () 

Y lo pruebo con el estilo de NDK Android.mk, woks muy bien. Aquí está la salida

Android.mk

 1. LOCAL_PATH := $(call my-dir) 2. 3. include $(CLEAR_VARS) 4. 5. LOCAL_MODULE := hello 6. LOCAL_SRC_FILES := hello.c 7. LOCAL_MODULE_TAGS := optional 8. 9. include $(BUILD_EXECUTABLE) 

Construir, empujar al emulador, iniciar el servidor de depuración

  #ndk-build #push obj/local/armeabi/hello /data/hello #adb shell gdbserver 10.0.2.15:10000 /data/hello 

Debug remoto:

 #arm-linux-androideabi-gdb (gdb) target remote :10000 Remote debugging using :10000 0xb0001000 in ?? () --------------still here (gdb) symbol-file hello Reading symbols from hello...done. (gdb) l 1 #include <stdio.h> 2 3 int main() { 4 printf("Hello World!\n"); 5 return 0; 6 } (gdb) b main Breakpoint 1 at 0x8372: file hello.c, line 4. (gdb) c Continuing. Breakpoint 1, main () at hello.c:4 4 printf("Hello World!\n"); (gdb) c Continuing. Program exited normally. -------Yes, erverything is normal, Hello World is output. 

Todavía construir con Android.mk por ndk-build, cuando hago algo más en gdb remoto, todavía falló.

 (gdb) target remote :10000 Remote debugging using :10000 0xb0001000 in ?? () (gdb) symbol-file hello Reading symbols from hello...done. (gdb) l 1 #include <stdio.h> 2 3 int main() { 4 printf("Hello World!\n"); 5 return 0; 6 } (gdb) b main Breakpoint 1 at 0x8372: file hello.c, line 4. (gdb) next Cannot access memory at address 0x0 Cannot find bounds of current function (gdb) c Continuing. Breakpoint 1, main () at hello.c:4 4 printf("Hello World!\n"); (gdb) next 6 } (gdb) next Program received signal SIGSEGV, Segmentation fault. ------Again fault. And no "Hello World" output in gdbserver. 0x0000832c in ?? () (gdb) next Cannot find bounds of current function 

============================================================================== Unesdoc.unesco.org unesdoc.unesco.org

Estoy fresco en android, cualquiera puede decirme lo que está sucediendo?

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.