Android NDK Development set breakpoints in local C + + source code Step into a detailed tutorial

Source: Internet
Author: User

Recently learning Android NDK Development, tossing a day, and finally be able to set breakpoints in ADT single-step debugging of local C + + source code. Online about this aspect of the information is too little, and mostly incomplete, and debugging process will appear a variety of problems, it is very torture, procedural apes have to have patience. Record your own debugging process and hope to be helpful to those who need it.

Before looking at this article, make sure you have successfully compiled an Android NDK project and can run it on a simulator or on a real machine. As for how to compile the NDK project, including configuring, generating. So files, etc., refer to my previous blog: http://blog.csdn.net/u013149325/article/details/40375455

First, say my development environment configuration:

Win7 64-bit

ADT Version: v22.6.2 (Eclipse, CDT already integrated, recommended for everyone with the latest version of ADT)

NDK version: android-ndk-r10c

Cygwin: Official website: http://cygwin.com/install.html

As for the installation of Cygwin and environment variable configuration, there is a lot of information on the web, no longer repeat.

Note: I have tried, you must use Cygwin to execute the ndk-gdb script in the NDK in order to enter the breakpoint of the C + + in ADT.

First, in the Java program to call the native function of the place to add breakpoints, such as:


Open the CPP file under the Jni folder and set breakpoints as needed, such as:


Three, set the project to debug mode:

Set the value of Debuggable to true in the application of androidmanifest, such as:


Note: The Ndk-build ndk_debug=1 is also set under Builder settings in C + + build

Four, open Cygwin, with CD command to locate the project directory, my is cd/cygdrive/f/practice/androidtest

Then execute the NDK-GDB command, mine is $NDK _root/ndk-gdb--verbose--force

Note: Be sure to add--force, otherwise you will get an error:another debug session Running,use--force to kill it

if the report  No symbol table is loaded. Use the "file" command error, then execute file to add the library, as follows:

File obj/local/armeabi-v7a/libtest.so

Execute the list or L command to display 10 lines of C + + source code each time.

Five, in ADT Debug as->android Native Application, if the console error can not find the library, point load that button (because there is no, anyway there are 3 buttons, you point the middle of that), Add the CPP file in the Jni folder. If the console is displayed as if you ignore the error directly, click Yes, this time if not unexpectedly, you will jump into the breakpoint set in C + +.



At this point, we can see the variable values, stack information, and some assembly instructions.

Note: If you do not jump into the breakpoint you set, it may be that the local debugging has not started the program is completed, the official web site is also explained:

note:there is a delay of a few seconds between when the activity was launched and when native Debugg ING starts. If your code is already executed by this point and then your won ' t see the breakpoint being hit. So either put a breakpoint on code that's called repetitively, or make sure that's call JNI code after you see the that NDK -GDB has connected. Link: http://tools.android.com/recent/usingthendkplugin

You can delay a few seconds in the appropriate place in the Java code so that the program executes to the breakpoint where the local debugger is turned on.

Can debug success is not easy Ah, if you encounter a problem, you can leave a message under the blog, I try to help solve.


Android NDK Development set breakpoints in local C + + source code Step into a detailed tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.