|
Lines 14-42
Link Here
|
| 14 |
|
14 |
|
| 15 |
<para>Here are some instructions for getting kernel debugging |
15 |
<para>Here are some instructions for getting kernel debugging |
| 16 |
working on a crash dump. They assume that you have enough swap |
16 |
working on a crash dump. They assume that you have enough swap |
| 17 |
space for a crash dump. If you have multiple swap partitions |
17 |
space for a crash dump. Typically you want to |
| 18 |
and the first one is too small to hold the dump, you can |
|
|
| 19 |
configure your kernel to use an alternate dump device (in the |
| 20 |
<literal>config kernel</literal> line), or you can specify an |
| 21 |
alternate using the &man.dumpon.8; command. The best way to use |
| 22 |
&man.dumpon.8; is to set the <literal>dumpdev</literal> variable |
| 23 |
in <filename>/etc/rc.conf</filename>. Typically you want to |
| 24 |
specify one of the swap devices specified in |
18 |
specify one of the swap devices specified in |
| 25 |
<filename>/etc/fstab</filename>. Dumps to non-swap devices, |
19 |
<filename>/etc/fstab</filename>. Dumps to non-swap devices, |
| 26 |
tapes for example, are currently not supported. Config your |
20 |
tapes for example, are currently not supported.</para> |
| 27 |
kernel using <command>config <option>-g</option></command>. See |
21 |
|
| 28 |
<ulink url="../handbook/index.html">The FreeBSD |
22 |
<note> |
| 29 |
Handbook</ulink> for details on configuring the FreeBSD |
23 |
<para>Use the &man.dumpon.8; command to tell the kernel where to dump to |
| 30 |
kernel.</para> |
24 |
(note that this will have to be done after configuring the partition in |
| 31 |
|
25 |
question as swap space via &man.swapon.8;). This is normally arranged |
| 32 |
<para>Use the &man.dumpon.8; command to tell the kernel where to dump to |
26 |
by setting the <varname>dumpdev</varname> variable in |
| 33 |
(note that this will have to be done after configuring the partition in |
27 |
<filename>/etc/rc.conf</filename>.</para> |
| 34 |
question as swap space via &man.swapon.8;). This is normally arranged |
28 |
|
| 35 |
via <filename>/etc/rc.conf</filename> and <filename>/etc/rc</filename>. |
29 |
<para>Alternatively, you can hard-code the dump device via the |
| 36 |
Alternatively, you can hard-code the dump device via the |
30 |
<literal>dump</literal> clause in the <literal>config</literal> line of |
| 37 |
<literal>dump</literal> clause in the <literal>config</literal> line of |
31 |
your kernel configuration file. This approach is deprecated and should |
| 38 |
your kernel config file. This is deprecated and should be used only if |
32 |
be used only if you want a crash dump from a kernel that crashes during |
| 39 |
you want a crash dump from a kernel that crashes during booting.</para> |
33 |
booting.</para> |
|
|
34 |
</note> |
| 40 |
|
35 |
|
| 41 |
<note> |
36 |
<note> |
| 42 |
<para>In the following, the term <command>gdb</command> refers to |
37 |
<para>In the following, the term <command>gdb</command> refers to |
|
Lines 211-218
Link Here
|
| 211 |
<term>line 36:</term> |
206 |
<term>line 36:</term> |
| 212 |
|
207 |
|
| 213 |
<listitem> |
208 |
<listitem> |
| 214 |
<para>Force usage of a new stack frame; this is no longer necessary |
209 |
<para>Force usage of a new stack frame; this is no longer necessary. |
| 215 |
now. The stack frames are supposed to point to the right |
210 |
The stack frames are supposed to point to the right |
| 216 |
locations now, even in case of a trap. |
211 |
locations now, even in case of a trap. |
| 217 |
From looking at the code in source line 403, there is a |
212 |
From looking at the code in source line 403, there is a |
| 218 |
high probability that either the pointer access for |
213 |
high probability that either the pointer access for |
|
Lines 248-254
Link Here
|
| 248 |
<title>Debugging a Crash Dump with DDD</title> |
243 |
<title>Debugging a Crash Dump with DDD</title> |
| 249 |
|
244 |
|
| 250 |
<para>Examining a kernel crash dump with a graphical debugger like |
245 |
<para>Examining a kernel crash dump with a graphical debugger like |
| 251 |
<command>ddd</command> is also possible. Add the <option>-k</option> |
246 |
<command>ddd</command> is also possible (you will need to install |
|
|
247 |
the <port>devel/ddd</port> port in order to use the |
| 248 |
<command>ddd</command> debugger). Add the <option>-k</option> |
| 252 |
option to the <command>ddd</command> command line you would use |
249 |
option to the <command>ddd</command> command line you would use |
| 253 |
normally. For example;</para> |
250 |
normally. For example;</para> |
| 254 |
|
251 |
|
|
Lines 265-282
Link Here
|
| 265 |
and it is therefore not compiled using <command>config -g</command>? Not |
262 |
and it is therefore not compiled using <command>config -g</command>? Not |
| 266 |
everything is lost here. Do not panic!</para> |
263 |
everything is lost here. Do not panic!</para> |
| 267 |
|
264 |
|
| 268 |
<para>Of course, you still need to enable crash dumps. See above on the |
265 |
<para>Of course, you still need to enable crash dumps. See above for the |
| 269 |
options you have to specify in order to do this.</para> |
266 |
options you have to specify in order to do this.</para> |
| 270 |
|
267 |
|
| 271 |
<para>Go to your kernel config directory |
268 |
<para>Go to your kernel config directory |
| 272 |
(<filename>/usr/src/sys/<replaceable>arch</replaceable>/conf</filename>) |
269 |
(<filename>/usr/src/sys/<replaceable>arch</replaceable>/conf</filename>) |
| 273 |
and edit your configuration file. Uncomment (or add, if it does not |
270 |
and edit your configuration file. Uncomment (or add, if it does not |
| 274 |
exist) the following line</para> |
271 |
exist) the following line:</para> |
| 275 |
|
272 |
|
| 276 |
<programlisting>makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols</programlisting> |
273 |
<programlisting>makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols</programlisting> |
| 277 |
|
274 |
|
| 278 |
<para>Rebuild the kernel. Due to the time stamp change on the Makefile, |
275 |
<para>Rebuild the kernel. Due to the time stamp change on the Makefile, |
| 279 |
there will be some other object files rebuild, for example |
276 |
there some other object files will be rebuilt, for example |
| 280 |
<filename>trap.o</filename>. With a bit of luck, the added |
277 |
<filename>trap.o</filename>. With a bit of luck, the added |
| 281 |
<option>-g</option> option will not change anything for the generated |
278 |
<option>-g</option> option will not change anything for the generated |
| 282 |
code, so you will finally get a new kernel with similar code to the |
279 |
code, so you will finally get a new kernel with similar code to the |
|
Lines 288-294
Link Here
|
| 288 |
might be incomplete for some places, as can be seen in the stack trace |
285 |
might be incomplete for some places, as can be seen in the stack trace |
| 289 |
in the example above where some functions are displayed without line |
286 |
in the example above where some functions are displayed without line |
| 290 |
numbers and argument lists. If you need more debugging symbols, remove |
287 |
numbers and argument lists. If you need more debugging symbols, remove |
| 291 |
the appropriate object files and repeat the <command>gdb <option>-k</option></command> |
288 |
the appropriate object files, recompile the kernel again and repeat the |
|
|
289 |
<command>gdb <option>-k</option></command> |
| 292 |
session until you know enough.</para> |
290 |
session until you know enough.</para> |
| 293 |
|
291 |
|
| 294 |
<para>All this is not guaranteed to work, but it will do it fine in most |
292 |
<para>All this is not guaranteed to work, but it will do it fine in most |
|
Lines 304-314
Link Here
|
| 304 |
code.</para> |
302 |
code.</para> |
| 305 |
|
303 |
|
| 306 |
<para>If you need to do low-level debugging on your kernel, there is an |
304 |
<para>If you need to do low-level debugging on your kernel, there is an |
| 307 |
on-line debugger available called DDB. It allows to setting |
305 |
on-line debugger available called DDB. It allows setting of |
| 308 |
breakpoints, single-stepping kernel functions, examining and changing |
306 |
breakpoints, single-stepping kernel functions, examining and changing |
| 309 |
kernel variables, etc. However, it cannot access kernel source files, |
307 |
kernel variables, etc. However, it cannot access kernel source files, |
| 310 |
and only has access to the global and static symbols, not to the full |
308 |
and only has access to the global and static symbols, not to the full |
| 311 |
debug information like <command>gdb</command>.</para> |
309 |
debug information like <command>gdb</command> does.</para> |
| 312 |
|
310 |
|
| 313 |
<para>To configure your kernel to include DDB, add the option line |
311 |
<para>To configure your kernel to include DDB, add the option line |
| 314 |
|
312 |
|
|
Lines 316-327
Link Here
|
| 316 |
|
314 |
|
| 317 |
to your config file, and rebuild. (See <ulink |
315 |
to your config file, and rebuild. (See <ulink |
| 318 |
url="../handbook/index.html">The FreeBSD Handbook</ulink> for details on |
316 |
url="../handbook/index.html">The FreeBSD Handbook</ulink> for details on |
| 319 |
configuring the FreeBSD kernel.</para> |
317 |
configuring the FreeBSD kernel).</para> |
| 320 |
|
318 |
|
| 321 |
<note> |
319 |
<note> |
| 322 |
<para>If you have an older version of the boot blocks, your |
320 |
<para>If you have an older version of the boot blocks, your |
| 323 |
debugger symbols might not be loaded at all. Update the boot blocks; |
321 |
debugger symbols might not be loaded at all. Update the boot blocks; |
| 324 |
the recent ones load the DDB symbols automagically.)</para> |
322 |
the recent ones load the DDB symbols automagically.</para> |
| 325 |
</note> |
323 |
</note> |
| 326 |
|
324 |
|
| 327 |
<para>Once your DDB kernel is running, there are several ways to enter |
325 |
<para>Once your DDB kernel is running, there are several ways to enter |
|
Lines 335-341
Link Here
|
| 335 |
this. If you would like to break to the debugger from the |
333 |
this. If you would like to break to the debugger from the |
| 336 |
command prompt, simply type the command :</para> |
334 |
command prompt, simply type the command :</para> |
| 337 |
|
335 |
|
| 338 |
<screen>&prompt.root; sysctl debug.enter_debugger=ddb</screen> |
336 |
<screen>&prompt.root; <userinput>sysctl debug.enter_debugger=ddb</userinput></screen> |
| 339 |
|
337 |
|
| 340 |
<para>Alternatively, if you are at the system console, you may use |
338 |
<para>Alternatively, if you are at the system console, you may use |
| 341 |
a hot-key on the keyboard. The default break-to-debugger |
339 |
a hot-key on the keyboard. The default break-to-debugger |
|
Lines 347-353
Link Here
|
| 347 |
for serial consoles that allows the use of a serial line BREAK on the |
345 |
for serial consoles that allows the use of a serial line BREAK on the |
| 348 |
console line to enter DDB (<literal>options BREAK_TO_DEBUGGER</literal> |
346 |
console line to enter DDB (<literal>options BREAK_TO_DEBUGGER</literal> |
| 349 |
in the kernel config file). It is not the default since there are a lot |
347 |
in the kernel config file). It is not the default since there are a lot |
| 350 |
of crappy serial adapters around that gratuitously generate a BREAK |
348 |
of serial adapters around that gratuitously generate a BREAK |
| 351 |
condition, for example when pulling the cable.</para> |
349 |
condition, for example when pulling the cable.</para> |
| 352 |
|
350 |
|
| 353 |
<para>The third way is that any panic condition will branch to DDB if the |
351 |
<para>The third way is that any panic condition will branch to DDB if the |
|
Lines 379-385
Link Here
|
| 379 |
<note> |
377 |
<note> |
| 380 |
<para>Note that when entering DDB via a hot-key, the kernel is currently |
378 |
<para>Note that when entering DDB via a hot-key, the kernel is currently |
| 381 |
servicing an interrupt, so the stack trace might be not of much use |
379 |
servicing an interrupt, so the stack trace might be not of much use |
| 382 |
for you.</para> |
380 |
to you.</para> |
| 383 |
</note> |
381 |
</note> |
| 384 |
|
382 |
|
| 385 |
<para>If you want to remove a breakpoint, use</para> |
383 |
<para>If you want to remove a breakpoint, use</para> |
|
Lines 487-493
Link Here
|
| 487 |
|
485 |
|
| 488 |
<screen><userinput>call cpu_reset()</userinput></screen> |
486 |
<screen><userinput>call cpu_reset()</userinput></screen> |
| 489 |
|
487 |
|
| 490 |
<para>is the final way out of disaster and almost the same as hitting the |
488 |
<para>This is the final way out of disaster and almost the same as hitting the |
| 491 |
Big Red Button.</para> |
489 |
Big Red Button.</para> |
| 492 |
|
490 |
|
| 493 |
<para>If you need a short command summary, simply type:</para> |
491 |
<para>If you need a short command summary, simply type:</para> |
|
Lines 517-523
Link Here
|
| 517 |
|
515 |
|
| 518 |
<para>You should configure the kernel in question with <command>config |
516 |
<para>You should configure the kernel in question with <command>config |
| 519 |
-g</command>, include <option>DDB</option> into the configuration, and |
517 |
-g</command>, include <option>DDB</option> into the configuration, and |
| 520 |
compile it as usual. This gives a large blurb of a binary, due to the |
518 |
compile it as usual. This gives a large binary, due to the |
| 521 |
debugging information. Copy this kernel to the target machine, strip |
519 |
debugging information. Copy this kernel to the target machine, strip |
| 522 |
the debugging symbols off with <command>strip -x</command>, and boot it |
520 |
the debugging symbols off with <command>strip -x</command>, and boot it |
| 523 |
using the <option>-d</option> boot option. Connect the serial line |
521 |
using the <option>-d</option> boot option. Connect the serial line |
|
Lines 563-569
Link Here
|
| 563 |
<para>You can use this session almost as any other GDB session, including |
561 |
<para>You can use this session almost as any other GDB session, including |
| 564 |
full access to the source, running it in gud-mode inside an Emacs window |
562 |
full access to the source, running it in gud-mode inside an Emacs window |
| 565 |
(which gives you an automatic source code display in another Emacs |
563 |
(which gives you an automatic source code display in another Emacs |
| 566 |
window) etc.</para> |
564 |
window), etc.</para> |
| 567 |
</sect1> |
565 |
</sect1> |
| 568 |
|
566 |
|
| 569 |
<sect1> |
567 |
<sect1> |
|
Lines 633-639
Link Here
|
| 633 |
the use of a serial console (either with modified boot blocks, or by |
631 |
the use of a serial console (either with modified boot blocks, or by |
| 634 |
specifying <option>-h</option> at the <prompt>Boot:</prompt> prompt), |
632 |
specifying <option>-h</option> at the <prompt>Boot:</prompt> prompt), |
| 635 |
and hook up a standard terminal onto your first serial port. DDB works |
633 |
and hook up a standard terminal onto your first serial port. DDB works |
| 636 |
on any configured console driver, of course also on a serial |
634 |
on any configured console driver, including a serial |
| 637 |
console.</para> |
635 |
console.</para> |
| 638 |
</sect1> |
636 |
</sect1> |
| 639 |
</chapter> |
637 |
</chapter> |