Lines Matching +full:in +full:- +full:kernel

2 Using kgdb, kdb and the kernel debugger internals
10 The kernel has two different debugger front ends (kdb and kgdb) which
13 configure the kernel properly at compile and runtime.
15 Kdb is simplistic shell-style interface which you can use on a system
18 stop in a certain location. Kdb is not a source level debugger, although
19 you can set breakpoints and execute some basic kernel run control. Kdb
20 is mainly aimed at doing some analysis to aid in development or
21 diagnosing kernel problems. You can access some symbols by name in
22 kernel built-ins or in kernel modules if the code was built with
26 kernel. It is used along with gdb to debug a Linux kernel. The
27 expectation is that gdb can be used to "break in" to the kernel to
30 application. It is possible to place breakpoints in kernel code and
34 development machine and the other is the target machine. The kernel to
37 a boot image such as bzImage, zImage, uImage...). In gdb the developer
40 kgdb I/O modules compiled as built-ins or loadable kernel modules in the
41 test machine's kernel.
43 Compiling a kernel
46 - In order to enable compilation of kdb, you must first enable kgdb.
48 - The kgdb test compile options are described in the kgdb test suite
51 Kernel config options for kgdb
52 ------------------------------
55 :menuselection:`Kernel hacking --> Kernel debugging` and select
56 :menuselection:`KGDB: kernel debugger`.
58 While it is not a hard requirement that you have symbols in your vmlinux
61 :menuselection:`Compile the kernel with debug info` in the config menu.
64 ``CONFIG_FRAME_POINTER`` kernel option which is called :menuselection:`Compile
65 the kernel with frame pointers` in the config menu. This option inserts code
66 into the compiled executable which saves the frame information in registers
68 more accurately construct stack back traces while debugging the kernel.
70 If the architecture that you are using supports the kernel option
73 certain regions of the kernel's memory space as read-only. If kgdb
81 the kernel directly. Kgdb I/O driver configuration takes place via
82 kernel or module parameters which you can learn more about in the
92 Kernel config options for kdb
93 -----------------------------
96 of the kernel's debug core. Kdb must implement a shell, and also adds
97 some helper functions in other parts of the kernel, responsible for
99 ``lsmod``, or ``ps``. In order to build kdb into the kernel you follow the
103 :menuselection:`KGDB_KDB: include kdb frontend for kgdb` in the config menu.
104 In theory you would have already also selected an I/O driver such as the
108 If you want to use a PS/2-style keyboard with kdb, you would select
110 input device` in the config menu. The ``CONFIG_KDB_KEYBOARD`` option is not
111 used for anything in the gdb interface to kgdb. The ``CONFIG_KDB_KEYBOARD``
123 Kernel Debugger Boot Arguments
126 This section describes the various runtime kernel parameters that affect
127 the configuration of the kernel debugger. The following chapter covers
131 Kernel parameter: kgdboc
132 ------------------------
141 console as your primary console as well as using it to perform kernel
143 designated as a system console. Kgdboc may be configured as a kernel
144 built-in or a kernel loadable module. You can only make use of
145 ``kgdbwait`` and early debugging if you build kgdboc into the kernel as
146 a built-in.
148 Optionally you can elect to activate kms (Kernel Mode Setting)
151 on the graphics console. When the kernel execution is resumed, the
153 useful tool to aid in diagnosing crashes or doing analysis of memory
168 - kms = Kernel Mode Setting
170 - kbd = Keyboard
173 depending on if you are using kdb and/or kgdb, in one of the following
178 Using loadable module or built-in
181 1. As a kernel built-in:
183 Use the kernel boot argument::
185 kgdboc=<tty-device>,[baud]
187 2. As a kernel loadable module:
191 modprobe kgdboc kgdboc=<tty-device>,[baud]
224 depending on if you are using kdb and/or kgdb, in one of the following
247 4. kdb with kernel mode setting::
251 5. kdb with kernel mode setting and kgdb over a serial port::
258 protocol. You must manually send a `SysRq-G` unless you have a proxy
261 "human" console. The proxy can take care of sending the `SysRq-G`
267 waiting for the debugger. In this case you disconnect your terminal
268 program and then connect the debugger in its place. If you want to
272 don't like this are to hack gdb to send the `SysRq-G` for you as well as
276 Kernel parameter: ``kgdboc_earlycon``
277 -------------------------------------
279 If you specify the kernel parameter ``kgdboc_earlycon`` and your serial
300 Kernel parameter: ``kgdbwait``
301 ------------------------------
303 The Kernel command line option ``kgdbwait`` makes kgdb wait for a
304 debugger connection during booting of a kernel. You can only use this
305 option if you compiled a kgdb I/O driver into the kernel and you
306 specified the I/O driver configuration as a kernel command line option.
308 for the kgdb I/O driver in the kernel command line else the I/O driver
309 will not be configured prior to asking the kernel to use it to wait.
311 The kernel will stop and wait as early as the I/O driver and
313 driver as a loadable kernel module kgdbwait will not do anything.
315 Kernel parameter: ``kgdbcon``
316 -----------------------------
319 while gdb is connected to the kernel. Kdb does not make use of the kgdbcon
326 1. Activate with the kernel command line option::
351 ----------------------------------
359 .. flat-table::
362 * - 1
363 - ``echo -1 > /sys/module/debug_core/parameters/kgdbreboot``
364 - Ignore the reboot notification entirely.
366 * - 2
367 - ``echo 0 > /sys/module/debug_core/parameters/kgdbreboot``
368 - Send the detach message to any attached debugger client.
370 * - 3
371 - ``echo 1 > /sys/module/debug_core/parameters/kgdbreboot``
372 - Enter the debugger on reboot notify.
374 Kernel parameter: ``nokaslr``
375 -----------------------------
379 virtual address where the kernel image is mapped and confuses
380 gdb which resolves addresses of kernel symbols from the symbol table
383 Kernel parameter: ``rodata``
384 ----------------------------
388 you can pass ``rodata=off`` to the kernel in this case.
394 ------------------------------------
398 1. Configure kgdboc at boot using kernel parameters::
404 Configure kgdboc after the kernel has booted; assuming you are using
409 2. Enter the kernel debugger manually or by waiting for an oops or
410 fault. There are several ways you can enter the kernel debugger
411 manually; all involve using the `SysRq-G`, which means you must have
412 enabled ``CONFIG_MAGIC_SYSRQ=y`` in your kernel config.
414 - When logged in as root or with a super user session you can run::
416 echo g > /proc/sysrq-trigger
418 - Example using minicom 2.2
420 Press: `CTRL-A` `f` `g`
422 - When you have telneted to a terminal server that supports sending
425 Press: `CTRL-]`
427 Type in: ``send break``
434 Some useful commands in kdb include:
437 ``lsmod`` Shows where kernel modules are loaded
440 ``summary`` Shows kernel version info and memory usage
442 ``dmesg`` View the kernel syslog buffer
447 or using the ``go`` command to resuming normal kernel execution. If you
448 have paused the kernel for a lengthy period of time, applications
451 consideration when using the kernel debugger.
454 ------------------------------------------------------
458 1. Configure kgdboc at boot using kernel parameters::
464 Configure kgdboc after the kernel has booted::
468 2. Enter the kernel debugger manually or by waiting for an oops or
469 fault. There are several ways you can enter the kernel debugger
470 manually; all involve using the `SysRq-G`, which means you must have
471 enabled ``CONFIG_MAGIC_SYSRQ=y`` in your kernel config.
473 - When logged in as root or with a super user session you can run::
475 echo g > /proc/sysrq-trigger
477 - Example using a laptop keyboard:
491 - Example using a PS/2 101-key keyboard
501 3. Now type in a kdb command such as ``help``, ``dmesg``, ``bt`` or ``go`` to
502 continue kernel execution.
507 In order to use kgdb you must activate it by passing configuration
510 only actively hook up to the kernel trap hooks if a kgdb I/O driver is
512 unregister all the kernel hook points.
523 ------------------------------------
527 Configure kgdboc at boot using kernel parameters::
533 Configure kgdboc after the kernel has booted::
537 2. Stop kernel execution (break into the debugger)
539 In order to connect to gdb via kgdboc, the kernel must first be
540 stopped. There are several ways to stop the kernel which include
541 using kgdbwait as a boot argument, via a `SysRq-G`, or running the
542 kernel until it takes an exception where it waits for the debugger to
545 - When logged in as root or with a super user session you can run::
547 echo g > /proc/sysrq-trigger
549 - Example using minicom 2.2
551 Press: `CTRL-A` `f` `g`
553 - When you have telneted to a terminal server that supports sending
556 Press: `CTRL-]`
558 Type in: ``send break``
577 Once connected, you can debug a kernel the way you would debug an
583 this prior to issuing the ``target remote`` command by typing in::
587 Remember if you continue in gdb, and need to "break in" again, you need
588 to issue an other `SysRq-G`. It is easy to create a simple entry point by
597 in the same mode.
600 ------------------------------
607 Whenever the kernel debugger stops in kgdb mode it will print the
609 to type the sequence correctly in one pass. You cannot type a backspace
622 Now you must kill gdb. Typically you press `CTRL-Z` and issue
625 kill -9 %
641 2. At the kdb prompt, disconnect the terminal program and connect gdb in
645 -----------------------------
649 breakpoint operations, because it can disrupt the state of the kernel
672 When kgdb is enabled in the kernel config you can also elect to enable
679 Linux kernel. The primary source of documentation would be to look in
683 core set of tests by setting the kernel config parameter
685 regression testing and does not require modifying the kernel boot config
687 specifying ``kgdbts=`` as a kernel boot argument.
689 Kernel Debugger Internals
693 ----------------------
695 The kernel debugger is organized into a number of components:
699 The debug core is found in ``kernel/debug/debug_core.c``. It
702 - A generic OS exception handler which includes sync'ing the
703 processors into a stopped state on an multi-CPU system.
705 - The API to talk to the kgdb I/O drivers
707 - The API to make calls to the arch-specific kgdb implementation
709 - The logic to perform safe memory reads and writes to memory while
712 - A full implementation for software breakpoints unless overridden
715 - The API to invoke either the kdb or kgdb frontend to the debug
718 - The structures and callback API for atomic kernel mode setting.
722 2. kgdb arch-specific implementation
724 This implementation is generally found in ``arch/*/kernel/kgdb.c``. As
725 an example, ``arch/x86/kernel/kgdb.c`` contains the specifics to
728 The arch-specific portion implements:
730 - contains an arch-specific trap catcher which invokes
733 - translation to and from gdb specific packet format to struct pt_regs
735 - Registration and unregistration of architecture specific trap
738 - Any special exception handling and cleanup
740 - NMI exception handling and cleanup
742 - (optional) HW breakpoints
746 The gdbstub is located in ``kernel/debug/gdbstub.c``. It contains:
748 - All the logic to implement the gdb serial protocol
753 The kdb core is located in kernel/debug/kdb. There are a number of
754 helper functions in some of the other kernel components to make it
755 possible for kdb to examine and report information about the kernel
756 without taking locks that could cause a kernel deadlock. The kdb core
759 - A simple shell
761 - The kdb core command set
763 - A registration API to register additional kdb shell commands.
765 - A good example of a self-contained kdb module is the ``ftdump``
767 ``kernel/trace/trace_kdb.c``
769 - For an example of how to dynamically register a new kdb command
770 you can build the kdb_hello.ko kernel module from
772 ``CONFIG_SAMPLES=y`` and ``CONFIG_SAMPLE_KDB=m`` in your kernel
776 - The implementation for kdb_printf() which emits messages directly
777 to I/O drivers, bypassing the kernel log.
779 - SW / HW breakpoint management for the kdb shell
786 - configuration via built-in or module
788 - dynamic configuration and kgdb hook registration calls
790 - read and write character interface
792 - A cleanup handler for unconfiguring from the kgdb core
794 - (optional) Early debug methodology
797 hardware and must do it in such a way that does not enable interrupts
802 for the future possibility to touch watchdog hardware in such a way
806 architecture, the architecture should define ``HAVE_ARCH_KGDB`` in the
811 There are a few flags which must be set on every architecture in their
814 - ``NUMREGBYTES``:
815 The size in bytes of all of the registers, so that we
818 - ``BUFMAX``:
819 The size in bytes of the buffer GDB will read into. This must
822 - ``CACHE_FLUSH_IS_SAFE``:
826 CPUs in a holding pattern.
828 There are also the following functions for the common backend, found in
829 ``kernel/kgdb.c``, that must be supplied by the architecture-specific
830 backend unless marked as (optional), in which case a default function
834 .. kernel-doc:: include/linux/kgdb.h
838 ----------------
845 which the tty driver is attached. In the initial implementation of
847 doing polled mode reading and writing of a single character while in an
849 invokes a callback in the serial core which in turn uses the callback in
853 callbacks in the struct uart_ops.
864 ``#ifdef CONFIG_CONSOLE_POLL``, as shown above. Keep in mind that
865 polling hooks have to be implemented in such a way that they can be
877 kernel when ``CONFIG_KDB_KEYBOARD=y`` is set in the kernel configuration.
879 The core polled keyboard driver for PS/2 type keyboards is in
880 ``kernel/debug/kdb/kdb_keyboard.c``. This driver is hooked into the debug core
881 when kgdboc populates the callback in the array called
882 :c:expr:`kdb_poll_funcs[]`. The kdb_get_kbd_char() is the top-level
891 kernel mode setting support.
893 Every time the kernel debugger is entered it calls
894 kgdboc_pre_exp_handler() which in turn calls con_debug_enter()
895 in the virtual console layer. On resuming kernel execution, the kernel
896 debugger calls kgdboc_post_exp_handler() which in turn calls
908 2. Tom Rini <trini@kernel.crashing.org>
910 In March 2008 this document was completely rewritten by:
912 - Jason Wessel <jason.wessel@windriver.com>
914 In Jan 2010 this document was updated to include kdb.
916 - Jason Wessel <jason.wessel@windriver.com>