Android NDK develops a specific tutorial on setting breakpoints in a local C + + source code in a single step

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-family: SimSun; font-size: 18px">Recently learning the development of Android ndk, toss a day, and finally can successfully set breakpoints in ADT Single-step debugging local C + + source Code. The information on the Internet is too small, and most of the incomplete, and debugging process will appear a variety of problems, it is very torture. Programmers have to be patient.</span></p></p><p><p>Keep track of your own debugging Process. Hope to be helpful to those who need it.</p></p><p><p><span style="font-family: SimSun; font-size: 18px">Before looking at this article, make sure that you have successfully compiled an Android Ndkproject and can execute it on the emulator or on the real machine. As for how to compile ndkproject, include configuration, build. so files, and so On. Can take a test of my previous blog: http://blog.csdn.net/u013149325/article/details/40375455</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">first, say my development environment configuration:</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Win7 64-bit</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">ADT version Number: v22.6.2 (eclipse, CDT already integrated, recommended for everyone with the latest version of Adt)</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">NDK version Number: android-ndk-r10c</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Cygwin: official Website: http://cygwin.com/install.html</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">As for the installation of Cygwin and environment variable configuration, There is a lot of information on the internet, no longer repeat Here.</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Note: I have tried to run the Ndk-gdb script in the NDK using Cygwin. The ability to enter the breakpoint in ADT in a C + +.</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">first, in the Java program calls the native function where the breakpoint is Added. For example, With:</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px"><br></span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Open the CPP file under the JNI directory and set the breakpoint according to the Need. For example, With:</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px"><br></span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">third, set Project to debug mode:</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Set the value of Debuggable to true in the application of androidmanifest, for example by:</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px"><br></span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Note: The Ndk-build ndk_debug=1 is also set under Builder settings in C + + build</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">four, Open the Cygwin. Use the CD command to navigate to the project folder, mine is Cd/cygdrive/f/practice/androidtest</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Then run the Ndk-gdb command. Mine is $NDK _root/ndk-gdb--verbose--force</span></p></p><p><p><span style="font-family: SimSun; font-size: 18px">Note: Be sure to add--force. Otherwise it will error:<span style="color: rgb(51,51,51); line-height: 26px">another debug session running,use--force to kill it</span></span></p></p><p><p><span style="font-family: SimSun; font-size: 18px"><span style="line-height: 26px"><span style="color: #333333">Assuming that the report</span>  <span style="color: rgb(255,0,0); line-height: 22px; background-color: rgb(249,249,249)">No symbol table is Loaded. Use the "file"</span> <span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="color: #333333">command error, run the file to add the Library. For example, the following:</span></span></span></span></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333">File obj/local/armeabi-v7a/libtest.so</span></span></span></span></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333">Run the list or L Command. Ability to display 10 lines of C + + source code each Time.</span></span></span></span></p></p><p><p></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333">five, in ADT Debug as->android Native application, Assuming the console error can not find the library, click on the Load button ( <span style="color: rgb(51,51,51); font-family: SimSun; line-height: 22px; background-color: rgb(249,249,249)">because there was No. There are 3 buttons anyway. You point the middle One)</span>, add the CPP file in the JNI directory. Assume that the console shows a demo sample for Example. You simply ignore the error, click yes, this time assuming no surprises, you will jump into the breakpoints set in C + +.</span></span></span></span></p></p><p><p></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333"><br></span></span></span></span></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333"><br></span></span></span></span></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333">At this point, we will be able to see the variable values, stack information, and some assembly instructions.</span></span></span></span></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333">Note: assume that you did not jump into the breakpoint you set, it is possible that the local debugging has not started <span style="color: rgb(51,51,51); font-family: SimSun; line-height: 22px; background-color: rgb(249,249,249)">to run the program is completed, the official website is also explained:</span></span></span></span></span></p></p><p><p> <span style="font-size:18px"><span style="line-height:26px"><span style="line-height:22px; background-color : RGB (249,249,249) "><span style=" font-family:simsun; color: #333333 "><span style=" Color:rgb (51,51,51); font-family:simsun; line-height:22px; Background-color:rgb (249,249,249) "><span style=" font-family:arial, Verdana, sans-serif "><span style=" font-family:arial; background-color:transparent; vertical-align:baseline; White-space:pre-wrap ">note:there is a delay in a few seconds between when the activity was launched and when native debug Ging 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 </span> </span> </span> </span> </span> </span> </span> </p></p><p><p> <span style="font-size:18px"><span style="line-height:26px"><span style="line-height:22px; background-color : RGB (249,249,249) "><span style=" font-family:simsun; color: #333333 "><span style=" Color:rgb (51,51,51); font-family:simsun; line-height:22px; Background-color:rgb (249,249,249) "><span style=" font-family:arial, Verdana, sans-serif "><span style=" font-family:arial; background-color:transparent; vertical-align:baseline; White-space:pre-wrap "> You can delay a few seconds in the appropriate place in the Java code so that the program runs to the breakpoint where the local debugger is turned On. </span></span></span></span></span></span></span></p></p><p><p><span style="font-size: 18px"><span style="line-height: 26px"><span style="line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: SimSun; color: #333333"><span style="color: rgb(51,51,51); font-family: SimSun; line-height: 22px; background-color: rgb(249,249,249)"><span style="font-family: Arial, Verdana, sans-serif"><span style="font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap">Can debug success is not easy ah, all friends assume that encountered a problem, you can leave a message under the Blog. I try my best to help solve it.</span></span></span></span></span></span></span></p></p><p><p><br></p></p> <p><p>Android NDK develops a specific tutorial on setting breakpoints in a local C + + source code in a single step</p></p></span>

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.