Whamcloud - gitweb
- adding CONFIG_KALLSYMS to kksymoops patch
[fs/lustre-release.git] / lustre / kernel_patches / patches / kksymoops-2.4.24.vanilla.patch
1 diff -urNp linux-700/arch/i386/config.in linux-720/arch/i386/config.in
2 --- linux-700/arch/i386/config.in
3 +++ linux-720/arch/i386/config.in
4 @@ -9,8 +9,6 @@ define_bool CONFIG_SBUS n
5   
6  define_bool CONFIG_UID16 y
7   
8 +define_bool CONFIG_KALLSYMS y
9 +
10  mainmenu_option next_comment
11  comment 'Code maturity level options'
12  bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL
13 diff -urNp linux-700/arch/i386/kernel/process.c linux-720/arch/i386/kernel/process.c
14 --- linux-700/arch/i386/kernel/process.c        
15 +++ linux-720/arch/i386/kernel/process.c        
16 @@ -33,6 +33,7 @@
17  #include <linux/reboot.h>
18  #include <linux/init.h>
19  #include <linux/mc146818rtc.h>
20 +#include <linux/version.h>
21  
22  #include <asm/uaccess.h>
23  #include <asm/pgtable.h>
24 @@ -437,10 +438,14 @@ extern void show_trace(unsigned long* es
25  void show_regs(struct pt_regs * regs)
26  {
27         unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
28 +       static char buffer[512];
29 +
30 +       lookup_symbol(regs->eip,buffer,512);
31  
32         printk("\n");
33         printk("Pid: %d, comm: %20s\n", current->pid, current->comm);
34         printk("EIP: %04x:[<%08lx>] CPU: %d",0xffff & regs->xcs,regs->eip, smp_processor_id());
35 +       printk("\nEIP is at %s (" UTS_RELEASE ")\n",buffer);
36         if (regs->xcs & 3)
37                 printk(" ESP: %04x:%08lx",0xffff & regs->xss,regs->esp);
38         printk(" EFLAGS: %08lx    %s\n",regs->eflags, print_tainted());
39 diff -urNp linux-700/arch/i386/kernel/traps.c linux-720/arch/i386/kernel/traps.c
40 --- linux-700/arch/i386/kernel/traps.c  
41 +++ linux-720/arch/i386/kernel/traps.c  
42 @@ -24,6 +24,7 @@
43  #include <linux/spinlock.h>
44  #include <linux/interrupt.h>
45  #include <linux/highmem.h>
46 +#include <linux/version.h>
47  
48  #ifdef CONFIG_MCA
49  #include <linux/mca.h>
50 @@ -135,6 +136,8 @@ void show_trace(unsigned long * stack)
51  {
52         int i;
53         unsigned long addr;
54 +       /* static to not take up stackspace; if we race here too bad */
55 +       static char buffer[512];
56  
57         if (!stack)
58                 stack = (unsigned long*)&stack;
59 @@ -144,9 +147,8 @@ void show_trace(unsigned long * stack)
60         while (((long) stack & (THREAD_SIZE-1)) != 0) {
61                 addr = *stack++;
62                 if (kernel_text_address(addr)) {
63 -                       if (i && ((i % 6) == 0))
64 -                               printk("\n ");
65 -                       printk(" [<%08lx>]", addr);
66 +                       lookup_symbol(addr, buffer, 512);
67 +                       printk("[<%08lx>] %s (0x%x))\n", addr,buffer,stack-1);
68                         i++;
69                 }
70         }
71 @@ -194,12 +196,17 @@ void dump_stack(void)
72         show_stack(0);
73  }
74  
75 +
76 +void print_modules(void);
77 +
78 +
79  void show_registers(struct pt_regs *regs)
80  {
81         int i;
82         int in_kernel = 1;
83         unsigned long esp;
84         unsigned short ss;
85 +       static char buffer[512];
86  
87         esp = (unsigned long) (&regs->esp);
88         ss = __KERNEL_DS;
89 @@ -208,8 +215,12 @@ void show_registers(struct pt_regs *regs
90                 esp = regs->esp;
91                 ss = regs->xss & 0xffff;
92         }
93 +
94 +       print_modules();
95 +       lookup_symbol(regs->eip, buffer, 512);
96         printk("CPU:    %d\nEIP:    %04x:[<%08lx>]    %s\nEFLAGS: %08lx\n",
97                 smp_processor_id(), 0xffff & regs->xcs, regs->eip, print_tainted(), regs->eflags);
98 +       printk("\nEIP is at %s (" UTS_RELEASE ")\n",buffer);
99         printk("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
100                 regs->eax, regs->ebx, regs->ecx, regs->edx);
101         printk("esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
102 @@ -269,7 +280,7 @@ static void handle_BUG(struct pt_regs *r
103         if (__get_user(file, (char **)(eip + 4)) ||
104                 (unsigned long)file < PAGE_OFFSET || __get_user(c, file))
105                 file = "<bad filename>";
106 -
107 +       printk("------------[ cut here ]------------\n");
108         printk("kernel BUG at %s:%d!\n", file, line);
109  
110  no_bug:
111 diff -urNp linux-700/include/linux/kernel.h linux-720/include/linux/kernel.h
112 --- linux-700/include/linux/kernel.h    
113 +++ linux-720/include/linux/kernel.h    
114 @@ -110,6 +110,8 @@ extern const char *print_tainted(void);
115  
116  extern void dump_stack(void);
117  
118 +extern int lookup_symbol(unsigned long address, char *buffer, int buflen);
119 +
120  #if DEBUG
121  #define pr_debug(fmt,arg...) \
122         printk(KERN_DEBUG fmt,##arg)
123 diff -urNp linux-700/kernel/kksymoops.c linux-720/kernel/kksymoops.c
124 --- linux-700/kernel/kksymoops.c        1970-01-01 01:00:00.000000000 +0100
125 +++ linux-720/kernel/kksymoops.c        
126 @@ -0,0 +1,82 @@
127 +#include <linux/module.h>
128 +#include <linux/string.h>
129 +#include <linux/errno.h>
130 +#include <linux/kernel.h>
131 +#include <linux/config.h>
132 +#ifdef CONFIG_KALLSYMS
133 +#include <linux/kallsyms.h>
134 +#endif
135 +
136 +
137 +
138 +int lookup_symbol(unsigned long address, char *buffer, int buflen)
139 +{
140 +       struct module *this_mod;
141 +       unsigned long bestsofar;
142 +
143 +       const char *mod_name = NULL, *sec_name = NULL, *sym_name = NULL;
144 +       unsigned long mod_start,mod_end,sec_start,sec_end,sym_start,sym_end;
145 +       
146 +       if (!buffer)
147 +               return -EFAULT;
148 +       
149 +       if (buflen<256)
150 +               return -ENOMEM;
151 +       
152 +       memset(buffer,0,buflen);
153 +
154 +#ifdef CONFIG_KALLSYMS
155 +       if (!kallsyms_address_to_symbol(address,&mod_name,&mod_start,&mod_end,&sec_name,
156 +               &sec_start, &sec_end, &sym_name, &sym_start, &sym_end)) {
157 +               /* kallsyms doesn't have a clue; lets try harder */
158 +               bestsofar = 0;
159 +               snprintf(buffer,buflen-1,"[unresolved]");
160 +               
161 +               this_mod = module_list;
162 +
163 +               while (this_mod != NULL) {
164 +                       int i;
165 +                       /* walk the symbol list of this module. Only symbols
166 +                          who's address is smaller than the searched for address
167 +                          are relevant; and only if it's better than the best so far */
168 +                       for (i=0; i< this_mod->nsyms; i++)
169 +                               if ((this_mod->syms[i].value<=address) &&
170 +                                       (bestsofar<this_mod->syms[i].value)) {
171 +                                       snprintf(buffer,buflen-1,"%s [%s] 0x%x",
172 +                                               this_mod->syms[i].name,
173 +                                               this_mod->name,
174 +                                               (unsigned int)(address - this_mod->syms[i].value));
175 +                                       bestsofar = this_mod->syms[i].value;
176 +                               }
177 +                       this_mod = this_mod->next;
178 +               }
179 +
180 +       } else { /* kallsyms success */
181 +               snprintf(buffer,buflen-1,"%s [%s] 0x%x",sym_name,mod_name,(unsigned int)(address-sym_start));
182 +       }
183 +#endif
184 +       return strlen(buffer);
185 +}
186 +
187 +static char modlist[4096];
188 +/* this function isn't smp safe but that's not really a problem; it's called from
189 + * oops context only and any locking could actually prevent the oops from going out;
190 + * the line that is generated is informational only and should NEVER prevent the real oops
191 + * from going out. 
192 + */
193 +void print_modules(void)
194 +{
195 +       struct module *this_mod;
196 +       int pos = 0, i;
197 +       memset(modlist,0,4096);
198 +
199 +#ifdef CONFIG_KALLSYMS
200 +       this_mod = module_list;
201 +       while (this_mod != NULL) {
202 +               if (this_mod->name != NULL)
203 +                       pos +=snprintf(modlist+pos,160-pos-1,"%s ",this_mod->name);
204 +               this_mod = this_mod->next;
205 +       }
206 +       printk("%s\n",modlist);
207 +#endif
208 +}
209 diff -urNp linux-700/kernel/Makefile linux-720/kernel/Makefile
210 --- linux-700/kernel/Makefile   2001-09-17 06:22:40.000000000 +0200
211 +++ linux-720/kernel/Makefile   
212 @@ -14,7 +14,7 @@ export-objs = signal.o sys.o kmod.o cont
213  obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
214             module.o exit.o itimer.o info.o time.o softirq.o resource.o \
215             sysctl.o acct.o capability.o ptrace.o timer.o user.o \
216 -           signal.o sys.o kmod.o context.o
217 +           signal.o sys.o kmod.o context.o kksymoops.o
218  
219  obj-$(CONFIG_UID16) += uid16.o
220  obj-$(CONFIG_MODULES) += ksyms.o