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 to into the compiled executable which saves the frame information in
69 debugging the kernel.
71 If the architecture that you are using supports the kernel option
74 certain regions of the kernel's memory space as read-only. If kgdb
82 the kernel directly. Kgdb I/O driver configuration takes place via
83 kernel or module parameters which you can learn more about in the in the
93 Kernel config options for kdb
94 -----------------------------
97 of the kernel's debug core. Kdb must implement a shell, and also adds
98 some helper functions in other parts of the kernel, responsible for
100 ``lsmod``, or ``ps``. In order to build kdb into the kernel you follow the
104 :menuselection:`KGDB_KDB: include kdb frontend for kgdb` in the config menu.
105 In theory you would have already also selected an I/O driver such as the
109 If you want to use a PS/2-style keyboard with kdb, you would select
111 input device` in the config menu. The ``CONFIG_KDB_KEYBOARD`` option is not
112 used for anything in the gdb interface to kgdb. The ``CONFIG_KDB_KEYBOARD``
124 Kernel Debugger Boot Arguments
127 This section describes the various runtime kernel parameters that affect
128 the configuration of the kernel debugger. The following chapter covers
132 Kernel parameter: kgdboc
133 ------------------------
142 console as your primary console as well as using it to perform kernel
144 designated as a system console. Kgdboc may be configured as a kernel
145 built-in or a kernel loadable module. You can only make use of
146 ``kgdbwait`` and early debugging if you build kgdboc into the kernel as
147 a built-in.
149 Optionally you can elect to activate kms (Kernel Mode Setting)
152 on the graphics console. When the kernel execution is resumed, the
154 useful tool to aid in diagnosing crashes or doing analysis of memory
169 - kms = Kernel Mode Setting
171 - kbd = Keyboard
174 depending on if you are using kdb and/or kgdb, in one of the following
179 Using loadable module or built-in
182 1. As a kernel built-in:
184 Use the kernel boot argument::
186 kgdboc=<tty-device>,[baud]
188 2. As a kernel loadable module:
192 modprobe kgdboc kgdboc=<tty-device>,[baud]
225 depending on if you are using kdb and/or kgdb, in one of the following
248 4. kdb with kernel mode setting::
252 5. kdb with kernel mode setting and kgdb over a serial port::
259 protocol. You must manually send a :kbd:`SysRq-G` unless you have a proxy
262 "human" console. The proxy can take care of sending the :kbd:`SysRq-G`
268 waiting for the debugger. In this case you disconnect your terminal
269 program and then connect the debugger in its place. If you want to
273 don't like this are to hack gdb to send the :kbd:`SysRq-G` for you as well as
277 Kernel parameter: ``kgdbwait``
278 ------------------------------
280 The Kernel command line option ``kgdbwait`` makes kgdb wait for a
281 debugger connection during booting of a kernel. You can only use this
282 option if you compiled a kgdb I/O driver into the kernel and you
283 specified the I/O driver configuration as a kernel command line option.
285 for the kgdb I/O driver in the kernel command line else the I/O driver
286 will not be configured prior to asking the kernel to use it to wait.
288 The kernel will stop and wait as early as the I/O driver and
290 driver as a loadable kernel module kgdbwait will not do anything.
292 Kernel parameter: ``kgdbcon``
293 -----------------------------
296 while gdb is connected to the kernel. Kdb does not make use of the kgdbcon
303 1. Activate with the kernel command line option::
328 ----------------------------------
336 .. flat-table::
339 * - 1
340 - ``echo -1 > /sys/module/debug_core/parameters/kgdbreboot``
341 - Ignore the reboot notification entirely.
343 * - 2
344 - ``echo 0 > /sys/module/debug_core/parameters/kgdbreboot``
345 - Send the detach message to any attached debugger client.
347 * - 3
348 - ``echo 1 > /sys/module/debug_core/parameters/kgdbreboot``
349 - Enter the debugger on reboot notify.
351 Kernel parameter: ``nokaslr``
352 -----------------------------
356 virtual address where the kernel image is mapped and confuse
357 gdb which resolve kernel symbol address from symbol table
364 ------------------------------------
368 1. Configure kgdboc at boot using kernel parameters::
374 Configure kgdboc after the kernel has booted; assuming you are using
379 2. Enter the kernel debugger manually or by waiting for an oops or
380 fault. There are several ways you can enter the kernel debugger
381 manually; all involve using the :kbd:`SysRq-G`, which means you must have
382 enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config.
384 - When logged in as root or with a super user session you can run::
386 echo g > /proc/sysrq-trigger
388 - Example using minicom 2.2
390 Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g`
392 - When you have telneted to a terminal server that supports sending
395 Press: :kbd:`CTRL-]`
397 Type in: ``send break``
404 Some useful commands in kdb include:
407 ``lsmod`` Shows where kernel modules are loaded
410 ``summary`` Shows kernel version info and memory usage
412 ``dmesg`` View the kernel syslog buffer
417 or using the ``go`` command to resuming normal kernel execution. If you
418 have paused the kernel for a lengthy period of time, applications
421 consideration when using the kernel debugger.
424 ------------------------------------------------------
428 1. Configure kgdboc at boot using kernel parameters::
434 Configure kgdboc after the kernel has booted::
438 2. Enter the kernel debugger manually or by waiting for an oops or
439 fault. There are several ways you can enter the kernel debugger
440 manually; all involve using the :kbd:`SysRq-G`, which means you must have
441 enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config.
443 - When logged in as root or with a super user session you can run::
445 echo g > /proc/sysrq-trigger
447 - Example using a laptop keyboard:
461 - Example using a PS/2 101-key keyboard
471 3. Now type in a kdb command such as ``help``, ``dmesg``, ``bt`` or ``go`` to
472 continue kernel execution.
477 In order to use kgdb you must activate it by passing configuration
480 only actively hook up to the kernel trap hooks if a kgdb I/O driver is
482 unregister all the kernel hook points.
493 ------------------------------------
497 Configure kgdboc at boot using kernel parameters::
503 Configure kgdboc after the kernel has booted::
507 2. Stop kernel execution (break into the debugger)
509 In order to connect to gdb via kgdboc, the kernel must first be
510 stopped. There are several ways to stop the kernel which include
511 using kgdbwait as a boot argument, via a :kbd:`SysRq-G`, or running the
512 kernel until it takes an exception where it waits for the debugger to
515 - When logged in as root or with a super user session you can run::
517 echo g > /proc/sysrq-trigger
519 - Example using minicom 2.2
521 Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g`
523 - When you have telneted to a terminal server that supports sending
526 Press: :kbd:`CTRL-]`
528 Type in: ``send break``
547 Once connected, you can debug a kernel the way you would debug an
553 this prior to issuing the ``target remote`` command by typing in::
557 Remember if you continue in gdb, and need to "break in" again, you need
558 to issue an other :kbd:`SysRq-G`. It is easy to create a simple entry point by
567 in the same mode.
570 ------------------------------
577 Whenever the kernel debugger stops in kgdb mode it will print the
579 to type the sequence correctly in one pass. You cannot type a backspace
592 Now you must kill gdb. Typically you press :kbd:`CTRL-Z` and issue
595 kill -9 %
611 Now disconnect your terminal program and connect gdb in its place
613 2. At the kdb prompt, disconnect the terminal program and connect gdb in
617 -----------------------------
621 breakpoint operations, because it can disrupt the state of the kernel
644 When kgdb is enabled in the kernel config you can also elect to enable
651 Linux kernel. The primary source of documentation would be to look in
655 core set of tests by setting the kernel config parameter
657 regression testing and does not require modifying the kernel boot config
659 specifying ``kgdbts=`` as a kernel boot argument.
661 Kernel Debugger Internals
665 ----------------------
667 The kernel debugger is organized into a number of components:
671 The debug core is found in ``kernel/debugger/debug_core.c``. It
674 - A generic OS exception handler which includes sync'ing the
675 processors into a stopped state on an multi-CPU system.
677 - The API to talk to the kgdb I/O drivers
679 - The API to make calls to the arch-specific kgdb implementation
681 - The logic to perform safe memory reads and writes to memory while
684 - A full implementation for software breakpoints unless overridden
687 - The API to invoke either the kdb or kgdb frontend to the debug
690 - The structures and callback API for atomic kernel mode setting.
694 2. kgdb arch-specific implementation
696 This implementation is generally found in ``arch/*/kernel/kgdb.c``. As
697 an example, ``arch/x86/kernel/kgdb.c`` contains the specifics to
700 The arch-specific portion implements:
702 - contains an arch-specific trap catcher which invokes
705 - translation to and from gdb specific packet format to :c:type:`pt_regs`
707 - Registration and unregistration of architecture specific trap
710 - Any special exception handling and cleanup
712 - NMI exception handling and cleanup
714 - (optional) HW breakpoints
718 The gdbstub is located in ``kernel/debug/gdbstub.c``. It contains:
720 - All the logic to implement the gdb serial protocol
725 The kdb core is located in kernel/debug/kdb. There are a number of
726 helper functions in some of the other kernel components to make it
727 possible for kdb to examine and report information about the kernel
728 without taking locks that could cause a kernel deadlock. The kdb core
731 - A simple shell
733 - The kdb core command set
735 - A registration API to register additional kdb shell commands.
737 - A good example of a self-contained kdb module is the ``ftdump``
739 ``kernel/trace/trace_kdb.c``
741 - For an example of how to dynamically register a new kdb command
742 you can build the kdb_hello.ko kernel module from
744 ``CONFIG_SAMPLES=y`` and ``CONFIG_SAMPLE_KDB=m`` in your kernel
748 - The implementation for :c:func:`kdb_printf` which emits messages directly
749 to I/O drivers, bypassing the kernel log.
751 - SW / HW breakpoint management for the kdb shell
758 - configuration via built-in or module
760 - dynamic configuration and kgdb hook registration calls
762 - read and write character interface
764 - A cleanup handler for unconfiguring from the kgdb core
766 - (optional) Early debug methodology
769 hardware and must do it in such a way that does not enable interrupts
774 for the future possibility to touch watchdog hardware in such a way
778 architecture, the architecture should define ``HAVE_ARCH_KGDB`` in the
783 There are a few flags which must be set on every architecture in their
786 - ``NUMREGBYTES``:
787 The size in bytes of all of the registers, so that we
790 - ``BUFMAX``:
791 The size in bytes of the buffer GDB will read into. This must
794 - ``CACHE_FLUSH_IS_SAFE``:
798 CPUs in a holding pattern.
800 There are also the following functions for the common backend, found in
801 ``kernel/kgdb.c``, that must be supplied by the architecture-specific
802 backend unless marked as (optional), in which case a default function
806 .. kernel-doc:: include/linux/kgdb.h
810 ----------------
817 which the tty driver is attached. In the initial implementation of
819 doing polled mode reading and writing of a single character while in an
821 invokes a callback in the serial core which in turn uses the callback in
825 callbacks in the :c:type:`struct uart_ops <uart_ops>`.
836 ``#ifdef CONFIG_CONSOLE_POLL``, as shown above. Keep in mind that
837 polling hooks have to be implemented in such a way that they can be
849 kernel when ``CONFIG_KDB_KEYBOARD=y`` is set in the kernel configuration.
851 The core polled keyboard driver driver for PS/2 type keyboards is in
853 when kgdboc populates the callback in the array called
854 :c:type:`kdb_poll_funcs[]`. The :c:func:`kdb_get_kbd_char` is the top-level
863 kernel mode setting support.
865 Every time the kernel debugger is entered it calls
866 :c:func:`kgdboc_pre_exp_handler` which in turn calls :c:func:`con_debug_enter`
867 in the virtual console layer. On resuming kernel execution, the kernel
868 debugger calls :c:func:`kgdboc_post_exp_handler` which in turn calls
871 Any video driver that wants to be compatible with the kernel debugger
877 .mode_set_base_atomic operation in
890 helpers in ``drivers/gpu/drm/i915/intel_fb.c``::
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>