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