mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
Improve debugging traces
This commit is contained in:
parent
975ba3323b
commit
6a951aa9f7
@ -100,6 +100,7 @@ AC_CHECK_HEADERS(
|
||||
inttypes.h \
|
||||
libutil.h \
|
||||
ncurses.h \
|
||||
execinfo.h \
|
||||
ndir.h \
|
||||
paths.h \
|
||||
pty.h \
|
||||
@ -121,6 +122,7 @@ AC_CHECK_FUNCS(
|
||||
[ \
|
||||
dirfd \
|
||||
flock \
|
||||
backtrace \
|
||||
setproctitle \
|
||||
sysconf \
|
||||
cfmakeraw \
|
||||
|
@ -1,9 +1,20 @@
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <regex.h>
|
||||
#include <signal.h>
|
||||
#include "tmate.h"
|
||||
|
||||
#ifndef HAVE_BACKTRACE
|
||||
|
||||
void tmate_print_stack_trace(void) {}
|
||||
void tmate_catch_sigsegv(void) {}
|
||||
void tmate_preload_trace_lib(void) {}
|
||||
|
||||
#else
|
||||
|
||||
#if DEBUG
|
||||
|
||||
static int print_resolved_stack_frame(const char *frame)
|
||||
@ -47,7 +58,7 @@ static int print_resolved_stack_frame(const char *frame)
|
||||
return -1;
|
||||
|
||||
line[strlen(line)-1] = 0; /* remove \n */
|
||||
tmate_crit("%s(%s) [%s]", file, line, address);
|
||||
tmate_debug("%s(%s) [%s]", file, line, address);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@ -62,20 +73,39 @@ void tmate_print_stack_trace(void)
|
||||
size = backtrace (array, 20);
|
||||
strings = backtrace_symbols (array, size);
|
||||
|
||||
tmate_crit("============ %zd stack frames ============", size);
|
||||
tmate_info ("============ %zd stack frames ============", size);
|
||||
|
||||
for (i = 1; i < size; i++) {
|
||||
#if DEBUG
|
||||
if (print_resolved_stack_frame(strings[i]) < 0)
|
||||
#endif
|
||||
tmate_crit("%s", strings[i]);
|
||||
tmate_info("%s", strings[i]);
|
||||
}
|
||||
|
||||
free (strings);
|
||||
}
|
||||
|
||||
static void handle_crash(__unused int sig)
|
||||
{
|
||||
/*
|
||||
* XXX we are in a signal handler, we are not allowed to use malloc
|
||||
* and friends, which is what we do
|
||||
*/
|
||||
tmate_info("CRASH, printing stack trace");
|
||||
tmate_print_stack_trace();
|
||||
tmate_fatal("CRASHED");
|
||||
}
|
||||
|
||||
void tmate_catch_sigsegv(void)
|
||||
{
|
||||
signal(SIGSEGV, handle_crash);
|
||||
signal(SIGABRT, handle_crash);
|
||||
}
|
||||
|
||||
void tmate_preload_trace_lib(void)
|
||||
{
|
||||
void *array[1];
|
||||
backtrace(array, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -213,6 +213,7 @@ int main(int argc, char **argv, char **envp)
|
||||
cmdline_end = *envp;
|
||||
|
||||
tmate_preload_trace_lib();
|
||||
tmate_catch_sigsegv();
|
||||
|
||||
if ((dev_urandom_fd = open("/dev/urandom", O_RDONLY)) < 0)
|
||||
tmate_fatal("Cannot open /dev/urandom");
|
||||
|
Loading…
x
Reference in New Issue
Block a user