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:
- ¿Cómo utilizar la actividad nativa? ¿Se puede combinar con la actividad tradicional?
- Android NDK: ¿Cómo limpiar el código nativo después de reiniciar la actividad?
- Cómo utilizar OpenSSL Library en la aplicación ANDROID
- Cómo deshabilitar la aplicación nativa de Facebook para el inicio de sesión de usuario
- Múltiples módulos nativos en Android Studio
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?
- Android: incluye funciones nativas de StageFright en mi propio proyecto
- Usando "nativo reactivo" con nuestro código existente
- SIG33 al depurar el Android nativo
- Native Android Crash - Mapa de bits no válido
- React-Native, Android, Genymotion: El servidor ADB no ACK
- Passprops equivalente para Navigator?
- Desbordamiento Desplazamiento en Android no funciona?
- ¿Es posible crear elementos de interfaz de usuario con el NDK? - falta de especificaciones en documentos Android
No sé por qué gdb funciona con el binario por ndk-build, pero usa el comando file en lugar del comando symbol-file, podría funcionar. Gdb necesita conocer la imagen del programa ejecutado a distancia.
(gdb) file hello