[master] da204fb40 vbt: New VBT_dump() function

Nils Goroll nils.goroll at uplex.de
Mon May 19 13:21:05 UTC 2025


commit da204fb40467eb319f8516f6c185c232e8e61d1b
Author: Asad Sajjad Ahmed <asadsa at varnish-software.com>
Date:   Wed Jun 5 12:34:14 2024 +0200

    vbt: New VBT_dump() function
    
    This is useful when printing a backtrace into a fixed size buffer.
    
    Suggested-by: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
    Signed-off-by: Asad Sajjad Ahmed <asadsa at varnish-software.com>

diff --git a/include/vbt.h b/include/vbt.h
index bd3a384b9..c2c8b28f2 100644
--- a/include/vbt.h
+++ b/include/vbt.h
@@ -31,3 +31,4 @@
 struct vsb;
 
 void VBT_format(struct vsb *);
+int VBT_dump(size_t len, char [len]);
diff --git a/lib/libvarnish/vbt.c b/lib/libvarnish/vbt.c
index c38227a88..99fc59400 100644
--- a/lib/libvarnish/vbt.c
+++ b/lib/libvarnish/vbt.c
@@ -157,3 +157,19 @@ VBT_format(struct vsb *vsb)
 	vbt_execinfo(vsb);
 #endif
 }
+
+int
+VBT_dump(size_t len, char buf[len])
+{
+	struct vsb vsb[1];
+
+	if (VSB_init(vsb, buf, len) == NULL)
+		return (-1);
+
+	VSB_printf(vsb, "Backtrace:\n");
+	VSB_indent(vsb, 2);
+	VBT_format(vsb);
+	VSB_indent(vsb, -2);
+
+	return (0);
+}


More information about the varnish-commit mailing list