识字粗堪供赋役,不须辛苦慕公卿。这篇文章主要讲述Android GDB 调试相关的知识,希望能为你提供帮助。
原文地址:https://github.com/mapbox/mapbox-gl-native/wiki/Android-debugging-with-remote-GDB
android debugging with remote GDB
Leith Bade edited this page
on Sep 15, 2015
·
17 revisions
Pages
18
- 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…
- Install Android Studio, SDK and NDK, including build tools and platform tools.
- Ensure
android-sdk/tools
andandroid-sdk/platform-tools
are on yourPATH
- Build the app with:
BUILDTYPE=Debug make android
- Connect your device via USB
- Check you can connect to the device by running
adb shell
. You should get the terminal from your device. - Exit with
exit
- Create a folder to hold the Android system binaries locally e.g.
~/android
cd
into the folder- Create a
system_lib
andvendor_lib
folder cd system_lib
adb pull /system/lib
cd ../vendor_lib
adb pull /vendor/lib
. If you get permissions error you will need to get a list of each file and folder inadb shell
then copy each file one at a time withadb pull /vendor/lib/file
cd ..
adb pull /system/bin/app_process
(or on 64 bit phonesadb pull /system/bin/app_process32
andadb pull /system/bin/app_process64
)adb pull /system/bin/linker
(and on 64 bit phonesadb pull /system/bin/linker64
)
- Go to the NDK folder.
- Copy
gdbserver
fromandroid-ndk/prebuilt/android-arm/gdbserver/gdbserver
tomapbox-gl-native/android/java/MapboxGLAndroidSDK/src/main/jniLibs/armeabi-v7a/gdbserver.so
IMPORTANT it must be renamed a .so file - Build and run the app in Android Studio
- Android studio will copy and install the APK with gdbserver in it to your device
- Open the project in Android Studio
- Place a breakpoint in Java class
NativeMapView
constructor onnativeCreate
line - Start app with Run -> Debug
- Wait for app to start and hit breakpoint
- Open up logcat and look for output from app
- Note the process ID e.g. in
11-08 19:25:52.957 31834-31834/com.mapbox.mapboxgl.app V/FragmentActivity﹕ onCreate
it is31834
- Open a terminal
- Run
adb forward tcp:5039 localfilesystem:/data/data/com.mapbox.mapboxgl.testapp/debug-pipe
- Run
adb shell run-as com.mapbox.mapboxgl.testapp /data/data/com.mapbox.mapboxgl.testapp/lib/gdbserver.so +debug-pipe --attach 31834
. Replace31834
with the process ID from earlier. (You will need to do this each time you restart the app as the PID will change)
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 be to load a fresh image.You should see:
Attached;
pid = 31834 Listening on sockaddr socket debug-socket
- Leave the terminal open
- Open another terminal
- Go to the NDK folder
android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
- On OSX use
android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
- Run
./arm-linux-androideabi-gdb ~/android/app_process
target remote :5039
- 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/
- Check that all the debug symbols were loaded with
info sharedlibrary
- Check each .so has
Yes (*)
except for the lastlibmapbox-gl.so
which must have onlyYes
i.e. (no star). If not double check yoursolib-search-path
b jni.cpp:183
(the first line ofnativeCreate
)c
- Switch to Android Studio
- Click Run -> Resume Program
- Switch back to GDB. It should be paused at
nativeCreate
- GDB now has control, so
c
will 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
#00x7956a3a8 in _armv7_tick () from /home/leith/dev/mapbox-gl-native-mason/build/android/out/Debug/lib.target/libmapbox-gl.so
#10x795d1ccc in OPENSSL_cpuid_setup () from /home/leith/dev/mapbox-gl-native-mason/build/android/out/Debug/lib.target/libmapbox-gl.so
#20x400bd9c6 in ?? () from /home/leith/dev/android/linker
#30x400bda9e in ?? () from /home/leith/dev/android/linker
#40x400bdbf0 in ?? () from /home/leith/dev/android/linker
#50x400bdc6e in ?? () from /home/leith/dev/android/linker
#60x400bc1a6 in _start () from /home/leith/dev/android/linker
#70x41643c86 in dvmLoadNativeCode(char const*, Object*, char**) () from /home/leith/dev/android/system_lib/libdvm.so
#80x416600f4 in ?? () from /home/leith/dev/android/system_lib/libdvm.so
#90x41613ee8 in dvmJitToInterpNoChain () from /home/leith/dev/android/system_lib/libdvm.so
#10 0x41613ee8 in dvmJitToInterpNoChain () from /home/leith/dev/android/system_lib/libdvm.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
【Android GDB 调试】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 errors. So a couple of sigills during startup is normal. When using a debugger in order to find the real failure in your application you must continue past the startup sigills. 14. Use GDB commands to debugRead http://condor.depaul.edu/glancast/373class/docs/gdb.html for GDB commands
推荐阅读
- Android SDK初体验
- 安卓7.0遇到 android.os.FileUriExposedException: file:///storage/emulated.. exposed beyond app through In
- Android(图解四种启动模式 及 实际应用场景讲解)
- android 四则运算
- 简单的Android四则运算
- 有瑕疵的Android四则运算
- Frameworks detected: Android framework is detected in the project
- Android 6.0版本以后运行时权限提醒
- Android的学习总结