From c32922c603c5cf170ccae1a25989c36c4dea55da Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Sun, 23 Apr 2006 02:56:08 +0200 Subject: [PATCH] conf2: debug dumping of memory into a fastbuf partially implemented --- lib/conf2-test.c | 5 ++++ lib/conf2.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/conf2.h | 2 ++ 3 files changed, 81 insertions(+) diff --git a/lib/conf2-test.c b/lib/conf2-test.c index 1d164f10..5a38355d 100644 --- a/lib/conf2-test.c +++ b/lib/conf2-test.c @@ -7,6 +7,7 @@ #include "lib/lib.h" #include "lib/conf2.h" #include "lib/clists.h" +#include "lib/fastbuf.h" #include #include @@ -153,5 +154,9 @@ main(int argc, char *argv[]) if (optind < argc) usage(); + struct fastbuf *out = bfdopen(1, 1<<14); + cf_dump_sections(out); + bclose(out); + return 0; } diff --git a/lib/conf2.c b/lib/conf2.c index fe66610a..57e9c353 100644 --- a/lib/conf2.c +++ b/lib/conf2.c @@ -1260,3 +1260,77 @@ cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct o } } } + +/* Debug dumping */ + +#include "fastbuf.h" + +static void +spaces(struct fastbuf *fb, uns nr) +{ + for (uns i=0; iptr; + enum cf_type type = item->u.type; + int i; + spaces(fb, level); + bprintf(fb, "%s: c%d #%d ", item->name, item->cls, item->number); + if (item->cls == CC_STATIC || item->cls == CC_DYNAMIC) + bprintf(fb, "t%d ", type); + if (item->cls == CC_STATIC) { + for (i=0; inumber; i++) + dump_basic(fb, ptr + i * parsers[type].size, type); + } else if (0 && item->cls == CC_DYNAMIC) { + ptr = * (void**) ptr; + int real_nr = * (int*) (ptr - parsers[type].size); + bprintf(fb, "##%d ", real_nr); + for (i=0; icls == CC_SECTION) + dump_section(fb, item->u.sec, level+1, ptr); + else if (item->cls == CC_LIST) { + uns idx = 0; + struct cnode *n; + CLIST_WALK(n, * (clist*) ptr) { + spaces(fb, level+1); + bprintf(fb, "item %d\n", ++idx); + dump_section(fb, item->u.sec, level+2, n); + } + } +} + +static void +dump_section(struct fastbuf *fb, struct cf_section *sec, int level, void *ptr) +{ + spaces(fb, level); + bprintf(fb, "S%d F%x:\n", sec->size, sec->flags); + for (struct cf_item *item=sec->cfg; item->cls; item++) + dump_item(fb, item, level, ptr); +} + +void +cf_dump_sections(struct fastbuf *fb) +{ + dump_section(fb, §ions, 0, NULL); +} diff --git a/lib/conf2.h b/lib/conf2.h index 6f2e245e..0455ec1a 100644 --- a/lib/conf2.h +++ b/lib/conf2.h @@ -141,8 +141,10 @@ byte *cf_parse_ip(byte *p, u32 *varp); enum operation { CF_OPERATIONS }; #undef T +struct fastbuf; byte *cf_find_item(byte *name, struct cf_item *item); byte *cf_write_item(struct cf_item *item, enum operation op, int number, byte **pars); +void cf_dump_sections(struct fastbuf *fb); /* * When using cf_get_opt(), you must prefix your own short/long options by the -- 2.39.5