From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Keir Fraser <keir@xen.org>, Jan Beulich <JBeulich@suse.com>,
Tim Deegan <tim@xen.org>
Subject: [PATCH for-4.5 1/2] xen/vsprintf: Introduce %*ph extended format specifier for hex buffers
Date: Fri, 26 Sep 2014 11:10:06 +0100 [thread overview]
Message-ID: <1411726207-2689-2-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1411726207-2689-1-git-send-email-andrew.cooper3@citrix.com>
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>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
docs/misc/printk-formats.txt | 6 ++++++
xen/common/vsprintf.c | 25 +++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt
index 3b4323a..81b3651 100644
--- a/docs/misc/printk-formats.txt
+++ b/docs/misc/printk-formats.txt
@@ -18,3 +18,9 @@ Symbol/Function pointers:
%pv Domain and vCPU ID from a 'struct vcpu *' (printed as
"d<domid>v<vcpuid>")
+
+
+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);
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index e68886a..4a7da1c 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -272,6 +272,31 @@ 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. */
+ {
+ /*
+ * User expected to provide an explicit count using %*. Bound between
+ * 0 and 64 bytes, defaulting to 0.
+ */
+ unsigned i, nr_bytes =
+ ((field_width < 1) || (field_width > 64)) ? 0 : 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);
+ 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
next prev parent reply other threads:[~2014-09-26 10:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-26 10:10 [PATCH for-4.5 0/2] Improve "Emulation failed" error message Andrew Cooper
2014-09-26 10:10 ` Andrew Cooper [this message]
2014-09-26 11:32 ` [PATCH for-4.5 1/2] xen/vsprintf: Introduce %*ph extended format specifier for hex buffers Jan Beulich
2014-09-26 12:16 ` Andrew Cooper
2014-09-26 12:31 ` Jan Beulich
2014-09-26 12:32 ` Andrew Cooper
2014-09-26 11:49 ` Tim Deegan
2014-09-26 11:57 ` Jan Beulich
2014-09-26 10:10 ` [PATCH for-4.5 2/2] x86/hvm: Improve "Emulation failed @" error messages Andrew Cooper
2014-09-26 11:39 ` Jan Beulich
2014-09-26 12:04 ` Andrew Cooper
2014-09-26 12:36 ` Jan Beulich
2014-09-26 12:53 ` Andrew Cooper
2014-09-26 12:05 ` Tim Deegan
2014-09-26 12:09 ` Andrew Cooper
2014-09-26 12:41 ` Tim Deegan
2014-09-26 12:57 ` Andrew Cooper
2014-09-26 13:06 ` Jan Beulich
2014-09-26 13:16 ` Andrew Cooper
2014-09-26 13:32 ` Jan Beulich
2014-09-26 14:15 ` [PATCH for-4.5 0/2] Improve "Emulation failed" error message Konrad Rzeszutek Wilk
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=1411726207-2689-2-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.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).