When compiled with --enable-debug, will compile a function to output the lens hierarchy in dot files. Enable this specific debug info with AUGEAS_DEBUG=lenses --- src/lens.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lens.h | 3 ++ 2 files changed, 105 insertions(+), 0 deletions(-)
--- Francis
>From 31bbf340d85faa2d997e97f7a94fa22633135fee Mon Sep 17 00:00:00 2001 From: Francis Giraldeau <[email protected]> Date: Wed, 20 Oct 2010 14:23:08 -0400 Subject: [PATCH] Add debugging information about lens hierarchy When compiled with --enable-debug, will compile a function to output the lens hierarchy in dot files. Enable this specific debug info with AUGEAS_DEBUG=lenses --- src/lens.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lens.h | 3 ++ 2 files changed, 105 insertions(+), 0 deletions(-) diff --git a/src/lens.c b/src/lens.c index d73ac7e..a1b300b 100644 --- a/src/lens.c +++ b/src/lens.c @@ -26,6 +26,7 @@ #include "lens.h" #include "memory.h" #include "errcode.h" +#include "internal.h" /* This enum must be kept in sync with type_offs and ntypes */ enum lens_type { @@ -59,6 +60,8 @@ static const char *const tags[] = { "subtree", "star", "maybe", "rec" }; +#define ltag(lens) (tags[lens->tag - L_DEL]) + static const struct string digits_string = { .ref = REF_MAX, .str = (char *) "[0123456789]+" }; @@ -801,6 +804,8 @@ void free_lens(struct lens *lens) { return; ensure(lens->ref == 0, lens->info); + if (debugging("lenses")) + dump_lens_tree(lens); switch (lens->tag) { case L_DEL: unref(lens->regexp, regexp); @@ -2101,6 +2106,103 @@ struct value *lns_check_rec(struct info *info, return result; } +#if ENABLE_DEBUG +void dump_lens_tree(struct lens *lens){ + static int count = 0; + FILE *fp; + + fp = debug_fopen("lens_%02d_%s.dot", count++, ltag(lens)); + if (fp == NULL) + return; + + fprintf(fp, "digraph \"%s\" {\n", "lens"); + dump_lens(fp, lens); + fprintf(fp, "}\n"); + + fclose(fp); +} + +void dump_lens(FILE *out, struct lens *lens){ + int i = 0; + struct regexp *re; + + fprintf(out, "\"%p\" [ shape = box, label = \"%s\\n", lens, ltag(lens)); + + for (int t=0; t < ntypes; t++) { + re = ltype(lens, t); + if (re == NULL) + continue; + fprintf(out, "%s=",lens_type_names[t]); + print_regexp(out, re); + fprintf(out, "\\n"); + } + + fprintf(out, "recursive=%x\\n", lens->recursive); + fprintf(out, "rec_internal=%x\\n", lens->rec_internal); + fprintf(out, "consumes_value=%x\\n", lens->consumes_value); + fprintf(out, "ctype_nullable=%x\\n", lens->ctype_nullable); + fprintf(out, "\"];\n"); + switch(lens->tag){ + case L_DEL: + break; + case L_STORE: + break; + case L_VALUE: + break; + case L_KEY: + break; + case L_LABEL: + break; + case L_SEQ: + break; + case L_COUNTER: + break; + case L_CONCAT: + for(i = 0; i<lens->nchildren;i++){ + fprintf(out, "\"%p\" -> \"%p\"\n", lens, lens->children[i]); + dump_lens(out, lens->children[i]); + } + break; + case L_UNION: + for(i = 0; i<lens->nchildren;i++){ + fprintf(out, "\"%p\" -> \"%p\"\n", lens, lens->children[i]); + dump_lens(out, lens->children[i]); + } + break; + case L_SUBTREE: + fprintf(out, "\"%p\" -> \"%p\"\n", lens, lens->child); + dump_lens(out, lens->child); + break; + case L_STAR: + fprintf(out, "\"%p\" -> \"%p\"\n", lens, lens->child); + dump_lens(out, lens->child); + + break; + case L_MAYBE: + fprintf(out, "\"%p\" -> \"%p\"\n", lens, lens->child); + dump_lens(out, lens->child); + + break; + case L_REC: + if (lens->rec_internal == 0){ + fprintf(out, "\"%p\" -> \"%p\"\n", lens, lens->child); + dump_lens(out, lens->body); + } + break; + /* uncomment for square lens */ + /* + case L_SQUARE: + fprintf(out, "\"%p\" -> \"%p\"\n", lens, lens->child); + dump_lens(out, lens->child); + break; + */ + default: + fprintf(out, "ERROR\n"); + break; + } +} +#endif + /* * Local variables: * indent-tabs-mode: nil diff --git a/src/lens.h b/src/lens.h index 3e5b988..6d4a7f0 100644 --- a/src/lens.h +++ b/src/lens.h @@ -241,6 +241,9 @@ void free_lens(struct lens *lens); */ char *enc_format(const char *e, size_t len); +void dump_lens_tree(struct lens *lens); +void dump_lens(FILE *out, struct lens *lens); + #endif -- 1.7.1
_______________________________________________ augeas-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/augeas-devel
