Added patch headers.
[linux-flexiantxendom0-3.2.10.git] / Documentation / kdb / kdb.mm
1 .TH KDB 8 "September 21, 2005"
2 .hy 0
3 .SH NAME
4 Built-in Kernel Debugger for Linux - v4.4
5 .SH "Overview"
6 This document describes the built-in kernel debugger available
7 for linux.   This debugger allows the programmer to interactively
8 examine kernel memory, disassemble kernel functions, set breakpoints
9 in the kernel code and display and modify register contents.
10 .P
11 A symbol table is included in the kernel image and in modules which
12 enables all non-stack symbols (including static symbols) to be used as
13 arguments to the kernel debugger commands.
14 .SH "Getting Started"
15 To include the kernel debugger in a linux kernel, use a
16 configuration mechanism (e.g. xconfig, menuconfig, et. al.)
17 to enable the \fBCONFIG_KDB\fP option.   Additionally, for accurate
18 stack tracebacks, it is recommended that the \fBCONFIG_FRAME_POINTER\fP
19 option be enabled (if present).   \fBCONFIG_FRAME_POINTER\fP changes the compiler
20 flags so that the frame pointer register will be used as a frame
21 pointer rather than a general purpose register.
22 .P
23 After linux has been configured to include the kernel debugger,
24 make a new kernel with the new configuration file (a make clean
25 is recommended before making the kernel), and install the kernel
26 as normal.
27 .P
28 You can compile a kernel with kdb support but have kdb off by default,
29 select \fBCONFIG_KDB_OFF\fR.  Then the user has to explicitly activate
30 kdb by booting with the 'kdb=on' flag or, after /proc is mounted, by
31 .nf
32   echo "1" > /proc/sys/kernel/kdb
33 .fi
34 You can also do the reverse, compile a kernel with kdb on and
35 deactivate kdb with the boot flag 'kdb=off' or, after /proc is mounted,
36 by
37 .nf
38   echo "0" > /proc/sys/kernel/kdb
39 .fi
40 .P
41 When booting the new kernel, the 'kdb=early' flag
42 may be added after the image name on the boot line to
43 force the kernel to stop in the kernel debugger early in the
44 kernel initialization process.  'kdb=early' implies 'kdb=on'.
45 If the 'kdb=early' flag isn't provided, then kdb will automatically be
46 invoked upon system panic or when the \fBPAUSE\fP key is used from the
47 keyboard, assuming that kdb is on.  Older versions of kdb used just a
48 boot flag of 'kdb' to activate kdb early, this is no longer supported.
49 .P
50 KDB can also be used via the serial port.  Set up the system to
51 have a serial console (see \fIDocumentation/serial-console.txt\fP), you
52 must also have a user space program such as agetty set up to read from
53 the serial console.
54 The control sequence \fB<esc>KDB\fP on the serial port will cause the
55 kernel debugger to be entered, assuming that kdb is on, that some
56 program is reading from the serial console, at least one cpu is
57 accepting interrupts and the serial console driver is still usable.
58 .P
59 \fBNote:\fR\ When the serial console sequence consists of multiple
60 characters such as <esc>KDB then all but the last character are passed
61 through to the application that is reading from the serial console.
62 After exiting from kdb, you should use backspace to delete the rest of
63 the control sequence.
64 .P
65 You can boot with kdb activated but without the ability to enter kdb
66 via any keyboard sequence.
67 In this mode, kdb will only be entered after a system failure.
68 Booting with kdb=on-nokey will activate kdb but ignore keyboard
69 sequences that would normally drop you into kdb.
70 kdb=on-nokey is mainly useful when you are using a PC keyboard and your
71 application needs to use the Pause key.
72 You can also activate this mode by
73 .nf
74   echo "2" > /proc/sys/kernel/kdb
75 .fi
76 .P
77 If the console is sitting on the login prompt when you enter kdb, then
78 the login command may switch into upper case mode.
79 This is not a kdb bug, it is a "feature" of login - if the userid is
80 all upper case then login assumes that you using a TeleType (circa
81 1960) which does not have lower case characters.
82 Wait 60 seconds for login to timeout and it will switch back to lower
83 case mode.
84 .P
85 \fBNote:\fR\ Your distributor may have chosen a different kdb
86 activation sequence for the serial console.
87 Consult your distribution documentation.
88 .P
89 If you have both a keyboard+video and a serial console, you can use
90 either for kdb.
91 Define both video and serial consoles with boot parameters
92 .P
93 .nf
94   console=tty0 console=ttyS0,38400
95 .fi
96 .P
97 Any kdb data entered on the keyboard or the serial console will be echoed
98 to both.
99 .P
100 If you are using a USB keyboard then kdb commands cannot be entered
101 until the kernel has initialised the USB subsystem and recognised the
102 keyboard.
103 Using kdb=early with a USB keyboard will not work, the USB subsystem is
104 initialised too late.
105 .P
106 While kdb is active, the keyboard (not serial console) indicators may strobe.
107 The caps lock and scroll lock lights will turn on and off, num lock is not used
108 because it can confuse laptop keyboards where the numeric keypad is mapped over
109 the normal keys.
110 On exit from kdb the keyboard indicators will probably be wrong, they will not match the kernel state.
111 Pressing caps lock twice should get the indicators back in sync with
112 the kernel.
113 .SH "Basic Commands"
114 There are several categories of commands available to the
115 kernel debugger user including commands providing memory
116 display and modification, register display and modification,
117 instruction disassemble, breakpoints and stack tracebacks.
118 Any command can be prefixed with '-' which will cause kdb to ignore any
119 errors on that command, this is useful when packaging commands using
120 defcmd.
121 A line whose first non-space character is '#' is printed and ignored.
122 .P
123 The following table shows the currently implemented standard commands,
124 these are always available.  Other commands can be added by extra
125 debugging modules, type '?' at the kdb prompt to get a list of all
126 available commands.
127 .DS
128 .TS
129 box, center;
130 l | l
131 l | l.
132 Command Description
133 _
134 bc      Clear Breakpoint
135 bd      Disable Breakpoint
136 be      Enable Breakpoint
137 bl      Display breakpoints
138 bp      Set or Display breakpoint
139 bph     Set or Display hardware breakpoint
140 bpa     Set or Display breakpoint globally
141 bpha    Set or Display hardware breakpoint globally
142 bt      Stack backtrace for current process
143 btp     Stack backtrace for specific process
144 bta     Stack backtrace for all processes
145 btc     Cycle over all live cpus and backtrace each one
146 cpu     Display or switch cpus
147 dmesg   Display system messages
148 defcmd  Define a command as a set of other commands
149 ef      Print exception frame
150 env     Show environment
151 go      Restart execution
152 handlers        Control the display of IA64 MCA/INIT handlers
153 help    Display help message
154 id      Disassemble Instructions
155 kill    Send a signal to a process
156 ll      Follow Linked Lists
157 lsmod   List loaded modules
158 md      Display memory contents
159 mdWcN   Display memory contents with width W and count N.
160 mdp     Display memory based on a physical address
161 mdr     Display raw memory contents
162 mds     Display memory contents symbolically
163 mm      Modify memory contents, words
164 mmW     Modify memory contents, bytes
165 per_cpu Display per_cpu variables
166 pid     Change the default process context
167 ps      Display process status
168 reboot  Reboot the machine
169 rd      Display register contents
170 rm      Modify register contents
171 rq      Display runqueue for one cpu
172 rqa     Display runqueue for all cpus
173 set     Add/change environment variable
174 sr      Invoke SysReq commands
175 ss      Single step a cpu
176 ssb     Single step a cpu until a branch instruction
177 stackdepth      Print the stack depth for selected processes
178 summary Summarize the system
179 .TE
180 .DE
181 .P
182 Some commands can be abbreviated, such commands are indicated by a
183 non-zero \fIminlen\fP parameter to \fBkdb_register\fP; the value of
184 \fIminlen\fP being the minimum length to which the command can be
185 abbreviated (for example, the \fBgo\fP command can be abbreviated
186 legally to \fBg\fP).
187 .P
188 If an input string does not match a command in the command table,
189 it is treated as an address expression and the corresponding address
190 value and nearest symbol are shown.
191 .P
192 Some of the commands are described here.
193 Information on the more complicated commands can be found in the
194 appropriate manual pages.
195 .TP 8
196 cpu
197 With no parameters, it lists the available cpus.
198 \&'*' after a cpu number indicates a cpu that did not respond to the kdb
199 stop signal.
200 \&'+' after a cpu number indicates a cpu for which kdb has some data, but
201 that cpu is no longer responding to kdb, so you cannot switch to it.
202 This could be a cpu that has failed after entering kdb, or the cpu may
203 have saved its state for debugging then entered the prom, this is
204 normal for an IA64 MCA event.
205 \&'I' after a cpu number means that the cpu was idle before it entered
206 kdb, it is unlikely to contain any useful data.
207 \&'F' after a cpu number means that the cpu is offline.
208 There is currenly no way to distinguish between cpus that used to be
209 online but are now offline and cpus that were never online, the kernel
210 does not maintain the information required to separate those two cases.
211 .I cpu
212 followed by a number will switch to that cpu, you cannot switch to
213 a cpu marked '*', '+' or 'F'.
214 This command is only available if the kernel was configured for SMP.
215 .TP 8
216 dmesg [lines] [adjust]
217 Displays the system messages from the kernel buffer.
218 If kdb logging is on, it is disabled by dmesg and is left as disabled.
219 With no parameters or a zero value for 'lines', dmesg dumps the entire
220 kernel buffer.
221 If lines is specified and is positive, dmesg dumps the last 'lines'
222 from the buffer.
223 If lines is specified and is negative, dmesg dumps the first 'lines'
224 from the buffer.
225 If adjust is specified, adjust the starting point for the lines that
226 are printed.
227 When 'lines' is positive, move the starting point back by 'adjust'
228 lines, when 'lines' is negative, move the starting point forward by
229 \&'adjust' lines.
230 .I dmesg -100
231 will dump 100 lines, from the start of the buffer.
232 .I dmesg 100
233 will dump 100 lines, starting 100 lines from the end of the buffer,
234 .I dmesg 100 100
235 will dump 100 lines, starting 200 lines from the end of the buffer.
236 .I dmesg -100 100
237 will dump 100 lines, starting 100 lines from the start of the buffer.
238 .TP 8
239 defcmd
240 Defines a new command as a set of other commands, all input until
241 .I endefcmd
242 is saved and executed as a package.
243 .I defcmd
244 takes three parameters, the command name to be defined and used to
245 invoke the package, a quoted string containing the usage text and a
246 quoted string containing the help text for the command.
247 When using defcmd, it is a good idea to prefix commands that might fail
248 with '-', this ignores errors so the following commands are still
249 executed.
250 For example,
251 .P
252 .nf
253         defcmd diag "" "Standard diagnostics"
254           set LINES 2000
255           set BTAPROMPT 0
256           -id %eip-0x40
257           -cpu
258           -ps
259           -dmesg 80
260           -bt
261           -bta
262         endefcmd
263 .fi
264 .P
265 When used with no parameters, defcmd prints all the defined commands.
266 .TP 8
267 go
268 Continue normal execution.
269 Active breakpoints are reestablished and the processor(s) allowed to
270 run normally.
271 To continue at a specific address, use
272 .I rm
273 to change the instruction pointer then go.
274 .TP 8
275 handlers
276 Control the display of IA64 MCA/INIT handlers.
277 The IA64 MCA/INIT handlers run on separate tasks.
278 During an MCA/INIT event, the active tasks are typically the handlers,
279 rather than the original tasks, which is not very useful for debugging.
280 By default, KDB hides the MCA/INIT handlers so commands such as ps and
281 btc will display the original task.
282 You can change this behaviour by using
283 .I handlers show
284 to display the MCA/INIT handlers instead of the original tasks or use
285 .I handlers hide
286 (the default) to hide the MCA/INIT handlers and display the original
287 tasks.
288 .I handlers status
289 will list the address of the handler task and the original task for
290 each cpu.
291 \fBNote:\fR\ If the original task was running in user space or it
292 failed any of the MCA/INIT verification tests then there is no original
293 task to display.
294 In this case, the handler will be displayed even if
295 .I handlers hide
296 is set and
297 .I handlers status
298 will not show an original task.
299 .TP 8
300 id
301 Disassemble instructions starting at an address.
302 Environment variable IDCOUNT controls how many lines of disassembly
303 output the command produces.
304 .TP 8
305 kill
306 Internal command to send a signal (like kill(1)) to a process.
307 kill -signal pid.
308 .TP 8
309 lsmod
310 Internal command to list modules.
311 This does not use any kernel nor user space services so can be used at any time.
312 .TP 8
313 per_cpu <variable_name> [<length>] [<cpu>]
314 Display the values of a per_cpu variable, the variable_name is
315 specified without the \fIper_cpu__\fR prefix.
316 Length is the length of the variable, 1-8, if omitted or 0 it defaults
317 to the size of the machine's register.
318 To display the variable on a specific cpu, the third parameter is the
319 cpu number.
320 When the third parameter is omitted, the variable's value is printed
321 from all cpus, except that zero values are suppressed.
322 For each cpu, per_cpu prints the cpu number, the address of the
323 variable and its value.
324 .TP 8
325 pid <number>
326 Change the current process context, with no parameters it displays the
327 current process.
328 The current process is used to display registers, both kernel and user
329 space.
330 It is also used when dumping user pages.
331 .I pid R
332 resets to the original process that was running when kdb was entered.
333 This command is useful if you have been looking at other processes and/or
334 cpus and you want to get back to the original process.
335 It does not switch cpus, it only resets the context to the original process.
336 .TP 8
337 reboot
338 Reboot the system, with no attempt to do a clean close down.
339 .TP 8
340 rq <cpu>
341 Display the runqueues for the specified cpu.
342 .TP 8
343 rqa
344 Display the runqueues for all cpus.
345 .TP 8
346 stackdepth <percentage>
347 Print the stack usage for processes using more than the specified
348 percentage of their stack.
349 If percentage is not supplied, it defaults to 60.
350 This command is only implemented on i386 and ia64 architectures,
351 patches for other architectures will be gratefully accepted.
352 .TP 8
353 summary
354 Print a summary of the system, including the time (no timezone is
355 applied), uname information and various critical system counters.
356 .SH INITIAL KDB COMMANDS
357 kdb/kdb_cmds is a plain text file where you can define kdb commands
358 which are to be issued during kdb_init().  One command per line, blank
359 lines are ignored, lines starting with '#' are ignored.  kdb_cmds is
360 intended for per user customization of kdb, you can use it to set
361 environment variables to suit your hardware or to set standard
362 breakpoints for the problem you are debugging.  This file is converted
363 to a small C object, compiled and linked into the kernel.  You must
364 rebuild and reinstall the kernel after changing kdb_cmds.  This file
365 will never be shipped with any useful data so you can always override
366 it with your local copy.  Sample kdb_cmds:
367 .P
368 .nf
369 # Initial commands for kdb, alter to suit your needs.
370 # These commands are executed in kdb_init() context, no SMP, no
371 # processes.  Commands that require process data (including stack or
372 # registers) are not reliable this early.  set and bp commands should
373 # be safe.  Global breakpoint commands affect each cpu as it is booted.
374
375 set LINES=50
376 set MDCOUNT=25
377 set RECURSE=1
378 bp sys_init_module
379 .fi
380 .SH INTERRUPTS AND KDB
381 When a kdb event occurs, one cpu (the initial cpu) enters kdb state.
382 It uses a cross system interrupt to interrupt the
383 other cpus and bring them all into kdb state.  All cpus run with
384 interrupts disabled while they are inside kdb, this prevents most
385 external events from disturbing the kernel while kdb is running.
386 .B Note:
387 Disabled interrupts means that any I/O that relies on interrupts cannot
388 proceed while kdb is in control, devices can time out.  The clock tick
389 is also disabled, machines will lose track of time while they are
390 inside kdb.
391 .P
392 Even with interrupts disabled, some non-maskable interrupt events will
393 still occur, these can disturb the kernel while you are debugging it.
394 The initial cpu will still accept NMI events, assuming that kdb was not
395 entered for an NMI event.  Any cpu where you use the SS or SSB commands
396 will accept NMI events, even after the instruction has finished and the
397 cpu is back in kdb.  This is an unavoidable side effect of the fact that
398 doing SS[B] requires the cpu to drop all the way out of kdb, including
399 exiting from the event that brought the cpu into kdb.  Under normal
400 circumstances the only NMI event is for the NMI oopser and that is kdb
401 aware so it does not disturb the kernel while kdb is running.
402 .P
403 Sometimes doing SS or SSB on ix86 will allow one interrupt to proceed,
404 even though the cpu is disabled for interrupts.  I have not been able
405 to track this one down but I suspect that the interrupt was pending
406 when kdb was entered and it runs when kdb exits through IRET even
407 though the popped flags are marked as cli().  If any ix86 hardware
408 expert can shed some light on this problem, please notify the kdb
409 maintainer.
410 .SH RECOVERING FROM KDB ERRORS
411 If a kdb command breaks and kdb has enough of a recovery environment
412 then kdb will abort the command and drop back into mainline kdb code.
413 This means that user written kdb commands can follow bad pointers
414 without killing kdb.  Ideally all code should verify that data areas
415 are valid (using kdb_getarea) before accessing it but lots of calls to
416 kdb_getarea can be clumsy.
417 .P
418 The sparc64 port does not currently provide this error recovery.
419 If someone would volunteer to write the necessary longjmp/setjmp
420 code, their efforts would be greatly appreciated. In the
421 meantime, it is possible for kdb to trigger a panic by accessing
422 a bad address.
423 .SH DEBUGGING THE DEBUGGER
424 kdb has limited support for debugging problems within kdb.  If you
425 suspect that kdb is failing, you can set environment variable KDBDEBUG
426 to a bit pattern which will activate kdb_printf statements within kdb.
427 See include/linux/kdb.h, KDB_DEBUG_FLAG_xxx defines.  For example
428 .nf
429   set KDBDEBUG=0x60
430 .fi
431 activates the event callbacks into kdb plus state tracing in sections
432 of kdb.
433 .nf
434   set KDBDEBUG=0x18
435 .fi
436 gives lots of tracing as kdb tries to decode the process stack.
437 .P
438 You can also perform one level of recursion in kdb.  If environment
439 variable RECURSE is not set or is 0 then kdb will either recover from
440 an error (if the recovery environment is satisfactory) or kdb will
441 allow the error to percolate, usually resulting in a dead system.  When
442 RECURSE is 1 then kdb will recover from an error or, if there is no
443 satisfactory recovery environment, it will drop into kdb state to let
444 you diagnose the problem.  When RECURSE is 2 then all errors drop into
445 kdb state, kdb does not attempt recovery first.  Errors while in
446 recursive state all drop through, kdb does not even attempt to recover
447 from recursive errors.
448 .SH KEYBOARD EDITING
449 kdb supports a command history, which can be accessed via keyboard
450 sequences.
451 It supports the special keys on PC keyboards, control characters and
452 vt100 sequences on a serial console or a PC keyboard.
453 .P
454 .DS
455 .TS
456 box, center;
457 l | l | l l | l
458 l | l | l l | l.
459 PC Special keys Control VT100 key       Codes   Action
460 _
461 Backspace       ctrl-H  Backspace       0x7f    Delete character to the left of the cursor
462 Delete  ctrl-D  Delete  \\e[3~  Delete character to the right of the cursor
463 Home    ctrl-A  Home    \\e[1~  Go to start of line
464 End     ctrl-E  End     \\e[4~  Go to end of line
465 Up arrow        ctrl-P  Up arrow        \\e[A   Up one command in history
466 Down arrow      ctrl-N  Down arrow      \\e[B   Down one command in history
467 Left arrow      ctrl-B  Left arrow      \\e[D   Left one character in current command
468 Right arrow     ctrl-F  Right arrow     \\e[C   Right one character in current command
469 .TE
470 .DE
471 .P
472 There is no toggle for insert/replace mode, kdb editing is always in
473 insert mode.
474 Use delete and backspace to delete characters.
475 .P
476 kdb also supports tab completion for kernel symbols
477 Type the start of a kernel symbol and press tab (ctrl-I) to complete
478 the name
479 If there is more than one possible match, kdb will append any common
480 characters and wait for more input, pressing tab a second time will
481 display the possible matches
482 The number of matches is limited by environment variable DTABCOUNT,
483 with a default of 30 if that variable is not set.
484 .SH AUTHORS
485 Scott Lurndal, Richard Bass, Scott Foehner, Srinivasa Thirumalachar,
486 Masahiro Adegawa, Marc Esipovich, Ted Kline, Steve Lord, Andi Kleen,
487 Sonic Zhang.
488 .br
489 Keith Owens <kaos@sgi.com> - kdb maintainer.
490 .SH SEE ALSO
491 .P
492 linux/Documentation/kdb/kdb_{bp,bt,env,ll,md,ps,rd,sr,ss}.man