[4.1] 55e253f Roto-till the panic/backtrace output to use the VSB auto-indent.

Poul-Henning Kamp phk at FreeBSD.org
Fri Sep 4 15:54:51 CEST 2015


commit 55e253fd0405a96dcd77f31fbda416506515fb7d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jul 31 08:08:43 2015 +0000

    Roto-till the panic/backtrace output to use the VSB auto-indent.
    
    Based largely on patch from:	Martin
    
    I wonder if we should make the panic output (readable) JSON format ?

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 75adf78..092abb3 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -319,17 +319,17 @@ vbe_panic(const struct director *d, struct vsb *vsb)
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
 
-	VSB_printf(vsb, "      display_name = %s\n", bp->display_name);
+	VSB_printf(vsb, "display_name = %s\n", bp->display_name);
 	if (bp->ipv4_addr != NULL)
-		VSB_printf(vsb, "      ipv4 = %s\n", bp->ipv4_addr);
+		VSB_printf(vsb, "ipv4 = %s\n", bp->ipv4_addr);
 	if (bp->ipv6_addr != NULL)
-		VSB_printf(vsb, "      ipv6 = %s\n", bp->ipv6_addr);
-	VSB_printf(vsb, "      port = %s\n", bp->port);
-	VSB_printf(vsb, "      hosthdr = %s\n", bp->hosthdr);
-	VSB_printf(vsb, "      health=%s, admin_health=%s",
+		VSB_printf(vsb, "ipv6 = %s\n", bp->ipv6_addr);
+	VSB_printf(vsb, "port = %s\n", bp->port);
+	VSB_printf(vsb, "hosthdr = %s\n", bp->hosthdr);
+	VSB_printf(vsb, "health=%s, admin_health=%s",
 	    bp->healthy ? "healthy" : "sick", bp->admin_health);
 	VSB_printf(vsb, ", changed=%.1f\n", bp->health_changed);
-	VSB_printf(vsb, "      n_conn = %u\n", bp->n_conn);
+	VSB_printf(vsb, "n_conn = %u\n", bp->n_conn);
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index f7e0479..b6d0944 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -187,10 +187,15 @@ VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm)
 {
 	if (d == NULL)
 		return;
-	VSB_printf(vsb, "    %s = %p {\n", nm, d);
-	VSB_printf(vsb, "      vcl_name = %s\n", d->vcl_name);
-	VSB_printf(vsb, "      name = %s\n", d->name);
+	VSB_printf(vsb, "%s = %p {\n", nm, d);
+	VSB_indent(vsb, 2);
+	VSB_printf(vsb, "vcl_name = %s\n", d->vcl_name);
+	VSB_printf(vsb, "type = %s {\n", d->name);
+	VSB_indent(vsb, 2);
 	if (d->panic != NULL)
 		d->panic(d, vsb);
-	VSB_printf(vsb, "    }\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "}\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "}\n");
 }
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index bfe3e70..873c5e0 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -58,10 +58,10 @@
  * (gdb) printf "%s", panicstr
  */
 
-static struct vsb pan_vsp_storage, *pan_vsp;
+static struct vsb pan_vsb_storage, *pan_vsb;
 static pthread_mutex_t panicstr_mtx = PTHREAD_MUTEX_INITIALIZER;
 
-static void pan_sess(const struct sess *sp);
+static void pan_sess(struct vsb *, const struct sess *);
 
 /*--------------------------------------------------------------------*/
 
@@ -110,252 +110,206 @@ sess_close_2str(enum sess_close sc, int want_desc)
 /*--------------------------------------------------------------------*/
 
 static void
-pan_ws(const struct ws *ws, int indent)
+pan_ws(struct vsb *vsb, const struct ws *ws)
 {
 
-	VSB_printf(pan_vsp, "%*sws = %p {", indent, "", ws);
-	if (!VALID_OBJ(ws, WS_MAGIC)) {
-		if (ws != NULL)
-			VSB_printf(pan_vsp, " BAD_MAGIC(0x%08x) ", ws->magic);
-	} else {
-		if (WS_Overflowed(ws))
-			VSB_printf(pan_vsp, " OVERFLOW");
-		VSB_printf(pan_vsp,
-		    "\n%*sid = \"%s\",\n", indent + 2, "", ws->id);
-		VSB_printf(pan_vsp,
-		    "%*s{s,f,r,e} = {%p", indent + 2, "", ws->s);
-		if (ws->f > ws->s)
-			VSB_printf(pan_vsp, ",+%ld", (long) (ws->f - ws->s));
-		else
-			VSB_printf(pan_vsp, ",%p", ws->f);
-		if (ws->r > ws->s)
-			VSB_printf(pan_vsp, ",+%ld", (long) (ws->r - ws->s));
-		else
-			VSB_printf(pan_vsp, ",%p", ws->r);
-		if (ws->e > ws->s)
-			VSB_printf(pan_vsp, ",+%ld", (long) (ws->e - ws->s));
-		else
-			VSB_printf(pan_vsp, ",%p", ws->e);
-	}
-	VSB_printf(pan_vsp, "},\n");
-	VSB_printf(pan_vsp, "%*s},\n", indent, "" );
+	VSB_printf(vsb, "ws = %p {\n", ws);
+	VSB_indent(vsb, 2);
+	if (WS_Overflowed(ws))
+		VSB_printf(vsb, " OVERFLOW");
+	VSB_printf(vsb, "id = \"%s\",\n",  ws->id);
+	VSB_printf(vsb, "{s,f,r,e} = {%p",  ws->s);
+	if (ws->f > ws->s)
+		VSB_printf(vsb, ",+%ld", (long) (ws->f - ws->s));
+	else
+		VSB_printf(vsb, ",%p", ws->f);
+	if (ws->r > ws->s)
+		VSB_printf(vsb, ",+%ld", (long) (ws->r - ws->s));
+	else
+		VSB_printf(vsb, ",%p", ws->r);
+	if (ws->e > ws->s)
+		VSB_printf(vsb, ",+%ld", (long) (ws->e - ws->s));
+	else
+		VSB_printf(vsb, ",%p", ws->e);
+	VSB_printf(vsb, "},\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
 }
 
 /*--------------------------------------------------------------------*/
 
 static void
-pan_htc(const struct http_conn *htc)
+pan_htc(struct vsb *vsb, const struct http_conn *htc)
 {
 
-	VSB_printf(pan_vsp, "    http_conn = %p {\n", htc);
-	VSB_printf(pan_vsp, "      fd = %d,\n", htc->fd);
-	VSB_printf(pan_vsp, "    },\n");
+	VSB_printf(vsb, "http_conn = %p {\n", htc);
+	VSB_indent(vsb, 2);
+	VSB_printf(vsb, "fd = %d,\n", htc->fd);
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
 }
 
 /*--------------------------------------------------------------------*/
 
-#if 0
 static void
-pan_storage(const struct storage *st)
-{
-	int i, j;
-
-#define MAX_BYTES (4*16)
-#define show(ch) (((ch) > 31 && (ch) < 127) ? (ch) : '.')
-
-	VSB_printf(pan_vsp, "      %u {\n", st->len);
-	for (i = 0; i < MAX_BYTES && i < st->len; i += 16) {
-		VSB_printf(pan_vsp, "        ");
-		for (j = 0; j < 16; ++j) {
-			if (i + j < st->len)
-				VSB_printf(pan_vsp, "%02x ", st->ptr[i + j]);
-			else
-				VSB_printf(pan_vsp, "   ");
-		}
-		VSB_printf(pan_vsp, "|");
-		for (j = 0; j < 16; ++j)
-			if (i + j < st->len)
-				VSB_printf(pan_vsp,
-				    "%c", show(st->ptr[i + j]));
-		VSB_printf(pan_vsp, "|\n");
-	}
-	if (st->len > MAX_BYTES)
-		VSB_printf(pan_vsp,
-		    "        [%u more]\n", st->len - MAX_BYTES);
-	VSB_printf(pan_vsp, "      },\n");
-
-#undef show
-#undef MAX_BYTES
-}
-#endif
-
-/*--------------------------------------------------------------------*/
-
-static void
-pan_http(const char *id, const struct http *h, int indent)
+pan_http(struct vsb *vsb, const char *id, const struct http *h)
 {
 	int i;
 
-	VSB_printf(pan_vsp, "%*shttp[%s] = {\n", indent, "", id);
-	VSB_printf(pan_vsp, "%*sws = %p[%s]\n", indent + 2, "",
-	    h->ws, h->ws ? h->ws->id : "");
+	VSB_printf(vsb, "http[%s] = %p {\n", id, h);
+	VSB_indent(vsb, 2);
+	VSB_printf(vsb, "ws[%s] = %p\n", h->ws ? h->ws->id : "", h->ws);
+	VSB_printf(vsb, "hdrs {\n");
+	VSB_indent(vsb, 2);
 	for (i = 0; i < h->nhd; ++i) {
 		if (h->hd[i].b == NULL && h->hd[i].e == NULL)
 			continue;
-		VSB_printf(pan_vsp, "%*s\"%.*s\",\n", indent + 4, "",
-		    (int)(h->hd[i].e - h->hd[i].b),
-		    h->hd[i].b);
+		VSB_printf(vsb, "\"%.*s\",\n",
+		    (int)(h->hd[i].e - h->hd[i].b), h->hd[i].b);
 	}
-	VSB_printf(pan_vsp, "%*s},\n", indent, "");
-}
-
-
-/*--------------------------------------------------------------------*/
-
-#if 0
-static void
-pan_object(const char *typ, const struct object *o)
-{
-	const struct storage *st;
-
-	VSB_printf(pan_vsp, "  obj (%s) = %p {\n", typ, o);
-	VSB_printf(pan_vsp, "    vxid = %u,\n", VXID(vbe32dec(o->oa_vxid)));
-	pan_http("obj", o->http, 4);
-	VSB_printf(pan_vsp, "    len = %jd,\n", (intmax_t)o->body->len);
-	VSB_printf(pan_vsp, "    store = {\n");
-	VTAILQ_FOREACH(st, &o->body->list, list)
-		pan_storage(st);
-	VSB_printf(pan_vsp, "    },\n");
-	VSB_printf(pan_vsp, "  },\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
 }
-#endif
 
 /*--------------------------------------------------------------------*/
 
 static void
-pan_objcore(const char *typ, const struct objcore *oc)
+pan_objcore(struct vsb *vsb, const char *typ, const struct objcore *oc)
 {
 
-	VSB_printf(pan_vsp, "  objcore (%s) = %p {\n", typ, oc);
-	VSB_printf(pan_vsp, "    refcnt = %d\n", oc->refcnt);
-	VSB_printf(pan_vsp, "    flags = 0x%x\n", oc->flags);
-	VSB_printf(pan_vsp, "    objhead = %p\n", oc->objhead);
-	VSB_printf(pan_vsp, "    stevedore = %p", oc->stobj->stevedore);
+	VSB_printf(vsb, "objcore[%s] = %p {\n", typ, oc);
+	VSB_indent(vsb, 2);
+	VSB_printf(vsb, "refcnt = %d\n", oc->refcnt);
+	VSB_printf(vsb, "flags = 0x%x\n", oc->flags);
+	VSB_printf(vsb, "objhead = %p\n", oc->objhead);
+	VSB_printf(vsb, "stevedore = %p", oc->stobj->stevedore);
 	if (oc->stobj->stevedore != NULL) {
-		VSB_printf(pan_vsp, " (%s", oc->stobj->stevedore->name);
+		VSB_printf(vsb, " (%s", oc->stobj->stevedore->name);
 		if (strlen(oc->stobj->stevedore->ident))
-			VSB_printf(pan_vsp, " %s", oc->stobj->stevedore->ident);
-		VSB_printf(pan_vsp, ")");
+			VSB_printf(vsb, " %s", oc->stobj->stevedore->ident);
+		VSB_printf(vsb, ")");
 	}
-	VSB_printf(pan_vsp, "\n");
-	VSB_printf(pan_vsp, "  }\n");
+	VSB_printf(vsb, "\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "}\n");
 }
 
 /*--------------------------------------------------------------------*/
 
 static void
-pan_wrk(const struct worker *wrk)
+pan_wrk(struct vsb *vsb, const struct worker *wrk)
 {
 	const char *hand;
 	unsigned m, u;
 	const char *p;
 
-	VSB_printf(pan_vsp, "  worker = %p {\n", wrk);
-	VSB_printf(pan_vsp, "    stack = {0x%jx -> 0x%jx}\n",
+	VSB_printf(vsb, "worker = %p {\n", wrk);
+	VSB_indent(vsb, 2);
+	VSB_printf(vsb, "stack = {0x%jx -> 0x%jx}\n",
 	    (uintmax_t)wrk->stack_start, (uintmax_t)wrk->stack_end);
-	pan_ws(wrk->aws, 4);
+	pan_ws(vsb, wrk->aws);
 
 	m = wrk->cur_method;
-	VSB_printf(pan_vsp, "    VCL::method = ");
+	VSB_printf(vsb, "VCL::method = ");
 	if (m == 0) {
-		VSB_printf(pan_vsp, "none,\n");
+		VSB_printf(vsb, "none,\n");
 		return;
 	}
 	if (!(m & 1))
-		VSB_printf(pan_vsp, "*");
+		VSB_printf(vsb, "inside ");
 	m &= ~1;
 	hand = VCL_Method_Name(m);
 	if (hand != NULL)
-		VSB_printf(pan_vsp, "%s,\n", hand);
+		VSB_printf(vsb, "%s,\n", hand);
 	else
-		VSB_printf(pan_vsp, "0x%x,\n", m);
+		VSB_printf(vsb, "0x%x,\n", m);
+
 	hand = VCL_Return_Name(wrk->handling);
 	if (hand != NULL)
-		VSB_printf(pan_vsp, "    VCL::return = %s,\n", hand);
+		VSB_printf(vsb, "VCL::return = %s,\n", hand);
 	else
-		VSB_printf(pan_vsp, "    VCL::return = 0x%x,\n", wrk->handling);
-	VSB_printf(pan_vsp, "    VCL::methods = {");
+		VSB_printf(vsb, "VCL::return = 0x%x,\n", wrk->handling);
+	VSB_printf(vsb, "VCL::methods = {");
 	m = wrk->seen_methods;
 	p = "";
 	for (u = 1; m ; u <<= 1) {
 		if (m & u) {
-			VSB_printf(pan_vsp, "%s%s", p, VCL_Method_Name(u));
+			VSB_printf(vsb, "%s%s", p, VCL_Method_Name(u));
 			m &= ~u;
 			p = ", ";
 		}
 	}
-	VSB_printf(pan_vsp, "},\n  },\n");
+	VSB_printf(vsb, "},\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
 }
 
 static void
-pan_busyobj(const struct busyobj *bo)
+pan_busyobj(struct vsb *vsb, const struct busyobj *bo)
 {
 	struct vfp_entry *vfe;
+	const char *p;
 
-	VSB_printf(pan_vsp, "  busyobj = %p {\n", bo);
-	pan_ws(bo->ws, 4);
-	VSB_printf(pan_vsp, "    refcnt = %u\n", bo->refcount);
-	VSB_printf(pan_vsp, "    retries = %d\n", bo->retries);
-	VSB_printf(pan_vsp, "    failed = %d\n", bo->vfc->failed);
-	VSB_printf(pan_vsp, "    state = %d\n", (int)bo->state);
-	VSB_printf(pan_vsp, "    flags = {\n");
-#define BO_FLAG(l, r, w, d) if(bo->l) VSB_printf(pan_vsp, "      " #l "\n");
+	VSB_printf(vsb, "busyobj = %p {\n", bo);
+	VSB_indent(vsb, 2);
+	pan_ws(vsb, bo->ws);
+	VSB_printf(vsb, "refcnt = %u\n", bo->refcount);
+	VSB_printf(vsb, "retries = %d, ", bo->retries);
+	VSB_printf(vsb, "failed = %d, ", bo->vfc->failed);
+	VSB_printf(vsb, "state = %d\n", (int)bo->state);
+	VSB_printf(vsb, "flags = {");
+	p = "";
+#define BO_FLAG(l, r, w, d) \
+	if(bo->l) { VSB_printf(vsb,  "%s" #l, p); p = ", "; }
 #include "tbl/bo_flags.h"
 #undef BO_FLAG
-	VSB_printf(pan_vsp, "    }\n");
+	VSB_printf(vsb, "}\n");
 
 	if (bo->htc != NULL) {
-		VSB_printf(pan_vsp, "    bodystatus = %d (%s),\n",
+		VSB_printf(vsb, "bodystatus = %d (%s),\n",
 		    bo->htc->body_status,
 		    body_status_2str(bo->htc->body_status));
 	}
 	if (!VTAILQ_EMPTY(&bo->vfc->vfp)) {
-		VSB_printf(pan_vsp, "    filters =");
+		VSB_printf(vsb, "filters =");
 		VTAILQ_FOREACH(vfe, &bo->vfc->vfp, list)
-			VSB_printf(pan_vsp, " %s=%d",
+			VSB_printf(vsb, " %s=%d",
 			    vfe->vfp->name, (int)vfe->closed);
-		VSB_printf(pan_vsp, "\n");
+		VSB_printf(vsb, "\n");
 	}
 
 	if (VALID_OBJ(bo->htc, HTTP_CONN_MAGIC))
-		pan_htc(bo->htc);
-	VDI_Panic(bo->director_req, pan_vsp, "director_req");
+		pan_htc(vsb, bo->htc);
+	VDI_Panic(bo->director_req, vsb, "director_req");
 	if (bo->director_resp == bo->director_req)
-		VSB_printf(pan_vsp, "    director_resp = director_req\n");
+		VSB_printf(vsb, "director_resp = director_req\n");
 	else
-		VDI_Panic(bo->director_resp, pan_vsp, "director_resp");
+		VDI_Panic(bo->director_resp, vsb, "director_resp");
 	if (bo->bereq != NULL && bo->bereq->ws != NULL)
-		pan_http("bereq", bo->bereq, 4);
+		pan_http(vsb, "bereq", bo->bereq);
 	if (bo->beresp != NULL && bo->beresp->ws != NULL)
-		pan_http("beresp", bo->beresp, 4);
+		pan_http(vsb, "beresp", bo->beresp);
 	if (bo->fetch_objcore)
-		pan_objcore("FETCH", bo->fetch_objcore);
+		pan_objcore(vsb, "fetch", bo->fetch_objcore);
 	if (bo->stale_oc)
-		pan_objcore("IMS", bo->stale_oc);
-	VSB_printf(pan_vsp, "  }\n");
+		pan_objcore(vsb, "ims", bo->stale_oc);
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "}\n");
 }
 
 /*--------------------------------------------------------------------*/
 
 static void
-pan_req(const struct req *req)
+pan_req(struct vsb *vsb, const struct req *req)
 {
 	const char *stp;
 
-	VSB_printf(pan_vsp, "req = %p {\n", req);
+	VSB_printf(vsb, "req = %p {\n", req);
+	VSB_indent(vsb, 2);
 
-	VSB_printf(pan_vsp, "  sp = %p, vxid = %u,",
-	    req->sp, VXID(req->vsl->wid));
+	VSB_printf(vsb, "vxid = %u, ", VXID(req->vsl->wid));
 
 	switch (req->req_step) {
 #define REQ_STEP(l, u, arg) case R_STP_##u: stp = "R_STP_" #u; break;
@@ -364,64 +318,65 @@ pan_req(const struct req *req)
 		default: stp = NULL;
 	}
 	if (stp != NULL)
-		VSB_printf(pan_vsp, "  step = %s,\n", stp);
+		VSB_printf(vsb, "step = %s,\n", stp);
 	else
-		VSB_printf(pan_vsp, "  step = 0x%x,\n", req->req_step);
+		VSB_printf(vsb, "step = 0x%x,\n", req->req_step);
 
-	VSB_printf(pan_vsp, "  req_body = %s,\n",
+	VSB_printf(vsb, "req_body = %s,\n",
 	    reqbody_status_2str(req->req_body_status));
 
 	if (req->err_code)
-		VSB_printf(pan_vsp,
+		VSB_printf(vsb,
 		    "  err_code = %d, err_reason = %s,\n", req->err_code,
 		    req->err_reason ? req->err_reason : "(null)");
 
-	VSB_printf(pan_vsp, "  restarts = %d, esi_level = %d,\n",
+	VSB_printf(vsb, "restarts = %d, esi_level = %d,\n",
 	    req->restarts, req->esi_level);
 
 	if (req->sp != NULL)
-		pan_sess(req->sp);
+		pan_sess(vsb, req->sp);
 
 	if (req->wrk != NULL)
-		pan_wrk(req->wrk);
+		pan_wrk(vsb, req->wrk);
 
-	pan_ws(req->ws, 2);
-	pan_http("req", req->http, 2);
+	pan_ws(vsb, req->ws);
+	pan_http(vsb, "req", req->http);
 	if (req->resp->ws != NULL)
-		pan_http("resp", req->resp, 2);
+		pan_http(vsb, "resp", req->resp);
 
-	VCL_Panic(pan_vsp, req->vcl);
+	VCL_Panic(vsb, req->vcl);
 
 	if (req->objcore != NULL) {
-		pan_objcore("REQ", req->objcore);
+		pan_objcore(vsb, "REQ", req->objcore);
 		if (req->objcore->busyobj != NULL)
-			pan_busyobj(req->objcore->busyobj);
+			pan_busyobj(vsb, req->objcore->busyobj);
 	}
 
-	VSB_printf(pan_vsp, "  flags = {\n");
-#define REQ_FLAG(l, r, w, d) if(req->l) VSB_printf(pan_vsp, "    " #l ",\n");
+	VSB_printf(vsb, "flags = {\n");
+#define REQ_FLAG(l, r, w, d) if(req->l) VSB_printf(vsb, "    " #l ",\n");
 #include "tbl/req_flags.h"
 #undef REQ_FLAG
-	VSB_printf(pan_vsp, "  }\n");
+	VSB_printf(vsb, "}\n");
 
-	VSB_printf(pan_vsp, "},\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
 }
 
 /*--------------------------------------------------------------------*/
 
 static void
-pan_sess(const struct sess *sp)
+pan_sess(struct vsb *vsb, const struct sess *sp)
 {
 	const char *stp;
 	char *ci;
 	char *cp;
 
-	VSB_printf(pan_vsp, "  sp = %p {\n", sp);
-	VSB_printf(pan_vsp, "    fd = %d, vxid = %u,\n",
-	    sp->fd, VXID(sp->vxid));
+	VSB_printf(vsb, "sp = %p {\n", sp);
+	VSB_indent(vsb, 2);
+	VSB_printf(vsb, "fd = %d, vxid = %u,\n", sp->fd, VXID(sp->vxid));
 	AZ(SES_Get_client_ip(sp, &ci));
 	AZ(SES_Get_client_port(sp, &cp));
-	VSB_printf(pan_vsp, "    client = %s %s,\n", ci, cp);
+	VSB_printf(vsb, "client = %s %s,\n", ci, cp);
 	switch (sp->sess_step) {
 #define SESS_STEP(l, u) case S_STP_##u: stp = "S_STP_" #u; break;
 #include "tbl/steps.h"
@@ -429,17 +384,18 @@ pan_sess(const struct sess *sp)
 		default: stp = NULL;
 	}
 	if (stp != NULL)
-		VSB_printf(pan_vsp, "    step = %s,\n", stp);
+		VSB_printf(vsb, "step = %s,\n", stp);
 	else
-		VSB_printf(pan_vsp, "    step = 0x%x,\n", sp->sess_step);
+		VSB_printf(vsb, "step = 0x%x,\n", sp->sess_step);
 
-	VSB_printf(pan_vsp, "  },\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
 }
 
 /*--------------------------------------------------------------------*/
 
 static void
-pan_backtrace(void)
+pan_backtrace(struct vsb *vsb)
 {
 	void *array[10];
 	size_t size;
@@ -450,24 +406,25 @@ pan_backtrace(void)
 	size = backtrace (array, 10);
 	if (size == 0)
 		return;
-	VSB_printf(pan_vsp, "Backtrace:\n");
+	VSB_printf(vsb, "Backtrace:\n");
+	VSB_indent(vsb, 2);
 	for (i = 0; i < size; i++) {
-		VSB_printf (pan_vsp, "  ");
-		if (Symbol_Lookup(pan_vsp, array[i]) < 0) {
+		if (Symbol_Lookup(vsb, array[i]) < 0) {
 			strings = backtrace_symbols(&array[i], 1);
 			if (strings == NULL || strings[0] == NULL) {
-				VSB_printf(pan_vsp, "%p: (?)", array[i]);
+				VSB_printf(vsb, "%p: (?)", array[i]);
 			} else {
 				p = strrchr(strings[0], '/');
 				if (p == NULL)
 					p = strings[0];
 				else
 					p++;
-				VSB_printf(pan_vsp, "%p: %s", array[i], p);
+				VSB_printf(vsb, "%p: %s", array[i], p);
 			}
 		}
-		VSB_printf (pan_vsp, "\n");
+		VSB_printf (vsb, "\n");
 	}
+	VSB_indent(vsb, -2);
 }
 
 /*--------------------------------------------------------------------*/
@@ -497,59 +454,59 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 
 	switch(kind) {
 	case VAS_WRONG:
-		VSB_printf(pan_vsp,
+		VSB_printf(pan_vsb,
 		    "Wrong turn at %s:%d:\n%s\n", file, line, cond);
 		break;
 	case VAS_VCL:
-		VSB_printf(pan_vsp,
+		VSB_printf(pan_vsb,
 		    "Panic from VCL:\n  %s\n", cond);
 		break;
 	case VAS_MISSING:
-		VSB_printf(pan_vsp,
+		VSB_printf(pan_vsb,
 		    "Missing errorhandling code in %s(), %s line %d:\n"
 		    "  Condition(%s) not true.",
 		    func, file, line, cond);
 		break;
 	case VAS_INCOMPLETE:
-		VSB_printf(pan_vsp,
+		VSB_printf(pan_vsb,
 		    "Incomplete code in %s(), %s line %d:\n",
 		    func, file, line);
 		break;
 	default:
 	case VAS_ASSERT:
-		VSB_printf(pan_vsp,
+		VSB_printf(pan_vsb,
 		    "Assert error in %s(), %s line %d:\n"
 		    "  Condition(%s) not true.\n",
 		    func, file, line, cond);
 		break;
 	}
 	if (err)
-		VSB_printf(pan_vsp, "errno = %d (%s)\n", err, strerror(err));
+		VSB_printf(pan_vsb, "errno = %d (%s)\n", err, strerror(err));
 
 	q = THR_GetName();
 	if (q != NULL)
-		VSB_printf(pan_vsp, "thread = (%s)\n", q);
+		VSB_printf(pan_vsb, "thread = (%s)\n", q);
 
-	VSB_printf(pan_vsp, "version = %s\n", VCS_version);
-	VSB_printf(pan_vsp, "ident = %s,%s\n",
+	VSB_printf(pan_vsb, "version = %s\n", VCS_version);
+	VSB_printf(pan_vsb, "ident = %s,%s\n",
 	    VSB_data(vident) + 1, Waiter_GetName());
 
-	pan_backtrace();
+	pan_backtrace(pan_vsb);
 
 	if (!FEATURE(FEATURE_SHORT_PANIC)) {
 		req = THR_GetRequest();
 		if (req != NULL) {
-			pan_req(req);
+			pan_req(pan_vsb, req);
 			VSL_Flush(req->vsl, 0);
 		}
 		bo = THR_GetBusyobj();
 		if (bo != NULL) {
-			pan_busyobj(bo);
+			pan_busyobj(pan_vsb, bo);
 			VSL_Flush(bo->vsl, 0);
 		}
 	}
-	VSB_printf(pan_vsp, "\n");
-	VSB_bcat(pan_vsp, "", 1);	/* NUL termination */
+	VSB_printf(pan_vsb, "\n");
+	VSB_bcat(pan_vsb, "", 1);	/* NUL termination */
 
 	if (FEATURE(FEATURE_NO_COREDUMP))
 		exit(4);
@@ -585,10 +542,10 @@ PAN_Init(void)
 {
 
 	VAS_Fail = pan_ic;
-	pan_vsp = &pan_vsp_storage;
+	pan_vsb = &pan_vsb_storage;
 	AN(heritage.panic_str);
 	AN(heritage.panic_str_len);
-	AN(VSB_new(pan_vsp, heritage.panic_str, heritage.panic_str_len,
+	AN(VSB_new(pan_vsb, heritage.panic_str, heritage.panic_str_len,
 	    VSB_FIXEDLEN));
 	CLI_AddFuncs(debug_cmds);
 }
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index c10d949..dd49cda 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -86,12 +86,16 @@ VCL_Panic(struct vsb *vsb, const struct vcl *vcl)
 	AN(vsb);
 	if (vcl == NULL)
 		return;
-	VSB_printf(vsb, "  vcl = {\n");
-	VSB_printf(vsb, "    srcname = {\n");
+	VSB_printf(vsb, "vcl = {\n");
+	VSB_indent(vsb, 2);
+	VSB_printf(vsb, "srcname = {\n");
+	VSB_indent(vsb, 2);
 	for (i = 0; i < vcl->conf->nsrc; ++i)
-		VSB_printf(vsb, "      \"%s\",\n", vcl->conf->srcname[i]);
-	VSB_printf(vsb, "    },\n");
-	VSB_printf(vsb, "  },\n");
+		VSB_printf(vsb, "\"%s\",\n", vcl->conf->srcname[i]);
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
+	VSB_indent(vsb, -2);
+	VSB_printf(vsb, "},\n");
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list