From: "Jan Beulich" <JBeulich@suse.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Keir Fraser <keir@xen.org>, Tim Deegan <tim@xen.org>
Subject: [PATCH v3 1/2] vsprintf: introduce %*ph extended format specifier for hex buffers
Date: Wed, 01 Oct 2014 08:21:32 +0100 [thread overview]
Message-ID: <542BC79C020000780003B527@mail.emea.novell.com> (raw)
In-Reply-To: <1411748677-21069-2-git-send-email-andrew.cooper3@citrix.com>
[-- Attachment #1: Type: text/plain, Size: 2385 bytes --]
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@citrix.com>
Release-acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Re-structured code.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/docs/misc/printk-formats.txt
+++ b/docs/misc/printk-formats.txt
@@ -3,6 +3,11 @@ Xen custom %p format options. A subset,
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>")
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -272,6 +272,34 @@ static char *pointer(char *str, char *en
/* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt */
switch ( fmt[1] )
{
+ case 'h': /* Raw buffer as hex string. */
+ {
+ const uint8_t *hex_buffer = arg;
+ unsigned int i;
+
+ /* Consumed 'h' from the format string. */
+ ++*fmt_ptr;
+
+ /* Bound user count from %* to between 0 and 64 bytes. */
+ if ( field_width <= 0 )
+ return str;
+ if ( field_width > 64 )
+ field_width = 64;
+
+ for ( i = 0; ; )
+ {
+ /* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */
+ str = number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD);
+
+ if ( ++i == field_width )
+ return str;
+
+ if ( str < end )
+ *str = ' ';
+ ++str;
+ }
+ }
+
case 's': /* Symbol name with offset and size (iff offset != 0) */
case 'S': /* Symbol name unconditionally with offset and size */
{
[-- Attachment #2: vsnprintf-%ph.patch --]
[-- Type: text/plain, Size: 2449 bytes --]
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@citrix.com>
Release-acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Re-structured code.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/docs/misc/printk-formats.txt
+++ b/docs/misc/printk-formats.txt
@@ -3,6 +3,11 @@ Xen custom %p format options. A subset,
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>")
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -272,6 +272,34 @@ static char *pointer(char *str, char *en
/* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt */
switch ( fmt[1] )
{
+ case 'h': /* Raw buffer as hex string. */
+ {
+ const uint8_t *hex_buffer = arg;
+ unsigned int i;
+
+ /* Consumed 'h' from the format string. */
+ ++*fmt_ptr;
+
+ /* Bound user count from %* to between 0 and 64 bytes. */
+ if ( field_width <= 0 )
+ return str;
+ if ( field_width > 64 )
+ field_width = 64;
+
+ for ( i = 0; ; )
+ {
+ /* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */
+ str = number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD);
+
+ if ( ++i == field_width )
+ return str;
+
+ if ( str < end )
+ *str = ' ';
+ ++str;
+ }
+ }
+
case 's': /* Symbol name with offset and size (iff offset != 0) */
case 'S': /* Symbol name unconditionally with offset and size */
{
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2014-10-01 7:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-26 16:24 [PATCH for 4.5 v2 0/2] Improve "Emulation failed" error message Andrew Cooper
2014-09-26 16:24 ` [PATCH for 4.5 v2 1/2] xen/vsprintf: Introduce %*ph extended format specifier for hex buffers Andrew Cooper
2014-10-01 7:21 ` Jan Beulich [this message]
2014-10-01 8:25 ` [PATCH v3 1/2] vsprintf: introduce " Andrew Cooper
2014-09-26 16:24 ` [PATCH for 4.5 v2 2/2] x86/hvm: Improve "Emulation failed @" error messages Andrew Cooper
2014-09-29 8:34 ` Jan Beulich
2014-09-29 9:23 ` Andrew Cooper
2014-09-29 9:35 ` Jan Beulich
2014-09-29 9:46 ` [PATCH for 4.5 v3 " Andrew Cooper
2014-10-01 0:55 ` Tian, Kevin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=542BC79C020000780003B527@mail.emea.novell.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=keir@xen.org \
--cc=tim@xen.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).