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.

184 lines
6.6 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. ;;
  14. ;; Common POSIX-Shell like constants and regular expressions.
  15. ;; Actually a lot of this is not about POSIX shell as it is about the
  16. ;; common-ness of bashdb, zshdb, and kshdb. But since those are the
  17. ;; *only* debuggers I know of for POSIX shells, it's not too much of
  18. ;; a stretch to think of this as for all "shell".
  19. (require 'load-relative)
  20. (require-relative-list '("../common/regexp" "../common/loc"
  21. "../common/track" "../common/send")
  22. "realgud-")
  23. (declare-function make-realgud-loc-pat 'realgud-regexp)
  24. (defconst realgud-shell-backtrace-loc-pat
  25. (make-realgud-loc-pat
  26. :regexp "^[ \t]+from \\([^:]+\\):\\([0-9]+\\)\\(?: in `.*'\\)?"
  27. :file-group 1
  28. :line-group 2)
  29. "A realgud-loc-pat struct that describes a Shell backtrace (or
  30. traceback) line." )
  31. (defconst realgud-shell-frame-start-regexp
  32. "\\(?:^\\|\n\\)\\(->\\|##\\)")
  33. (defconst realgud-shell-frame-num-regexp
  34. realgud:regexp-captured-num)
  35. (defconst realgud-shell-frame-file-regexp
  36. "[ \t\n]+\\(?:in\\|from\\) file `\\(.+\\)'")
  37. (defconst realgud-shell-frame-line-regexp
  38. (format "[ \t\n]+at line %s\\(?:\n\\|$\\)" realgud:regexp-captured-num))
  39. (defun realgud-posix-shell-populate-command-keys (&optional map)
  40. "Bind the debugger function key layout used by many debuggers.
  41. \\{realgud-example-map-standard}"
  42. (define-key map (kbd "C-c !b") 'realgud:goto-debugger-backtrace-line)
  43. (define-key map (kbd "C-c !!") 'realgud:goto-lang-backtrace-line)
  44. )
  45. ;; Regular expression that describes a bashdb/zshdb location generally shown
  46. ;; before a command prompt.
  47. ;; For example:
  48. ;; (/etc/init.d/apparmor:35):
  49. (defconst realgud:POSIX-debugger-loc-pat
  50. (make-realgud-loc-pat
  51. :regexp "\\(?:^\\|\n\\)(\\([^:]+\\):\\([0-9]*\\)):\\(?:\n\\(.+\\)\\)?"
  52. :file-group 1
  53. :line-group 2
  54. :text-group 3)
  55. "A realgud-loc-pat struct that describes a POSIX shell debugger
  56. location line.")
  57. ;; realgud-loc that describes a debugger "backtrace" command line.
  58. ;; For example:
  59. ;; ->0 in file `/etc/apparmor/fns' at line 24
  60. ;; ##1 /etc/apparmor/fns called from file `/etc/init.d/apparmor' at line 35
  61. ;; ##2 /etc/init.d/apparmor called from file `/usr/bin/zshdb' at line 129
  62. (defconst realgud:POSIX-debugger-backtrace-pat
  63. (make-realgud-loc-pat
  64. :regexp (concat realgud-shell-frame-start-regexp
  65. realgud-shell-frame-num-regexp "[ ]?"
  66. "\\(.*\\)"
  67. realgud-shell-frame-file-regexp
  68. "\\(?:" realgud-shell-frame-line-regexp "\\)?"
  69. )
  70. :num 2
  71. :file-group 4
  72. :line-group 5)
  73. "A realgud-loc-pat struct that describes a Python trepan
  74. backtrace location line." )
  75. ;; FIXME breakpoints aren't locations. It should be a different structure
  76. ;; realgud-loc that describes a bashdb/zshdb/kshdb "info breakpoints" line.
  77. ;; For example:
  78. ;; 1 breakpoint keep y /Users/rocky/.bashrc:17
  79. ;; 2 breakpoint keep y /Users/rocky/.bashrc:18
  80. (defconst realgud:POSIX-debugger-breakpoint-pat
  81. (make-realgud-loc-pat
  82. :regexp (format "^%s[ \t]+\\(breakpoint\\)[ \t]+\\(keep\\|del\\)[ \t]+\\([yn]\\)[ \t]+\\(.+\\):%s"
  83. realgud:regexp-captured-num realgud:regexp-captured-num)
  84. :num 1
  85. :text-group 2 ;; misnamed Is "breakpoint" or "watchpoint"
  86. :string 3 ;; misnamed. Is "keep" or "del"
  87. :file-group 5
  88. :line-group 6)
  89. "A realgud-loc-pat struct that describes a bashdb/zshdb/kshdb breakpoint." )
  90. ;; Regular expression that describes a "breakpoint set" line
  91. (defconst realgud:POSIX-debugger-brkpt-set-pat
  92. (make-realgud-loc-pat
  93. :regexp (format "^Breakpoint \\([0-9]+\\) set in file \\(.+\\), line %s.\n"
  94. realgud:regexp-captured-num)
  95. :num 1
  96. :file-group 2
  97. :line-group 3))
  98. ;; Regular expression that describes a debugger "delete" (breakpoint) response.
  99. ;; For example:
  100. ;; Removed 1 breakpoint(s).
  101. (defconst realgud:POSIX-debugger-brkpt-del-pat
  102. (make-realgud-loc-pat
  103. :regexp (format "^Deleted breakpoint %s\n"
  104. realgud:regexp-captured-num)
  105. :num 1))
  106. ;; Regular expression that describes a debugger "disable" (breakpoint) response.
  107. ;; For example:
  108. ;; Breakpoint entry 4 disabled.
  109. (defconst realgud:POSIX-debugger-brkpt-disable-pat
  110. (make-realgud-loc-pat
  111. :regexp (format "^Breakpoint entry %s disabled."
  112. realgud:regexp-captured-num)
  113. :num 1))
  114. ;; Regular expression that describes a debugger "enable" (breakpoint) response.
  115. ;; For example:
  116. ;; Breakpoint entry 4 enabled.
  117. (defconst realgud:POSIX-debugger-brkpt-enable-pat
  118. (make-realgud-loc-pat
  119. :regexp (format "^Breakpoint entry %s enabled."
  120. realgud:regexp-captured-num)
  121. :num 1))
  122. (defconst realgud:POSIX-debugger-font-lock-keywords
  123. '(
  124. ;; The frame number and first type name, if present.
  125. ;; E.g. ->0 in file `/etc/init.d/apparmor' at line 35
  126. ;; --^-
  127. ("^\\(->\\|##\\)\\([0-9]+\\) "
  128. (2 realgud-backtrace-number-face))
  129. ;; File name.
  130. ;; E.g. ->0 in file `/etc/init.d/apparmor' at line 35
  131. ;; ---------^^^^^^^^^^^^^^^^^^^^-
  132. ("[ \t]+\\(in\\|from\\) file `\\(.+\\)'"
  133. (2 realgud-file-name-face))
  134. ;; File name.
  135. ;; E.g. ->0 in file `/etc/init.d/apparmor' at line 35
  136. ;; --------^^
  137. ;; Line number.
  138. ("[ \t]+at line \\([0-9]+\\)$"
  139. (1 realgud-line-number-face))
  140. ;; (trepan-frames-match-current-line
  141. ;; (0 trepan-frames-current-frame-face append))
  142. ))
  143. (defconst realgud:POSIX-debugger-font-lock-breakpoint-keywords
  144. '(
  145. ;; The breakpoint number, type and disposition
  146. ;; 1 breakpoint keep y /Users/rocky/.bashrc:6
  147. ;; ^ ^^^^^^^^^^ ^^^^
  148. ("^\\([0-9]+\\)[ \t]+\\(breakpoint\\)[ \t]+\\(keep\\|del\\)"
  149. (1 realgud-breakpoint-number-face)
  150. (2 font-lock-function-name-face nil t) ; t means optional.
  151. (3 font-lock-function-name-face nil t)) ; t means optional.
  152. ;; 1 breakpoint keep y /Users/rocky/.bashrc:6
  153. ;; ^^^^^^^^^^^^^^^^^^^^ ^
  154. ("[ \t]+\\(.+*\\):\\([0-9]+\\)"
  155. (1 realgud-file-name-face)
  156. (2 realgud-line-number-face))
  157. ))
  158. (provide-me "realgud-lang-")