Hi, As discussed on the Stockholm VDD, here's a proposal for #1457.
Patch 1/2 makes the VCL compiler emit null pointer end markers to the 'srcname' and 'srcbody' arrays. Patch 2/2 adds a '-v' option to vcl.show, to have it also display all included files (including the implicitly included builtin VCL.) The output consists of a simple header for each file consisting of <name>|<length>. Then follows a newline and <length> bytes which is the contents of that VCL verbatim, followed by a blank line. The idea is for this to be easy to parse, while still being in human readable form. The VCLs are output in the same order as they appear in the VCL location/profiling table in the compiled VCL (the vcl->ref stuff used in the VCL_trace records), so if someone wanted to do a VCL code tracer thing, that should be possible. Regards, Dag -- Dag Haavi Finstad Software Developer | Varnish Software AS Mobile: +47 476 64 134 We Make Websites Fly!
From 8363de0900ed80fdf198efc351824bc3f856d386 Mon Sep 17 00:00:00 2001 From: Dag Haavi Finstad <[email protected]> Date: Fri, 11 Jul 2014 15:39:15 +0200 Subject: [PATCH 1/2] Add an endmarker to the generated srcbody/srcname arrays. --- lib/libvcc/vcc_compile.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index 31212aa..fffb1e2 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -337,16 +337,17 @@ EmitStruct(const struct vcc *tl) struct source *sp; Fc(tl, 0, "\nextern const char *srcname[];\n"); - Fc(tl, 0, "\nconst char *srcname[%u] = {\n", tl->nsources); + Fc(tl, 0, "\nconst char *srcname[%u] = {\n", tl->nsources + 1); VTAILQ_FOREACH(sp, &tl->sources, list) { Fc(tl, 0, "\t"); EncString(tl->fc, sp->name, NULL, 0); Fc(tl, 0, ",\n"); } + Fc(tl, 0, "\t0\n"); Fc(tl, 0, "};\n"); Fc(tl, 0, "\nextern const char *srcbody[];\n"); - Fc(tl, 0, "\nconst char *srcbody[%u] = {\n", tl->nsources); + Fc(tl, 0, "\nconst char *srcbody[%u] = {\n", tl->nsources + 1); VTAILQ_FOREACH(sp, &tl->sources, list) { Fc(tl, 0, " /* "); EncString(tl->fc, sp->name, NULL, 0); @@ -355,6 +356,7 @@ EmitStruct(const struct vcc *tl) EncString(tl->fc, sp->b, sp->e, 1); Fc(tl, 0, ",\n"); } + Fc(tl, 0, "\t0\n"); Fc(tl, 0, "};\n"); Fc(tl, 0, "\nstatic struct director\t*directors[%d];\n", -- 2.0.0.rc0
From 62cdbba65d75b3220565830b771923267573918f Mon Sep 17 00:00:00 2001 From: Dag Haavi Finstad <[email protected]> Date: Fri, 11 Jul 2014 15:41:05 +0200 Subject: [PATCH 2/2] Add a -v option to vcl.show to make it also expand includes. Fixes: #1457 --- bin/varnishd/mgt/mgt_vcc.c | 27 ++++++++++++++++++++------- include/vcli.h | 4 ++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index 2c2ffd9..52523e1 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -674,7 +674,6 @@ mcf_config_list(struct cli *cli, const char * const *av, void *priv) } /* - * XXX: This should take an option argument to show all (include) files * XXX: This violates the principle of not loading VCL's in the master * XXX: process. */ @@ -682,8 +681,12 @@ void mcf_config_show(struct cli *cli, const char * const *av, void *priv) { struct vclprog *vp; - void *dlh, *sym; - const char **src; + void *dlh, *bodysym, *namesym; + const char **srcbody, **srcname; + int i, verbose = 0; + + if (av[3] && !strcmp(av[3], "-v")) + verbose = 1; (void)priv; if ((vp = mcf_find_vcl(cli, av[2])) != NULL) { @@ -691,15 +694,25 @@ mcf_config_show(struct cli *cli, const char * const *av, void *priv) VCLI_Out(cli, "failed to load %s: %s\n", vp->name, dlerror()); VCLI_SetResult(cli, CLIS_CANT); - } else if ((sym = dlsym(dlh, "srcbody")) == NULL) { + } else if ((bodysym = dlsym(dlh, "srcbody")) == NULL + || (namesym = dlsym(dlh, "srcname")) == NULL) { VCLI_Out(cli, "failed to locate source for %s: %s\n", vp->name, dlerror()); VCLI_SetResult(cli, CLIS_CANT); AZ(dlclose(dlh)); } else { - src = sym; - VCLI_Out(cli, "%s", src[0]); - /* VCLI_Out(cli, src[1]); */ + srcname = namesym; + srcbody = bodysym; + if (verbose) { + for (i = 0; srcname[i]; i++) { + VCLI_Out(cli, "%s|%zu\n", srcname[i], + strlen(srcbody[i])); + VCLI_Out(cli, srcbody[i]); + if (srcname[i + 1]) + VCLI_Out(cli, "\n"); + } + } else + VCLI_Out(cli, "%s", srcbody[0]); AZ(dlclose(dlh)); } } diff --git a/include/vcli.h b/include/vcli.h index 3294dd7..5b84287 100644 --- a/include/vcli.h +++ b/include/vcli.h @@ -97,9 +97,9 @@ #define CLI_VCL_SHOW \ "vcl.show", \ - "vcl.show <configname>", \ + "vcl.show <configname> [-v]", \ "\tDisplay the source code for the specified configuration.", \ - 1, 1 + 1, 2 #define CLI_VCL_USE \ "vcl.use", \ -- 2.0.0.rc0
_______________________________________________ varnish-dev mailing list [email protected] https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev
