]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: make debug_hexdump() take a string prefix
authorWilly Tarreau <w@1wt.eu>
Thu, 27 Apr 2017 16:03:20 +0000 (18:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Jun 2017 13:49:31 +0000 (15:49 +0200)
When dumping data at various places in the code, it's hard to figure
what is present where. To make this easier, this patch slightly modifies
debug_hexdump() to take a prefix string which is prepended in front of
each output line.

include/common/standard.h
src/standard.c

index 9447e3669699dd19aaffec33c47b6b46f063b5d3..f94eff9204280f2bda8f633360baacbdb4f1b033 100644 (file)
@@ -1079,9 +1079,10 @@ char *env_expand(char *in);
 #define fddebug(msg...) do { char *_m = NULL; memprintf(&_m, ##msg); if (_m) write(-1, _m, strlen(_m)); free(_m); } while (0)
 
 /* displays a <len> long memory block at <buf>, assuming first byte of <buf>
- * has address <baseaddr>. The output is emitted to file <out>.
+ * has address <baseaddr>. String <pfx> may be placed as a prefix in front of
+ * each line. It may be NULL if unused. The output is emitted to file <out>.
  */
-void debug_hexdump(FILE *out, const char *buf, unsigned int baseaddr, int len);
+void debug_hexdump(FILE *out, const char *pfx, const char *buf, unsigned int baseaddr, int len);
 
 /* used from everywhere just to drain results we don't want to read and which
  * recent versions of gcc increasingly and annoyingly complain about.
index 1d7625486ad03c986a128e56f2e9d610401a4357..82b7a01a7a779d34dbe4f524262eaced5cc4f14b 100644 (file)
@@ -3780,16 +3780,18 @@ int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
 }
 
 /* displays a <len> long memory block at <buf>, assuming first byte of <buf>
- * has address <baseaddr>. The output is emitted to file <out>.
+ * has address <baseaddr>. String <pfx> may be placed as a prefix in front of
+ * each line. It may be NULL if unused. The output is emitted to file <out>.
  */
-void debug_hexdump(FILE *out, const char *buf, unsigned int baseaddr, int len)
+void debug_hexdump(FILE *out, const char *pfx, const char *buf,
+                   unsigned int baseaddr, int len)
 {
        unsigned int i;
        int b, j;
 
        for (i = 0; i < (len + (baseaddr & 15)); i += 16) {
                b = i - (baseaddr & 15);
-               fprintf(out, "%08x: ", i + (baseaddr & ~15));
+               fprintf(out, "%s%08x: ", pfx ? pfx : "", i + (baseaddr & ~15));
                for (j = 0; j < 8; j++) {
                        if (b + j >= 0 && b + j < len)
                                fprintf(out, "%02x ", (unsigned char)buf[b + j]);