asserts not triggered?

1,423 views
Skip to first unread message

Bram Stolk

unread,
Dec 21, 2011, 1:24:38 AM12/21/11
to android-ndk
Hi,

I'm developing using NDK r7, from the command line using:
$ ndk-build
$ ant debug
$ ant installd

I noticed that assertions never get triggered.

#include "assert.h"

..
assert(0);
...

will do nothing.

Is there a way to get assertions working?
They are an extremely valuable debugging tool to me.

thx

Bram Stolk
http://stolk.org/HoverBiker/

Glenn Kasten

unread,
Dec 22, 2011, 10:46:33 AM12/22/11
to android-ndk
Try adding this to jni/Android.mk
LOCAL_CFLAGS += -UNDEBUG

David Turner

unread,
Dec 22, 2011, 10:57:45 AM12/22/11
to andro...@googlegroups.com
On Wed, Dec 21, 2011 at 7:24 AM, Bram Stolk <b.s...@gmail.com> wrote:
Hi,

I'm developing using NDK r7, from the command line using:
$ ndk-build
$ ant debug
$ ant installd

I noticed that assertions never get triggered.

#include "assert.h"

..
assert(0);
...

will do nothing.

Is there a way to get assertions working?

Yes, by default, release builds have NDEBUG defined, which will cause <assert.h> to translate assert() as a no-op

This is not the case for debug native builds (which means using android:debuggable in your manifest, APP_OPTIM := debug in your Application.mk or simply NDK_DEBUG=1 on the command-line).

Alternatively, add -UNDEBUG to your compiler flags to enable assertions in release builds.
 
They are an extremely valuable debugging tool to me.

thx

Bram Stolk
http://stolk.org/HoverBiker/

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


Bram Stolk

unread,
Dec 27, 2011, 6:42:44 PM12/27/11
to android-ndk
Thanks David,

So I adjusted my Manifest, per your suggestion, adding
android:debuggable="true"

And yes, the app now throws a SIGSEGV.
However, the logcat will show no details about the failed assertion.
It will not print out the failed expression, and the callstack is just
in hex.

I guess by running in a debugger I would know which assert gets
triggered (have not tried gdb yet),
but would it not be a whole lot more useful if the failed assertion is
printed on the log?
Or is there a setting I need to change somewhere that does just this?

Thanks again!

Bram Stolk
http://stolk.org/HoverBiker/


On Dec 22, 7:57 am, David Turner <di...@android.com> wrote:

Stephen Williams

unread,
Dec 28, 2011, 1:55:51 AM12/28/11
to andro...@googlegroups.com, Bram Stolk
In my experience you could tell that it was an assertion thrown because
of a particular stack and registers, but there doesn't seem to be a way
to get a log message. Doesn't seem to be supported, even if you have
the stderr/stdout->logcat flag turned on and the daemon is still
running.
Have to arrange to call the Android logging functions instead.

I like to set up logging macros that call Android methods on Android,
normal stderr otherwise. Then make a debug static flag. Then create
wrapped Java calls. You can then toggle the logging from Java, and log
from generic (not Android specific) Java libraries. Then toggle Java
and native logging flags based on debug vs. release builds
("Debuggable" in the manifest). Plus you can only turn logging on for
certain sections of code.

sdw

Reply all
Reply to author
Forward
0 new messages