Blame SOURCES/0014-Add-more-hexdump-logging-functions.patch

d5c737
From 707276197e82e852e9d5c7acb97a9348efe467b7 Mon Sep 17 00:00:00 2001
d5c737
From: Peter Jones <pjones@redhat.com>
d5c737
Date: Wed, 13 Mar 2019 11:02:01 -0400
d5c737
Subject: [PATCH 14/63] Add more hexdump logging functions.
d5c737
d5c737
Signed-off-by: Peter Jones <pjones@redhat.com>
d5c737
---
d5c737
 src/hexdump.h | 30 ++++++++++++++++++++++++++++--
d5c737
 src/util.h    | 10 ++++++++++
d5c737
 2 files changed, 38 insertions(+), 2 deletions(-)
d5c737
d5c737
diff --git a/src/hexdump.h b/src/hexdump.h
d5c737
index 4c45cb3732d..f8c32faa9e1 100644
d5c737
--- a/src/hexdump.h
d5c737
+++ b/src/hexdump.h
d5c737
@@ -63,8 +63,12 @@ prepare_text(uint8_t *data, unsigned long size, char *buf)
d5c737
 	buf[offset] = '\0';
d5c737
 }
d5c737
 
d5c737
+/*
d5c737
+ * variadic fhexdump formatted
d5c737
+ * think of it as: fprintf(f, %s%s\n", vformat(fmt, ap), hexdump(data,size));
d5c737
+ */
d5c737
 static inline void UNUSED
d5c737
-hexdump(uint8_t *data, unsigned long size)
d5c737
+vfhexdumpf(FILE *f, const char * const fmt, uint8_t *data, unsigned long size, va_list ap)
d5c737
 {
d5c737
 	unsigned long display_offset = (unsigned long)data & 0xffffffff;
d5c737
 	unsigned long offset = 0;
d5c737
@@ -80,11 +84,33 @@ hexdump(uint8_t *data, unsigned long size)
d5c737
 			return;
d5c737
 
d5c737
 		prepare_text(data+offset, size-offset, txtbuf);
d5c737
-		printf("%016lx  %s  %s\n", display_offset, hexbuf, txtbuf);
d5c737
+		vfprintf(f, fmt, ap);
d5c737
+		fprintf(f, "%016lx  %s  %s\n", display_offset, hexbuf, txtbuf);
d5c737
 
d5c737
 		display_offset += sz;
d5c737
 		offset += sz;
d5c737
 	}
d5c737
+	fflush(f);
d5c737
+}
d5c737
+
d5c737
+/*
d5c737
+ * fhexdump formatted
d5c737
+ * think of it as: fprintf(f, %s%s\n", format(fmt, ...), hexdump(data,size));
d5c737
+ */
d5c737
+static inline void UNUSED
d5c737
+fhexdumpf(FILE *f, const char * const fmt, uint8_t *data, unsigned long size, ...)
d5c737
+{
d5c737
+	va_list ap;
d5c737
+
d5c737
+	va_start(ap, size);
d5c737
+	vfhexdumpf(f, fmt, data, size, ap);
d5c737
+	va_end(ap);
d5c737
+}
d5c737
+
d5c737
+static inline void UNUSED
d5c737
+hexdump(uint8_t *data, unsigned long size)
d5c737
+{
d5c737
+	fhexdumpf(stdout, "", data, size);
d5c737
 }
d5c737
 
d5c737
 #endif /* STATIC_HEXDUMP_H */
d5c737
diff --git a/src/util.h b/src/util.h
d5c737
index d98bfa1beed..a6a80e754ec 100644
d5c737
--- a/src/util.h
d5c737
+++ b/src/util.h
d5c737
@@ -400,5 +400,15 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
d5c737
 #endif
d5c737
 #define log(level, fmt, args...) log_(__FILE__, __LINE__, __func__, level, fmt, ## args)
d5c737
 #define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args)
d5c737
+#define log_hex_(file, line, func, level, buf, size)                    \
d5c737
+        ({                                                              \
d5c737
+                if (efi_get_verbose() >= level) {                       \
d5c737
+                        fhexdumpf(efi_get_logfile(), "%s:%d %s(): ",    \
d5c737
+                                  (uint8_t *)buf, size,                 \
d5c737
+                                  file, line, func);                    \
d5c737
+                }                                                       \
d5c737
+        })
d5c737
+#define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size)
d5c737
+#define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size)
d5c737
 
d5c737
 #endif /* EFIVAR_UTIL_H */
d5c737
-- 
d5c737
2.26.2
d5c737