diff --git a/src/mod/applications/mod_ivrtest/mod_ivrtest.c b/src/mod/applications/mod_ivrtest/mod_ivrtest.c index 2617395999..10738d9dcf 100644 --- a/src/mod/applications/mod_ivrtest/mod_ivrtest.c +++ b/src/mod/applications/mod_ivrtest/mod_ivrtest.c @@ -51,7 +51,9 @@ static switch_status on_dtmf(switch_core_session *session, char *dtmf, void *buf static void disast_function(switch_core_session *session, char *data) { - printf("%s WOOHOO\n", (char *) 42); + void *x = NULL; + memset((void *) x, 0, 1000); + //printf("%s WOOHOO\n", (char *) 42); } diff --git a/src/switch_core.c b/src/switch_core.c index f2fcd439f1..f8721abf0a 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1813,12 +1813,46 @@ SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session *ses return session->thread_running; } +#ifdef __GNUC__ +#include +#include +#include +#define STACK_LEN 10 + +/* Obtain a backtrace and print it to stdout. */ +static void print_trace (void) +{ + void *array[STACK_LEN]; + size_t size; + char **strings; + size_t i; + + size = backtrace (array, STACK_LEN); + strings = backtrace_symbols (array, size); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Obtained %zd stack frames.\n", size); + + for (i = 0; i < size; i++) { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CRIT, "%s\n", strings[i]); + } + + free (strings); +} +#else +static void print_trace (void) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Trace not avaliable =(\n"); +} +#endif + + static int handle_fatality(int sig) { switch_thread_id thread_id; jmp_buf *env; if (sig && (thread_id = switch_thread_self()) && (env = (jmp_buf *) apr_hash_get(runtime.stack_table, &thread_id, sizeof(thread_id)))) { + print_trace(); longjmp(*env, sig); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Caught SEGV for unmapped thread!");