diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-04-15 11:48:18 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-04-29 14:55:55 -0400 |
commit | 0c8b946e3ebb3846103486420ea7430a4b5e5b1b (patch) | |
tree | 7d1c7f73edb19e3d1a1322065fc714e69348a239 /lib | |
parent | a4e94ef0dd391eae05bdeacd12b8da3510957a97 (diff) |
vsprintf: introduce %pf format specifier
A printf format specifier which would allow us to print a pure
function name has been suggested by Andrew Morton a couple of
months ago.
The current %pF is very convenient to print a function symbol,
but often we only want to print the name of the function, without
its asm offset.
That's what %pf does in this patch. The lowecase f has been chosen
for its intuitive meaning of a 'weak kind of %pF'.
The support for this new format would be welcome by the tracing code
where the need to print pure function names is often needed. This is
also true for other parts of the kernel:
$ git-grep -E "kallsyms_lookup\(.+?\)"
arch/blackfin/kernel/traps.c: symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
arch/powerpc/xmon/xmon.c: name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
arch/sh/kernel/cpu/sh5/unwind.c: sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
arch/x86/kernel/ftrace.c: kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
kernel/kprobes.c: sym = kallsyms_lookup((unsigned long)p->addr, NULL,
kernel/lockdep.c: return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
kernel/trace/ftrace.c: kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
kernel/trace/trace_functions.c: kallsyms_lookup(ip, NULL, NULL, NULL, str);
kernel/trace/trace_output.c: kallsyms_lookup(address, NULL, NULL, NULL, str);
Changes in v2:
- Add the explanation of the %pf role for vsnprintf() and bstr_printf()
- Change the comments by dropping the "asm offset" notion and only
define the %pf against the actual function offset notion.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index b56f6d039d21..756ccafa9cec 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -575,12 +575,15 @@ static char *string(char *buf, char *end, char *s, struct printf_spec spec) | |||
575 | } | 575 | } |
576 | 576 | ||
577 | static char *symbol_string(char *buf, char *end, void *ptr, | 577 | static char *symbol_string(char *buf, char *end, void *ptr, |
578 | struct printf_spec spec) | 578 | struct printf_spec spec, char ext) |
579 | { | 579 | { |
580 | unsigned long value = (unsigned long) ptr; | 580 | unsigned long value = (unsigned long) ptr; |
581 | #ifdef CONFIG_KALLSYMS | 581 | #ifdef CONFIG_KALLSYMS |
582 | char sym[KSYM_SYMBOL_LEN]; | 582 | char sym[KSYM_SYMBOL_LEN]; |
583 | sprint_symbol(sym, value); | 583 | if (ext != 'f') |
584 | sprint_symbol(sym, value); | ||
585 | else | ||
586 | kallsyms_lookup(value, NULL, NULL, NULL, sym); | ||
584 | return string(buf, end, sym, spec); | 587 | return string(buf, end, sym, spec); |
585 | #else | 588 | #else |
586 | spec.field_width = 2*sizeof(void *); | 589 | spec.field_width = 2*sizeof(void *); |
@@ -692,7 +695,8 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, | |||
692 | * | 695 | * |
693 | * Right now we handle: | 696 | * Right now we handle: |
694 | * | 697 | * |
695 | * - 'F' For symbolic function descriptor pointers | 698 | * - 'F' For symbolic function descriptor pointers with offset |
699 | * - 'f' For simple symbolic function names without offset | ||
696 | * - 'S' For symbolic direct pointers | 700 | * - 'S' For symbolic direct pointers |
697 | * - 'R' For a struct resource pointer, it prints the range of | 701 | * - 'R' For a struct resource pointer, it prints the range of |
698 | * addresses (not the name nor the flags) | 702 | * addresses (not the name nor the flags) |
@@ -715,10 +719,11 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
715 | 719 | ||
716 | switch (*fmt) { | 720 | switch (*fmt) { |
717 | case 'F': | 721 | case 'F': |
722 | case 'f': | ||
718 | ptr = dereference_function_descriptor(ptr); | 723 | ptr = dereference_function_descriptor(ptr); |
719 | /* Fallthrough */ | 724 | /* Fallthrough */ |
720 | case 'S': | 725 | case 'S': |
721 | return symbol_string(buf, end, ptr, spec); | 726 | return symbol_string(buf, end, ptr, spec, *fmt); |
722 | case 'R': | 727 | case 'R': |
723 | return resource_string(buf, end, ptr, spec); | 728 | return resource_string(buf, end, ptr, spec); |
724 | case 'm': | 729 | case 'm': |
@@ -954,7 +959,8 @@ qualifier: | |||
954 | * | 959 | * |
955 | * This function follows C99 vsnprintf, but has some extensions: | 960 | * This function follows C99 vsnprintf, but has some extensions: |
956 | * %pS output the name of a text symbol | 961 | * %pS output the name of a text symbol |
957 | * %pF output the name of a function pointer | 962 | * %pF output the name of a function pointer with its offset |
963 | * %pf output the name of a function pointer without its offset | ||
958 | * %pR output the address range in a struct resource | 964 | * %pR output the address range in a struct resource |
959 | * | 965 | * |
960 | * The return value is the number of characters which would | 966 | * The return value is the number of characters which would |
@@ -1412,7 +1418,8 @@ EXPORT_SYMBOL_GPL(vbin_printf); | |||
1412 | * | 1418 | * |
1413 | * The format follows C99 vsnprintf, but has some extensions: | 1419 | * The format follows C99 vsnprintf, but has some extensions: |
1414 | * %pS output the name of a text symbol | 1420 | * %pS output the name of a text symbol |
1415 | * %pF output the name of a function pointer | 1421 | * %pF output the name of a function pointer with its offset |
1422 | * %pf output the name of a function pointer without its offset | ||
1416 | * %pR output the address range in a struct resource | 1423 | * %pR output the address range in a struct resource |
1417 | * %n is ignored | 1424 | * %n is ignored |
1418 | * | 1425 | * |