diff options
| author | Richard M. Stallman | 2002-12-04 11:56:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-12-04 11:56:55 +0000 |
| commit | d4c2acb9d8ef8b63c1d28c1ef1ce31a701f43ab3 (patch) | |
| tree | cce88b47a49e03d95bebb5f597479696c1602a99 | |
| parent | b271ee8d1521f0d480fff2da774da2ca29060f8e (diff) | |
| download | emacs-d4c2acb9d8ef8b63c1d28c1ef1ce31a701f43ab3.tar.gz emacs-d4c2acb9d8ef8b63c1d28c1ef1ce31a701f43ab3.zip | |
(gud-menu-map): Update for bashdb.
(perldb): Change prompt regexp.
(gud-bashdb-history, gud-bashdb-massage-args, gud-bashdb-marker-filter)
(gud-bashdb-find-file, gud-bashdb-command-name, bashdb): New.
| -rw-r--r-- | lisp/gud.el | 182 |
1 files changed, 173 insertions, 9 deletions
diff --git a/lisp/gud.el b/lisp/gud.el index 4deae7a4e05..8c6350463d9 100644 --- a/lisp/gud.el +++ b/lisp/gud.el | |||
| @@ -47,7 +47,7 @@ | |||
| 47 | 47 | ||
| 48 | (defgroup gud nil | 48 | (defgroup gud nil |
| 49 | "Grand Unified Debugger mode for gdb and other debuggers under Emacs. | 49 | "Grand Unified Debugger mode for gdb and other debuggers under Emacs. |
| 50 | Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), and jdb." | 50 | Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), jdb, and bash." |
| 51 | :group 'unix | 51 | :group 'unix |
| 52 | :group 'tools) | 52 | :group 'tools) |
| 53 | 53 | ||
| @@ -100,23 +100,26 @@ Used to grey out relevant toolbar icons.") | |||
| 100 | ([remove] menu-item "Remove Breakpoint" gud-remove | 100 | ([remove] menu-item "Remove Breakpoint" gud-remove |
| 101 | :enable (not gud-running)) | 101 | :enable (not gud-running)) |
| 102 | ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak | 102 | ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak |
| 103 | :enable (memq gud-minor-mode '(gdba gdb sdb xdb))) | 103 | :enable (memq gud-minor-mode '(gdba gdb sdb xdb bashdb))) |
| 104 | ([break] menu-item "Set Breakpoint" gud-break | 104 | ([break] menu-item "Set Breakpoint" gud-break |
| 105 | :enable (not gud-running)) | 105 | :enable (not gud-running)) |
| 106 | ([up] menu-item "Up Stack" gud-up | 106 | ([up] menu-item "Up Stack" gud-up |
| 107 | :enable (and (not gud-running) | 107 | :enable (and (not gdb-running) |
| 108 | (memq gud-minor-mode '(gdba gdb dbx xdb jdb)))) | 108 | (memq gud-minor-mode |
| 109 | '(gdba gdb dbx xdb jdb bashdb)))) | ||
| 109 | ([down] menu-item "Down Stack" gud-down | 110 | ([down] menu-item "Down Stack" gud-down |
| 110 | :enable (and (not gud-running) | 111 | :enable (and (not gdb-running) |
| 111 | (memq gud-minor-mode '(gdba gdb dbx xdb jdb)))) | 112 | (memq gud-minor-mode |
| 113 | '(gdba gdb dbx xdb jdb bashdb)))) | ||
| 112 | ([print] menu-item "Print Expression" gud-print | 114 | ([print] menu-item "Print Expression" gud-print |
| 113 | :enable (not gud-running)) | 115 | :enable (not gud-running)) |
| 114 | ([display] menu-item "Display Expression" gud-display | 116 | ([display] menu-item "Display Expression" gud-display |
| 115 | :enable (and (not gud-running) | 117 | :enable (and (not gud-running) |
| 116 | (eq gud-minor-mode 'gdba))) | 118 | (eq gud-minor-mode 'gdba))) |
| 117 | ([finish] menu-item "Finish Function" gud-finish | 119 | ([finish] menu-item "Finish Function" gud-finish |
| 118 | :enable (and (not gud-running) | 120 | :enable (and (not gdb-running) |
| 119 | (memq gud-minor-mode '(gdba gdb xdb jdb)))) | 121 | (memq gud-minor-mode |
| 122 | '(gdba gdb xdb jdb bashdb)))) | ||
| 120 | ([stepi] "Step Instruction" . gud-stepi) | 123 | ([stepi] "Step Instruction" . gud-stepi) |
| 121 | ([step] menu-item "Step Line" gud-step | 124 | ([step] menu-item "Step Line" gud-step |
| 122 | :enable (not gud-running)) | 125 | :enable (not gud-running)) |
| @@ -1318,7 +1321,7 @@ and source-file directory for your debugger." | |||
| 1318 | ; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") | 1321 | ; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") |
| 1319 | (gud-def gud-print "%e" "\C-p" "Evaluate perl expression at point.") | 1322 | (gud-def gud-print "%e" "\C-p" "Evaluate perl expression at point.") |
| 1320 | 1323 | ||
| 1321 | (setq comint-prompt-regexp "^ DB<+[0-9]+>+ ") | 1324 | (setq comint-prompt-regexp "^ DB<+(*[0-9])*+>+ ") |
| 1322 | (setq paragraph-start comint-prompt-regexp) | 1325 | (setq paragraph-start comint-prompt-regexp) |
| 1323 | (run-hooks 'perldb-mode-hook)) | 1326 | (run-hooks 'perldb-mode-hook)) |
| 1324 | 1327 | ||
| @@ -2104,6 +2107,167 @@ gud, see `gud-mode'." | |||
| 2104 | (fset 'gud-jdb-find-source 'gud-jdb-find-source-file))) | 2107 | (fset 'gud-jdb-find-source 'gud-jdb-find-source-file))) |
| 2105 | 2108 | ||
| 2106 | 2109 | ||
| 2110 | ;; ====================================================================== | ||
| 2111 | ;; | ||
| 2112 | ;; BASHDB support. See http://bashdb.sourceforge.net | ||
| 2113 | ;; | ||
| 2114 | ;; AUTHOR: Rocky Bernstein <rocky@panix.com> | ||
| 2115 | ;; | ||
| 2116 | ;; CREATED: Sun Nov 10 10:46:38 2002 Rocky Bernstein. | ||
| 2117 | ;; | ||
| 2118 | ;; INVOCATION NOTES: | ||
| 2119 | ;; | ||
| 2120 | ;; You invoke bashdb-mode with: | ||
| 2121 | ;; | ||
| 2122 | ;; M-x bashdb <enter> | ||
| 2123 | ;; | ||
| 2124 | ;; It responds with: | ||
| 2125 | ;; | ||
| 2126 | ;; Run bashdb (like this): bash | ||
| 2127 | ;; | ||
| 2128 | |||
| 2129 | ;;; History of argument lists passed to bashdb. | ||
| 2130 | (defvar gud-bashdb-history nil) | ||
| 2131 | |||
| 2132 | ;; Convert a command line as would be typed normally to run a script | ||
| 2133 | ;; into one that invokes an Emacs-enabled debugging session. | ||
| 2134 | ;; "--debugger" in inserted as the first switch. | ||
| 2135 | |||
| 2136 | (defun gud-bashdb-massage-args (file args) | ||
| 2137 | (let* ((new-args (list "--debugger")) | ||
| 2138 | (seen-e nil) | ||
| 2139 | (shift (lambda () | ||
| 2140 | (setq new-args (cons (car args) new-args)) | ||
| 2141 | (setq args (cdr args))))) | ||
| 2142 | |||
| 2143 | ;; Pass all switches and -e scripts through. | ||
| 2144 | (while (and args | ||
| 2145 | (string-match "^-" (car args)) | ||
| 2146 | (not (equal "-" (car args))) | ||
| 2147 | (not (equal "--" (car args)))) | ||
| 2148 | (funcall shift)) | ||
| 2149 | |||
| 2150 | (if (or (not args) | ||
| 2151 | (string-match "^-" (car args))) | ||
| 2152 | (error "Can't use stdin as the script to debug")) | ||
| 2153 | ;; This is the program name. | ||
| 2154 | (funcall shift) | ||
| 2155 | |||
| 2156 | (while args | ||
| 2157 | (funcall shift)) | ||
| 2158 | |||
| 2159 | (nreverse new-args))) | ||
| 2160 | |||
| 2161 | ;; There's no guarantee that Emacs will hand the filter the entire | ||
| 2162 | ;; marker at once; it could be broken up across several strings. We | ||
| 2163 | ;; might even receive a big chunk with several markers in it. If we | ||
| 2164 | ;; receive a chunk of text which looks like it might contain the | ||
| 2165 | ;; beginning of a marker, we save it here between calls to the | ||
| 2166 | ;; filter. | ||
| 2167 | (defun gud-bashdb-marker-filter (string) | ||
| 2168 | (setq gud-marker-acc (concat gud-marker-acc string)) | ||
| 2169 | (let ((output "")) | ||
| 2170 | |||
| 2171 | ;; Process all the complete markers in this chunk. | ||
| 2172 | ;; Format of line looks like this: | ||
| 2173 | ;; (/etc/init.d/ntp.init:16): | ||
| 2174 | ;; but we also allow DOS drive letters | ||
| 2175 | ;; (d:/etc/init.d/ntp.init:16): | ||
| 2176 | (while (string-match "\\(^\\|\n\\)(\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\)):.*\n" | ||
| 2177 | gud-marker-acc) | ||
| 2178 | (setq | ||
| 2179 | |||
| 2180 | ;; Extract the frame position from the marker. | ||
| 2181 | gud-last-frame | ||
| 2182 | (cons (substring gud-marker-acc (match-beginning 2) (match-end 2)) | ||
| 2183 | (string-to-int (substring gud-marker-acc | ||
| 2184 | (match-beginning 4) | ||
| 2185 | (match-end 4)))) | ||
| 2186 | |||
| 2187 | ;; Append any text before the marker to the output we're going | ||
| 2188 | ;; to return - we don't include the marker in this text. | ||
| 2189 | output (concat output | ||
| 2190 | (substring gud-marker-acc 0 (match-beginning 0))) | ||
| 2191 | |||
| 2192 | ;; Set the accumulator to the remaining text. | ||
| 2193 | gud-marker-acc (substring gud-marker-acc (match-end 0)))) | ||
| 2194 | |||
| 2195 | ;; Does the remaining text look like it might end with the | ||
| 2196 | ;; beginning of another marker? If it does, then keep it in | ||
| 2197 | ;; gud-marker-acc until we receive the rest of it. Since we | ||
| 2198 | ;; know the full marker regexp above failed, it's pretty simple to | ||
| 2199 | ;; test for marker starts. | ||
| 2200 | (if (string-match "\032.*\\'" gud-marker-acc) | ||
| 2201 | (progn | ||
| 2202 | ;; Everything before the potential marker start can be output. | ||
| 2203 | (setq output (concat output (substring gud-marker-acc | ||
| 2204 | 0 (match-beginning 0)))) | ||
| 2205 | |||
| 2206 | ;; Everything after, we save, to combine with later input. | ||
| 2207 | (setq gud-marker-acc | ||
| 2208 | (substring gud-marker-acc (match-beginning 0)))) | ||
| 2209 | |||
| 2210 | (setq output (concat output gud-marker-acc) | ||
| 2211 | gud-marker-acc "")) | ||
| 2212 | |||
| 2213 | output)) | ||
| 2214 | |||
| 2215 | (defun gud-bashdb-find-file (f) | ||
| 2216 | (save-excursion | ||
| 2217 | (let ((buf (find-file-noselect f 'nowarn))) | ||
| 2218 | (set-buffer buf) | ||
| 2219 | buf))) | ||
| 2220 | |||
| 2221 | (defcustom gud-bashdb-command-name "bash" | ||
| 2222 | "File name for executing bash debugger." | ||
| 2223 | :type 'string | ||
| 2224 | :group 'gud) | ||
| 2225 | |||
| 2226 | ;;;###autoload | ||
| 2227 | (defun bashdb (command-line) | ||
| 2228 | "Run bashdb on program FILE in buffer *gud-FILE*. | ||
| 2229 | The directory containing FILE becomes the initial working directory | ||
| 2230 | and source-file directory for your debugger." | ||
| 2231 | (interactive | ||
| 2232 | (list (read-from-minibuffer "Run bashdb (like this): " | ||
| 2233 | (if (consp gud-bashdb-history) | ||
| 2234 | (car gud-bashdb-history) | ||
| 2235 | (concat gud-bashdb-command-name | ||
| 2236 | " ")) | ||
| 2237 | gud-minibuffer-local-map nil | ||
| 2238 | '(gud-bashdb-history . 1)))) | ||
| 2239 | |||
| 2240 | (gud-common-init command-line 'gud-bashdb-massage-args | ||
| 2241 | 'gud-bashdb-marker-filter 'gud-bashdb-find-file) | ||
| 2242 | |||
| 2243 | (set (make-local-variable 'gud-minor-mode) 'bashdb) | ||
| 2244 | |||
| 2245 | (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.") | ||
| 2246 | (gud-def gud-tbreak "tbreak %l" "\C-t" "Set temporary breakpoint at current line.") | ||
| 2247 | (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") | ||
| 2248 | (gud-def gud-step "step" "\C-s" "Step one source line with display.") | ||
| 2249 | (gud-def gud-next "next" "\C-n" "Step one line (skip functions).") | ||
| 2250 | (gud-def gud-cont "continue" "\C-r" "Continue with display.") | ||
| 2251 | (gud-def gud-finish "finish" "\C-f" "Finish executing current function.") | ||
| 2252 | (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") | ||
| 2253 | (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") | ||
| 2254 | (gud-def gud-print "pe %e" "\C-p" "Evaluate bash expression at point.") | ||
| 2255 | |||
| 2256 | ;; Is this right? | ||
| 2257 | (gud-def gud-statement "eval %e" "\C-e" "Execute Python statement at point.") | ||
| 2258 | |||
| 2259 | (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak)) | ||
| 2260 | (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish)) | ||
| 2261 | (local-set-key [menu-bar debug up] '("Up Stack" . gud-up)) | ||
| 2262 | (local-set-key [menu-bar debug down] '("Down Stack" . gud-down)) | ||
| 2263 | |||
| 2264 | (setq comint-prompt-regexp "^bashdb<+[0-9]*>+ ") | ||
| 2265 | (setq paragraph-start comint-prompt-regexp) | ||
| 2266 | (run-hooks 'bashdb-mode-hook) | ||
| 2267 | ) | ||
| 2268 | |||
| 2269 | (provide 'bashdb) | ||
| 2270 | |||
| 2107 | ;; | 2271 | ;; |
| 2108 | ;; End of debugger-specific information | 2272 | ;; End of debugger-specific information |
| 2109 | ;; | 2273 | ;; |