]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
printk: introduce separator modifiers for the %ph custom format
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 26 Feb 2016 11:31:11 +0000 (12:31 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 15 Mar 2016 16:32:30 +0000 (16:32 +0000)
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>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
docs/misc/printk-formats.txt
xen/common/vsprintf.c

index dee0f3e8f77b6dcb4e77ddeda5ff1fa278d230e0..525108f86c0f51157c319cb423101104aaa16856 100644 (file)
@@ -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:
 
index 51b5e4e4d100f3d426718cff6ca741cd502cb4d5..18d263469340ede7123ec0dd3dd6c45a3321eeed 100644 (file)
@@ -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;
+            }
         }
     }