gdbstub.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ====================
  2. DEBUGGING FR-V LINUX
  3. ====================
  4. The kernel contains a GDB stub that talks GDB remote protocol across a serial
  5. port. This permits GDB to single step through the kernel, set breakpoints and
  6. trap exceptions that happen in kernel space and interrupt execution. It also
  7. permits the NMI interrupt button or serial port events to jump the kernel into
  8. the debugger.
  9. On the CPUs that have on-chip UARTs (FR400, FR403, FR405, FR555), the
  10. GDB stub hijacks a serial port for its own purposes, and makes it
  11. generate level 15 interrupts (NMI). The kernel proper cannot see the serial
  12. port in question under these conditions.
  13. On the MB93091-VDK CPU boards, the GDB stub uses UART1, which would otherwise
  14. be /dev/ttyS1. On the MB93093-PDK, the GDB stub uses UART0. Therefore, on the
  15. PDK there is no externally accessible serial port and the serial port to
  16. which the touch screen is attached becomes /dev/ttyS0.
  17. Note that the GDB stub runs entirely within CPU debug mode, and so should not
  18. incur any exceptions or interrupts whilst it is active. In particular, note
  19. that the clock will lose time since it is implemented in software.
  20. ==================
  21. KERNEL PREPARATION
  22. ==================
  23. Firstly, a debuggable kernel must be built. To do this, unpack the kernel tree
  24. and copy the configuration that you wish to use to .config. Then reconfigure
  25. the following things on the "Kernel Hacking" tab:
  26. (*) "Include debugging information"
  27. Set this to "Y". This causes all C and Assembly files to be compiled
  28. to include debugging information.
  29. (*) "In-kernel GDB stub"
  30. Set this to "Y". This causes the GDB stub to be compiled into the
  31. kernel.
  32. (*) "Immediate activation"
  33. Set this to "Y" if you want the GDB stub to activate as soon as possible
  34. and wait for GDB to connect. This allows you to start tracing right from
  35. the beginning of start_kernel() in init/main.c.
  36. (*) "Console through GDB stub"
  37. Set this to "Y" if you wish to be able to use "console=gdb0" on the
  38. command line. That tells the kernel to pass system console messages to
  39. GDB (which then prints them on its standard output). This is useful when
  40. debugging the serial drivers that'd otherwise be used to pass console
  41. messages to the outside world.
  42. Then build as usual, download to the board and execute. Note that if
  43. "Immediate activation" was selected, then the kernel will wait for GDB to
  44. attach. If not, then the kernel will boot immediately and GDB will have to
  45. interrupt it or wait for an exception to occur before doing anything with
  46. the kernel.
  47. =========================
  48. KERNEL DEBUGGING WITH GDB
  49. =========================
  50. Set the serial port on the computer that's going to run GDB to the appropriate
  51. baud rate. Assuming the board's debug port is connected to ttyS0/COM1 on the
  52. computer doing the debugging:
  53. stty -F /dev/ttyS0 115200
  54. Then start GDB in the base of the kernel tree:
  55. frv-uclinux-gdb linux [uClinux]
  56. Or:
  57. frv-uclinux-gdb vmlinux [MMU linux]
  58. When the prompt appears:
  59. GNU gdb frv-031024
  60. Copyright 2003 Free Software Foundation, Inc.
  61. GDB is free software, covered by the GNU General Public License, and you are
  62. welcome to change it and/or distribute copies of it under certain conditions.
  63. Type "show copying" to see the conditions.
  64. There is absolutely no warranty for GDB. Type "show warranty" for details.
  65. This GDB was configured as "--host=i686-pc-linux-gnu --target=frv-uclinux"...
  66. (gdb)
  67. Attach to the board like this:
  68. (gdb) target remote /dev/ttyS0
  69. Remote debugging using /dev/ttyS0
  70. start_kernel () at init/main.c:395
  71. (gdb)
  72. This should show the appropriate lines from the source too. The kernel can
  73. then be debugged almost as if it's any other program.
  74. ===============================
  75. INTERRUPTING THE RUNNING KERNEL
  76. ===============================
  77. The kernel can be interrupted whilst it is running, causing a jump back to the
  78. GDB stub and the debugger:
  79. (*) Pressing Ctrl-C in GDB. This will cause GDB to try and interrupt the
  80. kernel by sending an RS232 BREAK over the serial line to the GDB
  81. stub. This will (mostly) immediately interrupt the kernel and return it
  82. to the debugger.
  83. (*) Pressing the NMI button on the board will also cause a jump into the
  84. debugger.
  85. (*) Setting a software breakpoint. This sets a break instruction at the
  86. desired location which the GDB stub then traps the exception for.
  87. (*) Setting a hardware breakpoint. The GDB stub is capable of using the IBAR
  88. and DBAR registers to assist debugging.
  89. Furthermore, the GDB stub will intercept a number of exceptions automatically
  90. if they are caused by kernel execution. It will also intercept BUG() macro
  91. invocation.