floating point exceptions

General questions regarding the usage of CodeLite
User avatar
zaphod
CodeLite Veteran
Posts: 55
Joined: Fri Sep 11, 2009 6:20 pm
Contact:

floating point exceptions

Post by zaphod »

Codelite is great. I love it, use it every day. :)
If one compiles using x86 SSE options then floating point exceptions cause a SIGFPE signal and one's code will terminate without any message. This includes, surprisingly, even divide-by-zero errors cause by modulus arithmetic with integers. Here's a code fragment to illustrate things:

Code: Select all

#define __USE_GNU
#include <fenv.h>		// floating point exceptions that cause a SIGFPE
void fpe_handler(int sig_num)
{
	printf("** error ** a floating point exception occured # %d\n", sig_num);
	printf("press <Enter> to close window ");
	getchar();
	exit(sig_num);
}
int enable_floating_point_exception_tests(void)
{
	feenableexcept(FE_DIVBYZERO);
	signal(SIGFPE, fpe_handler);

	// test code to exercise the floating point exception
	volatile int a,b;
    a = 1;
	b = 1; // set b = 1 for no exception set b = 0 to cause one
    return a % b;
}
Codelite does a great job of stack tracing SIGSEG faults with gdb. I wonder if it might be able to do the same for SIGFPE too?