gadnio
9th January 2006, 10:48
Hi there,
I am wondering is there any way to determine if "CONFIG+=DEBUG" was specified in qmke-generated makefile?
Here's the problem:
when I compile an application in Debug mode, i want to print stack trace under some circumstances, but when compiling in release, those stacktraces are useless and only bloat the output. Is there any way to make the following code working w/o defining N_DEBUG?
void bt_sighandler(int sig, siginfo_t *info,
void *secret)
{
#ifdef N_DEBUG
void *trace[ trace_max_size ];
char **messages = (char **)NULL;
int i, trace_size = 0;
ucontext_t *uc = (ucontext_t *)secret;
// Do something useful with siginfo_t
if (sig == SIGSEGV)
printf("******* SEGMENTATION FAULT *******, faulty address is %p, "
"from %p\n", info->si_addr,
uc->uc_mcontext.gregs[REG_EIP]);
trace_size = backtrace(trace, trace_max_size );
// overwrite sigaction with caller's address
trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];
messages = backtrace_symbols(trace, trace_size);
// skip first stack frame (points here)
printf("[***] Execution path:\n");
for (i=1; i<trace_size; ++i)
printf("[%3d] %s\n", trace_size - i, messages[i]);
free( messages );
#else
printf( "[***] Backtrace not supported when compiled without N_DEBUG defined\n" );
#endif
}
I am wondering is there any way to determine if "CONFIG+=DEBUG" was specified in qmke-generated makefile?
Here's the problem:
when I compile an application in Debug mode, i want to print stack trace under some circumstances, but when compiling in release, those stacktraces are useless and only bloat the output. Is there any way to make the following code working w/o defining N_DEBUG?
void bt_sighandler(int sig, siginfo_t *info,
void *secret)
{
#ifdef N_DEBUG
void *trace[ trace_max_size ];
char **messages = (char **)NULL;
int i, trace_size = 0;
ucontext_t *uc = (ucontext_t *)secret;
// Do something useful with siginfo_t
if (sig == SIGSEGV)
printf("******* SEGMENTATION FAULT *******, faulty address is %p, "
"from %p\n", info->si_addr,
uc->uc_mcontext.gregs[REG_EIP]);
trace_size = backtrace(trace, trace_max_size );
// overwrite sigaction with caller's address
trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];
messages = backtrace_symbols(trace, trace_size);
// skip first stack frame (points here)
printf("[***] Execution path:\n");
for (i=1; i<trace_size; ++i)
printf("[%3d] %s\n", trace_size - i, messages[i]);
free( messages );
#else
printf( "[***] Backtrace not supported when compiled without N_DEBUG defined\n" );
#endif
}