Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
6.8 KiB

  1. ;; Copyright (C) 2015-2017, 2019 Free Software Foundation, Inc
  2. ;; Author: Rocky Bernstein <rocky@gnu.org>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; gdb debugger
  14. (eval-when-compile (require 'cl-lib))
  15. (require 'load-relative)
  16. (require-relative-list '("../../common/regexp" "../../common/loc") "realgud-")
  17. (defvar realgud-pat-hash)
  18. (declare-function make-realgud-loc-pat 'realgud-regexp)
  19. (defvar realgud:gdb-pat-hash (make-hash-table :test 'equal)
  20. "Hash key is the what kind of pattern we want to match:
  21. backtrace, prompt, etc. the values of a hash entry is a
  22. realgud-loc-pat struct")
  23. (declare-function make-realgud-loc "realgud-loc" (a b c d e f))
  24. (defconst realgud:gdb-frame-file-regexp
  25. (format "\\(.+\\):%s" realgud:regexp-captured-num))
  26. ;; Regular expression that describes a lldb location generally shown
  27. ;; before a command prompt. NOTE: we assume annotate 1!
  28. ;; For example:
  29. ;; /src/build/ruby-2.1.5/main.c:24:454:beg:0x55555557659f
  30. (setf (gethash "loc" realgud:gdb-pat-hash)
  31. (make-realgud-loc-pat
  32. :regexp (format "^%s:%s:beg:0x\\([0-9a-f]+\\)"
  33. realgud:gdb-frame-file-regexp realgud:regexp-captured-num)
  34. :file-group 1
  35. :line-group 2
  36. :char-offset-group 3))
  37. ;; Regular expression that describes a gdb prompt
  38. ;; For example:
  39. ;; (gdb)
  40. (setf (gethash "prompt" realgud:gdb-pat-hash)
  41. (make-realgud-loc-pat
  42. :regexp "^(gdb) "
  43. ))
  44. ;; Regular expression that describes a "breakpoint set" line
  45. ;; For example:
  46. ;; Breakpoint 1, main (argc=1, argv=0x7fffffffdbd8) at main.c:24
  47. (setf (gethash "brkpt-set" realgud:gdb-pat-hash)
  48. (list
  49. (make-realgud-loc-pat
  50. :regexp (format "^Breakpoint %s at 0x\\([0-9a-f]*\\): file \\(.+\\), line %s[.]\n"
  51. realgud:regexp-captured-num realgud:regexp-captured-num)
  52. :num 1
  53. :file-group 3
  54. :line-group 4)
  55. ;; Another breakpoint pattern seen
  56. (make-realgud-loc-pat
  57. :regexp (format "^Breakpoint %s, .* at \\(.+\\):%s[.]\n"
  58. realgud:regexp-captured-num realgud:regexp-captured-num)
  59. :num 1
  60. :file-group 2
  61. :line-group 3)
  62. ))
  63. ;; Regular expression that describes a debugger "delete" (breakpoint)
  64. ;; response.
  65. ;; For example:
  66. ;; Deleted breakpoint 1
  67. ;; Deleted breakpoints 1 2 3 4
  68. (setf (gethash "brkpt-del" realgud:gdb-pat-hash)
  69. (make-realgud-loc-pat
  70. :regexp "^Deleted breakpoints? \\(\\([0-9]+ *\\)+\\)\n"
  71. :num 1))
  72. (defconst realgud:gdb-frame-start-regexp
  73. "\\(?:^\\|\n\\)")
  74. (defconst realgud:gdb-frame-num-regexp
  75. (format "#%s " realgud:regexp-captured-num))
  76. ;; Regular expression that describes a gdb "backtrace" command line.
  77. ;; For example:
  78. ;; #0 main (argc=2, argv=0xbffff564, envp=0xbffff570) at main.c:935
  79. ;; #1 0xb7e9f4a5 in *__GI___strdup (s=0xbffff760 "/tmp/remake/remake") at strdup.c:42
  80. ;; #2 0x080593ac in main (argc=2, argv=0xbffff5a4, envp=0xbffff5b0)
  81. ;; at main.c:952
  82. ;; #46 0xb7f51b87 in vm_call_cfunc (th=0x804d188, reg_cfp=0xb7ba9e88, num=0,
  83. ;; recv=157798080, blockptr=0x0, me=0x80d12a0) at vm_insnhelper.c:410
  84. (setf (gethash "debugger-backtrace" realgud:gdb-pat-hash)
  85. (make-realgud-loc-pat
  86. :regexp (concat realgud:gdb-frame-start-regexp
  87. realgud:gdb-frame-num-regexp
  88. "\\(?:.\\|\\(?:[\n] \\)\\)+[ ]+at "
  89. realgud:gdb-frame-file-regexp
  90. )
  91. :num 1
  92. :file-group 2
  93. :line-group 3)
  94. )
  95. ;; FIXME breakpoints aren't locations. It should be a different structure
  96. ;; Regular expression that describes a gdb "info breakpoint" line
  97. ;; For example:
  98. ;; 1 breakpoint keep y 0x0000000000401471 in vcdnav_get_entries at ctest.c:67
  99. (setf (gethash "debugger-breakpoint" realgud:gdb-pat-hash)
  100. (make-realgud-loc-pat
  101. :regexp (format "^%s[ \t]+\\(breakpoint\\)[ \t]+\\(keep\\|del\\)[ \t]+\\([yn]\\)[ \t]+.*at \\(.+\\):%s"
  102. realgud:regexp-captured-num realgud:regexp-captured-num)
  103. :num 1
  104. :text-group 2 ;; misnamed Is "breakpoint" or "watchpoint"
  105. :string 3 ;; misnamed. Is "keep" or "del"
  106. ;; Enable is missing
  107. ;; Skipped address
  108. :file-group 5
  109. :line-group 6)
  110. )
  111. (setf (gethash "font-lock-keywords" realgud:gdb-pat-hash)
  112. '(
  113. ;; #2 0x080593ac in main (argc=2, argv=0xbffff5a4, envp=0xbffff5b0)
  114. ;; at main.c:952
  115. ("[ \n]+at \\(.*\\):\\([0-9]+\\)"
  116. (1 realgud-file-name-face)
  117. (2 realgud-line-number-face))
  118. ;; The frame number and first type name, if present.
  119. ;; E.g. =>#0 Makefile.in at /tmp/Makefile:216
  120. ;; ---^
  121. ( "#\\(?:^\\|\n\\)\\([0-9]+\\) "
  122. (1 realgud-backtrace-number-face))
  123. ))
  124. (setf (gethash "font-lock-breakpoint-keywords" realgud:gdb-pat-hash)
  125. '(
  126. ;; The breakpoint number, type and disposition
  127. ;; 1 breakpoint keep y 0x0000000000401471 in vcdnav_get_entries at ctest.c:67
  128. ;; ^ ^^^^^^^^^^ ^^^^
  129. ("^\\([0-9]+\\)[ \t]+\\(breakpoint\\)[ \t]+\\(keep\\|del\\)"
  130. (1 realgud-breakpoint-number-face)
  131. (2 font-lock-function-name-face nil t) ; t means optional.
  132. (3 font-lock-function-name-face nil t)) ; t means optional.
  133. ;; 1 breakpoint keep y 0x0000000000401471 in vcdnav_get_entries at ctest.c:67
  134. ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
  135. (" in[ \t]+\\(.+*\\):\\([0-9]+\\)"
  136. (1 realgud-file-name-face)
  137. (2 realgud-line-number-face))
  138. ))
  139. (setf (gethash "gdb" realgud-pat-hash) realgud:gdb-pat-hash)
  140. ;; Prefix used in variable names (e.g. short-key-mode-map) for
  141. ;; this debugger
  142. (setf (gethash "gdb" realgud:variable-basename-hash) "realgud:gdb")
  143. (defvar realgud:gdb-command-hash (make-hash-table :test 'equal)
  144. "Hash key is command name like 'continue' and the value is
  145. the gdb command to use, like 'continue'.")
  146. (setf (gethash "break" realgud:gdb-command-hash) "break %X:%l")
  147. (setf (gethash "clear" realgud:gdb-command-hash) "clear %X:%l")
  148. (setf (gethash "continue" realgud:gdb-command-hash) "continue")
  149. (setf (gethash "delete" realgud:gdb-command-hash) "delete %p")
  150. (setf (gethash "eval" realgud:gdb-command-hash) "print %s")
  151. (setf (gethash "quit" realgud:gdb-command-hash) "quit")
  152. (setf (gethash "run" realgud:gdb-command-hash) "run")
  153. (setf (gethash "step" realgud:gdb-command-hash) "step %p")
  154. (setf (gethash "gdb" realgud-command-hash) realgud:gdb-command-hash)
  155. (setf (gethash "gdb" realgud-pat-hash) realgud:gdb-pat-hash)
  156. (provide-me "realgud:gdb-")