mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 05:27:35 +02:00
Adding build option to print stack traces on segfault.
This commit is contained in:
parent
b127607cda
commit
3031b50406
2 changed files with 22 additions and 0 deletions
|
@ -112,6 +112,10 @@
|
||||||
/* may be very slow and using CFLAGS=-O0 is recommended. */
|
/* may be very slow and using CFLAGS=-O0 is recommended. */
|
||||||
/* #define SEXP_USE_SAFE_ACCESSORS 1 */
|
/* #define SEXP_USE_SAFE_ACCESSORS 1 */
|
||||||
|
|
||||||
|
/* uncomment to install a default signal handler in main() for segfaults */
|
||||||
|
/* This will print a helpful backtrace. */
|
||||||
|
/* #define SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT 1 */
|
||||||
|
|
||||||
/* uncomment this to make the heap common to all contexts */
|
/* uncomment this to make the heap common to all contexts */
|
||||||
/* By default separate contexts can have separate heaps, */
|
/* By default separate contexts can have separate heaps, */
|
||||||
/* and are thus thread-safe and independant. */
|
/* and are thus thread-safe and independant. */
|
||||||
|
|
18
main.c
18
main.c
|
@ -57,6 +57,21 @@ void sexp_usage(int err) {
|
||||||
#define sexp_usage(err) (err ? exit_failure() : exit_success())
|
#define sexp_usage(err) (err ? exit_failure() : exit_success())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT
|
||||||
|
#include <execinfo.h>
|
||||||
|
#include <signal.h>
|
||||||
|
void sexp_segfault_handler(int sig) {
|
||||||
|
void *array[10];
|
||||||
|
size_t size;
|
||||||
|
// get void*'s for all entries on the stack
|
||||||
|
size = backtrace(array, 10);
|
||||||
|
// print out all the frames to stderr
|
||||||
|
fprintf(stderr, "Error: signal %d:\n", sig);
|
||||||
|
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SEXP_USE_IMAGE_LOADING
|
#if SEXP_USE_IMAGE_LOADING
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -634,6 +649,9 @@ void run_main (int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char **argv) {
|
int main (int argc, char **argv) {
|
||||||
|
#if SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT
|
||||||
|
signal(SIGSEGV, sexp_segfault_handler);
|
||||||
|
#endif
|
||||||
sexp_scheme_init();
|
sexp_scheme_init();
|
||||||
run_main(argc, argv);
|
run_main(argc, argv);
|
||||||
exit_success();
|
exit_success();
|
||||||
|
|
Loading…
Add table
Reference in a new issue