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

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