summaryrefslogtreecommitdiffstats
path: root/Documentation/dev-tools
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2017-05-11 16:43:20 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2017-05-16 07:44:04 -0400
commit821c6df87761af9a56702f1dec61549ee1cf3109 (patch)
treebe342f51a69e6824c63f8bd9a0240d929c9d0b6f /Documentation/dev-tools
parent7fb2e8a49037099c56ea209aaa8527e5f3e742ba (diff)
kgdb.rst: Adjust ReST markups
The automatic conversion didn't work too well for this file. It added weird html blocks inside it, and did some weird things for literals. Manually fix it, in order to present a nice display at html/pdf outputs. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'Documentation/dev-tools')
-rw-r--r--Documentation/dev-tools/kgdb.rst487
1 files changed, 232 insertions, 255 deletions
diff --git a/Documentation/dev-tools/kgdb.rst b/Documentation/dev-tools/kgdb.rst
index ea01541806c8..75273203a35a 100644
--- a/Documentation/dev-tools/kgdb.rst
+++ b/Documentation/dev-tools/kgdb.rst
@@ -51,28 +51,29 @@ Compiling a kernel
51Kernel config options for kgdb 51Kernel config options for kgdb
52------------------------------ 52------------------------------
53 53
54To enable ``CONFIG_KGDB`` you should look under "Kernel hacking" / 54To enable ``CONFIG_KGDB`` you should look under
55"Kernel debugging" and select "KGDB: kernel debugger". 55:menuselection:`Kernel hacking --> Kernel debugging` and select
56:menuselection:`KGDB: kernel debugger`.
56 57
57While it is not a hard requirement that you have symbols in your vmlinux 58While it is not a hard requirement that you have symbols in your vmlinux
58file, gdb tends not to be very useful without the symbolic data, so you 59file, gdb tends not to be very useful without the symbolic data, so you
59will want to turn on ``CONFIG_DEBUG_INFO`` which is called "Compile the 60will want to turn on ``CONFIG_DEBUG_INFO`` which is called
60kernel with debug info" in the config menu. 61:menuselection:`Compile the kernel with debug info` in the config menu.
61 62
62It is advised, but not required, that you turn on the 63It is advised, but not required, that you turn on the
63``CONFIG_FRAME_POINTER`` kernel option which is called "Compile the 64``CONFIG_FRAME_POINTER`` kernel option which is called :menuselection:`Compile
64kernel with frame pointers" in the config menu. This option inserts code 65the kernel with frame pointers` in the config menu. This option inserts code
65to into the compiled executable which saves the frame information in 66to into the compiled executable which saves the frame information in
66registers or on the stack at different points which allows a debugger 67registers or on the stack at different points which allows a debugger
67such as gdb to more accurately construct stack back traces while 68such as gdb to more accurately construct stack back traces while
68debugging the kernel. 69debugging the kernel.
69 70
70If the architecture that you are using supports the kernel option 71If the architecture that you are using supports the kernel option
71CONFIG_STRICT_KERNEL_RWX, you should consider turning it off. This 72``CONFIG_STRICT_KERNEL_RWX``, you should consider turning it off. This
72option will prevent the use of software breakpoints because it marks 73option will prevent the use of software breakpoints because it marks
73certain regions of the kernel's memory space as read-only. If kgdb 74certain regions of the kernel's memory space as read-only. If kgdb
74supports it for the architecture you are using, you can use hardware 75supports it for the architecture you are using, you can use hardware
75breakpoints if you desire to run with the CONFIG_STRICT_KERNEL_RWX 76breakpoints if you desire to run with the ``CONFIG_STRICT_KERNEL_RWX``
76option turned on, else you need to turn off this option. 77option turned on, else you need to turn off this option.
77 78
78Next you should choose one of more I/O drivers to interconnect debugging 79Next you should choose one of more I/O drivers to interconnect debugging
@@ -80,17 +81,14 @@ host and debugged target. Early boot debugging requires a KGDB I/O
80driver that supports early debugging and the driver must be built into 81driver that supports early debugging and the driver must be built into
81the kernel directly. Kgdb I/O driver configuration takes place via 82the kernel directly. Kgdb I/O driver configuration takes place via
82kernel or module parameters which you can learn more about in the in the 83kernel or module parameters which you can learn more about in the in the
83section that describes the parameter "kgdboc". 84section that describes the parameter kgdboc.
84 85
85Here is an example set of .config symbols to enable or disable for kgdb: 86Here is an example set of ``.config`` symbols to enable or disable for kgdb::
86 87
87- # CONFIG_STRICT_KERNEL_RWX is not set 88 # CONFIG_STRICT_KERNEL_RWX is not set
88 89 CONFIG_FRAME_POINTER=y
89- CONFIG_FRAME_POINTER=y 90 CONFIG_KGDB=y
90 91 CONFIG_KGDB_SERIAL_CONSOLE=y
91- CONFIG_KGDB=y
92
93- CONFIG_KGDB_SERIAL_CONSOLE=y
94 92
95Kernel config options for kdb 93Kernel config options for kdb
96----------------------------- 94-----------------------------
@@ -99,34 +97,29 @@ Kdb is quite a bit more complex than the simple gdbstub sitting on top
99of the kernel's debug core. Kdb must implement a shell, and also adds 97of the kernel's debug core. Kdb must implement a shell, and also adds
100some helper functions in other parts of the kernel, responsible for 98some helper functions in other parts of the kernel, responsible for
101printing out interesting data such as what you would see if you ran 99printing out interesting data such as what you would see if you ran
102"lsmod", or "ps". In order to build kdb into the kernel you follow the 100``lsmod``, or ``ps``. In order to build kdb into the kernel you follow the
103same steps as you would for kgdb. 101same steps as you would for kgdb.
104 102
105The main config option for kdb is ``CONFIG_KGDB_KDB`` which is called 103The main config option for kdb is ``CONFIG_KGDB_KDB`` which is called
106"KGDB_KDB: include kdb frontend for kgdb" in the config menu. In theory 104:menuselection:`KGDB_KDB: include kdb frontend for kgdb` in the config menu.
107you would have already also selected an I/O driver such as the 105In theory you would have already also selected an I/O driver such as the
108CONFIG_KGDB_SERIAL_CONSOLE interface if you plan on using kdb on a 106``CONFIG_KGDB_SERIAL_CONSOLE`` interface if you plan on using kdb on a
109serial port, when you were configuring kgdb. 107serial port, when you were configuring kgdb.
110 108
111If you want to use a PS/2-style keyboard with kdb, you would select 109If you want to use a PS/2-style keyboard with kdb, you would select
112CONFIG_KDB_KEYBOARD which is called "KGDB_KDB: keyboard as input 110``CONFIG_KDB_KEYBOARD`` which is called :menuselection:`KGDB_KDB: keyboard as
113device" in the config menu. The CONFIG_KDB_KEYBOARD option is not used 111input device` in the config menu. The ``CONFIG_KDB_KEYBOARD`` option is not
114for anything in the gdb interface to kgdb. The CONFIG_KDB_KEYBOARD 112used for anything in the gdb interface to kgdb. The ``CONFIG_KDB_KEYBOARD``
115option only works with kdb. 113option only works with kdb.
116 114
117Here is an example set of .config symbols to enable/disable kdb: 115Here is an example set of ``.config`` symbols to enable/disable kdb::
118
119- # CONFIG_STRICT_KERNEL_RWX is not set
120
121- CONFIG_FRAME_POINTER=y
122
123- CONFIG_KGDB=y
124
125- CONFIG_KGDB_SERIAL_CONSOLE=y
126 116
127- CONFIG_KGDB_KDB=y 117 # CONFIG_STRICT_KERNEL_RWX is not set
128 118 CONFIG_FRAME_POINTER=y
129- CONFIG_KDB_KEYBOARD=y 119 CONFIG_KGDB=y
120 CONFIG_KGDB_SERIAL_CONSOLE=y
121 CONFIG_KGDB_KDB=y
122 CONFIG_KDB_KEYBOARD=y
130 123
131Kernel Debugger Boot Arguments 124Kernel Debugger Boot Arguments
132============================== 125==============================
@@ -164,7 +157,9 @@ with kdb while allowing the full graphics console applications to run.
164kgdboc arguments 157kgdboc arguments
165~~~~~~~~~~~~~~~~ 158~~~~~~~~~~~~~~~~
166 159
167Usage: ``kgdboc=[kms][[,]kbd][[,]serial_device][,baud]`` 160Usage::
161
162 kgdboc=[kms][[,]kbd][[,]serial_device][,baud]
168 163
169The order listed above must be observed if you use any of the optional 164The order listed above must be observed if you use any of the optional
170configurations together. 165configurations together.
@@ -186,11 +181,15 @@ Using loadable module or built-in
186 181
1871. As a kernel built-in: 1821. As a kernel built-in:
188 183
189 Use the kernel boot argument: ``kgdboc=<tty-device>,[baud]`` 184 Use the kernel boot argument::
185
186 kgdboc=<tty-device>,[baud]
190 187
1912. As a kernel loadable module: 1882. As a kernel loadable module:
192 189
193 Use the command: ``modprobe kgdboc kgdboc=<tty-device>,[baud]`` 190 Use the command::
191
192 modprobe kgdboc kgdboc=<tty-device>,[baud]
194 193
195 Here are two examples of how you might format the kgdboc string. The 194 Here are two examples of how you might format the kgdboc string. The
196 first is for an x86 target using the first serial port. The second 195 first is for an x86 target using the first serial port. The second
@@ -206,16 +205,18 @@ Configure kgdboc at runtime with sysfs
206At run time you can enable or disable kgdboc by echoing a parameters 205At run time you can enable or disable kgdboc by echoing a parameters
207into the sysfs. Here are two examples: 206into the sysfs. Here are two examples:
208 207
2091. Enable kgdboc on ttyS0 2081. Enable kgdboc on ttyS0::
210 209
211 ``echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc`` 210 echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
212 211
2132. Disable kgdboc 2122. Disable kgdboc::
214 213
215 ``echo "" > /sys/module/kgdboc/parameters/kgdboc`` 214 echo "" > /sys/module/kgdboc/parameters/kgdboc
216 215
217NOTE: You do not need to specify the baud if you are configuring the 216.. note::
218console on tty which is already configured or open. 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.
219 220
220More examples 221More examples
221^^^^^^^^^^^^^ 222^^^^^^^^^^^^^
@@ -224,35 +225,42 @@ You can configure kgdboc to use the keyboard, and/or a serial device
224depending on if you are using kdb and/or kgdb, in one of the following 225depending on if you are using kdb and/or kgdb, in one of the following
225scenarios. 226scenarios.
226 227
2271. kdb and kgdb over only a serial port 2281. kdb and kgdb over only a serial port::
229
230 kgdboc=<serial_device>[,baud]
231
232 Example::
228 233
229 ``kgdboc=<serial_device>[,baud]`` 234 kgdboc=ttyS0,115200
230 235
231 Example: ``kgdboc=ttyS0,115200`` 2362. kdb and kgdb with keyboard and a serial port::
232 237
2332. kdb and kgdb with keyboard and a serial port 238 kgdboc=kbd,<serial_device>[,baud]
234 239
235 ``kgdboc=kbd,<serial_device>[,baud]`` 240 Example::
236 241
237 Example: ``kgdboc=kbd,ttyS0,115200`` 242 kgdboc=kbd,ttyS0,115200
238 243
2393. kdb with a keyboard 2443. kdb with a keyboard::
240 245
241 ``kgdboc=kbd`` 246 kgdboc=kbd
242 247
2434. kdb with kernel mode setting 2484. kdb with kernel mode setting::
244 249
245 ``kgdboc=kms,kbd`` 250 kgdboc=kms,kbd
246 251
2475. kdb with kernel mode setting and kgdb over a serial port 2525. kdb with kernel mode setting and kgdb over a serial port::
248 253
249 ``kgdboc=kms,kbd,ttyS0,115200`` 254 kgdboc=kms,kbd,ttyS0,115200
250 255
251NOTE: Kgdboc does not support interrupting the target via the gdb remote 256.. note::
252protocol. You must manually send a sysrq-g unless you have a proxy that 257
253splits console output to a terminal program. A console proxy has a 258 Kgdboc does not support interrupting the target via the gdb remote
254separate TCP port for the debugger and a separate TCP port for the 259 protocol. You must manually send a :kbd:`SysRq-G` unless you have a proxy
255"human" console. The proxy can take care of sending the sysrq-g for you. 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.
256 264
257When using kgdboc with no debugger proxy, you can end up connecting the 265When using kgdboc with no debugger proxy, you can end up connecting the
258debugger at one of two entry points. If an exception occurs after you 266debugger at one of two entry points. If an exception occurs after you
@@ -260,14 +268,14 @@ have loaded kgdboc, a message should print on the console stating it is
260waiting for the debugger. In this case you disconnect your terminal 268waiting for the debugger. In this case you disconnect your terminal
261program and then connect the debugger in its place. If you want to 269program and then connect the debugger in its place. If you want to
262interrupt the target system and forcibly enter a debug session you have 270interrupt the target system and forcibly enter a debug session you have
263to issue a Sysrq sequence and then type the letter ``g``. Then you 271to issue a :kbd:`Sysrq` sequence and then type the letter :kbd:`g`. Then you
264disconnect the terminal session and connect gdb. Your options if you 272disconnect the terminal session and connect gdb. Your options if you
265don't like this are to hack gdb to send the sysrq-g for you as well as 273don't like this are to hack gdb to send the :kbd:`SysRq-G` for you as well as
266on the initial connect, or to use a debugger proxy that allows an 274on the initial connect, or to use a debugger proxy that allows an
267unmodified gdb to do the debugging. 275unmodified gdb to do the debugging.
268 276
269Kernel parameter: kgdbwait 277Kernel parameter: ``kgdbwait``
270-------------------------- 278------------------------------
271 279
272The Kernel command line option ``kgdbwait`` makes kgdb wait for a 280The Kernel command line option ``kgdbwait`` makes kgdb wait for a
273debugger connection during booting of a kernel. You can only use this 281debugger connection during booting of a kernel. You can only use this
@@ -281,54 +289,64 @@ The kernel will stop and wait as early as the I/O driver and
281architecture allows when you use this option. If you build the kgdb I/O 289architecture allows when you use this option. If you build the kgdb I/O
282driver as a loadable kernel module kgdbwait will not do anything. 290driver as a loadable kernel module kgdbwait will not do anything.
283 291
284Kernel parameter: kgdbcon 292Kernel parameter: ``kgdbcon``
285------------------------- 293-----------------------------
286 294
287The kgdbcon feature allows you to see printk() messages inside gdb while 295The ``kgdbcon`` feature allows you to see :c:func:`printk` messages inside gdb
288gdb is connected to the kernel. Kdb does not make use of the kgdbcon 296while gdb is connected to the kernel. Kdb does not make use of the kgdbcon
289feature. 297feature.
290 298
291Kgdb supports using the gdb serial protocol to send console messages to 299Kgdb supports using the gdb serial protocol to send console messages to
292the debugger when the debugger is connected and running. There are two 300the debugger when the debugger is connected and running. There are two
293ways to activate this feature. 301ways to activate this feature.
294 302
2951. Activate with the kernel command line option: 3031. Activate with the kernel command line option::
304
305 kgdbcon
296 306
297 ``kgdbcon`` 3072. Use sysfs before configuring an I/O driver::
298 308
2992. Use sysfs before configuring an I/O driver 309 echo 1 > /sys/module/kgdb/parameters/kgdb_use_con
300 310
301 ``echo 1 > /sys/module/kgdb/parameters/kgdb_use_con`` 311.. note::
302 312
303 NOTE: If you do this after you configure the kgdb I/O driver, the 313 If you do this after you configure the kgdb I/O driver, the
304 setting will not take effect until the next point the I/O is 314 setting will not take effect until the next point the I/O is
305 reconfigured. 315 reconfigured.
306 316
307IMPORTANT NOTE: You cannot use kgdboc + kgdbcon on a tty that is an 317.. important::
308active system console. An example of incorrect usage is 318
309``console=ttyS0,115200 kgdboc=ttyS0 kgdbcon`` 319 You cannot use kgdboc + kgdbcon on a tty that is an
320 active system console. An example of incorrect usage is::
321
322 console=ttyS0,115200 kgdboc=ttyS0 kgdbcon
310 323
311It is possible to use this option with kgdboc on a tty that is not a 324It is possible to use this option with kgdboc on a tty that is not a
312system console. 325system console.
313 326
314Run time parameter: kgdbreboot 327Run time parameter: ``kgdbreboot``
315------------------------------ 328----------------------------------
316 329
317The kgdbreboot feature allows you to change how the debugger deals with 330The kgdbreboot feature allows you to change how the debugger deals with
318the reboot notification. You have 3 choices for the behavior. The 331the reboot notification. You have 3 choices for the behavior. The
319default behavior is always set to 0. 332default behavior is always set to 0.
320 333
3211. echo -1 > /sys/module/debug_core/parameters/kgdbreboot 334.. tabularcolumns:: |p{0.4cm}|p{11.5cm}|p{5.6cm}|
322 335
323 Ignore the reboot notification entirely. 336.. flat-table::
337 :widths: 1 10 8
324 338
3252. echo 0 > /sys/module/debug_core/parameters/kgdbreboot 339 * - 1
340 - ``echo -1 > /sys/module/debug_core/parameters/kgdbreboot``
341 - Ignore the reboot notification entirely.
326 342
327 Send the detach message to any attached debugger client. 343 * - 2
344 - ``echo 0 > /sys/module/debug_core/parameters/kgdbreboot``
345 - Send the detach message to any attached debugger client.
328 346
3293. echo 1 > /sys/module/debug_core/parameters/kgdbreboot 347 * - 3
330 348 - ``echo 1 > /sys/module/debug_core/parameters/kgdbreboot``
331 Enter the debugger on reboot notify. 349 - Enter the debugger on reboot notify.
332 350
333Using kdb 351Using kdb
334========= 352=========
@@ -338,66 +356,56 @@ Quick start for kdb on a serial port
338 356
339This is a quick example of how to use kdb. 357This is a quick example of how to use kdb.
340 358
3411. Configure kgdboc at boot using kernel parameters: 3591. Configure kgdboc at boot using kernel parameters::
342 360
343 - ``console=ttyS0,115200 kgdboc=ttyS0,115200`` 361 console=ttyS0,115200 kgdboc=ttyS0,115200
344 362
345 OR 363 OR
346 364
347 Configure kgdboc after the kernel has booted; assuming you are using 365 Configure kgdboc after the kernel has booted; assuming you are using
348 a serial port console: 366 a serial port console::
349 367
350 - ``echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc`` 368 echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
351 369
3522. Enter the kernel debugger manually or by waiting for an oops or 3702. Enter the kernel debugger manually or by waiting for an oops or
353 fault. There are several ways you can enter the kernel debugger 371 fault. There are several ways you can enter the kernel debugger
354 manually; all involve using the sysrq-g, which means you must have 372 manually; all involve using the :kbd:`SysRq-G`, which means you must have
355 enabled CONFIG_MAGIC_SYSRQ=y in your kernel config. 373 enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config.
356 374
357 - When logged in as root or with a super user session you can run: 375 - When logged in as root or with a super user session you can run::
358 376
359 ``echo g > /proc/sysrq-trigger`` 377 echo g > /proc/sysrq-trigger
360 378
361 - Example using minicom 2.2 379 - Example using minicom 2.2
362 380
363 Press: ``Control-a`` 381 Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g`
364
365 Press: ``f``
366
367 Press: ``g``
368 382
369 - When you have telneted to a terminal server that supports sending 383 - When you have telneted to a terminal server that supports sending
370 a remote break 384 a remote break
371 385
372 Press: ``Control-]`` 386 Press: :kbd:`CTRL-]`
373 387
374 Type in:\ ``send break`` 388 Type in: ``send break``
375 389
376 Press: ``Enter`` 390 Press: :kbd:`Enter` :kbd:`g`
377 391
378 Press: ``g`` 3923. From the kdb prompt you can run the ``help`` command to see a complete
379
3803. From the kdb prompt you can run the "help" command to see a complete
381 list of the commands that are available. 393 list of the commands that are available.
382 394
383 Some useful commands in kdb include: 395 Some useful commands in kdb include:
384 396
385 - lsmod -- Shows where kernel modules are loaded 397 =========== =================================================================
386 398 ``lsmod`` Shows where kernel modules are loaded
387 - ps -- Displays only the active processes 399 ``ps`` Displays only the active processes
388 400 ``ps A`` Shows all the processes
389 - ps A -- Shows all the processes 401 ``summary`` Shows kernel version info and memory usage
390 402 ``bt`` Get a backtrace of the current process using :c:func:`dump_stack`
391 - summary -- Shows kernel version info and memory usage 403 ``dmesg`` View the kernel syslog buffer
392 404 ``go`` Continue the system
393 - bt -- Get a backtrace of the current process using dump_stack() 405 =========== =================================================================
394
395 - dmesg -- View the kernel syslog buffer
396
397 - go -- Continue the system
398 406
3994. When you are done using kdb you need to consider rebooting the system 4074. When you are done using kdb you need to consider rebooting the system
400 or using the "go" command to resuming normal kernel execution. If you 408 or using the ``go`` command to resuming normal kernel execution. If you
401 have paused the kernel for a lengthy period of time, applications 409 have paused the kernel for a lengthy period of time, applications
402 that rely on timely networking or anything to do with real wall clock 410 that rely on timely networking or anything to do with real wall clock
403 time could be adversely affected, so you should take this into 411 time could be adversely affected, so you should take this into
@@ -408,50 +416,50 @@ Quick start for kdb using a keyboard connected console
408 416
409This is a quick example of how to use kdb with a keyboard. 417This is a quick example of how to use kdb with a keyboard.
410 418
4111. Configure kgdboc at boot using kernel parameters: 4191. Configure kgdboc at boot using kernel parameters::
412 420
413 - ``kgdboc=kbd`` 421 kgdboc=kbd
414 422
415 OR 423 OR
416 424
417 Configure kgdboc after the kernel has booted: 425 Configure kgdboc after the kernel has booted::
418 426
419 - ``echo kbd > /sys/module/kgdboc/parameters/kgdboc`` 427 echo kbd > /sys/module/kgdboc/parameters/kgdboc
420 428
4212. Enter the kernel debugger manually or by waiting for an oops or 4292. Enter the kernel debugger manually or by waiting for an oops or
422 fault. There are several ways you can enter the kernel debugger 430 fault. There are several ways you can enter the kernel debugger
423 manually; all involve using the sysrq-g, which means you must have 431 manually; all involve using the :kbd:`SysRq-G`, which means you must have
424 enabled CONFIG_MAGIC_SYSRQ=y in your kernel config. 432 enabled ``CONFIG_MAGIC_SysRq=y`` in your kernel config.
425 433
426 - When logged in as root or with a super user session you can run: 434 - When logged in as root or with a super user session you can run::
427 435
428 ``echo g > /proc/sysrq-trigger`` 436 echo g > /proc/sysrq-trigger
429 437
430 - Example using a laptop keyboard 438 - Example using a laptop keyboard:
431 439
432 Press and hold down: ``Alt`` 440 Press and hold down: :kbd:`Alt`
433 441
434 Press and hold down: ``Fn`` 442 Press and hold down: :kbd:`Fn`
435 443
436 Press and release the key with the label: ``SysRq`` 444 Press and release the key with the label: :kbd:`SysRq`
437 445
438 Release: ``Fn`` 446 Release: :kbd:`Fn`
439 447
440 Press and release: ``g`` 448 Press and release: :kbd:`g`
441 449
442 Release: ``Alt`` 450 Release: :kbd:`Alt`
443 451
444 - Example using a PS/2 101-key keyboard 452 - Example using a PS/2 101-key keyboard
445 453
446 Press and hold down: ``Alt`` 454 Press and hold down: :kbd:`Alt`
447 455
448 Press and release the key with the label: ``SysRq`` 456 Press and release the key with the label: :kbd:`SysRq`
449 457
450 Press and release: ``g`` 458 Press and release: :kbd:`g`
451 459
452 Release: ``Alt`` 460 Release: :kbd:`Alt`
453 461
4543. Now type in a kdb command such as "help", "dmesg", "bt" or "go" to 4623. Now type in a kdb command such as ``help``, ``dmesg``, ``bt`` or ``go`` to
455 continue kernel execution. 463 continue kernel execution.
456 464
457Using kgdb / gdb 465Using kgdb / gdb
@@ -477,61 +485,51 @@ Connecting with gdb to a serial port
477 485
4781. Configure kgdboc 4861. Configure kgdboc
479 487
480 Configure kgdboc at boot using kernel parameters: 488 Configure kgdboc at boot using kernel parameters::
481 489
482 - ``kgdboc=ttyS0,115200`` 490 kgdboc=ttyS0,115200
483 491
484 OR 492 OR
485 493
486 Configure kgdboc after the kernel has booted: 494 Configure kgdboc after the kernel has booted::
487 495
488 - ``echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc`` 496 echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
489 497
4902. Stop kernel execution (break into the debugger) 4982. Stop kernel execution (break into the debugger)
491 499
492 In order to connect to gdb via kgdboc, the kernel must first be 500 In order to connect to gdb via kgdboc, the kernel must first be
493 stopped. There are several ways to stop the kernel which include 501 stopped. There are several ways to stop the kernel which include
494 using kgdbwait as a boot argument, via a sysrq-g, or running the 502 using kgdbwait as a boot argument, via a :kbd:`SysRq-G`, or running the
495 kernel until it takes an exception where it waits for the debugger to 503 kernel until it takes an exception where it waits for the debugger to
496 attach. 504 attach.
497 505
498 - When logged in as root or with a super user session you can run: 506 - When logged in as root or with a super user session you can run::
499 507
500 ``echo g > /proc/sysrq-trigger`` 508 echo g > /proc/sysrq-trigger
501 509
502 - Example using minicom 2.2 510 - Example using minicom 2.2
503 511
504 Press: ``Control-a`` 512 Press: :kbd:`CTRL-A` :kbd:`f` :kbd:`g`
505
506 Press: ``f``
507
508 Press: ``g``
509 513
510 - When you have telneted to a terminal server that supports sending 514 - When you have telneted to a terminal server that supports sending
511 a remote break 515 a remote break
512 516
513 Press: ``Control-]`` 517 Press: :kbd:`CTRL-]`
514
515 Type in:\ ``send break``
516 518
517 Press: ``Enter`` 519 Type in: ``send break``
518 520
519 Press: ``g`` 521 Press: :kbd:`Enter` :kbd:`g`
520 522
5213. Connect from gdb 5233. Connect from gdb
522 524
523 Example (using a directly connected port): 525 Example (using a directly connected port)::
524
525 ::
526 526
527 % gdb ./vmlinux 527 % gdb ./vmlinux
528 (gdb) set remotebaud 115200 528 (gdb) set remotebaud 115200
529 (gdb) target remote /dev/ttyS0 529 (gdb) target remote /dev/ttyS0
530 530
531 531
532 Example (kgdb to a terminal server on TCP port 2012): 532 Example (kgdb to a terminal server on TCP port 2012)::
533
534 ::
535 533
536 % gdb ./vmlinux 534 % gdb ./vmlinux
537 (gdb) target remote 192.168.2.2:2012 535 (gdb) target remote 192.168.2.2:2012
@@ -543,12 +541,13 @@ Connecting with gdb to a serial port
543 If you are having problems connecting or something is going seriously 541 If you are having problems connecting or something is going seriously
544 wrong while debugging, it will most often be the case that you want 542 wrong while debugging, it will most often be the case that you want
545 to enable gdb to be verbose about its target communications. You do 543 to enable gdb to be verbose about its target communications. You do
546 this prior to issuing the ``target 544 this prior to issuing the ``target remote`` command by typing in::
547 remote`` command by typing in: ``set debug remote 1`` 545
546 set debug remote 1
548 547
549Remember if you continue in gdb, and need to "break in" again, you need 548Remember if you continue in gdb, and need to "break in" again, you need
550to issue an other sysrq-g. It is easy to create a simple entry point by 549to issue an other :kbd:`SysRq-G`. It is easy to create a simple entry point by
551putting a breakpoint at ``sys_sync`` and then you can run "sync" from a 550putting a breakpoint at ``sys_sync`` and then you can run ``sync`` from a
552shell or script to break into the debugger. 551shell or script to break into the debugger.
553 552
554kgdb and kdb interoperability 553kgdb and kdb interoperability
@@ -565,22 +564,26 @@ Switching from kgdb to kdb
565~~~~~~~~~~~~~~~~~~~~~~~~~~ 564~~~~~~~~~~~~~~~~~~~~~~~~~~
566 565
567There are two ways to switch from kgdb to kdb: you can use gdb to issue 566There are two ways to switch from kgdb to kdb: you can use gdb to issue
568a maintenance packet, or you can blindly type the command $3#33. 567a maintenance packet, or you can blindly type the command ``$3#33``.
569Whenever the kernel debugger stops in kgdb mode it will print the 568Whenever the kernel debugger stops in kgdb mode it will print the
570message ``KGDB or $3#33 for KDB``. It is important to note that you have 569message ``KGDB or $3#33 for KDB``. It is important to note that you have
571to type the sequence correctly in one pass. You cannot type a backspace 570to type the sequence correctly in one pass. You cannot type a backspace
572or delete because kgdb will interpret that as part of the debug stream. 571or delete because kgdb will interpret that as part of the debug stream.
573 572
5741. Change from kgdb to kdb by blindly typing: 5731. Change from kgdb to kdb by blindly typing::
575 574
576 ``$3#33`` 575 $3#33
577 576
5782. Change from kgdb to kdb with gdb 5772. Change from kgdb to kdb with gdb::
579 578
580 ``maintenance packet 3`` 579 maintenance packet 3
581 580
582 NOTE: Now you must kill gdb. Typically you press control-z and issue 581 .. note::
583 the command: kill -9 % 582
583 Now you must kill gdb. Typically you press :kbd:`CTRL-Z` and issue
584 the command::
585
586 kill -9 %
584 587
585Change from kdb to kgdb 588Change from kdb to kgdb
586~~~~~~~~~~~~~~~~~~~~~~~ 589~~~~~~~~~~~~~~~~~~~~~~~
@@ -592,9 +595,9 @@ shell looks for the typical first commands that gdb would issue with the
592gdb remote protocol and if it sees one of those commands it 595gdb remote protocol and if it sees one of those commands it
593automatically changes into kgdb mode. 596automatically changes into kgdb mode.
594 597
5951. From kdb issue the command: 5981. From kdb issue the command::
596 599
597 ``kgdb`` 600 kgdb
598 601
599 Now disconnect your terminal program and connect gdb in its place 602 Now disconnect your terminal program and connect gdb in its place
600 603
@@ -613,13 +616,7 @@ are things like lsmod, dmesg, ps or possibly some of the memory
613information commands. To see all the kdb commands you can run 616information commands. To see all the kdb commands you can run
614``monitor help``. 617``monitor help``.
615 618
616Example: 619Example::
617
618.. raw:: html
619
620 <div class="informalexample">
621
622::
623 620
624 (gdb) monitor ps 621 (gdb) monitor ps
625 1 idle process (state I) and 622 1 idle process (state I) and
@@ -632,30 +629,25 @@ Example:
632 0xc78789c0 944 1 0 0 S 0xc7878bf4 sh 629 0xc78789c0 944 1 0 0 S 0xc7878bf4 sh
633 (gdb) 630 (gdb)
634 631
635
636.. raw:: html
637
638 </div>
639
640kgdb Test Suite 632kgdb Test Suite
641=============== 633===============
642 634
643When kgdb is enabled in the kernel config you can also elect to enable 635When kgdb is enabled in the kernel config you can also elect to enable
644the config parameter KGDB_TESTS. Turning this on will enable a special 636the config parameter ``KGDB_TESTS``. Turning this on will enable a special
645kgdb I/O module which is designed to test the kgdb internal functions. 637kgdb I/O module which is designed to test the kgdb internal functions.
646 638
647The kgdb tests are mainly intended for developers to test the kgdb 639The kgdb tests are mainly intended for developers to test the kgdb
648internals as well as a tool for developing a new kgdb architecture 640internals as well as a tool for developing a new kgdb architecture
649specific implementation. These tests are not really for end users of the 641specific implementation. These tests are not really for end users of the
650Linux kernel. The primary source of documentation would be to look in 642Linux kernel. The primary source of documentation would be to look in
651the drivers/misc/kgdbts.c file. 643the ``drivers/misc/kgdbts.c`` file.
652 644
653The kgdb test suite can also be configured at compile time to run the 645The kgdb test suite can also be configured at compile time to run the
654core set of tests by setting the kernel config parameter 646core set of tests by setting the kernel config parameter
655KGDB_TESTS_ON_BOOT. This particular option is aimed at automated 647``KGDB_TESTS_ON_BOOT``. This particular option is aimed at automated
656regression testing and does not require modifying the kernel boot config 648regression testing and does not require modifying the kernel boot config
657arguments. If this is turned on, the kgdb test suite can be disabled by 649arguments. If this is turned on, the kgdb test suite can be disabled by
658specifying "kgdbts=" as a kernel boot argument. 650specifying ``kgdbts=`` as a kernel boot argument.
659 651
660Kernel Debugger Internals 652Kernel Debugger Internals
661========================= 653=========================
@@ -667,7 +659,7 @@ The kernel debugger is organized into a number of components:
667 659
6681. The debug core 6601. The debug core
669 661
670 The debug core is found in kernel/debugger/debug_core.c. It 662 The debug core is found in ``kernel/debugger/debug_core.c``. It
671 contains: 663 contains:
672 664
673 - A generic OS exception handler which includes sync'ing the 665 - A generic OS exception handler which includes sync'ing the
@@ -688,20 +680,20 @@ The kernel debugger is organized into a number of components:
688 680
689 - The structures and callback API for atomic kernel mode setting. 681 - The structures and callback API for atomic kernel mode setting.
690 682
691 NOTE: kgdboc is where the kms callbacks are invoked. 683 .. note:: kgdboc is where the kms callbacks are invoked.
692 684
6932. kgdb arch-specific implementation 6852. kgdb arch-specific implementation
694 686
695 This implementation is generally found in arch/\*/kernel/kgdb.c. As 687 This implementation is generally found in ``arch/*/kernel/kgdb.c``. As
696 an example, arch/x86/kernel/kgdb.c contains the specifics to 688 an example, ``arch/x86/kernel/kgdb.c`` contains the specifics to
697 implement HW breakpoint as well as the initialization to dynamically 689 implement HW breakpoint as well as the initialization to dynamically
698 register and unregister for the trap handlers on this architecture. 690 register and unregister for the trap handlers on this architecture.
699 The arch-specific portion implements: 691 The arch-specific portion implements:
700 692
701 - contains an arch-specific trap catcher which invokes 693 - contains an arch-specific trap catcher which invokes
702 kgdb_handle_exception() to start kgdb about doing its work 694 :c:func:`kgdb_handle_exception` to start kgdb about doing its work
703 695
704 - translation to and from gdb specific packet format to pt_regs 696 - translation to and from gdb specific packet format to :c:type:`pt_regs`
705 697
706 - Registration and unregistration of architecture specific trap 698 - Registration and unregistration of architecture specific trap
707 hooks 699 hooks
@@ -714,7 +706,7 @@ The kernel debugger is organized into a number of components:
714 706
7153. gdbstub frontend (aka kgdb) 7073. gdbstub frontend (aka kgdb)
716 708
717 The gdbstub is located in kernel/debug/gdbstub.c. It contains: 709 The gdbstub is located in ``kernel/debug/gdbstub.c``. It contains:
718 710
719 - All the logic to implement the gdb serial protocol 711 - All the logic to implement the gdb serial protocol
720 712
@@ -733,18 +725,18 @@ The kernel debugger is organized into a number of components:
733 725
734 - A registration API to register additional kdb shell commands. 726 - A registration API to register additional kdb shell commands.
735 727
736 - A good example of a self-contained kdb module is the "ftdump" 728 - A good example of a self-contained kdb module is the ``ftdump``
737 command for dumping the ftrace buffer. See: 729 command for dumping the ftrace buffer. See:
738 kernel/trace/trace_kdb.c 730 ``kernel/trace/trace_kdb.c``
739 731
740 - For an example of how to dynamically register a new kdb command 732 - For an example of how to dynamically register a new kdb command
741 you can build the kdb_hello.ko kernel module from 733 you can build the kdb_hello.ko kernel module from
742 samples/kdb/kdb_hello.c. To build this example you can set 734 ``samples/kdb/kdb_hello.c``. To build this example you can set
743 CONFIG_SAMPLES=y and CONFIG_SAMPLE_KDB=m in your kernel 735 ``CONFIG_SAMPLES=y`` and ``CONFIG_SAMPLE_KDB=m`` in your kernel
744 config. Later run "modprobe kdb_hello" and the next time you 736 config. Later run ``modprobe kdb_hello`` and the next time you
745 enter the kdb shell, you can run the "hello" command. 737 enter the kdb shell, you can run the ``hello`` command.
746 738
747 - The implementation for kdb_printf() which emits messages directly 739 - The implementation for :c:func:`kdb_printf` which emits messages directly
748 to I/O drivers, bypassing the kernel log. 740 to I/O drivers, bypassing the kernel log.
749 741
750 - SW / HW breakpoint management for the kdb shell 742 - SW / HW breakpoint management for the kdb shell
@@ -780,21 +772,24 @@ architecture, and at that point you must create an architecture specific
780kgdb implementation. 772kgdb implementation.
781 773
782There are a few flags which must be set on every architecture in their 774There are a few flags which must be set on every architecture in their
783<asm/kgdb.h> file. These are: 775``asm/kgdb.h`` file. These are:
784 776
785- NUMREGBYTES: The size in bytes of all of the registers, so that we 777- ``NUMREGBYTES``:
786 can ensure they will all fit into a packet. 778 The size in bytes of all of the registers, so that we
779 can ensure they will all fit into a packet.
787 780
788- BUFMAX: The size in bytes of the buffer GDB will read into. This must 781- ``BUFMAX``:
789 be larger than NUMREGBYTES. 782 The size in bytes of the buffer GDB will read into. This must
783 be larger than NUMREGBYTES.
790 784
791- CACHE_FLUSH_IS_SAFE: Set to 1 if it is always safe to call 785- ``CACHE_FLUSH_IS_SAFE``:
792 flush_cache_range or flush_icache_range. On some architectures, 786 Set to 1 if it is always safe to call
793 these functions may not be safe to call on SMP since we keep other 787 flush_cache_range or flush_icache_range. On some architectures,
794 CPUs in a holding pattern. 788 these functions may not be safe to call on SMP since we keep other
789 CPUs in a holding pattern.
795 790
796There are also the following functions for the common backend, found in 791There are also the following functions for the common backend, found in
797kernel/kgdb.c, that must be supplied by the architecture-specific 792``kernel/kgdb.c``, that must be supplied by the architecture-specific
798backend unless marked as (optional), in which case a default function 793backend unless marked as (optional), in which case a default function
799maybe used if the architecture does not need to provide a specific 794maybe used if the architecture does not need to provide a specific
800implementation. 795implementation.
@@ -818,9 +813,9 @@ invokes a callback in the serial core which in turn uses the callback in
818the UART driver. 813the UART driver.
819 814
820When using kgdboc with a UART, the UART driver must implement two 815When using kgdboc with a UART, the UART driver must implement two
821callbacks in the ``struct uart_ops``. Example from drivers/8250.c: 816callbacks in the :c:type:`struct uart_ops <uart_ops>`.
817Example from ``drivers/8250.c``::
822 818
823::
824 819
825 #ifdef CONFIG_CONSOLE_POLL 820 #ifdef CONFIG_CONSOLE_POLL
826 .poll_get_char = serial8250_get_poll_char, 821 .poll_get_char = serial8250_get_poll_char,
@@ -838,46 +833,41 @@ consider, because failing here is most likely going to mean pressing the
838reset button. 833reset button.
839 834
840kgdboc and keyboards 835kgdboc and keyboards
841~~~~~~~~~~~~~~~~~~~~ 836~~~~~~~~~~~~~~~~~~~~~~~~
842 837
843The kgdboc driver contains logic to configure communications with an 838The kgdboc driver contains logic to configure communications with an
844attached keyboard. The keyboard infrastructure is only compiled into the 839attached keyboard. The keyboard infrastructure is only compiled into the
845kernel when CONFIG_KDB_KEYBOARD=y is set in the kernel configuration. 840kernel when ``CONFIG_KDB_KEYBOARD=y`` is set in the kernel configuration.
846 841
847The core polled keyboard driver driver for PS/2 type keyboards is in 842The core polled keyboard driver driver for PS/2 type keyboards is in
848drivers/char/kdb_keyboard.c. This driver is hooked into the debug core 843``drivers/char/kdb_keyboard.c``. This driver is hooked into the debug core
849when kgdboc populates the callback in the array called 844when kgdboc populates the callback in the array called
850``kdb_poll_funcs[]``. The kdb_get_kbd_char() is the top-level 845:c:type:`kdb_poll_funcs[]`. The :c:func:`kdb_get_kbd_char` is the top-level
851function which polls hardware for single character input. 846function which polls hardware for single character input.
852 847
853kgdboc and kms 848kgdboc and kms
854~~~~~~~~~~~~~~ 849~~~~~~~~~~~~~~~~~~
855 850
856The kgdboc driver contains logic to request the graphics display to 851The kgdboc driver contains logic to request the graphics display to
857switch to a text context when you are using "kgdboc=kms,kbd", provided 852switch to a text context when you are using ``kgdboc=kms,kbd``, provided
858that you have a video driver which has a frame buffer console and atomic 853that you have a video driver which has a frame buffer console and atomic
859kernel mode setting support. 854kernel mode setting support.
860 855
861Every time the kernel debugger is entered it calls 856Every time the kernel debugger is entered it calls
862kgdboc_pre_exp_handler() which in turn calls con_debug_enter() in 857:c:func:`kgdboc_pre_exp_handler` which in turn calls :c:func:`con_debug_enter`
863the virtual console layer. On resuming kernel execution, the kernel 858in the virtual console layer. On resuming kernel execution, the kernel
864debugger calls kgdboc_post_exp_handler() which in turn calls 859debugger calls :c:func:`kgdboc_post_exp_handler` which in turn calls
865con_debug_leave(). 860:c:func:`con_debug_leave`.
866 861
867Any video driver that wants to be compatible with the kernel debugger 862Any video driver that wants to be compatible with the kernel debugger
868and the atomic kms callbacks must implement the mode_set_base_atomic, 863and the atomic kms callbacks must implement the ``mode_set_base_atomic``,
869fb_debug_enter and fb_debug_leave operations. For the 864``fb_debug_enter`` and ``fb_debug_leave operations``. For the
870fb_debug_enter and fb_debug_leave the option exists to use the 865``fb_debug_enter`` and ``fb_debug_leave`` the option exists to use the
871generic drm fb helper functions or implement something custom for the 866generic drm fb helper functions or implement something custom for the
872hardware. The following example shows the initialization of the 867hardware. The following example shows the initialization of the
873.mode_set_base_atomic operation in 868.mode_set_base_atomic operation in
874drivers/gpu/drm/i915/intel_display.c: 869drivers/gpu/drm/i915/intel_display.c::
875
876.. raw:: html
877
878 <div class="informalexample">
879 870
880::
881 871
882 static const struct drm_crtc_helper_funcs intel_helper_funcs = { 872 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
883 [...] 873 [...]
@@ -886,19 +876,10 @@ drivers/gpu/drm/i915/intel_display.c:
886 }; 876 };
887 877
888 878
889.. raw:: html
890
891 </div>
892
893Here is an example of how the i915 driver initializes the 879Here is an example of how the i915 driver initializes the
894fb_debug_enter and fb_debug_leave functions to use the generic drm 880fb_debug_enter and fb_debug_leave functions to use the generic drm
895helpers in drivers/gpu/drm/i915/intel_fb.c: 881helpers in ``drivers/gpu/drm/i915/intel_fb.c``::
896
897.. raw:: html
898 882
899 <div class="informalexample">
900
901::
902 883
903 static struct fb_ops intelfb_ops = { 884 static struct fb_ops intelfb_ops = {
904 [...] 885 [...]
@@ -908,23 +889,19 @@ helpers in drivers/gpu/drm/i915/intel_fb.c:
908 }; 889 };
909 890
910 891
911.. raw:: html
912
913 </div>
914
915Credits 892Credits
916======= 893=======
917 894
918The following people have contributed to this document: 895The following people have contributed to this document:
919 896
9201. Amit Kale\ amitkale@linsyssoft.com 8971. Amit Kale <amitkale@linsyssoft.com>
921 898
9222. Tom Rini\ trini@kernel.crashing.org 8992. Tom Rini <trini@kernel.crashing.org>
923 900
924In March 2008 this document was completely rewritten by: 901In March 2008 this document was completely rewritten by:
925 902
926- Jason Wessel\ jason.wessel@windriver.com 903- Jason Wessel <jason.wessel@windriver.com>
927 904
928In Jan 2010 this document was updated to include kdb. 905In Jan 2010 this document was updated to include kdb.
929 906
930- Jason Wessel\ jason.wessel@windriver.com 907- Jason Wessel <jason.wessel@windriver.com>