Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 1 | ================================================= |
| 2 | Using kgdb, kdb and the kernel debugger internals |
| 3 | ================================================= |
| 4 | |
| 5 | :Author: Jason Wessel |
| 6 | |
| 7 | Introduction |
| 8 | ============ |
| 9 | |
| 10 | The kernel has two different debugger front ends (kdb and kgdb) which |
| 11 | interface to the debug core. It is possible to use either of the |
| 12 | debugger front ends and dynamically transition between them if you |
| 13 | configure the kernel properly at compile and runtime. |
| 14 | |
| 15 | Kdb is simplistic shell-style interface which you can use on a system |
| 16 | console with a keyboard or serial console. You can use it to inspect |
| 17 | memory, registers, process lists, dmesg, and even set breakpoints to |
| 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 |
| 23 | ``CONFIG_KALLSYMS``. |
| 24 | |
| 25 | Kgdb is intended to be used as a source level debugger for the Linux |
| 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 |
| 28 | inspect memory, variables and look through call stack information |
| 29 | similar to the way an application developer would use gdb to debug an |
| 30 | application. It is possible to place breakpoints in kernel code and |
| 31 | perform some limited execution stepping. |
| 32 | |
| 33 | Two machines are required for using kgdb. One of these machines is a |
| 34 | development machine and the other is the target machine. The kernel to |
| 35 | be debugged runs on the target machine. The development machine runs an |
| 36 | instance of gdb against the vmlinux file which contains the symbols (not |
| 37 | a boot image such as bzImage, zImage, uImage...). In gdb the developer |
| 38 | specifies the connection parameters and connects to kgdb. The type of |
| 39 | connection a developer makes with gdb depends on the availability of |
| 40 | kgdb I/O modules compiled as built-ins or loadable kernel modules in the |
| 41 | test machine's kernel. |
| 42 | |
| 43 | Compiling a kernel |
| 44 | ================== |
| 45 | |
| 46 | - In order to enable compilation of kdb, you must first enable kgdb. |
| 47 | |
| 48 | - The kgdb test compile options are described in the kgdb test suite |
| 49 | chapter. |
| 50 | |
| 51 | Kernel config options for kgdb |
| 52 | ------------------------------ |
| 53 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 54 | To enable ``CONFIG_KGDB`` you should look under |
| 55 | :menuselection:`Kernel hacking --> Kernel debugging` and select |
| 56 | :menuselection:`KGDB: kernel debugger`. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 57 | |
| 58 | While it is not a hard requirement that you have symbols in your vmlinux |
| 59 | file, gdb tends not to be very useful without the symbolic data, so you |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 60 | will want to turn on ``CONFIG_DEBUG_INFO`` which is called |
| 61 | :menuselection:`Compile the kernel with debug info` in the config menu. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 62 | |
| 63 | It is advised, but not required, that you turn on the |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 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 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 66 | to into the compiled executable which saves the frame information in |
| 67 | registers or on the stack at different points which allows a debugger |
| 68 | such as gdb to more accurately construct stack back traces while |
| 69 | debugging the kernel. |
| 70 | |
| 71 | If the architecture that you are using supports the kernel option |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 72 | ``CONFIG_STRICT_KERNEL_RWX``, you should consider turning it off. This |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 73 | option will prevent the use of software breakpoints because it marks |
| 74 | certain regions of the kernel's memory space as read-only. If kgdb |
| 75 | supports it for the architecture you are using, you can use hardware |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 76 | breakpoints if you desire to run with the ``CONFIG_STRICT_KERNEL_RWX`` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 77 | option turned on, else you need to turn off this option. |
| 78 | |
| 79 | Next you should choose one of more I/O drivers to interconnect debugging |
| 80 | host and debugged target. Early boot debugging requires a KGDB I/O |
| 81 | driver that supports early debugging and the driver must be built into |
| 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 |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 84 | section that describes the parameter kgdboc. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 85 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 86 | Here is an example set of ``.config`` symbols to enable or disable for kgdb:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 87 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 88 | # CONFIG_STRICT_KERNEL_RWX is not set |
| 89 | CONFIG_FRAME_POINTER=y |
| 90 | CONFIG_KGDB=y |
| 91 | CONFIG_KGDB_SERIAL_CONSOLE=y |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 92 | |
| 93 | Kernel config options for kdb |
| 94 | ----------------------------- |
| 95 | |
| 96 | Kdb is quite a bit more complex than the simple gdbstub sitting on top |
| 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 |
| 99 | printing out interesting data such as what you would see if you ran |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 100 | ``lsmod``, or ``ps``. In order to build kdb into the kernel you follow the |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 101 | same steps as you would for kgdb. |
| 102 | |
| 103 | The main config option for kdb is ``CONFIG_KGDB_KDB`` which is called |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 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 |
| 106 | ``CONFIG_KGDB_SERIAL_CONSOLE`` interface if you plan on using kdb on a |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 107 | serial port, when you were configuring kgdb. |
| 108 | |
| 109 | If you want to use a PS/2-style keyboard with kdb, you would select |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 110 | ``CONFIG_KDB_KEYBOARD`` which is called :menuselection:`KGDB_KDB: keyboard as |
| 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`` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 113 | option only works with kdb. |
| 114 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 115 | Here is an example set of ``.config`` symbols to enable/disable kdb:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 116 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 117 | # CONFIG_STRICT_KERNEL_RWX is not set |
| 118 | CONFIG_FRAME_POINTER=y |
| 119 | CONFIG_KGDB=y |
| 120 | CONFIG_KGDB_SERIAL_CONSOLE=y |
| 121 | CONFIG_KGDB_KDB=y |
| 122 | CONFIG_KDB_KEYBOARD=y |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 123 | |
| 124 | Kernel Debugger Boot Arguments |
| 125 | ============================== |
| 126 | |
| 127 | This section describes the various runtime kernel parameters that affect |
| 128 | the configuration of the kernel debugger. The following chapter covers |
| 129 | using kdb and kgdb as well as providing some examples of the |
| 130 | configuration parameters. |
| 131 | |
| 132 | Kernel parameter: kgdboc |
| 133 | ------------------------ |
| 134 | |
| 135 | The kgdboc driver was originally an abbreviation meant to stand for |
| 136 | "kgdb over console". Today it is the primary mechanism to configure how |
| 137 | to communicate from gdb to kgdb as well as the devices you want to use |
| 138 | to interact with the kdb shell. |
| 139 | |
| 140 | For kgdb/gdb, kgdboc is designed to work with a single serial port. It |
| 141 | is intended to cover the circumstance where you want to use a serial |
| 142 | console as your primary console as well as using it to perform kernel |
| 143 | debugging. It is also possible to use kgdb on a serial port which is not |
| 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. |
| 148 | |
| 149 | Optionally you can elect to activate kms (Kernel Mode Setting) |
| 150 | integration. When you use kms with kgdboc and you have a video driver |
| 151 | that has atomic mode setting hooks, it is possible to enter the debugger |
| 152 | on the graphics console. When the kernel execution is resumed, the |
| 153 | previous graphics mode will be restored. This integration can serve as a |
| 154 | useful tool to aid in diagnosing crashes or doing analysis of memory |
| 155 | with kdb while allowing the full graphics console applications to run. |
| 156 | |
| 157 | kgdboc arguments |
| 158 | ~~~~~~~~~~~~~~~~ |
| 159 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 160 | Usage:: |
| 161 | |
| 162 | kgdboc=[kms][[,]kbd][[,]serial_device][,baud] |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 163 | |
| 164 | The order listed above must be observed if you use any of the optional |
| 165 | configurations together. |
| 166 | |
| 167 | Abbreviations: |
| 168 | |
| 169 | - kms = Kernel Mode Setting |
| 170 | |
| 171 | - kbd = Keyboard |
| 172 | |
| 173 | You can configure kgdboc to use the keyboard, and/or a serial device |
| 174 | depending on if you are using kdb and/or kgdb, in one of the following |
| 175 | scenarios. The order listed above must be observed if you use any of the |
| 176 | optional configurations together. Using kms + only gdb is generally not |
| 177 | a useful combination. |
| 178 | |
| 179 | Using loadable module or built-in |
| 180 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 181 | |
| 182 | 1. As a kernel built-in: |
| 183 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 184 | Use the kernel boot argument:: |
| 185 | |
| 186 | kgdboc=<tty-device>,[baud] |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 187 | |
| 188 | 2. As a kernel loadable module: |
| 189 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 190 | Use the command:: |
| 191 | |
| 192 | modprobe kgdboc kgdboc=<tty-device>,[baud] |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 193 | |
| 194 | Here are two examples of how you might format the kgdboc string. The |
| 195 | first is for an x86 target using the first serial port. The second |
| 196 | example is for the ARM Versatile AB using the second serial port. |
| 197 | |
| 198 | 1. ``kgdboc=ttyS0,115200`` |
| 199 | |
| 200 | 2. ``kgdboc=ttyAMA1,115200`` |
| 201 | |
| 202 | Configure kgdboc at runtime with sysfs |
| 203 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 204 | |
| 205 | At run time you can enable or disable kgdboc by echoing a parameters |
| 206 | into the sysfs. Here are two examples: |
| 207 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 208 | 1. Enable kgdboc on ttyS0:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 209 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 210 | echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 211 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 212 | 2. Disable kgdboc:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 213 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 214 | echo "" > /sys/module/kgdboc/parameters/kgdboc |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 215 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 216 | .. note:: |
| 217 | |
| 218 | You do not need to specify the baud if you are configuring the |
| 219 | console on tty which is already configured or open. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 220 | |
| 221 | More examples |
| 222 | ^^^^^^^^^^^^^ |
| 223 | |
| 224 | You can configure kgdboc to use the keyboard, and/or a serial device |
| 225 | depending on if you are using kdb and/or kgdb, in one of the following |
| 226 | scenarios. |
| 227 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 228 | 1. kdb and kgdb over only a serial port:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 229 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 230 | kgdboc=<serial_device>[,baud] |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 231 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 232 | Example:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 233 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 234 | kgdboc=ttyS0,115200 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 235 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 236 | 2. kdb and kgdb with keyboard and a serial port:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 237 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 238 | kgdboc=kbd,<serial_device>[,baud] |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 239 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 240 | Example:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 241 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 242 | kgdboc=kbd,ttyS0,115200 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 243 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 244 | 3. kdb with a keyboard:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 245 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 246 | kgdboc=kbd |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 247 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 248 | 4. kdb with kernel mode setting:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 249 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 250 | kgdboc=kms,kbd |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 251 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 252 | 5. kdb with kernel mode setting and kgdb over a serial port:: |
| 253 | |
| 254 | kgdboc=kms,kbd,ttyS0,115200 |
| 255 | |
| 256 | .. note:: |
| 257 | |
| 258 | Kgdboc does not support interrupting the target via the gdb remote |
| 259 | protocol. You must manually send a :kbd:`SysRq-G` unless you have a proxy |
| 260 | that splits console output to a terminal program. A console proxy has a |
| 261 | separate TCP port for the debugger and a separate TCP port for the |
| 262 | "human" console. The proxy can take care of sending the :kbd:`SysRq-G` |
| 263 | for you. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 264 | |
| 265 | When using kgdboc with no debugger proxy, you can end up connecting the |
| 266 | debugger at one of two entry points. If an exception occurs after you |
| 267 | have loaded kgdboc, a message should print on the console stating it is |
| 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 |
| 270 | interrupt the target system and forcibly enter a debug session you have |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 271 | to issue a :kbd:`Sysrq` sequence and then type the letter :kbd:`g`. Then you |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 272 | disconnect the terminal session and connect gdb. Your options if you |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 273 | don't like this are to hack gdb to send the :kbd:`SysRq-G` for you as well as |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 274 | on the initial connect, or to use a debugger proxy that allows an |
| 275 | unmodified gdb to do the debugging. |
| 276 | |
Douglas Anderson | f71fc3b | 2020-05-07 13:08:47 -0700 | [diff] [blame] | 277 | Kernel parameter: ``kgdboc_earlycon`` |
| 278 | ------------------------------------- |
| 279 | |
| 280 | If you specify the kernel parameter ``kgdboc_earlycon`` and your serial |
| 281 | driver registers a boot console that supports polling (doesn't need |
| 282 | interrupts and implements a nonblocking read() function) kgdb will attempt |
| 283 | to work using the boot console until it can transition to the regular |
| 284 | tty driver specified by the ``kgdboc`` parameter. |
| 285 | |
| 286 | Normally there is only one boot console (especially that implements the |
| 287 | read() function) so just adding ``kgdboc_earlycon`` on its own is |
| 288 | sufficient to make this work. If you have more than one boot console you |
| 289 | can add the boot console's name to differentiate. Note that names that |
| 290 | are registered through the boot console layer and the tty layer are not |
| 291 | the same for the same port. |
| 292 | |
| 293 | For instance, on one board to be explicit you might do:: |
| 294 | |
| 295 | kgdboc_earlycon=qcom_geni kgdboc=ttyMSM0 |
| 296 | |
| 297 | If the only boot console on the device was "qcom_geni", you could simplify:: |
| 298 | |
| 299 | kgdboc_earlycon kgdboc=ttyMSM0 |
| 300 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 301 | Kernel parameter: ``kgdbwait`` |
| 302 | ------------------------------ |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 303 | |
| 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. |
| 308 | The kgdbwait parameter should always follow the configuration parameter |
| 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. |
| 311 | |
| 312 | The kernel will stop and wait as early as the I/O driver and |
| 313 | architecture allows when you use this option. If you build the kgdb I/O |
| 314 | driver as a loadable kernel module kgdbwait will not do anything. |
| 315 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 316 | Kernel parameter: ``kgdbcon`` |
| 317 | ----------------------------- |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 318 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 319 | The ``kgdbcon`` feature allows you to see :c:func:`printk` messages inside gdb |
| 320 | while gdb is connected to the kernel. Kdb does not make use of the kgdbcon |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 321 | feature. |
| 322 | |
| 323 | Kgdb supports using the gdb serial protocol to send console messages to |
| 324 | the debugger when the debugger is connected and running. There are two |
| 325 | ways to activate this feature. |
| 326 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 327 | 1. Activate with the kernel command line option:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 328 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 329 | kgdbcon |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 330 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 331 | 2. Use sysfs before configuring an I/O driver:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 332 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 333 | echo 1 > /sys/module/kgdb/parameters/kgdb_use_con |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 334 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 335 | .. note:: |
| 336 | |
| 337 | If you do this after you configure the kgdb I/O driver, the |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 338 | setting will not take effect until the next point the I/O is |
| 339 | reconfigured. |
| 340 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 341 | .. important:: |
| 342 | |
| 343 | You cannot use kgdboc + kgdbcon on a tty that is an |
| 344 | active system console. An example of incorrect usage is:: |
| 345 | |
| 346 | console=ttyS0,115200 kgdboc=ttyS0 kgdbcon |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 347 | |
| 348 | It is possible to use this option with kgdboc on a tty that is not a |
| 349 | system console. |
| 350 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 351 | Run time parameter: ``kgdbreboot`` |
| 352 | ---------------------------------- |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 353 | |
| 354 | The kgdbreboot feature allows you to change how the debugger deals with |
| 355 | the reboot notification. You have 3 choices for the behavior. The |
| 356 | default behavior is always set to 0. |
| 357 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 358 | .. tabularcolumns:: |p{0.4cm}|p{11.5cm}|p{5.6cm}| |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 359 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 360 | .. flat-table:: |
| 361 | :widths: 1 10 8 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 362 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 363 | * - 1 |
| 364 | - ``echo -1 > /sys/module/debug_core/parameters/kgdbreboot`` |
| 365 | - Ignore the reboot notification entirely. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 366 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 367 | * - 2 |
| 368 | - ``echo 0 > /sys/module/debug_core/parameters/kgdbreboot`` |
| 369 | - Send the detach message to any attached debugger client. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 370 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 371 | * - 3 |
| 372 | - ``echo 1 > /sys/module/debug_core/parameters/kgdbreboot`` |
| 373 | - Enter the debugger on reboot notify. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 374 | |
Zhouyi Zhou | 14994a9 | 2017-07-07 15:11:46 +0800 | [diff] [blame] | 375 | Kernel parameter: ``nokaslr`` |
| 376 | ----------------------------- |
| 377 | |
| 378 | If the architecture that you are using enable KASLR by default, |
| 379 | you should consider turning it off. KASLR randomizes the |
| 380 | virtual address where the kernel image is mapped and confuse |
| 381 | gdb which resolve kernel symbol address from symbol table |
| 382 | of vmlinux. |
| 383 | |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 384 | Using kdb |
| 385 | ========= |
| 386 | |
| 387 | Quick start for kdb on a serial port |
| 388 | ------------------------------------ |
| 389 | |
| 390 | This is a quick example of how to use kdb. |
| 391 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 392 | 1. Configure kgdboc at boot using kernel parameters:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 393 | |
Zhouyi Zhou | 14994a9 | 2017-07-07 15:11:46 +0800 | [diff] [blame] | 394 | console=ttyS0,115200 kgdboc=ttyS0,115200 nokaslr |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 395 | |
| 396 | OR |
| 397 | |
| 398 | Configure kgdboc after the kernel has booted; assuming you are using |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 399 | a serial port console:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 400 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 401 | echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 402 | |
| 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 |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 405 | manually; all involve using the :kbd:`SysRq-G`, which means you must have |
| 406 | enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 407 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 408 | - When logged in as root or with a super user session you can run:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 409 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 410 | echo g > /proc/sysrq-trigger |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 411 | |
| 412 | - Example using minicom 2.2 |
| 413 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 414 | Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 415 | |
| 416 | - When you have telneted to a terminal server that supports sending |
| 417 | a remote break |
| 418 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 419 | Press: :kbd:`CTRL-]` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 420 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 421 | Type in: ``send break`` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 422 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 423 | Press: :kbd:`Enter` :kbd:`g` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 424 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 425 | 3. From the kdb prompt you can run the ``help`` command to see a complete |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 426 | list of the commands that are available. |
| 427 | |
| 428 | Some useful commands in kdb include: |
| 429 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 430 | =========== ================================================================= |
| 431 | ``lsmod`` Shows where kernel modules are loaded |
| 432 | ``ps`` Displays only the active processes |
| 433 | ``ps A`` Shows all the processes |
| 434 | ``summary`` Shows kernel version info and memory usage |
| 435 | ``bt`` Get a backtrace of the current process using :c:func:`dump_stack` |
| 436 | ``dmesg`` View the kernel syslog buffer |
| 437 | ``go`` Continue the system |
| 438 | =========== ================================================================= |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 439 | |
| 440 | 4. When you are done using kdb you need to consider rebooting the system |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 441 | or using the ``go`` command to resuming normal kernel execution. If you |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 442 | have paused the kernel for a lengthy period of time, applications |
| 443 | that rely on timely networking or anything to do with real wall clock |
| 444 | time could be adversely affected, so you should take this into |
| 445 | consideration when using the kernel debugger. |
| 446 | |
| 447 | Quick start for kdb using a keyboard connected console |
| 448 | ------------------------------------------------------ |
| 449 | |
| 450 | This is a quick example of how to use kdb with a keyboard. |
| 451 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 452 | 1. Configure kgdboc at boot using kernel parameters:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 453 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 454 | kgdboc=kbd |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 455 | |
| 456 | OR |
| 457 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 458 | Configure kgdboc after the kernel has booted:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 459 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 460 | echo kbd > /sys/module/kgdboc/parameters/kgdboc |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 461 | |
| 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 |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 464 | manually; all involve using the :kbd:`SysRq-G`, which means you must have |
| 465 | enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 466 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 467 | - When logged in as root or with a super user session you can run:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 468 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 469 | echo g > /proc/sysrq-trigger |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 470 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 471 | - Example using a laptop keyboard: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 472 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 473 | Press and hold down: :kbd:`Alt` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 474 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 475 | Press and hold down: :kbd:`Fn` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 476 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 477 | Press and release the key with the label: :kbd:`SysRq` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 478 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 479 | Release: :kbd:`Fn` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 480 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 481 | Press and release: :kbd:`g` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 482 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 483 | Release: :kbd:`Alt` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 484 | |
| 485 | - Example using a PS/2 101-key keyboard |
| 486 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 487 | Press and hold down: :kbd:`Alt` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 488 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 489 | Press and release the key with the label: :kbd:`SysRq` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 490 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 491 | Press and release: :kbd:`g` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 492 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 493 | Release: :kbd:`Alt` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 494 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 495 | 3. Now type in a kdb command such as ``help``, ``dmesg``, ``bt`` or ``go`` to |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 496 | continue kernel execution. |
| 497 | |
| 498 | Using kgdb / gdb |
| 499 | ================ |
| 500 | |
| 501 | In order to use kgdb you must activate it by passing configuration |
| 502 | information to one of the kgdb I/O drivers. If you do not pass any |
| 503 | configuration information kgdb will not do anything at all. Kgdb will |
| 504 | only actively hook up to the kernel trap hooks if a kgdb I/O driver is |
| 505 | loaded and configured. If you unconfigure a kgdb I/O driver, kgdb will |
| 506 | unregister all the kernel hook points. |
| 507 | |
| 508 | All kgdb I/O drivers can be reconfigured at run time, if |
| 509 | ``CONFIG_SYSFS`` and ``CONFIG_MODULES`` are enabled, by echo'ing a new |
| 510 | config string to ``/sys/module/<driver>/parameter/<option>``. The driver |
| 511 | can be unconfigured by passing an empty string. You cannot change the |
| 512 | configuration while the debugger is attached. Make sure to detach the |
| 513 | debugger with the ``detach`` command prior to trying to unconfigure a |
| 514 | kgdb I/O driver. |
| 515 | |
| 516 | Connecting with gdb to a serial port |
| 517 | ------------------------------------ |
| 518 | |
| 519 | 1. Configure kgdboc |
| 520 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 521 | Configure kgdboc at boot using kernel parameters:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 522 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 523 | kgdboc=ttyS0,115200 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 524 | |
| 525 | OR |
| 526 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 527 | Configure kgdboc after the kernel has booted:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 528 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 529 | echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 530 | |
| 531 | 2. Stop kernel execution (break into the debugger) |
| 532 | |
| 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 |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 535 | using kgdbwait as a boot argument, via a :kbd:`SysRq-G`, or running the |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 536 | kernel until it takes an exception where it waits for the debugger to |
| 537 | attach. |
| 538 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 539 | - When logged in as root or with a super user session you can run:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 540 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 541 | echo g > /proc/sysrq-trigger |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 542 | |
| 543 | - Example using minicom 2.2 |
| 544 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 545 | Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 546 | |
| 547 | - When you have telneted to a terminal server that supports sending |
| 548 | a remote break |
| 549 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 550 | Press: :kbd:`CTRL-]` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 551 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 552 | Type in: ``send break`` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 553 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 554 | Press: :kbd:`Enter` :kbd:`g` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 555 | |
| 556 | 3. Connect from gdb |
| 557 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 558 | Example (using a directly connected port):: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 559 | |
| 560 | % gdb ./vmlinux |
| 561 | (gdb) set remotebaud 115200 |
| 562 | (gdb) target remote /dev/ttyS0 |
| 563 | |
| 564 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 565 | Example (kgdb to a terminal server on TCP port 2012):: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 566 | |
| 567 | % gdb ./vmlinux |
| 568 | (gdb) target remote 192.168.2.2:2012 |
| 569 | |
| 570 | |
| 571 | Once connected, you can debug a kernel the way you would debug an |
| 572 | application program. |
| 573 | |
| 574 | If you are having problems connecting or something is going seriously |
| 575 | wrong while debugging, it will most often be the case that you want |
| 576 | to enable gdb to be verbose about its target communications. You do |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 577 | this prior to issuing the ``target remote`` command by typing in:: |
| 578 | |
| 579 | set debug remote 1 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 580 | |
| 581 | Remember if you continue in gdb, and need to "break in" again, you need |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 582 | to issue an other :kbd:`SysRq-G`. It is easy to create a simple entry point by |
| 583 | putting a breakpoint at ``sys_sync`` and then you can run ``sync`` from a |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 584 | shell or script to break into the debugger. |
| 585 | |
| 586 | kgdb and kdb interoperability |
| 587 | ============================= |
| 588 | |
| 589 | It is possible to transition between kdb and kgdb dynamically. The debug |
| 590 | core will remember which you used the last time and automatically start |
| 591 | in the same mode. |
| 592 | |
| 593 | Switching between kdb and kgdb |
| 594 | ------------------------------ |
| 595 | |
| 596 | Switching from kgdb to kdb |
| 597 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 598 | |
| 599 | There are two ways to switch from kgdb to kdb: you can use gdb to issue |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 600 | a maintenance packet, or you can blindly type the command ``$3#33``. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 601 | Whenever the kernel debugger stops in kgdb mode it will print the |
| 602 | message ``KGDB or $3#33 for KDB``. It is important to note that you have |
| 603 | to type the sequence correctly in one pass. You cannot type a backspace |
| 604 | or delete because kgdb will interpret that as part of the debug stream. |
| 605 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 606 | 1. Change from kgdb to kdb by blindly typing:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 607 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 608 | $3#33 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 609 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 610 | 2. Change from kgdb to kdb with gdb:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 611 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 612 | maintenance packet 3 |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 613 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 614 | .. note:: |
| 615 | |
| 616 | Now you must kill gdb. Typically you press :kbd:`CTRL-Z` and issue |
| 617 | the command:: |
| 618 | |
| 619 | kill -9 % |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 620 | |
| 621 | Change from kdb to kgdb |
| 622 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 623 | |
| 624 | There are two ways you can change from kdb to kgdb. You can manually |
| 625 | enter kgdb mode by issuing the kgdb command from the kdb shell prompt, |
| 626 | or you can connect gdb while the kdb shell prompt is active. The kdb |
| 627 | shell looks for the typical first commands that gdb would issue with the |
| 628 | gdb remote protocol and if it sees one of those commands it |
| 629 | automatically changes into kgdb mode. |
| 630 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 631 | 1. From kdb issue the command:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 632 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 633 | kgdb |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 634 | |
| 635 | Now disconnect your terminal program and connect gdb in its place |
| 636 | |
| 637 | 2. At the kdb prompt, disconnect the terminal program and connect gdb in |
| 638 | its place. |
| 639 | |
| 640 | Running kdb commands from gdb |
| 641 | ----------------------------- |
| 642 | |
| 643 | It is possible to run a limited set of kdb commands from gdb, using the |
| 644 | gdb monitor command. You don't want to execute any of the run control or |
| 645 | breakpoint operations, because it can disrupt the state of the kernel |
| 646 | debugger. You should be using gdb for breakpoints and run control |
| 647 | operations if you have gdb connected. The more useful commands to run |
| 648 | are things like lsmod, dmesg, ps or possibly some of the memory |
| 649 | information commands. To see all the kdb commands you can run |
| 650 | ``monitor help``. |
| 651 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 652 | Example:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 653 | |
| 654 | (gdb) monitor ps |
| 655 | 1 idle process (state I) and |
| 656 | 27 sleeping system daemon (state M) processes suppressed, |
| 657 | use 'ps A' to see all. |
| 658 | Task Addr Pid Parent [*] cpu State Thread Command |
| 659 | |
| 660 | 0xc78291d0 1 0 0 0 S 0xc7829404 init |
| 661 | 0xc7954150 942 1 0 0 S 0xc7954384 dropbear |
| 662 | 0xc78789c0 944 1 0 0 S 0xc7878bf4 sh |
| 663 | (gdb) |
| 664 | |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 665 | kgdb Test Suite |
| 666 | =============== |
| 667 | |
| 668 | When kgdb is enabled in the kernel config you can also elect to enable |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 669 | the config parameter ``KGDB_TESTS``. Turning this on will enable a special |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 670 | kgdb I/O module which is designed to test the kgdb internal functions. |
| 671 | |
| 672 | The kgdb tests are mainly intended for developers to test the kgdb |
| 673 | internals as well as a tool for developing a new kgdb architecture |
| 674 | specific implementation. These tests are not really for end users of the |
| 675 | Linux kernel. The primary source of documentation would be to look in |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 676 | the ``drivers/misc/kgdbts.c`` file. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 677 | |
| 678 | The kgdb test suite can also be configured at compile time to run the |
| 679 | core set of tests by setting the kernel config parameter |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 680 | ``KGDB_TESTS_ON_BOOT``. This particular option is aimed at automated |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 681 | regression testing and does not require modifying the kernel boot config |
| 682 | arguments. If this is turned on, the kgdb test suite can be disabled by |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 683 | specifying ``kgdbts=`` as a kernel boot argument. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 684 | |
| 685 | Kernel Debugger Internals |
| 686 | ========================= |
| 687 | |
| 688 | Architecture Specifics |
| 689 | ---------------------- |
| 690 | |
| 691 | The kernel debugger is organized into a number of components: |
| 692 | |
| 693 | 1. The debug core |
| 694 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 695 | The debug core is found in ``kernel/debugger/debug_core.c``. It |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 696 | contains: |
| 697 | |
| 698 | - A generic OS exception handler which includes sync'ing the |
| 699 | processors into a stopped state on an multi-CPU system. |
| 700 | |
| 701 | - The API to talk to the kgdb I/O drivers |
| 702 | |
| 703 | - The API to make calls to the arch-specific kgdb implementation |
| 704 | |
| 705 | - The logic to perform safe memory reads and writes to memory while |
| 706 | using the debugger |
| 707 | |
| 708 | - A full implementation for software breakpoints unless overridden |
| 709 | by the arch |
| 710 | |
| 711 | - The API to invoke either the kdb or kgdb frontend to the debug |
| 712 | core. |
| 713 | |
| 714 | - The structures and callback API for atomic kernel mode setting. |
| 715 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 716 | .. note:: kgdboc is where the kms callbacks are invoked. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 717 | |
| 718 | 2. kgdb arch-specific implementation |
| 719 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 720 | This implementation is generally found in ``arch/*/kernel/kgdb.c``. As |
| 721 | an example, ``arch/x86/kernel/kgdb.c`` contains the specifics to |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 722 | implement HW breakpoint as well as the initialization to dynamically |
| 723 | register and unregister for the trap handlers on this architecture. |
| 724 | The arch-specific portion implements: |
| 725 | |
| 726 | - contains an arch-specific trap catcher which invokes |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 727 | :c:func:`kgdb_handle_exception` to start kgdb about doing its work |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 728 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 729 | - translation to and from gdb specific packet format to :c:type:`pt_regs` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 730 | |
| 731 | - Registration and unregistration of architecture specific trap |
| 732 | hooks |
| 733 | |
| 734 | - Any special exception handling and cleanup |
| 735 | |
| 736 | - NMI exception handling and cleanup |
| 737 | |
| 738 | - (optional) HW breakpoints |
| 739 | |
| 740 | 3. gdbstub frontend (aka kgdb) |
| 741 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 742 | The gdbstub is located in ``kernel/debug/gdbstub.c``. It contains: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 743 | |
| 744 | - All the logic to implement the gdb serial protocol |
| 745 | |
| 746 | 4. kdb frontend |
| 747 | |
| 748 | The kdb debugger shell is broken down into a number of components. |
| 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 |
| 753 | contains implements the following functionality. |
| 754 | |
| 755 | - A simple shell |
| 756 | |
| 757 | - The kdb core command set |
| 758 | |
| 759 | - A registration API to register additional kdb shell commands. |
| 760 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 761 | - A good example of a self-contained kdb module is the ``ftdump`` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 762 | command for dumping the ftrace buffer. See: |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 763 | ``kernel/trace/trace_kdb.c`` |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 764 | |
| 765 | - For an example of how to dynamically register a new kdb command |
| 766 | you can build the kdb_hello.ko kernel module from |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 767 | ``samples/kdb/kdb_hello.c``. To build this example you can set |
| 768 | ``CONFIG_SAMPLES=y`` and ``CONFIG_SAMPLE_KDB=m`` in your kernel |
| 769 | config. Later run ``modprobe kdb_hello`` and the next time you |
| 770 | enter the kdb shell, you can run the ``hello`` command. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 771 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 772 | - The implementation for :c:func:`kdb_printf` which emits messages directly |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 773 | to I/O drivers, bypassing the kernel log. |
| 774 | |
| 775 | - SW / HW breakpoint management for the kdb shell |
| 776 | |
| 777 | 5. kgdb I/O driver |
| 778 | |
| 779 | Each kgdb I/O driver has to provide an implementation for the |
| 780 | following: |
| 781 | |
| 782 | - configuration via built-in or module |
| 783 | |
| 784 | - dynamic configuration and kgdb hook registration calls |
| 785 | |
| 786 | - read and write character interface |
| 787 | |
| 788 | - A cleanup handler for unconfiguring from the kgdb core |
| 789 | |
| 790 | - (optional) Early debug methodology |
| 791 | |
| 792 | Any given kgdb I/O driver has to operate very closely with the |
| 793 | hardware and must do it in such a way that does not enable interrupts |
| 794 | or change other parts of the system context without completely |
| 795 | restoring them. The kgdb core will repeatedly "poll" a kgdb I/O |
| 796 | driver for characters when it needs input. The I/O driver is expected |
| 797 | to return immediately if there is no data available. Doing so allows |
| 798 | for the future possibility to touch watchdog hardware in such a way |
| 799 | as to have a target system not reset when these are enabled. |
| 800 | |
| 801 | If you are intent on adding kgdb architecture specific support for a new |
| 802 | architecture, the architecture should define ``HAVE_ARCH_KGDB`` in the |
| 803 | architecture specific Kconfig file. This will enable kgdb for the |
| 804 | architecture, and at that point you must create an architecture specific |
| 805 | kgdb implementation. |
| 806 | |
| 807 | There are a few flags which must be set on every architecture in their |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 808 | ``asm/kgdb.h`` file. These are: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 809 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 810 | - ``NUMREGBYTES``: |
| 811 | The size in bytes of all of the registers, so that we |
| 812 | can ensure they will all fit into a packet. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 813 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 814 | - ``BUFMAX``: |
| 815 | The size in bytes of the buffer GDB will read into. This must |
| 816 | be larger than NUMREGBYTES. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 817 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 818 | - ``CACHE_FLUSH_IS_SAFE``: |
| 819 | Set to 1 if it is always safe to call |
| 820 | flush_cache_range or flush_icache_range. On some architectures, |
| 821 | these functions may not be safe to call on SMP since we keep other |
| 822 | CPUs in a holding pattern. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 823 | |
| 824 | There are also the following functions for the common backend, found in |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 825 | ``kernel/kgdb.c``, that must be supplied by the architecture-specific |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 826 | backend unless marked as (optional), in which case a default function |
| 827 | maybe used if the architecture does not need to provide a specific |
| 828 | implementation. |
| 829 | |
| 830 | .. kernel-doc:: include/linux/kgdb.h |
| 831 | :internal: |
| 832 | |
| 833 | kgdboc internals |
| 834 | ---------------- |
| 835 | |
| 836 | kgdboc and uarts |
| 837 | ~~~~~~~~~~~~~~~~ |
| 838 | |
| 839 | The kgdboc driver is actually a very thin driver that relies on the |
| 840 | underlying low level to the hardware driver having "polling hooks" to |
| 841 | which the tty driver is attached. In the initial implementation of |
| 842 | kgdboc the serial_core was changed to expose a low level UART hook for |
| 843 | doing polled mode reading and writing of a single character while in an |
| 844 | atomic context. When kgdb makes an I/O request to the debugger, kgdboc |
| 845 | invokes a callback in the serial core which in turn uses the callback in |
| 846 | the UART driver. |
| 847 | |
| 848 | When using kgdboc with a UART, the UART driver must implement two |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 849 | callbacks in the :c:type:`struct uart_ops <uart_ops>`. |
| 850 | Example from ``drivers/8250.c``:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 851 | |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 852 | |
| 853 | #ifdef CONFIG_CONSOLE_POLL |
| 854 | .poll_get_char = serial8250_get_poll_char, |
| 855 | .poll_put_char = serial8250_put_poll_char, |
| 856 | #endif |
| 857 | |
| 858 | |
| 859 | Any implementation specifics around creating a polling driver use the |
| 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 |
| 862 | called from an atomic context and have to restore the state of the UART |
| 863 | chip on return such that the system can return to normal when the |
| 864 | debugger detaches. You need to be very careful with any kind of lock you |
| 865 | consider, because failing here is most likely going to mean pressing the |
| 866 | reset button. |
| 867 | |
| 868 | kgdboc and keyboards |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 869 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 870 | |
| 871 | The kgdboc driver contains logic to configure communications with an |
| 872 | attached keyboard. The keyboard infrastructure is only compiled into the |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 873 | kernel when ``CONFIG_KDB_KEYBOARD=y`` is set in the kernel configuration. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 874 | |
Randy Dunlap | 06467a7 | 2020-07-07 11:03:58 -0700 | [diff] [blame^] | 875 | The core polled keyboard driver for PS/2 type keyboards is in |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 876 | ``drivers/char/kdb_keyboard.c``. This driver is hooked into the debug core |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 877 | when kgdboc populates the callback in the array called |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 878 | :c:type:`kdb_poll_funcs[]`. The :c:func:`kdb_get_kbd_char` is the top-level |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 879 | function which polls hardware for single character input. |
| 880 | |
| 881 | kgdboc and kms |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 882 | ~~~~~~~~~~~~~~~~~~ |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 883 | |
| 884 | The kgdboc driver contains logic to request the graphics display to |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 885 | switch to a text context when you are using ``kgdboc=kms,kbd``, provided |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 886 | that you have a video driver which has a frame buffer console and atomic |
| 887 | kernel mode setting support. |
| 888 | |
| 889 | Every time the kernel debugger is entered it calls |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 890 | :c:func:`kgdboc_pre_exp_handler` which in turn calls :c:func:`con_debug_enter` |
| 891 | in the virtual console layer. On resuming kernel execution, the kernel |
| 892 | debugger calls :c:func:`kgdboc_post_exp_handler` which in turn calls |
| 893 | :c:func:`con_debug_leave`. |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 894 | |
| 895 | Any video driver that wants to be compatible with the kernel debugger |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 896 | and the atomic kms callbacks must implement the ``mode_set_base_atomic``, |
| 897 | ``fb_debug_enter`` and ``fb_debug_leave operations``. For the |
| 898 | ``fb_debug_enter`` and ``fb_debug_leave`` the option exists to use the |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 899 | generic drm fb helper functions or implement something custom for the |
| 900 | hardware. The following example shows the initialization of the |
| 901 | .mode_set_base_atomic operation in |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 902 | drivers/gpu/drm/i915/intel_display.c:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 903 | |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 904 | |
| 905 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
| 906 | [...] |
| 907 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 908 | [...] |
| 909 | }; |
| 910 | |
| 911 | |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 912 | Here is an example of how the i915 driver initializes the |
| 913 | fb_debug_enter and fb_debug_leave functions to use the generic drm |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 914 | helpers in ``drivers/gpu/drm/i915/intel_fb.c``:: |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 915 | |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 916 | |
| 917 | static struct fb_ops intelfb_ops = { |
| 918 | [...] |
| 919 | .fb_debug_enter = drm_fb_helper_debug_enter, |
| 920 | .fb_debug_leave = drm_fb_helper_debug_leave, |
| 921 | [...] |
| 922 | }; |
| 923 | |
| 924 | |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 925 | Credits |
| 926 | ======= |
| 927 | |
| 928 | The following people have contributed to this document: |
| 929 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 930 | 1. Amit Kale <amitkale@linsyssoft.com> |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 931 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 932 | 2. Tom Rini <trini@kernel.crashing.org> |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 933 | |
| 934 | In March 2008 this document was completely rewritten by: |
| 935 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 936 | - Jason Wessel <jason.wessel@windriver.com> |
Mauro Carvalho Chehab | 7fb2e8a | 2017-05-11 16:23:50 -0300 | [diff] [blame] | 937 | |
| 938 | In Jan 2010 this document was updated to include kdb. |
| 939 | |
Mauro Carvalho Chehab | 821c6df | 2017-05-11 17:43:20 -0300 | [diff] [blame] | 940 | - Jason Wessel <jason.wessel@windriver.com> |