r4399 - in branches/2.0/varnish-cache: bin/varnishd include/compat lib/libvarnishcompat

tfheen at projects.linpro.no tfheen at projects.linpro.no
Wed Dec 16 09:59:41 CET 2009


Author: tfheen
Date: 2009-12-16 09:59:41 +0100 (Wed, 16 Dec 2009)
New Revision: 4399

Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache_panic.c
   branches/2.0/varnish-cache/include/compat/execinfo.h
   branches/2.0/varnish-cache/lib/libvarnishcompat/execinfo.c
Log:
Merge r4349: Hide GCC specific backtrace() compat function under a #ifdef.
    
We do not want to be dependent on GCC.
    
Fixes #577



Modified: branches/2.0/varnish-cache/bin/varnishd/cache_panic.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_panic.c	2009-12-16 08:50:49 UTC (rev 4398)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_panic.c	2009-12-16 08:59:41 UTC (rev 4399)
@@ -264,6 +264,8 @@
 	size_t i;
 
 	size = backtrace (array, 10);
+	if (size == 0)
+		return;
 	vsb_printf(vsp, "Backtrace:\n");
 	for (i = 0; i < size; i++) {
 		vsb_printf (vsp, "  ");

Modified: branches/2.0/varnish-cache/include/compat/execinfo.h
===================================================================
--- branches/2.0/varnish-cache/include/compat/execinfo.h	2009-12-16 08:50:49 UTC (rev 4398)
+++ branches/2.0/varnish-cache/include/compat/execinfo.h	2009-12-16 08:59:41 UTC (rev 4399)
@@ -35,7 +35,6 @@
 
 int     backtrace(void **, int);
 char ** backtrace_symbols(void *const *, int);
-void    backtrace_symbols_fd(void *const *, int, int);
 
 #ifdef __cplusplus
 }

Modified: branches/2.0/varnish-cache/lib/libvarnishcompat/execinfo.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnishcompat/execinfo.c	2009-12-16 08:50:49 UTC (rev 4398)
+++ branches/2.0/varnish-cache/lib/libvarnishcompat/execinfo.c	2009-12-16 08:59:41 UTC (rev 4399)
@@ -28,6 +28,10 @@
 
 #include "config.h"
 
+#include "compat/execinfo.h"
+
+#if defined (__GNUC__) && __GNUC__ >= 4	/* XXX Correct version to check for ? */
+
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <dlfcn.h>
@@ -38,10 +42,9 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "compat/execinfo.h"
 
-void *getreturnaddr(int);
-void *getframeaddr(int);
+static void *getreturnaddr(int);
+static void *getframeaddr(int);
 
 #define D10(x) ceil(log10(((x) == 0) ? 2 : ((x) + 1)))
 
@@ -132,51 +135,7 @@
     return rval;
 }
 
-#if 0
-void
-backtrace_symbols_fd(void *const *buffer, int size, int fd)
-{
-    int i, len, offset;
-    char *buf;
-    Dl_info info;
-
-    for (i = 0; i < size; i++) {
-        if (dladdr(buffer[i], &info) != 0) {
-            if (info.dli_sname == NULL)
-                info.dli_sname = "???";
-            if (info.dli_saddr == NULL)
-                info.dli_saddr = buffer[i];
-            offset = (const char *)buffer[i] - (const char *)info.dli_saddr;
-            /* "0x01234567 <function+offset> at filename" */
-            len = 2 +                      /* "0x" */
-                  (sizeof(void *) * 2) +   /* "01234567" */
-                  2 +                      /* " <" */
-                  strlen(info.dli_sname) + /* "function" */
-                  1 +                      /* "+" */
-                  D10(offset) +            /* "offset */
-                  5 +                      /* "> at " */
-                  strlen(info.dli_fname) + /* "filename" */
-                  2;                       /* "\n\0" */
-            buf = alloca(len);
-            if (buf == NULL)
-                return;
-            snprintf(buf, len, "%p <%s+%d> at %s\n",
-              buffer[i], info.dli_sname, offset, info.dli_fname);
-        } else {
-            len = 2 +                      /* "0x" */
-                  (sizeof(void *) * 2) +   /* "01234567" */
-                  2;                       /* "\n\0" */
-            buf = alloca(len);
-            if (buf == NULL)
-                return;
-            snprintf(buf, len, "%p\n", buffer[i]);
-        }
-        write(fd, buf, len - 1);
-    }
-}
-#endif
-
-void *
+static void *
 getreturnaddr(int level)
 {
 
@@ -313,7 +272,7 @@
     }
 }
 
-void *
+static void *
 getframeaddr(int level)
 {
 
@@ -449,3 +408,23 @@
     default: return NULL;
     }
 }
+
+#else
+
+int
+backtrace(void **buffer, int size)
+{
+	(void)buffer;
+	(void)size;
+	return (0);
+}
+
+char **
+backtrace_symbols(void *const *buffer, int size)
+{
+	(void)buffer;
+	(void)size;
+	return (0);
+}
+
+#endif



More information about the varnish-commit mailing list