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