Problem with debugging native code

Put problems with the Android NDK in this forum.

Problem with debugging native code

Postby it.er.newsletters » Wed Oct 13, 2010 1:15 pm

Hello all,

Here is a summary of my work environment.

OS : Win XP sp2.
Eclipse: Galileo
Target OS= Android 2.2
NDK Version = android-ndk-r4b-windows

I have a native library which compiles and runs without any error or crash, the native code needs to be debugged and I have gone through too many sites, videos etc.. but I'm having a hard time to get my debugger into native code. I couldn't use sequoyah as i heard that it is for eclipse Helios not for Galileo, and i think Helios is not supported for android development.

Is there any other alternative that can debug or even print the desired log for my native code in this stated environment? Any help will be appreciated.

Thanks.........
it.er.newsletters
Freshman
Freshman
 
Posts: 5
Joined: Sat Oct 09, 2010 10:19 am

Top

Re: Problem with debugging native code

Postby wjspoel » Fri Oct 22, 2010 12:57 pm

Hi,

I made the following tut (based on an another tut) for myself. I have got it working on Ubuntu (didn;t try it on windows)


Source:http://groups.google.com/group/android-ndk/web/debugging-through-the-jni-with-android-2-2 (it is almost the same, but extended with the "Sequoyah solution" )

Pre-requisites:
-The target platform must be Android 2.2 (android-8, aka Froyo)
-The ndk version must be r4b (it contains bugfixes to ndk-gdb that are necessary)
-Eclipse CDT 7.0 or newer must be installed.
-The AndroidManifest.xml must have the property of the application node android:debuggable=“true”
-The build must have been done with the ndk-build
-Sequoyah Android Native Support is installed in Eclipse using the following link: http://download.eclipse.org/sequoyah/updates/1.1/


Instructions:

Transform the project to a C++ project using Sequoyah:
-Choose Android Tools > Add Native Support and follow the wizard

Create a debug configuration for an Android application
Create a debug configuration for a C/C++ application, set the following properties:
-The process launcher must be the Standard Process Launcher. This is selected at the bottom of the Main
- -On the Main tab:
- - -the Field C/C++ Application: $PROJECT_PATH/obj/local/armeabi/app_process
- -on the Debugger:
- - -Field Debugger: gdbserver
- - -Subtab Main:
- - - -GDB debugger: $NDK_PATH/build/prebuilt/$ARCH/arm-eabi-$GCC_VERSION/bin/arm-eabi-gdb
- - - -GDB command file: $PROJECT_PATH/obj/local/armeabi/gdb2.setup
- - - -Subtab Connection:
- - - - -Type: TCP
- - - - -Hostname or IP address: localhost
- - - - -Port number: 5039

-Open the ndk-gdb script that came with the android NDK and comment the last line (we are not calling the usual gdb client, but we will attach an Eclipse gdb session instead)# $GDBCLIENT -x $GDBSETUP -e $APP_PROCESS
-Insert a breakpoint in your Java code , preferably after all System.loadLibrary() calls. (to make sure that the debugger is correctly attached to the Java process)
-Launch the android debug and wait it to reach the breakpoint
-From a Terminal session, in the project folder, run the modified ndk-gdb command. It should not attach to an gdb client, but call the gdbserver on the emulator and open a TCP port for connection.
-In the $PROJECT_PATH/obj/local/armeabi/, modify the gdb.setup file, removing the target remote :5039 statement. (for some reason, the Eclipse GDB session does not like this statement being done in the commands file). Rename this new file to gdb2.setup. This step need to be run just once, on the first debug session. (I am working on further tweaking the ndk-gdb script to generate the gdb.setup file without the target statement, but for the time being, this workaround will work)
-Launch the C/C++ Application debug and wait for the Eclipse GDB session to fully connect to the emulator's gdbserver instance.

After following these steps, one can continue to debug the application as usual, using the “continue” option to let the execution flow until the next breakpoint is hit or by using the usual “step-in” to execute each statement individually. Setting a breakpoint on a Java statement that calls a native function through JNI and stepping into will place the user at the beginning of the native code.


goog luck!
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Re: Problem with debugging native code

Postby VansFannel » Wed Dec 08, 2010 10:34 am

It works with a lib.so?
VansFannel
Freshman
Freshman
 
Posts: 7
Joined: Fri Dec 03, 2010 2:49 pm

Re: Problem with debugging native code

Postby guian » Thu Dec 09, 2010 2:28 pm

I also tried it but I don't get any Subtab "Connection" in the debug configuration manager c/C++ Application debugger tab ...

do you know why ?
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Re: Problem with debugging native code

Postby VansFannel » Thu Dec 09, 2010 5:17 pm

No.
VansFannel
Freshman
Freshman
 
Posts: 7
Joined: Fri Dec 03, 2010 2:49 pm

Re: Problem with debugging native code

Postby wjspoel » Wed Dec 15, 2010 12:00 pm

guian wrote:I also tried it but I don't get any Subtab "Connection" in the debug configuration manager c/C++ Application debugger tab ...

do you know why ?


Initialy in my case, there is no connection tab. Because the first option "Debugger" in the debugger tab is set on "gdb/mi". If I change that to "gdbserver" a third tab "connection" appears.
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Top

Re: Problem with debugging native code

Postby wjspoel » Wed Dec 15, 2010 12:01 pm

VansFannel wrote:It works with a lib.so?


I am not sure what you mean...
if you create your own c code a *.so file is generated and you can debug you own code. Is that what you want?
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Re: Problem with debugging native code

Postby VansFannel » Wed Dec 15, 2010 12:18 pm

Yes, I want to debug the code inside a lib.so library.
VansFannel
Freshman
Freshman
 
Posts: 7
Joined: Fri Dec 03, 2010 2:49 pm

Re: Problem with debugging native code

Postby wjspoel » Wed Dec 15, 2010 4:23 pm

VansFannel wrote:Yes, I want to debug the code inside a lib.so library.


but isn't that compiled code? And is it a library with debug information? Correct me if I am wrong, but don't you want to debug source code?
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Re: Problem with debugging native code

Postby VansFannel » Wed Dec 15, 2010 4:41 pm

I have compiled my C++ into a lib.so library with ndk-build.

Now, I want to debug that code while is running on my Android device.
VansFannel
Freshman
Freshman
 
Posts: 7
Joined: Fri Dec 03, 2010 2:49 pm

Re: Problem with debugging native code

Postby wjspoel » Wed Dec 15, 2010 8:04 pm

When you add c++ support for your project, you don't have to use ndk-build explicitly. Like I mentioned in the tutorial, you have to use the Sequoyah plugin: http://www.eclipse.org/sequoyah/. Then your project is automatically build when you run you android project. And then you can also debug as a c++ project.
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Re: Problem with debugging native code

Postby VansFannel » Wed Dec 15, 2010 8:22 pm

tutorial, I don't remember to read a tutorial. Where is it?
VansFannel
Freshman
Freshman
 
Posts: 7
Joined: Fri Dec 03, 2010 2:49 pm

Re: Problem with debugging native code

Postby wjspoel » Thu Dec 16, 2010 8:06 am

Read the second post of this thread :) which is the tutorial. Although it seams much work for simple debugging, you will gain a lot (if it works...)

If debugging is not working, I still advice to use Sequoyah because it will do a lot for you: automatically builds you c code when building you android project in eclipse, reports syntax errors etc... like a normal c++ project.
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Re: Problem with debugging native code

Postby cherylfoster » Fri Dec 24, 2010 12:43 am

"Full Path to Visual Studio Common7 IDE directory"\devenv.exe "Full Path to MicroStation"\ustation.exe This will start the IDE and put you in the debugger. You then hit go (F5 or the arrow). You then need to load your application. After loading you can set break points.
cherylfoster
Freshman
Freshman
 
Posts: 6
Joined: Fri Dec 24, 2010 12:33 am

Re: Problem with debugging native code

Postby cherylfoster » Fri Dec 24, 2010 12:45 am

"Full Path to Visual Studio Common7 IDE directory"\devenv.exe "Full Path to MicroStation"\ustation.exe This will start the IDE and put you in the debugger. You then hit go (F5 or the arrow). You then need to load your application. After loading you can set break points.
cherylfoster
Freshman
Freshman
 
Posts: 6
Joined: Fri Dec 24, 2010 12:33 am

Top

Return to NDK Problems

Who is online

Users browsing this forum: Google [Bot] and 1 guest