Mercurial > emacs
annotate lisp/gud.el @ 910:4fba6d4b6a28
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 03 Aug 1992 03:44:51 +0000 |
parents | b2fef2e0c761 |
children | 3122c9756a56 |
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) |
46 (require 'tags) | |
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 |
460 | 73 ;; user defined ones. |
74 | |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
75 (defmacro gud-def (func name key &optional doc) |
460 | 76 (let* ((cstr (list 'if '(not (= 1 arg)) |
77 (list 'format "%s %s" name 'arg) name))) | |
78 (list 'progn | |
79 (list 'defun func '(arg) | |
80 (or doc "") | |
81 '(interactive "p") | |
82 (list 'gud-call cstr)) | |
83 (list 'define-key 'gud-mode-map key (list 'quote func))))) | |
84 | |
85 ;; All debugger-specific information is collected here | |
86 ;; Here's how it works, in case you ever need to add a debugger to the table. | |
87 ;; | |
88 ;; Each entry must define the following at startup: | |
89 ;; | |
90 ;;<name> | |
91 ;; comint-prompt-regexp | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
92 ;; gud-<name>-debugger-startup |
460 | 93 ;; gud-<name>-marker-filter |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
94 ;; gud-<name>-visit-file |
460 | 95 ;; gud-<name>-set-break |
96 ;; | |
477 | 97 ;; The job of the startup-command method is to fire up a copy of the debugger, |
98 ;; given an object file and source directory. | |
99 ;; | |
100 ;; The job of the marker-filter method is to detect file/line markers in | |
101 ;; strings and set the global gud-last-frame to indicate what display | |
102 ;; action (if any) should be triggered by the marker. Note that only | |
103 ;; whetever the method *returns* is displayed in the buffer; thus, you | |
104 ;; can filter the debugger's output, interpreting some and passing on | |
105 ;; the rest. | |
106 ;; | |
107 ;; The job of the visit-file method is to visit and return the buffer indicated | |
108 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or | |
109 ;; something else. | |
110 ;; | |
111 ;; The job of the gud-set-break method is to send the commands necessary | |
112 ;; to set a breakpoint at a given line in a given source file. | |
113 ;; | |
114 ;; Debugger-specific information begins here: | |
460 | 115 |
116 ;; ====================================================================== | |
117 ;; gdb functions | |
118 | |
119 (defun gud-gdb-debugger-startup (f d) | |
120 (make-comint (concat "gud-" f) "gdb" nil "-fullname" "-cd" d f)) | |
121 | |
122 (defun gud-gdb-marker-filter (proc s) | |
123 (if (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n" s) | |
124 (progn | |
125 (setq gud-last-frame | |
126 (cons | |
127 (substring string (match-beginning 1) (match-end 1)) | |
128 (string-to-int | |
129 (substring string (match-beginning 2) (match-end 2))))) | |
130 ;; this computation means the ^Z^Z-initiated marker in the | |
131 ;; input string is never emitted. | |
132 (concat | |
133 (substring string 0 (match-beginning 0)) | |
134 (substring string (match-end 0)) | |
135 )) | |
136 string)) | |
137 | |
138 (defun gud-gdb-visit-file (f) | |
139 (find-file-noselect f)) | |
140 | |
141 (defun gud-gdb-set-break (proc f n) | |
142 (gud-call "break %s:%d" f n)) | |
143 | |
477 | 144 ;;;###autoload |
460 | 145 (defun gdb (path) |
146 "Run gdb on program FILE in buffer *gud-FILE*. | |
147 The directory containing FILE becomes the initial working directory | |
148 and source-file directory for your debugger." | |
149 (interactive "fRun gdb on file: ") | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
150 (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
|
151 (gud-marker-filter . gud-gdb-marker-filter) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
152 (gud-visit-file . gud-gdb-visit-file) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
153 (gud-set-break . gud-gdb-set-break))) |
460 | 154 |
889
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
155 (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
|
156 (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
|
157 (gud-def gud-next "next" "\C-c\C-n" "Step one line (skip functions)") |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
158 (gud-def gud-cont "cont" "\C-c\C-c" "Continue with display") |
460 | 159 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
160 (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
|
161 (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
|
162 (gud-def gud-down "down" "\C-c>" "Down N stack frames (numeric arg)") |
460 | 163 |
164 (gud-common-init path) | |
165 | |
166 (setq comint-prompt-regexp "^(.*gdb[+]?) *") | |
167 (run-hooks 'gdb-mode-hook) | |
168 ) | |
169 | |
170 | |
171 ;; ====================================================================== | |
172 ;; sdb functions | |
173 | |
174 (defun gud-sdb-debugger-startup (f d) | |
175 (make-comint (concat "gud-" f) "sdb" nil f "-" d)) | |
176 | |
177 (defun gud-sdb-marker-filter (proc str) | |
178 (if (string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n" | |
179 str) | |
180 (setq gud-last-frame | |
181 (cons | |
182 (substring string (match-beginning 2) (match-end 2)) | |
183 (string-to-int | |
184 (substring string (match-beginning 3) (match-end 3)))))) | |
185 string) | |
186 | |
187 (defun gud-sdb-visit-file (f) | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
188 (find-tag-noselect f)) |
460 | 189 |
190 (defun gud-sdb-set-break (proc f n) | |
191 (gud-queue-send (format "e %s" f) (format "%d b" n))) | |
192 | |
477 | 193 ;;;###autoload |
460 | 194 (defun sdb (path) |
195 "Run sdb on program FILE in buffer *gud-FILE*. | |
196 The directory containing FILE becomes the initial working directory | |
197 and source-file directory for your debugger." | |
198 (if (not (and (boundp 'tags-file-name) (file-exists-p tags-file-name))) | |
199 (error "The sdb support requires a valid tags table to work.")) | |
200 (interactive "fRun sdb on file: ") | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
201 (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
|
202 (gud-marker-filter . gud-sdb-marker-filter) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
203 (gud-visit-file . gud-sdb-visit-file) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
204 (gud-set-break . gud-sdb-set-break))) |
460 | 205 |
889
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
206 (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
|
207 (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
|
208 (gud-def gud-next "S" "\C-c\C-n" "Step one source line (skip functions)") |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
209 (gud-def gud-cont "c" "\C-c\C-c" "Continue with display") |
460 | 210 |
211 (gud-common-init path) | |
212 | |
213 (setq comint-prompt-pattern "\\(^\\|\n\\)\\*") | |
214 (run-hooks 'sdb-mode-hook) | |
215 ) | |
216 | |
217 ;; ====================================================================== | |
218 ;; dbx functions | |
219 | |
220 (defun gud-dbx-debugger-startup (f d) | |
221 (make-comint (concat "gud-" file) "dbx" nil f)) | |
222 | |
223 (defun gud-dbx-marker-filter (proc str) | |
224 (if (string-match | |
225 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" str) | |
226 (setq gud-last-frame | |
227 (cons | |
228 (substring string (match-beginning 2) (match-end 2)) | |
229 (string-to-int | |
230 (substring string (match-beginning 1) (match-end 1)))))) | |
231 string) | |
232 | |
233 (defun gud-dbx-visit-file (f) | |
234 (find-file-noselect f)) | |
235 | |
236 (defun gud-dbx-set-break (proc f n) | |
237 (gud-call "stop at \"%s\":%d" f n)) | |
238 | |
477 | 239 ;;;###autoload |
460 | 240 (defun dbx (path) |
241 "Run dbx on program FILE in buffer *gud-FILE*. | |
242 The directory containing FILE becomes the initial working directory | |
243 and source-file directory for your debugger." | |
244 (interactive "fRun dbx on file: ") | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
245 (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
|
246 (gud-marker-filter . gud-dbx-marker-filter) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
247 (gud-visit-file . gud-dbx-visit-file) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
248 (gud-set-break . gud-dbx-set-break))) |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
249 |
889
b2fef2e0c761
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
868
diff
changeset
|
250 (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
|
251 (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
|
252 (gud-def gud-next "next" "\C-c\C-n" "Step one line (skip functions)") |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
253 (gud-def gud-cont "cont" "\C-c\C-c" "Continue with display") |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
254 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
255 (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
|
256 (gud-def gud-down "down" "\C-c>" "Down N stack frames (numeric arg)") |
460 | 257 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
258 (gud-common-init path) |
460 | 259 (setq comint-prompt-regexp "^[^)]*dbx) *") |
260 | |
261 (run-hooks 'dbx-mode-hook) | |
262 ) | |
263 | |
264 ;; | |
265 ;; End of debugger-specific information | |
477 | 266 ;; |
460 | 267 |
268 (defvar gud-mode-map nil | |
269 "Keymap for gud-mode.") | |
270 | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
271 (defvar gud-commands nil |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
272 "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
|
273 It is for customization by you.") |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
274 |
460 | 275 (defvar gud-command-queue nil) |
276 | |
277 (if gud-mode-map | |
278 nil | |
279 (setq gud-mode-map (copy-keymap comint-mode-map)) | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
280 (define-key gud-mode-map "\C-cl" 'gud-refresh)) |
460 | 281 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
282 ;; Global mappings --- we'll invoke these from a source buffer. |
460 | 283 (define-key ctl-x-map " " 'gud-break) |
284 (define-key ctl-x-map "&" 'send-gud-command) | |
285 | |
286 | |
287 (defun gud-mode () | |
288 "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
|
289 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
290 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
|
291 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
|
292 sdb-mode-hook or dbx-mode-hook respectively. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
293 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
294 After startup, the following commands are available: |
460 | 295 |
296 \\{gud-mode-map} | |
297 | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
298 \\[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
|
299 in the gud buffer. |
460 | 300 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
301 \\[gud-step], \\[gud-next], and \\[gud-stepi] in the gud window, |
460 | 302 do a step-one-line, step-one-line (not entering function calls), and |
303 step-one-instruction and then update the other window | |
304 with the current file and position. \\[gud-cont] continues | |
305 execution. | |
306 | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
307 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
|
308 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
|
309 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
310 \\[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
|
311 back down through one. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
312 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
313 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
|
314 the current function and stops. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
315 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
316 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
|
317 prefix argument. |
460 | 318 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
319 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
|
320 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 have no effect or raise an error. |
460 | 325 |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 up from point. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
330 |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
331 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
|
332 comint mode, which see." |
460 | 333 (interactive) |
334 (comint-mode) | |
335 ; (kill-all-local-variables) | |
336 (setq major-mode 'gud-mode) | |
337 (setq mode-name "Debugger") | |
338 (setq mode-line-process '(": %s")) | |
339 (use-local-map gud-mode-map) | |
340 (make-local-variable 'gud-last-frame) | |
341 (setq gud-last-frame nil) | |
342 (make-local-variable 'comint-prompt-regexp) | |
343 (run-hooks 'gud-mode-hook) | |
344 ) | |
345 | |
346 (defvar current-gud-buffer nil) | |
347 | |
348 (defun gud-common-init (path) | |
349 ;; perform initializations common to all debuggers | |
350 (setq path (expand-file-name path)) | |
351 (let ((file (file-name-nondirectory path))) | |
352 (switch-to-buffer (concat "*gud-" file "*")) | |
353 (setq default-directory (file-name-directory path)) | |
354 (or (bolp) (newline)) | |
355 (insert "Current directory is " default-directory "\n") | |
356 (gud-debugger-startup file default-directory)) | |
357 (gud-mode) | |
358 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter) | |
359 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel) | |
360 (setq gud-command-queue nil) | |
361 (gud-set-buffer) | |
362 ) | |
363 | |
364 (defun gud-set-buffer () | |
365 (cond ((eq major-mode 'gud-mode) | |
366 (setq current-gud-buffer (current-buffer))))) | |
367 | |
368 (defun gud-filter (proc string) | |
369 ;; This function is responsible for inserting output from your debugger | |
370 ;; into the buffer. The hard work is done by the method that is | |
371 ;; the value of gud-marker-filter. | |
372 (let ((inhibit-quit t)) | |
373 (gud-filter-insert proc (gud-marker-filter proc string)) | |
374 ;; If we've got queued commands and we see a prompt, pop one and send it. | |
375 ;; In theory we should check that a prompt has been issued before sending | |
376 ;; queued commands. In practice, command responses from the first through | |
377 ;; penultimate elements of a command sequence are short enough that we | |
378 ;; don't really have to bother. | |
379 (if gud-command-queue | |
380 (progn | |
381 (gud-call (car gud-command-queue)) | |
382 (setq gud-command-queue (cdr gud-command-queue)) | |
383 ) | |
384 ))) | |
385 | |
386 (defun gud-filter-insert (proc string) | |
387 ;; Here's where the actual buffer insertion is done | |
388 (let ((moving (= (point) (process-mark proc))) | |
389 (output-after-point (< (point) (process-mark proc))) | |
390 (old-buffer (current-buffer)) | |
391 start) | |
392 (set-buffer (process-buffer proc)) | |
393 (unwind-protect | |
394 (save-excursion | |
395 ;; Insert the text, moving the process-marker. | |
396 (goto-char (process-mark proc)) | |
397 (setq start (point)) | |
398 (insert-before-markers string) | |
399 (set-marker (process-mark proc) (point)) | |
400 ;; Check for a filename-and-line number. | |
401 ;; Don't display the specified file | |
402 ;; unless (1) point is at or after the position where output appears | |
403 ;; and (2) this buffer is on the screen. | |
404 (if (and gud-last-frame (not output-after-point) | |
405 (get-buffer-window (current-buffer))) | |
406 (gud-display-frame)) | |
407 ) | |
408 (set-buffer old-buffer)) | |
409 (if moving (goto-char (process-mark proc))))) | |
410 | |
411 (defun gud-sentinel (proc msg) | |
412 (cond ((null (buffer-name (process-buffer proc))) | |
413 ;; buffer killed | |
414 ;; Stop displaying an arrow in a source file. | |
415 (setq overlay-arrow-position nil) | |
416 (set-process-buffer proc nil)) | |
417 ((memq (process-status proc) '(signal exit)) | |
418 ;; Stop displaying an arrow in a source file. | |
419 (setq overlay-arrow-position nil) | |
420 ;; Fix the mode line. | |
421 (setq mode-line-process | |
422 (concat ": " | |
423 (symbol-name (process-status proc)))) | |
424 (let* ((obuf (current-buffer))) | |
425 ;; save-excursion isn't the right thing if | |
426 ;; process-buffer is current-buffer | |
427 (unwind-protect | |
428 (progn | |
429 ;; Write something in *compilation* and hack its mode line, | |
430 (set-buffer (process-buffer proc)) | |
431 ;; Force mode line redisplay soon | |
432 (set-buffer-modified-p (buffer-modified-p)) | |
433 (if (eobp) | |
434 (insert ?\n mode-name " " msg) | |
435 (save-excursion | |
436 (goto-char (point-max)) | |
437 (insert ?\n mode-name " " msg))) | |
438 ;; If buffer and mode line will show that the process | |
439 ;; is dead, we can delete it now. Otherwise it | |
440 ;; will stay around until M-x list-processes. | |
441 (delete-process proc)) | |
442 ;; Restore old buffer, but don't restore old point | |
443 ;; if obuf is the gud buffer. | |
444 (set-buffer obuf)))))) | |
445 | |
446 | |
447 (defun gud-refresh (&optional arg) | |
448 "Fix up a possibly garbled display, and redraw the arrow." | |
449 (interactive "P") | |
450 (recenter arg) | |
451 (gud-display-frame)) | |
452 | |
453 (defun gud-display-frame () | |
454 "Find and obey the last filename-and-line marker from the debugger. | |
455 Obeying it means displaying in another window the specified file and line." | |
456 (interactive) | |
457 (if gud-last-frame | |
458 (progn | |
459 (gud-set-buffer) | |
460 (gud-display-line (car gud-last-frame) (cdr gud-last-frame)) | |
461 (setq gud-last-frame nil)))) | |
462 | |
463 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen | |
464 ;; and that its line LINE is visible. | |
465 ;; Put the overlay-arrow on the line LINE in that buffer. | |
466 | |
467 (defun gud-display-line (true-file line) | |
468 (let* ((buffer (gud-visit-file true-file)) | |
469 (window (display-buffer buffer t)) | |
470 (pos)) | |
471 (save-excursion | |
472 (set-buffer buffer) | |
473 (save-restriction | |
474 (widen) | |
475 (goto-line line) | |
476 (setq pos (point)) | |
477 (setq overlay-arrow-string "=>") | |
478 (or overlay-arrow-position | |
479 (setq overlay-arrow-position (make-marker))) | |
480 (set-marker overlay-arrow-position (point) (current-buffer))) | |
481 (cond ((or (< pos (point-min)) (> pos (point-max))) | |
482 (widen) | |
483 (goto-char pos)))) | |
484 (set-window-point window overlay-arrow-position))) | |
485 | |
486 (defun gud-call (command &rest args) | |
487 "Invoke the debugger COMMAND displaying source in other window." | |
488 (interactive) | |
489 (gud-set-buffer) | |
490 (goto-char (point-max)) | |
491 (let ((command (concat (apply 'format command args) "\n")) | |
492 (proc (get-buffer-process current-gud-buffer))) | |
493 (gud-filter-insert proc command) | |
494 (send-string proc command) | |
495 )) | |
496 | |
497 (defun gud-queue-send (&rest cmdlist) | |
498 ;; Send the first command, queue the rest for send after successive | |
499 ;; send on subsequent prompts | |
500 (interactive) | |
501 (gud-call (car cmdlist)) | |
502 (setq gud-command-queue (append gud-command-queue (cdr cmdlist)))) | |
503 | |
504 (defun gud-apply-from-source (func) | |
505 ;; Apply a method from the gud buffer environment, passing it file and line. | |
506 ;; This is intended to be used for gud commands called from a source file. | |
507 (if (not buffer-file-name) | |
508 (error "There is no file associated with this buffer")) | |
509 (let ((file (file-name-nondirectory buffer-file-name)) | |
510 (line (save-restriction (widen) (1+ (count-lines 1 (point)))))) | |
511 (save-excursion | |
512 (gud-set-buffer) | |
513 (funcall func | |
514 (get-buffer-process current-gud-buffer) | |
515 file | |
516 line) | |
517 ))) | |
518 | |
519 (defun gud-break () | |
520 "Set breakpoint at this source line." | |
521 (interactive) | |
522 (gud-apply-from-source 'gud-set-break)) | |
523 | |
524 (defun gud-read-address() | |
525 "Return a string containing the core-address found in the buffer at point." | |
526 (save-excursion | |
527 (let ((pt (dot)) found begin) | |
528 (setq found (if (search-backward "0x" (- pt 7) t)(dot))) | |
529 (cond (found (forward-char 2) | |
530 (setq result | |
531 (buffer-substring found | |
532 (progn (re-search-forward "[^0-9a-f]") | |
533 (forward-char -1) | |
534 (dot))))) | |
535 (t (setq begin (progn (re-search-backward "[^0-9]") (forward-char 1) | |
536 (dot))) | |
537 (forward-char 1) | |
538 (re-search-forward "[^0-9]") | |
539 (forward-char -1) | |
540 (buffer-substring begin (dot))))))) | |
541 | |
542 | |
543 (defun send-gud-command (arg) | |
868
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
544 "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
|
545 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
|
546 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
|
547 otherwise (funcall COMMAND ADDR) is inserted. |
0cda1f7b154e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
810
diff
changeset
|
548 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
|
549 member of gud-commands." |
460 | 550 (interactive "P") |
551 (let (comm addr) | |
552 (if arg (setq comm (nth arg gud-commands))) | |
553 (setq addr (gud-read-address)) | |
554 (if (eq (current-buffer) current-gud-buffer) | |
555 (set-mark (point))) | |
556 (cond (comm | |
557 (setq comm | |
558 (if (stringp comm) (format comm addr) (funcall comm addr)))) | |
559 (t (setq comm addr))) | |
560 (switch-to-buffer current-gud-buffer) | |
561 (goto-char (dot-max)) | |
562 (insert-string comm))) | |
477 | 563 |
810
80303373daae
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
806
diff
changeset
|
564 ;;; gud.el ends here |