diff options
author | marha <marha@users.sourceforge.net> | 2013-03-25 10:23:25 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2013-03-25 10:23:25 +0100 |
commit | 30ac3efa02bbd1aecff4a0aa2da17bc886bdd5ea (patch) | |
tree | 7ae924e3fb64c93a0f59e55fd08a914db9bb551b /xorg-server/os | |
parent | 55a9a54c65cd0ff58966408ea4d7879a3d9c749c (diff) | |
parent | 176eab9e8277db1549bfc6c9ae805c4e1858f0b0 (diff) | |
download | vcxsrv-30ac3efa02bbd1aecff4a0aa2da17bc886bdd5ea.tar.gz vcxsrv-30ac3efa02bbd1aecff4a0aa2da17bc886bdd5ea.tar.bz2 vcxsrv-30ac3efa02bbd1aecff4a0aa2da17bc886bdd5ea.zip |
Merge remote-tracking branch 'origin/released'
* origin/released:
fontconfig mesa pixman xserver git update 25 Mar 2013
Diffstat (limited to 'xorg-server/os')
-rw-r--r-- | xorg-server/os/Makefile.am | 5 | ||||
-rw-r--r-- | xorg-server/os/backtrace.c | 75 | ||||
-rw-r--r-- | xorg-server/os/log.c | 4 |
3 files changed, 84 insertions, 0 deletions
diff --git a/xorg-server/os/Makefile.am b/xorg-server/os/Makefile.am index 88914852f..364b6da2d 100644 --- a/xorg-server/os/Makefile.am +++ b/xorg-server/os/Makefile.am @@ -34,6 +34,11 @@ if XDMCP libos_la_SOURCES += $(XDMCP_SRCS) endif +if HAVE_LIBUNWIND +AM_CFLAGS += $(LIBUNWIND_CFLAGS) +libos_la_LIBADD += $(LIBUNWIND_LIBS) +endif + EXTRA_DIST = $(SECURERPC_SRCS) $(XDMCP_SRCS) if SPECIAL_DTRACE_OBJECTS diff --git a/xorg-server/os/backtrace.c b/xorg-server/os/backtrace.c index daac60cf6..426f9b15b 100644 --- a/xorg-server/os/backtrace.c +++ b/xorg-server/os/backtrace.c @@ -30,6 +30,80 @@ #include <errno.h> #include <string.h> +#ifdef HAVE_LIBUNWIND + +#define UNW_LOCAL_ONLY +#include <libunwind.h> + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include <dlfcn.h> + +void +xorg_backtrace(void) +{ + unw_cursor_t cursor; + unw_context_t context; + unw_word_t off; + unw_proc_info_t pip; + int ret, i = 0; + char procname[256]; + const char *filename; + Dl_info dlinfo; + + pip.unwind_info = NULL; + ret = unw_getcontext(&context); + if (ret) { + ErrorFSigSafe("unw_getcontext failed: %s [%d]\n", unw_strerror(ret), + ret); + return; + } + + ret = unw_init_local(&cursor, &context); + if (ret) { + ErrorFSigSafe("unw_init_local failed: %s [%d]\n", unw_strerror(ret), + ret); + return; + } + + ErrorFSigSafe("\n"); + ErrorFSigSafe("Backtrace:\n"); + ret = unw_step(&cursor); + while (ret > 0) { + ret = unw_get_proc_info(&cursor, &pip); + if (ret) { + ErrorFSigSafe("unw_get_proc_info failed: %s [%d]\n", + unw_strerror(ret), ret); + break; + } + + ret = unw_get_proc_name(&cursor, procname, 256, &off); + if (ret && ret != -UNW_ENOMEM) { + if (ret != -UNW_EUNSPEC) + ErrorFSigSafe("unw_get_proc_name failed: %s [%d]\n", + unw_strerror(ret), ret); + procname[0] = '?'; + procname[1] = 0; + } + + if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname && + *dlinfo.dli_fname) + filename = dlinfo.dli_fname; + else + filename = "?"; + + ErrorFSigSafe("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname, + ret == -UNW_ENOMEM ? "..." : "", (int)off, + (void *)(pip.start_ip + off)); + + ret = unw_step(&cursor); + if (ret < 0) + ErrorFSigSafe("unw_step failed: %s [%d]\n", unw_strerror(ret), ret); + } + ErrorFSigSafe("\n"); +} +#else /* HAVE_LIBUNWIND */ #ifdef HAVE_BACKTRACE #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -246,3 +320,4 @@ xorg_backtrace(void) #endif #endif +#endif diff --git a/xorg-server/os/log.c b/xorg-server/os/log.c index 4f37da2ad..f8ebe7551 100644 --- a/xorg-server/os/log.c +++ b/xorg-server/os/log.c @@ -285,6 +285,10 @@ LogSetParameter(LogParameter param, int value) } } +/** + * Signal-safe snprintf, with some limitations over snprintf. Be careful + * which directives you use. + */ static int pnprintf(char *string, size_t size, const char *f, va_list args) { |