From: "Jan Beulich" Subject: [PATCH v3 1/2] vsprintf: introduce %*ph extended format specifier for hex buffers Date: Wed, 01 Oct 2014 08:21:32 +0100 Message-ID: <542BC79C020000780003B527@mail.emea.novell.com> References: <1411748677-21069-1-git-send-email-andrew.cooper3@citrix.com> <1411748677-21069-2-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartD0E5A26C.1__=" Return-path: In-Reply-To: <1411748677-21069-2-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Keir Fraser , Tim Deegan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartD0E5A26C.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 Release-acked-by: Konrad Rzeszutek Wilk Re-structured code. Signed-off-by: Jan Beulich --- 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. =20 +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: =20 %ps Symbol name with condition offset and size (iff offset = !=3D 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. =20 +Domain and vCPU information: + %pv Domain and vCPU ID from a 'struct vcpu *' (printed as "dv") --- 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 =3D 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 <=3D 0 ) + return str; + if ( field_width > 64 ) + field_width =3D 64; + + for ( i =3D 0; ; ) + { + /* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */ + str =3D number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD); + + if ( ++i =3D=3D field_width ) + return str; + + if ( str < end ) + *str =3D ' '; + ++str; + } + } + case 's': /* Symbol name with offset and size (iff offset !=3D 0) */ case 'S': /* Symbol name unconditionally with offset and size */ { --=__PartD0E5A26C.1__= Content-Type: text/plain; name="vsnprintf-%ph.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vsnprintf-%ph.patch" vsprintf: introduce %*ph extended format specifier for hex buffers=0A=0AThi= s behaves in the same way as Linux. The 64 byte limit is arbitrary = but=0Along enough for practical purposes.=0A=0ASigned-off-by: Andrew = Cooper =0ARelease-acked-by: Konrad Rzeszutek = Wilk =0A=0ARe-structured code.=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- a/docs/misc/printk-formats.txt=0A+= ++ b/docs/misc/printk-formats.txt=0A@@ -3,6 +3,11 @@ Xen custom %p format = options. A subset,=0A All parameters to a %p option should be compatible = with void*. Regular=0A pointers are fine. Numbers should make use of the = _p() macro.=0A =0A+Raw buffer as hex string:=0A+=0A+ %*ph Up to = 64 characters, printed as "00 01 02 ... ff". Buffer length=0A+ = expected via the field_width paramter. i.e. printk("%*ph", 8, = buffer);=0A+=0A Symbol/Function pointers:=0A =0A %ps Symbol = name with condition offset and size (iff offset !=3D 0)=0A@@ -16,5 +21,7 = @@ Symbol/Function pointers:=0A In the case that an appropriate = symbol name can't be found, %p[sS] will=0A fall back to '%p' and = print the address in hex.=0A =0A+Domain and vCPU information:=0A+=0A = %pv Domain and vCPU ID from a 'struct vcpu *' (printed as=0A = "dv")=0A--- a/xen/common/vsprintf.c=0A+++ b/xen/common= /vsprintf.c=0A@@ -272,6 +272,34 @@ static char *pointer(char *str, char = *en=0A /* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt= */=0A switch ( fmt[1] )=0A {=0A+ case 'h': /* Raw buffer as = hex string. */=0A+ {=0A+ const uint8_t *hex_buffer =3D arg;=0A+ = unsigned int i;=0A+=0A+ /* Consumed 'h' from the format = string. */=0A+ ++*fmt_ptr;=0A+=0A+ /* Bound user count from = %* to between 0 and 64 bytes. */=0A+ if ( field_width <=3D 0 )=0A+ = return str;=0A+ if ( field_width > 64 )=0A+ = field_width =3D 64;=0A+=0A+ for ( i =3D 0; ; )=0A+ {=0A+ = /* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */=0A+ = str =3D number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD);=0A+=0A+= if ( ++i =3D=3D field_width )=0A+ return = str;=0A+=0A+ if ( str < end )=0A+ *str =3D ' = ';=0A+ ++str;=0A+ }=0A+ }=0A+=0A case 's': /* = Symbol name with offset and size (iff offset !=3D 0) */=0A case 'S': = /* Symbol name unconditionally with offset and size */=0A {=0A --=__PartD0E5A26C.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartD0E5A26C.1__=--