Author Topic: How do I Make Asserts Behave the Way They Should on Linux?  (Read 1626 times)

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
So apparently Linux and/or gcc thinks asserts should terminate a program completely instead of just triggering a breakpoint and allowing me to step through it with a debugger.  How do I make them behave correctly?

Krizdo4

  • PGP
  • Posts: 43
Re: How do I Make Asserts Behave the Way They Should on Linux?
« Reply #1 on: May 25, 2008, 09:01:40 PM »
I'm not sure about the "right" way to do this but here's a suggestion.

Code: [Select]
#include <signal.h>

#undef assert
#define assert(expression)  \
  ((void) ((expression) ? 0 : raise(SIGTRAP)))


http://en.wikipedia.org/wiki/SIGTRAP

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: How do I Make Asserts Behave the Way They Should on Linux?
« Reply #2 on: May 27, 2008, 04:46:36 PM »
Thanks - I'll look into that.