From: "Jan Beulich" Subject: Re: [PATCH 1/5] common/vsprintf: Add %ps and %pS format specifier support Date: Mon, 04 Nov 2013 14:51:37 +0000 Message-ID: <5277C28902000078000FF201@nat28.tlf.novell.com> References: <1383562539-16085-1-git-send-email-andrew.cooper3@citrix.com> <1383562539-16085-2-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VdLVI-0000TC-Gs for xen-devel@lists.xenproject.org; Mon, 04 Nov 2013 14:51:44 +0000 In-Reply-To: <1383562539-16085-2-git-send-email-andrew.cooper3@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: xen-devel , Keir Fraser List-Id: xen-devel@lists.xenproject.org >>> On 04.11.13 at 11:55, Andrew Cooper wrote: > @@ -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; For the sake of future extensibility (with the code remaining legible) this should be broken out into a pointer() function similar (but not necessarily identical) to Linux'es. Nesting long switch() statements isn't really nice (I've got comments on nested ones in the past even if the inner one was short). Jan