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.

237 lines
9.0 KiB

  1. ;; Copyright (C) 2010, 2014-2016, 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. ;; Ruby Trepanning debugger
  14. (eval-when-compile (require 'cl-lib)) ;For setf.
  15. (require 'load-relative)
  16. (require-relative-list '("../../common/regexp"
  17. "../../common/loc"
  18. "../../common/init")
  19. "realgud-")
  20. (require-relative-list '("../../lang/ruby") "realgud-lang-")
  21. (defvar realgud-pat-hash)
  22. (declare-function make-realgud-loc-pat 'realgud-regexp)
  23. (defvar realgud:trepan-pat-hash (make-hash-table :test 'equal)
  24. "Hash key is the what kind of pattern we want to match:
  25. backtrace, prompt, etc. The values of a hash entry is a
  26. realgud-loc-pat struct")
  27. (setf (gethash "loc-callback-fn" realgud:trepan-pat-hash) 'realgud:trepan-loc-fn-callback)
  28. ;; Regular expression that describes a trepan location generally shown
  29. ;; before a command prompt.
  30. ;; For example:
  31. ;; -- (/tmp/linecache.rb:64)
  32. ;; C> (/tmp/eval.rb:2)
  33. (setf (gethash "loc" realgud:trepan-pat-hash)
  34. (make-realgud-loc-pat
  35. :regexp ".. (\\(?:.+ \\(?:via\\|remapped\\) \\)?\\(.+\\):\\([0-9]+\\)\\(?: @[0-9]+\\)?)\\(?:\n\\(.*?\\)\n\\)?"
  36. :file-group 1
  37. :line-group 2
  38. :text-group 3
  39. ))
  40. ;; An initial list of regexps that don't generally have files
  41. ;; associated with them and therefore we should not try to find file
  42. ;; associations for them. This list is used to seed a field of the
  43. ;; same name in the cmd-info structure inside a command buffer. A user
  44. ;; may add additional files to the command-buffer's re-ignore-list.
  45. (setf (gethash "ignore-re-file-list" realgud:trepan-pat-hash)
  46. '("(eval: .*)"))
  47. ;; Regular expression that describes a trepan command prompt
  48. ;; For example:
  49. ;; (trepan):
  50. ;; ((trepan)):
  51. ;; (trepan@main):
  52. ;; (trepan@55):
  53. (setf (gethash "prompt" realgud:trepan-pat-hash)
  54. (make-realgud-loc-pat
  55. :regexp "^(+trepan\\(@[0-9]+\\|@main\\)?)+: "
  56. ))
  57. ;; Regular expression that describes a Ruby YARV 1.9 syntax error line.
  58. (setf (gethash "syntax-error" realgud:trepan-pat-hash)
  59. realgud-ruby-YARV-syntax-error-pat)
  60. ;; Regular expression that describes a Ruby YARV backtrace line.
  61. ;; For example:
  62. ;; from /ruby/gems/2.2.0/gems/fog-1.32.0/lib/fog/digitalocean.rb:1:in `<top (required)>'
  63. ;; from /Users/fog-1.32.0/lib/fog.rb:28:in `require'
  64. (setf (gethash "lang-backtrace" realgud:trepan-pat-hash)
  65. realgud-ruby-backtrace-loc-pat)
  66. ;; realgud-loc-pat that describes a ruby $! backtrace
  67. (setf (gethash "dollar-bang-backtrace" realgud:trepan-pat-hash)
  68. realgud-ruby-dollar-bang-loc-pat)
  69. ;; realgud-loc-pat that describes a "breakpoint set" line.
  70. ;; For example:
  71. ;; Breakpoint 1 set at VM offset 2 of instruction sequence "require",
  72. ;; line 29 in file <internal:lib/rubygems/custom_require>.
  73. ;; Breakpoint 2 set at VM offset 29 of instruction sequence "<top /xx.rb>",
  74. ;; line 64 in file /src/external-vcs/linecache/trunk/lib/linecache.rb.
  75. (setf (gethash "brkpt-set" realgud:trepan-pat-hash)
  76. (make-realgud-loc-pat
  77. :regexp "^Breakpoint \\([0-9]+\\) set at .*[\n\t ]+line \\([0-9]+\\)[ \t\n]+in file \\(.+\\)."
  78. :num 1
  79. :file-group 3
  80. :line-group 2))
  81. ;; realgud-loc-pat that describes a debugger "delete" (breakpoint) response.
  82. ;; For example:
  83. ;; Deleted breakpoint 1.
  84. (setf (gethash "brkpt-del" realgud:trepan-pat-hash)
  85. (make-realgud-loc-pat
  86. :regexp "^Deleted breakpoint \\([0-9]+\\).\n"
  87. :num 1))
  88. (defconst realgud:trepan-selected-frame-indicator "-->"
  89. "String that describes which frame is selected in a debugger
  90. backtrace listing.")
  91. (defconst realgud:trepan-frame-file-regexp
  92. "[ \t\n]+in file \\([^ \n]+\\)")
  93. (defconst realgud:trepan-debugger-name "trepan" "Name of debugger")
  94. ;; Top frame number
  95. (setf (gethash "top-frame-num" realgud:trepan-pat-hash) 0)
  96. ;; realgud-loc-pat that describes a debugger "selected" frame in in
  97. ;; a frame-motion command.
  98. ;; For example:
  99. ;; --> #1 TOP Object#<top /usr/local/bin/irb> in file /usr/local/bin/irb at line 9
  100. (setf (gethash "selected-frame" realgud:trepan-pat-hash)
  101. (make-realgud-loc-pat
  102. :regexp
  103. (format "^%s #\\([0-9]+\\) .*%s"
  104. realgud:trepan-selected-frame-indicator
  105. realgud:trepan-frame-file-regexp)
  106. :num 1))
  107. (setf (gethash "control-frame" realgud:trepan-pat-hash)
  108. (make-realgud-loc-pat
  109. :regexp "^c:\\([0-9]+\\) p:\\([0-9]+\\) s:\\([0-9]+\\) b:\\([0-9]+\\) l:\\([0-9a-f]+\\) d:\\([0-9a-f]+\\) \\([A-Z]+\\) \\(.+\\):\\([0-9]+\\)"
  110. :file-group 8
  111. :line-group 9))
  112. ;; realgud-loc-pat that describes a Ruby $! string
  113. (setf (gethash "dollar-bang" realgud:trepan-pat-hash)
  114. realgud-ruby-dollar-bang-loc-pat)
  115. ;; realgud-loc-pat that describes debugger "backtrace" command line.
  116. ;; e.g.
  117. ;; --> #0 METHOD Object#require(path) in file <internal:lib/require> at line 28
  118. ;; #1 TOP Object#<top /tmp/linecache.rb> in file /tmp/linecache.rb
  119. (setf (gethash "debugger-backtrace" realgud:trepan-pat-hash)
  120. (make-realgud-loc-pat
  121. :regexp (concat realgud:trepan-frame-start-regexp " "
  122. realgud:trepan-frame-num-regexp " "
  123. "\\([A-Z]+\\) *\\([A-Z_][a-zA-Z0-9_]*\\)[#]\\(.*\\)"
  124. realgud:trepan-frame-file-regexp
  125. "\\(?:" realgud:trepan-frame-line-regexp "\\)?"
  126. )
  127. :num 2
  128. :file-group 6
  129. :line-group 7)
  130. )
  131. ;; realgud-loc-pat that for a termination message.
  132. (setf (gethash "termination" realgud:trepan-pat-hash)
  133. "^trepan: That's all, folks...\n")
  134. (setf (gethash "font-lock-keywords" realgud:trepan-pat-hash)
  135. '(
  136. ;; The frame number and first type name, if present.
  137. ("^\\(-->\\| \\)? #\\([0-9]+\\) \\([A-Z]+\\) *\\([A-Z_][a-zA-Z0-9_]*\\)[#]\\([a-zA-Z_][a-zA-Z_[0-9]]*\\)?"
  138. (2 realgud-backtrace-number-face)
  139. (3 font-lock-keyword-face) ; e.g. METHOD, TOP
  140. (4 font-lock-constant-face) ; e.g. Object
  141. (5 font-lock-function-name-face nil t)) ; t means optional
  142. ;; Instruction sequence
  143. ("<\\(.+\\)>"
  144. (1 font-lock-variable-name-face))
  145. ;; "::Type", which occurs in class name of function and in parameter list.
  146. ;; Parameter sequence
  147. ("(\\(.+\\))"
  148. (1 font-lock-variable-name-face))
  149. ;; "::Type", which occurs in class name of function and in parameter list.
  150. ("::\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  151. (1 font-lock-type-face))
  152. ;; File name.
  153. ("[ \t]+in file \\([^ ]+*\\)"
  154. (1 realgud-file-name-face))
  155. ;; Line number.
  156. ("[ \t]+at line \\([0-9]+\\)$"
  157. (1 realgud-line-number-face))
  158. ;; Function name.
  159. ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\.\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  160. (1 font-lock-type-face)
  161. (2 font-lock-function-name-face))
  162. ;; (trepan-frames-match-current-line
  163. ;; (0 trepan-frames-current-frame-face append))
  164. ))
  165. ;; (setf (gethash "font-lock-keywords" realgud:trepan-pat-hash)
  166. ;; '(
  167. ;; ;; The frame number and first type name, if present.
  168. ;; ((concat realgud:trepan-frame-start-regexp " "
  169. ;; realgud:trepan-frame-num-regexp " "
  170. ;; "\\([A-Z]+\\) *\\([A-Z_][a-zA-Z0-9_]*\\)[#]\\([a-zA-Z_][a-zA-Z_[0-9]]*\\)?")
  171. ;; (2 realgud-backtrace-number-face)
  172. ;; (3 font-lock-keyword-face) ; e.g. METHOD, TOP
  173. ;; (4 font-lock-constant-face) ; e.g. Object
  174. ;; (5 font-lock-function-name-face nil t)) ; t means optional
  175. ;; ;; Instruction sequence
  176. ;; ("<\\(.+\\)>"
  177. ;; (1 font-lock-variable-name-face))
  178. ;; ;; "::Type", which occurs in class name of function and in
  179. ;; ;; parameter list. Parameter sequence
  180. ;; ("(\\(.+\\))"
  181. ;; (1 font-lock-variable-name-face))
  182. ;; ;; "::Type", which occurs in class name of function and in
  183. ;; ;; parameter list.
  184. ;; ("::\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  185. ;; (1 font-lock-type-face))
  186. ;; ;; File name.
  187. ;; (realgud:trepan-frame-file-regexp (1 realgud-file-name-face))
  188. ;; ;; Line number.
  189. ;; (realgud:trepan-frame-line-regexp (1 realgud-line-number-face))
  190. ;; ;; Function name.
  191. ;; ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\.\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  192. ;; (1 font-lock-type-face)
  193. ;; (2 font-lock-function-name-face))
  194. ;; ;; (trepan-frames-match-current-line
  195. ;; ;; (0 trepan-frames-current-frame-face append))
  196. ;; ))
  197. (setf (gethash realgud:trepan-debugger-name realgud-pat-hash) realgud:trepan-pat-hash)
  198. (defvar realgud:trepan-command-hash (make-hash-table :test 'equal)
  199. "Hash key is command name like 'quit' and the value is
  200. the trepan command to use, like 'quit!'")
  201. (setf (gethash "quit" realgud:trepan-command-hash) "quit!")
  202. (setf (gethash "shell" realgud:trepan-command-hash) "irb")
  203. (setf (gethash realgud:trepan-debugger-name
  204. realgud-command-hash) realgud:trepan-command-hash)
  205. (provide-me "realgud:trepan-")