ndk-gdb works with c files, doesn't work cpp ...

177 views
Skip to first unread message

Damien Courtois

unread,
Apr 6, 2011, 5:36:38 PM4/6/11
to andro...@googlegroups.com
Hi,
First post in this mailing list, so first of all : thanks for the help
and usefull hints shared :)

Here is my problem : I'm learning how to debug native code using gdb
and I found this article :
http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/
It's a little application with a big button which, when pressed,
called a native function containing something like :

int * badptr = 0x00000000;
*badptr = 1;

(you can download the sample, that's what I did)

Everything works perfectly, I can compile this, debug it with gdb, set
a breakpoint and step once I hit it, etc. (I didn't even had to do the
part about modifying the ndk (step 2 of the article))

Now I want to start playing with C++ (class and method debugging. I
never used gdb, so I need to get used to it before trying to use it in
my project) So what i did is change the extension of the native file
to .cpp, and updated the Android.mk file like this :
- change the LOCAL_SRC_FILES to use the .cpp file
- changed the LOCAL_CFLAGS to LOCAL_CPPFLAGS

But now, gdb doesn't seem to work correctly anymore ! When I launch
it, there's nothing different, I can even set breakpoints, but as soon
as I continue and press the button which makes the application crash,
I get a popup on my device saying : "The application has stopped
unexpectedly. Please try again." with a "Force close" button.
And gdb doesn't reach the breakpoint I set ! When I press the "Force
close" button, gdb simply prints this :

"
Child terminated with signal = 9

Program terminated with signal SIGKILL, Killed.
she program no longer exist
Child terminated with signal = 0x9 (SIGKILL)
GDBserver exiting
"

I've search for hours, but I didn't find anything ... I don't even
know it this is something gdb related, something related to the
makefile (an option needed to make C++ debuggable ?) or something else
...

Any help would be greatly appreciated !
Thanks in advance.

--
http://blog.pcitron.fr (blog)
http://gallery.pcitron.fr (photos)
http://profiles.bleau.info/damien.courtois (profil bleau.info)

Jocelyn Houle

unread,
Apr 6, 2011, 6:31:53 PM4/6/11
to android-ndk
> I've search for hours, but I didn't find anything ... I don't even
> know it this is something gdb related, something related to the
> makefile (an option needed to make C++ debuggable ?) or something else
> ...
>
> Any help would be greatly appreciated !
> Thanks in advance.

I assume your native routine just isn't found, most likely due to
different mangling of C++ routines.

Try prefixing 'extern "C"' to you routine, e.g.:

jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv*
env, jobject thiz );

becomes:

extern "C" jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject
thiz );


(I've been playing around with the NDK for the past week or two, and I
know it can get quite frustrating at times... ;-)

Riasat Abir

unread,
Apr 7, 2011, 1:10:54 AM4/7/11
to andro...@googlegroups.com
Yes I my GDB works with CPP files.
you can use extern "C" as suggested (I've used it too)

Thanks,
Riasat


--
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.




--

HimHim

Reply all
Reply to author
Forward
0 new messages