]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOLib.cpp
xnu-4570.71.2.tar.gz
[apple/xnu.git] / iokit / Kernel / IOLib.cpp
index 2fba9bc5d5dbd2eca2a121b4a776032bdf2d0e6d..73057d7a98a3a6f8d6c4ab22df8336128469b8f4 100644 (file)
@@ -1192,6 +1192,40 @@ void IOPanic(const char *reason)
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
+void IOKitKernelLogBuffer(const char * title, const void * buffer, size_t size,
+                          void (*output)(const char *format, ...))
+{
+    uint8_t c, chars[17];
+    size_t idx;
+
+    output("%s(0x%x):\n", title, size);
+    if (size > 4096) size = 4096;
+    chars[16] = idx = 0;
+    while (true) {
+        if (!(idx & 15)) {
+            if (idx) output(" |%s|\n", chars);
+            if (idx >= size) break;
+            output("%04x:  ", idx);
+        }
+        else if (!(idx & 7)) output(" ");
+
+        c =  ((char *)buffer)[idx];
+        output("%02x ", c);
+        chars[idx & 15] = ((c >= 0x20) && (c <= 0x7f)) ? c : ' ';
+
+        idx++;
+        if ((idx == size) && (idx & 15)) {
+            chars[idx & 15] = 0;
+            while (idx & 15) {
+                idx++;
+                output("   ");
+            }
+        }
+    }
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
 /*
  * Convert a integer constant (typically a #define or enum) to a string.
  */