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>
Related
How to compile and build iotivity-lite (https://github.com/iotivity/iotivity-constrained) for android using arm-linux-androideabi compiler? I'm interested in the Makefile changes and settings.
The instructions for building iotivity-lite for Android are available by in a readme format inside the Makefile.
go to [iotivity-lite]/port/android/Makefile
Link to the Andorid Makefile
from that make file:
Port for native Android compilation (without Java).
Tested NDK versions:
API Android version
19 4.4
21 5.0
23 6.0
24 7.0
API version 24 is closest to regular Linux so far.
With API 24 the Android port is almost identical to the Linux port
except for the removal of the unsupported pthread_cancel and that
the IP adapter assures that interfaces have multicast and broadcast
enabled to avoid 3G/4G/5G interfaces.
It is expected that higher versions then API 24 should work without any
further modifications.
Testing compilations on non-rooted Android phones:
- Enable USB debugging on your phone.
- Install ADB or Android Studio
- adb start-server
Your phone should query now if you trust the computer. Hit OK.
- adb push simpleclient /data/local/tmp/
Most likely your phone gives you in /data/local some more permissions
Non-rooted devices are a bit restrictive what you can do in the file system.
- adb shell
- cd /data/local/tmp
- chmod 755 simpleclient
It was observed that the file has read-write permissions only after the upload
on Android 7.
- In a different terminal window start simpleserver on your developer box.
- ./simpleclient
- Kill client with Ctrl-C or Ctrl-\
- exit
- *** DISABLE USB debugging!!! *** (security issue if left on)
Note: On regular Android phones the server versions will not be found
(ie. simpleserver will not be discovered). But the clients
should work.
Download NDK: https://developer.android.com/ndk/downloads/index.html
Unzip downloaded package.
Choose architecture and API level.
cd <NDK>/build/tools
./make_standalone_toolchain.py --arch <architecture> --api <level> --install-dir <path>
For example: ./make_standalone_toolchain.py --arch arm --api 23 --install-dir ~/android-arm-23
This makefile uses then the NDK in <install-dir>.
For further setup see: https://developer.android.com/ndk/guides/standalone_toolchain.html
Either set ANDROID_API and ANDROID_BASE in this makefile
or invoke like this: make NDK_HOME=/opt/android-ndk ANDROID_API=24
After downloading the NDK make sure you run the make_standalone_toolchain.py script.
To build debug version for arm I end up running the following command.
make NDK_HOME=~/Android/android-arm-23/ ANDROID_API=23 DYNAMIC=1 TCP=1 SECURE=1 DEBUG=1
The build instructions are limited to building the C code that must be run using adb shell.
At the time I am writing this, There is a separate branch that is working to expose IoTivity-lite to Java using JNI. This is the swig branch.
There is a readme that contains the instructions to build the Java APIs as well as some sample programs.
README instructions for swig branch
The swig branch is still under active development but should be stable enough to meet your needs.
edit:
Since this question was asked the swig branch has been merged with the master branch of iotivity-lite. Also note since this question was asked the repository name was changed from iotivity-constrained to iotivity-lite. Everything needed to build for Android should be in the [iotivity-lite]/port/android/README.md file.
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
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
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.
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.