aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/os/backtrace.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-03-26 14:23:28 +0200
committermarha <marha@users.sourceforge.net>2012-03-26 14:23:28 +0200
commit76bcc36ed305418a3ddc5752d287ede894243e1b (patch)
treebacb320c825768471ce56f058f17ce863d592376 /xorg-server/os/backtrace.c
parent7d894e32566b710952c44cbc71939ad1d9e2fa8d (diff)
parent0f834b91a4768673833ab4917e87d86c237bb1a6 (diff)
downloadvcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.gz
vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.bz2
vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.zip
Merge remote-tracking branch 'origin/released'
Conflicts: pixman/pixman/pixman-mmx.c xorg-server/Xext/shm.c xorg-server/Xext/syncsrv.h xorg-server/Xext/xvmain.c xorg-server/Xi/exevents.c xorg-server/Xi/opendev.c xorg-server/composite/compalloc.c xorg-server/composite/compoverlay.c xorg-server/dix/colormap.c xorg-server/dix/devices.c xorg-server/dix/dispatch.c xorg-server/dix/dixfonts.c xorg-server/dix/eventconvert.c xorg-server/dix/events.c xorg-server/dix/gc.c xorg-server/dix/getevents.c xorg-server/dix/main.c xorg-server/dix/privates.c xorg-server/dix/registry.c xorg-server/dix/resource.c xorg-server/exa/exa_accel.c xorg-server/exa/exa_migration_classic.c xorg-server/exa/exa_unaccel.c xorg-server/fb/fb.h xorg-server/fb/fbcopy.c xorg-server/fb/fbpixmap.c xorg-server/glx/dispatch.h xorg-server/glx/glapi.h xorg-server/glx/glapi_gentable.c xorg-server/glx/glapitable.h xorg-server/glx/glprocs.h xorg-server/glx/glxcmds.c xorg-server/glx/glxcmdsswap.c xorg-server/glx/glxdricommon.c xorg-server/glx/glxdriswrast.c xorg-server/glx/glxext.c xorg-server/glx/indirect_dispatch.c xorg-server/glx/indirect_dispatch.h xorg-server/glx/indirect_dispatch_swap.c xorg-server/glx/indirect_size.h xorg-server/glx/indirect_size_get.h xorg-server/glx/indirect_table.c xorg-server/glx/indirect_util.c xorg-server/glx/rensize.c xorg-server/glx/single2swap.c xorg-server/glx/singlepix.c xorg-server/glx/singlepixswap.c xorg-server/glx/singlesize.c xorg-server/hw/dmx/dmxinit.c xorg-server/hw/kdrive/ephyr/ephyr.c xorg-server/hw/kdrive/ephyr/hostx.c xorg-server/hw/kdrive/ephyr/hostx.h xorg-server/hw/kdrive/src/kinput.c xorg-server/hw/xfree86/common/compiler.h xorg-server/hw/xwin/InitInput.c xorg-server/hw/xwin/InitOutput.c xorg-server/hw/xwin/ddraw.h xorg-server/hw/xwin/glx/glwrap.c xorg-server/hw/xwin/glx/indirect.c xorg-server/hw/xwin/glx/wgl_ext_api.h xorg-server/hw/xwin/glx/winpriv.c xorg-server/hw/xwin/win.h xorg-server/hw/xwin/winallpriv.c xorg-server/hw/xwin/winauth.c xorg-server/hw/xwin/winclipboard.h xorg-server/hw/xwin/winclipboardinit.c xorg-server/hw/xwin/winclipboardthread.c xorg-server/hw/xwin/winclipboardunicode.c xorg-server/hw/xwin/winclipboardwndproc.c xorg-server/hw/xwin/winclipboardwrappers.c xorg-server/hw/xwin/winclipboardxevents.c xorg-server/hw/xwin/wincmap.c xorg-server/hw/xwin/winconfig.c xorg-server/hw/xwin/wincreatewnd.c xorg-server/hw/xwin/wincursor.c xorg-server/hw/xwin/windialogs.c xorg-server/hw/xwin/winengine.c xorg-server/hw/xwin/winerror.c xorg-server/hw/xwin/wingc.c xorg-server/hw/xwin/wingetsp.c xorg-server/hw/xwin/winkeybd.c xorg-server/hw/xwin/winkeybd.h xorg-server/hw/xwin/winlayouts.h xorg-server/hw/xwin/winmisc.c xorg-server/hw/xwin/winmonitors.c xorg-server/hw/xwin/winmouse.c xorg-server/hw/xwin/winmsg.c xorg-server/hw/xwin/winmsg.h xorg-server/hw/xwin/winmultiwindowclass.c xorg-server/hw/xwin/winmultiwindowicons.c xorg-server/hw/xwin/winmultiwindowshape.c xorg-server/hw/xwin/winmultiwindowwindow.c xorg-server/hw/xwin/winmultiwindowwm.c xorg-server/hw/xwin/winmultiwindowwndproc.c xorg-server/hw/xwin/winnativegdi.c xorg-server/hw/xwin/winpfbdd.c xorg-server/hw/xwin/winpixmap.c xorg-server/hw/xwin/winpolyline.c xorg-server/hw/xwin/winprefs.c xorg-server/hw/xwin/winprocarg.c xorg-server/hw/xwin/winregistry.c xorg-server/hw/xwin/winscrinit.c xorg-server/hw/xwin/winsetsp.c xorg-server/hw/xwin/winshaddd.c xorg-server/hw/xwin/winshadddnl.c xorg-server/hw/xwin/winshadgdi.c xorg-server/hw/xwin/wintrayicon.c xorg-server/hw/xwin/winwin32rootless.c xorg-server/hw/xwin/winwin32rootlesswindow.c xorg-server/hw/xwin/winwin32rootlesswndproc.c xorg-server/hw/xwin/winwindow.c xorg-server/hw/xwin/winwindow.h xorg-server/hw/xwin/winwindowswm.c xorg-server/hw/xwin/winwndproc.c xorg-server/include/callback.h xorg-server/include/dixstruct.h xorg-server/include/misc.h xorg-server/include/os.h xorg-server/include/scrnintstr.h xorg-server/mi/micmap.c xorg-server/mi/miinitext.c xorg-server/mi/mioverlay.c xorg-server/mi/misprite.c xorg-server/mi/mivaltree.c xorg-server/mi/miwindow.c xorg-server/miext/damage/damage.c xorg-server/miext/rootless/rootlessGC.c xorg-server/miext/rootless/rootlessWindow.c xorg-server/os/WaitFor.c xorg-server/os/access.c xorg-server/os/connection.c xorg-server/os/io.c xorg-server/os/log.c xorg-server/os/osinit.c xorg-server/os/utils.c xorg-server/os/xdmcp.c xorg-server/os/xprintf.c xorg-server/os/xstrans.c xorg-server/render/mipict.c xorg-server/xkb/xkbActions.c xorg-server/xkb/xkbInit.c xorg-server/xkeyboard-config/compat/default.in
Diffstat (limited to 'xorg-server/os/backtrace.c')
-rw-r--r--xorg-server/os/backtrace.c235
1 files changed, 126 insertions, 109 deletions
diff --git a/xorg-server/os/backtrace.c b/xorg-server/os/backtrace.c
index edaeb17c7..81348f417 100644
--- a/xorg-server/os/backtrace.c
+++ b/xorg-server/os/backtrace.c
@@ -37,53 +37,61 @@
#include <dlfcn.h>
#include <execinfo.h>
-void xorg_backtrace(void)
+void
+xorg_backtrace(void)
{
void *array[64];
const char *mod;
int size, i;
Dl_info info;
+
ErrorF("\n");
ErrorF("Backtrace:\n");
size = backtrace(array, 64);
for (i = 0; i < size; i++) {
- int rc = dladdr(array[i], &info);
- if (rc == 0) {
- ErrorF("%d: ?? [%p]\n", i, array[i]);
- continue;
- }
- mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
- if (info.dli_saddr)
- ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
- info.dli_sname, (long unsigned int)((char *) array[i] - (char *) info.dli_saddr), array[i]);
- else
- ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
- info.dli_fbase, (long unsigned int)((char *) array[i] - (char *) info.dli_fbase), array[i]);
+ int rc = dladdr(array[i], &info);
+
+ if (rc == 0) {
+ ErrorF("%d: ?? [%p]\n", i, array[i]);
+ continue;
+ }
+ mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
+ if (info.dli_saddr)
+ ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
+ info.dli_sname,
+ (long unsigned int) ((char *) array[i] -
+ (char *) info.dli_saddr), array[i]);
+ else
+ ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
+ info.dli_fbase,
+ (long unsigned int) ((char *) array[i] -
+ (char *) info.dli_fbase), array[i]);
}
ErrorF("\n");
}
-#else /* not glibc or glibc < 2.1 */
+#else /* not glibc or glibc < 2.1 */
-# if defined(sun) && defined(__SVR4)
-# define HAVE_PSTACK
-# endif
+#if defined(sun) && defined(__SVR4)
+#define HAVE_PSTACK
+#endif
-# if defined(HAVE_WALKCONTEXT) /* Solaris 9 & later */
+#if defined(HAVE_WALKCONTEXT) /* Solaris 9 & later */
-# include <ucontext.h>
-# include <signal.h>
-# include <dlfcn.h>
-# include <sys/elf.h>
+#include <ucontext.h>
+#include <signal.h>
+#include <dlfcn.h>
+#include <sys/elf.h>
#ifdef _LP64
-# define ElfSym Elf64_Sym
+#define ElfSym Elf64_Sym
#else
-# define ElfSym Elf32_Sym
+#define ElfSym Elf32_Sym
#endif
/* Called for each frame on the stack to print it's contents */
-static int xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
+static int
+xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
{
Dl_info dlinfo;
ElfSym *dlsym;
@@ -91,13 +99,13 @@ static int xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
int depth = *((int *) arg);
if (signo) {
- char signame[SIG2STR_MAX];
+ char signame[SIG2STR_MAX];
- if (sig2str(signo, signame) != 0) {
- strcpy(signame, "unknown");
- }
+ if (sig2str(signo, signame) != 0) {
+ strcpy(signame, "unknown");
+ }
- ErrorF("** Signal %d (%s)\n", signo, signame);
+ ErrorF("** Signal %d (%s)\n", signo, signame);
}
snprintf(header, sizeof(header), "%d: 0x%lx", depth, pc);
@@ -105,118 +113,127 @@ static int xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
/* Ask system dynamic loader for info on the address */
if (dladdr1((void *) pc, &dlinfo, (void **) &dlsym, RTLD_DL_SYMENT)) {
- unsigned long offset = pc - (uintptr_t) dlinfo.dli_saddr;
- const char *symname;
-
- if (offset < dlsym->st_size) { /* inside a function */
- symname = dlinfo.dli_sname;
- } else { /* found which file it was in, but not which function */
- symname = "<section start>";
- offset = pc - (uintptr_t)dlinfo.dli_fbase;
- }
- ErrorF("%s: %s:%s+0x%lx\n", header, dlinfo.dli_fname,
- symname, offset);
-
- } else {
- /* Couldn't find symbol info from system dynamic loader, should
- * probably poke elfloader here, but haven't written that code yet,
- * so we just print the pc.
- */
- ErrorF("%s\n", header);
+ unsigned long offset = pc - (uintptr_t) dlinfo.dli_saddr;
+ const char *symname;
+
+ if (offset < dlsym->st_size) { /* inside a function */
+ symname = dlinfo.dli_sname;
+ }
+ else { /* found which file it was in, but not which function */
+ symname = "<section start>";
+ offset = pc - (uintptr_t) dlinfo.dli_fbase;
+ }
+ ErrorF("%s: %s:%s+0x%lx\n", header, dlinfo.dli_fname, symname, offset);
+
+ }
+ else {
+ /* Couldn't find symbol info from system dynamic loader, should
+ * probably poke elfloader here, but haven't written that code yet,
+ * so we just print the pc.
+ */
+ ErrorF("%s\n", header);
}
return 0;
}
-# endif /* HAVE_WALKCONTEXT */
+#endif /* HAVE_WALKCONTEXT */
-# ifdef HAVE_PSTACK
-static int xorg_backtrace_pstack(void) {
+#ifdef HAVE_PSTACK
+static int
+xorg_backtrace_pstack(void)
+{
pid_t kidpid;
int pipefd[2];
if (pipe(pipefd) != 0) {
- return -1;
+ return -1;
}
kidpid = fork1();
if (kidpid == -1) {
- /* ERROR */
- return -1;
- } else if (kidpid == 0) {
- /* CHILD */
- char parent[16];
-
- seteuid(0);
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- dup2(pipefd[1],STDOUT_FILENO);
- closefrom(STDERR_FILENO);
-
- snprintf(parent, sizeof(parent), "%d", getppid());
- execle("/usr/bin/pstack", "pstack", parent, NULL);
- exit(1);
- } else {
- /* PARENT */
- char btline[256];
- int kidstat;
- int bytesread;
- int done = 0;
-
- close(pipefd[1]);
-
- while (!done) {
- bytesread = read(pipefd[0], btline, sizeof(btline) - 1);
-
- if (bytesread > 0) {
- btline[bytesread] = 0;
- ErrorF("%s", btline);
- }
- else if ((bytesread < 0) ||
- ((errno != EINTR) && (errno != EAGAIN)))
- done = 1;
- }
- close(pipefd[0]);
- waitpid(kidpid, &kidstat, 0);
- if (kidstat != 0)
- return -1;
+ /* ERROR */
+ return -1;
+ }
+ else if (kidpid == 0) {
+ /* CHILD */
+ char parent[16];
+
+ seteuid(0);
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ dup2(pipefd[1], STDOUT_FILENO);
+ closefrom(STDERR_FILENO);
+
+ snprintf(parent, sizeof(parent), "%d", getppid());
+ execle("/usr/bin/pstack", "pstack", parent, NULL);
+ exit(1);
+ }
+ else {
+ /* PARENT */
+ char btline[256];
+ int kidstat;
+ int bytesread;
+ int done = 0;
+
+ close(pipefd[1]);
+
+ while (!done) {
+ bytesread = read(pipefd[0], btline, sizeof(btline) - 1);
+
+ if (bytesread > 0) {
+ btline[bytesread] = 0;
+ ErrorF("%s", btline);
+ }
+ else if ((bytesread < 0) || ((errno != EINTR) && (errno != EAGAIN)))
+ done = 1;
+ }
+ close(pipefd[0]);
+ waitpid(kidpid, &kidstat, 0);
+ if (kidstat != 0)
+ return -1;
}
return 0;
}
-# endif /* HAVE_PSTACK */
-
+#endif /* HAVE_PSTACK */
-# if defined(HAVE_PSTACK) || defined(HAVE_WALKCONTEXT)
+#if defined(HAVE_PSTACK) || defined(HAVE_WALKCONTEXT)
-void xorg_backtrace(void) {
+void
+xorg_backtrace(void)
+{
ErrorF("\n");
ErrorF("Backtrace:\n");
-# ifdef HAVE_PSTACK
+#ifdef HAVE_PSTACK
/* First try fork/exec of pstack - otherwise fall back to walkcontext
pstack is preferred since it can print names of non-exported functions */
if (xorg_backtrace_pstack() < 0)
-# endif
+#endif
{
-# ifdef HAVE_WALKCONTEXT
- ucontext_t u;
- int depth = 1;
-
- if (getcontext(&u) == 0)
- walkcontext(&u, xorg_backtrace_frame, &depth);
- else
-# endif
- ErrorF("Failed to get backtrace info: %s\n", strerror(errno));
+#ifdef HAVE_WALKCONTEXT
+ ucontext_t u;
+ int depth = 1;
+
+ if (getcontext(&u) == 0)
+ walkcontext(&u, xorg_backtrace_frame, &depth);
+ else
+#endif
+ ErrorF("Failed to get backtrace info: %s\n", strerror(errno));
}
ErrorF("\n");
}
-# else
+#else
/* Default fallback if we can't find any way to get a backtrace */
-void xorg_backtrace(void) { return; }
+void
+xorg_backtrace(void)
+{
+ return;
+}
-# endif
+#endif
#endif