Android GDB Debugging

Source: Internet
Author: User

Original address: Https://github.com/mapbox/mapbox-gl-native/wiki/Android-debugging-with-remote-GDB Android debugging with Remote Gdbleith Bade edited this page on Sep 15, 2015 • Revisions Pages -
    • Home
    • Android 4.x to 5.0 update
    • Android Debugging with Remote GDB
    • Android GL must reads
    • Android NDK Bugs
    • Bitrise Workflow Details
    • Contributing
    • Getting line numbers from an Android crash
    • GPUs
    • OpenGL Docs
    • Prototyping with Framer.js
    • Releasing the Mapbox IOS SDK
    • Setting up Mapbox Checkstyle
    • Strategies to reduce Android APK size
    • Symbolicating Android crashes
    • Show 3 More pages ...
Clone this wiki locallyClone in Desktoppreparation
    1. Install Android Studio, SDK and NDK, including build tools and platform tools.
    2. Ensure and is on android-sdk/tools android-sdk/platform-tools yourPATH
    3. Build the app with:BUILDTYPE=Debug make android
    4. Connect your device via USB
    5. Check your can connect to the device by running adb shell . You should get the terminal from your device.
    6. Exit withexit
Extract system binaries from device

(You'll need to does this for every device and every Android OS version)

    1. Create A folder to hold the Android system binaries locally e.g.  ~/android
    2. cd< /code> into the folder
    3. Create a  system_lib  and  vendor_lib  folder
    4. cd system_lib
    5. adb pull/system/lib
    6. CD. /vendor_lib
    7. adb pull/vendor/lib . If You get permissions error, you'll need to get a list of each file and folder in  adb shell  then Copy each of the file one at a time with  adb pull/vendor/lib/file
    8. CD:
    9. adb pull/system/bin/app_process   (or on phones  adb pull/system/bin/app_ Process32  and  adb pull/system/bin/app_process64 )
    10. adb pull/system/bin /linker   (and on phones  bit; adb pull/system/bin/linker64 )
Install GDB Server
    1. Go to the NDK folder.
    2. Copy from to gdbserver android-ndk/prebuilt/android-arm/gdbserver/gdbserver mapbox-gl-native/android/java/MapboxGLAndroidSDK/src/main/jniLibs/armeabi-v7a/gdbserver.so IMPORTANT It must is renamed a. so file
    3. Build and run the app in Android Studio
    4. Android Studio would copy and install the APK with Gdbserver on it to your device
Start the app paused
    1. Open the project in Android Studio
    2. Place a breakpoint in Java class NativeMapView constructor on nativeCreate line
    3. Start app with Run, Debug
    4. Wait for app to start and hit breakpoint
    5. Open up Logcat and look for output from app
    6. Note the process ID e.g. in 11-08 19:25:52.957 31834-31834/com.mapbox.mapboxgl.app V/FragmentActivity﹕ onCreate it is31834
Start Gdbserver
    1. Open a terminal
    2. Runadb forward tcp:5039 localfilesystem:/data/data/com.mapbox.mapboxgl.testapp/debug-pipe
    3. Run adb shell run-as com.mapbox.mapboxgl.testapp /data/data/com.mapbox.mapboxgl.testapp/lib/gdbserver.so +debug-pipe --attach 31834 . Replace with the 31834 process ID from earlier. ( you'll need to does this all time you restart the app as the PID would change)

If you get the error ' then you have a version of Android not compatible with adb run-as '. See [This page] for information. It appears to affect Android updates in 4.2.2, 4.3, 5.0, 5.1.1. Workaround appears to is to load a fresh image.

You should see:Attached; pid = 31834 Listening on sockaddr socket debug-socket

    1. Leave the terminal open
Start GDB
  1. Open another terminal
  2. Go to the NDK folderandroid-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
  3. On the OSX useandroid-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
  4. Run./arm-linux-androideabi-gdb ~/android/app_process
  5. target remote :5039
  6. In GDB:set solib-search-path ~/android/:~/android/system_lib:~/android/vendor_lib:~/android/vendor_lib/egl:~/path/to/mapbox-gl-native/build/android-arm-v7/Debug/lib.target/
  7. Check the debug symbols were loaded withinfo sharedlibrary
  8. Check each of the. So had except for the last Yes (*) libmapbox-gl.so which must had only Yes i.e. (no star). If not double check yoursolib-search-path
  9. b jni.cpp:183(The first line of nativeCreate )
  10. c
  11. Switch to Android Studio
  12. Click Run, Resume program
  13. Switch back to GDB. It should is paused atnativeCreate
  14. GDB now have control, so would c continue execution (set breakpoints first) Note:if you encounter this crash:
Program received signal Sigill, illegal instruction.0x7956a3a8 in _armv7_tick () from/home/leith/dev/ Mapbox-gl-native-mason/build/android/out/debug/lib.target/libmapbox-gl.so (GDB) bt#0 0x7956a3a8 in _armv7_tick () From/home/leith/dev/mapbox-gl-native-mason/build/android/out/debug/lib.target/libmapbox-gl.so#1 0X795D1CCC in Openssl_cpuid_setup () from/home/leith/dev/mapbox-gl-native-mason/build/android/out/debug/lib.target/ Libmapbox-gl.so#2 0x400bd9c6 in?? () From/home/leith/dev/android/linker#3 0x400bda9e in?? () From/home/leith/dev/android/linker#4 0x400bdbf0 in?? () from/home/leith/dev/android/linker#5 0x400bdc6e in?? () from/home/leith/dev/android/linker#6 0x400bc1a6 in _start () from/home/leith/dev/android/linker#7 0x41643c86 in DVM Loadnativecode (char const*, object*, char**) () From/home/leith/dev/android/system_lib/libdvm.so#8 0x416600f4 in?? () from/home/leith/dev/android/system_lib/libdvm.so#9 0x41613ee8 in Dvmjittointerpnochain () from/home/leith/dev/aNdroid/system_lib/libdvm.so#10 0x41613ee8 in Dvmjittointerpnochain () from/home/leith/dev/android/system_lib/ Libdvm.sobacktrace stopped:previous frame identical to this frame (corrupt stack?)

You just need to c past it to the real crash. From https://bugs.launchpad.net/raspbian/+bug/1154042:

AFAICT OpenSSL probes the capabilities of the user ' s CPU by trying to do things and trapping the illegal instruction error S. So a couple of sigills during startup is normal. When using a debugger on order to find the real failure in your application you must continue past the startup Sigills. Use GDB commands to debug

Read http://condor.depaul.edu/glancast/373class/docs/gdb.html for GDB commands

Android GDB Debugging

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.