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.

163 lines
6.1 KiB

  1. ;; Copyright (C) 2015-2016, 2018, 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. ;;; Regular expressions for nodejs Javascript 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/js") "realgud-lang-")
  21. (defvar realgud:trepanjs-pat-hash (make-hash-table :test 'equal)
  22. "Hash key is the what kind of pattern we want to match:
  23. backtrace, prompt, etc. The values of a hash entry is a
  24. realgud-loc-pat struct")
  25. (declare-function make-realgud-loc-pat 'realgud-regexp)
  26. ;; realgud-loc-pat that describes a trepanjs location generally shown
  27. ;; before a command prompt.
  28. ;; For example:
  29. ;; break in /home/indutny/Code/git/indutny/myscript.js:1
  30. ;; exception in /usr/lib/nodejs/module.js [module.js]:362
  31. (setf (gethash "loc" realgud:trepanjs-pat-hash)
  32. (make-realgud-loc-pat
  33. :regexp (format
  34. "\\(?:%s\\)*\\(?:break\\|exception\\|call\\) in %s at line %s:%s"
  35. realgud:js-term-escape realgud:js-file-regexp
  36. realgud:regexp-captured-num
  37. realgud:regexp-captured-num)
  38. :file-group 1
  39. :line-group 2
  40. :char-offset-group 3
  41. ))
  42. (setf (gethash "file-line" realgud:trepanjs-pat-hash) realgud:js-file-line-loc-pat)
  43. ;; realgud-loc-pat that describes a trepanjs command prompt
  44. ;; For example:
  45. ;; (trepanjs):
  46. (setf (gethash "prompt" realgud:trepanjs-pat-hash)
  47. (make-realgud-loc-pat
  48. :regexp (format "^\\(?:%s\\)*(+trepanjs)+ " realgud:js-term-escape)
  49. ))
  50. ;; realgud-loc-pat that describes a "breakpoint set" line
  51. ;; For example:
  52. ;; Breakpoint 2 set in file /tmp/gcd.js, line 2.
  53. ;; Breakpoint 3 set in file /usr/lib/nodejs/module.js [module.js], line 380.
  54. (setf (gethash "brkpt-set" realgud:trepanjs-pat-hash)
  55. (make-realgud-loc-pat
  56. :regexp (format "^Breakpoint %s set in file %s, line %s.\n"
  57. realgud:regexp-captured-num
  58. realgud:js-file-regexp
  59. realgud:regexp-captured-num)
  60. :num 1
  61. :file-group 2
  62. :line-group 3))
  63. ;; realgud-loc-pat that describes a debugger "delete" (breakpoint) response.
  64. ;; For example:
  65. ;; Deleted breakpoint 1
  66. (setf (gethash "brkpt-del" realgud:trepanjs-pat-hash)
  67. (make-realgud-loc-pat
  68. :regexp "^Deleted breakpoint \\(\\([0-9]+ *\\)+\\)\n"
  69. :num 1))
  70. ;; realgud-loc-pat that describes a V8 backtrace line.
  71. ;; For example:
  72. ;; at repl:1:7
  73. ;; at Interface.controlEval (/src/external-vcs/github/trepanjs/lib/interface.js:352:18)
  74. ;; at REPLServer.b [as eval] (domain.js:183:18)
  75. (setf (gethash "lang-backtrace" realgud:trepanjs-pat-hash)
  76. realgud:js-backtrace-loc-pat)
  77. ;; realgud-loc-pat that describes a debugger "delete" (breakpoint)
  78. ;; response.
  79. ;; For example:
  80. ;; Deleted breakpoint 1.
  81. (setf (gethash "brkpt-del" realgud:trepanjs-pat-hash)
  82. (make-realgud-loc-pat
  83. :regexp (format "^Deleted breakpoint %s.\n"
  84. realgud:regexp-captured-num)
  85. :num 1))
  86. (defconst realgud:trepanjs-frame-start-regexp "\\(?:^\\|\n\\)\\(?: #\\)")
  87. (defconst realgud:trepanjs-frame-num-regexp realgud:regexp-captured-num)
  88. (defconst realgud:trepanjs-frame-module-regexp "[^ \t\n]+")
  89. ;; realgud-loc-pat that describes debugger "backtrace" command line.
  90. ;; e.g.
  91. ;; ## require called from file /usr/lib/nodejs/module.js [module.js] at line 380:17
  92. ;; ## in file /src/external-vcs/github/trepanjs/example/gcd.js [/src/external-vcs/github/trepanjs/example/gcd.js] at line 2:12
  93. (setf (gethash "debugger-backtrace" realgud:trepanjs-pat-hash)
  94. (make-realgud-loc-pat
  95. :regexp (concat realgud:trepanjs-frame-start-regexp " "
  96. realgud:regexp-captured-num " "
  97. "\\(?:" realgud:trepanjs-frame-module-regexp "[ \t\n]+called from file "
  98. realgud:js-file-regexp
  99. "\\)\\| in file "
  100. realgud:regexp-captured-num
  101. "\\)"
  102. "at line \\(" realgud:regexp-captured-num "\\):"
  103. realgud:regexp-captured-num
  104. )
  105. :num 1
  106. :file-group 2
  107. :line-group 3
  108. :char-offset-group 4
  109. ))
  110. (defconst realgud:trepanjs-debugger-name "trepanjs" "Name of debugger")
  111. ;; Top frame number
  112. (setf (gethash "top-frame-num" realgud:trepanjs-pat-hash) 0)
  113. ;; realgud-loc-pat that for a termination message.
  114. (setf (gethash "termination" realgud:trepanjs-pat-hash)
  115. "^trepanjs: That's all, folks...\n")
  116. (setf (gethash realgud:trepanjs-debugger-name realgud-pat-hash) realgud:trepanjs-pat-hash)
  117. (defvar realgud:trepanjs-command-hash (make-hash-table :test 'equal)
  118. "Hash key is command name like 'quit' and the value is
  119. the trepanjs command to use, like 'quit!'")
  120. (setf (gethash realgud:trepanjs-debugger-name
  121. realgud-command-hash) realgud:trepanjs-command-hash)
  122. (setf (gethash "break" realgud:trepanjs-command-hash)
  123. "setBreakpoint(%l)")
  124. (setf (gethash "clear" realgud:trepanjs-command-hash)
  125. "clearBreakpoint('%X', %l)")
  126. (setf (gethash "delete" realgud:trepanjs-command-hash)
  127. "clearBreakpoint('%X', %l)")
  128. ;; We need aliases for step and next because the default would
  129. ;; do step 1 and trepanjs doesn't handle this. Or when it does,
  130. ;; it will probably look like step(1)
  131. (setf (gethash "eval" realgud:trepanjs-command-hash) "eval(%q)")
  132. (setf (gethash "info-breakpoints" realgud:trepanjs-command-hash) "info('breakpoints')")
  133. (setf (gethash "quit" realgud:trepanjs-command-hash) "quit()")
  134. ;; Unsupported features:
  135. (setf (gethash "kill" realgud:trepanjs-command-hash) "*not-implemented*")
  136. (provide-me "realgud:trepanjs-")