Debugging through the JNI using Eclipse

1,638 views
Skip to first unread message

Willem-Jan Spoel

unread,
Sep 3, 2010, 6:53:50 AM9/3/10
to android-ndk
Hi all,

the following article describes howto debug native code:
http://groups.google.com/group/android-ndk/web/debugging-through-the-jni-with-android-2-2

I have followed all the steps successfully, except for the last one.
it says: "Launch the C/C++ Application debug and wait for the Eclipse
GDB session to fully connect to the emulator's gdbserver instance." I
have problems with that step because I can't start that debug
configuration because there is no project assigned to it.

If I open the C/C++ Application debug properties and browse for a
project, the android project is not listed. If I type in the name of
the android project, I get the error message "Program does not
exist".

Does someone know howto solve this problem?

Thanks in advance,
Willem


Eclipse version = Galileo

Carlos Alberto Souto Junior

unread,
Sep 3, 2010, 4:15:43 PM9/3/10
to andro...@googlegroups.com
Hi, 

You need to convert the project to a C/C++ one. This can be done by using the standard CDT way, 
or you can use the Sequoyah Android Native facilities to speed up the process. ( http://www.eclipse.org/sequoyah )

Using Sequoyah, it is just a matter of right-clicking the Android Project, choose Android Tools > Add Native Support...
Just follow the wizard and, if your project have more than one lib, just point one and define the other in the android.mk.

Hopefully, after adding the native support this way, you will be able to configure the C/C++ run configuration and debug 
your application.


Hope it helped.




--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
--
Carlos Alberto Souto Junior
Computing Engineer 
MSc. in Electrical Engineering

カルロス アルベルト ソウト ジュニオル
コンピューター工学者 - UNICAMP
電気工学修士課程


Willem-Jan Spoel

unread,
Sep 6, 2010, 2:38:20 PM9/6/10
to android-ndk
Hi Carlos,

thank you for you quick and helpful response!

I have installed Sequoyah and it works indeed. I can now fire up the c+
+ debugger to connect, it only gives the following error:

org.eclipse.cdt.debug.mi.core.MIException: Process Terminated
at org.eclipse.cdt.debug.mi.core.MISession.setup(MISession.java:239)
at org.eclipse.cdt.debug.mi.core.MISession.<init>(MISession.java:210)
at
org.eclipse.cdt.debug.mi.core.MIPlugin.createMISession0(MIPlugin.java:
142)
at org.eclipse.cdt.debug.mi.core.MIPlugin.createSession(MIPlugin.java:
471)
at
org.eclipse.cdt.debug.mi.core.AbstractGDBCDIDebugger.createGDBSession(AbstractGDBCDIDebugger.java:
114)
at
org.eclipse.cdt.debug.mi.core.AbstractGDBCDIDebugger.createSession(AbstractGDBCDIDebugger.java:
68)
at
org.eclipse.cdt.launch.internal.LocalCDILaunchDelegate.launchDebugSession(LocalCDILaunchDelegate.java:
344)
at
org.eclipse.cdt.launch.internal.LocalCDILaunchDelegate.createCDISession(LocalCDILaunchDelegate.java:
469)
at
org.eclipse.cdt.launch.internal.LocalCDILaunchDelegate.launchLocalDebugSession(LocalCDILaunchDelegate.java:
146)
at
org.eclipse.cdt.launch.internal.LocalCDILaunchDelegate.launchDebugger(LocalCDILaunchDelegate.java:
113)
at
org.eclipse.cdt.launch.internal.LocalCDILaunchDelegate.launch(LocalCDILaunchDelegate.java:
73)
at
org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:
853)
at
org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:
702)
at
org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:
923)
at org.eclipse.debug.internal.ui.DebugUIPlugin
$8.run(DebugUIPlugin.java:1126)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

At page 6 of this document: http://developer.download.nvidia.com/tegra/docs/android_gdb_debugging.pdf
(which describes a similar approach) it says:
"If you get the error “Error creating session”, it is usually due to
not starting eclipse from a
cygwin shell on Windows. If you did and still get the error, try
executing the arm-eabigdb
binary in a shell and resolve any errors that might show up doing so".

Starting eclipse from shell doesn't change and calling arm-eabigdb
doesn't give errors. Tomorrow I am going to try the same steps using
Ubuntu instead of Windows, hopefully that gives more luck because at
the moment I am stuck.

But thanks again for your help and I will give an update if there is
any progress.
Willem


On 3 sep, 22:15, Carlos Alberto Souto Junior <csoutojun...@gmail.com>
wrote:
> Hi,
>
> You need to convert the project to a C/C++ one. This can be done by using
> the standard CDT way,
> or you can use the Sequoyah Android Native facilities to speed up the
> process. (http://www.eclipse.org/sequoyah)
>
> Using Sequoyah, it is just a matter of right-clicking the Android Project,
> choose Android Tools > Add Native Support...
> Just follow the wizard and, if your project have more than one lib, just
> point one and define the other in the android.mk.
>
> Hopefully, after adding the native support this way, you will be able to
> configure the C/C++ run configuration and debug
> your application.
>
> Hope it helped.
>
>
>
>
>
> On Fri, Sep 3, 2010 at 7:53 AM, Willem-Jan Spoel <wjsp...@gmail.com> wrote:
> > Hi all,
>
> > the following article describes howto debug native code:
>
> >http://groups.google.com/group/android-ndk/web/debugging-through-the-...
>
> > I have followed all the steps successfully, except for the last one.
> > it says: "Launch the C/C++ Application debug and wait for the Eclipse
> > GDB session to fully connect to the emulator's gdbserver instance." I
> > have problems with that step because I can't start that debug
> > configuration because there is no project assigned to it.
>
> > If I open the C/C++ Application debug properties and browse for a
> > project, the android project is not listed. If I type in the name of
> > the android project, I get the error message "Program does not
> > exist".
>
> > Does someone know howto solve this problem?
>
> > Thanks in advance,
> > Willem
>
> > Eclipse version = Galileo
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .

Willem-Jan Spoel

unread,
Sep 7, 2010, 6:55:21 AM9/7/10
to android-ndk
Hi,

I have followed the same steps on Ubuntu, and it works! But it is
still unclear why it is not working on Windows 7...but at least
debugging my project is possible

Willem-Jan
> At page 6 of this document:http://developer.download.nvidia.com/tegra/docs/android_gdb_debugging...

Ó. Egilsson

unread,
Oct 7, 2010, 8:01:48 AM10/7/10
to android-ndk
Got this working on Windows XP with the following mods:

* Had to run eclipse (Helios SR1) via cygwin
* Add native support to the project like Carlos suggests in the second
post in this thread
* Run > Debug Configurations > You C/C++ config > Source > Add > Path
mapping: \cygdrive\i _> I:\

Installed Sequoyah from the 1.1 repository for Helios SR1, even if on
the page is says you should use 1.0.1 - but there is no "Android
native code support" in 1.0.1.

Can someone tell me, which version of Eclipse is newer, 3.6.1 or SR1 ?

I saw somewere that Eclipse 3.6 wasn't recommended for Android dev,
but I couldn't install Sequoyah on 3.5 since it wanted CDT 7 which
doesn't seem to be availabe to 3.5.

Hope this will be of help to someone, it's taken me a while to get
this to work! But having a debugger is like having the holy grail!

Doug Schaefer

unread,
Oct 7, 2010, 8:48:58 AM10/7/10
to andro...@googlegroups.com
On Thu, Oct 7, 2010 at 8:01 AM, Ó. Egilsson <ola...@gmail.com> wrote:
> Got this working on Windows XP with the following mods:
>
> * Had to run eclipse (Helios SR1) via cygwin
> * Add native support to the project like Carlos suggests in the second
> post in this thread
> * Run > Debug Configurations > You C/C++ config > Source > Add > Path
> mapping: \cygdrive\i  _> I:\
>
> Installed Sequoyah from the 1.1 repository for Helios SR1, even if on
> the page is says you should use 1.0.1 - but there is no "Android
> native code support" in 1.0.1.
>
> Can someone tell me, which version of Eclipse is newer, 3.6.1 or SR1 ?

They are the same.

> I saw somewere that Eclipse 3.6 wasn't recommended for Android dev,
> but I couldn't install Sequoyah on 3.5 since it wanted CDT 7 which
> doesn't seem to be availabe to 3.5.

Not sure where you saw that. Helios is fine.

> Hope this will be of help to someone, it's taken me a while to get
> this to work!  But having a debugger is like having the holy grail!

Did I mention I hate cygwin? :P

CDT Doug.

Tim Mensch

unread,
Oct 7, 2010, 10:57:43 AM10/7/10
to andro...@googlegroups.com
On 10/7/2010 6:48 AM, Doug Schaefer wrote:
> > Hope this will be of help to someone, it's taken me a while to get
> > this to work! But having a debugger is like having the holy grail!
>
> Did I mention I hate cygwin? :P
So say we all. ;) If I hadn't already blown so much time trying to make
other aspects of Android development work, I would be trying out the
MinGW port. But at some point you've got to stop "making things better"
and just get work done.

Tim


Ó. Egilsson

unread,
Oct 8, 2010, 9:45:22 AM10/8/10
to android-ndk
One problem I have regarding to breakpoints.

Problem explained with code below.
I want to break into native code, but do I have to set a break point
in Java just before that JNI call ?
If the JNI call finishes (to someNativeCall()), returnes, and later on
I call another JNI call, that would eventually internally call
someCppFunction(), the breakpoint doesn't work ... any ideas ?


Java Code:

function foo() {
someNativeCall(); // <-- I put breakpoint here
}


And some C++ code:

Java_some_pkg_someNativeCall(...) {
// do something
}

int someCppFunction() { // This function is called, probably after
Java_some_pkg_someNativeCall() has finished.
IamBuggedCode(); // <-- I want to break here, but It doesn't
work
}


... Now, this might be off topic since I'm note sure If it has to do
with Eclipse plugin ..
Reply all
Reply to author
Forward
0 new messages