From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Tim Deegan <tim@xen.org>, Ian Campbell <Ian.Campbell@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH] xen: Introduce separator modifiers for the %ph custom printk
Date: Thu, 25 Feb 2016 17:57:32 +0000 [thread overview]
Message-ID: <1456423052-19300-1-git-send-email-andrew.cooper3@citrix.com> (raw)
The printk formats %*ph{C,D,N} are chosen to be compatible with their Linux
counterparts.
Sample:
(XEN) buf: 00 01 03 07 78 65 6e 00
(XEN) buf: 00:01:03:07:78:65:6e:00
(XEN) buf: 00-01-03-07-78-65-6e-00
(XEN) buf: 0001030778656e00
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
docs/misc/printk-formats.txt | 9 +++++++--
xen/common/vsprintf.c | 32 +++++++++++++++++++++++++++++---
2 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt
index dee0f3e..525108f 100644
--- a/docs/misc/printk-formats.txt
+++ b/docs/misc/printk-formats.txt
@@ -5,8 +5,13 @@ 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);
+ %*ph 00 01 02 ... 3f
+ %*phC 00:01:02: ... :3f
+ %*phD 00-01-02- ... -3f
+ %*phN 000102 ... 3f
+
+ Up to 64 characters. Buffer length expected via the field_width
+ paramter. i.e. printk("%*ph", 8, buffer);
Symbol/Function pointers:
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index 51b5e4e..18d2634 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -275,6 +275,7 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
case 'h': /* Raw buffer as hex string. */
{
const uint8_t *hex_buffer = arg;
+ char sep = ' '; /* Separator character. */
unsigned int i;
/* Consumed 'h' from the format string. */
@@ -286,6 +287,28 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
if ( field_width > 64 )
field_width = 64;
+ /*
+ * Peek ahead in the format string to see if a recognised separator
+ * modifier is present.
+ */
+ switch ( fmt[2] )
+ {
+ case 'C': /* Colons. */
+ ++*fmt_ptr;
+ sep = ':';
+ break;
+
+ case 'D': /* Dashes. */
+ ++*fmt_ptr;
+ sep = '-';
+ break;
+
+ case 'N': /* No separator. */
+ ++*fmt_ptr;
+ sep = 0;
+ break;
+ }
+
for ( i = 0; ; )
{
/* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */
@@ -294,9 +317,12 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
if ( ++i == field_width )
return str;
- if ( str < end )
- *str = ' ';
- ++str;
+ if ( sep )
+ {
+ if ( str < end )
+ *str = sep;
+ ++str;
+ }
}
}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
reply other threads:[~2016-02-25 17:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1456423052-19300-1-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=JBeulich@suse.com \
--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).