Mercurial > emacs
annotate lisp/gud.el @ 1257:e712192d20f5
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Tue, 29 Sep 1992 10:03:50 +0000 |
parents | ff24725192d3 |
children | 4d867d1bedda |
rev | line source |
---|---|
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
1 ;;; gud.el --- Grand Unified Debugger mode for gdb, sdb, or dbx under Emacs |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
2 |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
3 ;; Author: Eric S. Raymond <eric@snark.thyrsus.com> |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
4 ;; Keywords: unix, tools |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
5 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
6 ;; %W% |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
7 |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
8 ;; Copyright (C) 1992 Free Software Foundation, Inc. |
460 | 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 | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
460 | 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 | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
26 ;;; Commentary: |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
27 |
460 | 28 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu> |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
29 ;; It was later rewritten by rms. Some ideas were due to Masanobu. |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
30 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com> |
460 | 31 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>, |
32 ;; who also hacked the mode to use comint.el. | |
33 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
34 ;; Note: use of this package with sdb requires that your tags.el support |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
35 ;; the find-tag-noselect entry point. Stock distributions up to 18.57 do |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
36 ;; *not* include this feature; if it's not included with this file, email |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
37 ;; esr@snark.thyrsus.com for it or get 18.58. |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
38 |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
39 ;; Further note: due to lossage in the Emacs-18 byte compiler, compiled |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
40 ;; versions of this code will fail with a complaint about gud-step if |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
41 ;; you invoke the gdb or sdb initializers. This should be fixed in 19. |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
42 |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
43 ;;; Code: |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
44 |
460 | 45 (require 'comint) |
923 | 46 (require 'etags) |
460 | 47 |
48 ;; ====================================================================== | |
49 ;; the overloading mechanism | |
50 | |
51 (defun gud-overload-functions (gud-overload-alist) | |
52 "Overload functions defined in GUD-OVERLOAD-ALIST. | |
53 This association list has elements of the form | |
54 (ORIGINAL-FUNCTION-NAME OVERLOAD-FUNCTION)" | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
55 (mapcar |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
56 (function (lambda (p) (fset (car p) (symbol-function (cdr p))))) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
57 gud-overload-alist)) |
460 | 58 |
59 (defun gud-debugger-startup (f d) | |
60 (error "GUD not properly entered.")) | |
61 | |
62 (defun gud-marker-filter (proc s) | |
63 (error "GUD not properly entered.")) | |
64 | |
65 (defun gud-visit-file (f) | |
66 (error "GUD not properly entered.")) | |
67 | |
68 (defun gud-set-break (proc f n) | |
69 (error "GUD not properly entered.")) | |
70 | |
71 ;; This macro is used below to define some basic debugger interface commands. | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
72 ;; Of course you may use `gud-def' with any other debugger command, including |
1255 | 73 ;; user defined ones. |
74 | |
75 ;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form | |
76 ;; which defines FUNC to send the command NAME to the debugger, gives | |
77 ;; it the docstring DOC, and binds that function to KEY. NAME should | |
78 ;; be a string. If a numeric prefix argument is given to FUNC, it | |
79 ;; gets sent after NAME. | |
460 | 80 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
81 (defmacro gud-def (func name key &optional doc) |
460 | 82 (let* ((cstr (list 'if '(not (= 1 arg)) |
1255 | 83 (list 'format "%s %s" name 'arg) |
84 name))) | |
460 | 85 (list 'progn |
86 (list 'defun func '(arg) | |
87 (or doc "") | |
88 '(interactive "p") | |
89 (list 'gud-call cstr)) | |
914
3122c9756a56
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
889
diff
changeset
|
90 (if key |
3122c9756a56
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
889
diff
changeset
|
91 (list 'define-key 'gud-mode-map key (list 'quote func)))))) |
460 | 92 |
93 ;; All debugger-specific information is collected here | |
94 ;; Here's how it works, in case you ever need to add a debugger to the table. | |
95 ;; | |
96 ;; Each entry must define the following at startup: | |
97 ;; | |
98 ;;<name> | |
99 ;; comint-prompt-regexp | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
100 ;; gud-<name>-debugger-startup |
460 | 101 ;; gud-<name>-marker-filter |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
102 ;; gud-<name>-visit-file |
460 | 103 ;; gud-<name>-set-break |
104 ;; | |
477 | 105 ;; The job of the startup-command method is to fire up a copy of the debugger, |
106 ;; given an object file and source directory. | |
107 ;; | |
108 ;; The job of the marker-filter method is to detect file/line markers in | |
109 ;; strings and set the global gud-last-frame to indicate what display | |
110 ;; action (if any) should be triggered by the marker. Note that only | |
111 ;; whetever the method *returns* is displayed in the buffer; thus, you | |
112 ;; can filter the debugger's output, interpreting some and passing on | |
113 ;; the rest. | |
114 ;; | |
115 ;; The job of the visit-file method is to visit and return the buffer indicated | |
116 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or | |
117 ;; something else. | |
118 ;; | |
119 ;; The job of the gud-set-break method is to send the commands necessary | |
120 ;; to set a breakpoint at a given line in a given source file. | |
121 ;; | |
122 ;; Debugger-specific information begins here: | |
460 | 123 |
124 ;; ====================================================================== | |
125 ;; gdb functions | |
126 | |
127 (defun gud-gdb-debugger-startup (f d) | |
128 (make-comint (concat "gud-" f) "gdb" nil "-fullname" "-cd" d f)) | |
129 | |
1255 | 130 (defun gud-gdb-marker-filter (proc string) |
131 (if (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n" string) | |
460 | 132 (progn |
133 (setq gud-last-frame | |
134 (cons | |
135 (substring string (match-beginning 1) (match-end 1)) | |
136 (string-to-int | |
137 (substring string (match-beginning 2) (match-end 2))))) | |
138 ;; this computation means the ^Z^Z-initiated marker in the | |
139 ;; input string is never emitted. | |
140 (concat | |
141 (substring string 0 (match-beginning 0)) | |
142 (substring string (match-end 0)) | |
143 )) | |
144 string)) | |
145 | |
146 (defun gud-gdb-visit-file (f) | |
147 (find-file-noselect f)) | |
148 | |
149 (defun gud-gdb-set-break (proc f n) | |
150 (gud-call "break %s:%d" f n)) | |
151 | |
477 | 152 ;;;###autoload |
460 | 153 (defun gdb (path) |
154 "Run gdb on program FILE in buffer *gud-FILE*. | |
155 The directory containing FILE becomes the initial working directory | |
156 and source-file directory for your debugger." | |
157 (interactive "fRun gdb on file: ") | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
158 (gud-overload-functions '((gud-debugger-startup . gud-gdb-debugger-startup) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
159 (gud-marker-filter . gud-gdb-marker-filter) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
160 (gud-visit-file . gud-gdb-visit-file) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
161 (gud-set-break . gud-gdb-set-break))) |
460 | 162 |
889
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
163 (gud-def gud-step "step" "\C-c\C-s" "Step one source line with display") |
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
164 (gud-def gud-stepi "stepi" "\C-c\C-i" "Step one instruction with display") |
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
165 (gud-def gud-next "next" "\C-c\C-n" "Step one line (skip functions)") |
1255 | 166 (gud-def gud-cont "cont" "\C-c\C-r" "Continue with display") |
460 | 167 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
168 (gud-def gud-finish "finish" "\C-c\C-f" "Finish executing current function") |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
169 (gud-def gud-up "up" "\C-c<" "Up N stack frames (numeric arg)") |
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
170 (gud-def gud-down "down" "\C-c>" "Down N stack frames (numeric arg)") |
460 | 171 |
172 (gud-common-init path) | |
173 | |
174 (setq comint-prompt-regexp "^(.*gdb[+]?) *") | |
175 (run-hooks 'gdb-mode-hook) | |
176 ) | |
177 | |
178 | |
179 ;; ====================================================================== | |
180 ;; sdb functions | |
181 | |
182 (defun gud-sdb-debugger-startup (f d) | |
183 (make-comint (concat "gud-" f) "sdb" nil f "-" d)) | |
184 | |
1255 | 185 (defun gud-sdb-marker-filter (proc string) |
460 | 186 (if (string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n" |
1255 | 187 string) |
460 | 188 (setq gud-last-frame |
189 (cons | |
190 (substring string (match-beginning 2) (match-end 2)) | |
191 (string-to-int | |
192 (substring string (match-beginning 3) (match-end 3)))))) | |
193 string) | |
194 | |
195 (defun gud-sdb-visit-file (f) | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
196 (find-tag-noselect f)) |
460 | 197 |
198 (defun gud-sdb-set-break (proc f n) | |
199 (gud-queue-send (format "e %s" f) (format "%d b" n))) | |
200 | |
477 | 201 ;;;###autoload |
460 | 202 (defun sdb (path) |
203 "Run sdb on program FILE in buffer *gud-FILE*. | |
204 The directory containing FILE becomes the initial working directory | |
205 and source-file directory for your debugger." | |
923 | 206 (interactive "fRun sdb on file: ") |
460 | 207 (if (not (and (boundp 'tags-file-name) (file-exists-p tags-file-name))) |
208 (error "The sdb support requires a valid tags table to work.")) | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
209 (gud-overload-functions '((gud-debugger-startup . gud-sdb-debugger-startup) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
210 (gud-marker-filter . gud-sdb-marker-filter) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
211 (gud-visit-file . gud-sdb-visit-file) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
212 (gud-set-break . gud-sdb-set-break))) |
460 | 213 |
889
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
214 (gud-def gud-step "s" "\C-c\C-s" "Step one source line with display") |
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
215 (gud-def gud-stepi "i" "\C-c\C-i" "Step one instruction with display") |
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
216 (gud-def gud-next "S" "\C-c\C-n" "Step one source line (skip functions)") |
1255 | 217 (gud-def gud-cont "c" "\C-c\C-r" "Continue with display (`resume')") |
460 | 218 |
219 (gud-common-init path) | |
220 | |
1255 | 221 (setq comint-prompt-regexp "\\(^\\|\n\\)\\*") |
460 | 222 (run-hooks 'sdb-mode-hook) |
223 ) | |
224 | |
225 ;; ====================================================================== | |
226 ;; dbx functions | |
227 | |
228 (defun gud-dbx-debugger-startup (f d) | |
1255 | 229 (make-comint (concat "gud-" f) "dbx" nil f)) |
460 | 230 |
1255 | 231 (defun gud-dbx-marker-filter (proc string) |
460 | 232 (if (string-match |
1255 | 233 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" string) |
460 | 234 (setq gud-last-frame |
235 (cons | |
236 (substring string (match-beginning 2) (match-end 2)) | |
237 (string-to-int | |
238 (substring string (match-beginning 1) (match-end 1)))))) | |
239 string) | |
240 | |
241 (defun gud-dbx-visit-file (f) | |
242 (find-file-noselect f)) | |
243 | |
244 (defun gud-dbx-set-break (proc f n) | |
245 (gud-call "stop at \"%s\":%d" f n)) | |
246 | |
477 | 247 ;;;###autoload |
460 | 248 (defun dbx (path) |
249 "Run dbx on program FILE in buffer *gud-FILE*. | |
250 The directory containing FILE becomes the initial working directory | |
251 and source-file directory for your debugger." | |
252 (interactive "fRun dbx on file: ") | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
253 (gud-overload-functions '((gud-debugger-startup . gud-dbx-debugger-startup) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
254 (gud-marker-filter . gud-dbx-marker-filter) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
255 (gud-visit-file . gud-dbx-visit-file) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
256 (gud-set-break . gud-dbx-set-break))) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
257 |
889
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
258 (gud-def gud-step "step" "\C-c\C-s" "Step one source line with display") |
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
259 (gud-def gud-stepi "stepi" "\C-c\C-i" "Step one instruction with display") |
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
260 (gud-def gud-next "next" "\C-c\C-n" "Step one line (skip functions)") |
1255 | 261 (gud-def gud-cont "cont" "\C-c\C-r" "Continue with display (`resume')") |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
262 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
263 (gud-def gud-up "up" "\C-c<" "Up N stack frames (numeric arg)") |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
264 (gud-def gud-down "down" "\C-c>" "Down N stack frames (numeric arg)") |
460 | 265 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
266 (gud-common-init path) |
460 | 267 (setq comint-prompt-regexp "^[^)]*dbx) *") |
268 | |
269 (run-hooks 'dbx-mode-hook) | |
270 ) | |
271 | |
272 ;; | |
273 ;; End of debugger-specific information | |
477 | 274 ;; |
460 | 275 |
276 (defvar gud-mode-map nil | |
277 "Keymap for gud-mode.") | |
278 | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
279 (defvar gud-commands nil |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
280 "List of strings or functions used by send-gud-command. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
281 It is for customization by you.") |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
282 |
460 | 283 (defvar gud-command-queue nil) |
284 | |
1256
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
285 ;;; When we send a command to the debugger via gud-call, it's annoying |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
286 ;;; to see the command and the new prompt inserted into the debugger's |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
287 ;;; buffer; we have other ways of knowing the command has completed. |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
288 ;;; |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
289 ;;; If the buffer looks like this: |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
290 ;;; -------------------- |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
291 ;;; (gdb) set args foo bar |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
292 ;;; (gdb) -!- |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
293 ;;; -------------------- |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
294 ;;; (the -!- marks the location of point), and we type `C-x SPC' in a |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
295 ;;; source file to set a breakpoint, we want the buffer to end up like |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
296 ;;; this: |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
297 ;;; -------------------- |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
298 ;;; (gdb) set args foo bar |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
299 ;;; Breakpoint 1 at 0x92: file make-docfile.c, line 49. |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
300 ;;; (gdb) -!- |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
301 ;;; -------------------- |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
302 ;;; Essentially, the old prompt is deleted, and the command's output |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
303 ;;; and the new prompt take its place. |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
304 ;;; |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
305 ;;; Not echoing the command is easy enough; you send it directly using |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
306 ;;; process-send-string, and it never enters the buffer. However, |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
307 ;;; getting rid of the old prompt is trickier; you don't want to do it |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
308 ;;; when you send the command, since that will result in an annoying |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
309 ;;; flicker as the prompt is deleted, redisplay occurs while Emacs |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
310 ;;; waits for a response from the debugger, and the new prompt is |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
311 ;;; inserted. Instead, we'll wait until we actually get some output |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
312 ;;; from the subprocess before we delete the prompt. If the command |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
313 ;;; produced no output other than a new prompt, that prompt will most |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
314 ;;; likely be in the first chunk of output received, so we will delete |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
315 ;;; the prompt and then replace it with an identical one. If the |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
316 ;;; command produces output, the prompt is moving anyway, so the |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
317 ;;; flicker won't be annoying. |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
318 ;;; |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
319 ;;; So - when we want to delete the prompt upon receipt of the next |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
320 ;;; chunk of debugger output, we position gud-delete-prompt-marker at |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
321 ;;; the start of the prompt; the process filter will notice this, and |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
322 ;;; delete all text between it and the process output marker. If |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
323 ;;; gud-delete-prompt-marker points nowhere, we leave the current |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
324 ;;; prompt alone. |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
325 (defvar gud-delete-prompt-marker nil) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
326 |
460 | 327 (if gud-mode-map |
328 nil | |
329 (setq gud-mode-map (copy-keymap comint-mode-map)) | |
1255 | 330 (define-key gud-mode-map "\C-c\C-l" 'gud-refresh)) |
460 | 331 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
332 ;; Global mappings --- we'll invoke these from a source buffer. |
460 | 333 (define-key ctl-x-map " " 'gud-break) |
334 (define-key ctl-x-map "&" 'send-gud-command) | |
335 | |
336 | |
337 (defun gud-mode () | |
338 "Major mode for interacting with an inferior debugger process. | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
339 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
340 You start it up with one of the commands M-x gdb, M-x sdb, or |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
341 M-x dbx. Each entry point finishes by executing a hook; gdb-mode-hook, |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
342 sdb-mode-hook or dbx-mode-hook respectively. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
343 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
344 After startup, the following commands are available: |
460 | 345 |
346 \\{gud-mode-map} | |
347 | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
348 \\[gud-refresh] displays in the other window the last line referred to |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
349 in the gud buffer. |
460 | 350 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
351 \\[gud-step], \\[gud-next], and \\[gud-stepi] in the gud window, |
460 | 352 do a step-one-line, step-one-line (not entering function calls), and |
353 step-one-instruction and then update the other window | |
354 with the current file and position. \\[gud-cont] continues | |
355 execution. | |
356 | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
357 The above commands are common to all supported debuggers. If you are |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
358 using gdb or dbx, the following additional commands will be available: |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
359 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
360 \\[gud-up] pops up through an enclosing stack frame. \\[gud-down] drops |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
361 back down through one. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
362 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
363 If you are using gdb, \\[gdb-finish] runs execution to the return from |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
364 the current function and stops. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
365 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
366 These functions repeat themselves the appropriate number of times if you give a |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
367 prefix argument. |
460 | 368 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
369 If you are in a source file, you may do the following: |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
370 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
371 Set a breakpoint at the current line by doing \\[gud-break]. This causes |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
372 an appropriate set-break to be send to the debugger; of course, if the file |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
373 you're visiting doesn't correspond to any code in the executable this will |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
374 have no effect or raise an error. |
460 | 375 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
376 Execute a user-defined command at point with \\[send-gud-command]; the |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
377 prefix argument is taken as an index into the list of strings gud-commands. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
378 A %s in a gud-commands string is substituted with a number or address picked |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
379 up from point. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
380 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
381 Other commands for interacting with the debugger process are inherited from |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
382 comint mode, which see." |
460 | 383 (interactive) |
384 (comint-mode) | |
385 ; (kill-all-local-variables) | |
386 (setq major-mode 'gud-mode) | |
387 (setq mode-name "Debugger") | |
388 (setq mode-line-process '(": %s")) | |
389 (use-local-map gud-mode-map) | |
390 (make-local-variable 'gud-last-frame) | |
391 (setq gud-last-frame nil) | |
392 (make-local-variable 'comint-prompt-regexp) | |
1256
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
393 (make-local-variable 'gud-delete-prompt-marker) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
394 (setq gud-delete-prompt-marker (make-marker)) |
460 | 395 (run-hooks 'gud-mode-hook) |
396 ) | |
397 | |
398 (defvar current-gud-buffer nil) | |
399 | |
400 (defun gud-common-init (path) | |
401 ;; perform initializations common to all debuggers | |
402 (setq path (expand-file-name path)) | |
403 (let ((file (file-name-nondirectory path))) | |
404 (switch-to-buffer (concat "*gud-" file "*")) | |
405 (setq default-directory (file-name-directory path)) | |
406 (or (bolp) (newline)) | |
407 (insert "Current directory is " default-directory "\n") | |
408 (gud-debugger-startup file default-directory)) | |
409 (gud-mode) | |
410 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter) | |
411 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel) | |
412 (setq gud-command-queue nil) | |
413 (gud-set-buffer) | |
414 ) | |
415 | |
416 (defun gud-set-buffer () | |
417 (cond ((eq major-mode 'gud-mode) | |
418 (setq current-gud-buffer (current-buffer))))) | |
419 | |
420 (defun gud-filter (proc string) | |
421 ;; This function is responsible for inserting output from your debugger | |
422 ;; into the buffer. The hard work is done by the method that is | |
423 ;; the value of gud-marker-filter. | |
424 (let ((inhibit-quit t)) | |
425 (gud-filter-insert proc (gud-marker-filter proc string)) | |
426 ;; If we've got queued commands and we see a prompt, pop one and send it. | |
427 ;; In theory we should check that a prompt has been issued before sending | |
428 ;; queued commands. In practice, command responses from the first through | |
429 ;; penultimate elements of a command sequence are short enough that we | |
430 ;; don't really have to bother. | |
431 (if gud-command-queue | |
432 (progn | |
433 (gud-call (car gud-command-queue)) | |
434 (setq gud-command-queue (cdr gud-command-queue)) | |
435 ) | |
436 ))) | |
437 | |
438 (defun gud-filter-insert (proc string) | |
439 ;; Here's where the actual buffer insertion is done | |
1255 | 440 (save-excursion |
460 | 441 (set-buffer (process-buffer proc)) |
1255 | 442 (let ((output-after-point (< (point) (process-mark proc)))) |
443 (goto-char (process-mark proc)) | |
1256
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
444 ;; If we have been so requested, delete the debugger prompt. |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
445 (if (marker-buffer gud-delete-prompt-marker) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
446 (progn |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
447 (delete-region (point) gud-delete-prompt-marker) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
448 (set-marker gud-delete-prompt-marker nil))) |
1255 | 449 (insert-before-markers string) |
450 ;; Check for a filename-and-line number. | |
451 ;; Don't display the specified file | |
452 ;; unless (1) point is at or after the position where output appears | |
453 ;; and (2) this buffer is on the screen. | |
454 (if (and gud-last-frame | |
455 (not output-after-point) | |
456 (get-buffer-window (current-buffer))) | |
457 (gud-display-frame))))) | |
460 | 458 |
459 (defun gud-sentinel (proc msg) | |
460 (cond ((null (buffer-name (process-buffer proc))) | |
461 ;; buffer killed | |
462 ;; Stop displaying an arrow in a source file. | |
463 (setq overlay-arrow-position nil) | |
464 (set-process-buffer proc nil)) | |
465 ((memq (process-status proc) '(signal exit)) | |
466 ;; Stop displaying an arrow in a source file. | |
467 (setq overlay-arrow-position nil) | |
468 ;; Fix the mode line. | |
469 (setq mode-line-process | |
470 (concat ": " | |
471 (symbol-name (process-status proc)))) | |
472 (let* ((obuf (current-buffer))) | |
473 ;; save-excursion isn't the right thing if | |
474 ;; process-buffer is current-buffer | |
475 (unwind-protect | |
476 (progn | |
477 ;; Write something in *compilation* and hack its mode line, | |
478 (set-buffer (process-buffer proc)) | |
479 ;; Force mode line redisplay soon | |
480 (set-buffer-modified-p (buffer-modified-p)) | |
481 (if (eobp) | |
482 (insert ?\n mode-name " " msg) | |
483 (save-excursion | |
484 (goto-char (point-max)) | |
485 (insert ?\n mode-name " " msg))) | |
486 ;; If buffer and mode line will show that the process | |
487 ;; is dead, we can delete it now. Otherwise it | |
488 ;; will stay around until M-x list-processes. | |
489 (delete-process proc)) | |
490 ;; Restore old buffer, but don't restore old point | |
491 ;; if obuf is the gud buffer. | |
492 (set-buffer obuf)))))) | |
493 | |
494 | |
495 (defun gud-refresh (&optional arg) | |
496 "Fix up a possibly garbled display, and redraw the arrow." | |
497 (interactive "P") | |
498 (recenter arg) | |
499 (gud-display-frame)) | |
500 | |
501 (defun gud-display-frame () | |
502 "Find and obey the last filename-and-line marker from the debugger. | |
503 Obeying it means displaying in another window the specified file and line." | |
504 (interactive) | |
505 (if gud-last-frame | |
506 (progn | |
507 (gud-set-buffer) | |
508 (gud-display-line (car gud-last-frame) (cdr gud-last-frame)) | |
509 (setq gud-last-frame nil)))) | |
510 | |
511 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen | |
512 ;; and that its line LINE is visible. | |
513 ;; Put the overlay-arrow on the line LINE in that buffer. | |
514 | |
515 (defun gud-display-line (true-file line) | |
516 (let* ((buffer (gud-visit-file true-file)) | |
517 (window (display-buffer buffer t)) | |
518 (pos)) | |
519 (save-excursion | |
520 (set-buffer buffer) | |
521 (save-restriction | |
522 (widen) | |
523 (goto-line line) | |
524 (setq pos (point)) | |
525 (setq overlay-arrow-string "=>") | |
526 (or overlay-arrow-position | |
527 (setq overlay-arrow-position (make-marker))) | |
528 (set-marker overlay-arrow-position (point) (current-buffer))) | |
529 (cond ((or (< pos (point-min)) (> pos (point-max))) | |
530 (widen) | |
531 (goto-char pos)))) | |
532 (set-window-point window overlay-arrow-position))) | |
533 | |
534 (defun gud-call (command &rest args) | |
535 "Invoke the debugger COMMAND displaying source in other window." | |
536 (interactive) | |
537 (gud-set-buffer) | |
538 (let ((command (concat (apply 'format command args) "\n")) | |
539 (proc (get-buffer-process current-gud-buffer))) | |
1256
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
540 |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
541 ;; Arrange for the current prompt to get deleted. |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
542 (save-excursion |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
543 (set-buffer current-gud-buffer) |
1257 | 544 (goto-char (process-mark proc)) |
1256
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
545 (beginning-of-line) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
546 (if (looking-at comint-prompt-regexp) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
547 (set-marker gud-delete-prompt-marker (point)))) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
548 |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
549 (goto-char (point-max)) |
ff24725192d3
* gud.el: When we send a command to the debugger via gud-call,
Jim Blandy <jimb@redhat.com>
parents:
1255
diff
changeset
|
550 (process-send-string proc command))) |
460 | 551 |
552 (defun gud-queue-send (&rest cmdlist) | |
553 ;; Send the first command, queue the rest for send after successive | |
554 ;; send on subsequent prompts | |
555 (interactive) | |
556 (gud-call (car cmdlist)) | |
557 (setq gud-command-queue (append gud-command-queue (cdr cmdlist)))) | |
558 | |
559 (defun gud-apply-from-source (func) | |
560 ;; Apply a method from the gud buffer environment, passing it file and line. | |
561 ;; This is intended to be used for gud commands called from a source file. | |
562 (if (not buffer-file-name) | |
563 (error "There is no file associated with this buffer")) | |
564 (let ((file (file-name-nondirectory buffer-file-name)) | |
565 (line (save-restriction (widen) (1+ (count-lines 1 (point)))))) | |
566 (save-excursion | |
567 (gud-set-buffer) | |
568 (funcall func | |
569 (get-buffer-process current-gud-buffer) | |
570 file | |
571 line) | |
572 ))) | |
573 | |
574 (defun gud-break () | |
575 "Set breakpoint at this source line." | |
576 (interactive) | |
577 (gud-apply-from-source 'gud-set-break)) | |
578 | |
1255 | 579 (defun gud-read-address () |
460 | 580 "Return a string containing the core-address found in the buffer at point." |
581 (save-excursion | |
1255 | 582 (let ((pt (point)) found begin) |
583 (setq found (if (search-backward "0x" (- pt 7) t)(point))) | |
584 (cond | |
585 (found (forward-char 2) | |
586 (buffer-substring found | |
587 (progn (re-search-forward "[^0-9a-f]") | |
588 (forward-char -1) | |
589 (point)))) | |
590 (t (setq begin (progn (re-search-backward "[^0-9]") | |
591 (forward-char 1) | |
592 (point))) | |
593 (forward-char 1) | |
594 (re-search-forward "[^0-9]") | |
595 (forward-char -1) | |
596 (buffer-substring begin (point))))))) | |
460 | 597 |
598 | |
599 (defun send-gud-command (arg) | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
600 "This command reads the number where the cursor is positioned. A numeric arg |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
601 selects the ARG'th member COMMAND of the list gud-commands. If COMMAND is a |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
602 string, (format COMMAND ADDR) is inserted at the end of the debugger buffer, |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
603 otherwise (funcall COMMAND ADDR) is inserted. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
604 For example, \"p (rtx)%s->fld[0].rtint\" is a possible string to be a |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
605 member of gud-commands." |
460 | 606 (interactive "P") |
607 (let (comm addr) | |
608 (if arg (setq comm (nth arg gud-commands))) | |
609 (setq addr (gud-read-address)) | |
610 (if (eq (current-buffer) current-gud-buffer) | |
611 (set-mark (point))) | |
612 (cond (comm | |
613 (setq comm | |
614 (if (stringp comm) (format comm addr) (funcall comm addr)))) | |
615 (t (setq comm addr))) | |
616 (switch-to-buffer current-gud-buffer) | |
923 | 617 (goto-char (point-max)) |
460 | 618 (insert-string comm))) |
477 | 619 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
620 ;;; gud.el ends here |