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

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



>>> On 04.11.13 at 11:55, Andrew Cooper <andrew.cooper3@xxxxxxxxxx> 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


_______________________________________________
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®.