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