Mercurial > emacs
annotate lisp/progmodes/gud.el @ 89573:6b5d42f51038
(x_get_font_repertory): Handle the case that the
encoding of font is other than Unicode.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 06 Oct 2003 11:23:25 +0000 |
parents | 375f2633d815 |
children | 68c22ea6027c |
rev | line source |
---|---|
51494 | 1 ;;; gud.el --- Grand Unified Debugger mode for running GDB and other debuggers |
2 | |
3 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | |
4 ;; Maintainer: FSF | |
5 ;; Keywords: unix, tools | |
6 | |
7 ;; Copyright (C) 1992,93,94,95,96,1998,2000,02,2003 Free Software Foundation, Inc. | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu> | |
29 ;; It was later rewritten by rms. Some ideas were due to Masanobu. | |
30 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com> | |
31 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>, | |
32 ;; who also hacked the mode to use comint.el. Shane Hartman <shane@spr.com> | |
33 ;; added support for xdb (HPUX debugger). Rick Sladkey <jrs@world.std.com> | |
34 ;; wrote the GDB command completion code. Dave Love <d.love@dl.ac.uk> | |
35 ;; added the IRIX kluge, re-implemented the Mips-ish variant and added | |
36 ;; a menu. Brian D. Carlstrom <bdc@ai.mit.edu> combined the IRIX kluge with | |
37 ;; the gud-xdb-directories hack producing gud-dbx-directories. Derek L. Davies | |
38 ;; <ddavies@world.std.com> added support for jdb (Java debugger.) | |
39 | |
40 ;;; Code: | |
41 | |
42 (require 'comint) | |
43 (require 'etags) | |
44 | |
45 ;; ====================================================================== | |
46 ;; GUD commands must be visible in C buffers visited by GUD | |
47 | |
48 (defgroup gud nil | |
49 "Grand Unified Debugger mode for gdb and other debuggers under Emacs. | |
50 Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), jdb, and bash." | |
51 :group 'unix | |
52 :group 'tools) | |
53 | |
54 | |
55 (defcustom gud-key-prefix "\C-x\C-a" | |
56 "Prefix of all GUD commands valid in C buffers." | |
57 :type 'string | |
58 :group 'gud) | |
59 | |
60 (global-set-key (concat gud-key-prefix "\C-l") 'gud-refresh) | |
61 (define-key ctl-x-map " " 'gud-break) ;; backward compatibility hack | |
62 | |
63 (defvar gud-marker-filter nil) | |
64 (put 'gud-marker-filter 'permanent-local t) | |
65 (defvar gud-find-file nil) | |
66 (put 'gud-find-file 'permanent-local t) | |
67 | |
68 (defun gud-marker-filter (&rest args) | |
69 (apply gud-marker-filter args)) | |
70 | |
71 (defvar gud-minor-mode nil) | |
72 (put 'gud-minor-mode 'permanent-local t) | |
73 | |
74 (defvar gud-keep-buffer nil) | |
75 | |
76 (defun gud-symbol (sym &optional soft minor-mode) | |
77 "Return the symbol used for SYM in MINOR-MODE. | |
78 MINOR-MODE defaults to `gud-minor-mode. | |
79 The symbol returned is `gud-<MINOR-MODE>-<SYM>'. | |
80 If SOFT is non-nil, returns nil if the symbol doesn't already exist." | |
81 (unless (or minor-mode gud-minor-mode) (error "Gud internal error")) | |
82 (funcall (if soft 'intern-soft 'intern) | |
83 (format "gud-%s-%s" (or minor-mode gud-minor-mode) sym))) | |
84 | |
85 (defun gud-val (sym &optional minor-mode) | |
86 "Return the value of `gud-symbol' SYM. Default to nil." | |
87 (let ((sym (gud-symbol sym t minor-mode))) | |
88 (if (boundp sym) (symbol-value sym)))) | |
89 | |
90 (defvar gud-running nil | |
91 "Non-nil if debuggee is running. | |
92 Used to grey out relevant toolbar icons.") | |
93 | |
94 (easy-mmode-defmap gud-menu-map | |
95 '(([refresh] "Refresh" . gud-refresh) | |
96 ([run] menu-item "Run" gud-run | |
97 :enable (and (not gud-running) | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
98 (memq gud-minor-mode '(gdba gdb dbx jdb)))) |
51494 | 99 ([goto] menu-item "Continue to selection" gud-until |
100 :enable (and (not gud-running) | |
101 (memq gud-minor-mode '(gdba gdb)))) | |
102 ([remove] menu-item "Remove Breakpoint" gud-remove | |
103 :enable (not gud-running)) | |
104 ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak | |
105 :enable (memq gud-minor-mode '(gdba gdb sdb xdb bashdb))) | |
106 ([break] menu-item "Set Breakpoint" gud-break | |
107 :enable (not gud-running)) | |
108 ([up] menu-item "Up Stack" gud-up | |
109 :enable (and (not gud-running) | |
110 (memq gud-minor-mode | |
111 '(gdba gdb dbx xdb jdb pdb bashdb)))) | |
112 ([down] menu-item "Down Stack" gud-down | |
113 :enable (and (not gud-running) | |
114 (memq gud-minor-mode | |
115 '(gdba gdb dbx xdb jdb pdb bashdb)))) | |
116 ([print] menu-item "Print Expression" gud-print | |
117 :enable (not gud-running)) | |
118 ([display] menu-item "Display Expression" gud-display | |
119 :enable (and (not gud-running) | |
120 (eq gud-minor-mode 'gdba))) | |
121 ([finish] menu-item "Finish Function" gud-finish | |
122 :enable (and (not gud-running) | |
123 (memq gud-minor-mode | |
124 '(gdba gdb xdb jdb pdb bashdb)))) | |
125 ([stepi] menu-item "Step Instruction" gud-stepi | |
126 :enable (and (not gud-running) | |
127 (memq gud-minor-mode | |
128 '(gdba gdb dbx)))) | |
129 ([nexti] menu-item "Next Instruction" gud-nexti | |
130 :enable (and (not gud-running) | |
131 (memq gud-minor-mode | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
132 '(gdba gdb dbx)))) |
51494 | 133 ([step] menu-item "Step Line" gud-step |
134 :enable (not gud-running)) | |
135 ([next] menu-item "Next Line" gud-next | |
136 :enable (not gud-running)) | |
137 ([cont] menu-item "Continue" gud-cont | |
138 :enable (not gud-running))) | |
139 "Menu for `gud-mode'." | |
140 :name "Gud") | |
141 | |
142 (easy-mmode-defmap gud-minor-mode-map | |
143 `(([menu-bar debug] . ("Gud" . ,gud-menu-map))) | |
144 "Map used in visited files.") | |
145 | |
146 (let ((m (assq 'gud-minor-mode minor-mode-map-alist))) | |
147 (if m (setcdr m gud-minor-mode-map) | |
148 (push (cons 'gud-minor-mode gud-minor-mode-map) minor-mode-map-alist))) | |
149 | |
150 (defvar gud-mode-map | |
151 ;; Will inherit from comint-mode via define-derived-mode. | |
152 (make-sparse-keymap) | |
153 "`gud-mode' keymap.") | |
154 | |
155 (defvar gud-tool-bar-map | |
156 (if (display-graphic-p) | |
157 (let ((map (make-sparse-keymap))) | |
158 (dolist (x '((gud-break . "gud-break") | |
159 (gud-remove . "gud-remove") | |
160 (gud-print . "gud-print") | |
161 (gud-display . "gud-display") | |
162 (gud-run . "gud-run") | |
163 (gud-until . "gud-until") | |
164 (gud-cont . "gud-cont") | |
165 (gud-step . "gud-step") | |
166 (gud-next . "gud-next") | |
167 (gud-finish . "gud-finish") | |
168 (gud-stepi . "gud-stepi") | |
169 (gud-nexti . "gud-nexti") | |
170 (gud-up . "gud-up") | |
171 (gud-down . "gud-down")) | |
172 map) | |
173 (tool-bar-local-item-from-menu | |
174 (car x) (cdr x) map gud-minor-mode-map))))) | |
175 | |
176 (defun gud-file-name (f) | |
177 "Transform a relative file name to an absolute file name. | |
178 Uses `gud-<MINOR-MODE>-directories' to find the source files." | |
179 (if (file-exists-p f) (expand-file-name f) | |
180 (let ((directories (gud-val 'directories)) | |
181 (result nil)) | |
182 (while directories | |
183 (let ((path (expand-file-name f (car directories)))) | |
184 (if (file-exists-p path) | |
185 (setq result path | |
186 directories nil))) | |
187 (setq directories (cdr directories))) | |
188 result))) | |
189 | |
190 (defun gud-find-file (file) | |
191 ;; Don't get confused by double slashes in the name that comes from GDB. | |
192 (while (string-match "//+" file) | |
193 (setq file (replace-match "/" t t file))) | |
194 (let ((minor-mode gud-minor-mode) | |
195 (buf (funcall (or gud-find-file 'gud-file-name) file))) | |
196 (when (stringp buf) | |
197 (setq buf (and (file-readable-p buf) (find-file-noselect buf 'nowarn)))) | |
198 (when buf | |
199 ;; Copy `gud-minor-mode' to the found buffer to turn on the menu. | |
200 (with-current-buffer buf | |
201 (set (make-local-variable 'gud-minor-mode) minor-mode) | |
202 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
203 (make-local-variable 'gud-keep-buffer)) | |
204 buf))) | |
205 | |
206 ;; ====================================================================== | |
207 ;; command definition | |
208 | |
209 ;; This macro is used below to define some basic debugger interface commands. | |
210 ;; Of course you may use `gud-def' with any other debugger command, including | |
211 ;; user defined ones. | |
212 | |
213 ;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form | |
214 ;; which defines FUNC to send the command NAME to the debugger, gives | |
215 ;; it the docstring DOC, and binds that function to KEY in the GUD | |
216 ;; major mode. The function is also bound in the global keymap with the | |
217 ;; GUD prefix. | |
218 | |
219 (defmacro gud-def (func cmd key &optional doc) | |
220 "Define FUNC to be a command sending STR and bound to KEY, with | |
221 optional doc string DOC. Certain %-escapes in the string arguments | |
222 are interpreted specially if present. These are: | |
223 | |
224 %f name (without directory) of current source file. | |
225 %F name (without directory or extension) of current source file. | |
226 %d directory of current source file. | |
227 %l number of current source line | |
228 %e text of the C lvalue or function-call expression surrounding point. | |
229 %a text of the hexadecimal address surrounding point | |
230 %p prefix argument to the command (if any) as a number | |
231 | |
232 The `current' source file is the file of the current buffer (if | |
233 we're in a C file) or the source file current at the last break or | |
234 step (if we're in the GUD buffer). | |
235 The `current' line is that of the current buffer (if we're in a | |
236 source file) or the source line number at the last break or step (if | |
237 we're in the GUD buffer)." | |
238 `(progn | |
239 (defun ,func (arg) | |
240 ,@(if doc (list doc)) | |
241 (interactive "p") | |
242 ,(if (stringp cmd) | |
243 `(gud-call ,cmd arg) | |
244 cmd)) | |
245 ,(if key `(local-set-key ,(concat "\C-c" key) ',func)) | |
246 ,(if key `(global-set-key (vconcat gud-key-prefix ,key) ',func)))) | |
247 | |
248 ;; Where gud-display-frame should put the debugging arrow; a cons of | |
249 ;; (filename . line-number). This is set by the marker-filter, which scans | |
250 ;; the debugger's output for indications of the current program counter. | |
251 (defvar gud-last-frame nil) | |
252 | |
253 ;; Used by gud-refresh, which should cause gud-display-frame to redisplay | |
254 ;; the last frame, even if it's been called before and gud-last-frame has | |
255 ;; been set to nil. | |
256 (defvar gud-last-last-frame nil) | |
257 | |
258 ;; All debugger-specific information is collected here. | |
259 ;; Here's how it works, in case you ever need to add a debugger to the mode. | |
260 ;; | |
261 ;; Each entry must define the following at startup: | |
262 ;; | |
263 ;;<name> | |
264 ;; comint-prompt-regexp | |
265 ;; gud-<name>-massage-args | |
266 ;; gud-<name>-marker-filter | |
267 ;; gud-<name>-find-file | |
268 ;; | |
269 ;; The job of the massage-args method is to modify the given list of | |
270 ;; debugger arguments before running the debugger. | |
271 ;; | |
272 ;; The job of the marker-filter method is to detect file/line markers in | |
273 ;; strings and set the global gud-last-frame to indicate what display | |
274 ;; action (if any) should be triggered by the marker. Note that only | |
275 ;; whatever the method *returns* is displayed in the buffer; thus, you | |
276 ;; can filter the debugger's output, interpreting some and passing on | |
277 ;; the rest. | |
278 ;; | |
279 ;; The job of the find-file method is to visit and return the buffer indicated | |
280 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or | |
281 ;; something else. | |
282 | |
283 ;; ====================================================================== | |
284 ;; speedbar support functions and variables. | |
285 (eval-when-compile (require 'speedbar)) ;For speedbar-with-attached-buffer. | |
286 | |
287 (defvar gud-last-speedbar-buffer nil | |
288 "The last GUD buffer used.") | |
289 | |
290 (defvar gud-last-speedbar-stackframe nil | |
291 "Description of the currently displayed GUD stack. | |
292 t means that there is no stack, and we are in display-file mode.") | |
293 | |
294 (defvar gud-speedbar-key-map nil | |
295 "Keymap used when in the buffers display mode.") | |
296 | |
297 (defun gud-install-speedbar-variables () | |
298 "Install those variables used by speedbar to enhance gud/gdb." | |
299 (if gud-speedbar-key-map | |
300 nil | |
301 (setq gud-speedbar-key-map (speedbar-make-specialized-keymap)) | |
302 | |
303 (define-key gud-speedbar-key-map "j" 'speedbar-edit-line) | |
304 (define-key gud-speedbar-key-map "e" 'speedbar-edit-line) | |
305 (define-key gud-speedbar-key-map "\C-m" 'speedbar-edit-line))) | |
306 | |
307 (defvar gud-speedbar-menu-items | |
308 ;; Note to self. Add expand, and turn off items when not available. | |
309 '(["Jump to stack frame" speedbar-edit-line t]) | |
310 "Additional menu items to add to the speedbar frame.") | |
311 | |
312 ;; Make sure our special speedbar mode is loaded | |
313 (if (featurep 'speedbar) | |
314 (gud-install-speedbar-variables) | |
315 (add-hook 'speedbar-load-hook 'gud-install-speedbar-variables)) | |
316 | |
317 (defun gud-speedbar-buttons (buffer) | |
318 "Create a speedbar display based on the current state of GUD. | |
319 If the GUD BUFFER is not running a supported debugger, then turn | |
320 off the specialized speedbar mode." | |
321 (if (and (save-excursion (goto-char (point-min)) | |
322 (looking-at "Current Stack")) | |
323 (equal gud-last-last-frame gud-last-speedbar-stackframe)) | |
324 nil | |
325 (setq gud-last-speedbar-buffer buffer) | |
326 (let* ((minor-mode (with-current-buffer buffer gud-minor-mode)) | |
327 (frames | |
328 (cond ((memq minor-mode '(gdba gdb)) | |
329 (gud-gdb-get-stackframe buffer)) | |
330 ;; Add more debuggers here! | |
331 (t | |
332 (speedbar-remove-localized-speedbar-support buffer) | |
333 nil)))) | |
334 (erase-buffer) | |
335 (if (not frames) | |
336 (insert "No Stack frames\n") | |
337 (insert "Current Stack:\n")) | |
338 (while frames | |
339 (insert (nth 1 (car frames)) ":\n") | |
340 (if (= (length (car frames)) 2) | |
341 (progn | |
342 ; (speedbar-insert-button "[?]" | |
343 ; 'speedbar-button-face | |
344 ; nil nil nil t) | |
345 (speedbar-insert-button (car (car frames)) | |
346 'speedbar-directory-face | |
347 nil nil nil t)) | |
348 ; (speedbar-insert-button "[+]" | |
349 ; 'speedbar-button-face | |
350 ; 'speedbar-highlight-face | |
351 ; 'gud-gdb-get-scope-data | |
352 ; (car frames) t) | |
353 (speedbar-insert-button (car (car frames)) | |
354 'speedbar-file-face | |
355 'speedbar-highlight-face | |
356 (cond ((memq minor-mode '(gdba gdb)) | |
357 'gud-gdb-goto-stackframe) | |
358 (t (error "Should never be here"))) | |
359 (car frames) t)) | |
360 (setq frames (cdr frames))) | |
361 ; (let ((selected-frame | |
362 ; (cond ((eq ff 'gud-gdb-find-file) | |
363 ; (gud-gdb-selected-frame-info buffer)) | |
364 ; (t (error "Should never be here")))))) | |
365 ) | |
366 (setq gud-last-speedbar-stackframe gud-last-last-frame))) | |
367 | |
368 | |
369 ;; ====================================================================== | |
370 ;; gdb functions | |
371 | |
372 ;; History of argument lists passed to gdb. | |
373 (defvar gud-gdb-history nil) | |
374 | |
375 (defcustom gud-gdb-command-name "gdb --fullname" | |
376 "Default command to execute an executable under the GDB debugger." | |
377 :type 'string | |
378 :group 'gud) | |
379 | |
380 (defvar gud-gdb-marker-regexp | |
381 ;; This used to use path-separator instead of ":"; | |
382 ;; however, we found that on both Windows 32 and MSDOS | |
383 ;; a colon is correct here. | |
384 (concat "\032\032\\(.:?[^" ":" "\n]*\\)" ":" | |
385 "\\([0-9]*\\)" ":" ".*\n")) | |
386 | |
387 ;; There's no guarantee that Emacs will hand the filter the entire | |
388 ;; marker at once; it could be broken up across several strings. We | |
389 ;; might even receive a big chunk with several markers in it. If we | |
390 ;; receive a chunk of text which looks like it might contain the | |
391 ;; beginning of a marker, we save it here between calls to the | |
392 ;; filter. | |
393 (defvar gud-marker-acc "") | |
394 (make-variable-buffer-local 'gud-marker-acc) | |
395 | |
396 (defun gud-gdb-marker-filter (string) | |
397 (setq gud-marker-acc (concat gud-marker-acc string)) | |
398 (let ((output "")) | |
399 | |
400 ;; Process all the complete markers in this chunk. | |
401 (while (string-match gud-gdb-marker-regexp gud-marker-acc) | |
402 (setq | |
403 | |
404 ;; Extract the frame position from the marker. | |
405 gud-last-frame (cons (match-string 1 gud-marker-acc) | |
406 (string-to-int (match-string 2 gud-marker-acc))) | |
407 | |
408 ;; Append any text before the marker to the output we're going | |
409 ;; to return - we don't include the marker in this text. | |
410 output (concat output | |
411 (substring gud-marker-acc 0 (match-beginning 0))) | |
412 | |
413 ;; Set the accumulator to the remaining text. | |
414 gud-marker-acc (substring gud-marker-acc (match-end 0)))) | |
415 | |
416 ;; Does the remaining text look like it might end with the | |
417 ;; beginning of another marker? If it does, then keep it in | |
418 ;; gud-marker-acc until we receive the rest of it. Since we | |
419 ;; know the full marker regexp above failed, it's pretty simple to | |
420 ;; test for marker starts. | |
421 (if (string-match "\032.*\\'" gud-marker-acc) | |
422 (progn | |
423 ;; Everything before the potential marker start can be output. | |
424 (setq output (concat output (substring gud-marker-acc | |
425 0 (match-beginning 0)))) | |
426 | |
427 ;; Everything after, we save, to combine with later input. | |
428 (setq gud-marker-acc | |
429 (substring gud-marker-acc (match-beginning 0)))) | |
430 | |
431 (setq output (concat output gud-marker-acc) | |
432 gud-marker-acc "")) | |
433 | |
434 output)) | |
435 | |
436 (easy-mmode-defmap gud-minibuffer-local-map | |
437 '(("\C-i" . comint-dynamic-complete-filename)) | |
438 "Keymap for minibuffer prompting of gud startup command." | |
439 :inherit minibuffer-local-map) | |
440 | |
441 (defun gud-query-cmdline (minor-mode &optional init) | |
442 (let* ((hist-sym (gud-symbol 'history nil minor-mode)) | |
443 (cmd-name (gud-val 'command-name minor-mode))) | |
444 (unless (boundp hist-sym) (set hist-sym nil)) | |
445 (read-from-minibuffer | |
446 (format "Run %s (like this): " minor-mode) | |
447 (or (car-safe (symbol-value hist-sym)) | |
448 (concat (or cmd-name (symbol-name minor-mode)) | |
449 " " | |
450 (or init | |
451 (let ((file nil)) | |
452 (dolist (f (directory-files default-directory) file) | |
453 (if (and (file-executable-p f) | |
454 (not (file-directory-p f)) | |
455 (or (not file) | |
456 (file-newer-than-file-p f file))) | |
457 (setq file f))))))) | |
458 gud-minibuffer-local-map nil | |
459 hist-sym))) | |
460 | |
461 ;;;###autoload | |
462 (defun gdb (command-line) | |
463 "Run gdb on program FILE in buffer *gud-FILE*. | |
464 The directory containing FILE becomes the initial working directory | |
465 and source-file directory for your debugger." | |
466 (interactive (list (gud-query-cmdline 'gdb))) | |
467 | |
468 (gud-common-init command-line nil 'gud-gdb-marker-filter) | |
469 (set (make-local-variable 'gud-minor-mode) 'gdb) | |
470 | |
471 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.") | |
472 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set temporary breakpoint at current line.") | |
473 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line") | |
474 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.") | |
475 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.") | |
476 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).") | |
477 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).") | |
478 (gud-def gud-cont "cont" "\C-r" "Continue with display.") | |
479 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.") | |
480 (gud-def gud-jump "tbreak %f:%l\njump %f:%l" "\C-j" "Relocate execution address to line at point in source buffer.") | |
481 | |
482 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") | |
483 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") | |
484 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.") | |
485 (gud-def gud-until "until %l" "\C-u" "Continue to current line.") | |
486 (gud-def gud-run "run" nil "Run the program.") | |
487 | |
488 (local-set-key "\C-i" 'gud-gdb-complete-command) | |
489 (setq comint-prompt-regexp "^(.*gdb[+]?) *") | |
490 (setq paragraph-start comint-prompt-regexp) | |
491 (run-hooks 'gdb-mode-hook) | |
492 ) | |
493 | |
494 ;; One of the nice features of GDB is its impressive support for | |
495 ;; context-sensitive command completion. We preserve that feature | |
496 ;; in the GUD buffer by using a GDB command designed just for Emacs. | |
497 | |
498 ;; The completion process filter indicates when it is finished. | |
499 (defvar gud-gdb-fetch-lines-in-progress) | |
500 | |
501 ;; Since output may arrive in fragments we accumulate partials strings here. | |
502 (defvar gud-gdb-fetch-lines-string) | |
503 | |
504 ;; We need to know how much of the completion to chop off. | |
505 (defvar gud-gdb-fetch-lines-break) | |
506 | |
507 ;; The completion list is constructed by the process filter. | |
508 (defvar gud-gdb-fetched-lines) | |
509 | |
510 (defvar gud-comint-buffer nil) | |
511 | |
512 (defun gud-gdb-complete-command () | |
513 "Perform completion on the GDB command preceding point. | |
514 This is implemented using the GDB `complete' command which isn't | |
515 available with older versions of GDB." | |
516 (interactive) | |
517 (let* ((end (point)) | |
518 (command (buffer-substring (comint-line-beginning-position) end)) | |
519 (command-word | |
520 ;; Find the word break. This match will always succeed. | |
521 (and (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command) | |
522 (substring command (match-beginning 2)))) | |
523 (complete-list | |
524 (gud-gdb-run-command-fetch-lines (concat "complete " command) | |
525 (current-buffer) | |
526 ;; From string-match above. | |
527 (match-beginning 2)))) | |
528 ;; Protect against old versions of GDB. | |
529 (and complete-list | |
530 (string-match "^Undefined command: \"complete\"" (car complete-list)) | |
531 (error "This version of GDB doesn't support the `complete' command")) | |
532 ;; Sort the list like readline. | |
533 (setq complete-list (sort complete-list (function string-lessp))) | |
534 ;; Remove duplicates. | |
535 (let ((first complete-list) | |
536 (second (cdr complete-list))) | |
537 (while second | |
538 (if (string-equal (car first) (car second)) | |
539 (setcdr first (setq second (cdr second))) | |
540 (setq first second | |
541 second (cdr second))))) | |
542 ;; Add a trailing single quote if there is a unique completion | |
543 ;; and it contains an odd number of unquoted single quotes. | |
544 (and (= (length complete-list) 1) | |
545 (let ((str (car complete-list)) | |
546 (pos 0) | |
547 (count 0)) | |
548 (while (string-match "\\([^'\\]\\|\\\\'\\)*'" str pos) | |
549 (setq count (1+ count) | |
550 pos (match-end 0))) | |
551 (and (= (mod count 2) 1) | |
552 (setq complete-list (list (concat str "'")))))) | |
553 ;; Let comint handle the rest. | |
554 (comint-dynamic-simple-complete command-word complete-list))) | |
555 | |
556 ;; The completion process filter is installed temporarily to slurp the | |
557 ;; output of GDB up to the next prompt and build the completion list. | |
558 (defun gud-gdb-fetch-lines-filter (string filter) | |
559 "Filter used to read the list of lines output by a command. | |
560 STRING is the output to filter. | |
561 It is passed through FILTER before we look at it." | |
562 (setq string (funcall filter string)) | |
563 (setq string (concat gud-gdb-fetch-lines-string string)) | |
564 (while (string-match "\n" string) | |
565 (push (substring string gud-gdb-fetch-lines-break (match-beginning 0)) | |
566 gud-gdb-fetched-lines) | |
567 (setq string (substring string (match-end 0)))) | |
568 (if (string-match comint-prompt-regexp string) | |
569 (progn | |
570 (setq gud-gdb-fetch-lines-in-progress nil) | |
571 string) | |
572 (progn | |
573 (setq gud-gdb-fetch-lines-string string) | |
574 ""))) | |
575 | |
576 ;; gdb speedbar functions | |
577 | |
578 (defun gud-gdb-goto-stackframe (text token indent) | |
579 "Goto the stackframe described by TEXT, TOKEN, and INDENT." | |
580 (speedbar-with-attached-buffer | |
581 (gud-basic-call (concat "server frame " (nth 1 token))) | |
582 (sit-for 1))) | |
583 | |
584 (defvar gud-gdb-fetched-stack-frame nil | |
585 "Stack frames we are fetching from GDB.") | |
586 | |
587 ;(defun gud-gdb-get-scope-data (text token indent) | |
588 ; ;; checkdoc-params: (indent) | |
589 ; "Fetch data associated with a stack frame, and expand/contract it. | |
590 ;Data to do this is retrieved from TEXT and TOKEN." | |
591 ; (let ((args nil) (scope nil)) | |
592 ; (gud-gdb-run-command-fetch-lines "info args") | |
593 ; | |
594 ; (gud-gdb-run-command-fetch-lines "info local") | |
595 ; | |
596 ; )) | |
597 | |
598 (defun gud-gdb-get-stackframe (buffer) | |
599 "Extract the current stack frame out of the GUD GDB BUFFER." | |
600 (let ((newlst nil) | |
601 (fetched-stack-frame-list | |
602 (gud-gdb-run-command-fetch-lines "server backtrace" buffer))) | |
603 (if (and (car fetched-stack-frame-list) | |
604 (string-match "No stack" (car fetched-stack-frame-list))) | |
605 ;; Go into some other mode??? | |
606 nil | |
607 (dolist (e fetched-stack-frame-list) | |
608 (let ((name nil) (num nil)) | |
609 (if (not (or | |
610 (string-match "^#\\([0-9]+\\) +[0-9a-fx]+ in \\([:0-9a-zA-Z_]+\\) (" e) | |
611 (string-match "^#\\([0-9]+\\) +\\([:0-9a-zA-Z_]+\\) (" e))) | |
612 (if (not (string-match | |
613 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e)) | |
614 nil | |
615 (setcar newlst | |
616 (list (nth 0 (car newlst)) | |
617 (nth 1 (car newlst)) | |
618 (match-string 1 e) | |
619 (match-string 2 e)))) | |
620 (setq num (match-string 1 e) | |
621 name (match-string 2 e)) | |
622 (setq newlst | |
623 (cons | |
624 (if (string-match | |
625 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e) | |
626 (list name num (match-string 1 e) | |
627 (match-string 2 e)) | |
628 (list name num)) | |
629 newlst))))) | |
630 (nreverse newlst)))) | |
631 | |
632 ;(defun gud-gdb-selected-frame-info (buffer) | |
633 ; "Learn GDB information for the currently selected stack frame in BUFFER." | |
634 ; ) | |
635 | |
636 (defun gud-gdb-run-command-fetch-lines (command buffer &optional skip) | |
637 "Run COMMAND, and return the list of lines it outputs. | |
638 BUFFER is the GUD buffer in which to run the command. | |
639 SKIP is the number of chars to skip on each lines, it defaults to 0." | |
640 (with-current-buffer buffer | |
641 (if (save-excursion | |
642 (goto-char (point-max)) | |
643 (forward-line 0) | |
644 (not (looking-at comint-prompt-regexp))) | |
645 nil | |
646 ;; Much of this copied from GDB complete, but I'm grabbing the stack | |
647 ;; frame instead. | |
648 (let ((gud-gdb-fetch-lines-in-progress t) | |
649 (gud-gdb-fetched-lines nil) | |
650 (gud-gdb-fetch-lines-string nil) | |
651 (gud-gdb-fetch-lines-break (or skip 0)) | |
652 (gud-marker-filter | |
653 `(lambda (string) (gud-gdb-fetch-lines-filter string ',gud-marker-filter)))) | |
654 ;; Issue the command to GDB. | |
655 (gud-basic-call command) | |
656 ;; Slurp the output. | |
657 (while gud-gdb-fetch-lines-in-progress | |
658 (accept-process-output (get-buffer-process buffer))) | |
659 (nreverse gud-gdb-fetched-lines))))) | |
660 | |
661 | |
662 ;; ====================================================================== | |
663 ;; sdb functions | |
664 | |
665 ;; History of argument lists passed to sdb. | |
666 (defvar gud-sdb-history nil) | |
667 | |
668 (defvar gud-sdb-needs-tags (not (file-exists-p "/var")) | |
669 "If nil, we're on a System V Release 4 and don't need the tags hack.") | |
670 | |
671 (defvar gud-sdb-lastfile nil) | |
672 | |
673 (defun gud-sdb-marker-filter (string) | |
674 (setq gud-marker-acc | |
675 (if gud-marker-acc (concat gud-marker-acc string) string)) | |
676 (let (start) | |
677 ;; Process all complete markers in this chunk | |
678 (while | |
679 (cond | |
680 ;; System V Release 3.2 uses this format | |
681 ((string-match "\\(^\\|\n\\)\\*?\\(0x\\w* in \\)?\\([^:\n]*\\):\\([0-9]*\\):.*\n" | |
682 gud-marker-acc start) | |
683 (setq gud-last-frame | |
684 (cons (match-string 3 gud-marker-acc) | |
685 (string-to-int (match-string 4 gud-marker-acc))))) | |
686 ;; System V Release 4.0 quite often clumps two lines together | |
687 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n\\([0-9]+\\):" | |
688 gud-marker-acc start) | |
689 (setq gud-sdb-lastfile (match-string 2 gud-marker-acc)) | |
690 (setq gud-last-frame | |
691 (cons gud-sdb-lastfile | |
692 (string-to-int (match-string 3 gud-marker-acc))))) | |
693 ;; System V Release 4.0 | |
694 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n" | |
695 gud-marker-acc start) | |
696 (setq gud-sdb-lastfile (match-string 2 gud-marker-acc))) | |
697 ((and gud-sdb-lastfile (string-match "^\\([0-9]+\\):" | |
698 gud-marker-acc start)) | |
699 (setq gud-last-frame | |
700 (cons gud-sdb-lastfile | |
701 (string-to-int (match-string 1 gud-marker-acc))))) | |
702 (t | |
703 (setq gud-sdb-lastfile nil))) | |
704 (setq start (match-end 0))) | |
705 | |
706 ;; Search for the last incomplete line in this chunk | |
707 (while (string-match "\n" gud-marker-acc start) | |
708 (setq start (match-end 0))) | |
709 | |
710 ;; If we have an incomplete line, store it in gud-marker-acc. | |
711 (setq gud-marker-acc (substring gud-marker-acc (or start 0)))) | |
712 string) | |
713 | |
714 (defun gud-sdb-find-file (f) | |
715 (if gud-sdb-needs-tags (find-tag-noselect f) (find-file-noselect f))) | |
716 | |
717 ;;;###autoload | |
718 (defun sdb (command-line) | |
719 "Run sdb on program FILE in buffer *gud-FILE*. | |
720 The directory containing FILE becomes the initial working directory | |
721 and source-file directory for your debugger." | |
722 (interactive (list (gud-query-cmdline 'sdb))) | |
723 | |
724 (if (and gud-sdb-needs-tags | |
725 (not (and (boundp 'tags-file-name) | |
726 (stringp tags-file-name) | |
727 (file-exists-p tags-file-name)))) | |
728 (error "The sdb support requires a valid tags table to work")) | |
729 | |
730 (gud-common-init command-line nil 'gud-sdb-marker-filter 'gud-sdb-find-file) | |
731 (set (make-local-variable 'gud-minor-mode) 'sdb) | |
732 | |
733 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.") | |
734 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.") | |
735 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line") | |
736 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.") | |
737 (gud-def gud-stepi "i %p" "\C-i" "Step one instruction with display.") | |
738 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).") | |
739 (gud-def gud-cont "c" "\C-r" "Continue with display.") | |
740 (gud-def gud-print "%e/" "\C-p" "Evaluate C expression at point.") | |
741 | |
742 (setq comint-prompt-regexp "\\(^\\|\n\\)\\*") | |
743 (setq paragraph-start comint-prompt-regexp) | |
744 (run-hooks 'sdb-mode-hook) | |
745 ) | |
746 | |
747 ;; ====================================================================== | |
748 ;; dbx functions | |
749 | |
750 ;; History of argument lists passed to dbx. | |
751 (defvar gud-dbx-history nil) | |
752 | |
753 (defcustom gud-dbx-directories nil | |
754 "*A list of directories that dbx should search for source code. | |
755 If nil, only source files in the program directory | |
756 will be known to dbx. | |
757 | |
758 The file names should be absolute, or relative to the directory | |
759 containing the executable being debugged." | |
760 :type '(choice (const :tag "Current Directory" nil) | |
761 (repeat :value ("") | |
762 directory)) | |
763 :group 'gud) | |
764 | |
765 (defun gud-dbx-massage-args (file args) | |
766 (nconc (let ((directories gud-dbx-directories) | |
767 (result nil)) | |
768 (while directories | |
769 (setq result (cons (car directories) (cons "-I" result))) | |
770 (setq directories (cdr directories))) | |
771 (nreverse result)) | |
772 args)) | |
773 | |
774 (defun gud-dbx-marker-filter (string) | |
775 (setq gud-marker-acc (if gud-marker-acc (concat gud-marker-acc string) string)) | |
776 | |
777 (let (start) | |
778 ;; Process all complete markers in this chunk. | |
779 (while (or (string-match | |
780 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" | |
781 gud-marker-acc start) | |
782 (string-match | |
783 "signal .* in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" | |
784 gud-marker-acc start)) | |
785 (setq gud-last-frame | |
786 (cons (match-string 2 gud-marker-acc) | |
787 (string-to-int (match-string 1 gud-marker-acc))) | |
788 start (match-end 0))) | |
789 | |
790 ;; Search for the last incomplete line in this chunk | |
791 (while (string-match "\n" gud-marker-acc start) | |
792 (setq start (match-end 0))) | |
793 | |
794 ;; If the incomplete line APPEARS to begin with another marker, keep it | |
795 ;; in the accumulator. Otherwise, clear the accumulator to avoid an | |
796 ;; unnecessary concat during the next call. | |
797 (setq gud-marker-acc | |
798 (if (string-match "\\(stopped\\|signal\\)" gud-marker-acc start) | |
799 (substring gud-marker-acc (match-beginning 0)) | |
800 nil))) | |
801 string) | |
802 | |
803 ;; Functions for Mips-style dbx. Given the option `-emacs', documented in | |
804 ;; OSF1, not necessarily elsewhere, it produces markers similar to gdb's. | |
805 (defvar gud-mips-p | |
806 (or (string-match "^mips-[^-]*-ultrix" system-configuration) | |
807 ;; We haven't tested gud on this system: | |
808 (string-match "^mips-[^-]*-riscos" system-configuration) | |
809 ;; It's documented on OSF/1.3 | |
810 (string-match "^mips-[^-]*-osf1" system-configuration) | |
811 (string-match "^alpha[^-]*-[^-]*-osf" system-configuration)) | |
812 "Non-nil to assume the MIPS/OSF dbx conventions (argument `-emacs').") | |
813 | |
814 (defvar gud-dbx-command-name | |
815 (concat "dbx" (if gud-mips-p " -emacs"))) | |
816 | |
817 ;; This is just like the gdb one except for the regexps since we need to cope | |
818 ;; with an optional breakpoint number in [] before the ^Z^Z | |
819 (defun gud-mipsdbx-marker-filter (string) | |
820 (setq gud-marker-acc (concat gud-marker-acc string)) | |
821 (let ((output "")) | |
822 | |
823 ;; Process all the complete markers in this chunk. | |
824 (while (string-match | |
825 ;; This is like th gdb marker but with an optional | |
826 ;; leading break point number like `[1] ' | |
827 "[][ 0-9]*\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n" | |
828 gud-marker-acc) | |
829 (setq | |
830 | |
831 ;; Extract the frame position from the marker. | |
832 gud-last-frame | |
833 (cons (match-string 1 gud-marker-acc) | |
834 (string-to-int (match-string 2 gud-marker-acc))) | |
835 | |
836 ;; Append any text before the marker to the output we're going | |
837 ;; to return - we don't include the marker in this text. | |
838 output (concat output | |
839 (substring gud-marker-acc 0 (match-beginning 0))) | |
840 | |
841 ;; Set the accumulator to the remaining text. | |
842 gud-marker-acc (substring gud-marker-acc (match-end 0)))) | |
843 | |
844 ;; Does the remaining text look like it might end with the | |
845 ;; beginning of another marker? If it does, then keep it in | |
846 ;; gud-marker-acc until we receive the rest of it. Since we | |
847 ;; know the full marker regexp above failed, it's pretty simple to | |
848 ;; test for marker starts. | |
849 (if (string-match "[][ 0-9]*\032.*\\'" gud-marker-acc) | |
850 (progn | |
851 ;; Everything before the potential marker start can be output. | |
852 (setq output (concat output (substring gud-marker-acc | |
853 0 (match-beginning 0)))) | |
854 | |
855 ;; Everything after, we save, to combine with later input. | |
856 (setq gud-marker-acc | |
857 (substring gud-marker-acc (match-beginning 0)))) | |
858 | |
859 (setq output (concat output gud-marker-acc) | |
860 gud-marker-acc "")) | |
861 | |
862 output)) | |
863 | |
864 ;; The dbx in IRIX is a pain. It doesn't print the file name when | |
865 ;; stopping at a breakpoint (but you do get it from the `up' and | |
866 ;; `down' commands...). The only way to extract the information seems | |
867 ;; to be with a `file' command, although the current line number is | |
868 ;; available in $curline. Thus we have to look for output which | |
869 ;; appears to indicate a breakpoint. Then we prod the dbx sub-process | |
870 ;; to output the information we want with a combination of the | |
871 ;; `printf' and `file' commands as a pseudo marker which we can | |
872 ;; recognise next time through the marker-filter. This would be like | |
873 ;; the gdb marker but you can't get the file name without a newline... | |
874 ;; Note that gud-remove won't work since Irix dbx expects a breakpoint | |
875 ;; number rather than a line number etc. Maybe this could be made to | |
876 ;; work by listing all the breakpoints and picking the one(s) with the | |
877 ;; correct line number, but life's too short. | |
878 ;; d.love@dl.ac.uk (Dave Love) can be blamed for this | |
879 | |
880 (defvar gud-irix-p | |
881 (and (string-match "^mips-[^-]*-irix" system-configuration) | |
882 (not (string-match "irix[6-9]\\.[1-9]" system-configuration))) | |
883 "Non-nil to assume the interface appropriate for IRIX dbx. | |
884 This works in IRIX 4, 5 and 6, but `gud-dbx-use-stopformat-p' provides | |
885 a better solution in 6.1 upwards.") | |
886 (defvar gud-dbx-use-stopformat-p | |
887 (string-match "irix[6-9]\\.[1-9]" system-configuration) | |
888 "Non-nil to use the dbx feature present at least from Irix 6.1 | |
889 whereby $stopformat=1 produces an output format compatiable with | |
890 `gud-dbx-marker-filter'.") | |
891 ;; [Irix dbx seems to be a moving target. The dbx output changed | |
892 ;; subtly sometime between OS v4.0.5 and v5.2 so that, for instance, | |
893 ;; the output from `up' is no longer spotted by gud (and it's probably | |
894 ;; not distinctive enough to try to match it -- use C-<, C-> | |
895 ;; exclusively) . For 5.3 and 6.0, the $curline variable changed to | |
896 ;; `long long'(why?!), so the printf stuff needed changing. The line | |
897 ;; number was cast to `long' as a compromise between the new `long | |
898 ;; long' and the original `int'. This is reported not to work in 6.2, | |
899 ;; so it's changed back to int -- don't make your sources too long. | |
900 ;; From Irix6.1 (but not 6.0?) dbx supports an undocumented feature | |
901 ;; whereby `set $stopformat=1' reportedly produces output compatible | |
902 ;; with `gud-dbx-marker-filter', which we prefer. | |
903 | |
904 ;; The process filter is also somewhat | |
905 ;; unreliable, sometimes not spotting the markers; I don't know | |
906 ;; whether there's anything that can be done about that. It would be | |
907 ;; much better if SGI could be persuaded to (re?)instate the MIPS | |
908 ;; -emacs flag for gdb-like output (which ought to be possible as most | |
909 ;; of the communication I've had over it has been from sgi.com).] | |
910 | |
911 ;; this filter is influenced by the xdb one rather than the gdb one | |
912 (defun gud-irixdbx-marker-filter (string) | |
913 (let (result (case-fold-search nil)) | |
914 (if (or (string-match comint-prompt-regexp string) | |
915 (string-match ".*\012" string)) | |
916 (setq result (concat gud-marker-acc string) | |
917 gud-marker-acc "") | |
918 (setq gud-marker-acc (concat gud-marker-acc string))) | |
919 (if result | |
920 (cond | |
921 ;; look for breakpoint or signal indication e.g.: | |
922 ;; [2] Process 1267 (pplot) stopped at [params:338 ,0x400ec0] | |
923 ;; Process 1281 (pplot) stopped at [params:339 ,0x400ec8] | |
924 ;; Process 1270 (pplot) Floating point exception [._read._read:16 ,0x452188] | |
925 ((string-match | |
926 "^\\(\\[[0-9]+] \\)?Process +[0-9]+ ([^)]*) [^[]+\\[[^]\n]*]\n" | |
927 result) | |
928 ;; prod dbx into printing out the line number and file | |
929 ;; name in a form we can grok as below | |
930 (process-send-string (get-buffer-process gud-comint-buffer) | |
931 "printf \"\032\032%1d:\",(int)$curline;file\n")) | |
932 ;; look for result of, say, "up" e.g.: | |
933 ;; .pplot.pplot(0x800) ["src/pplot.f":261, 0x400c7c] | |
934 ;; (this will also catch one of the lines printed by "where") | |
935 ((string-match | |
936 "^[^ ][^[]*\\[\"\\([^\"]+\\)\":\\([0-9]+\\), [^]]+]\n" | |
937 result) | |
938 (let ((file (match-string 1 result))) | |
939 (if (file-exists-p file) | |
940 (setq gud-last-frame | |
941 (cons (match-string 1 result) | |
942 (string-to-int (match-string 2 result)))))) | |
943 result) | |
944 ((string-match ; kluged-up marker as above | |
945 "\032\032\\([0-9]*\\):\\(.*\\)\n" result) | |
946 (let ((file (gud-file-name (match-string 2 result)))) | |
947 (if (and file (file-exists-p file)) | |
948 (setq gud-last-frame | |
949 (cons file | |
950 (string-to-int (match-string 1 result)))))) | |
951 (setq result (substring result 0 (match-beginning 0)))))) | |
952 (or result ""))) | |
953 | |
954 (defvar gud-dgux-p (string-match "-dgux" system-configuration) | |
955 "Non-nil means to assume the interface approriate for DG/UX dbx. | |
956 This was tested using R4.11.") | |
957 | |
958 ;; There are a couple of differences between DG's dbx output and normal | |
959 ;; dbx output which make it nontrivial to integrate this into the | |
960 ;; standard dbx-marker-filter (mainly, there are a different number of | |
961 ;; backreferences). The markers look like: | |
962 ;; | |
963 ;; (0) Stopped at line 10, routine main(argc=1, argv=0xeffff0e0), file t.c | |
964 ;; | |
965 ;; from breakpoints (the `(0)' there isn't constant, it's the breakpoint | |
966 ;; number), and | |
967 ;; | |
968 ;; Stopped at line 13, routine main(argc=1, argv=0xeffff0e0), file t.c | |
969 ;; | |
970 ;; from signals and | |
971 ;; | |
972 ;; Frame 21, line 974, routine command_loop(), file keyboard.c | |
973 ;; | |
974 ;; from up/down/where. | |
975 | |
976 (defun gud-dguxdbx-marker-filter (string) | |
977 (setq gud-marker-acc (if gud-marker-acc | |
978 (concat gud-marker-acc string) | |
979 string)) | |
980 (let ((re (concat "^\\(\\(([0-9]+) \\)?Stopped at\\|Frame [0-9]+,\\)" | |
981 " line \\([0-9]+\\), routine .*, file \\([^ \t\n]+\\)")) | |
982 start) | |
983 ;; Process all complete markers in this chunk. | |
984 (while (string-match re gud-marker-acc start) | |
985 (setq gud-last-frame | |
986 (cons (match-string 4 gud-marker-acc) | |
987 (string-to-int (match-string 3 gud-marker-acc))) | |
988 start (match-end 0))) | |
989 | |
990 ;; Search for the last incomplete line in this chunk | |
991 (while (string-match "\n" gud-marker-acc start) | |
992 (setq start (match-end 0))) | |
993 | |
994 ;; If the incomplete line APPEARS to begin with another marker, keep it | |
995 ;; in the accumulator. Otherwise, clear the accumulator to avoid an | |
996 ;; unnecessary concat during the next call. | |
997 (setq gud-marker-acc | |
998 (if (string-match "Stopped\\|Frame" gud-marker-acc start) | |
999 (substring gud-marker-acc (match-beginning 0)) | |
1000 nil))) | |
1001 string) | |
1002 | |
1003 ;;;###autoload | |
1004 (defun dbx (command-line) | |
1005 "Run dbx on program FILE in buffer *gud-FILE*. | |
1006 The directory containing FILE becomes the initial working directory | |
1007 and source-file directory for your debugger." | |
1008 (interactive (list (gud-query-cmdline 'dbx))) | |
1009 | |
1010 (cond | |
1011 (gud-mips-p | |
1012 (gud-common-init command-line nil 'gud-mipsdbx-marker-filter)) | |
1013 (gud-irix-p | |
1014 (gud-common-init command-line 'gud-dbx-massage-args | |
1015 'gud-irixdbx-marker-filter)) | |
1016 (gud-dgux-p | |
1017 (gud-common-init command-line 'gud-dbx-massage-args | |
1018 'gud-dguxdbx-marker-filter)) | |
1019 (t | |
1020 (gud-common-init command-line 'gud-dbx-massage-args | |
1021 'gud-dbx-marker-filter))) | |
1022 | |
1023 (set (make-local-variable 'gud-minor-mode) 'dbx) | |
1024 | |
1025 (cond | |
1026 (gud-mips-p | |
1027 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.") | |
1028 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.") | |
1029 (gud-def gud-break "stop at \"%f\":%l" | |
1030 "\C-b" "Set breakpoint at current line.") | |
1031 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")) | |
1032 (gud-irix-p | |
1033 (gud-def gud-break "stop at \"%d%f\":%l" | |
1034 "\C-b" "Set breakpoint at current line.") | |
1035 (gud-def gud-finish "return" "\C-f" "Finish executing current function.") | |
1036 (gud-def gud-up "up %p; printf \"\032\032%1d:\",(int)$curline;file\n" | |
1037 "<" "Up (numeric arg) stack frames.") | |
1038 (gud-def gud-down "down %p; printf \"\032\032%1d:\",(int)$curline;file\n" | |
1039 ">" "Down (numeric arg) stack frames.") | |
1040 ;; Make dbx give out the source location info that we need. | |
1041 (process-send-string (get-buffer-process gud-comint-buffer) | |
1042 "printf \"\032\032%1d:\",(int)$curline;file\n")) | |
1043 (t | |
1044 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.") | |
1045 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.") | |
1046 (gud-def gud-break "file \"%d%f\"\nstop at %l" | |
1047 "\C-b" "Set breakpoint at current line.") | |
1048 (if gud-dbx-use-stopformat-p | |
1049 (process-send-string (get-buffer-process gud-comint-buffer) | |
1050 "set $stopformat=1\n")))) | |
1051 | |
1052 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") | |
1053 (gud-def gud-step "step %p" "\C-s" "Step one line with display.") | |
1054 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.") | |
1055 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).") | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
1056 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).") |
51494 | 1057 (gud-def gud-cont "cont" "\C-r" "Continue with display.") |
1058 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.") | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
1059 (gud-def gud-run "run" nil "Run the program.") |
51494 | 1060 |
1061 (setq comint-prompt-regexp "^[^)\n]*dbx) *") | |
1062 (setq paragraph-start comint-prompt-regexp) | |
1063 (run-hooks 'dbx-mode-hook) | |
1064 ) | |
1065 | |
1066 ;; ====================================================================== | |
1067 ;; xdb (HP PARISC debugger) functions | |
1068 | |
1069 ;; History of argument lists passed to xdb. | |
1070 (defvar gud-xdb-history nil) | |
1071 | |
1072 (defcustom gud-xdb-directories nil | |
1073 "*A list of directories that xdb should search for source code. | |
1074 If nil, only source files in the program directory | |
1075 will be known to xdb. | |
1076 | |
1077 The file names should be absolute, or relative to the directory | |
1078 containing the executable being debugged." | |
1079 :type '(choice (const :tag "Current Directory" nil) | |
1080 (repeat :value ("") | |
1081 directory)) | |
1082 :group 'gud) | |
1083 | |
1084 (defun gud-xdb-massage-args (file args) | |
1085 (nconc (let ((directories gud-xdb-directories) | |
1086 (result nil)) | |
1087 (while directories | |
1088 (setq result (cons (car directories) (cons "-d" result))) | |
1089 (setq directories (cdr directories))) | |
1090 (nreverse result)) | |
1091 args)) | |
1092 | |
1093 ;; xdb does not print the lines all at once, so we have to accumulate them | |
1094 (defun gud-xdb-marker-filter (string) | |
1095 (let (result) | |
1096 (if (or (string-match comint-prompt-regexp string) | |
1097 (string-match ".*\012" string)) | |
1098 (setq result (concat gud-marker-acc string) | |
1099 gud-marker-acc "") | |
1100 (setq gud-marker-acc (concat gud-marker-acc string))) | |
1101 (if result | |
1102 (if (or (string-match "\\([^\n \t:]+\\): [^:]+: \\([0-9]+\\)[: ]" | |
1103 result) | |
1104 (string-match "[^: \t]+:[ \t]+\\([^:]+\\): [^:]+: \\([0-9]+\\):" | |
1105 result)) | |
1106 (let ((line (string-to-int (match-string 2 result))) | |
1107 (file (gud-file-name (match-string 1 result)))) | |
1108 (if file | |
1109 (setq gud-last-frame (cons file line)))))) | |
1110 (or result ""))) | |
1111 | |
1112 ;;;###autoload | |
1113 (defun xdb (command-line) | |
1114 "Run xdb on program FILE in buffer *gud-FILE*. | |
1115 The directory containing FILE becomes the initial working directory | |
1116 and source-file directory for your debugger. | |
1117 | |
1118 You can set the variable 'gud-xdb-directories' to a list of program source | |
1119 directories if your program contains sources from more than one directory." | |
1120 (interactive (list (gud-query-cmdline 'xdb))) | |
1121 | |
1122 (gud-common-init command-line 'gud-xdb-massage-args | |
1123 'gud-xdb-marker-filter) | |
1124 (set (make-local-variable 'gud-minor-mode) 'xdb) | |
1125 | |
1126 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.") | |
1127 (gud-def gud-tbreak "b %f:%l\\t" "\C-t" | |
1128 "Set temporary breakpoint at current line.") | |
1129 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line") | |
1130 (gud-def gud-step "s %p" "\C-s" "Step one line with display.") | |
1131 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).") | |
1132 (gud-def gud-cont "c" "\C-r" "Continue with display.") | |
1133 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.") | |
1134 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.") | |
1135 (gud-def gud-finish "bu\\t" "\C-f" "Finish executing current function.") | |
1136 (gud-def gud-print "p %e" "\C-p" "Evaluate C expression at point.") | |
1137 | |
1138 (setq comint-prompt-regexp "^>") | |
1139 (setq paragraph-start comint-prompt-regexp) | |
1140 (run-hooks 'xdb-mode-hook)) | |
1141 | |
1142 ;; ====================================================================== | |
1143 ;; perldb functions | |
1144 | |
1145 ;; History of argument lists passed to perldb. | |
1146 (defvar gud-perldb-history nil) | |
1147 | |
1148 (defun gud-perldb-massage-args (file args) | |
1149 "Convert a command line as would be typed normally to run perldb | |
1150 into one that invokes an Emacs-enabled debugging session. | |
1151 \"-emacs\" is inserted where it will be $ARGV[0] (see perl5db.pl)." | |
1152 ;; FIXME: what if the command is `make perldb' and doesn't accept those extra | |
1153 ;; arguments ? | |
1154 (let* ((new-args nil) | |
1155 (seen-e nil) | |
1156 (shift (lambda () (push (pop args) new-args)))) | |
1157 | |
1158 ;; Pass all switches and -e scripts through. | |
1159 (while (and args | |
1160 (string-match "^-" (car args)) | |
1161 (not (equal "-" (car args))) | |
1162 (not (equal "--" (car args)))) | |
1163 (when (equal "-e" (car args)) | |
1164 ;; -e goes with the next arg, so shift one extra. | |
1165 (or (funcall shift) | |
1166 ;; -e as the last arg is an error in Perl. | |
1167 (error "No code specified for -e")) | |
1168 (setq seen-e t)) | |
1169 (funcall shift)) | |
1170 | |
1171 (unless seen-e | |
1172 (if (or (not args) | |
1173 (string-match "^-" (car args))) | |
1174 (error "Can't use stdin as the script to debug")) | |
1175 ;; This is the program name. | |
1176 (funcall shift)) | |
1177 | |
1178 ;; If -e specified, make sure there is a -- so -emacs is not taken | |
1179 ;; as -e macs. | |
1180 (if (and args (equal "--" (car args))) | |
1181 (funcall shift) | |
1182 (and seen-e (push "--" new-args))) | |
1183 | |
1184 (push "-emacs" new-args) | |
1185 (while args | |
1186 (funcall shift)) | |
1187 | |
1188 (nreverse new-args))) | |
1189 | |
1190 ;; There's no guarantee that Emacs will hand the filter the entire | |
1191 ;; marker at once; it could be broken up across several strings. We | |
1192 ;; might even receive a big chunk with several markers in it. If we | |
1193 ;; receive a chunk of text which looks like it might contain the | |
1194 ;; beginning of a marker, we save it here between calls to the | |
1195 ;; filter. | |
1196 (defun gud-perldb-marker-filter (string) | |
1197 (setq gud-marker-acc (concat gud-marker-acc string)) | |
1198 (let ((output "")) | |
1199 | |
1200 ;; Process all the complete markers in this chunk. | |
1201 (while (string-match "\032\032\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\):.*\n" | |
1202 gud-marker-acc) | |
1203 (setq | |
1204 | |
1205 ;; Extract the frame position from the marker. | |
1206 gud-last-frame | |
1207 (cons (match-string 1 gud-marker-acc) | |
1208 (string-to-int (match-string 3 gud-marker-acc))) | |
1209 | |
1210 ;; Append any text before the marker to the output we're going | |
1211 ;; to return - we don't include the marker in this text. | |
1212 output (concat output | |
1213 (substring gud-marker-acc 0 (match-beginning 0))) | |
1214 | |
1215 ;; Set the accumulator to the remaining text. | |
1216 gud-marker-acc (substring gud-marker-acc (match-end 0)))) | |
1217 | |
1218 ;; Does the remaining text look like it might end with the | |
1219 ;; beginning of another marker? If it does, then keep it in | |
1220 ;; gud-marker-acc until we receive the rest of it. Since we | |
1221 ;; know the full marker regexp above failed, it's pretty simple to | |
1222 ;; test for marker starts. | |
1223 (if (string-match "\032.*\\'" gud-marker-acc) | |
1224 (progn | |
1225 ;; Everything before the potential marker start can be output. | |
1226 (setq output (concat output (substring gud-marker-acc | |
1227 0 (match-beginning 0)))) | |
1228 | |
1229 ;; Everything after, we save, to combine with later input. | |
1230 (setq gud-marker-acc | |
1231 (substring gud-marker-acc (match-beginning 0)))) | |
1232 | |
1233 (setq output (concat output gud-marker-acc) | |
1234 gud-marker-acc "")) | |
1235 | |
1236 output)) | |
1237 | |
1238 (defcustom gud-perldb-command-name "perl -d" | |
1239 "Default command to execute a Perl script under debugger." | |
1240 :type 'string | |
1241 :group 'gud) | |
1242 | |
1243 ;;;###autoload | |
1244 (defun perldb (command-line) | |
1245 "Run perldb on program FILE in buffer *gud-FILE*. | |
1246 The directory containing FILE becomes the initial working directory | |
1247 and source-file directory for your debugger." | |
1248 (interactive | |
1249 (list (gud-query-cmdline 'perldb | |
1250 (concat (or (buffer-file-name) "-e 0") " ")))) | |
1251 | |
1252 (gud-common-init command-line 'gud-perldb-massage-args | |
1253 'gud-perldb-marker-filter) | |
1254 (set (make-local-variable 'gud-minor-mode) 'perldb) | |
1255 | |
1256 (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.") | |
1257 (gud-def gud-remove "d %l" "\C-d" "Remove breakpoint at current line") | |
1258 (gud-def gud-step "s" "\C-s" "Step one source line with display.") | |
1259 (gud-def gud-next "n" "\C-n" "Step one line (skip functions).") | |
1260 (gud-def gud-cont "c" "\C-r" "Continue with display.") | |
1261 ; (gud-def gud-finish "finish" "\C-f" "Finish executing current function.") | |
1262 ; (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") | |
1263 ; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") | |
1264 (gud-def gud-print "%e" "\C-p" "Evaluate perl expression at point.") | |
1265 | |
1266 (setq comint-prompt-regexp "^ DB<+[0-9]+>+ ") | |
1267 (setq paragraph-start comint-prompt-regexp) | |
1268 (run-hooks 'perldb-mode-hook)) | |
1269 | |
1270 ;; ====================================================================== | |
1271 ;; pdb (Python debugger) functions | |
1272 | |
1273 ;; History of argument lists passed to pdb. | |
1274 (defvar gud-pdb-history nil) | |
1275 | |
1276 ;; Last group is for return value, e.g. "> test.py(2)foo()->None" | |
1277 ;; Either file or function name may be omitted: "> <string>(0)?()" | |
1278 (defvar gud-pdb-marker-regexp | |
1279 "^> \\([-a-zA-Z0-9_/.:\\]*\\|<string>\\)(\\([0-9]+\\))\\([a-zA-Z0-9_]*\\|\\?\\)()\\(->[^\n]*\\)?\n") | |
1280 (defvar gud-pdb-marker-regexp-file-group 1) | |
1281 (defvar gud-pdb-marker-regexp-line-group 2) | |
1282 (defvar gud-pdb-marker-regexp-fnname-group 3) | |
1283 | |
1284 (defvar gud-pdb-marker-regexp-start "^> ") | |
1285 | |
1286 ;; There's no guarantee that Emacs will hand the filter the entire | |
1287 ;; marker at once; it could be broken up across several strings. We | |
1288 ;; might even receive a big chunk with several markers in it. If we | |
1289 ;; receive a chunk of text which looks like it might contain the | |
1290 ;; beginning of a marker, we save it here between calls to the | |
1291 ;; filter. | |
1292 (defun gud-pdb-marker-filter (string) | |
1293 (setq gud-marker-acc (concat gud-marker-acc string)) | |
1294 (let ((output "")) | |
1295 | |
1296 ;; Process all the complete markers in this chunk. | |
1297 (while (string-match gud-pdb-marker-regexp gud-marker-acc) | |
1298 (setq | |
1299 | |
1300 ;; Extract the frame position from the marker. | |
1301 gud-last-frame | |
1302 (let ((file (match-string gud-pdb-marker-regexp-file-group | |
1303 gud-marker-acc)) | |
1304 (line (string-to-int | |
1305 (match-string gud-pdb-marker-regexp-line-group | |
1306 gud-marker-acc)))) | |
1307 (if (string-equal file "<string>") | |
1308 gud-last-frame | |
1309 (cons file line))) | |
1310 | |
1311 ;; Output everything instead of the below | |
1312 output (concat output (substring gud-marker-acc 0 (match-end 0))) | |
1313 ;; ;; Append any text before the marker to the output we're going | |
1314 ;; ;; to return - we don't include the marker in this text. | |
1315 ;; output (concat output | |
1316 ;; (substring gud-marker-acc 0 (match-beginning 0))) | |
1317 | |
1318 ;; Set the accumulator to the remaining text. | |
1319 gud-marker-acc (substring gud-marker-acc (match-end 0)))) | |
1320 | |
1321 ;; Does the remaining text look like it might end with the | |
1322 ;; beginning of another marker? If it does, then keep it in | |
1323 ;; gud-marker-acc until we receive the rest of it. Since we | |
1324 ;; know the full marker regexp above failed, it's pretty simple to | |
1325 ;; test for marker starts. | |
1326 (if (string-match gud-pdb-marker-regexp-start gud-marker-acc) | |
1327 (progn | |
1328 ;; Everything before the potential marker start can be output. | |
1329 (setq output (concat output (substring gud-marker-acc | |
1330 0 (match-beginning 0)))) | |
1331 | |
1332 ;; Everything after, we save, to combine with later input. | |
1333 (setq gud-marker-acc | |
1334 (substring gud-marker-acc (match-beginning 0)))) | |
1335 | |
1336 (setq output (concat output gud-marker-acc) | |
1337 gud-marker-acc "")) | |
1338 | |
1339 output)) | |
1340 | |
1341 (defcustom gud-pdb-command-name "pdb" | |
1342 "File name for executing the Python debugger. | |
1343 This should be an executable on your path, or an absolute file name." | |
1344 :type 'string | |
1345 :group 'gud) | |
1346 | |
1347 ;;;###autoload | |
1348 (defun pdb (command-line) | |
1349 "Run pdb on program FILE in buffer `*gud-FILE*'. | |
1350 The directory containing FILE becomes the initial working directory | |
1351 and source-file directory for your debugger." | |
1352 (interactive | |
1353 (list (gud-query-cmdline 'pdb))) | |
1354 | |
1355 (gud-common-init command-line nil 'gud-pdb-marker-filter) | |
1356 (set (make-local-variable 'gud-minor-mode) 'pdb) | |
1357 | |
1358 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.") | |
1359 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line") | |
1360 (gud-def gud-step "step" "\C-s" "Step one source line with display.") | |
1361 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).") | |
1362 (gud-def gud-cont "continue" "\C-r" "Continue with display.") | |
1363 (gud-def gud-finish "return" "\C-f" "Finish executing current function.") | |
1364 (gud-def gud-up "up" "<" "Up one stack frame.") | |
1365 (gud-def gud-down "down" ">" "Down one stack frame.") | |
1366 (gud-def gud-print "p %e" "\C-p" "Evaluate Python expression at point.") | |
1367 ;; Is this right? | |
1368 (gud-def gud-statement "! %e" "\C-e" "Execute Python statement at point.") | |
1369 | |
1370 ;; (setq comint-prompt-regexp "^(.*pdb[+]?) *") | |
1371 (setq comint-prompt-regexp "^(Pdb) *") | |
1372 (setq paragraph-start comint-prompt-regexp) | |
1373 (run-hooks 'pdb-mode-hook)) | |
1374 | |
1375 ;; ====================================================================== | |
1376 ;; | |
1377 ;; JDB support. | |
1378 ;; | |
1379 ;; AUTHOR: Derek Davies <ddavies@world.std.com> | |
1380 ;; Zoltan Kemenczy <zoltan@ieee.org;zkemenczy@rim.net> | |
1381 ;; | |
1382 ;; CREATED: Sun Feb 22 10:46:38 1998 Derek Davies. | |
1383 ;; UPDATED: Nov 11, 2001 Zoltan Kemenczy | |
1384 ;; Dec 10, 2002 Zoltan Kemenczy - added nested class support | |
1385 ;; | |
1386 ;; INVOCATION NOTES: | |
1387 ;; | |
1388 ;; You invoke jdb-mode with: | |
1389 ;; | |
1390 ;; M-x jdb <enter> | |
1391 ;; | |
1392 ;; It responds with: | |
1393 ;; | |
1394 ;; Run jdb (like this): jdb | |
1395 ;; | |
1396 ;; type any jdb switches followed by the name of the class you'd like to debug. | |
1397 ;; Supply a fully qualfied classname (these do not have the ".class" extension) | |
1398 ;; for the name of the class to debug (e.g. "COM.the-kind.ddavies.CoolClass"). | |
1399 ;; See the known problems section below for restrictions when specifying jdb | |
1400 ;; command line switches (search forward for '-classpath'). | |
1401 ;; | |
1402 ;; You should see something like the following: | |
1403 ;; | |
1404 ;; Current directory is ~/src/java/hello/ | |
1405 ;; Initializing jdb... | |
1406 ;; 0xed2f6628:class(hello) | |
1407 ;; > | |
1408 ;; | |
1409 ;; To set an initial breakpoint try: | |
1410 ;; | |
1411 ;; > stop in hello.main | |
1412 ;; Breakpoint set in hello.main | |
1413 ;; > | |
1414 ;; | |
1415 ;; To execute the program type: | |
1416 ;; | |
1417 ;; > run | |
1418 ;; run hello | |
1419 ;; | |
1420 ;; Breakpoint hit: running ... | |
1421 ;; hello.main (hello:12) | |
1422 ;; | |
1423 ;; Type M-n to step over the current line and M-s to step into it. That, | |
1424 ;; along with the JDB 'help' command should get you started. The 'quit' | |
1425 ;; JDB command will get out out of the debugger. There is some truly | |
1426 ;; pathetic JDB documentation available at: | |
1427 ;; | |
1428 ;; http://java.sun.com/products/jdk/1.1/debugging/ | |
1429 ;; | |
1430 ;; KNOWN PROBLEMS AND FIXME's: | |
1431 ;; | |
1432 ;; Not sure what happens with inner classes ... haven't tried them. | |
1433 ;; | |
1434 ;; Does not grok UNICODE id's. Only ASCII id's are supported. | |
1435 ;; | |
1436 ;; You must not put whitespace between "-classpath" and the path to | |
1437 ;; search for java classes even though it is required when invoking jdb | |
1438 ;; from the command line. See gud-jdb-massage-args for details. | |
1439 ;; The same applies for "-sourcepath". | |
1440 ;; | |
1441 ;; Note: The following applies only if `gud-jdb-use-classpath' is nil; | |
1442 ;; refer to the documentation of `gud-jdb-use-classpath' and | |
1443 ;; `gud-jdb-classpath',`gud-jdb-sourcepath' variables for information | |
1444 ;; on using the classpath for locating java source files. | |
1445 ;; | |
1446 ;; If any of the source files in the directories listed in | |
1447 ;; gud-jdb-directories won't parse you'll have problems. Make sure | |
1448 ;; every file ending in ".java" in these directories parses without error. | |
1449 ;; | |
1450 ;; All the .java files in the directories in gud-jdb-directories are | |
1451 ;; syntactically analyzed each time gud jdb is invoked. It would be | |
1452 ;; nice to keep as much information as possible between runs. It would | |
1453 ;; be really nice to analyze the files only as neccessary (when the | |
1454 ;; source needs to be displayed.) I'm not sure to what extent the former | |
1455 ;; can be accomplished and I'm not sure the latter can be done at all | |
1456 ;; since I don't know of any general way to tell which .class files are | |
1457 ;; defined by which .java file without analyzing all the .java files. | |
1458 ;; If anyone knows why JavaSoft didn't put the source file names in | |
1459 ;; debuggable .class files please clue me in so I find something else | |
1460 ;; to be spiteful and bitter about. | |
1461 ;; | |
1462 ;; ====================================================================== | |
1463 ;; gud jdb variables and functions | |
1464 | |
1465 (defcustom gud-jdb-command-name "jdb" | |
1466 "Command that executes the Java debugger." | |
1467 :type 'string | |
1468 :group 'gud) | |
1469 | |
1470 (defcustom gud-jdb-use-classpath t | |
1471 "If non-nil, search for Java source files in classpath directories. | |
1472 The list of directories to search is the value of `gud-jdb-classpath'. | |
1473 The file pathname is obtained by converting the fully qualified | |
1474 class information output by jdb to a relative pathname and appending | |
1475 it to `gud-jdb-classpath' element by element until a match is found. | |
1476 | |
1477 This method has a significant jdb startup time reduction advantage | |
1478 since it does not require the scanning of all `gud-jdb-directories' | |
1479 and parsing all Java files for class information. | |
1480 | |
1481 Set to nil to use `gud-jdb-directories' to scan java sources for | |
1482 class information on jdb startup (original method)." | |
1483 :type 'boolean | |
1484 :group 'gud) | |
1485 | |
1486 (defvar gud-jdb-classpath nil | |
1487 "Java/jdb classpath directories list. | |
1488 If `gud-jdb-use-classpath' is non-nil, gud-jdb derives the `gud-jdb-classpath' | |
1489 list automatically using the following methods in sequence | |
1490 \(with subsequent successful steps overriding the results of previous | |
1491 steps): | |
1492 | |
1493 1) Read the CLASSPATH environment variable, | |
1494 2) Read any \"-classpath\" argument used to run jdb, | |
1495 or detected in jdb output (e.g. if jdb is run by a script | |
1496 that echoes the actual jdb command before starting jdb) | |
1497 3) Send a \"classpath\" command to jdb and scan jdb output for | |
1498 classpath information if jdb is invoked with an \"-attach\" (to | |
1499 an already running VM) argument (This case typically does not | |
1500 have a \"-classpath\" command line argument - that is provided | |
1501 to the VM when it is started). | |
1502 | |
1503 Note that method 3 cannot be used with oldjdb (or Java 1 jdb) since | |
1504 those debuggers do not support the classpath command. Use 1) or 2).") | |
1505 | |
1506 (defvar gud-jdb-sourcepath nil | |
1507 "Directory list provided by an (optional) \"-sourcepath\" option to jdb. | |
1508 This list is prepended to `gud-jdb-classpath' to form the complete | |
1509 list of directories searched for source files.") | |
1510 | |
1511 (defvar gud-marker-acc-max-length 4000 | |
1512 "Maximum number of debugger output characters to keep. | |
1513 This variable limits the size of `gud-marker-acc' which holds | |
1514 the most recent debugger output history while searching for | |
1515 source file information.") | |
1516 | |
1517 (defvar gud-jdb-history nil | |
1518 "History of argument lists passed to jdb.") | |
1519 | |
1520 | |
1521 ;; List of Java source file directories. | |
1522 (defvar gud-jdb-directories (list ".") | |
1523 "*A list of directories that gud jdb should search for source code. | |
1524 The file names should be absolute, or relative to the current | |
1525 directory. | |
1526 | |
1527 The set of .java files residing in the directories listed are | |
1528 syntactically analyzed to determine the classes they define and the | |
1529 packages in which these classes belong. In this way gud jdb maps the | |
1530 package-qualified class names output by the jdb debugger to the source | |
1531 file from which the class originated. This allows gud mode to keep | |
1532 the source code display in sync with the debugging session.") | |
1533 | |
1534 (defvar gud-jdb-source-files nil | |
1535 "List of the java source files for this debugging session.") | |
1536 | |
1537 ;; Association list of fully qualified class names (package + class name) | |
1538 ;; and their source files. | |
1539 (defvar gud-jdb-class-source-alist nil | |
1540 "Association list of fully qualified class names and source files.") | |
1541 | |
1542 ;; This is used to hold a source file during analysis. | |
1543 (defvar gud-jdb-analysis-buffer nil) | |
1544 | |
1545 (defvar gud-jdb-classpath-string nil | |
1546 "Holds temporary classpath values.") | |
1547 | |
1548 (defun gud-jdb-build-source-files-list (path extn) | |
1549 "Return a list of java source files (absolute paths). | |
1550 PATH gives the directories in which to search for files with | |
1551 extension EXTN. Normally EXTN is given as the regular expression | |
1552 \"\\.java$\" ." | |
1553 (apply 'nconc (mapcar (lambda (d) | |
1554 (when (file-directory-p d) | |
1555 (directory-files d t extn nil))) | |
1556 path))) | |
1557 | |
1558 ;; Move point past whitespace. | |
1559 (defun gud-jdb-skip-whitespace () | |
1560 (skip-chars-forward " \n\r\t\014")) | |
1561 | |
1562 ;; Move point past a "// <eol>" type of comment. | |
1563 (defun gud-jdb-skip-single-line-comment () | |
1564 (end-of-line)) | |
1565 | |
1566 ;; Move point past a "/* */" or "/** */" type of comment. | |
1567 (defun gud-jdb-skip-traditional-or-documentation-comment () | |
1568 (forward-char 2) | |
1569 (catch 'break | |
1570 (while (not (eobp)) | |
1571 (if (eq (following-char) ?*) | |
1572 (progn | |
1573 (forward-char) | |
1574 (if (not (eobp)) | |
1575 (if (eq (following-char) ?/) | |
1576 (progn | |
1577 (forward-char) | |
1578 (throw 'break nil))))) | |
1579 (forward-char))))) | |
1580 | |
1581 ;; Move point past any number of consecutive whitespace chars and/or comments. | |
1582 (defun gud-jdb-skip-whitespace-and-comments () | |
1583 (gud-jdb-skip-whitespace) | |
1584 (catch 'done | |
1585 (while t | |
1586 (cond | |
1587 ((looking-at "//") | |
1588 (gud-jdb-skip-single-line-comment) | |
1589 (gud-jdb-skip-whitespace)) | |
1590 ((looking-at "/\\*") | |
1591 (gud-jdb-skip-traditional-or-documentation-comment) | |
1592 (gud-jdb-skip-whitespace)) | |
1593 (t (throw 'done nil)))))) | |
1594 | |
1595 ;; Move point past things that are id-like. The intent is to skip regular | |
1596 ;; id's, such as class or interface names as well as package and interface | |
1597 ;; names. | |
1598 (defun gud-jdb-skip-id-ish-thing () | |
1599 (skip-chars-forward "^ /\n\r\t\014,;{")) | |
1600 | |
1601 ;; Move point past a string literal. | |
1602 (defun gud-jdb-skip-string-literal () | |
1603 (forward-char) | |
1604 (while (not (cond | |
1605 ((eq (following-char) ?\\) | |
1606 (forward-char)) | |
1607 ((eq (following-char) ?\042)))) | |
1608 (forward-char)) | |
1609 (forward-char)) | |
1610 | |
1611 ;; Move point past a character literal. | |
1612 (defun gud-jdb-skip-character-literal () | |
1613 (forward-char) | |
1614 (while | |
1615 (progn | |
1616 (if (eq (following-char) ?\\) | |
1617 (forward-char 2)) | |
1618 (not (eq (following-char) ?\'))) | |
1619 (forward-char)) | |
1620 (forward-char)) | |
1621 | |
1622 ;; Move point past the following block. There may be (legal) cruft before | |
1623 ;; the block's opening brace. There must be a block or it's the end of life | |
1624 ;; in petticoat junction. | |
1625 (defun gud-jdb-skip-block () | |
1626 | |
1627 ;; Find the begining of the block. | |
1628 (while | |
1629 (not (eq (following-char) ?{)) | |
1630 | |
1631 ;; Skip any constructs that can harbor literal block delimiter | |
1632 ;; characters and/or the delimiters for the constructs themselves. | |
1633 (cond | |
1634 ((looking-at "//") | |
1635 (gud-jdb-skip-single-line-comment)) | |
1636 ((looking-at "/\\*") | |
1637 (gud-jdb-skip-traditional-or-documentation-comment)) | |
1638 ((eq (following-char) ?\042) | |
1639 (gud-jdb-skip-string-literal)) | |
1640 ((eq (following-char) ?\') | |
1641 (gud-jdb-skip-character-literal)) | |
1642 (t (forward-char)))) | |
1643 | |
1644 ;; Now at the begining of the block. | |
1645 (forward-char) | |
1646 | |
1647 ;; Skip over the body of the block as well as the final brace. | |
1648 (let ((open-level 1)) | |
1649 (while (not (eq open-level 0)) | |
1650 (cond | |
1651 ((looking-at "//") | |
1652 (gud-jdb-skip-single-line-comment)) | |
1653 ((looking-at "/\\*") | |
1654 (gud-jdb-skip-traditional-or-documentation-comment)) | |
1655 ((eq (following-char) ?\042) | |
1656 (gud-jdb-skip-string-literal)) | |
1657 ((eq (following-char) ?\') | |
1658 (gud-jdb-skip-character-literal)) | |
1659 ((eq (following-char) ?{) | |
1660 (setq open-level (+ open-level 1)) | |
1661 (forward-char)) | |
1662 ((eq (following-char) ?}) | |
1663 (setq open-level (- open-level 1)) | |
1664 (forward-char)) | |
1665 (t (forward-char)))))) | |
1666 | |
1667 ;; Find the package and class definitions in Java source file FILE. Assumes | |
1668 ;; that FILE contains a legal Java program. BUF is a scratch buffer used | |
1669 ;; to hold the source during analysis. | |
1670 (defun gud-jdb-analyze-source (buf file) | |
1671 (let ((l nil)) | |
1672 (set-buffer buf) | |
1673 (insert-file-contents file nil nil nil t) | |
1674 (goto-char 0) | |
1675 (catch 'abort | |
1676 (let ((p "")) | |
1677 (while (progn | |
1678 (gud-jdb-skip-whitespace) | |
1679 (not (eobp))) | |
1680 (cond | |
1681 | |
1682 ;; Any number of semi's following a block is legal. Move point | |
1683 ;; past them. Note that comments and whitespace may be | |
1684 ;; interspersed as well. | |
1685 ((eq (following-char) ?\073) | |
1686 (forward-char)) | |
1687 | |
1688 ;; Move point past a single line comment. | |
1689 ((looking-at "//") | |
1690 (gud-jdb-skip-single-line-comment)) | |
1691 | |
1692 ;; Move point past a traditional or documentation comment. | |
1693 ((looking-at "/\\*") | |
1694 (gud-jdb-skip-traditional-or-documentation-comment)) | |
1695 | |
1696 ;; Move point past a package statement, but save the PackageName. | |
1697 ((looking-at "package") | |
1698 (forward-char 7) | |
1699 (gud-jdb-skip-whitespace-and-comments) | |
1700 (let ((s (point))) | |
1701 (gud-jdb-skip-id-ish-thing) | |
1702 (setq p (concat (buffer-substring s (point)) ".")) | |
1703 (gud-jdb-skip-whitespace-and-comments) | |
1704 (if (eq (following-char) ?\073) | |
1705 (forward-char)))) | |
1706 | |
1707 ;; Move point past an import statement. | |
1708 ((looking-at "import") | |
1709 (forward-char 6) | |
1710 (gud-jdb-skip-whitespace-and-comments) | |
1711 (gud-jdb-skip-id-ish-thing) | |
1712 (gud-jdb-skip-whitespace-and-comments) | |
1713 (if (eq (following-char) ?\073) | |
1714 (forward-char))) | |
1715 | |
1716 ;; Move point past the various kinds of ClassModifiers. | |
1717 ((looking-at "public") | |
1718 (forward-char 6)) | |
1719 ((looking-at "abstract") | |
1720 (forward-char 8)) | |
1721 ((looking-at "final") | |
1722 (forward-char 5)) | |
1723 | |
1724 ;; Move point past a ClassDeclaraction, but save the class | |
1725 ;; Identifier. | |
1726 ((looking-at "class") | |
1727 (forward-char 5) | |
1728 (gud-jdb-skip-whitespace-and-comments) | |
1729 (let ((s (point))) | |
1730 (gud-jdb-skip-id-ish-thing) | |
1731 (setq | |
1732 l (nconc l (list (concat p (buffer-substring s (point))))))) | |
1733 (gud-jdb-skip-block)) | |
1734 | |
1735 ;; Move point past an interface statement. | |
1736 ((looking-at "interface") | |
1737 (forward-char 9) | |
1738 (gud-jdb-skip-block)) | |
1739 | |
1740 ;; Anything else means the input is invalid. | |
1741 (t | |
1742 (message (format "Error parsing file %s." file)) | |
1743 (throw 'abort nil)))))) | |
1744 l)) | |
1745 | |
1746 (defun gud-jdb-build-class-source-alist-for-file (file) | |
1747 (mapcar | |
1748 (lambda (c) | |
1749 (cons c file)) | |
1750 (gud-jdb-analyze-source gud-jdb-analysis-buffer file))) | |
1751 | |
1752 ;; Return an alist of fully qualified classes and the source files | |
1753 ;; holding their definitions. SOURCES holds a list of all the source | |
1754 ;; files to examine. | |
1755 (defun gud-jdb-build-class-source-alist (sources) | |
1756 (setq gud-jdb-analysis-buffer (get-buffer-create " *gud-jdb-scratch*")) | |
1757 (prog1 | |
1758 (apply | |
1759 'nconc | |
1760 (mapcar | |
1761 'gud-jdb-build-class-source-alist-for-file | |
1762 sources)) | |
1763 (kill-buffer gud-jdb-analysis-buffer) | |
1764 (setq gud-jdb-analysis-buffer nil))) | |
1765 | |
1766 ;; Change what was given in the minibuffer to something that can be used to | |
1767 ;; invoke the debugger. | |
1768 (defun gud-jdb-massage-args (file args) | |
1769 ;; The jdb executable must have whitespace between "-classpath" and | |
1770 ;; its value while gud-common-init expects all switch values to | |
1771 ;; follow the switch keyword without intervening whitespace. We | |
1772 ;; require that when the user enters the "-classpath" switch in the | |
1773 ;; EMACS minibuffer that they do so without the intervening | |
1774 ;; whitespace. This function adds it back (it's called after | |
1775 ;; gud-common-init). There are more switches like this (for | |
1776 ;; instance "-host" and "-password") but I don't care about them | |
1777 ;; yet. | |
1778 (if args | |
1779 (let (massaged-args user-error) | |
1780 | |
1781 (while (and args (not user-error)) | |
1782 (cond | |
1783 ((setq user-error (string-match "-classpath$" (car args)))) | |
1784 ((setq user-error (string-match "-sourcepath$" (car args)))) | |
1785 ((string-match "-classpath\\(.+\\)" (car args)) | |
1786 (setq massaged-args | |
1787 (append massaged-args | |
1788 (list "-classpath" | |
1789 (setq gud-jdb-classpath-string | |
1790 (match-string 1 (car args))))))) | |
1791 ((string-match "-sourcepath\\(.+\\)" (car args)) | |
1792 (setq massaged-args | |
1793 (append massaged-args | |
1794 (list "-sourcepath" | |
1795 (setq gud-jdb-sourcepath | |
1796 (match-string 1 (car args))))))) | |
1797 (t (setq massaged-args (append massaged-args (list (car args)))))) | |
1798 (setq args (cdr args))) | |
1799 | |
1800 ;; By this point the current directory is all screwed up. Maybe we | |
1801 ;; could fix things and re-invoke gud-common-init, but for now I think | |
1802 ;; issueing the error is good enough. | |
1803 (if user-error | |
1804 (progn | |
1805 (kill-buffer (current-buffer)) | |
1806 (error "Error: Omit whitespace between '-classpath or -sourcepath' and its value"))) | |
1807 massaged-args))) | |
1808 | |
1809 ;; Search for an association with P, a fully qualified class name, in | |
1810 ;; gud-jdb-class-source-alist. The asssociation gives the fully | |
1811 ;; qualified file name of the source file which produced the class. | |
1812 (defun gud-jdb-find-source-file (p) | |
1813 (cdr (assoc p gud-jdb-class-source-alist))) | |
1814 | |
1815 ;; Note: Reset to this value every time a prompt is seen | |
1816 (defvar gud-jdb-lowest-stack-level 999) | |
1817 | |
1818 (defun gud-jdb-find-source-using-classpath (p) | |
1819 "Find source file corresponding to fully qualified class p. | |
1820 Convert p from jdb's output, converted to a pathname | |
1821 relative to a classpath directory." | |
1822 (save-match-data | |
1823 (let | |
1824 (;; Replace dots with slashes and append ".java" to generate file | |
1825 ;; name relative to classpath | |
1826 (filename | |
1827 (concat | |
1828 (mapconcat 'identity | |
1829 (split-string | |
1830 ;; Eliminate any subclass references in the class | |
1831 ;; name string. These start with a "$" | |
1832 ((lambda (x) | |
1833 (if (string-match "$.*" x) | |
1834 (replace-match "" t t x) p)) | |
1835 p) | |
1836 "\\.") "/") | |
1837 ".java")) | |
1838 (cplist (append gud-jdb-sourcepath gud-jdb-classpath)) | |
1839 found-file) | |
1840 (while (and cplist | |
1841 (not (setq found-file | |
1842 (file-readable-p | |
1843 (concat (car cplist) "/" filename))))) | |
1844 (setq cplist (cdr cplist))) | |
1845 (if found-file (concat (car cplist) "/" filename))))) | |
1846 | |
1847 (defun gud-jdb-find-source (string) | |
1848 "Alias for function used to locate source files. | |
1849 Set to `gud-jdb-find-source-using-classpath' or `gud-jdb-find-source-file' | |
1850 during jdb initialization depending on the value of | |
1851 `gud-jdb-use-classpath'." | |
1852 nil) | |
1853 | |
1854 (defun gud-jdb-parse-classpath-string (string) | |
1855 "Parse the classpath list and convert each item to an absolute pathname." | |
1856 (mapcar (lambda (s) (if (string-match "[/\\]$" s) | |
1857 (replace-match "" nil nil s) s)) | |
1858 (mapcar 'file-truename | |
1859 (split-string | |
1860 string | |
1861 (concat "[ \t\n\r,\"" path-separator "]+"))))) | |
1862 | |
1863 ;; See comentary for other debugger's marker filters - there you will find | |
1864 ;; important notes about STRING. | |
1865 (defun gud-jdb-marker-filter (string) | |
1866 | |
1867 ;; Build up the accumulator. | |
1868 (setq gud-marker-acc | |
1869 (if gud-marker-acc | |
1870 (concat gud-marker-acc string) | |
1871 string)) | |
1872 | |
1873 ;; Look for classpath information until gud-jdb-classpath-string is found | |
1874 ;; (interactive, multiple settings of classpath from jdb | |
1875 ;; not supported/followed) | |
1876 (if (and gud-jdb-use-classpath | |
1877 (not gud-jdb-classpath-string) | |
1878 (or (string-match "classpath:[ \t[]+\\([^]]+\\)" gud-marker-acc) | |
1879 (string-match "-classpath[ \t\"]+\\([^ \"]+\\)" gud-marker-acc))) | |
1880 (setq gud-jdb-classpath | |
1881 (gud-jdb-parse-classpath-string | |
1882 (setq gud-jdb-classpath-string | |
1883 (match-string 1 gud-marker-acc))))) | |
1884 | |
1885 ;; We process STRING from left to right. Each time through the | |
1886 ;; following loop we process at most one marker. After we've found a | |
1887 ;; marker, delete gud-marker-acc up to and including the match | |
1888 (let (file-found) | |
1889 ;; Process each complete marker in the input. | |
1890 (while | |
1891 | |
1892 ;; Do we see a marker? | |
1893 (string-match | |
1894 ;; jdb puts out a string of the following form when it | |
1895 ;; hits a breakpoint: | |
1896 ;; | |
1897 ;; <fully-qualified-class><method> (<class>:<line-number>) | |
1898 ;; | |
1899 ;; <fully-qualified-class>'s are composed of Java ID's | |
1900 ;; separated by periods. <method> and <class> are | |
1901 ;; also Java ID's. <method> begins with a period and | |
1902 ;; may contain less-than and greater-than (constructors, | |
1903 ;; for instance, are called <init> in the symbol table.) | |
1904 ;; Java ID's begin with a letter followed by letters | |
1905 ;; and/or digits. The set of letters includes underscore | |
1906 ;; and dollar sign. | |
1907 ;; | |
1908 ;; The first group matches <fully-qualified-class>, | |
1909 ;; the second group matches <class> and the third group | |
1910 ;; matches <line-number>. We don't care about using | |
1911 ;; <method> so we don't "group" it. | |
1912 ;; | |
1913 ;; FIXME: Java ID's are UNICODE strings, this matches ASCII | |
1914 ;; ID's only. | |
1915 ;; | |
1916 ;; The "," in the last square-bracket is necessary because of | |
1917 ;; Sun's total disrespect for backwards compatibility in | |
1918 ;; reported line numbers from jdb - starting in 1.4.0 they | |
1919 ;; introduced a comma at the thousands position (how | |
1920 ;; ingenious!) | |
1921 | |
1922 "\\(\[[0-9]+\] \\)*\\([a-zA-Z0-9.$_]+\\)\\.[a-zA-Z0-9$_<>(),]+ \ | |
1923 \\(([a-zA-Z0-9.$_]+:\\|line=\\)\\([0-9,]+\\)" | |
1924 gud-marker-acc) | |
1925 | |
1926 ;; A good marker is one that: | |
1927 ;; 1) does not have a "[n] " prefix (not part of a stack backtrace) | |
1928 ;; 2) does have an "[n] " prefix and n is the lowest prefix seen | |
1929 ;; since the last prompt | |
1930 ;; Figure out the line on which to position the debugging arrow. | |
1931 ;; Return the info as a cons of the form: | |
1932 ;; | |
1933 ;; (<file-name> . <line-number>) . | |
1934 (if (if (match-beginning 1) | |
1935 (let (n) | |
1936 (setq n (string-to-int (substring | |
1937 gud-marker-acc | |
1938 (1+ (match-beginning 1)) | |
1939 (- (match-end 1) 2)))) | |
1940 (if (< n gud-jdb-lowest-stack-level) | |
1941 (progn (setq gud-jdb-lowest-stack-level n) t))) | |
1942 t) | |
1943 (if (setq file-found | |
1944 (gud-jdb-find-source (match-string 2 gud-marker-acc))) | |
1945 (setq gud-last-frame | |
1946 (cons file-found | |
1947 (string-to-int | |
1948 (let | |
1949 ((numstr (match-string 4 gud-marker-acc))) | |
1950 (if (string-match "," numstr) | |
1951 (replace-match "" nil nil numstr) | |
1952 numstr))))) | |
1953 (message "Could not find source file."))) | |
1954 | |
1955 ;; Set the accumulator to the remaining text. | |
1956 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))) | |
1957 | |
1958 (if (string-match comint-prompt-regexp gud-marker-acc) | |
1959 (setq gud-jdb-lowest-stack-level 999))) | |
1960 | |
1961 ;; Do not allow gud-marker-acc to grow without bound. If the source | |
1962 ;; file information is not within the last 3/4 | |
1963 ;; gud-marker-acc-max-length characters, well,... | |
1964 (if (> (length gud-marker-acc) gud-marker-acc-max-length) | |
1965 (setq gud-marker-acc | |
1966 (substring gud-marker-acc | |
1967 (- (/ (* gud-marker-acc-max-length 3) 4))))) | |
1968 | |
1969 ;; We don't filter any debugger output so just return what we were given. | |
1970 string) | |
1971 | |
1972 (defvar gud-jdb-command-name "jdb" "Command that executes the Java debugger.") | |
1973 | |
1974 ;;;###autoload | |
1975 (defun jdb (command-line) | |
1976 "Run jdb with command line COMMAND-LINE in a buffer. | |
1977 The buffer is named \"*gud*\" if no initial class is given or | |
1978 \"*gud-<initial-class-basename>*\" if there is. If the \"-classpath\" | |
1979 switch is given, omit all whitespace between it and its value. | |
1980 | |
1981 See `gud-jdb-use-classpath' and `gud-jdb-classpath' documentation for | |
1982 information on how jdb accesses source files. Alternatively (if | |
1983 `gud-jdb-use-classpath' is nil), see `gud-jdb-directories' for the | |
1984 original source file access method. | |
1985 | |
1986 For general information about commands available to control jdb from | |
1987 gud, see `gud-mode'." | |
1988 (interactive | |
1989 (list (gud-query-cmdline 'jdb))) | |
1990 (setq gud-jdb-classpath nil) | |
1991 (setq gud-jdb-sourcepath nil) | |
1992 | |
1993 ;; Set gud-jdb-classpath from the CLASSPATH environment variable, | |
1994 ;; if CLASSPATH is set. | |
1995 (setq gud-jdb-classpath-string (getenv "CLASSPATH")) | |
1996 (if gud-jdb-classpath-string | |
1997 (setq gud-jdb-classpath | |
1998 (gud-jdb-parse-classpath-string gud-jdb-classpath-string))) | |
1999 (setq gud-jdb-classpath-string nil) ; prepare for next | |
2000 | |
2001 (gud-common-init command-line 'gud-jdb-massage-args | |
2002 'gud-jdb-marker-filter) | |
2003 (set (make-local-variable 'gud-minor-mode) 'jdb) | |
2004 | |
2005 ;; If a -classpath option was provided, set gud-jdb-classpath | |
2006 (if gud-jdb-classpath-string | |
2007 (setq gud-jdb-classpath | |
2008 (gud-jdb-parse-classpath-string gud-jdb-classpath-string))) | |
2009 (setq gud-jdb-classpath-string nil) ; prepare for next | |
2010 ;; If a -sourcepath option was provided, parse it | |
2011 (if gud-jdb-sourcepath | |
2012 (setq gud-jdb-sourcepath | |
2013 (gud-jdb-parse-classpath-string gud-jdb-sourcepath))) | |
2014 | |
2015 (gud-def gud-break "stop at %c:%l" "\C-b" "Set breakpoint at current line.") | |
2016 (gud-def gud-remove "clear %c:%l" "\C-d" "Remove breakpoint at current line") | |
2017 (gud-def gud-step "step" "\C-s" "Step one source line with display.") | |
2018 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).") | |
2019 (gud-def gud-cont "cont" "\C-r" "Continue with display.") | |
2020 (gud-def gud-finish "step up" "\C-f" "Continue until current method returns.") | |
2021 (gud-def gud-up "up\C-Mwhere" "<" "Up one stack frame.") | |
2022 (gud-def gud-down "down\C-Mwhere" ">" "Up one stack frame.") | |
2023 (gud-def gud-run "run" nil "Run the program.") ;if VM start using jdb | |
2024 | |
2025 (setq comint-prompt-regexp "^> \\|^[^ ]+\\[[0-9]+\\] ") | |
2026 (setq paragraph-start comint-prompt-regexp) | |
2027 (run-hooks 'jdb-mode-hook) | |
2028 | |
2029 (if gud-jdb-use-classpath | |
2030 ;; Get the classpath information from the debugger | |
2031 (progn | |
2032 (if (string-match "-attach" command-line) | |
2033 (gud-call "classpath")) | |
2034 (fset 'gud-jdb-find-source | |
2035 'gud-jdb-find-source-using-classpath)) | |
2036 | |
2037 ;; Else create and bind the class/source association list as well | |
2038 ;; as the source file list. | |
2039 (setq gud-jdb-class-source-alist | |
2040 (gud-jdb-build-class-source-alist | |
2041 (setq gud-jdb-source-files | |
2042 (gud-jdb-build-source-files-list gud-jdb-directories | |
2043 "\\.java$")))) | |
2044 (fset 'gud-jdb-find-source 'gud-jdb-find-source-file))) | |
2045 | |
2046 | |
2047 ;; ====================================================================== | |
2048 ;; | |
2049 ;; BASHDB support. See http://bashdb.sourceforge.net | |
2050 ;; | |
2051 ;; AUTHOR: Rocky Bernstein <rocky@panix.com> | |
2052 ;; | |
2053 ;; CREATED: Sun Nov 10 10:46:38 2002 Rocky Bernstein. | |
2054 ;; | |
2055 ;; INVOCATION NOTES: | |
2056 ;; | |
2057 ;; You invoke bashdb-mode with: | |
2058 ;; | |
2059 ;; M-x bashdb <enter> | |
2060 ;; | |
2061 ;; It responds with: | |
2062 ;; | |
2063 ;; Run bashdb (like this): bash | |
2064 ;; | |
2065 | |
2066 ;; History of argument lists passed to bashdb. | |
2067 (defvar gud-bashdb-history nil) | |
2068 | |
2069 ;; Convert a command line as would be typed normally to run a script | |
2070 ;; into one that invokes an Emacs-enabled debugging session. | |
2071 ;; "--debugger" in inserted as the first switch. | |
2072 | |
2073 ;; There's no guarantee that Emacs will hand the filter the entire | |
2074 ;; marker at once; it could be broken up across several strings. We | |
2075 ;; might even receive a big chunk with several markers in it. If we | |
2076 ;; receive a chunk of text which looks like it might contain the | |
2077 ;; beginning of a marker, we save it here between calls to the | |
2078 ;; filter. | |
2079 (defun gud-bashdb-marker-filter (string) | |
2080 (setq gud-marker-acc (concat gud-marker-acc string)) | |
2081 (let ((output "")) | |
2082 | |
2083 ;; Process all the complete markers in this chunk. | |
2084 ;; Format of line looks like this: | |
2085 ;; (/etc/init.d/ntp.init:16): | |
2086 ;; but we also allow DOS drive letters | |
2087 ;; (d:/etc/init.d/ntp.init:16): | |
2088 (while (string-match "\\(^\\|\n\\)(\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\)):.*\n" | |
2089 gud-marker-acc) | |
2090 (setq | |
2091 | |
2092 ;; Extract the frame position from the marker. | |
2093 gud-last-frame | |
2094 (cons (match-string 2 gud-marker-acc) | |
2095 (string-to-int (match-string 4 gud-marker-acc))) | |
2096 | |
2097 ;; Append any text before the marker to the output we're going | |
2098 ;; to return - we don't include the marker in this text. | |
2099 output (concat output | |
2100 (substring gud-marker-acc 0 (match-beginning 0))) | |
2101 | |
2102 ;; Set the accumulator to the remaining text. | |
2103 gud-marker-acc (substring gud-marker-acc (match-end 0)))) | |
2104 | |
2105 ;; Does the remaining text look like it might end with the | |
2106 ;; beginning of another marker? If it does, then keep it in | |
2107 ;; gud-marker-acc until we receive the rest of it. Since we | |
2108 ;; know the full marker regexp above failed, it's pretty simple to | |
2109 ;; test for marker starts. | |
2110 (if (string-match "\032.*\\'" gud-marker-acc) | |
2111 (progn | |
2112 ;; Everything before the potential marker start can be output. | |
2113 (setq output (concat output (substring gud-marker-acc | |
2114 0 (match-beginning 0)))) | |
2115 | |
2116 ;; Everything after, we save, to combine with later input. | |
2117 (setq gud-marker-acc | |
2118 (substring gud-marker-acc (match-beginning 0)))) | |
2119 | |
2120 (setq output (concat output gud-marker-acc) | |
2121 gud-marker-acc "")) | |
2122 | |
2123 output)) | |
2124 | |
2125 (defcustom gud-bashdb-command-name "bash --debugger" | |
2126 "File name for executing bash debugger." | |
2127 :type 'string | |
2128 :group 'gud) | |
2129 | |
2130 ;;;###autoload | |
2131 (defun bashdb (command-line) | |
2132 "Run bashdb on program FILE in buffer *gud-FILE*. | |
2133 The directory containing FILE becomes the initial working directory | |
2134 and source-file directory for your debugger." | |
2135 (interactive | |
2136 (list (read-from-minibuffer "Run bashdb (like this): " | |
2137 (if (consp gud-bashdb-history) | |
2138 (car gud-bashdb-history) | |
2139 (concat gud-bashdb-command-name | |
2140 " ")) | |
2141 gud-minibuffer-local-map nil | |
2142 '(gud-bashdb-history . 1)))) | |
2143 | |
2144 (gud-common-init command-line nil 'gud-bashdb-marker-filter) | |
2145 | |
2146 (set (make-local-variable 'gud-minor-mode) 'bashdb) | |
2147 | |
2148 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.") | |
2149 (gud-def gud-tbreak "tbreak %l" "\C-t" "Set temporary breakpoint at current line.") | |
2150 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") | |
2151 (gud-def gud-step "step" "\C-s" "Step one source line with display.") | |
2152 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).") | |
2153 (gud-def gud-cont "continue" "\C-r" "Continue with display.") | |
2154 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.") | |
2155 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") | |
2156 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") | |
2157 (gud-def gud-print "x %e" "\C-p" "Evaluate BASH expression at point.") | |
2158 | |
2159 ;; Is this right? | |
2160 (gud-def gud-statement "eval %e" "\C-e" "Execute BASH statement at point.") | |
2161 | |
2162 (setq comint-prompt-regexp "^bashdb<+(*[0-9]+)*>+ ") | |
2163 (setq paragraph-start comint-prompt-regexp) | |
2164 (run-hooks 'bashdb-mode-hook) | |
2165 ) | |
2166 | |
2167 ;; | |
2168 ;; End of debugger-specific information | |
2169 ;; | |
2170 | |
2171 | |
2172 ;; When we send a command to the debugger via gud-call, it's annoying | |
2173 ;; to see the command and the new prompt inserted into the debugger's | |
2174 ;; buffer; we have other ways of knowing the command has completed. | |
2175 ;; | |
2176 ;; If the buffer looks like this: | |
2177 ;; -------------------- | |
2178 ;; (gdb) set args foo bar | |
2179 ;; (gdb) -!- | |
2180 ;; -------------------- | |
2181 ;; (the -!- marks the location of point), and we type `C-x SPC' in a | |
2182 ;; source file to set a breakpoint, we want the buffer to end up like | |
2183 ;; this: | |
2184 ;; -------------------- | |
2185 ;; (gdb) set args foo bar | |
2186 ;; Breakpoint 1 at 0x92: file make-docfile.c, line 49. | |
2187 ;; (gdb) -!- | |
2188 ;; -------------------- | |
2189 ;; Essentially, the old prompt is deleted, and the command's output | |
2190 ;; and the new prompt take its place. | |
2191 ;; | |
2192 ;; Not echoing the command is easy enough; you send it directly using | |
2193 ;; process-send-string, and it never enters the buffer. However, | |
2194 ;; getting rid of the old prompt is trickier; you don't want to do it | |
2195 ;; when you send the command, since that will result in an annoying | |
2196 ;; flicker as the prompt is deleted, redisplay occurs while Emacs | |
2197 ;; waits for a response from the debugger, and the new prompt is | |
2198 ;; inserted. Instead, we'll wait until we actually get some output | |
2199 ;; from the subprocess before we delete the prompt. If the command | |
2200 ;; produced no output other than a new prompt, that prompt will most | |
2201 ;; likely be in the first chunk of output received, so we will delete | |
2202 ;; the prompt and then replace it with an identical one. If the | |
2203 ;; command produces output, the prompt is moving anyway, so the | |
2204 ;; flicker won't be annoying. | |
2205 ;; | |
2206 ;; So - when we want to delete the prompt upon receipt of the next | |
2207 ;; chunk of debugger output, we position gud-delete-prompt-marker at | |
2208 ;; the start of the prompt; the process filter will notice this, and | |
2209 ;; delete all text between it and the process output marker. If | |
2210 ;; gud-delete-prompt-marker points nowhere, we leave the current | |
2211 ;; prompt alone. | |
2212 (defvar gud-delete-prompt-marker nil) | |
2213 | |
2214 | |
2215 (put 'gud-mode 'mode-class 'special) | |
2216 | |
2217 (define-derived-mode gud-mode comint-mode "Debugger" | |
2218 "Major mode for interacting with an inferior debugger process. | |
2219 | |
2220 You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx, | |
2221 M-x perldb, M-x xdb, or M-x jdb. Each entry point finishes by executing a | |
2222 hook; `gdb-mode-hook', `sdb-mode-hook', `dbx-mode-hook', | |
2223 `perldb-mode-hook', `xdb-mode-hook', or `jdb-mode-hook' respectively. | |
2224 | |
2225 After startup, the following commands are available in both the GUD | |
2226 interaction buffer and any source buffer GUD visits due to a breakpoint stop | |
2227 or step operation: | |
2228 | |
2229 \\[gud-break] sets a breakpoint at the current file and line. In the | |
2230 GUD buffer, the current file and line are those of the last breakpoint or | |
2231 step. In a source buffer, they are the buffer's file and current line. | |
2232 | |
2233 \\[gud-remove] removes breakpoints on the current file and line. | |
2234 | |
2235 \\[gud-refresh] displays in the source window the last line referred to | |
2236 in the gud buffer. | |
2237 | |
2238 \\[gud-step], \\[gud-next], and \\[gud-stepi] do a step-one-line, | |
2239 step-one-line (not entering function calls), and step-one-instruction | |
2240 and then update the source window with the current file and position. | |
2241 \\[gud-cont] continues execution. | |
2242 | |
2243 \\[gud-print] tries to find the largest C lvalue or function-call expression | |
2244 around point, and sends it to the debugger for value display. | |
2245 | |
2246 The above commands are common to all supported debuggers except xdb which | |
2247 does not support stepping instructions. | |
2248 | |
2249 Under gdb, sdb and xdb, \\[gud-tbreak] behaves exactly like \\[gud-break], | |
2250 except that the breakpoint is temporary; that is, it is removed when | |
2251 execution stops on it. | |
2252 | |
2253 Under gdb, dbx, and xdb, \\[gud-up] pops up through an enclosing stack | |
2254 frame. \\[gud-down] drops back down through one. | |
2255 | |
2256 If you are using gdb or xdb, \\[gud-finish] runs execution to the return from | |
2257 the current function and stops. | |
2258 | |
2259 All the keystrokes above are accessible in the GUD buffer | |
2260 with the prefix C-c, and in all buffers through the prefix C-x C-a. | |
2261 | |
2262 All pre-defined functions for which the concept make sense repeat | |
2263 themselves the appropriate number of times if you give a prefix | |
2264 argument. | |
2265 | |
2266 You may use the `gud-def' macro in the initialization hook to define other | |
2267 commands. | |
2268 | |
2269 Other commands for interacting with the debugger process are inherited from | |
2270 comint mode, which see." | |
2271 (setq mode-line-process '(":%s")) | |
2272 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh) | |
2273 (set (make-local-variable 'gud-last-frame) nil) | |
2274 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
2275 (make-local-variable 'comint-prompt-regexp) | |
2276 ;; Don't put repeated commands in command history many times. | |
2277 (set (make-local-variable 'comint-input-ignoredups) t) | |
2278 (make-local-variable 'paragraph-start) | |
2279 (set (make-local-variable 'gud-delete-prompt-marker) (make-marker))) | |
2280 | |
2281 ;; Cause our buffers to be displayed, by default, | |
2282 ;; in the selected window. | |
2283 ;;;###autoload (add-hook 'same-window-regexps "\\*gud-.*\\*\\(\\|<[0-9]+>\\)") | |
2284 | |
2285 (defcustom gud-chdir-before-run t | |
2286 "Non-nil if GUD should `cd' to the debugged executable." | |
2287 :group 'gud | |
2288 :type 'boolean) | |
2289 | |
2290 (defvar gud-target-name "--unknown--" | |
2291 "The apparent name of the program being debugged in a gud buffer.") | |
2292 | |
2293 ;; Perform initializations common to all debuggers. | |
2294 ;; The first arg is the specified command line, | |
2295 ;; which starts with the program to debug. | |
2296 ;; The other three args specify the values to use | |
2297 ;; for local variables in the debugger buffer. | |
2298 (defun gud-common-init (command-line massage-args marker-filter | |
2299 &optional find-file) | |
2300 (let* ((words (split-string command-line)) | |
2301 (program (car words)) | |
2302 (dir default-directory) | |
2303 ;; Extract the file name from WORDS | |
2304 ;; and put t in its place. | |
2305 ;; Later on we will put the modified file name arg back there. | |
2306 (file-word (let ((w (cdr words))) | |
2307 (while (and w (= ?- (aref (car w) 0))) | |
2308 (setq w (cdr w))) | |
2309 (and w | |
2310 (prog1 (car w) | |
2311 (setcar w t))))) | |
2312 (file-subst | |
2313 (and file-word (substitute-in-file-name file-word))) | |
2314 (args (cdr words)) | |
2315 ;; If a directory was specified, expand the file name. | |
2316 ;; Otherwise, don't expand it, so GDB can use the PATH. | |
2317 ;; A file name without directory is literally valid | |
2318 ;; only if the file exists in ., and in that case, | |
2319 ;; omitting the expansion here has no visible effect. | |
2320 (file (and file-word | |
2321 (if (file-name-directory file-subst) | |
2322 (expand-file-name file-subst) | |
2323 file-subst))) | |
2324 (filepart (and file-word (concat "-" (file-name-nondirectory file))))) | |
2325 (pop-to-buffer (concat "*gud" filepart "*")) | |
2326 ;; Set the dir, in case the buffer already existed with a different dir. | |
2327 (setq default-directory dir) | |
2328 ;; Set default-directory to the file's directory. | |
2329 (and file-word | |
2330 gud-chdir-before-run | |
2331 ;; Don't set default-directory if no directory was specified. | |
2332 ;; In that case, either the file is found in the current directory, | |
2333 ;; in which case this setq is a no-op, | |
2334 ;; or it is found by searching PATH, | |
2335 ;; in which case we don't know what directory it was found in. | |
2336 (file-name-directory file) | |
2337 (setq default-directory (file-name-directory file))) | |
2338 (or (bolp) (newline)) | |
2339 (insert "Current directory is " default-directory "\n") | |
2340 ;; Put the substituted and expanded file name back in its place. | |
2341 (let ((w args)) | |
2342 (while (and w (not (eq (car w) t))) | |
2343 (setq w (cdr w))) | |
2344 (if w | |
2345 (setcar w file))) | |
2346 (apply 'make-comint (concat "gud" filepart) program nil | |
2347 (if massage-args (funcall massage-args file args) args)) | |
2348 ;; Since comint clobbered the mode, we don't set it until now. | |
2349 (gud-mode) | |
2350 (set (make-local-variable 'gud-target-name) | |
2351 (and file-word (file-name-nondirectory file)))) | |
2352 (set (make-local-variable 'gud-marker-filter) marker-filter) | |
2353 (if find-file (set (make-local-variable 'gud-find-file) find-file)) | |
2354 (setq gud-running nil) | |
2355 (setq gud-last-last-frame nil) | |
2356 | |
2357 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter) | |
2358 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel) | |
2359 (gud-set-buffer)) | |
2360 | |
2361 (defun gud-set-buffer () | |
2362 (when (eq major-mode 'gud-mode) | |
2363 (setq gud-comint-buffer (current-buffer)))) | |
2364 | |
2365 (defvar gud-filter-defer-flag nil | |
2366 "Non-nil means don't process anything from the debugger right now. | |
2367 It is saved for when this flag is not set.") | |
2368 | |
2369 (defvar gud-filter-pending-text nil | |
2370 "Non-nil means this is text that has been saved for later in `gud-filter'.") | |
2371 | |
2372 ;; These functions are responsible for inserting output from your debugger | |
2373 ;; into the buffer. The hard work is done by the method that is | |
2374 ;; the value of gud-marker-filter. | |
2375 | |
2376 (defun gud-filter (proc string) | |
2377 ;; Here's where the actual buffer insertion is done | |
2378 (let (output process-window) | |
2379 (if (buffer-name (process-buffer proc)) | |
2380 (if gud-filter-defer-flag | |
2381 ;; If we can't process any text now, | |
2382 ;; save it for later. | |
2383 (setq gud-filter-pending-text | |
2384 (concat (or gud-filter-pending-text "") string)) | |
2385 | |
2386 ;; If we have to ask a question during the processing, | |
2387 ;; defer any additional text that comes from the debugger | |
2388 ;; during that time. | |
2389 (let ((gud-filter-defer-flag t)) | |
2390 ;; Process now any text we previously saved up. | |
2391 (if gud-filter-pending-text | |
2392 (setq string (concat gud-filter-pending-text string) | |
2393 gud-filter-pending-text nil)) | |
2394 | |
2395 (with-current-buffer (process-buffer proc) | |
2396 ;; If we have been so requested, delete the debugger prompt. | |
2397 (save-restriction | |
2398 (widen) | |
2399 (if (marker-buffer gud-delete-prompt-marker) | |
2400 (progn | |
2401 (delete-region (process-mark proc) | |
2402 gud-delete-prompt-marker) | |
2403 (set-marker gud-delete-prompt-marker nil))) | |
2404 ;; Save the process output, checking for source file markers. | |
2405 (setq output (gud-marker-filter string)) | |
2406 ;; Check for a filename-and-line number. | |
2407 ;; Don't display the specified file | |
2408 ;; unless (1) point is at or after the position where output appears | |
2409 ;; and (2) this buffer is on the screen. | |
2410 (setq process-window | |
2411 (and gud-last-frame | |
2412 (>= (point) (process-mark proc)) | |
2413 (get-buffer-window (current-buffer))))) | |
2414 | |
2415 ;; Let the comint filter do the actual insertion. | |
2416 ;; That lets us inherit various comint features. | |
2417 (comint-output-filter proc output)) | |
2418 | |
2419 ;; Put the arrow on the source line. | |
2420 ;; This must be outside of the save-excursion | |
2421 ;; in case the source file is our current buffer. | |
2422 (if process-window | |
2423 (save-selected-window | |
2424 (select-window process-window) | |
2425 (gud-display-frame)) | |
2426 ;; We have to be in the proper buffer, (process-buffer proc), | |
2427 ;; but not in a save-excursion, because that would restore point. | |
2428 (let ((old-buf (current-buffer))) | |
2429 (set-buffer (process-buffer proc)) | |
2430 (unwind-protect | |
2431 (gud-display-frame) | |
2432 (set-buffer old-buf))))) | |
2433 | |
2434 ;; If we deferred text that arrived during this processing, | |
2435 ;; handle it now. | |
2436 (if gud-filter-pending-text | |
2437 (gud-filter proc "")))))) | |
2438 | |
2439 (defvar gud-minor-mode-type nil) | |
2440 | |
2441 (defun gud-sentinel (proc msg) | |
2442 (cond ((null (buffer-name (process-buffer proc))) | |
2443 ;; buffer killed | |
2444 ;; Stop displaying an arrow in a source file. | |
2445 (setq overlay-arrow-position nil) | |
2446 (set-process-buffer proc nil) | |
2447 (if (eq gud-minor-mode-type 'gdba) | |
2448 (gdb-reset) | |
2449 (gud-reset))) | |
2450 ((memq (process-status proc) '(signal exit)) | |
2451 ;; Stop displaying an arrow in a source file. | |
2452 (setq overlay-arrow-position nil) | |
2453 (with-current-buffer gud-comint-buffer | |
2454 (if (eq gud-minor-mode 'gdba) | |
2455 (gdb-reset) | |
2456 (gud-reset))) | |
2457 (let* ((obuf (current-buffer))) | |
2458 ;; save-excursion isn't the right thing if | |
2459 ;; process-buffer is current-buffer | |
2460 (unwind-protect | |
2461 (progn | |
2462 ;; Write something in *compilation* and hack its mode line, | |
2463 (set-buffer (process-buffer proc)) | |
2464 ;; Fix the mode line. | |
2465 (setq mode-line-process | |
2466 (concat ":" | |
2467 (symbol-name (process-status proc)))) | |
2468 (force-mode-line-update) | |
2469 (if (eobp) | |
2470 (insert ?\n mode-name " " msg) | |
2471 (save-excursion | |
2472 (goto-char (point-max)) | |
2473 (insert ?\n mode-name " " msg))) | |
2474 ;; If buffer and mode line will show that the process | |
2475 ;; is dead, we can delete it now. Otherwise it | |
2476 ;; will stay around until M-x list-processes. | |
2477 (delete-process proc)) | |
2478 ;; Restore old buffer, but don't restore old point | |
2479 ;; if obuf is the gud buffer. | |
2480 (set-buffer obuf)))))) | |
2481 | |
2482 (defun gud-kill-buffer-hook () | |
2483 (if gud-minor-mode | |
2484 (setq gud-minor-mode-type gud-minor-mode))) | |
2485 | |
2486 (add-hook 'kill-buffer-hook 'gud-kill-buffer-hook) | |
2487 | |
2488 (defun gud-reset () | |
2489 (dolist (buffer (buffer-list)) | |
2490 (if (not (eq buffer gud-comint-buffer)) | |
2491 (save-excursion | |
2492 (set-buffer buffer) | |
2493 (when gud-minor-mode | |
2494 (setq gud-minor-mode nil) | |
2495 (kill-local-variable 'tool-bar-map)))))) | |
2496 | |
2497 (defun gud-display-frame () | |
2498 "Find and obey the last filename-and-line marker from the debugger. | |
2499 Obeying it means displaying in another window the specified file and line." | |
2500 (interactive) | |
2501 (when gud-last-frame | |
2502 (gud-set-buffer) | |
2503 (gud-display-line (car gud-last-frame) (cdr gud-last-frame)) | |
2504 (setq gud-last-last-frame gud-last-frame | |
2505 gud-last-frame nil))) | |
2506 | |
2507 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen | |
2508 ;; and that its line LINE is visible. | |
2509 ;; Put the overlay-arrow on the line LINE in that buffer. | |
2510 ;; Most of the trickiness in here comes from wanting to preserve the current | |
2511 ;; region-restriction if that's possible. We use an explicit display-buffer | |
2512 ;; to get around the fact that this is called inside a save-excursion. | |
2513 | |
2514 (defun gud-display-line (true-file line) | |
2515 (let* ((last-nonmenu-event t) ; Prevent use of dialog box for questions. | |
2516 (buffer | |
2517 (with-current-buffer gud-comint-buffer | |
2518 (gud-find-file true-file))) | |
2519 (window (and buffer (or (get-buffer-window buffer) | |
2520 (if (eq gud-minor-mode 'gdba) | |
2521 (gdb-display-source-buffer buffer) | |
2522 (display-buffer buffer))))) | |
2523 (pos)) | |
2524 (if buffer | |
2525 (progn | |
2526 (with-current-buffer buffer | |
88123 | 2527 (if (not (or (verify-visited-file-modtime buffer) gud-keep-buffer)) |
2528 (progn | |
2529 (if | |
2530 (yes-or-no-p | |
51494 | 2531 (format "File %s changed on disk. Reread from disk? " |
2532 (buffer-name))) | |
2533 (revert-buffer t t) | |
88123 | 2534 (setq gud-keep-buffer t)))) |
51494 | 2535 (save-restriction |
2536 (widen) | |
2537 (goto-line line) | |
2538 (setq pos (point)) | |
2539 (setq overlay-arrow-string "=>") | |
2540 (or overlay-arrow-position | |
88123 | 2541 (setq overlay-arrow-position (make-marker))) |
51494 | 2542 (set-marker overlay-arrow-position (point) (current-buffer))) |
2543 (cond ((or (< pos (point-min)) (> pos (point-max))) | |
88123 | 2544 (widen) |
2545 (goto-char pos)))) | |
2546 (set-window-point window overlay-arrow-position))))) | |
51494 | 2547 |
2548 ;; The gud-call function must do the right thing whether its invoking | |
2549 ;; keystroke is from the GUD buffer itself (via major-mode binding) | |
2550 ;; or a C buffer. In the former case, we want to supply data from | |
2551 ;; gud-last-frame. Here's how we do it: | |
2552 | |
2553 (defun gud-format-command (str arg) | |
2554 (let ((insource (not (eq (current-buffer) gud-comint-buffer))) | |
2555 (frame (or gud-last-frame gud-last-last-frame)) | |
2556 result) | |
2557 (while (and str (string-match "\\([^%]*\\)%\\([adeflpc]\\)" str)) | |
2558 (let ((key (string-to-char (match-string 2 str))) | |
2559 subst) | |
2560 (cond | |
2561 ((eq key ?f) | |
2562 (setq subst (file-name-nondirectory (if insource | |
2563 (buffer-file-name) | |
2564 (car frame))))) | |
2565 ((eq key ?F) | |
2566 (setq subst (file-name-sans-extension | |
2567 (file-name-nondirectory (if insource | |
2568 (buffer-file-name) | |
2569 (car frame)))))) | |
2570 ((eq key ?d) | |
2571 (setq subst (file-name-directory (if insource | |
2572 (buffer-file-name) | |
2573 (car frame))))) | |
2574 ((eq key ?l) | |
2575 (setq subst (int-to-string | |
2576 (if insource | |
2577 (save-restriction | |
2578 (widen) | |
2579 (+ (count-lines (point-min) (point)) | |
2580 (if (bolp) 1 0))) | |
2581 (cdr frame))))) | |
2582 ((eq key ?e) | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2583 (setq subst (gud-find-expr))) |
51494 | 2584 ((eq key ?a) |
2585 (setq subst (gud-read-address))) | |
2586 ((eq key ?c) | |
2587 (setq subst | |
2588 (gud-find-class | |
2589 (if insource | |
2590 (buffer-file-name) | |
2591 (car frame)) | |
2592 (if insource | |
2593 (save-restriction | |
2594 (widen) | |
2595 (+ (count-lines (point-min) (point)) | |
2596 (if (bolp) 1 0))) | |
2597 (cdr frame))))) | |
2598 ((eq key ?p) | |
2599 (setq subst (if arg (int-to-string arg))))) | |
2600 (setq result (concat result (match-string 1 str) subst))) | |
2601 (setq str (substring str (match-end 2)))) | |
2602 ;; There might be text left in STR when the loop ends. | |
2603 (concat result str))) | |
2604 | |
2605 (defun gud-read-address () | |
2606 "Return a string containing the core-address found in the buffer at point." | |
2607 (save-match-data | |
2608 (save-excursion | |
2609 (let ((pt (point)) found begin) | |
2610 (setq found (if (search-backward "0x" (- pt 7) t) (point))) | |
2611 (cond | |
2612 (found (forward-char 2) | |
2613 (buffer-substring found | |
2614 (progn (re-search-forward "[^0-9a-f]") | |
2615 (forward-char -1) | |
2616 (point)))) | |
2617 (t (setq begin (progn (re-search-backward "[^0-9]") | |
2618 (forward-char 1) | |
2619 (point))) | |
2620 (forward-char 1) | |
2621 (re-search-forward "[^0-9]") | |
2622 (forward-char -1) | |
2623 (buffer-substring begin (point)))))))) | |
2624 | |
2625 (defun gud-call (fmt &optional arg) | |
2626 (let ((msg (gud-format-command fmt arg))) | |
2627 (message "Command: %s" msg) | |
2628 (sit-for 0) | |
2629 (gud-basic-call msg))) | |
2630 | |
2631 (defun gud-basic-call (command) | |
2632 "Invoke the debugger COMMAND displaying source in other window." | |
2633 (interactive) | |
2634 (gud-set-buffer) | |
2635 (let ((proc (get-buffer-process gud-comint-buffer))) | |
2636 (or proc (error "Current buffer has no process")) | |
2637 ;; Arrange for the current prompt to get deleted. | |
2638 (save-excursion | |
2639 (set-buffer gud-comint-buffer) | |
2640 (save-restriction | |
2641 (widen) | |
2642 (goto-char (process-mark proc)) | |
2643 (forward-line 0) | |
2644 (if (looking-at comint-prompt-regexp) | |
2645 (set-marker gud-delete-prompt-marker (point))) | |
2646 (if (eq gud-minor-mode 'gdba) | |
2647 (apply comint-input-sender (list proc command)) | |
2648 (process-send-string proc (concat command "\n"))))))) | |
2649 | |
2650 (defun gud-refresh (&optional arg) | |
2651 "Fix up a possibly garbled display, and redraw the arrow." | |
2652 (interactive "P") | |
2653 (or gud-last-frame (setq gud-last-frame gud-last-last-frame)) | |
2654 (gud-display-frame) | |
2655 (recenter arg)) | |
2656 | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2657 ;; Code for parsing expressions out of C or Fortran code. The single entry |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2658 ;; point is gud-find-expr, which tries to return an lvalue expression from |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2659 ;; around point. |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2660 |
51619
16b79b135bf5
(gud-find-expr-function): Rename from gud-find-expr.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51616
diff
changeset
|
2661 (defvar gud-find-expr-function 'gud-find-c-expr) |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2662 |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2663 (defun gud-find-expr (&rest args) |
51619
16b79b135bf5
(gud-find-expr-function): Rename from gud-find-expr.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51616
diff
changeset
|
2664 (apply gud-find-expr-function args)) |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2665 |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2666 ;; The next eight functions are hacked from gdbsrc.el by |
51494 | 2667 ;; Debby Ayers <ayers@asc.slb.com>, |
2668 ;; Rich Schaefer <schaefer@asc.slb.com> Schlumberger, Austin, Tx. | |
2669 | |
2670 (defun gud-find-c-expr () | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2671 "Returns the expr that surrounds point." |
51494 | 2672 (interactive) |
2673 (save-excursion | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2674 (let ((p (point)) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2675 (expr (gud-innermost-expr)) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2676 (test-expr (gud-prev-expr))) |
51494 | 2677 (while (and test-expr (gud-expr-compound test-expr expr)) |
2678 (let ((prev-expr expr)) | |
2679 (setq expr (cons (car test-expr) (cdr expr))) | |
2680 (goto-char (car expr)) | |
2681 (setq test-expr (gud-prev-expr)) | |
2682 ;; If we just pasted on the condition of an if or while, | |
2683 ;; throw it away again. | |
2684 (if (member (buffer-substring (car test-expr) (cdr test-expr)) | |
2685 '("if" "while" "for")) | |
2686 (setq test-expr nil | |
2687 expr prev-expr)))) | |
2688 (goto-char p) | |
2689 (setq test-expr (gud-next-expr)) | |
2690 (while (gud-expr-compound expr test-expr) | |
2691 (setq expr (cons (car expr) (cdr test-expr))) | |
2692 (setq test-expr (gud-next-expr))) | |
2693 (buffer-substring (car expr) (cdr expr))))) | |
2694 | |
2695 (defun gud-innermost-expr () | |
2696 "Returns the smallest expr that point is in; move point to beginning of it. | |
2697 The expr is represented as a cons cell, where the car specifies the point in | |
2698 the current buffer that marks the beginning of the expr and the cdr specifies | |
2699 the character after the end of the expr." | |
2700 (let ((p (point)) begin end) | |
2701 (gud-backward-sexp) | |
2702 (setq begin (point)) | |
2703 (gud-forward-sexp) | |
2704 (setq end (point)) | |
2705 (if (>= p end) | |
2706 (progn | |
2707 (setq begin p) | |
2708 (goto-char p) | |
2709 (gud-forward-sexp) | |
2710 (setq end (point))) | |
2711 ) | |
2712 (goto-char begin) | |
2713 (cons begin end))) | |
2714 | |
2715 (defun gud-backward-sexp () | |
2716 "Version of `backward-sexp' that catches errors." | |
2717 (condition-case nil | |
2718 (backward-sexp) | |
2719 (error t))) | |
2720 | |
2721 (defun gud-forward-sexp () | |
2722 "Version of `forward-sexp' that catches errors." | |
2723 (condition-case nil | |
2724 (forward-sexp) | |
2725 (error t))) | |
2726 | |
2727 (defun gud-prev-expr () | |
2728 "Returns the previous expr, point is set to beginning of that expr. | |
2729 The expr is represented as a cons cell, where the car specifies the point in | |
2730 the current buffer that marks the beginning of the expr and the cdr specifies | |
2731 the character after the end of the expr" | |
2732 (let ((begin) (end)) | |
2733 (gud-backward-sexp) | |
2734 (setq begin (point)) | |
2735 (gud-forward-sexp) | |
2736 (setq end (point)) | |
2737 (goto-char begin) | |
2738 (cons begin end))) | |
2739 | |
2740 (defun gud-next-expr () | |
2741 "Returns the following expr, point is set to beginning of that expr. | |
2742 The expr is represented as a cons cell, where the car specifies the point in | |
2743 the current buffer that marks the beginning of the expr and the cdr specifies | |
2744 the character after the end of the expr." | |
2745 (let ((begin) (end)) | |
2746 (gud-forward-sexp) | |
2747 (gud-forward-sexp) | |
2748 (setq end (point)) | |
2749 (gud-backward-sexp) | |
2750 (setq begin (point)) | |
2751 (cons begin end))) | |
2752 | |
2753 (defun gud-expr-compound-sep (span-start span-end) | |
2754 "Scan from SPAN-START to SPAN-END for punctuation characters. | |
2755 If `->' is found, return `?.'. If `.' is found, return `?.'. | |
2756 If any other punctuation is found, return `??'. | |
2757 If no punctuation is found, return `? '." | |
2758 (let ((result ?\ ) | |
2759 (syntax)) | |
2760 (while (< span-start span-end) | |
2761 (setq syntax (char-syntax (char-after span-start))) | |
2762 (cond | |
2763 ((= syntax ?\ ) t) | |
2764 ((= syntax ?.) (setq syntax (char-after span-start)) | |
2765 (cond | |
2766 ((= syntax ?.) (setq result ?.)) | |
2767 ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>)) | |
2768 (setq result ?.) | |
2769 (setq span-start (+ span-start 1))) | |
2770 (t (setq span-start span-end) | |
2771 (setq result ??))))) | |
2772 (setq span-start (+ span-start 1))) | |
2773 result)) | |
2774 | |
2775 (defun gud-expr-compound (first second) | |
2776 "Non-nil if concatenating FIRST and SECOND makes a single C expression. | |
2777 The two exprs are represented as a cons cells, where the car | |
2778 specifies the point in the current buffer that marks the beginning of the | |
2779 expr and the cdr specifies the character after the end of the expr. | |
2780 Link exprs of the form: | |
2781 Expr -> Expr | |
2782 Expr . Expr | |
2783 Expr (Expr) | |
2784 Expr [Expr] | |
2785 (Expr) Expr | |
2786 [Expr] Expr" | |
2787 (let ((span-start (cdr first)) | |
2788 (span-end (car second)) | |
2789 (syntax)) | |
2790 (setq syntax (gud-expr-compound-sep span-start span-end)) | |
2791 (cond | |
2792 ((= (car first) (car second)) nil) | |
2793 ((= (cdr first) (cdr second)) nil) | |
2794 ((= syntax ?.) t) | |
2795 ((= syntax ?\ ) | |
51616
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2796 (setq span-start (char-after (- span-start 1))) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2797 (setq span-end (char-after span-end)) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2798 (cond |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2799 ((= span-start ?)) t) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2800 ((= span-start ?]) t) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2801 ((= span-end ?() t) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2802 ((= span-end ?[) t) |
25262b54af10
(gud-menu-map): Add dbx support for "run" and
Nick Roberts <nickrob@snap.net.nz>
parents:
51494
diff
changeset
|
2803 (t nil))) |
51494 | 2804 (t nil)))) |
2805 | |
2806 (defun gud-find-class (f line) | |
2807 "Find fully qualified class in file F at line LINE. | |
2808 This function uses the `gud-jdb-classpath' (and optional | |
2809 `gud-jdb-sourcepath') list(s) to derive a file | |
2810 pathname relative to its classpath directory. The values in | |
2811 `gud-jdb-classpath' are assumed to have been converted to absolute | |
2812 pathname standards using file-truename. | |
2813 If F is visited by a buffer and its mode is CC-mode(Java), | |
2814 syntactic information of LINE is used to find the enclosing (nested) | |
2815 class string which is appended to the top level | |
2816 class of the file (using s to separate nested class ids)." | |
2817 ;; Convert f to a standard representation and remove suffix | |
2818 (if (and gud-jdb-use-classpath (or gud-jdb-classpath gud-jdb-sourcepath)) | |
2819 (save-match-data | |
2820 (let ((cplist (append gud-jdb-sourcepath gud-jdb-classpath)) | |
2821 (fbuffer (get-file-buffer f)) | |
2822 class-found) | |
2823 (setq f (file-name-sans-extension (file-truename f))) | |
2824 ;; Search through classpath list for an entry that is | |
2825 ;; contained in f | |
2826 (while (and cplist (not class-found)) | |
2827 (if (string-match (car cplist) f) | |
2828 (setq class-found | |
2829 (mapconcat 'identity | |
2830 (split-string | |
2831 (substring f (+ (match-end 0) 1)) | |
2832 "/") "."))) | |
2833 (setq cplist (cdr cplist))) | |
2834 ;; if f is visited by a java(cc-mode) buffer, walk up the | |
2835 ;; syntactic information chain and collect any 'inclass | |
2836 ;; symbols until 'topmost-intro is reached to find out if | |
2837 ;; point is within a nested class | |
2838 (if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode")) | |
2839 (save-excursion | |
2840 (set-buffer fbuffer) | |
2841 (let ((nclass) (syntax)) | |
2842 ;; While the c-syntactic information does not start | |
2843 ;; with the 'topmost-intro symbol, there may be | |
2844 ;; nested classes... | |
2845 (while (not (eq 'topmost-intro | |
2846 (car (car (c-guess-basic-syntax))))) | |
2847 ;; Check if the current position c-syntactic | |
2848 ;; analysis has 'inclass | |
2849 (setq syntax (c-guess-basic-syntax)) | |
2850 (while | |
2851 (and (not (eq 'inclass (car (car syntax)))) | |
2852 (cdr syntax)) | |
2853 (setq syntax (cdr syntax))) | |
2854 (if (eq 'inclass (car (car syntax))) | |
2855 (progn | |
2856 (goto-char (cdr (car syntax))) | |
2857 ;; Now we're at the beginning of a class | |
2858 ;; definition. Find class name | |
2859 (looking-at | |
2860 "[A-Za-z0-9 \t\n]*?class[ \t\n]+\\([^ \t\n]+\\)") | |
2861 (setq nclass | |
2862 (append (list (match-string-no-properties 1)) | |
2863 nclass))) | |
2864 (setq syntax (c-guess-basic-syntax)) | |
2865 (while (and (not (cdr (car syntax))) (cdr syntax)) | |
2866 (setq syntax (cdr syntax))) | |
2867 (goto-char (cdr (car syntax))) | |
2868 )) | |
2869 (string-match (concat (car nclass) "$") class-found) | |
2870 (setq class-found | |
2871 (replace-match (mapconcat 'identity nclass "$") | |
2872 t t class-found))))) | |
2873 (if (not class-found) | |
2874 (message "gud-find-class: class for file %s not found!" f)) | |
2875 class-found)) | |
2876 ;; Not using classpath - try class/source association list | |
2877 (let ((class-found (rassoc f gud-jdb-class-source-alist))) | |
2878 (if class-found | |
2879 (car class-found) | |
2880 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f) | |
2881 nil)))) | |
2882 | |
2883 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2884 ;;; GDB script mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2885 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2886 | |
2887 (defvar gdb-script-mode-syntax-table | |
2888 (let ((st (make-syntax-table))) | |
2889 (modify-syntax-entry ?' "\"" st) | |
2890 (modify-syntax-entry ?# "<" st) | |
2891 (modify-syntax-entry ?\n ">" st) | |
2892 st)) | |
2893 | |
2894 (defvar gdb-script-font-lock-keywords | |
52058
5d60b6e20fbd
(gdb-script-font-lock-keywords): Put `font-lock-function-name-face'
Masatake YAMATO <jet@gyve.org>
parents:
51619
diff
changeset
|
2895 '(("^define\\s-+\\(\\(\\w\\|\\s_\\)+\\)" (1 font-lock-function-name-face)) |
5d60b6e20fbd
(gdb-script-font-lock-keywords): Put `font-lock-function-name-face'
Masatake YAMATO <jet@gyve.org>
parents:
51619
diff
changeset
|
2896 ("\\$\\(\\w+\\)" (1 font-lock-variable-name-face)) |
51494 | 2897 ("^\\s-*\\([a-z]+\\)" (1 font-lock-keyword-face)))) |
2898 | |
2899 (defvar gdb-script-font-lock-syntactic-keywords | |
2900 '(("^document\\s-.*\\(\n\\)" (1 "< b")) | |
2901 ;; It would be best to change the \n in front, but it's more difficult. | |
2902 ("^en\\(d\\)\\>" (1 "> b")))) | |
2903 | |
2904 (defun gdb-script-font-lock-syntactic-face (state) | |
2905 (cond | |
2906 ((nth 3 state) font-lock-string-face) | |
2907 ((nth 7 state) font-lock-doc-face) | |
2908 (t font-lock-comment-face))) | |
2909 | |
2910 (defvar gdb-script-basic-indent 2) | |
2911 | |
2912 (defun gdb-script-skip-to-head () | |
2913 "We're just in front of an `end' and we need to go to its head." | |
2914 (while (and (re-search-backward "^\\s-*\\(\\(end\\)\\|define\\|document\\|if\\|while\\)\\>" nil 'move) | |
2915 (match-end 2)) | |
2916 (gdb-script-skip-to-head))) | |
2917 | |
2918 (defun gdb-script-calculate-indentation () | |
2919 (cond | |
2920 ((looking-at "end\\>") | |
2921 (gdb-script-skip-to-head) | |
2922 (current-indentation)) | |
2923 ((looking-at "else\\>") | |
2924 (while (and (re-search-backward "^\\s-*\\(if\\|\\(end\\)\\)\\>" nil 'move) | |
2925 (match-end 2)) | |
2926 (gdb-script-skip-to-head)) | |
2927 (current-indentation)) | |
2928 (t | |
2929 (forward-comment (- (point-max))) | |
2930 (forward-line 0) | |
2931 (skip-chars-forward " \t") | |
2932 (+ (current-indentation) | |
2933 (if (looking-at "\\(if\\|while\\|define\\|else\\)\\>") | |
2934 gdb-script-basic-indent 0))))) | |
2935 | |
2936 (defun gdb-script-indent-line () | |
2937 "Indent current line of GDB script." | |
2938 (interactive) | |
2939 (if (and (eq (get-text-property (point) 'face) font-lock-doc-face) | |
2940 (save-excursion | |
2941 (forward-line 0) | |
2942 (skip-chars-forward " \t") | |
2943 (not (looking-at "end\\>")))) | |
2944 'noindent | |
2945 (let* ((savep (point)) | |
2946 (indent (condition-case nil | |
2947 (save-excursion | |
2948 (forward-line 0) | |
2949 (skip-chars-forward " \t") | |
2950 (if (>= (point) savep) (setq savep nil)) | |
2951 (max (gdb-script-calculate-indentation) 0)) | |
2952 (error 0)))) | |
2953 (if savep | |
2954 (save-excursion (indent-line-to indent)) | |
2955 (indent-line-to indent))))) | |
2956 | |
2957 ;;;###autoload | |
2958 (add-to-list 'auto-mode-alist '("/\\.gdbinit" . gdb-script-mode)) | |
2959 | |
2960 ;;;###autoload | |
2961 (define-derived-mode gdb-script-mode nil "GDB-Script" | |
2962 "Major mode for editing GDB scripts" | |
2963 (set (make-local-variable 'comment-start) "#") | |
2964 (set (make-local-variable 'comment-start-skip) "#+\\s-*") | |
2965 (set (make-local-variable 'outline-regexp) "[ \t]") | |
2966 (set (make-local-variable 'imenu-generic-expression) | |
2967 '((nil "^define[ \t]+\\(\\w+\\)" 1))) | |
2968 (set (make-local-variable 'indent-line-function) 'gdb-script-indent-line) | |
2969 (set (make-local-variable 'font-lock-defaults) | |
2970 '(gdb-script-font-lock-keywords nil nil ((?_ . "w")) nil | |
2971 (font-lock-syntactic-keywords | |
2972 . gdb-script-font-lock-syntactic-keywords) | |
2973 (font-lock-syntactic-face-function | |
2974 . gdb-script-font-lock-syntactic-face)))) | |
2975 | |
2976 (provide 'gud) | |
2977 | |
2978 ;;; gud.el ends here |