I. BACKGROUND
First of all, this requirement is very common, that is, the need for Android, Linux has open source code and very stable, want to directly porting the past use, this program is pure C code, that is, with the Android framework, Java It doesn't matter, it has nothing to do with JNI, we want to be able to compile into an executable tool that can be used to run directly to Android.
Since it is the native code, the main impact is bionic libc, because this base library of Android with the common GNU libc Linux, is mainly streamlined, as far as the more specific understanding of what is called streamlining, it is recommended to find a Linux open source tool code in Android NDK Environment to know, in fact, this also hides the other two layers of difference, one is the Android API level, is the so-called Android version, such as Android 4.4.4 corresponding to Android API, Android 5 corresponding to Android API 21, different versions of Bionic libc itself is also a difference. The other is the ABI, is the difference between the architecture, such as x86, x86_64, armeabi-v7a, and so on, different ABI settings bionic libc use of the interface is not the same. The above two effects will cause your code to be compiled in API 21, but failed in API 19, or, at armeabi-v7a, but failed in arm64-v8a. This two-point treatment is placed in an additional article stating that this article is not considered. It can be argued that we temporarily do not consider the generality of compiled tools, only run on specific targets such as Abi = armeabi-v7a, API = 21 on Android devices.
All right, we've made it. This tool, push to target device (or emulator) found that the operation of a segment error, this is very common, because during the migration process, we have some glibc call to replace the bionic call, then how to debug it? First of all, the debugging here, of course, is the source level of one-step debugging, is that we develop and debug the program on Linux. The request seemed simple, but I searched for a day, tried a variety of ways, and finally found a simple way to match the requirements.
Second, the method
First of all, try to search Gdb-for-arm tool, is to see if there is a gdb executable, can be directly on the Android arm devices run, if any, and directly in the Linux environment debugging the same, unfortunately, so simple requirements, can not search
Here are the ways to try remote debugging
First, the client is in Win7. Using Ida Pro 6.6, it provides a android_server that can be used to push to the Android system, and then run the remote executable in the IDA interface, which can run, step into, and break the following breakpoints, but cannot add Load the correct symbol table.
Second, the client in Win7, found a Http://gnutoolchains.com/android/for Android compiled GNU tool chains website, download Gdbserver and Gdb.exe, Gdbserver p Ush to the target machine to run, the local start with Gdb.exe, using GDB remote debugging that set of steps to find out is able to run up, or can not load the symbol table correctly.
Third, customers in Win7, using Cygwin way to run GDB client, after the start of Cygwin reported a long length of the problem, did not go deep to solve
From here, suddenly to start GDB client under Win7 Some disappointment, and then to start the GDB client in ubuntu14.04, the Android emulator is also launched in Ubuntu. Ubuntu here runs in VMware on the Win7. Specifically, if you download and configure the Android SDK development environment in UBUTNU, and create an AVD, launch the AVD, you can search from the Internet and eventually start an Android emulator normally in Ubuntu.
Then, using the following method, it is possible to debug the source code in one step:
1. Deploying Gdbserver on the device the so-called deployment is actually to copy the Gdbserver under the ANDROID NDK to the device, which can be ordered by ADB push $ANDROID _ndk_root/prebuilt/android-arm/ Gdbserver/gdbserver/data 2. Deploying your native program on your device requires you to deploy your compiled programs and related so libraries to your device, noting that so libraries are placed under/system/lib,/system paths are read-only by default and can be reset by adb remount. ADB push./MYAPP/DATA/DATAADB push./libmylib.so/system/lib 3. Copy the relevant debugging environment on the device to local because remote debugging requires some target machine libraries, copy the following files to the local folder adb pull/system/lib./debugging/libadb pull/system/bin/linker. Debugging/lib 4. Run your program on the device via gdbserver adb shell gdbserver:12345/data/data/myapp 5. Local TCP ports are forward locally to the TCP port of the device adb forward tcp:12345 tcp:12345 6. GDB program $android_ndk/toolchains/arm-linux-androideabi-4.4.3/prebuild/darwin-x86/bin/running on-premises ANDROID NDK Path Arm-linux-androideabi-gdb here Note that if you use the Linux NDK package under Ubuntu, the path will be a bit different, and the darwin-x86 should be linux-x86. The most insured thing is to search under the NDK. 7. After starting GDB, setting the Solib search path under GDB means that GDB will be able to find the debug-related lib, which is the file that was pulled from the device in the third step. (GDB) Set Solib-search-path./debugging/lib 8. Under GDB, set the native program (GDB) file that you want to debug./myapp 9. Gdbserver (GDB) target remote connected to the device: 12345 The 6~9 step above can also be executed by the following command step $android_ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/ Arm-linux-androideabi-gdb--eval-command= "set Solib-search-path./debugging/lib" --eval-command= "file ./myapp " --eval-command=" target remote:12345 " 10. Start debugging by running the program through continue or C. Note that it is not run, because the program is actually started on the target machine, just break at the program entrance. Reference: use GDB to debug Android NDK native (c + +) programs
How to debug native programs on Android