From: Andrew Cooper Date: Mon, 10 Jul 2017 10:25:48 +0000 (+0100) Subject: Implement arch_fmt_pointer() for custom %pe handling X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a2b5571225850c4cfb3cb36ee0b25cd2c53ae358;p=people%2Fandrewcoop%2Fxen-test-framework.git Implement arch_fmt_pointer() for custom %pe handling 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 --- diff --git a/arch/x86/decode.c b/arch/x86/decode.c index 5b13e8c..925eba2 100644 --- a/arch/x86/decode.c +++ b/arch/x86/decode.c @@ -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 diff --git a/common/libc/vsnprintf.c b/common/libc/vsnprintf.c index 9165f0e..a49fd30 100644 --- a/common/libc/vsnprintf.c +++ b/common/libc/vsnprintf.c @@ -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. */ diff --git a/include/xtf/libc.h b/include/xtf/libc.h index 7ea26dc..66f834b 100644 --- a/include/xtf/libc.h +++ b/include/xtf/libc.h @@ -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 */ /*