]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Implement arch_fmt_pointer() for custom %pe handling
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 10 Jul 2017 10:25:48 +0000 (11:25 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 10 Aug 2017 18:43:38 +0000 (19:43 +0100)
This allows %pe to be used to print an exinfo_t.  The implementation uses
x86_decode_exinfo() under the hook.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/decode.c
common/libc/vsnprintf.c
include/xtf/libc.h

index 5b13e8c411480e634d2333e3ab05cdcc549ae32e..925eba25ca056ee2771730a848b2f88f7fe582b9 100644 (file)
@@ -87,6 +87,37 @@ int x86_decode_exinfo(char *buf, size_t bufsz, exinfo_t info)
         return snprintf(buf, bufsz, "%s", x86_exc_short_name(vec));
 }
 
+bool arch_fmt_pointer(
+    char **str_ptr, char *end, const char **fmt_ptr, const void *arg,
+    int width, int precision, unsigned int flags)
+{
+    const char *fmt = *fmt_ptr;
+    char *str = *str_ptr;
+
+    switch ( fmt[1] )
+    {
+    case 'e':
+    {
+        exinfo_t ex = _u(arg);
+        char buf[16];
+
+        /* Consumed 'e' from the format string. */
+        ++*fmt_ptr;
+
+        x86_decode_exinfo(buf, sizeof buf, ex);
+
+        str = fmt_string(str, end, buf, width, precision, flags);
+        break;
+    }
+
+    default:
+        return false;
+    }
+
+    *str_ptr = str;
+    return true;
+}
+
 /*
  * Local variables:
  * mode: C
index 9165f0ec1dbdb65ab9465a3b7cd6255a28b26eb4..a49fd308b7046346e00a81a6ff71ab2cf339b5ee 100644 (file)
@@ -250,6 +250,11 @@ static char *pointer(
         }
     }
     break;
+
+    default:
+        if ( arch_fmt_pointer(&str, end, fmt_ptr,
+                              arg, width, precision, flags) )
+            return str;
     }
 
     /* Fall back to plain 32/64bit hex integer. */
index 7ea26dc85fd32407896c8a39b860ac3c6e1eccde..66f834b474c4b30d0b8597f96cc9610522363810 100644 (file)
@@ -49,6 +49,11 @@ char *fmt_number(char *str, char *end, long long val, unsigned int base,
 char *fmt_string(char *str, char *end, const char *val,
                  int width, int precision, unsigned int flags);
 
+/* Arch hook for vsnprintf() custom %p handling. */
+bool arch_fmt_pointer(
+    char **str, char *end, const char **fmt_ptr, const void *arg,
+    int width, int precision, unsigned int flags);
+
 #endif /* XTF_LIBC_H */
 
 /*