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?
Qt Code:
  1. void bt_sighandler(int sig, siginfo_t *info,
  2. void *secret)
  3. {
  4.  
  5. #ifdef N_DEBUG
  6. void *trace[ trace_max_size ];
  7. char **messages = (char **)NULL;
  8. int i, trace_size = 0;
  9. ucontext_t *uc = (ucontext_t *)secret;
  10.  
  11. // Do something useful with siginfo_t
  12. if (sig == SIGSEGV)
  13. printf("******* SEGMENTATION FAULT *******, faulty address is %p, "
  14. "from %p\n", info->si_addr,
  15. uc->uc_mcontext.gregs[REG_EIP]);
  16.  
  17. trace_size = backtrace(trace, trace_max_size );
  18. // overwrite sigaction with caller's address
  19. trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];
  20.  
  21. messages = backtrace_symbols(trace, trace_size);
  22. // skip first stack frame (points here)
  23. printf("[***] Execution path:\n");
  24. for (i=1; i<trace_size; ++i)
  25. printf("[%3d] %s\n", trace_size - i, messages[i]);
  26. free( messages );
  27. #else
  28. printf( "[***] Backtrace not supported when compiled without N_DEBUG defined\n" );
  29. #endif
  30. }
To copy to clipboard, switch view to plain text mode