[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 1/5] common/vsprintf: Add %ps and %pS format specifier support



Introduce the %ps and %pS format options for printing a symbol.

  %ps will print the symbol name along
  %pS will print the symbol name + offset / size

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CC: Keir Fraser <keir@xxxxxxx>
CC: Jan Beulich <JBeulich@xxxxxxxx>
---
 xen/common/vsprintf.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index 95bf85d..e5fb2e1 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -17,6 +17,7 @@
  */
 
 #include <xen/ctype.h>
+#include <xen/symbols.h>
 #include <xen/lib.h>
 #include <asm/div64.h>
 #include <asm/page.h>
@@ -392,6 +393,47 @@ int vsnprintf(char *buf, size_t size, const char *fmt, 
va_list args)
             continue;
 
         case 'p':
+
+            /*
+             * Custom %p suffixes, compatible with Linux.
+             * See Linux:Documentation/printk-formats.txt
+             */
+            switch ( fmt[1] )
+            {
+            case 's': /* Symbol name */
+            case 'S': /* Symbol name with offset and size */
+            {
+                unsigned long sym_size, sym_offset,
+                    addr = (unsigned long)va_arg(args, void *);
+                char namebuf[KSYM_NAME_LEN+1];
+
+                s = symbols_lookup(addr, &sym_size, &sym_offset, namebuf);
+
+                if ( !s || fmt[1] == 's' )
+                {
+                    if ( !s )
+                        s = "???";
+
+                    len = strnlen(s, KSYM_NAME_LEN);
+
+                    for ( i = 0; i < len; ++i )
+                    {
+                        if ( str <= end )
+                            *str = *s;
+                        ++str; ++s;
+                    }
+                }
+                else
+                    str += snprintf(str, end - str + 1, "%s+%#lx/%#lx",
+                                    s, sym_offset, sym_size);
+
+                fmt++;
+                continue;
+            }
+
+            /* Fall through to basic %p */
+            }
+
             if (field_width == -1) {
                 field_width = 2*sizeof(void *);
                 flags |= ZEROPAD;
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.