[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH for 4.5 v2 1/2] xen/vsprintf: Introduce %*ph extended format specifier for hex buffers
This behaves in the same way as Linux. The 64 byte limit is arbitrary but long enough for practical purposes. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Reviewed-by: Tim Deegan <tim@xxxxxxx> Release-acked-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> CC: Keir Fraser <keir@xxxxxxx> CC: Jan Beulich <JBeulich@xxxxxxxx> --- v2: (Suggestions from Jan and Tim) * Sort position of %*ph in document. Introduce missing title for %pv. * Clip limit at 64 bytes rather than defaulting back to 0. * Don't emit a trailing space after the last byte of the hex buffer. --- docs/misc/printk-formats.txt | 7 +++++++ xen/common/vsprintf.c | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt index 3b4323a..dee0f3e 100644 --- a/docs/misc/printk-formats.txt +++ b/docs/misc/printk-formats.txt @@ -3,6 +3,11 @@ Xen custom %p format options. A subset, borrowed from Linux. All parameters to a %p option should be compatible with void*. Regular pointers are fine. Numbers should make use of the _p() macro. +Raw buffer as hex string: + + %*ph Up to 64 characters, printed as "00 01 02 ... ff". Buffer length + expected via the field_width paramter. i.e. printk("%*ph", 8, buffer); + Symbol/Function pointers: %ps Symbol name with condition offset and size (iff offset != 0) @@ -16,5 +21,7 @@ Symbol/Function pointers: In the case that an appropriate symbol name can't be found, %p[sS] will fall back to '%p' and print the address in hex. +Domain and vCPU information: + %pv Domain and vCPU ID from a 'struct vcpu *' (printed as "d<domid>v<vcpuid>") diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index e68886a..599d52a 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -272,6 +272,33 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, /* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt */ switch ( fmt[1] ) { + case 'h': /* Raw buffer as hex string. */ + { + /* Bound user count from %* to between 0 and 64 bytes. */ + unsigned i, nr_bytes = + (field_width < 0) ? 0 : (field_width > 64) ? 64 : field_width; + const uint8_t *hex_buffer = arg; + + /* Consumed 'h' from the format string. */ + ++*fmt_ptr; + + for ( i = 0; i < nr_bytes; ++i ) + { + /* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */ + str = number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD); + + /* Skip trailing space after final byte. */ + if ( i == (nr_bytes - 1) ) + break; + + if ( str < end ) + *str = ' '; + ++str; + } + + return str; + } + case 's': /* Symbol name with offset and size (iff offset != 0) */ case 'S': /* Symbol name unconditionally with offset and size */ { -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |