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: ``kgdboc_earlycon``
278 -------------------------------------
280 If you specify the kernel parameter ``kgdboc_earlycon`` and your serial
301 Kernel parameter: ``kgdbwait``
302 ------------------------------
304 The Kernel command line option ``kgdbwait`` makes kgdb wait for a
305 debugger connection during booting of a kernel. You can only use this
306 option if you compiled a kgdb I/O driver into the kernel and you
307 specified the I/O driver configuration as a kernel command line option.
309 for the kgdb I/O driver in the kernel command line else the I/O driver
310 will not be configured prior to asking the kernel to use it to wait.
312 The kernel will stop and wait as early as the I/O driver and
314 driver as a loadable kernel module kgdbwait will not do anything.
316 Kernel parameter: ``kgdbcon``
317 -----------------------------
320 while gdb is connected to the kernel. Kdb does not make use of the kgdbcon
327 1. Activate with the kernel command line option::
352 ----------------------------------
360 .. flat-table::
363 * - 1
364 - ``echo -1 > /sys/module/debug_core/parameters/kgdbreboot``
365 - Ignore the reboot notification entirely.
367 * - 2
368 - ``echo 0 > /sys/module/debug_core/parameters/kgdbreboot``
369 - Send the detach message to any attached debugger client.
371 * - 3
372 - ``echo 1 > /sys/module/debug_core/parameters/kgdbreboot``
373 - Enter the debugger on reboot notify.
375 Kernel parameter: ``nokaslr``
376 -----------------------------
380 virtual address where the kernel image is mapped and confuse
381 gdb which resolve kernel symbol address from symbol table
388 ------------------------------------
392 1. Configure kgdboc at boot using kernel parameters::
398 Configure kgdboc after the kernel has booted; assuming you are using
403 2. Enter the kernel debugger manually or by waiting for an oops or
404 fault. There are several ways you can enter the kernel debugger
405 manually; all involve using the :kbd:`SysRq-G`, which means you must have
406 enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config.
408 - When logged in as root or with a super user session you can run::
410 echo g > /proc/sysrq-trigger
412 - Example using minicom 2.2
414 Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g`
416 - When you have telneted to a terminal server that supports sending
419 Press: :kbd:`CTRL-]`
421 Type in: ``send break``
428 Some useful commands in kdb include:
431 ``lsmod`` Shows where kernel modules are loaded
434 ``summary`` Shows kernel version info and memory usage
436 ``dmesg`` View the kernel syslog buffer
441 or using the ``go`` command to resuming normal kernel execution. If you
442 have paused the kernel for a lengthy period of time, applications
445 consideration when using the kernel debugger.
448 ------------------------------------------------------
452 1. Configure kgdboc at boot using kernel parameters::
458 Configure kgdboc after the kernel has booted::
462 2. Enter the kernel debugger manually or by waiting for an oops or
463 fault. There are several ways you can enter the kernel debugger
464 manually; all involve using the :kbd:`SysRq-G`, which means you must have
465 enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config.
467 - When logged in as root or with a super user session you can run::
469 echo g > /proc/sysrq-trigger
471 - Example using a laptop keyboard:
485 - Example using a PS/2 101-key keyboard
495 3. Now type in a kdb command such as ``help``, ``dmesg``, ``bt`` or ``go`` to
496 continue kernel execution.
501 In order to use kgdb you must activate it by passing configuration
504 only actively hook up to the kernel trap hooks if a kgdb I/O driver is
506 unregister all the kernel hook points.
517 ------------------------------------
521 Configure kgdboc at boot using kernel parameters::
527 Configure kgdboc after the kernel has booted::
531 2. Stop kernel execution (break into the debugger)
533 In order to connect to gdb via kgdboc, the kernel must first be
534 stopped. There are several ways to stop the kernel which include
535 using kgdbwait as a boot argument, via a :kbd:`SysRq-G`, or running the
536 kernel until it takes an exception where it waits for the debugger to
539 - When logged in as root or with a super user session you can run::
541 echo g > /proc/sysrq-trigger
543 - Example using minicom 2.2
545 Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g`
547 - When you have telneted to a terminal server that supports sending
550 Press: :kbd:`CTRL-]`
552 Type in: ``send break``
571 Once connected, you can debug a kernel the way you would debug an
577 this prior to issuing the ``target remote`` command by typing in::
581 Remember if you continue in gdb, and need to "break in" again, you need
582 to issue an other :kbd:`SysRq-G`. It is easy to create a simple entry point by
591 in the same mode.
594 ------------------------------
601 Whenever the kernel debugger stops in kgdb mode it will print the
603 to type the sequence correctly in one pass. You cannot type a backspace
616 Now you must kill gdb. Typically you press :kbd:`CTRL-Z` and issue
619 kill -9 %
635 Now disconnect your terminal program and connect gdb in its place
637 2. At the kdb prompt, disconnect the terminal program and connect gdb in
641 -----------------------------
645 breakpoint operations, because it can disrupt the state of the kernel
668 When kgdb is enabled in the kernel config you can also elect to enable
675 Linux kernel. The primary source of documentation would be to look in
679 core set of tests by setting the kernel config parameter
681 regression testing and does not require modifying the kernel boot config
683 specifying ``kgdbts=`` as a kernel boot argument.
685 Kernel Debugger Internals
689 ----------------------
691 The kernel debugger is organized into a number of components:
695 The debug core is found in ``kernel/debugger/debug_core.c``. It
698 - A generic OS exception handler which includes sync'ing the
699 processors into a stopped state on an multi-CPU system.
701 - The API to talk to the kgdb I/O drivers
703 - The API to make calls to the arch-specific kgdb implementation
705 - The logic to perform safe memory reads and writes to memory while
708 - A full implementation for software breakpoints unless overridden
711 - The API to invoke either the kdb or kgdb frontend to the debug
714 - The structures and callback API for atomic kernel mode setting.
718 2. kgdb arch-specific implementation
720 This implementation is generally found in ``arch/*/kernel/kgdb.c``. As
721 an example, ``arch/x86/kernel/kgdb.c`` contains the specifics to
724 The arch-specific portion implements:
726 - contains an arch-specific trap catcher which invokes
729 - translation to and from gdb specific packet format to struct pt_regs
731 - Registration and unregistration of architecture specific trap
734 - Any special exception handling and cleanup
736 - NMI exception handling and cleanup
738 - (optional) HW breakpoints
742 The gdbstub is located in ``kernel/debug/gdbstub.c``. It contains:
744 - All the logic to implement the gdb serial protocol
749 The kdb core is located in kernel/debug/kdb. There are a number of
750 helper functions in some of the other kernel components to make it
751 possible for kdb to examine and report information about the kernel
752 without taking locks that could cause a kernel deadlock. The kdb core
755 - A simple shell
757 - The kdb core command set
759 - A registration API to register additional kdb shell commands.
761 - A good example of a self-contained kdb module is the ``ftdump``
763 ``kernel/trace/trace_kdb.c``
765 - For an example of how to dynamically register a new kdb command
766 you can build the kdb_hello.ko kernel module from
768 ``CONFIG_SAMPLES=y`` and ``CONFIG_SAMPLE_KDB=m`` in your kernel
772 - The implementation for kdb_printf() which emits messages directly
773 to I/O drivers, bypassing the kernel log.
775 - SW / HW breakpoint management for the kdb shell
782 - configuration via built-in or module
784 - dynamic configuration and kgdb hook registration calls
786 - read and write character interface
788 - A cleanup handler for unconfiguring from the kgdb core
790 - (optional) Early debug methodology
793 hardware and must do it in such a way that does not enable interrupts
798 for the future possibility to touch watchdog hardware in such a way
802 architecture, the architecture should define ``HAVE_ARCH_KGDB`` in the
807 There are a few flags which must be set on every architecture in their
810 - ``NUMREGBYTES``:
811 The size in bytes of all of the registers, so that we
814 - ``BUFMAX``:
815 The size in bytes of the buffer GDB will read into. This must
818 - ``CACHE_FLUSH_IS_SAFE``:
822 CPUs in a holding pattern.
824 There are also the following functions for the common backend, found in
825 ``kernel/kgdb.c``, that must be supplied by the architecture-specific
826 backend unless marked as (optional), in which case a default function
830 .. kernel-doc:: include/linux/kgdb.h
834 ----------------
841 which the tty driver is attached. In the initial implementation of
843 doing polled mode reading and writing of a single character while in an
845 invokes a callback in the serial core which in turn uses the callback in
849 callbacks in the struct uart_ops.
860 ``#ifdef CONFIG_CONSOLE_POLL``, as shown above. Keep in mind that
861 polling hooks have to be implemented in such a way that they can be
873 kernel when ``CONFIG_KDB_KEYBOARD=y`` is set in the kernel configuration.
875 The core polled keyboard driver for PS/2 type keyboards is in
877 when kgdboc populates the callback in the array called
878 :c:expr:`kdb_poll_funcs[]`. The kdb_get_kbd_char() is the top-level
887 kernel mode setting support.
889 Every time the kernel debugger is entered it calls
890 kgdboc_pre_exp_handler() which in turn calls con_debug_enter()
891 in the virtual console layer. On resuming kernel execution, the kernel
892 debugger calls kgdboc_post_exp_handler() which in turn calls
895 Any video driver that wants to be compatible with the kernel debugger
901 .mode_set_base_atomic operation in
914 helpers in ``drivers/gpu/drm/i915/intel_fb.c``::
932 2. Tom Rini <trini@kernel.crashing.org>
934 In March 2008 this document was completely rewritten by:
936 - Jason Wessel <jason.wessel@windriver.com>
938 In Jan 2010 this document was updated to include kdb.
940 - Jason Wessel <jason.wessel@windriver.com>