[master] a808daa3d Add a "vcl.symtab" debug command.

Poul-Henning Kamp phk at FreeBSD.org
Mon May 27 08:01:10 UTC 2019


commit a808daa3d0f5e2e3d0147a120c2ad15800161214
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 27 07:55:53 2019 +0000

    Add a "vcl.symtab" debug command.

diff --git a/bin/varnishd/mgt/mgt_symtab.c b/bin/varnishd/mgt/mgt_symtab.c
index 608c3c24e..fff79a785 100644
--- a/bin/varnishd/mgt/mgt_symtab.c
+++ b/bin/varnishd/mgt/mgt_symtab.c
@@ -40,6 +40,7 @@
 #include "mgt/mgt.h"
 #include "mgt/mgt_vcl.h"
 
+#include "vcli_serve.h"
 #include "libvcc.h"
 #include "vjsn.h"
 
@@ -198,3 +199,33 @@ mgt_vcl_export_labels(struct vcc *vcc)
 
 /*--------------------------------------------------------------------*/
 
+static void
+mcf_vcl_vjsn_dump(struct cli *cli, const struct vjsn_val *vj, int indent)
+{
+	struct vjsn_val *vj1;
+	AN(cli);
+	AN(vj);
+
+	VCLI_Out(cli, "%*s", indent, "");
+	if (vj->name != NULL)
+		VCLI_Out(cli, "[\"%s\"]: ", vj->name);
+	VCLI_Out(cli, "{%s}", vj->type);
+	if (vj->value != NULL)
+		VCLI_Out(cli, " <%s>", vj->value);
+	VCLI_Out(cli, "\n");
+	VTAILQ_FOREACH(vj1, &vj->children, list)
+		mcf_vcl_vjsn_dump(cli, vj1, indent + 2);
+}
+
+void v_matchproto_(cli_func_t)
+mcf_vcl_symtab(struct cli *cli, const char * const *av, void *priv)
+{
+	struct vclprog *vp;
+	(void)av;
+	(void)priv;
+	VTAILQ_FOREACH(vp, &vclhead, list) {
+		VCLI_Out(cli, "VCL: %s\n", vp->name);
+		if (vp->symtab != NULL)
+			mcf_vcl_vjsn_dump(cli, vp->symtab->value, 4);
+	}
+}
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index 88e8bcce0..147eaed90 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -906,6 +906,7 @@ static struct cli_proto cli_vcl[] = {
 	{ CLICMD_VCL_DISCARD,		"", mcf_vcl_discard },
 	{ CLICMD_VCL_LIST,		"", mcf_vcl_list, mcf_vcl_list_json },
 	{ CLICMD_VCL_LABEL,		"", mcf_vcl_label },
+	{ CLICMD_DEBUG_VCL_SYMTAB,	"d", mcf_vcl_symtab },
 	{ NULL }
 };
 
diff --git a/bin/varnishd/mgt/mgt_vcl.h b/bin/varnishd/mgt/mgt_vcl.h
index 21163d7ae..fe740dde4 100644
--- a/bin/varnishd/mgt/mgt_vcl.h
+++ b/bin/varnishd/mgt/mgt_vcl.h
@@ -82,4 +82,5 @@ int mcf_is_label(const struct vclprog *vp);
 
 void mgt_vcl_export_labels(struct vcc *vcc);
 void mgt_vcl_symtab(struct vclprog *vp, const char *input);
+void mcf_vcl_symtab(struct cli *cli, const char * const *av, void *priv);
 
diff --git a/bin/varnishtest/tests/c00077.vtc b/bin/varnishtest/tests/c00077.vtc
index 8b2c35df1..78b9002f9 100644
--- a/bin/varnishtest/tests/c00077.vtc
+++ b/bin/varnishtest/tests/c00077.vtc
@@ -59,6 +59,9 @@ varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
 varnish v1 -clierr 300 "vcl.discard vclA"
 
 varnish v1 -vcl+backend { }
+
+varnish v1 -cliok "vcl.symtab"
+
 varnish v1 -cliok "vcl.discard vcl3"
 varnish v1 -cliok "vcl.discard vcl4"
 varnish v1 -cliok "vcl.discard vcl5"
diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h
index 99193c6c7..d1b9f2afa 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -362,6 +362,14 @@ CLI_CMD(DEBUG_PANIC_MASTER,
 	0, 0
 )
 
+CLI_CMD(DEBUG_VCL_SYMTAB,
+	"vcl.symtab",
+	"vcl.symtab",
+	"Dump the VCL symbol-tables.",
+	"",
+	0, 0
+)
+
 CLI_CMD(DEBUG_VMOD,
 	"debug.vmod",
 	"debug.vmod",


More information about the varnish-commit mailing list