Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug pure native code on android?

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.

like image 371
behe Avatar asked May 24 '12 22:05

behe


1 Answers

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!

like image 81
behe Avatar answered Oct 07 '22 06:10

behe