]> mj.ucw.cz Git - libucw.git/commitdiff
conf2: debug dumping of memory into a fastbuf partially implemented
authorRobert Spalek <robert@ucw.cz>
Sun, 23 Apr 2006 00:56:08 +0000 (02:56 +0200)
committerRobert Spalek <robert@ucw.cz>
Sun, 23 Apr 2006 00:56:08 +0000 (02:56 +0200)
lib/conf2-test.c
lib/conf2.c
lib/conf2.h

index 1d164f10ec55602da771dfb7961cd7b5d09d9cb3..5a38355d392fcaf24e5a268a7203397e372a9d5a 100644 (file)
@@ -7,6 +7,7 @@
 #include "lib/lib.h"
 #include "lib/conf2.h"
 #include "lib/clists.h"
+#include "lib/fastbuf.h"
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -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;
 }
index fe66610a0ca361e0df93afee48961f7f4b4fe1ca..57e9c353c7a7ce0ee2e1e5fbc0373fbf636b93cf 100644 (file)
@@ -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; i<nr; i++)
+    bputs(fb, "  ");
+}
+
+static void
+dump_basic(struct fastbuf *fb, void *ptr, enum cf_type type)
+{
+  switch (type) {
+    case CT_INT:       bprintf(fb, "%d ", *(uns*)ptr); break;
+    case CT_U64:       bprintf(fb, "%lld ", *(u64*)ptr); break;
+    case CT_DOUBLE:    bprintf(fb, "%lf ", *(double*)ptr); break;
+    case CT_IP:                bprintf(fb, "%08x ", *(uns*)ptr); break;
+    case CT_STRING:    bprintf(fb, "'%s' ", *(byte**)ptr); break;
+  }
+}
+
+static void dump_section(struct fastbuf *fb, struct cf_section *sec, int level, void *ptr);
+
+static void
+dump_item(struct fastbuf *fb, struct cf_item *item, int level, void *ptr)
+{
+  ptr += (addr_int_t) item->ptr;
+  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; i<item->number; 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; i<real_nr; i++)
+      dump_basic(fb, ptr + i * parsers[type].size, type);
+  }
+  bputc(fb, '\n');
+  if (item->cls == 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, &sections, 0, NULL);
+}
index 6f2e245e0297722fe839b20f69fbc99ef8a61e70..0455ec1afda4ce44be03980042bc29661f2ba51f 100644 (file)
@@ -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