Extend print_symbol capability
[linux-2.6.git] / include / linux / kallsyms.h
1 /* Rewritten and vastly simplified by Rusty Russell for in-kernel
2  * module loader:
3  *   Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4  */
5 #ifndef _LINUX_KALLSYMS_H
6 #define _LINUX_KALLSYMS_H
7
8
9 #define KSYM_NAME_LEN 127
10 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN +  \
11                          2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1)
12
13 #ifdef CONFIG_KALLSYMS
14 /* Lookup the address for a symbol. Returns 0 if not found. */
15 unsigned long kallsyms_lookup_name(const char *name);
16
17 extern int kallsyms_lookup_size_offset(unsigned long addr,
18                                   unsigned long *symbolsize,
19                                   unsigned long *offset);
20
21 /* Lookup an address.  modname is set to NULL if it's in the kernel. */
22 const char *kallsyms_lookup(unsigned long addr,
23                             unsigned long *symbolsize,
24                             unsigned long *offset,
25                             char **modname, char *namebuf);
26
27 /* Look up a kernel symbol and return it in a text buffer. */
28 extern int sprint_symbol(char *buffer, unsigned long address);
29
30 /* Look up a kernel symbol and print it to the kernel messages. */
31 extern void __print_symbol(const char *fmt, unsigned long address);
32
33 #else /* !CONFIG_KALLSYMS */
34
35 static inline unsigned long kallsyms_lookup_name(const char *name)
36 {
37         return 0;
38 }
39
40 static inline int kallsyms_lookup_size_offset(unsigned long addr,
41                                               unsigned long *symbolsize,
42                                               unsigned long *offset)
43 {
44         return 0;
45 }
46
47 static inline const char *kallsyms_lookup(unsigned long addr,
48                                           unsigned long *symbolsize,
49                                           unsigned long *offset,
50                                           char **modname, char *namebuf)
51 {
52         return NULL;
53 }
54
55 static inline int sprint_symbol(char *buffer, unsigned long addr)
56 {
57         *buffer = '\0';
58         return 0;
59 }
60
61 /* Stupid that this does nothing, but I didn't create this mess. */
62 #define __print_symbol(fmt, addr)
63 #endif /*CONFIG_KALLSYMS*/
64
65 /* This macro allows us to keep printk typechecking */
66 static void __check_printsym_format(const char *fmt, ...)
67 __attribute__((format(printf,1,2)));
68 static inline void __check_printsym_format(const char *fmt, ...)
69 {
70 }
71 /* ia64 and ppc64 use function descriptors, which contain the real address */
72 #if defined(CONFIG_IA64) || defined(CONFIG_PPC64)
73 #define print_fn_descriptor_symbol(fmt, addr)           \
74 do {                                            \
75         unsigned long *__faddr = (unsigned long*) addr;         \
76         print_symbol(fmt, __faddr[0]);          \
77 } while (0)
78 #else
79 #define print_fn_descriptor_symbol(fmt, addr) print_symbol(fmt, addr)
80 #endif
81
82 static inline void print_symbol(const char *fmt, unsigned long addr)
83 {
84         __check_printsym_format(fmt, "");
85         __print_symbol(fmt, (unsigned long)
86                        __builtin_extract_return_addr((void *)addr));
87 }
88
89 #ifndef CONFIG_64BIT
90 #define print_ip_sym(ip)                \
91 do {                                    \
92         printk("[<%08lx>]", ip);        \
93         print_symbol(" %s\n", ip);      \
94 } while(0)
95 #else
96 #define print_ip_sym(ip)                \
97 do {                                    \
98         printk("[<%016lx>]", ip);       \
99         print_symbol(" %s\n", ip);      \
100 } while(0)
101 #endif
102
103 #endif /*_LINUX_KALLSYMS_H*/