how to debug pure native code on android?
Asked Answered
D

2

7

I have built a binary excutable from pure C++ code and it prompts time error when running on android device.

How can I debug the pure native code for android? It seems that the existing methods are not for pure native code.

Dusk answered 24/5, 2012 at 22:0 Comment(2)
I'd recommend you read stackoverflow.com/questions/how-to-ask and try asking again to improve our ability to help you get an answer.Hadfield
Thanks. I have found the solution. Post here and hope it can help others bothered by this problem.Dusk
D
6

Step 1: Put the gdbserver and your unstripped native binary executable (suppose it is named testexec) on the android emulator. E.g. you can put it under folder /data/data/test. And use chmod command to add permissions to them.

Step2: Start gdb debugger. And this step consists of following sub-steps:

Step 2.1: Start gdb debugger of the emulator by typing command on your host machine terminal:

 adb shell /data/data/test/gdbserver 10.0.2.2:1234 /data/data/test/testexec 

The emulator will then listen on port 1234.

Step 2.2: Connect the gdb debugger of the local machine with the gdbserver of the emulator:

telnet localhost 5554 

It will prompt:

Android Console: type 'help' for a list of commands

OK

Then input:

redir add tcp:1234:1234

to enable data redirection and then type

exit

Step2.3: Start the gdb debugger of the local machine. Input:

arm-linux-androideabi-gdb.exe YOUR_ EXECUTABLE_PATH_ON_LOCAL_MACHINE\testexec

After that, input

target remote localhost:1234

to connect to the gdbserver.

Finally, enjoy your debugging!

Dusk answered 26/5, 2012 at 2:38 Comment(1)
would you know how to connect with telnet to real device - not an emulator? i was trying to query for the ip with adb shell ip -f inet addr show but cannot connectAppellee
M
-1

Android supports the use of GDB. However, I should note that if by "pure C++" you mean that there is no Java at all in the application, this is technically not allowed (although you can definitely do it). See the NDK page.

Mariahmariam answered 24/5, 2012 at 23:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.