xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
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>
Subject: [PATCH 1/5] common/vsprintf: Add %ps and %pS format specifier support
Date: Mon, 4 Nov 2013 10:55:35 +0000	[thread overview]
Message-ID: <1383562539-16085-2-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1383562539-16085-1-git-send-email-andrew.cooper3@citrix.com>

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@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
---
 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

  reply	other threads:[~2013-11-04 10:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04 10:55 [PATCH 0/5] Printk symbol specifier Andrew Cooper
2013-11-04 10:55 ` Andrew Cooper [this message]
2013-11-04 14:51   ` [PATCH 1/5] common/vsprintf: Add %ps and %pS format specifier support Jan Beulich
2013-11-04 14:54   ` Jan Beulich
2013-11-04 18:39   ` Tim Deegan
2013-11-04 10:55 ` [PATCH 2/5] x86: Replace print_symbol() with new %ps/%pS format Andrew Cooper
2013-11-04 10:55 ` [PATCH 3/5] arm: " Andrew Cooper
2013-11-04 15:20   ` Ian Campbell
2013-11-04 10:55 ` [PATCH 4/5] common/symbols: Remove print_symbol() and associated infrastructure Andrew Cooper
2013-11-04 10:55 ` [PATCH 5/5] Test harness for new printk formatting Andrew Cooper

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=1383562539-16085-2-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=keir@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).