From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: [PATCH 1/5] common/vsprintf: Add %ps and %pS format specifier support Date: Mon, 4 Nov 2013 10:55:35 +0000 Message-ID: <1383562539-16085-2-git-send-email-andrew.cooper3@citrix.com> References: <1383562539-16085-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1383562539-16085-1-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 , Jan Beulich List-Id: xen-devel@lists.xenproject.org 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 CC: Keir Fraser CC: Jan Beulich --- 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 +#include #include #include #include @@ -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