1 |
1625 |
jcastillo |
From: Linus Torvalds
|
2 |
|
|
|
3 |
|
|
How to track down an Oops.. [originally a mail to linux-kernel]
|
4 |
|
|
|
5 |
|
|
The main trick is having 5 years of experience with those pesky oops
|
6 |
|
|
messages ;-)
|
7 |
|
|
|
8 |
|
|
Actually, there are things you can do that make this easier. I have two
|
9 |
|
|
separate approaches:
|
10 |
|
|
|
11 |
|
|
gdb /usr/src/linux/vmlinux
|
12 |
|
|
gdb> disassemble
|
13 |
|
|
|
14 |
|
|
That's the easy way to find the problem, at least if the bug-report is
|
15 |
|
|
well made (like this one was - run through ksymoops to get the
|
16 |
|
|
information of which function and the offset in the function that it
|
17 |
|
|
happened in).
|
18 |
|
|
|
19 |
|
|
Oh, it helps if the report happens on a kernel that is compiled with the
|
20 |
|
|
same compiler and similar setups.
|
21 |
|
|
|
22 |
|
|
The other thing to do is disassemble the "Code:" part of the bug report:
|
23 |
|
|
ksymoops will do this too with the correct tools (and new version of
|
24 |
|
|
ksymoops), but if you don't have the tools you can just do a silly
|
25 |
|
|
program:
|
26 |
|
|
|
27 |
|
|
char str[] = "\xXX\xXX\xXX...";
|
28 |
|
|
main(){}
|
29 |
|
|
|
30 |
|
|
and compile it with gcc -g and then do "disassemble str" (where the "XX"
|
31 |
|
|
stuff are the values reported by the Oops - you can just cut-and-paste
|
32 |
|
|
and do a replace of spaces to "\x" - that's what I do, as I'm too lazy
|
33 |
|
|
to write a program to automate this all).
|
34 |
|
|
|
35 |
|
|
Finally, if you want to see where the code comes from, you can do
|
36 |
|
|
|
37 |
|
|
cd /usr/src/linux
|
38 |
|
|
make fs/buffer.s # or whatever file the bug happened in
|
39 |
|
|
|
40 |
|
|
and then you get a better idea of what happens than with the gdb
|
41 |
|
|
disassembly.
|
42 |
|
|
|
43 |
|
|
Now, the trick is just then to combine all the data you have: the C
|
44 |
|
|
sources (and general knowledge of what it _should_ do, the assembly
|
45 |
|
|
listing and the code disassembly (and additionally the register dump you
|
46 |
|
|
also get from the "oops" message - that can be useful to see _what_ the
|
47 |
|
|
corrupted pointers were, and when you have the assembler listing you can
|
48 |
|
|
also match the other registers to whatever C expressions they were used
|
49 |
|
|
for).
|
50 |
|
|
|
51 |
|
|
Essentially, you just look at what doesn't match (in this case it was the
|
52 |
|
|
"Code" disassembly that didn't match with what the compiler generated).
|
53 |
|
|
Then you need to find out _why_ they don't match. Often it's simple - you
|
54 |
|
|
see that the code uses a NULL pointer and then you look at the code and
|
55 |
|
|
wonder how the NULL pointer got there, and if it's a valid thing to do
|
56 |
|
|
you just check against it..
|
57 |
|
|
|
58 |
|
|
Now, if somebody gets the idea that this is time-consuming and requires
|
59 |
|
|
some small amount of concentration, you're right. Which is why I will
|
60 |
|
|
mostly just ignore any panic reports that don't have the symbol table
|
61 |
|
|
info etc looked up: it simply gets too hard to look it up (I have some
|
62 |
|
|
programs to search for specific patterns in the kernel code segment, and
|
63 |
|
|
sometimes I have been able to look up those kinds of panics too, but
|
64 |
|
|
that really requires pretty good knowledge of the kernel just to be able
|
65 |
|
|
to pick out the right sequences etc..)
|
66 |
|
|
|
67 |
|
|
_Sometimes_ it happens that I just see the disassembled code sequence
|
68 |
|
|
from the panic, and I know immediately where it's coming from. That's when
|
69 |
|
|
I get worried that I've been doing this for too long ;-)
|
70 |
|
|
|
71 |
|
|
Linus
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
---------------------------------------------------------------------------
|
75 |
|
|
Notes on Oops tracing with klogd:
|
76 |
|
|
|
77 |
|
|
In order to help Linus and the other kernel developers there has been
|
78 |
|
|
substantial support incorporated into klogd for processing protection
|
79 |
|
|
faults. In order to have full support for address resolution at least
|
80 |
|
|
version 1.3-pl3 of the sysklogd package should be used.
|
81 |
|
|
|
82 |
|
|
When a protection fault occurs the klogd daemon automatically
|
83 |
|
|
translates important addresses in the kernel log messages to their
|
84 |
|
|
symbolic equivalents. This translated kernel message is then
|
85 |
|
|
forwarded through whatever reporting mechanism klogd is using. The
|
86 |
|
|
protection fault message can be simply cut out of the message files
|
87 |
|
|
and forwarded to the kernel developers.
|
88 |
|
|
|
89 |
|
|
Two types of address resolution are performed by klogd. The first is
|
90 |
|
|
static translation and the second is dynamic translation. Static
|
91 |
|
|
translation uses the System.map file in much the same manner that
|
92 |
|
|
ksymoops does. In order to do static translation the klogd daemon
|
93 |
|
|
must be able to find a system map file at daemon initialization time.
|
94 |
|
|
See the klogd man page for information on how klogd searches for map
|
95 |
|
|
files.
|
96 |
|
|
|
97 |
|
|
Dynamic address translation is important when kernel loadable modules
|
98 |
|
|
are being used. Since memory for kernel modules is allocated from the
|
99 |
|
|
kernel's dynamic memory pools there are no fixed locations for either
|
100 |
|
|
the start of the module or for functions and symbols in the module.
|
101 |
|
|
|
102 |
|
|
The kernel supports system calls which allow a program to determine
|
103 |
|
|
which modules are loaded and their location in memory. Using these
|
104 |
|
|
system calls the klogd daemon builds a symbol table which can be used
|
105 |
|
|
to debug a protection fault which occurs in a loadable kernel module.
|
106 |
|
|
|
107 |
|
|
At the very minimum klogd will provide the name of the module which
|
108 |
|
|
generated the protection fault. There may be additional symbolic
|
109 |
|
|
information available if the developer of the loadable module chose to
|
110 |
|
|
export symbol information from the module.
|
111 |
|
|
|
112 |
|
|
Since the kernel module environment can be dynamic there must be a
|
113 |
|
|
mechanism for notifying the klogd daemon when a change in module
|
114 |
|
|
environment occurs. There are command line options available which
|
115 |
|
|
allow klogd to signal the currently executing daemon that symbol
|
116 |
|
|
information should be refreshed. See the klogd manual page for more
|
117 |
|
|
information.
|
118 |
|
|
|
119 |
|
|
A patch is included with the sysklogd distribution which modifies the
|
120 |
|
|
modules-2.0.0 package to automatically signal klogd whenever a module
|
121 |
|
|
is loaded or unloaded. Applying this patch provides essentially
|
122 |
|
|
seamless support for debugging protection faults which occur with
|
123 |
|
|
kernel loadable modules.
|
124 |
|
|
|
125 |
|
|
The following is an example of a protection fault in a loadable module
|
126 |
|
|
processed by klogd:
|
127 |
|
|
---------------------------------------------------------------------------
|
128 |
|
|
Aug 29 09:51:01 blizard kernel: Unable to handle kernel paging request at virtual address f15e97cc
|
129 |
|
|
Aug 29 09:51:01 blizard kernel: current->tss.cr3 = 0062d000, %cr3 = 0062d000
|
130 |
|
|
Aug 29 09:51:01 blizard kernel: *pde = 00000000
|
131 |
|
|
Aug 29 09:51:01 blizard kernel: Oops: 0002
|
132 |
|
|
Aug 29 09:51:01 blizard kernel: CPU: 0
|
133 |
|
|
Aug 29 09:51:01 blizard kernel: EIP: 0010:[oops:_oops+16/3868]
|
134 |
|
|
Aug 29 09:51:01 blizard kernel: EFLAGS: 00010212
|
135 |
|
|
Aug 29 09:51:01 blizard kernel: eax: 315e97cc ebx: 003a6f80 ecx: 001be77b edx: 00237c0c
|
136 |
|
|
Aug 29 09:51:01 blizard kernel: esi: 00000000 edi: bffffdb3 ebp: 00589f90 esp: 00589f8c
|
137 |
|
|
Aug 29 09:51:01 blizard kernel: ds: 0018 es: 0018 fs: 002b gs: 002b ss: 0018
|
138 |
|
|
Aug 29 09:51:01 blizard kernel: Process oops_test (pid: 3374, process nr: 21, stackpage=00589000)
|
139 |
|
|
Aug 29 09:51:01 blizard kernel: Stack: 315e97cc 00589f98 0100b0b4 bffffed4 0012e38e 00240c64 003a6f80 00000001
|
140 |
|
|
Aug 29 09:51:01 blizard kernel: 00000000 00237810 bfffff00 0010a7fa 00000003 00000001 00000000 bfffff00
|
141 |
|
|
Aug 29 09:51:01 blizard kernel: bffffdb3 bffffed4 ffffffda 0000002b 0007002b 0000002b 0000002b 00000036
|
142 |
|
|
Aug 29 09:51:01 blizard kernel: Call Trace: [oops:_oops_ioctl+48/80] [_sys_ioctl+254/272] [_system_call+82/128]
|
143 |
|
|
Aug 29 09:51:01 blizard kernel: Code: c7 00 05 00 00 00 eb 08 90 90 90 90 90 90 90 90 89 ec 5d c3
|
144 |
|
|
---------------------------------------------------------------------------
|
145 |
|
|
|
146 |
|
|
Dr. G.W. Wettstein Oncology Research Div. Computing Facility
|
147 |
|
|
Roger Maris Cancer Center INTERNET: greg@wind.rmcc.com
|
148 |
|
|
820 4th St. N.
|
149 |
|
|
Fargo, ND 58122
|
150 |
|
|
Phone: 701-234-7556
|