Android: No debugging symbols found in gdbserver - android

I try to attach a process on my rooted Android and create corefile with GDB but it can't create a gcore file because the symbols could not be found.
on my phone, i open Terminal app and i input
su
to grant root access in Terminal. i input
dumpsys meminfo
to show all running processes. i input
gdbserver :1234 --attach 5132
on my computer, i open gdb.exe (from Android NDK) and i input
(gdb) target remote 192.168.1.13:1234
and i got those infomation
(gdb) target remote 192.168.1.13:1234
Remote debugging using 192.168.1.13:1234
warning: Architecture rejected target-supplied description
Reading /system/bin/app_process32_original from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
warning: A handler for the OS ABI "Cygwin" is not built into this configuration
of GDB. Attempting to continue with the default arm settings.
Reading /system/bin/app_process32_original from remote target...
warning: A handler for the OS ABI "Cygwin" is not built into this configuration
of GDB. Attempting to continue with the default arm settings.
Reading symbols from target:/system/bin/app_process32_original...(no debugging symbols found)...done.
0xb6e8b0f8 in ?? ()
With my own compiled gdb.exe, i got another info
(gdb) target remote 192.168.1.13:1234
Remote debugging using 192.168.1.13:1234
warning: Can not parse XML target description; XML support was disabled at compile time
Reading /system/bin/app_process32_original from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /system/bin/app_process32_original from remote target...
Reading symbols from target:/system/bin/app_process32_original...(no debugging symbols found)...done.
Remote 'g' packet reply is too long: fcffffff605fd9be10000000ffffffff0000000008000000000000005a010000a87687b414000000000000004010c032105fd9be005fd9be1352e6b6f8b0e8b610000f204a280000000000003d0000001100000000000000000000006000000004000000d002000068010000680100003702000052000010110000001600000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a28000072002e0073006500720076006900630065002e0056006f006900700043006f006e006e006500630074006f0072005300e83bb770e83bb77088639b70e83bb770e83bb770e83bb770e83bb770e83bb770e83bb770e83bb770e83bb770e83bb770e83bb770e83bb770e83bb770e83bb77011000060
0xb6e8b0f8 in ?? ()
i type
gcore
and it says
Can't create a corefile
I have installed the correct gdbserver binary that match with my kernel architecture in /system/bin
I tried different Android OSes below Android 4.4.4 which does not have PIE protection thing, but i still getting the same problem. I tried to use ported version gdb client and it works perfectly.
I just wanna save the corefile with my powerful device running Android 5.1.1 with 2 GB RAM, instead using gdb client on my low-end tablet that has 512 MB RAM and running Android 4.4.4, and the gdb could not fully create the corefile due to low RAM.

Just download gdb source and compile with below steps:
1).Compile gdb with below command:
cd gdb-7.11/gdb
./configure --target=arm-linux-androideabi --with-python --prefix=$HOME/mybinaries/bin
make
make install
2).Compile gdbserver with below command:
cd gdb-7.11/gdb/gdbserver
CC=arm-linux-androideabi-gcc LDFLAGS="-fPIC -pie" ./configure --target=arm-linux-androideabi --host=arm-linux-androideabi --prefix=$HOME/mybinaries/bin
make
make install

When compiling the GDB, i must give the target --target arm-linux-androideabi instead --target arm-eabi and it works perfectly

Related

add gdb target achitecture: aarch64

I`m trying to debug android's Linux kernel. I can run gdbserver64 on the android device and connect to it with gdb on the host computer. However when i try to debug i receive this error:
(gdb) target remote localhost:2345
Remote debugging using localhost:2345
warning: while parsing target description (at line 11): Target description specified unknown architecture "aarch64"
warning: Could not load XML target description; ignoring
Remote register badly formatted:T051d:0000000000000000;1f:50f8ffff7f000000;20:641cf5b77f000000;thread:p57c.57c;core:5;
here: 00000000;1f:50f8ffff7f000000;20:641cf5b77f000000;thread:p57c.57c;core:5;
Its pretty clear that the host gdb does not have aarch64. Is there a way to add architectures to gdb? I cant seem to find a way to.
Is there a way to add architectures to gdb?
Yes: configure it with --enable-targets=all.
I had to build it from the gdb source code:
cd gdb-10.1
./configure --target=aarch64-linux-android && make -j8 && sudo make install
aarch64-linux-android-gdb
set sysroot
target remote <android-ip-address>:<port-number>

how can I debug an android native executable and library not directly integrated into the APK application

I have an android application that consists of a Java based APK, native executable, and native library. The apk talks to the native (root NDK c/c++) executable and library over a socket.
I'm not sure if it matters but the executable and library are compiled via cmake, and copied to be executable and then run as root. I need to get some type of debugging going with breakpoints and such, regardless of if it's directly in android studio or via command line.
You would need to run gdbserver on the device and let it attach to your executable
gdbserver comes prebuilt with ndk, usually under <ndk>/prebuilt/android-arm/gdbserver/
Copy gdbserver binary to your device, for instance to /data/local/tmp and give it executable permissions with chmod
If your executable is already running, find its PID with ps command and attach gdb to it:
gdbserver :5039 --attach <PID>
Note that 5039 is port number that is usually used for debugging with gdb, you can use your own if you like
set up a port forwarding from device to pc with
adb forward tcp:5039 tcp:5039
Run gdb locally, note that you need arm targeted gdb that comes with ndk too, usually at
<ndk>toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gdb
Attach gdb to your process
target remote :5039
And from here you need to use gdb commands that match your debugging expectations (set breakpoints, load symbols, step through etc), for examples use cheatsheet or ask in comments

Remote debugging of pure C program with GDB

I am trying to remotely debug a pure C program on an Android device.
The Android device (target) is connected via USB to a host machine.
What I did was:
Copied from the target the following files:
/system/lib, /vendor/lib, /system/bin/app_process, and /system/bin/linker.
Target:
Copied gdbserver from NDK to the target device
Sent the exe that I want to debug
runned gdb server on target using ./gdbserver :5039 exec
this basically executes the process, and gets a pid
Host:
enabled the port adb forward tcp:5039 tcp:5039
runned: arm-eabi-gcc exec.
Then in gdb:
set solib-search-path ..., with the libraries that I pulled earlier from the target
target remote :5039
The arm-eabi-gcc can connect to the remote process, and even continue(c) the execution. However, I cannot set breakpoints. If I do, I get the following error:
Cannot access memory at address xxx.
Am I missing something here?
Thank you.
So, at host, in gdb shell, before specifying the remote's target port, I should type shared. This command loads the shared symbols.
Also, for compiling, I used -ggdb.

Symbols out of sync when cross debugging android ndk

I'm trying to debug a native built (NDK) executable test (+shared library) using adb shell, gdbserver on one side and the ndk's gdb on the other side.
I copied the executable and .so to the device and executed in adb shell:
$ gdbserver :5039 ./my_test my_args
Process ./my_test created; pid = 11131
Listening on port 5039
On the host I run gdb on the same my_test executable:
$ $NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb ./my_test
And put a breakpoint in main():
Reading symbols from /.../my_test...done.
(gdb) target remote :5039
Remote debugging using :5039
warning: Unable to find dynamic linker breakpoint function.
GDB will retry eventurally. Meanwhile, it is likely
that GDB is unable to debug shared library initializers
or resolve pending breakpoints after dlopen().
0xb6f71a60 in ?? ()
(gdb) b main
Cannot access memory at address 0x0
warning: (Internal error: pc 0xa468 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0xa468 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0xa468 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0xa46c in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0xa468 in read in psymtab, but not in symtab.)
...
When hooked to eclipse as remote debug the 'next statement' jumps to different places in the code when I attempt to step-by-step the code. This is the same thing that I see when I do a series of 'next' command in gdb.
gdbserver version on the device is 7.6.
Any ideas?
Update:
After building gdb 7.6.2 and using it instead of the gdb 7.3.1-gg which comes with the NDK release I have (r9d 64-bit), those warning messages of Internal error are gone.
What's left is the lack of sync between the code and debugging. I built the code with NDK_DEBUG=1 and copied the executable and .so from .obj dir to the device, but still when I do 'step-by-step' debug from gdb+gdbserver the program flow as seen from gdb doesn't make any sense.
OK, the issue is resolved. Now the program flow as seen from gdb looks as expected.
These are the two things that were done and made it work:
Build a newer version of gdb. Instead of the 7.3.1 which came with the NDK release (version r9d), I downloaded and built gdb with --target=arm-linux-gnueabi and used it.
Previously I specified -g in APP_CPPFLAGS inside Application.mk. This time, I specified -ggdb -O0.

How do I insert breakpoints on threads using the Android NDK without crashing?

I'm currently working on debugging some code with my android project.
I'm having an issue getting gdb to hit my breakpoints on secondary threads. Everything works fine when they're set on the main thread, but as soon as a breakpoint is hit on a secondary one, my app crashes.
I've searched the web and some people were saying that the ndk uses an old version of GDB, but this appears to be irrelevant now (as the version shipped with the ndk r8 gives 7.3.1). One other site had said that the gdb version that's included was compiled without multithreading support, but I can't seem to verify this either.
Additional Details:
Device : Nexus S
OS: Android 4.1.1
I'm not sure if this is related or not, but I get the following output when I attach my debugger to the running application (seems to only have issues with symbols):
warning: .dynamic section for "/home/sandy/workspace/tumbleweed/obj/local/armeabi-v7a/linker" is not at the expected address (wrong library or version mismatch?)
warning: Could not load shared library symbols for 78 libraries, e.g. libstdc++.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code.
Also, here's my verbose output when running ndk-gdb --verbose:
Android NDK installation path: /home/sandy/workspace/android-ndk-r8b
Using default adb command: /home/sandy/workspace/android-sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.29
Using ADB flags:
Using auto-detected project path: .
Found package name: com.sandroid.tumbleweed
ABIs targetted by application: jni/../libs
/home/sandy/workspace/tumbleweed/libs/gtest-1.6.0
/home/sandy/workspace/tumbleweed/libs/gtest-1.6.0/lib/.libs/libgtest.a
armeabi-v7a
Device API Level: 16
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /home/sandy/workspace/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/com.sandroid.tumbleweed/lib/gdbserver
Found data directory: '/data/data/com.sandroid.tumbleweed'
Found running PID: 3539
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd shell run-as com.sandroid.tumbleweed lib/gdbserver +debug-socket --attach 3539
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.sandroid.tumbleweed/debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process ./obj/local/armeabi-v7a/app_process
Attached; pid = 3539
Listening on sockaddr socket debug-socket
118 KB/s (9572 bytes in 0.078s)
Pulled app_process from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker ./obj/local/armeabi-v7a/linker
844 KB/s (79976 bytes in 0.092s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so ./obj/local/armeabi-v7a/libc.so
1662 KB/s (286500 bytes in 0.168s)
Pulled libc.so from device/emulator.
When the app crashes, I get this:
Child terminated with signal = 5
Child terminated with signal = 0x5 (SIGTRAP)
GDBserver exiting
It's been a while since I've posted this, but I think I recall figuring it out. Turns out I had recently updated NDK versions and didn't quite migrate all of the references to the old NDK directory. After completely moving the old NDK directory into a backup directory, I fixed the lingering references in my Eclipse project. After rebuilding, this seemed to fix my problems.
TL;DR: Ensure your NDK references are correct.

Categories

Resources