17fb2e8a4SMauro Carvalho Chehab================================================= 27fb2e8a4SMauro Carvalho ChehabUsing kgdb, kdb and the kernel debugger internals 37fb2e8a4SMauro Carvalho Chehab================================================= 47fb2e8a4SMauro Carvalho Chehab 57fb2e8a4SMauro Carvalho Chehab:Author: Jason Wessel 67fb2e8a4SMauro Carvalho Chehab 77fb2e8a4SMauro Carvalho ChehabIntroduction 87fb2e8a4SMauro Carvalho Chehab============ 97fb2e8a4SMauro Carvalho Chehab 107fb2e8a4SMauro Carvalho ChehabThe kernel has two different debugger front ends (kdb and kgdb) which 117fb2e8a4SMauro Carvalho Chehabinterface to the debug core. It is possible to use either of the 127fb2e8a4SMauro Carvalho Chehabdebugger front ends and dynamically transition between them if you 137fb2e8a4SMauro Carvalho Chehabconfigure the kernel properly at compile and runtime. 147fb2e8a4SMauro Carvalho Chehab 157fb2e8a4SMauro Carvalho ChehabKdb is simplistic shell-style interface which you can use on a system 167fb2e8a4SMauro Carvalho Chehabconsole with a keyboard or serial console. You can use it to inspect 177fb2e8a4SMauro Carvalho Chehabmemory, registers, process lists, dmesg, and even set breakpoints to 187fb2e8a4SMauro Carvalho Chehabstop in a certain location. Kdb is not a source level debugger, although 197fb2e8a4SMauro Carvalho Chehabyou can set breakpoints and execute some basic kernel run control. Kdb 207fb2e8a4SMauro Carvalho Chehabis mainly aimed at doing some analysis to aid in development or 217fb2e8a4SMauro Carvalho Chehabdiagnosing kernel problems. You can access some symbols by name in 227fb2e8a4SMauro Carvalho Chehabkernel built-ins or in kernel modules if the code was built with 237fb2e8a4SMauro Carvalho Chehab``CONFIG_KALLSYMS``. 247fb2e8a4SMauro Carvalho Chehab 257fb2e8a4SMauro Carvalho ChehabKgdb is intended to be used as a source level debugger for the Linux 267fb2e8a4SMauro Carvalho Chehabkernel. It is used along with gdb to debug a Linux kernel. The 277fb2e8a4SMauro Carvalho Chehabexpectation is that gdb can be used to "break in" to the kernel to 287fb2e8a4SMauro Carvalho Chehabinspect memory, variables and look through call stack information 297fb2e8a4SMauro Carvalho Chehabsimilar to the way an application developer would use gdb to debug an 307fb2e8a4SMauro Carvalho Chehabapplication. It is possible to place breakpoints in kernel code and 317fb2e8a4SMauro Carvalho Chehabperform some limited execution stepping. 327fb2e8a4SMauro Carvalho Chehab 337fb2e8a4SMauro Carvalho ChehabTwo machines are required for using kgdb. One of these machines is a 347fb2e8a4SMauro Carvalho Chehabdevelopment machine and the other is the target machine. The kernel to 357fb2e8a4SMauro Carvalho Chehabbe debugged runs on the target machine. The development machine runs an 367fb2e8a4SMauro Carvalho Chehabinstance of gdb against the vmlinux file which contains the symbols (not 377fb2e8a4SMauro Carvalho Chehaba boot image such as bzImage, zImage, uImage...). In gdb the developer 387fb2e8a4SMauro Carvalho Chehabspecifies the connection parameters and connects to kgdb. The type of 397fb2e8a4SMauro Carvalho Chehabconnection a developer makes with gdb depends on the availability of 407fb2e8a4SMauro Carvalho Chehabkgdb I/O modules compiled as built-ins or loadable kernel modules in the 417fb2e8a4SMauro Carvalho Chehabtest machine's kernel. 427fb2e8a4SMauro Carvalho Chehab 437fb2e8a4SMauro Carvalho ChehabCompiling a kernel 447fb2e8a4SMauro Carvalho Chehab================== 457fb2e8a4SMauro Carvalho Chehab 467fb2e8a4SMauro Carvalho Chehab- In order to enable compilation of kdb, you must first enable kgdb. 477fb2e8a4SMauro Carvalho Chehab 487fb2e8a4SMauro Carvalho Chehab- The kgdb test compile options are described in the kgdb test suite 497fb2e8a4SMauro Carvalho Chehab chapter. 507fb2e8a4SMauro Carvalho Chehab 517fb2e8a4SMauro Carvalho ChehabKernel config options for kgdb 527fb2e8a4SMauro Carvalho Chehab------------------------------ 537fb2e8a4SMauro Carvalho Chehab 54821c6df8SMauro Carvalho ChehabTo enable ``CONFIG_KGDB`` you should look under 55821c6df8SMauro Carvalho Chehab:menuselection:`Kernel hacking --> Kernel debugging` and select 56821c6df8SMauro Carvalho Chehab:menuselection:`KGDB: kernel debugger`. 577fb2e8a4SMauro Carvalho Chehab 587fb2e8a4SMauro Carvalho ChehabWhile it is not a hard requirement that you have symbols in your vmlinux 597fb2e8a4SMauro Carvalho Chehabfile, gdb tends not to be very useful without the symbolic data, so you 60821c6df8SMauro Carvalho Chehabwill want to turn on ``CONFIG_DEBUG_INFO`` which is called 61821c6df8SMauro Carvalho Chehab:menuselection:`Compile the kernel with debug info` in the config menu. 627fb2e8a4SMauro Carvalho Chehab 637fb2e8a4SMauro Carvalho ChehabIt is advised, but not required, that you turn on the 64821c6df8SMauro Carvalho Chehab``CONFIG_FRAME_POINTER`` kernel option which is called :menuselection:`Compile 65821c6df8SMauro Carvalho Chehabthe kernel with frame pointers` in the config menu. This option inserts code 66c12af30bSTiezhu Yanginto the compiled executable which saves the frame information in registers 67c12af30bSTiezhu Yangor on the stack at different points which allows a debugger such as gdb to 68c12af30bSTiezhu Yangmore accurately construct stack back traces while debugging the kernel. 697fb2e8a4SMauro Carvalho Chehab 707fb2e8a4SMauro Carvalho ChehabIf the architecture that you are using supports the kernel option 71821c6df8SMauro Carvalho Chehab``CONFIG_STRICT_KERNEL_RWX``, you should consider turning it off. This 727fb2e8a4SMauro Carvalho Chehaboption will prevent the use of software breakpoints because it marks 737fb2e8a4SMauro Carvalho Chehabcertain regions of the kernel's memory space as read-only. If kgdb 747fb2e8a4SMauro Carvalho Chehabsupports it for the architecture you are using, you can use hardware 75821c6df8SMauro Carvalho Chehabbreakpoints if you desire to run with the ``CONFIG_STRICT_KERNEL_RWX`` 767fb2e8a4SMauro Carvalho Chehaboption turned on, else you need to turn off this option. 777fb2e8a4SMauro Carvalho Chehab 787fb2e8a4SMauro Carvalho ChehabNext you should choose one of more I/O drivers to interconnect debugging 797fb2e8a4SMauro Carvalho Chehabhost and debugged target. Early boot debugging requires a KGDB I/O 807fb2e8a4SMauro Carvalho Chehabdriver that supports early debugging and the driver must be built into 817fb2e8a4SMauro Carvalho Chehabthe kernel directly. Kgdb I/O driver configuration takes place via 827fb2e8a4SMauro Carvalho Chehabkernel or module parameters which you can learn more about in the in the 83821c6df8SMauro Carvalho Chehabsection that describes the parameter kgdboc. 847fb2e8a4SMauro Carvalho Chehab 85821c6df8SMauro Carvalho ChehabHere is an example set of ``.config`` symbols to enable or disable for kgdb:: 867fb2e8a4SMauro Carvalho Chehab 87821c6df8SMauro Carvalho Chehab # CONFIG_STRICT_KERNEL_RWX is not set 88821c6df8SMauro Carvalho Chehab CONFIG_FRAME_POINTER=y 89821c6df8SMauro Carvalho Chehab CONFIG_KGDB=y 90821c6df8SMauro Carvalho Chehab CONFIG_KGDB_SERIAL_CONSOLE=y 917fb2e8a4SMauro Carvalho Chehab 927fb2e8a4SMauro Carvalho ChehabKernel config options for kdb 937fb2e8a4SMauro Carvalho Chehab----------------------------- 947fb2e8a4SMauro Carvalho Chehab 957fb2e8a4SMauro Carvalho ChehabKdb is quite a bit more complex than the simple gdbstub sitting on top 967fb2e8a4SMauro Carvalho Chehabof the kernel's debug core. Kdb must implement a shell, and also adds 977fb2e8a4SMauro Carvalho Chehabsome helper functions in other parts of the kernel, responsible for 987fb2e8a4SMauro Carvalho Chehabprinting out interesting data such as what you would see if you ran 99821c6df8SMauro Carvalho Chehab``lsmod``, or ``ps``. In order to build kdb into the kernel you follow the 1007fb2e8a4SMauro Carvalho Chehabsame steps as you would for kgdb. 1017fb2e8a4SMauro Carvalho Chehab 1027fb2e8a4SMauro Carvalho ChehabThe main config option for kdb is ``CONFIG_KGDB_KDB`` which is called 103821c6df8SMauro Carvalho Chehab:menuselection:`KGDB_KDB: include kdb frontend for kgdb` in the config menu. 104821c6df8SMauro Carvalho ChehabIn theory you would have already also selected an I/O driver such as the 105821c6df8SMauro Carvalho Chehab``CONFIG_KGDB_SERIAL_CONSOLE`` interface if you plan on using kdb on a 1067fb2e8a4SMauro Carvalho Chehabserial port, when you were configuring kgdb. 1077fb2e8a4SMauro Carvalho Chehab 1087fb2e8a4SMauro Carvalho ChehabIf you want to use a PS/2-style keyboard with kdb, you would select 109821c6df8SMauro Carvalho Chehab``CONFIG_KDB_KEYBOARD`` which is called :menuselection:`KGDB_KDB: keyboard as 110821c6df8SMauro Carvalho Chehabinput device` in the config menu. The ``CONFIG_KDB_KEYBOARD`` option is not 111821c6df8SMauro Carvalho Chehabused for anything in the gdb interface to kgdb. The ``CONFIG_KDB_KEYBOARD`` 1127fb2e8a4SMauro Carvalho Chehaboption only works with kdb. 1137fb2e8a4SMauro Carvalho Chehab 114821c6df8SMauro Carvalho ChehabHere is an example set of ``.config`` symbols to enable/disable kdb:: 1157fb2e8a4SMauro Carvalho Chehab 116821c6df8SMauro Carvalho Chehab # CONFIG_STRICT_KERNEL_RWX is not set 117821c6df8SMauro Carvalho Chehab CONFIG_FRAME_POINTER=y 118821c6df8SMauro Carvalho Chehab CONFIG_KGDB=y 119821c6df8SMauro Carvalho Chehab CONFIG_KGDB_SERIAL_CONSOLE=y 120821c6df8SMauro Carvalho Chehab CONFIG_KGDB_KDB=y 121821c6df8SMauro Carvalho Chehab CONFIG_KDB_KEYBOARD=y 1227fb2e8a4SMauro Carvalho Chehab 1237fb2e8a4SMauro Carvalho ChehabKernel Debugger Boot Arguments 1247fb2e8a4SMauro Carvalho Chehab============================== 1257fb2e8a4SMauro Carvalho Chehab 1267fb2e8a4SMauro Carvalho ChehabThis section describes the various runtime kernel parameters that affect 1277fb2e8a4SMauro Carvalho Chehabthe configuration of the kernel debugger. The following chapter covers 1287fb2e8a4SMauro Carvalho Chehabusing kdb and kgdb as well as providing some examples of the 1297fb2e8a4SMauro Carvalho Chehabconfiguration parameters. 1307fb2e8a4SMauro Carvalho Chehab 1317fb2e8a4SMauro Carvalho ChehabKernel parameter: kgdboc 1327fb2e8a4SMauro Carvalho Chehab------------------------ 1337fb2e8a4SMauro Carvalho Chehab 1347fb2e8a4SMauro Carvalho ChehabThe kgdboc driver was originally an abbreviation meant to stand for 1357fb2e8a4SMauro Carvalho Chehab"kgdb over console". Today it is the primary mechanism to configure how 1367fb2e8a4SMauro Carvalho Chehabto communicate from gdb to kgdb as well as the devices you want to use 1377fb2e8a4SMauro Carvalho Chehabto interact with the kdb shell. 1387fb2e8a4SMauro Carvalho Chehab 1397fb2e8a4SMauro Carvalho ChehabFor kgdb/gdb, kgdboc is designed to work with a single serial port. It 1407fb2e8a4SMauro Carvalho Chehabis intended to cover the circumstance where you want to use a serial 1417fb2e8a4SMauro Carvalho Chehabconsole as your primary console as well as using it to perform kernel 1427fb2e8a4SMauro Carvalho Chehabdebugging. It is also possible to use kgdb on a serial port which is not 1437fb2e8a4SMauro Carvalho Chehabdesignated as a system console. Kgdboc may be configured as a kernel 1447fb2e8a4SMauro Carvalho Chehabbuilt-in or a kernel loadable module. You can only make use of 1457fb2e8a4SMauro Carvalho Chehab``kgdbwait`` and early debugging if you build kgdboc into the kernel as 1467fb2e8a4SMauro Carvalho Chehaba built-in. 1477fb2e8a4SMauro Carvalho Chehab 1487fb2e8a4SMauro Carvalho ChehabOptionally you can elect to activate kms (Kernel Mode Setting) 1497fb2e8a4SMauro Carvalho Chehabintegration. When you use kms with kgdboc and you have a video driver 1507fb2e8a4SMauro Carvalho Chehabthat has atomic mode setting hooks, it is possible to enter the debugger 1517fb2e8a4SMauro Carvalho Chehabon the graphics console. When the kernel execution is resumed, the 1527fb2e8a4SMauro Carvalho Chehabprevious graphics mode will be restored. This integration can serve as a 1537fb2e8a4SMauro Carvalho Chehabuseful tool to aid in diagnosing crashes or doing analysis of memory 1547fb2e8a4SMauro Carvalho Chehabwith kdb while allowing the full graphics console applications to run. 1557fb2e8a4SMauro Carvalho Chehab 1567fb2e8a4SMauro Carvalho Chehabkgdboc arguments 1577fb2e8a4SMauro Carvalho Chehab~~~~~~~~~~~~~~~~ 1587fb2e8a4SMauro Carvalho Chehab 159821c6df8SMauro Carvalho ChehabUsage:: 160821c6df8SMauro Carvalho Chehab 161821c6df8SMauro Carvalho Chehab kgdboc=[kms][[,]kbd][[,]serial_device][,baud] 1627fb2e8a4SMauro Carvalho Chehab 1637fb2e8a4SMauro Carvalho ChehabThe order listed above must be observed if you use any of the optional 1647fb2e8a4SMauro Carvalho Chehabconfigurations together. 1657fb2e8a4SMauro Carvalho Chehab 1667fb2e8a4SMauro Carvalho ChehabAbbreviations: 1677fb2e8a4SMauro Carvalho Chehab 1687fb2e8a4SMauro Carvalho Chehab- kms = Kernel Mode Setting 1697fb2e8a4SMauro Carvalho Chehab 1707fb2e8a4SMauro Carvalho Chehab- kbd = Keyboard 1717fb2e8a4SMauro Carvalho Chehab 1727fb2e8a4SMauro Carvalho ChehabYou can configure kgdboc to use the keyboard, and/or a serial device 1737fb2e8a4SMauro Carvalho Chehabdepending on if you are using kdb and/or kgdb, in one of the following 1747fb2e8a4SMauro Carvalho Chehabscenarios. The order listed above must be observed if you use any of the 1757fb2e8a4SMauro Carvalho Chehaboptional configurations together. Using kms + only gdb is generally not 1767fb2e8a4SMauro Carvalho Chehaba useful combination. 1777fb2e8a4SMauro Carvalho Chehab 1787fb2e8a4SMauro Carvalho ChehabUsing loadable module or built-in 1797fb2e8a4SMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1807fb2e8a4SMauro Carvalho Chehab 1817fb2e8a4SMauro Carvalho Chehab1. As a kernel built-in: 1827fb2e8a4SMauro Carvalho Chehab 183821c6df8SMauro Carvalho Chehab Use the kernel boot argument:: 184821c6df8SMauro Carvalho Chehab 185821c6df8SMauro Carvalho Chehab kgdboc=<tty-device>,[baud] 1867fb2e8a4SMauro Carvalho Chehab 1877fb2e8a4SMauro Carvalho Chehab2. As a kernel loadable module: 1887fb2e8a4SMauro Carvalho Chehab 189821c6df8SMauro Carvalho Chehab Use the command:: 190821c6df8SMauro Carvalho Chehab 191821c6df8SMauro Carvalho Chehab modprobe kgdboc kgdboc=<tty-device>,[baud] 1927fb2e8a4SMauro Carvalho Chehab 1937fb2e8a4SMauro Carvalho Chehab Here are two examples of how you might format the kgdboc string. The 1947fb2e8a4SMauro Carvalho Chehab first is for an x86 target using the first serial port. The second 1957fb2e8a4SMauro Carvalho Chehab example is for the ARM Versatile AB using the second serial port. 1967fb2e8a4SMauro Carvalho Chehab 1977fb2e8a4SMauro Carvalho Chehab 1. ``kgdboc=ttyS0,115200`` 1987fb2e8a4SMauro Carvalho Chehab 1997fb2e8a4SMauro Carvalho Chehab 2. ``kgdboc=ttyAMA1,115200`` 2007fb2e8a4SMauro Carvalho Chehab 2017fb2e8a4SMauro Carvalho ChehabConfigure kgdboc at runtime with sysfs 2027fb2e8a4SMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2037fb2e8a4SMauro Carvalho Chehab 2047fb2e8a4SMauro Carvalho ChehabAt run time you can enable or disable kgdboc by echoing a parameters 2057fb2e8a4SMauro Carvalho Chehabinto the sysfs. Here are two examples: 2067fb2e8a4SMauro Carvalho Chehab 207821c6df8SMauro Carvalho Chehab1. Enable kgdboc on ttyS0:: 2087fb2e8a4SMauro Carvalho Chehab 209821c6df8SMauro Carvalho Chehab echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc 2107fb2e8a4SMauro Carvalho Chehab 211821c6df8SMauro Carvalho Chehab2. Disable kgdboc:: 2127fb2e8a4SMauro Carvalho Chehab 213821c6df8SMauro Carvalho Chehab echo "" > /sys/module/kgdboc/parameters/kgdboc 2147fb2e8a4SMauro Carvalho Chehab 215821c6df8SMauro Carvalho Chehab.. note:: 216821c6df8SMauro Carvalho Chehab 217821c6df8SMauro Carvalho Chehab You do not need to specify the baud if you are configuring the 2187fb2e8a4SMauro Carvalho Chehab console on tty which is already configured or open. 2197fb2e8a4SMauro Carvalho Chehab 2207fb2e8a4SMauro Carvalho ChehabMore examples 2217fb2e8a4SMauro Carvalho Chehab^^^^^^^^^^^^^ 2227fb2e8a4SMauro Carvalho Chehab 2237fb2e8a4SMauro Carvalho ChehabYou can configure kgdboc to use the keyboard, and/or a serial device 2247fb2e8a4SMauro Carvalho Chehabdepending on if you are using kdb and/or kgdb, in one of the following 2257fb2e8a4SMauro Carvalho Chehabscenarios. 2267fb2e8a4SMauro Carvalho Chehab 227821c6df8SMauro Carvalho Chehab1. kdb and kgdb over only a serial port:: 2287fb2e8a4SMauro Carvalho Chehab 229821c6df8SMauro Carvalho Chehab kgdboc=<serial_device>[,baud] 2307fb2e8a4SMauro Carvalho Chehab 231821c6df8SMauro Carvalho Chehab Example:: 2327fb2e8a4SMauro Carvalho Chehab 233821c6df8SMauro Carvalho Chehab kgdboc=ttyS0,115200 2347fb2e8a4SMauro Carvalho Chehab 235821c6df8SMauro Carvalho Chehab2. kdb and kgdb with keyboard and a serial port:: 2367fb2e8a4SMauro Carvalho Chehab 237821c6df8SMauro Carvalho Chehab kgdboc=kbd,<serial_device>[,baud] 2387fb2e8a4SMauro Carvalho Chehab 239821c6df8SMauro Carvalho Chehab Example:: 2407fb2e8a4SMauro Carvalho Chehab 241821c6df8SMauro Carvalho Chehab kgdboc=kbd,ttyS0,115200 2427fb2e8a4SMauro Carvalho Chehab 243821c6df8SMauro Carvalho Chehab3. kdb with a keyboard:: 2447fb2e8a4SMauro Carvalho Chehab 245821c6df8SMauro Carvalho Chehab kgdboc=kbd 2467fb2e8a4SMauro Carvalho Chehab 247821c6df8SMauro Carvalho Chehab4. kdb with kernel mode setting:: 2487fb2e8a4SMauro Carvalho Chehab 249821c6df8SMauro Carvalho Chehab kgdboc=kms,kbd 2507fb2e8a4SMauro Carvalho Chehab 251821c6df8SMauro Carvalho Chehab5. kdb with kernel mode setting and kgdb over a serial port:: 252821c6df8SMauro Carvalho Chehab 253821c6df8SMauro Carvalho Chehab kgdboc=kms,kbd,ttyS0,115200 254821c6df8SMauro Carvalho Chehab 255821c6df8SMauro Carvalho Chehab.. note:: 256821c6df8SMauro Carvalho Chehab 257821c6df8SMauro Carvalho Chehab Kgdboc does not support interrupting the target via the gdb remote 258821c6df8SMauro Carvalho Chehab protocol. You must manually send a :kbd:`SysRq-G` unless you have a proxy 259821c6df8SMauro Carvalho Chehab that splits console output to a terminal program. A console proxy has a 2607fb2e8a4SMauro Carvalho Chehab separate TCP port for the debugger and a separate TCP port for the 261821c6df8SMauro Carvalho Chehab "human" console. The proxy can take care of sending the :kbd:`SysRq-G` 262821c6df8SMauro Carvalho Chehab for you. 2637fb2e8a4SMauro Carvalho Chehab 2647fb2e8a4SMauro Carvalho ChehabWhen using kgdboc with no debugger proxy, you can end up connecting the 2657fb2e8a4SMauro Carvalho Chehabdebugger at one of two entry points. If an exception occurs after you 2667fb2e8a4SMauro Carvalho Chehabhave loaded kgdboc, a message should print on the console stating it is 2677fb2e8a4SMauro Carvalho Chehabwaiting for the debugger. In this case you disconnect your terminal 2687fb2e8a4SMauro Carvalho Chehabprogram and then connect the debugger in its place. If you want to 2697fb2e8a4SMauro Carvalho Chehabinterrupt the target system and forcibly enter a debug session you have 270821c6df8SMauro Carvalho Chehabto issue a :kbd:`Sysrq` sequence and then type the letter :kbd:`g`. Then you 2717fb2e8a4SMauro Carvalho Chehabdisconnect the terminal session and connect gdb. Your options if you 272821c6df8SMauro Carvalho Chehabdon't like this are to hack gdb to send the :kbd:`SysRq-G` for you as well as 2737fb2e8a4SMauro Carvalho Chehabon the initial connect, or to use a debugger proxy that allows an 2747fb2e8a4SMauro Carvalho Chehabunmodified gdb to do the debugging. 2757fb2e8a4SMauro Carvalho Chehab 276f71fc3bcSDouglas AndersonKernel parameter: ``kgdboc_earlycon`` 277f71fc3bcSDouglas Anderson------------------------------------- 278f71fc3bcSDouglas Anderson 279f71fc3bcSDouglas AndersonIf you specify the kernel parameter ``kgdboc_earlycon`` and your serial 280f71fc3bcSDouglas Andersondriver registers a boot console that supports polling (doesn't need 281f71fc3bcSDouglas Andersoninterrupts and implements a nonblocking read() function) kgdb will attempt 282f71fc3bcSDouglas Andersonto work using the boot console until it can transition to the regular 283f71fc3bcSDouglas Andersontty driver specified by the ``kgdboc`` parameter. 284f71fc3bcSDouglas Anderson 285f71fc3bcSDouglas AndersonNormally there is only one boot console (especially that implements the 286f71fc3bcSDouglas Andersonread() function) so just adding ``kgdboc_earlycon`` on its own is 287f71fc3bcSDouglas Andersonsufficient to make this work. If you have more than one boot console you 288f71fc3bcSDouglas Andersoncan add the boot console's name to differentiate. Note that names that 289f71fc3bcSDouglas Andersonare registered through the boot console layer and the tty layer are not 290f71fc3bcSDouglas Andersonthe same for the same port. 291f71fc3bcSDouglas Anderson 292f71fc3bcSDouglas AndersonFor instance, on one board to be explicit you might do:: 293f71fc3bcSDouglas Anderson 294f71fc3bcSDouglas Anderson kgdboc_earlycon=qcom_geni kgdboc=ttyMSM0 295f71fc3bcSDouglas Anderson 296f71fc3bcSDouglas AndersonIf the only boot console on the device was "qcom_geni", you could simplify:: 297f71fc3bcSDouglas Anderson 298f71fc3bcSDouglas Anderson kgdboc_earlycon kgdboc=ttyMSM0 299f71fc3bcSDouglas Anderson 300821c6df8SMauro Carvalho ChehabKernel parameter: ``kgdbwait`` 301821c6df8SMauro Carvalho Chehab------------------------------ 3027fb2e8a4SMauro Carvalho Chehab 3037fb2e8a4SMauro Carvalho ChehabThe Kernel command line option ``kgdbwait`` makes kgdb wait for a 3047fb2e8a4SMauro Carvalho Chehabdebugger connection during booting of a kernel. You can only use this 3057fb2e8a4SMauro Carvalho Chehaboption if you compiled a kgdb I/O driver into the kernel and you 3067fb2e8a4SMauro Carvalho Chehabspecified the I/O driver configuration as a kernel command line option. 3077fb2e8a4SMauro Carvalho ChehabThe kgdbwait parameter should always follow the configuration parameter 3087fb2e8a4SMauro Carvalho Chehabfor the kgdb I/O driver in the kernel command line else the I/O driver 3097fb2e8a4SMauro Carvalho Chehabwill not be configured prior to asking the kernel to use it to wait. 3107fb2e8a4SMauro Carvalho Chehab 3117fb2e8a4SMauro Carvalho ChehabThe kernel will stop and wait as early as the I/O driver and 3127fb2e8a4SMauro Carvalho Chehabarchitecture allows when you use this option. If you build the kgdb I/O 3137fb2e8a4SMauro Carvalho Chehabdriver as a loadable kernel module kgdbwait will not do anything. 3147fb2e8a4SMauro Carvalho Chehab 315821c6df8SMauro Carvalho ChehabKernel parameter: ``kgdbcon`` 316821c6df8SMauro Carvalho Chehab----------------------------- 3177fb2e8a4SMauro Carvalho Chehab 3182d88fc62SPuranjay MohanThe ``kgdbcon`` feature allows you to see printk() messages inside gdb 319821c6df8SMauro Carvalho Chehabwhile gdb is connected to the kernel. Kdb does not make use of the kgdbcon 3207fb2e8a4SMauro Carvalho Chehabfeature. 3217fb2e8a4SMauro Carvalho Chehab 3227fb2e8a4SMauro Carvalho ChehabKgdb supports using the gdb serial protocol to send console messages to 3237fb2e8a4SMauro Carvalho Chehabthe debugger when the debugger is connected and running. There are two 3247fb2e8a4SMauro Carvalho Chehabways to activate this feature. 3257fb2e8a4SMauro Carvalho Chehab 326821c6df8SMauro Carvalho Chehab1. Activate with the kernel command line option:: 3277fb2e8a4SMauro Carvalho Chehab 328821c6df8SMauro Carvalho Chehab kgdbcon 3297fb2e8a4SMauro Carvalho Chehab 330821c6df8SMauro Carvalho Chehab2. Use sysfs before configuring an I/O driver:: 3317fb2e8a4SMauro Carvalho Chehab 332821c6df8SMauro Carvalho Chehab echo 1 > /sys/module/kgdb/parameters/kgdb_use_con 3337fb2e8a4SMauro Carvalho Chehab 334821c6df8SMauro Carvalho Chehab.. note:: 335821c6df8SMauro Carvalho Chehab 336821c6df8SMauro Carvalho Chehab If you do this after you configure the kgdb I/O driver, the 3377fb2e8a4SMauro Carvalho Chehab setting will not take effect until the next point the I/O is 3387fb2e8a4SMauro Carvalho Chehab reconfigured. 3397fb2e8a4SMauro Carvalho Chehab 340821c6df8SMauro Carvalho Chehab.. important:: 341821c6df8SMauro Carvalho Chehab 342821c6df8SMauro Carvalho Chehab You cannot use kgdboc + kgdbcon on a tty that is an 343821c6df8SMauro Carvalho Chehab active system console. An example of incorrect usage is:: 344821c6df8SMauro Carvalho Chehab 345821c6df8SMauro Carvalho Chehab console=ttyS0,115200 kgdboc=ttyS0 kgdbcon 3467fb2e8a4SMauro Carvalho Chehab 3477fb2e8a4SMauro Carvalho ChehabIt is possible to use this option with kgdboc on a tty that is not a 3487fb2e8a4SMauro Carvalho Chehabsystem console. 3497fb2e8a4SMauro Carvalho Chehab 350821c6df8SMauro Carvalho ChehabRun time parameter: ``kgdbreboot`` 351821c6df8SMauro Carvalho Chehab---------------------------------- 3527fb2e8a4SMauro Carvalho Chehab 3537fb2e8a4SMauro Carvalho ChehabThe kgdbreboot feature allows you to change how the debugger deals with 3547fb2e8a4SMauro Carvalho Chehabthe reboot notification. You have 3 choices for the behavior. The 3557fb2e8a4SMauro Carvalho Chehabdefault behavior is always set to 0. 3567fb2e8a4SMauro Carvalho Chehab 357821c6df8SMauro Carvalho Chehab.. tabularcolumns:: |p{0.4cm}|p{11.5cm}|p{5.6cm}| 3587fb2e8a4SMauro Carvalho Chehab 359821c6df8SMauro Carvalho Chehab.. flat-table:: 360821c6df8SMauro Carvalho Chehab :widths: 1 10 8 3617fb2e8a4SMauro Carvalho Chehab 362821c6df8SMauro Carvalho Chehab * - 1 363821c6df8SMauro Carvalho Chehab - ``echo -1 > /sys/module/debug_core/parameters/kgdbreboot`` 364821c6df8SMauro Carvalho Chehab - Ignore the reboot notification entirely. 3657fb2e8a4SMauro Carvalho Chehab 366821c6df8SMauro Carvalho Chehab * - 2 367821c6df8SMauro Carvalho Chehab - ``echo 0 > /sys/module/debug_core/parameters/kgdbreboot`` 368821c6df8SMauro Carvalho Chehab - Send the detach message to any attached debugger client. 3697fb2e8a4SMauro Carvalho Chehab 370821c6df8SMauro Carvalho Chehab * - 3 371821c6df8SMauro Carvalho Chehab - ``echo 1 > /sys/module/debug_core/parameters/kgdbreboot`` 372821c6df8SMauro Carvalho Chehab - Enter the debugger on reboot notify. 3737fb2e8a4SMauro Carvalho Chehab 37414994a9bSZhouyi ZhouKernel parameter: ``nokaslr`` 37514994a9bSZhouyi Zhou----------------------------- 37614994a9bSZhouyi Zhou 37714994a9bSZhouyi ZhouIf the architecture that you are using enable KASLR by default, 37814994a9bSZhouyi Zhouyou should consider turning it off. KASLR randomizes the 37914994a9bSZhouyi Zhouvirtual address where the kernel image is mapped and confuse 38014994a9bSZhouyi Zhougdb which resolve kernel symbol address from symbol table 38114994a9bSZhouyi Zhouof vmlinux. 38214994a9bSZhouyi Zhou 3837fb2e8a4SMauro Carvalho ChehabUsing kdb 3847fb2e8a4SMauro Carvalho Chehab========= 3857fb2e8a4SMauro Carvalho Chehab 3867fb2e8a4SMauro Carvalho ChehabQuick start for kdb on a serial port 3877fb2e8a4SMauro Carvalho Chehab------------------------------------ 3887fb2e8a4SMauro Carvalho Chehab 3897fb2e8a4SMauro Carvalho ChehabThis is a quick example of how to use kdb. 3907fb2e8a4SMauro Carvalho Chehab 391821c6df8SMauro Carvalho Chehab1. Configure kgdboc at boot using kernel parameters:: 3927fb2e8a4SMauro Carvalho Chehab 39314994a9bSZhouyi Zhou console=ttyS0,115200 kgdboc=ttyS0,115200 nokaslr 3947fb2e8a4SMauro Carvalho Chehab 3957fb2e8a4SMauro Carvalho Chehab OR 3967fb2e8a4SMauro Carvalho Chehab 3977fb2e8a4SMauro Carvalho Chehab Configure kgdboc after the kernel has booted; assuming you are using 398821c6df8SMauro Carvalho Chehab a serial port console:: 3997fb2e8a4SMauro Carvalho Chehab 400821c6df8SMauro Carvalho Chehab echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc 4017fb2e8a4SMauro Carvalho Chehab 4027fb2e8a4SMauro Carvalho Chehab2. Enter the kernel debugger manually or by waiting for an oops or 4037fb2e8a4SMauro Carvalho Chehab fault. There are several ways you can enter the kernel debugger 404821c6df8SMauro Carvalho Chehab manually; all involve using the :kbd:`SysRq-G`, which means you must have 405e765c747SLukas Bulwahn enabled ``CONFIG_MAGIC_SYSRQ=y`` in your kernel config. 4067fb2e8a4SMauro Carvalho Chehab 407821c6df8SMauro Carvalho Chehab - When logged in as root or with a super user session you can run:: 4087fb2e8a4SMauro Carvalho Chehab 409821c6df8SMauro Carvalho Chehab echo g > /proc/sysrq-trigger 4107fb2e8a4SMauro Carvalho Chehab 4117fb2e8a4SMauro Carvalho Chehab - Example using minicom 2.2 4127fb2e8a4SMauro Carvalho Chehab 413821c6df8SMauro Carvalho Chehab Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g` 4147fb2e8a4SMauro Carvalho Chehab 4157fb2e8a4SMauro Carvalho Chehab - When you have telneted to a terminal server that supports sending 4167fb2e8a4SMauro Carvalho Chehab a remote break 4177fb2e8a4SMauro Carvalho Chehab 418821c6df8SMauro Carvalho Chehab Press: :kbd:`CTRL-]` 4197fb2e8a4SMauro Carvalho Chehab 420821c6df8SMauro Carvalho Chehab Type in: ``send break`` 4217fb2e8a4SMauro Carvalho Chehab 422821c6df8SMauro Carvalho Chehab Press: :kbd:`Enter` :kbd:`g` 4237fb2e8a4SMauro Carvalho Chehab 424821c6df8SMauro Carvalho Chehab3. From the kdb prompt you can run the ``help`` command to see a complete 4257fb2e8a4SMauro Carvalho Chehab list of the commands that are available. 4267fb2e8a4SMauro Carvalho Chehab 4277fb2e8a4SMauro Carvalho Chehab Some useful commands in kdb include: 4287fb2e8a4SMauro Carvalho Chehab 429821c6df8SMauro Carvalho Chehab =========== ================================================================= 430821c6df8SMauro Carvalho Chehab ``lsmod`` Shows where kernel modules are loaded 431821c6df8SMauro Carvalho Chehab ``ps`` Displays only the active processes 432821c6df8SMauro Carvalho Chehab ``ps A`` Shows all the processes 433821c6df8SMauro Carvalho Chehab ``summary`` Shows kernel version info and memory usage 4342d88fc62SPuranjay Mohan ``bt`` Get a backtrace of the current process using dump_stack() 435821c6df8SMauro Carvalho Chehab ``dmesg`` View the kernel syslog buffer 436821c6df8SMauro Carvalho Chehab ``go`` Continue the system 437821c6df8SMauro Carvalho Chehab =========== ================================================================= 4387fb2e8a4SMauro Carvalho Chehab 4397fb2e8a4SMauro Carvalho Chehab4. When you are done using kdb you need to consider rebooting the system 440821c6df8SMauro Carvalho Chehab or using the ``go`` command to resuming normal kernel execution. If you 4417fb2e8a4SMauro Carvalho Chehab have paused the kernel for a lengthy period of time, applications 4427fb2e8a4SMauro Carvalho Chehab that rely on timely networking or anything to do with real wall clock 4437fb2e8a4SMauro Carvalho Chehab time could be adversely affected, so you should take this into 4447fb2e8a4SMauro Carvalho Chehab consideration when using the kernel debugger. 4457fb2e8a4SMauro Carvalho Chehab 4467fb2e8a4SMauro Carvalho ChehabQuick start for kdb using a keyboard connected console 4477fb2e8a4SMauro Carvalho Chehab------------------------------------------------------ 4487fb2e8a4SMauro Carvalho Chehab 4497fb2e8a4SMauro Carvalho ChehabThis is a quick example of how to use kdb with a keyboard. 4507fb2e8a4SMauro Carvalho Chehab 451821c6df8SMauro Carvalho Chehab1. Configure kgdboc at boot using kernel parameters:: 4527fb2e8a4SMauro Carvalho Chehab 453821c6df8SMauro Carvalho Chehab kgdboc=kbd 4547fb2e8a4SMauro Carvalho Chehab 4557fb2e8a4SMauro Carvalho Chehab OR 4567fb2e8a4SMauro Carvalho Chehab 457821c6df8SMauro Carvalho Chehab Configure kgdboc after the kernel has booted:: 4587fb2e8a4SMauro Carvalho Chehab 459821c6df8SMauro Carvalho Chehab echo kbd > /sys/module/kgdboc/parameters/kgdboc 4607fb2e8a4SMauro Carvalho Chehab 4617fb2e8a4SMauro Carvalho Chehab2. Enter the kernel debugger manually or by waiting for an oops or 4627fb2e8a4SMauro Carvalho Chehab fault. There are several ways you can enter the kernel debugger 463821c6df8SMauro Carvalho Chehab manually; all involve using the :kbd:`SysRq-G`, which means you must have 464e765c747SLukas Bulwahn enabled ``CONFIG_MAGIC_SYSRQ=y`` in your kernel config. 4657fb2e8a4SMauro Carvalho Chehab 466821c6df8SMauro Carvalho Chehab - When logged in as root or with a super user session you can run:: 4677fb2e8a4SMauro Carvalho Chehab 468821c6df8SMauro Carvalho Chehab echo g > /proc/sysrq-trigger 4697fb2e8a4SMauro Carvalho Chehab 470821c6df8SMauro Carvalho Chehab - Example using a laptop keyboard: 4717fb2e8a4SMauro Carvalho Chehab 472821c6df8SMauro Carvalho Chehab Press and hold down: :kbd:`Alt` 4737fb2e8a4SMauro Carvalho Chehab 474821c6df8SMauro Carvalho Chehab Press and hold down: :kbd:`Fn` 4757fb2e8a4SMauro Carvalho Chehab 476821c6df8SMauro Carvalho Chehab Press and release the key with the label: :kbd:`SysRq` 4777fb2e8a4SMauro Carvalho Chehab 478821c6df8SMauro Carvalho Chehab Release: :kbd:`Fn` 4797fb2e8a4SMauro Carvalho Chehab 480821c6df8SMauro Carvalho Chehab Press and release: :kbd:`g` 4817fb2e8a4SMauro Carvalho Chehab 482821c6df8SMauro Carvalho Chehab Release: :kbd:`Alt` 4837fb2e8a4SMauro Carvalho Chehab 4847fb2e8a4SMauro Carvalho Chehab - Example using a PS/2 101-key keyboard 4857fb2e8a4SMauro Carvalho Chehab 486821c6df8SMauro Carvalho Chehab Press and hold down: :kbd:`Alt` 4877fb2e8a4SMauro Carvalho Chehab 488821c6df8SMauro Carvalho Chehab Press and release the key with the label: :kbd:`SysRq` 4897fb2e8a4SMauro Carvalho Chehab 490821c6df8SMauro Carvalho Chehab Press and release: :kbd:`g` 4917fb2e8a4SMauro Carvalho Chehab 492821c6df8SMauro Carvalho Chehab Release: :kbd:`Alt` 4937fb2e8a4SMauro Carvalho Chehab 494821c6df8SMauro Carvalho Chehab3. Now type in a kdb command such as ``help``, ``dmesg``, ``bt`` or ``go`` to 4957fb2e8a4SMauro Carvalho Chehab continue kernel execution. 4967fb2e8a4SMauro Carvalho Chehab 4977fb2e8a4SMauro Carvalho ChehabUsing kgdb / gdb 4987fb2e8a4SMauro Carvalho Chehab================ 4997fb2e8a4SMauro Carvalho Chehab 5007fb2e8a4SMauro Carvalho ChehabIn order to use kgdb you must activate it by passing configuration 5017fb2e8a4SMauro Carvalho Chehabinformation to one of the kgdb I/O drivers. If you do not pass any 5027fb2e8a4SMauro Carvalho Chehabconfiguration information kgdb will not do anything at all. Kgdb will 5037fb2e8a4SMauro Carvalho Chehabonly actively hook up to the kernel trap hooks if a kgdb I/O driver is 5047fb2e8a4SMauro Carvalho Chehabloaded and configured. If you unconfigure a kgdb I/O driver, kgdb will 5057fb2e8a4SMauro Carvalho Chehabunregister all the kernel hook points. 5067fb2e8a4SMauro Carvalho Chehab 5077fb2e8a4SMauro Carvalho ChehabAll kgdb I/O drivers can be reconfigured at run time, if 5087fb2e8a4SMauro Carvalho Chehab``CONFIG_SYSFS`` and ``CONFIG_MODULES`` are enabled, by echo'ing a new 5097fb2e8a4SMauro Carvalho Chehabconfig string to ``/sys/module/<driver>/parameter/<option>``. The driver 5107fb2e8a4SMauro Carvalho Chehabcan be unconfigured by passing an empty string. You cannot change the 5117fb2e8a4SMauro Carvalho Chehabconfiguration while the debugger is attached. Make sure to detach the 5127fb2e8a4SMauro Carvalho Chehabdebugger with the ``detach`` command prior to trying to unconfigure a 5137fb2e8a4SMauro Carvalho Chehabkgdb I/O driver. 5147fb2e8a4SMauro Carvalho Chehab 5157fb2e8a4SMauro Carvalho ChehabConnecting with gdb to a serial port 5167fb2e8a4SMauro Carvalho Chehab------------------------------------ 5177fb2e8a4SMauro Carvalho Chehab 5187fb2e8a4SMauro Carvalho Chehab1. Configure kgdboc 5197fb2e8a4SMauro Carvalho Chehab 520821c6df8SMauro Carvalho Chehab Configure kgdboc at boot using kernel parameters:: 5217fb2e8a4SMauro Carvalho Chehab 522821c6df8SMauro Carvalho Chehab kgdboc=ttyS0,115200 5237fb2e8a4SMauro Carvalho Chehab 5247fb2e8a4SMauro Carvalho Chehab OR 5257fb2e8a4SMauro Carvalho Chehab 526821c6df8SMauro Carvalho Chehab Configure kgdboc after the kernel has booted:: 5277fb2e8a4SMauro Carvalho Chehab 528821c6df8SMauro Carvalho Chehab echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc 5297fb2e8a4SMauro Carvalho Chehab 5307fb2e8a4SMauro Carvalho Chehab2. Stop kernel execution (break into the debugger) 5317fb2e8a4SMauro Carvalho Chehab 5327fb2e8a4SMauro Carvalho Chehab In order to connect to gdb via kgdboc, the kernel must first be 5337fb2e8a4SMauro Carvalho Chehab stopped. There are several ways to stop the kernel which include 534821c6df8SMauro Carvalho Chehab using kgdbwait as a boot argument, via a :kbd:`SysRq-G`, or running the 5357fb2e8a4SMauro Carvalho Chehab kernel until it takes an exception where it waits for the debugger to 5367fb2e8a4SMauro Carvalho Chehab attach. 5377fb2e8a4SMauro Carvalho Chehab 538821c6df8SMauro Carvalho Chehab - When logged in as root or with a super user session you can run:: 5397fb2e8a4SMauro Carvalho Chehab 540821c6df8SMauro Carvalho Chehab echo g > /proc/sysrq-trigger 5417fb2e8a4SMauro Carvalho Chehab 5427fb2e8a4SMauro Carvalho Chehab - Example using minicom 2.2 5437fb2e8a4SMauro Carvalho Chehab 544821c6df8SMauro Carvalho Chehab Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g` 5457fb2e8a4SMauro Carvalho Chehab 5467fb2e8a4SMauro Carvalho Chehab - When you have telneted to a terminal server that supports sending 5477fb2e8a4SMauro Carvalho Chehab a remote break 5487fb2e8a4SMauro Carvalho Chehab 549821c6df8SMauro Carvalho Chehab Press: :kbd:`CTRL-]` 5507fb2e8a4SMauro Carvalho Chehab 551821c6df8SMauro Carvalho Chehab Type in: ``send break`` 5527fb2e8a4SMauro Carvalho Chehab 553821c6df8SMauro Carvalho Chehab Press: :kbd:`Enter` :kbd:`g` 5547fb2e8a4SMauro Carvalho Chehab 5557fb2e8a4SMauro Carvalho Chehab3. Connect from gdb 5567fb2e8a4SMauro Carvalho Chehab 557821c6df8SMauro Carvalho Chehab Example (using a directly connected port):: 5587fb2e8a4SMauro Carvalho Chehab 5597fb2e8a4SMauro Carvalho Chehab % gdb ./vmlinux 560*689d8014SChristian Löhle (gdb) set serial baud 115200 5617fb2e8a4SMauro Carvalho Chehab (gdb) target remote /dev/ttyS0 5627fb2e8a4SMauro Carvalho Chehab 5637fb2e8a4SMauro Carvalho Chehab 564821c6df8SMauro Carvalho Chehab Example (kgdb to a terminal server on TCP port 2012):: 5657fb2e8a4SMauro Carvalho Chehab 5667fb2e8a4SMauro Carvalho Chehab % gdb ./vmlinux 5677fb2e8a4SMauro Carvalho Chehab (gdb) target remote 192.168.2.2:2012 5687fb2e8a4SMauro Carvalho Chehab 5697fb2e8a4SMauro Carvalho Chehab 5707fb2e8a4SMauro Carvalho Chehab Once connected, you can debug a kernel the way you would debug an 5717fb2e8a4SMauro Carvalho Chehab application program. 5727fb2e8a4SMauro Carvalho Chehab 5737fb2e8a4SMauro Carvalho Chehab If you are having problems connecting or something is going seriously 5747fb2e8a4SMauro Carvalho Chehab wrong while debugging, it will most often be the case that you want 5757fb2e8a4SMauro Carvalho Chehab to enable gdb to be verbose about its target communications. You do 576821c6df8SMauro Carvalho Chehab this prior to issuing the ``target remote`` command by typing in:: 577821c6df8SMauro Carvalho Chehab 578821c6df8SMauro Carvalho Chehab set debug remote 1 5797fb2e8a4SMauro Carvalho Chehab 5807fb2e8a4SMauro Carvalho ChehabRemember if you continue in gdb, and need to "break in" again, you need 581821c6df8SMauro Carvalho Chehabto issue an other :kbd:`SysRq-G`. It is easy to create a simple entry point by 582821c6df8SMauro Carvalho Chehabputting a breakpoint at ``sys_sync`` and then you can run ``sync`` from a 5837fb2e8a4SMauro Carvalho Chehabshell or script to break into the debugger. 5847fb2e8a4SMauro Carvalho Chehab 5857fb2e8a4SMauro Carvalho Chehabkgdb and kdb interoperability 5867fb2e8a4SMauro Carvalho Chehab============================= 5877fb2e8a4SMauro Carvalho Chehab 5887fb2e8a4SMauro Carvalho ChehabIt is possible to transition between kdb and kgdb dynamically. The debug 5897fb2e8a4SMauro Carvalho Chehabcore will remember which you used the last time and automatically start 5907fb2e8a4SMauro Carvalho Chehabin the same mode. 5917fb2e8a4SMauro Carvalho Chehab 5927fb2e8a4SMauro Carvalho ChehabSwitching between kdb and kgdb 5937fb2e8a4SMauro Carvalho Chehab------------------------------ 5947fb2e8a4SMauro Carvalho Chehab 5957fb2e8a4SMauro Carvalho ChehabSwitching from kgdb to kdb 5967fb2e8a4SMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~~~~~~~~~ 5977fb2e8a4SMauro Carvalho Chehab 5987fb2e8a4SMauro Carvalho ChehabThere are two ways to switch from kgdb to kdb: you can use gdb to issue 599821c6df8SMauro Carvalho Chehaba maintenance packet, or you can blindly type the command ``$3#33``. 6007fb2e8a4SMauro Carvalho ChehabWhenever the kernel debugger stops in kgdb mode it will print the 6017fb2e8a4SMauro Carvalho Chehabmessage ``KGDB or $3#33 for KDB``. It is important to note that you have 6027fb2e8a4SMauro Carvalho Chehabto type the sequence correctly in one pass. You cannot type a backspace 6037fb2e8a4SMauro Carvalho Chehabor delete because kgdb will interpret that as part of the debug stream. 6047fb2e8a4SMauro Carvalho Chehab 605821c6df8SMauro Carvalho Chehab1. Change from kgdb to kdb by blindly typing:: 6067fb2e8a4SMauro Carvalho Chehab 607821c6df8SMauro Carvalho Chehab $3#33 6087fb2e8a4SMauro Carvalho Chehab 609821c6df8SMauro Carvalho Chehab2. Change from kgdb to kdb with gdb:: 6107fb2e8a4SMauro Carvalho Chehab 611821c6df8SMauro Carvalho Chehab maintenance packet 3 6127fb2e8a4SMauro Carvalho Chehab 613821c6df8SMauro Carvalho Chehab .. note:: 614821c6df8SMauro Carvalho Chehab 615821c6df8SMauro Carvalho Chehab Now you must kill gdb. Typically you press :kbd:`CTRL-Z` and issue 616821c6df8SMauro Carvalho Chehab the command:: 617821c6df8SMauro Carvalho Chehab 618821c6df8SMauro Carvalho Chehab kill -9 % 6197fb2e8a4SMauro Carvalho Chehab 6207fb2e8a4SMauro Carvalho ChehabChange from kdb to kgdb 6217fb2e8a4SMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~~~~~~ 6227fb2e8a4SMauro Carvalho Chehab 6237fb2e8a4SMauro Carvalho ChehabThere are two ways you can change from kdb to kgdb. You can manually 6247fb2e8a4SMauro Carvalho Chehabenter kgdb mode by issuing the kgdb command from the kdb shell prompt, 6257fb2e8a4SMauro Carvalho Chehabor you can connect gdb while the kdb shell prompt is active. The kdb 6267fb2e8a4SMauro Carvalho Chehabshell looks for the typical first commands that gdb would issue with the 6277fb2e8a4SMauro Carvalho Chehabgdb remote protocol and if it sees one of those commands it 6287fb2e8a4SMauro Carvalho Chehabautomatically changes into kgdb mode. 6297fb2e8a4SMauro Carvalho Chehab 630821c6df8SMauro Carvalho Chehab1. From kdb issue the command:: 6317fb2e8a4SMauro Carvalho Chehab 632821c6df8SMauro Carvalho Chehab kgdb 6337fb2e8a4SMauro Carvalho Chehab 6347fb2e8a4SMauro Carvalho Chehab Now disconnect your terminal program and connect gdb in its place 6357fb2e8a4SMauro Carvalho Chehab 6367fb2e8a4SMauro Carvalho Chehab2. At the kdb prompt, disconnect the terminal program and connect gdb in 6377fb2e8a4SMauro Carvalho Chehab its place. 6387fb2e8a4SMauro Carvalho Chehab 6397fb2e8a4SMauro Carvalho ChehabRunning kdb commands from gdb 6407fb2e8a4SMauro Carvalho Chehab----------------------------- 6417fb2e8a4SMauro Carvalho Chehab 6427fb2e8a4SMauro Carvalho ChehabIt is possible to run a limited set of kdb commands from gdb, using the 6437fb2e8a4SMauro Carvalho Chehabgdb monitor command. You don't want to execute any of the run control or 6447fb2e8a4SMauro Carvalho Chehabbreakpoint operations, because it can disrupt the state of the kernel 6457fb2e8a4SMauro Carvalho Chehabdebugger. You should be using gdb for breakpoints and run control 6467fb2e8a4SMauro Carvalho Chehaboperations if you have gdb connected. The more useful commands to run 6477fb2e8a4SMauro Carvalho Chehabare things like lsmod, dmesg, ps or possibly some of the memory 6487fb2e8a4SMauro Carvalho Chehabinformation commands. To see all the kdb commands you can run 6497fb2e8a4SMauro Carvalho Chehab``monitor help``. 6507fb2e8a4SMauro Carvalho Chehab 651821c6df8SMauro Carvalho ChehabExample:: 6527fb2e8a4SMauro Carvalho Chehab 6537fb2e8a4SMauro Carvalho Chehab (gdb) monitor ps 6547fb2e8a4SMauro Carvalho Chehab 1 idle process (state I) and 6557fb2e8a4SMauro Carvalho Chehab 27 sleeping system daemon (state M) processes suppressed, 6567fb2e8a4SMauro Carvalho Chehab use 'ps A' to see all. 6577fb2e8a4SMauro Carvalho Chehab Task Addr Pid Parent [*] cpu State Thread Command 6587fb2e8a4SMauro Carvalho Chehab 6597fb2e8a4SMauro Carvalho Chehab 0xc78291d0 1 0 0 0 S 0xc7829404 init 6607fb2e8a4SMauro Carvalho Chehab 0xc7954150 942 1 0 0 S 0xc7954384 dropbear 6617fb2e8a4SMauro Carvalho Chehab 0xc78789c0 944 1 0 0 S 0xc7878bf4 sh 6627fb2e8a4SMauro Carvalho Chehab (gdb) 6637fb2e8a4SMauro Carvalho Chehab 6647fb2e8a4SMauro Carvalho Chehabkgdb Test Suite 6657fb2e8a4SMauro Carvalho Chehab=============== 6667fb2e8a4SMauro Carvalho Chehab 6677fb2e8a4SMauro Carvalho ChehabWhen kgdb is enabled in the kernel config you can also elect to enable 668821c6df8SMauro Carvalho Chehabthe config parameter ``KGDB_TESTS``. Turning this on will enable a special 6697fb2e8a4SMauro Carvalho Chehabkgdb I/O module which is designed to test the kgdb internal functions. 6707fb2e8a4SMauro Carvalho Chehab 6717fb2e8a4SMauro Carvalho ChehabThe kgdb tests are mainly intended for developers to test the kgdb 6727fb2e8a4SMauro Carvalho Chehabinternals as well as a tool for developing a new kgdb architecture 6737fb2e8a4SMauro Carvalho Chehabspecific implementation. These tests are not really for end users of the 6747fb2e8a4SMauro Carvalho ChehabLinux kernel. The primary source of documentation would be to look in 675821c6df8SMauro Carvalho Chehabthe ``drivers/misc/kgdbts.c`` file. 6767fb2e8a4SMauro Carvalho Chehab 6777fb2e8a4SMauro Carvalho ChehabThe kgdb test suite can also be configured at compile time to run the 6787fb2e8a4SMauro Carvalho Chehabcore set of tests by setting the kernel config parameter 679821c6df8SMauro Carvalho Chehab``KGDB_TESTS_ON_BOOT``. This particular option is aimed at automated 6807fb2e8a4SMauro Carvalho Chehabregression testing and does not require modifying the kernel boot config 6817fb2e8a4SMauro Carvalho Chehabarguments. If this is turned on, the kgdb test suite can be disabled by 682821c6df8SMauro Carvalho Chehabspecifying ``kgdbts=`` as a kernel boot argument. 6837fb2e8a4SMauro Carvalho Chehab 6847fb2e8a4SMauro Carvalho ChehabKernel Debugger Internals 6857fb2e8a4SMauro Carvalho Chehab========================= 6867fb2e8a4SMauro Carvalho Chehab 6877fb2e8a4SMauro Carvalho ChehabArchitecture Specifics 6887fb2e8a4SMauro Carvalho Chehab---------------------- 6897fb2e8a4SMauro Carvalho Chehab 6907fb2e8a4SMauro Carvalho ChehabThe kernel debugger is organized into a number of components: 6917fb2e8a4SMauro Carvalho Chehab 6927fb2e8a4SMauro Carvalho Chehab1. The debug core 6937fb2e8a4SMauro Carvalho Chehab 694821c6df8SMauro Carvalho Chehab The debug core is found in ``kernel/debugger/debug_core.c``. It 6957fb2e8a4SMauro Carvalho Chehab contains: 6967fb2e8a4SMauro Carvalho Chehab 6977fb2e8a4SMauro Carvalho Chehab - A generic OS exception handler which includes sync'ing the 6987fb2e8a4SMauro Carvalho Chehab processors into a stopped state on an multi-CPU system. 6997fb2e8a4SMauro Carvalho Chehab 7007fb2e8a4SMauro Carvalho Chehab - The API to talk to the kgdb I/O drivers 7017fb2e8a4SMauro Carvalho Chehab 7027fb2e8a4SMauro Carvalho Chehab - The API to make calls to the arch-specific kgdb implementation 7037fb2e8a4SMauro Carvalho Chehab 7047fb2e8a4SMauro Carvalho Chehab - The logic to perform safe memory reads and writes to memory while 7057fb2e8a4SMauro Carvalho Chehab using the debugger 7067fb2e8a4SMauro Carvalho Chehab 7077fb2e8a4SMauro Carvalho Chehab - A full implementation for software breakpoints unless overridden 7087fb2e8a4SMauro Carvalho Chehab by the arch 7097fb2e8a4SMauro Carvalho Chehab 7107fb2e8a4SMauro Carvalho Chehab - The API to invoke either the kdb or kgdb frontend to the debug 7117fb2e8a4SMauro Carvalho Chehab core. 7127fb2e8a4SMauro Carvalho Chehab 7137fb2e8a4SMauro Carvalho Chehab - The structures and callback API for atomic kernel mode setting. 7147fb2e8a4SMauro Carvalho Chehab 715821c6df8SMauro Carvalho Chehab .. note:: kgdboc is where the kms callbacks are invoked. 7167fb2e8a4SMauro Carvalho Chehab 7177fb2e8a4SMauro Carvalho Chehab2. kgdb arch-specific implementation 7187fb2e8a4SMauro Carvalho Chehab 719821c6df8SMauro Carvalho Chehab This implementation is generally found in ``arch/*/kernel/kgdb.c``. As 720821c6df8SMauro Carvalho Chehab an example, ``arch/x86/kernel/kgdb.c`` contains the specifics to 7217fb2e8a4SMauro Carvalho Chehab implement HW breakpoint as well as the initialization to dynamically 7227fb2e8a4SMauro Carvalho Chehab register and unregister for the trap handlers on this architecture. 7237fb2e8a4SMauro Carvalho Chehab The arch-specific portion implements: 7247fb2e8a4SMauro Carvalho Chehab 7257fb2e8a4SMauro Carvalho Chehab - contains an arch-specific trap catcher which invokes 7262d88fc62SPuranjay Mohan kgdb_handle_exception() to start kgdb about doing its work 7277fb2e8a4SMauro Carvalho Chehab 728365ff56fSMauro Carvalho Chehab - translation to and from gdb specific packet format to struct pt_regs 7297fb2e8a4SMauro Carvalho Chehab 7307fb2e8a4SMauro Carvalho Chehab - Registration and unregistration of architecture specific trap 7317fb2e8a4SMauro Carvalho Chehab hooks 7327fb2e8a4SMauro Carvalho Chehab 7337fb2e8a4SMauro Carvalho Chehab - Any special exception handling and cleanup 7347fb2e8a4SMauro Carvalho Chehab 7357fb2e8a4SMauro Carvalho Chehab - NMI exception handling and cleanup 7367fb2e8a4SMauro Carvalho Chehab 7377fb2e8a4SMauro Carvalho Chehab - (optional) HW breakpoints 7387fb2e8a4SMauro Carvalho Chehab 7397fb2e8a4SMauro Carvalho Chehab3. gdbstub frontend (aka kgdb) 7407fb2e8a4SMauro Carvalho Chehab 741821c6df8SMauro Carvalho Chehab The gdbstub is located in ``kernel/debug/gdbstub.c``. It contains: 7427fb2e8a4SMauro Carvalho Chehab 7437fb2e8a4SMauro Carvalho Chehab - All the logic to implement the gdb serial protocol 7447fb2e8a4SMauro Carvalho Chehab 7457fb2e8a4SMauro Carvalho Chehab4. kdb frontend 7467fb2e8a4SMauro Carvalho Chehab 7477fb2e8a4SMauro Carvalho Chehab The kdb debugger shell is broken down into a number of components. 7487fb2e8a4SMauro Carvalho Chehab The kdb core is located in kernel/debug/kdb. There are a number of 7497fb2e8a4SMauro Carvalho Chehab helper functions in some of the other kernel components to make it 7507fb2e8a4SMauro Carvalho Chehab possible for kdb to examine and report information about the kernel 7517fb2e8a4SMauro Carvalho Chehab without taking locks that could cause a kernel deadlock. The kdb core 7527fb2e8a4SMauro Carvalho Chehab contains implements the following functionality. 7537fb2e8a4SMauro Carvalho Chehab 7547fb2e8a4SMauro Carvalho Chehab - A simple shell 7557fb2e8a4SMauro Carvalho Chehab 7567fb2e8a4SMauro Carvalho Chehab - The kdb core command set 7577fb2e8a4SMauro Carvalho Chehab 7587fb2e8a4SMauro Carvalho Chehab - A registration API to register additional kdb shell commands. 7597fb2e8a4SMauro Carvalho Chehab 760821c6df8SMauro Carvalho Chehab - A good example of a self-contained kdb module is the ``ftdump`` 7617fb2e8a4SMauro Carvalho Chehab command for dumping the ftrace buffer. See: 762821c6df8SMauro Carvalho Chehab ``kernel/trace/trace_kdb.c`` 7637fb2e8a4SMauro Carvalho Chehab 7647fb2e8a4SMauro Carvalho Chehab - For an example of how to dynamically register a new kdb command 7657fb2e8a4SMauro Carvalho Chehab you can build the kdb_hello.ko kernel module from 766821c6df8SMauro Carvalho Chehab ``samples/kdb/kdb_hello.c``. To build this example you can set 767821c6df8SMauro Carvalho Chehab ``CONFIG_SAMPLES=y`` and ``CONFIG_SAMPLE_KDB=m`` in your kernel 768821c6df8SMauro Carvalho Chehab config. Later run ``modprobe kdb_hello`` and the next time you 769821c6df8SMauro Carvalho Chehab enter the kdb shell, you can run the ``hello`` command. 7707fb2e8a4SMauro Carvalho Chehab 7712d88fc62SPuranjay Mohan - The implementation for kdb_printf() which emits messages directly 7727fb2e8a4SMauro Carvalho Chehab to I/O drivers, bypassing the kernel log. 7737fb2e8a4SMauro Carvalho Chehab 7747fb2e8a4SMauro Carvalho Chehab - SW / HW breakpoint management for the kdb shell 7757fb2e8a4SMauro Carvalho Chehab 7767fb2e8a4SMauro Carvalho Chehab5. kgdb I/O driver 7777fb2e8a4SMauro Carvalho Chehab 7787fb2e8a4SMauro Carvalho Chehab Each kgdb I/O driver has to provide an implementation for the 7797fb2e8a4SMauro Carvalho Chehab following: 7807fb2e8a4SMauro Carvalho Chehab 7817fb2e8a4SMauro Carvalho Chehab - configuration via built-in or module 7827fb2e8a4SMauro Carvalho Chehab 7837fb2e8a4SMauro Carvalho Chehab - dynamic configuration and kgdb hook registration calls 7847fb2e8a4SMauro Carvalho Chehab 7857fb2e8a4SMauro Carvalho Chehab - read and write character interface 7867fb2e8a4SMauro Carvalho Chehab 7877fb2e8a4SMauro Carvalho Chehab - A cleanup handler for unconfiguring from the kgdb core 7887fb2e8a4SMauro Carvalho Chehab 7897fb2e8a4SMauro Carvalho Chehab - (optional) Early debug methodology 7907fb2e8a4SMauro Carvalho Chehab 7917fb2e8a4SMauro Carvalho Chehab Any given kgdb I/O driver has to operate very closely with the 7927fb2e8a4SMauro Carvalho Chehab hardware and must do it in such a way that does not enable interrupts 7937fb2e8a4SMauro Carvalho Chehab or change other parts of the system context without completely 7947fb2e8a4SMauro Carvalho Chehab restoring them. The kgdb core will repeatedly "poll" a kgdb I/O 7957fb2e8a4SMauro Carvalho Chehab driver for characters when it needs input. The I/O driver is expected 7967fb2e8a4SMauro Carvalho Chehab to return immediately if there is no data available. Doing so allows 7977fb2e8a4SMauro Carvalho Chehab for the future possibility to touch watchdog hardware in such a way 7987fb2e8a4SMauro Carvalho Chehab as to have a target system not reset when these are enabled. 7997fb2e8a4SMauro Carvalho Chehab 8007fb2e8a4SMauro Carvalho ChehabIf you are intent on adding kgdb architecture specific support for a new 8017fb2e8a4SMauro Carvalho Chehabarchitecture, the architecture should define ``HAVE_ARCH_KGDB`` in the 8027fb2e8a4SMauro Carvalho Chehabarchitecture specific Kconfig file. This will enable kgdb for the 8037fb2e8a4SMauro Carvalho Chehabarchitecture, and at that point you must create an architecture specific 8047fb2e8a4SMauro Carvalho Chehabkgdb implementation. 8057fb2e8a4SMauro Carvalho Chehab 8067fb2e8a4SMauro Carvalho ChehabThere are a few flags which must be set on every architecture in their 807821c6df8SMauro Carvalho Chehab``asm/kgdb.h`` file. These are: 8087fb2e8a4SMauro Carvalho Chehab 809821c6df8SMauro Carvalho Chehab- ``NUMREGBYTES``: 810821c6df8SMauro Carvalho Chehab The size in bytes of all of the registers, so that we 8117fb2e8a4SMauro Carvalho Chehab can ensure they will all fit into a packet. 8127fb2e8a4SMauro Carvalho Chehab 813821c6df8SMauro Carvalho Chehab- ``BUFMAX``: 814821c6df8SMauro Carvalho Chehab The size in bytes of the buffer GDB will read into. This must 8157fb2e8a4SMauro Carvalho Chehab be larger than NUMREGBYTES. 8167fb2e8a4SMauro Carvalho Chehab 817821c6df8SMauro Carvalho Chehab- ``CACHE_FLUSH_IS_SAFE``: 818821c6df8SMauro Carvalho Chehab Set to 1 if it is always safe to call 8197fb2e8a4SMauro Carvalho Chehab flush_cache_range or flush_icache_range. On some architectures, 8207fb2e8a4SMauro Carvalho Chehab these functions may not be safe to call on SMP since we keep other 8217fb2e8a4SMauro Carvalho Chehab CPUs in a holding pattern. 8227fb2e8a4SMauro Carvalho Chehab 8237fb2e8a4SMauro Carvalho ChehabThere are also the following functions for the common backend, found in 824821c6df8SMauro Carvalho Chehab``kernel/kgdb.c``, that must be supplied by the architecture-specific 8257fb2e8a4SMauro Carvalho Chehabbackend unless marked as (optional), in which case a default function 8267fb2e8a4SMauro Carvalho Chehabmaybe used if the architecture does not need to provide a specific 8277fb2e8a4SMauro Carvalho Chehabimplementation. 8287fb2e8a4SMauro Carvalho Chehab 8297fb2e8a4SMauro Carvalho Chehab.. kernel-doc:: include/linux/kgdb.h 8307fb2e8a4SMauro Carvalho Chehab :internal: 8317fb2e8a4SMauro Carvalho Chehab 8327fb2e8a4SMauro Carvalho Chehabkgdboc internals 8337fb2e8a4SMauro Carvalho Chehab---------------- 8347fb2e8a4SMauro Carvalho Chehab 8357fb2e8a4SMauro Carvalho Chehabkgdboc and uarts 8367fb2e8a4SMauro Carvalho Chehab~~~~~~~~~~~~~~~~ 8377fb2e8a4SMauro Carvalho Chehab 8387fb2e8a4SMauro Carvalho ChehabThe kgdboc driver is actually a very thin driver that relies on the 8397fb2e8a4SMauro Carvalho Chehabunderlying low level to the hardware driver having "polling hooks" to 8407fb2e8a4SMauro Carvalho Chehabwhich the tty driver is attached. In the initial implementation of 8417fb2e8a4SMauro Carvalho Chehabkgdboc the serial_core was changed to expose a low level UART hook for 8427fb2e8a4SMauro Carvalho Chehabdoing polled mode reading and writing of a single character while in an 8437fb2e8a4SMauro Carvalho Chehabatomic context. When kgdb makes an I/O request to the debugger, kgdboc 8447fb2e8a4SMauro Carvalho Chehabinvokes a callback in the serial core which in turn uses the callback in 8457fb2e8a4SMauro Carvalho Chehabthe UART driver. 8467fb2e8a4SMauro Carvalho Chehab 8477fb2e8a4SMauro Carvalho ChehabWhen using kgdboc with a UART, the UART driver must implement two 848365ff56fSMauro Carvalho Chehabcallbacks in the struct uart_ops. 849821c6df8SMauro Carvalho ChehabExample from ``drivers/8250.c``:: 8507fb2e8a4SMauro Carvalho Chehab 8517fb2e8a4SMauro Carvalho Chehab 8527fb2e8a4SMauro Carvalho Chehab #ifdef CONFIG_CONSOLE_POLL 8537fb2e8a4SMauro Carvalho Chehab .poll_get_char = serial8250_get_poll_char, 8547fb2e8a4SMauro Carvalho Chehab .poll_put_char = serial8250_put_poll_char, 8557fb2e8a4SMauro Carvalho Chehab #endif 8567fb2e8a4SMauro Carvalho Chehab 8577fb2e8a4SMauro Carvalho Chehab 8587fb2e8a4SMauro Carvalho ChehabAny implementation specifics around creating a polling driver use the 8597fb2e8a4SMauro Carvalho Chehab``#ifdef CONFIG_CONSOLE_POLL``, as shown above. Keep in mind that 8607fb2e8a4SMauro Carvalho Chehabpolling hooks have to be implemented in such a way that they can be 8617fb2e8a4SMauro Carvalho Chehabcalled from an atomic context and have to restore the state of the UART 8627fb2e8a4SMauro Carvalho Chehabchip on return such that the system can return to normal when the 8637fb2e8a4SMauro Carvalho Chehabdebugger detaches. You need to be very careful with any kind of lock you 8647fb2e8a4SMauro Carvalho Chehabconsider, because failing here is most likely going to mean pressing the 8657fb2e8a4SMauro Carvalho Chehabreset button. 8667fb2e8a4SMauro Carvalho Chehab 8677fb2e8a4SMauro Carvalho Chehabkgdboc and keyboards 868821c6df8SMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~~~~~~~ 8697fb2e8a4SMauro Carvalho Chehab 8707fb2e8a4SMauro Carvalho ChehabThe kgdboc driver contains logic to configure communications with an 8717fb2e8a4SMauro Carvalho Chehabattached keyboard. The keyboard infrastructure is only compiled into the 872821c6df8SMauro Carvalho Chehabkernel when ``CONFIG_KDB_KEYBOARD=y`` is set in the kernel configuration. 8737fb2e8a4SMauro Carvalho Chehab 87406467a78SRandy DunlapThe core polled keyboard driver for PS/2 type keyboards is in 875821c6df8SMauro Carvalho Chehab``drivers/char/kdb_keyboard.c``. This driver is hooked into the debug core 8767fb2e8a4SMauro Carvalho Chehabwhen kgdboc populates the callback in the array called 877365ff56fSMauro Carvalho Chehab:c:expr:`kdb_poll_funcs[]`. The kdb_get_kbd_char() is the top-level 8787fb2e8a4SMauro Carvalho Chehabfunction which polls hardware for single character input. 8797fb2e8a4SMauro Carvalho Chehab 8807fb2e8a4SMauro Carvalho Chehabkgdboc and kms 881821c6df8SMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~ 8827fb2e8a4SMauro Carvalho Chehab 8837fb2e8a4SMauro Carvalho ChehabThe kgdboc driver contains logic to request the graphics display to 884821c6df8SMauro Carvalho Chehabswitch to a text context when you are using ``kgdboc=kms,kbd``, provided 8857fb2e8a4SMauro Carvalho Chehabthat you have a video driver which has a frame buffer console and atomic 8867fb2e8a4SMauro Carvalho Chehabkernel mode setting support. 8877fb2e8a4SMauro Carvalho Chehab 8887fb2e8a4SMauro Carvalho ChehabEvery time the kernel debugger is entered it calls 8892d88fc62SPuranjay Mohankgdboc_pre_exp_handler() which in turn calls con_debug_enter() 890821c6df8SMauro Carvalho Chehabin the virtual console layer. On resuming kernel execution, the kernel 8912d88fc62SPuranjay Mohandebugger calls kgdboc_post_exp_handler() which in turn calls 8922d88fc62SPuranjay Mohancon_debug_leave(). 8937fb2e8a4SMauro Carvalho Chehab 8947fb2e8a4SMauro Carvalho ChehabAny video driver that wants to be compatible with the kernel debugger 895821c6df8SMauro Carvalho Chehaband the atomic kms callbacks must implement the ``mode_set_base_atomic``, 896821c6df8SMauro Carvalho Chehab``fb_debug_enter`` and ``fb_debug_leave operations``. For the 897821c6df8SMauro Carvalho Chehab``fb_debug_enter`` and ``fb_debug_leave`` the option exists to use the 8987fb2e8a4SMauro Carvalho Chehabgeneric drm fb helper functions or implement something custom for the 8997fb2e8a4SMauro Carvalho Chehabhardware. The following example shows the initialization of the 9007fb2e8a4SMauro Carvalho Chehab.mode_set_base_atomic operation in 901821c6df8SMauro Carvalho Chehabdrivers/gpu/drm/i915/intel_display.c:: 9027fb2e8a4SMauro Carvalho Chehab 9037fb2e8a4SMauro Carvalho Chehab 9047fb2e8a4SMauro Carvalho Chehab static const struct drm_crtc_helper_funcs intel_helper_funcs = { 9057fb2e8a4SMauro Carvalho Chehab [...] 9067fb2e8a4SMauro Carvalho Chehab .mode_set_base_atomic = intel_pipe_set_base_atomic, 9077fb2e8a4SMauro Carvalho Chehab [...] 9087fb2e8a4SMauro Carvalho Chehab }; 9097fb2e8a4SMauro Carvalho Chehab 9107fb2e8a4SMauro Carvalho Chehab 9117fb2e8a4SMauro Carvalho ChehabHere is an example of how the i915 driver initializes the 9127fb2e8a4SMauro Carvalho Chehabfb_debug_enter and fb_debug_leave functions to use the generic drm 913821c6df8SMauro Carvalho Chehabhelpers in ``drivers/gpu/drm/i915/intel_fb.c``:: 9147fb2e8a4SMauro Carvalho Chehab 9157fb2e8a4SMauro Carvalho Chehab 9167fb2e8a4SMauro Carvalho Chehab static struct fb_ops intelfb_ops = { 9177fb2e8a4SMauro Carvalho Chehab [...] 9187fb2e8a4SMauro Carvalho Chehab .fb_debug_enter = drm_fb_helper_debug_enter, 9197fb2e8a4SMauro Carvalho Chehab .fb_debug_leave = drm_fb_helper_debug_leave, 9207fb2e8a4SMauro Carvalho Chehab [...] 9217fb2e8a4SMauro Carvalho Chehab }; 9227fb2e8a4SMauro Carvalho Chehab 9237fb2e8a4SMauro Carvalho Chehab 9247fb2e8a4SMauro Carvalho ChehabCredits 9257fb2e8a4SMauro Carvalho Chehab======= 9267fb2e8a4SMauro Carvalho Chehab 9277fb2e8a4SMauro Carvalho ChehabThe following people have contributed to this document: 9287fb2e8a4SMauro Carvalho Chehab 929821c6df8SMauro Carvalho Chehab1. Amit Kale <amitkale@linsyssoft.com> 9307fb2e8a4SMauro Carvalho Chehab 931821c6df8SMauro Carvalho Chehab2. Tom Rini <trini@kernel.crashing.org> 9327fb2e8a4SMauro Carvalho Chehab 9337fb2e8a4SMauro Carvalho ChehabIn March 2008 this document was completely rewritten by: 9347fb2e8a4SMauro Carvalho Chehab 935821c6df8SMauro Carvalho Chehab- Jason Wessel <jason.wessel@windriver.com> 9367fb2e8a4SMauro Carvalho Chehab 9377fb2e8a4SMauro Carvalho ChehabIn Jan 2010 this document was updated to include kdb. 9387fb2e8a4SMauro Carvalho Chehab 939821c6df8SMauro Carvalho Chehab- Jason Wessel <jason.wessel@windriver.com> 940