[master] 95437e6 Get rid of the old "symbol" hack, it worked fine when everybody used GCC.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Jan 27 13:45:06 CET 2017
commit 95437e6c882f2c2b332be94060a7ac96907db322
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Jan 27 11:40:06 2017 +0000
Get rid of the old "symbol" hack, it worked fine when everybody used GCC.
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index 578f54c..5d3b23c 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -80,16 +80,6 @@ VDP_push(struct req *req, vdp_bytes *func, void *priv, int bottom,
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
AN(func);
-#if 0
- // Gross hack for debugging
- struct vsb *vsb;
- vsb = VSB_new_auto();
- AN(vsb);
- Symbol_Lookup(vsb, func);
- AZ(VSB_finish(vsb));
- VSLb(req->vsl, SLT_Debug, "VDP %s %p %d", VSB_data(vsb), priv, bottom);
- VSB_destroy(&vsb);
-#endif
vdp = WS_Alloc(req->ws, sizeof *vdp);
if (vdp == NULL)
return;
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 8b6ad6d..16ecf47 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -31,6 +31,7 @@
#include <execinfo.h>
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@@ -526,6 +527,7 @@ pan_backtrace(struct vsb *vsb)
size_t i;
char **strings;
char *p;
+ char buf[32];
size = backtrace (array, BACKTRACE_LEVELS);
if (size > BACKTRACE_LEVELS) {
@@ -535,18 +537,21 @@ pan_backtrace(struct vsb *vsb)
VSB_printf(vsb, "Backtrace:\n");
VSB_indent(vsb, 2);
for (i = 0; i < size; i++) {
- if (Symbol_Lookup(vsb, array[i]) < 0) {
- strings = backtrace_symbols(&array[i], 1);
- if (strings == NULL || strings[0] == NULL) {
- VSB_printf(vsb, "%p: (?)", array[i]);
- } else {
- p = strrchr(strings[0], '/');
- if (p == NULL)
- p = strings[0];
- else
+ bprintf(buf, "%p", array[i]);
+ VSB_printf(vsb, "%s: ", buf);
+ strings = backtrace_symbols(&array[i], 1);
+ if (strings == NULL || strings[0] == NULL) {
+ VSB_printf(vsb, "(?)");
+ } else {
+ p = strings[0];
+ if (!memcmp(buf, p, strlen(buf))) {
+ p += strlen(buf);
+ if (*p == ':')
+ p++;
+ while(*p == ' ')
p++;
- VSB_printf(vsb, "%p: %s", array[i], p);
}
+ VSB_printf(vsb, "%s", p);
}
VSB_printf (vsb, "\n");
}
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
index b476cb9..27da283 100644
--- a/bin/varnishd/common/common.h
+++ b/bin/varnishd/common/common.h
@@ -59,8 +59,6 @@ extern pid_t mgt_pid;
/* varnishd.c */
extern struct vsb *vident; // XXX: -> heritage ?
-int Symbol_Lookup(struct vsb *vsb, void *ptr);
-
/* Really belongs in mgt.h, but storage_file chokes on both */
void MCH_Fd_Inherit(int fd, const char *what);
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 60e7def..d2dc522 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -171,7 +171,6 @@ void mgt_DumpRstVsl(void);
struct vsb *mgt_BuildVident(void);
void MGT_Complain(const char *, const char *, ...) __v_printflike(2, 3);
const void *MGT_Pick(const struct choice *, const char *, const char *);
-void mgt_SymbolHack(const char *);
/* stevedore_mgt.c */
void STV_Config(const char *spec);
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 652a273..286c025 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -565,8 +565,6 @@ main(int argc, char * const *argv)
vident = mgt_BuildVident();
- mgt_SymbolHack(argv[0]);
-
/* Various initializations */
VTAILQ_INIT(&heritage.socks);
mgt_evb = vev_new_base();
diff --git a/bin/varnishd/mgt/mgt_util.c b/bin/varnishd/mgt/mgt_util.c
index 83b3bc5..0870089 100644
--- a/bin/varnishd/mgt/mgt_util.c
+++ b/bin/varnishd/mgt/mgt_util.c
@@ -153,75 +153,3 @@ MGT_Pick(const struct choice *cp, const char *which, const char *kind)
}
ARGV_ERR("Unknown %s method \"%s\"\n", kind, which);
}
-
-/*--------------------------------------------------------------------
- * All praise POSIX! Thanks to our glorious standards there are no
- * standard way to get a back-trace of the stack, and even if we hack
- * that together from spit and pieces of string, there is no way no
- * standard way to translate a pointer to a symbol, which returns anything
- * usable. (See for instance FreeBSD PR-134391).
- *
- * Attempt to run nm(1) on our binary during startup, hoping it will
- * give us a usable list of symbols.
- */
-
-struct symbols {
- uintptr_t a;
- uintptr_t l;
- char *n;
- VTAILQ_ENTRY(symbols) list;
-};
-
-static VTAILQ_HEAD(,symbols) symbols = VTAILQ_HEAD_INITIALIZER(symbols);
-
-int
-Symbol_Lookup(struct vsb *vsb, void *ptr)
-{
- struct symbols *s, *s0;
- uintptr_t pp;
-
- pp = (uintptr_t)ptr;
- s0 = NULL;
- VTAILQ_FOREACH(s, &symbols, list) {
- if (s->a > pp || s->a + s->l <= pp)
- continue;
- if (s0 == NULL || s->l < s0->l)
- s0 = s;
- }
- if (s0 == NULL)
- return (-1);
- VSB_printf(vsb, "%p: %s", ptr, s0->n);
- if ((uintmax_t)pp != s0->a)
- VSB_printf(vsb, "+0x%jx", (uintmax_t)pp - s0->a);
- return (0);
-}
-
-void
-mgt_SymbolHack(const char *a0)
-{
- char buf[BUFSIZ];
- FILE *fi;
- struct symbols *s;
- uintmax_t aa, ll;
- char type[10];
- char name[100];
- int i;
-
- bprintf(buf, "nm -t x -n -P %s 2>/dev/null", a0);
- fi = popen(buf, "r");
- if (fi == NULL)
- return;
- while (fgets(buf, sizeof buf, fi)) {
- i = sscanf(buf, "%99s\t%9s\t%jx\t%jx\n", name, type, &aa, &ll);
- if (i != 4)
- continue;
- s = malloc(sizeof *s + strlen(name) + 1);
- AN(s);
- s->a = aa;
- s->l = ll;
- s->n = (void*)(s + 1);
- strcpy(s->n, name);
- VTAILQ_INSERT_TAIL(&symbols, s, list);
- }
- (void)pclose(fi);
-}
More information about the varnish-commit
mailing list