chiark / gitweb /
regress: hfuzzraw: Introduce P_read_dump
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Nov 2016 17:55:37 +0000 (17:55 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Jun 2020 15:13:02 +0000 (16:13 +0100)
This really helps debugging.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
regress/hfuzzraw.c.m4

index b843f157653905d6a6d37ad16d18dbe2589f3163..a1a9d0fb7645520e2ad8cefadfa2e12ba76c2ca3 100644 (file)
@@ -97,13 +97,32 @@ void Tensurerecordfile(void) {
   if (proutstr) stdout_enable= atoi(proutstr);
 }
 
   if (proutstr) stdout_enable= atoi(proutstr);
 }
 
-static void P_read(void *p, size_t sz) {
+
+static void P_read_dump(const unsigned char *p0, size_t count, ssize_t d) {
+  fputs(" | ",stdout);
+  while (count) {
+    fprintf(stdout,"%02x", *p0);
+    p0 += d;
+    count--;
+  }
+}
+    
+static void P_read(void *p, size_t sz, const char *what) {
   ssize_t got = fread(p,1,sz,Tinputfile);
   Pcheckinput();
   assert(got==sz);
   ssize_t got = fread(p,1,sz,Tinputfile);
   Pcheckinput();
   assert(got==sz);
+  if (stdout_enable && sz) {
+    fprintf(stdout,"%s:",what);
+    P_read_dump(p, sz, +1);
+    if (sz<=16) {
+      P_read_dump((const unsigned char *)p+sz-1, sz, -1);
+    }
+    fputs(" |\n",stdout);
+    Tflushstdout();
+  }
 }
 
 }
 
-#define P_READ(x) (P_read(&(x), sizeof((x))))
+#define P_READ(x) (P_read(&(x), sizeof((x)), #x))
 
 static unsigned P_fdf(int fd) {
   assert(fd>=0 && fd<fdtab.used);
 
 static unsigned P_fdf(int fd) {
   assert(fd>=0 && fd<fdtab.used);
@@ -137,7 +156,7 @@ static int Pbytes(byte *buf, int maxlen) {
   int l;
   P_READ(l);
   if (l<0 || l>maxlen) Pformat("bad byte block len");
   int l;
   P_READ(l);
   if (l<0 || l>maxlen) Pformat("bad byte block len");
-  P_read(buf, l);
+  P_read(buf, l, "bytes");
   return l;
 }
 
   return l;
 }