kgdb.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. This file describes the configuration and behavior of KGDB for the SH
  2. kernel. Based on a description from Henry Bell <henry.bell@st.com>, it
  3. has been modified to account for quirks in the current implementation.
  4. Version
  5. =======
  6. This version of KGDB was written for 2.4.xx kernels for the SH architecture.
  7. Further documentation is available from the linux-sh project website.
  8. Debugging Setup: Host
  9. ======================
  10. The two machines will be connected together via a serial line - this
  11. should be a null modem cable i.e. with a twist.
  12. On your DEVELOPMENT machine, go to your kernel source directory and
  13. build the kernel, enabling KGDB support in the "kernel hacking" section.
  14. This includes the KGDB code, and also makes the kernel be compiled with
  15. the "-g" option set -- necessary for debugging.
  16. To install this new kernel, use the following installation procedure.
  17. Decide on which tty port you want the machines to communicate, then
  18. cable them up back-to-back using the null modem. On the DEVELOPMENT
  19. machine, you may wish to create an initialization file called .gdbinit
  20. (in the kernel source directory or in your home directory) to execute
  21. commonly-used commands at startup.
  22. A minimal .gdbinit might look like this:
  23. file vmlinux
  24. set remotebaud 115200
  25. target remote /dev/ttyS0
  26. Change the "target" definition so that it specifies the tty port that
  27. you intend to use. Change the "remotebaud" definition to match the
  28. data rate that you are going to use for the com line (115200 is the
  29. default).
  30. Debugging Setup: Target
  31. ========================
  32. By default, the KGDB stub will communicate with the host GDB using
  33. ttySC1 at 115200 baud, 8 databits, no parity; these defaults can be
  34. changed in the kernel configuration. As the kernel starts up, KGDB will
  35. initialize so that breakpoints, kernel segfaults, and so forth will
  36. generally enter the debugger.
  37. This behavior can be modified by including the "kgdb" option in the
  38. kernel command line; this option has the general form:
  39. kgdb=<ttyspec>,<action>
  40. The <ttyspec> indicates the port to use, and can optionally specify
  41. baud, parity and databits -- e.g. "ttySC0,9600N8" or "ttySC1,19200".
  42. The <action> can be "halt" or "disabled". The "halt" action enters the
  43. debugger via a breakpoint as soon as kgdb is initialized; the "disabled"
  44. action causes kgdb to ignore kernel segfaults and such until explicitly
  45. entered by a breakpoint in the code or by external action (sysrq or NMI).
  46. (Both <ttyspec> and <action> can appear alone, w/o the separating comma.)
  47. For example, if you wish to debug early in kernel startup code, you
  48. might specify the halt option:
  49. kgdb=halt
  50. Boot the TARGET machine, which will appear to hang.
  51. On your DEVELOPMENT machine, cd to the source directory and run the gdb
  52. program. (This is likely to be a cross GDB which runs on your host but
  53. is built for an SH target.) If everything is working correctly you
  54. should see gdb print out a few lines indicating that a breakpoint has
  55. been taken. It will actually show a line of code in the target kernel
  56. inside the gdbstub activation code.
  57. NOTE: BE SURE TO TERMINATE OR SUSPEND any other host application which
  58. may be using the same serial port (for example, a terminal emulator you
  59. have been using to connect to the target boot code.) Otherwise, data
  60. from the target may not all get to GDB!
  61. You can now use whatever gdb commands you like to set breakpoints.
  62. Enter "continue" to start your target machine executing again. At this
  63. point the target system will run at full speed until it encounters
  64. your breakpoint or gets a segment violation in the kernel, or whatever.
  65. Serial Ports: KGDB, Console
  66. ============================
  67. This version of KGDB may not gracefully handle conflict with other
  68. drivers in the kernel using the same port. If KGDB is configured on the
  69. same port (and with the same parameters) as the kernel console, or if
  70. CONFIG_SH_KGDB_CONSOLE is configured, things should be fine (though in
  71. some cases console messages may appear twice through GDB). But if the
  72. KGDB port is not the kernel console and used by another serial driver
  73. which assumes different serial parameters (e.g. baud rate) KGDB may not
  74. recover.
  75. Also, when KGDB is entered via sysrq-g (requires CONFIG_KGDB_SYSRQ) and
  76. the kgdb port uses the same port as the console, detaching GDB will not
  77. restore the console to working order without the port being re-opened.
  78. Another serious consequence of this is that GDB currently CANNOT break
  79. into KGDB externally (e.g. via ^C or <BREAK>); unless a breakpoint or
  80. error is encountered, the only way to enter KGDB after the initial halt
  81. (see above) is via NMI (CONFIG_KGDB_NMI) or sysrq-g (CONFIG_KGDB_SYSRQ).
  82. Code is included for the basic Hitachi Solution Engine boards to allow
  83. the use of ttyS0 for KGDB if desired; this is less robust, but may be
  84. useful in some cases. (This cannot be selected using the config file,
  85. but only through the kernel command line, e.g. "kgdb=ttyS0", though the
  86. configured defaults for baud rate etc. still apply if not overridden.)
  87. If gdbstub Does Not Work
  88. ========================
  89. If it doesn't work, you will have to troubleshoot it. Do the easy
  90. things first like double checking your cabling and data rates. You
  91. might try some non-kernel based programs to see if the back-to-back
  92. connection works properly. Just something simple like cat /etc/hosts
  93. /dev/ttyS0 on one machine and cat /dev/ttyS0 on the other will tell you
  94. if you can send data from one machine to the other. There is no point
  95. in tearing out your hair in the kernel if the line doesn't work.
  96. If you need to debug the GDB/KGDB communication itself, the gdb commands
  97. "set debug remote 1" and "set debug serial 1" may be useful, but be
  98. warned: they produce a lot of output.
  99. Threads
  100. =======
  101. Each process in a target machine is seen as a gdb thread. gdb thread related
  102. commands (info threads, thread n) can be used. CONFIG_KGDB_THREAD must
  103. be defined for this to work.
  104. In this version, kgdb reports PID_MAX (32768) as the process ID for the
  105. idle process (pid 0), since GDB does not accept 0 as an ID.
  106. Detaching (exiting KGDB)
  107. =========================
  108. There are two ways to resume full-speed target execution: "continue" and
  109. "detach". With "continue", GDB inserts any specified breakpoints in the
  110. target code and resumes execution; the target is still in "gdb mode".
  111. If a breakpoint or other debug event (e.g. NMI) happens, the target
  112. halts and communicates with GDB again, which is waiting for it.
  113. With "detach", GDB does *not* insert any breakpoints; target execution
  114. is resumed and GDB stops communicating (does not wait for the target).
  115. In this case, the target is no longer in "gdb mode" -- for example,
  116. console messages no longer get sent separately to the KGDB port, or
  117. encapsulated for GDB. If a debug event (e.g. NMI) occurs, the target
  118. will re-enter "gdb mode" and will display this fact on the console; you
  119. must give a new "target remote" command to gdb.
  120. NOTE: TO AVOID LOSSING CONSOLE MESSAGES IN CASE THE KERNEL CONSOLE AND
  121. KGDB USING THE SAME PORT, THE TARGET WAITS FOR ANY INPUT CHARACTER ON
  122. THE KGDB PORT AFTER A DETACH COMMAND. For example, after the detach you
  123. could start a terminal emulator on the same host port and enter a <cr>;
  124. however, this program must then be terminated or suspended in order to
  125. use GBD again if KGDB is re-entered.
  126. Acknowledgements
  127. ================
  128. This code was mostly generated by Henry Bell <henry.bell@st.com>;
  129. largely from KGDB by Amit S. Kale <akale@veritas.com> - extracts from
  130. code by Glenn Engel, Jim Kingdon, David Grothe <dave@gcom.com>, Tigran
  131. Aivazian <tigran@sco.com>, William Gatliff <bgat@open-widgets.com>, Ben
  132. Lee, Steve Chamberlain and Benoit Miller <fulg@iname.com> are also
  133. included.
  134. Jeremy Siegel
  135. <jsiegel@mvista.com>