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.

281 lines
10 KiB

  1. ;; Copyright (C) 2015-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. ;; Trepanning Perl 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/perl") "realgud-lang-")
  21. (defvar realgud-pat-hash)
  22. (declare-function make-realgud-loc-pat 'realgud-regexp)
  23. (defvar realgud:trepanpl-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. ;; Regular expression that describes a trepan.pl location generally shown
  28. ;; before a command prompt. We include matching the source text so we
  29. ;; can save that.
  30. ;;
  31. ;; Program-location lines look like this:
  32. ;; -- File::Basename::(/usr/share/perl/5.14/File/Basename.pm:284 @0x8918b70)
  33. ;; my $dirname = dirname(__FILE__);
  34. ;;
  35. ;; or for an eval'd expression:
  36. ;; -- main::((eval 1189)[/tmp/test.pl:2] remapped /tmp/JLlH.pl:1 @0xadcbda0)
  37. ;; $x = 1 + 2;
  38. ;;
  39. ;; or at a function call without the Perl OpCode position or source text:
  40. ;; -> main::(example/gcd.pl:8)
  41. (setf (gethash "loc" realgud:trepanpl-pat-hash)
  42. (make-realgud-loc-pat
  43. :regexp (format ".. \\(?:.+::\\)?(\\(?:.+ \\(?:via\\|remapped\\) \\)?\\(.+\\):%s\\(?: @0x[0-9a-f]+\\)?)\\(?:\n\\(.*?\\)\n\\)?"
  44. realgud:regexp-captured-num)
  45. :file-group 1
  46. :line-group 2
  47. :text-group 3
  48. :ignore-file-re realgud-perl-ignore-file-re)
  49. )
  50. (defconst realgud:trepanpl-frame-start-regexp
  51. "\\(^\\|\n\\)\\(?:-->\\| \\) #")
  52. ;; Regular expression that describes a trepanpl command prompt
  53. ;; For example:
  54. ;; (trepanpl):
  55. ;; ((trepanpl)):
  56. ;; (trepanpl@main):
  57. ;; (trepanpl@55):
  58. (defconst realgud:trepanpl-prompt-regexp
  59. "^(+trepanpl\\(@[0-9]+\\|@main\\)?)+: ")
  60. (setf (gethash "prompt" realgud:trepanpl-pat-hash)
  61. (make-realgud-loc-pat
  62. :regexp realgud:trepanpl-prompt-regexp
  63. ))
  64. (defconst realgud:trepanpl-eval-result-prefix-regexp
  65. "^\\$DB::D\\[[0-9]+\\] = ")
  66. (setf (gethash "prompt" realgud:trepanpl-pat-hash)
  67. (make-realgud-loc-pat
  68. :regexp realgud:trepanpl-prompt-regexp
  69. ))
  70. (defconst realgud:trepanpl-frame-num-regexp
  71. realgud:regexp-captured-num)
  72. ;; Regular expression that describes a Perl backtrace line.
  73. ;; For example:
  74. ;; --> #0 @ = File::Basename::fileparse('/usr/local/bin/trepan.pl') in
  75. ;; file `/usr/share/perl/5.18.2/File/Basename.pm' at line 107
  76. ;; #1 @ = File::Basename::dirname('/usr/local/bin/trepan.pl') in
  77. ;; file `/usr/share/perl/5.18.2/File/Basename.pm' at line 294
  78. ;; #2 file `/usr/local/bin/trepan.pl' at line 11
  79. (setf (gethash "debugger-backtrace" realgud:trepanpl-pat-hash)
  80. (make-realgud-loc-pat
  81. :regexp (concat
  82. realgud:trepanpl-frame-start-regexp
  83. realgud:trepanpl-frame-num-regexp
  84. "\\(?: [$@] = .* in\\)?"
  85. "[\n\t ]+?file `"
  86. "\\(.*\\)' at line "
  87. realgud:regexp-captured-num)
  88. :num 2
  89. :file-group 3
  90. :line-group 4
  91. :ignore-file-re realgud-perl-ignore-file-re)
  92. )
  93. ;; Regular expression that describes location in a Perl errmsg
  94. (setf (gethash "perl-errmsg" realgud:trepanpl-pat-hash)
  95. realgud-perl-errmsg-loc-pat)
  96. ;; Regular expression that describes a Perl Carp backtrace line.
  97. ;; at /tmp/foo.pl line 7
  98. ;; main::__ANON__('Illegal division by zero at /tmp/foo.pl line 4.\x{a}') called at /tmp/foo.pl line 4
  99. ;; main::foo(3) called at /tmp/foo.pl line 8
  100. (setf (gethash "lang-backtrace" realgud:trepanpl-pat-hash)
  101. realgud-perl-carp-loc-pat)
  102. ;; Regular expression that describes a "breakpoint set" line.
  103. ;; For example:
  104. ;; Breakpoint 1 set in (eval 1177)[/Eval.pm:94] at line 5"
  105. ;; Breakpoint 2 set in /tmp/File/Basename.pm at line 215
  106. (setf (gethash "brkpt-set" realgud:trepanpl-pat-hash)
  107. (make-realgud-loc-pat
  108. :regexp (format "^Breakpoint %s set in[\n\t ]+\\(.+\\)[ \t\n]+at line \\([0-9]+\\)"
  109. realgud:regexp-captured-num)
  110. :num 1
  111. :file-group 2
  112. :line-group 3
  113. :ignore-file-re realgud-perl-ignore-file-re)
  114. )
  115. ;; Regular expression that describes a debugger "delete" (breakpoint) response.
  116. ;; For example:
  117. ;; Deleted breakpoint 1.
  118. (setf (gethash "brkpt-del" realgud:trepanpl-pat-hash)
  119. (make-realgud-loc-pat
  120. :regexp (format "^Deleted breakpoint %s\n"
  121. realgud:regexp-captured-num)
  122. :num 1))
  123. ;; Regular expression that describes a debugger "disable" (breakpoint) response.
  124. ;; For example:
  125. ;; Breakpoint entry 4 disabled.
  126. (setf (gethash "brkpt-disable" realgud:trepanpl-pat-hash)
  127. (make-realgud-loc-pat
  128. :regexp (format "^Breakpoint %s disabled"
  129. realgud:regexp-captured-num)
  130. :num 1))
  131. ;; Regular expression that describes a debugger "enable" (breakpoint) response.
  132. ;; For example:
  133. ;; Breakpoint 4 enabled.
  134. (setf (gethash "brkpt-enable" realgud:trepanpl-pat-hash)
  135. (make-realgud-loc-pat
  136. :regexp (format "^Breakpoint %s enabled"
  137. realgud:regexp-captured-num)
  138. :num 1))
  139. (defconst realgud:trepanpl-selected-frame-indicator "-->"
  140. "String that describes which frame is selected in a debugger
  141. backtrace listing.")
  142. (defconst realgud:trepanpl-frame-file-regexp
  143. "[ \t\n]+in file \\([^ \n]+\\)")
  144. (defconst realgud:trepanpl-debugger-name "trepan.pl" "Name of debugger")
  145. ;; Top frame number
  146. (setf (gethash "top-frame-num" realgud:trepanpl-pat-hash) 0)
  147. ;; realgud-loc-pat that describes a debugger "selected" frame in in
  148. ;; a frame-motion command.
  149. ;; For example:
  150. ;; --> #1 TOP Object#<top /usr/local/bin/irb> in file /usr/local/bin/ipl at line 9
  151. (setf (gethash "selected-frame" realgud:trepanpl-pat-hash)
  152. (make-realgud-loc-pat
  153. :regexp
  154. (format "^%s #\\([0-9]+\\) .*%s"
  155. realgud:trepanpl-selected-frame-indicator
  156. realgud:trepanpl-frame-file-regexp)
  157. :num 1))
  158. ;; Regular expression that for a termination message.
  159. (setf (gethash "termination" realgud:trepanpl-pat-hash)
  160. "^trepan.pl: That's all, folks...\n")
  161. (setf (gethash "font-lock-keywords" realgud:trepanpl-pat-hash)
  162. '(
  163. ;; The frame number and first type name, if present.
  164. ("^\\(-->\\| \\)? #\\([0-9]+\\) \\([A-Z]+\\) *\\([A-Z_][a-zA-Z0-9_]*\\)[#]\\([a-zA-Z_][a-zA-Z_[0-9]]*\\)?"
  165. (2 realgud-backtrace-number-face)
  166. (3 font-lock-keyword-face) ; e.g. METHOD, TOP
  167. (4 font-lock-constant-face) ; e.g. Object
  168. (5 font-lock-function-name-face nil t)) ; t means optional
  169. ;; Instruction sequence
  170. ("<\\(.+\\)>"
  171. (1 font-lock-variable-name-face))
  172. ;; "::Type", which occurs in class name of function and in parameter list.
  173. ;; Parameter sequence
  174. ("(\\(.+\\))"
  175. (1 font-lock-variable-name-face))
  176. ;; "::Type", which occurs in class name of function and in parameter list.
  177. ("::\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  178. (1 font-lock-type-face))
  179. ;; File name.
  180. ("[ \t]+in file \\([^ ]+*\\)"
  181. (1 realgud-file-name-face))
  182. ;; Line number.
  183. ("[ \t]+at line \\([0-9]+\\)$"
  184. (1 realgud-line-number-face))
  185. ;; Function name.
  186. ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\.\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  187. (1 font-lock-type-face)
  188. (2 font-lock-function-name-face))
  189. ;; (trepanpl-frames-match-current-line
  190. ;; (0 trepanpl-frames-current-frame-face append))
  191. ))
  192. ;; (setf (gethash "font-lock-keywords" realgud:trepanpl-pat-hash)
  193. ;; '(
  194. ;; ;; The frame number and first type name, if present.
  195. ;; ((concat realgud:trepanpl-frame-start-regexp " "
  196. ;; realgud:trepanpl-frame-num-regexp " "
  197. ;; "\\([A-Z]+\\) *\\([A-Z_][a-zA-Z0-9_]*\\)[#]\\([a-zA-Z_][a-zA-Z_[0-9]]*\\)?")
  198. ;; (2 realgud-backtrace-number-face)
  199. ;; (3 font-lock-keyword-face) ; e.g. METHOD, TOP
  200. ;; (4 font-lock-constant-face) ; e.g. Object
  201. ;; (5 font-lock-function-name-face nil t)) ; t means optional
  202. ;; ;; Instruction sequence
  203. ;; ("<\\(.+\\)>"
  204. ;; (1 font-lock-variable-name-face))
  205. ;; ;; "::Type", which occurs in class name of function and in
  206. ;; ;; parameter list. Parameter sequence
  207. ;; ("(\\(.+\\))"
  208. ;; (1 font-lock-variable-name-face))
  209. ;; ;; "::Type", which occurs in class name of function and in
  210. ;; ;; parameter list.
  211. ;; ("::\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  212. ;; (1 font-lock-type-face))
  213. ;; ;; File name.
  214. ;; (realgud:trepanpl-frame-file-regexp (1 realgud-file-name-face))
  215. ;; ;; Line number.
  216. ;; (realgud:trepanpl-frame-line-regexp (1 realgud-line-number-face))
  217. ;; ;; Function name.
  218. ;; ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\.\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  219. ;; (1 font-lock-type-face)
  220. ;; (2 font-lock-function-name-face))
  221. ;; ;; (trepanpl-frames-match-current-line
  222. ;; ;; (0 trepanpl-frames-current-frame-face append))
  223. ;; ))
  224. (setf (gethash "callback-eval-filter" realgud:trepanpl-pat-hash)
  225. 'realgud:trepanpl-eval-filter-callback)
  226. (setf (gethash realgud:trepanpl-debugger-name realgud-pat-hash) realgud:trepanpl-pat-hash)
  227. ;; Prefix used in variable names (e.g. short-key-mode-map) for
  228. ;; this debugger
  229. (setf (gethash "trepan.pl" realgud:variable-basename-hash) "realgud:trepanpl")
  230. (defvar realgud:trepanpl-command-hash (make-hash-table :test 'equal)
  231. "Hash key is command name like 'quit' and the value is
  232. the trepanpl command to use, like 'quit!'")
  233. (setf (gethash "break" realgud:trepanpl-command-hash) "break %x %l")
  234. (setf (gethash "eval" realgud:trepanpl-command-hash) "eval %s")
  235. (setf (gethash "quit" realgud:trepanpl-command-hash) "quit!")
  236. (setf (gethash "until" realgud:trepanpl-command-hash) "continue %l")
  237. (setf (gethash realgud:trepanpl-debugger-name
  238. realgud-command-hash) realgud:trepanpl-command-hash)
  239. ;; Unsupported features:
  240. (setf (gethash "jump" realgud:trepanpl-command-hash) "*not-implemented*")
  241. (provide-me "realgud:trepanpl-")