Mercurial > emacs
annotate lisp/gdb-ui.el @ 48498:8fdedd7dca85
General tidying. Patches from Stefan Monnier.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Thu, 21 Nov 2002 21:07:01 +0000 |
parents | 69646014abb3 |
children | 3216cd45d6d2 |
rev | line source |
---|---|
48292 | 1 ;;; gdb-ui.el --- User Interface for running GDB |
2 | |
3 ;; Author: Nick Roberts <nick@nick.uklinux.net> | |
4 ;; Maintainer: FSF | |
5 ;; Keywords: unix, tools | |
6 | |
7 ;; Copyright (C) 2002 Free Software Foundation, Inc. | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; Extension of gdba.el written by Jim Kingdon from gdb 5.0 | |
29 | |
30 ;;; Code: | |
31 | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
32 (require 'gud) |
48292 | 33 |
34 (defcustom gdb-many-windows t | |
35 "If t, using gdba, start gdb with ancillary buffers visible. | |
36 Use `toggle-gdb-windows' to change this value during a gdb session" | |
37 :type 'boolean | |
38 :group 'gud) | |
39 | |
40 (defvar gdb-main-file nil "Source file from which program execution begins.") | |
41 (defvar gdb-cdir nil "Compilation directory.") | |
42 (defvar gdb-main-or-pc nil "Initialisation for Assembler buffer.") | |
43 (defvar gdb-prev-main-or-pc nil) | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
44 (defvar gdb-current-address nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
45 (defvar gdb-current-frame nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
46 (defvar gdb-display-in-progress nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
47 (defvar gdb-dive nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
48 (defvar gdb-first-time nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
49 (defvar breakpoint-enabled-icon |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
50 "Icon for enabled breakpoint in display margin") |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
51 (defvar breakpoint-disabled-icon |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
52 "Icon for disabled breakpoint in display margin") |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
53 (defvar gdb-nesting-level) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
54 (defvar gdb-expression-buffer-name) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
55 (defvar gdb-expression) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
56 (defvar gdb-point) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
57 (defvar gdb-annotation-arg) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
58 (defvar gdb-array-start) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
59 (defvar gdb-array-stop) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
60 (defvar gdb-display-number) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
61 (defvar gdb-dive-display-number) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
62 (defvar gdb-dive-map nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
63 (defvar gdb-display-string) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
64 (defvar gdb-values) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
65 (defvar gdb-array-size) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
66 (defvar gdb-array-slice-map nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
67 (defvar gdb-buffer-instance nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
68 (defvar gdb-source-window nil) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
69 (defvar gdb-target-name "--unknown--" |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
70 "The apparent name of the program being debugged in a gud buffer.") |
48292 | 71 |
72 (defun gdba (command-line) | |
73 "Run gdb on program FILE in buffer *gdb-FILE*. | |
74 The directory containing FILE becomes the initial working directory | |
75 and source-file directory for your debugger. | |
76 | |
77 If `gdb-many-windows' is set to t this works best in X (depending on the size | |
78 of your monitor) using most of the screen. After a short delay the following | |
79 layout will appear (keybindings given in relevant buffer) : | |
80 | |
81 --------------------------------------------------------------------- | |
82 GDB Toolbar | |
83 --------------------------------------------------------------------- | |
84 GUD buffer (I/O of gdb) | Locals buffer | |
85 | | |
86 | | |
87 | | |
88 --------------------------------------------------------------------- | |
89 Source buffer | Input/Output (of debuggee) buffer | |
90 | (comint-mode) | |
91 | | |
92 | | |
93 | | |
94 | | |
95 | | |
96 | | |
97 --------------------------------------------------------------------- | |
98 Stack buffer | Breakpoints buffer | |
99 \[mouse-2\] gdb-frames-select | SPC gdb-toggle-bp-this-line | |
100 | g gdb-goto-bp-this-line | |
101 | d gdb-delete-bp-this-line | |
102 --------------------------------------------------------------------- | |
103 | |
104 All the buffers share the toolbar and source should always display in the same | |
105 window e.g after typing g on a breakpoint in the breakpoints buffer. Breakpoint | |
106 icons are displayed both by setting a break with gud-break and by typing break | |
107 in the GUD buffer. | |
108 | |
109 Displayed expressions appear in separate frames. Arrays may be displayed | |
110 as slices and visualised using the graph program from plotutils if installed. | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
111 |
48292 | 112 If `gdb-many-windows' is set to nil then gdb starts with just two windows : |
113 the GUD and the source buffer. | |
114 | |
115 The following interactive lisp functions help control operation : | |
116 | |
117 `toggle-gdb-windows' - Toggle the number of windows gdb uses. | |
118 `gdb-restore-windows' - to restore the layout if its lost. | |
119 `gdb-quit' - to delete (most) of the buffers used by gdb." | |
120 | |
121 (interactive (list (gud-query-cmdline 'gdba))) | |
122 | |
123 (gdba-common-init command-line nil | |
124 'gdba-marker-filter 'gud-gdb-find-file) | |
125 | |
126 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
127 | |
128 ; (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.") | |
129 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set breakpoint at current line.") | |
130 ; (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line") | |
131 (gud-def gud-run "run" nil "Run the program.") | |
132 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.") | |
133 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.") | |
134 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).") | |
135 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.") | |
136 (gud-def gud-cont "cont" "\C-r" "Continue with display.") | |
137 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") | |
138 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") | |
139 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.") | |
140 (gud-def gud-goto "until %f:%l" "\C-u" "Continue up to current line.") | |
141 | |
142 (define-key gud-mode-map "\C-c\C-b" 'gud-break) | |
143 (define-key global-map "\C-x\C-a\C-b" 'gud-break) | |
144 | |
145 (define-key gud-mode-map "\C-c\C-d" 'gud-remove) | |
146 (define-key global-map "\C-x\C-a\C-d" 'gud-remove) | |
147 | |
148 (local-set-key "\C-i" 'gud-gdb-complete-command) | |
149 | |
150 (setq comint-prompt-regexp "^(.*gdb[+]?) *") | |
151 (setq comint-input-sender 'gdb-send) | |
152 | |
153 ; (re-)initialise | |
154 (setq gdb-main-or-pc "main") | |
155 (setq gdb-current-address nil) | |
156 (setq gdb-display-in-progress nil) | |
157 (setq gdb-dive nil) | |
158 (setq gud-last-last-frame nil) | |
159 | |
160 (run-hooks 'gdb-mode-hook) | |
161 (let ((instance | |
162 (make-gdb-instance (get-buffer-process (current-buffer))))) | |
163 (if gdb-first-time (gdb-clear-inferior-io instance)) | |
164 | |
165 ; find source file and compilation directory here | |
166 (gdb-instance-enqueue-idle-input instance (list "server list\n" | |
167 '(lambda () nil))) | |
168 (gdb-instance-enqueue-idle-input instance (list "server info source\n" | |
169 '(lambda () (gdb-source-info)))))) | |
170 | |
171 (defun gud-break (arg) | |
172 "Set breakpoint at current line or address." | |
173 (interactive "p") | |
174 (if (not (string-equal mode-name "Assembler")) | |
175 (gud-call "break %f:%l" arg) | |
176 ;else | |
177 (save-excursion | |
178 (beginning-of-line) | |
179 (forward-char 2) | |
180 (gud-call "break *%a" arg)))) | |
181 | |
182 (defun gud-remove (arg) | |
183 "Remove breakpoint at current line or address." | |
184 (interactive "p") | |
185 (if (not (string-equal mode-name "Assembler")) | |
186 (gud-call "clear %f:%l" arg) | |
187 ;else | |
188 (save-excursion | |
189 (beginning-of-line) | |
190 (forward-char 2) | |
191 (gud-call "clear *%a" arg)))) | |
192 | |
193 (defun gud-display () | |
194 "Display (possibly dereferenced) C expression at point." | |
195 (interactive) | |
196 (save-excursion | |
197 (let ((expr (gud-find-c-expr))) | |
198 (gdb-instance-enqueue-idle-input | |
199 gdb-buffer-instance | |
200 (list (concat "server whatis " expr "\n") | |
201 `(lambda () (gud-display1 ,expr))))))) | |
202 | |
203 (defun gud-display1 (expr) | |
204 (goto-char (point-min)) | |
205 (if (re-search-forward "\*" nil t) | |
206 (gdb-instance-enqueue-idle-input | |
207 gdb-buffer-instance | |
208 (list (concat "server display* " expr "\n") | |
209 '(lambda () nil))) | |
210 ;else | |
211 (gdb-instance-enqueue-idle-input | |
212 gdb-buffer-instance | |
213 (list (concat "server display " expr "\n") | |
214 '(lambda () nil))))) | |
215 | |
216 | |
217 ;; The completion process filter is installed temporarily to slurp the | |
218 ;; output of GDB up to the next prompt and build the completion list. | |
219 ;; It must also handle annotations. | |
220 (defun gdba-complete-filter (string) | |
221 (gdb-output-burst gdb-buffer-instance string) | |
222 (while (string-match "\n\032\032\\(.*\\)\n" string) | |
223 (setq string (concat (substring string 0 (match-beginning 0)) | |
224 (substring string (match-end 0))))) | |
225 (setq string (concat gud-gdb-complete-string string)) | |
226 (while (string-match "\n" string) | |
227 (setq gud-gdb-complete-list | |
228 (cons (substring string gud-gdb-complete-break (match-beginning 0)) | |
229 gud-gdb-complete-list)) | |
230 (setq string (substring string (match-end 0)))) | |
231 (if (string-match comint-prompt-regexp string) | |
232 (progn | |
233 (setq gud-gdb-complete-in-progress nil) | |
234 string) | |
235 (progn | |
236 (setq gud-gdb-complete-string string) | |
237 ""))) | |
238 | |
239 | |
240 (defun gdba-common-init (command-line massage-args marker-filter &optional find-file) | |
241 | |
242 (let* ((words (split-string command-line)) | |
243 (program (car words)) | |
244 | |
245 ;; Extract the file name from WORDS | |
246 ;; and put t in its place. | |
247 ;; Later on we will put the modified file name arg back there. | |
248 (file-word (let ((w (cdr words))) | |
249 (while (and w (= ?- (aref (car w) 0))) | |
250 (setq w (cdr w))) | |
251 (and w | |
252 (prog1 (car w) | |
253 (setcar w t))))) | |
254 (file-subst | |
255 (and file-word (substitute-in-file-name file-word))) | |
256 | |
257 (args (cdr words)) | |
258 | |
259 ;; If a directory was specified, expand the file name. | |
260 ;; Otherwise, don't expand it, so GDB can use the PATH. | |
261 ;; A file name without directory is literally valid | |
262 ;; only if the file exists in ., and in that case, | |
263 ;; omitting the expansion here has no visible effect. | |
264 (file (and file-word | |
265 (if (file-name-directory file-subst) | |
266 (expand-file-name file-subst) | |
267 file-subst))) | |
268 (filepart (and file-word (file-name-nondirectory file))) | |
269 (buffer-name (concat "*gdb-" filepart "*"))) | |
270 | |
271 (setq gdb-first-time (not (get-buffer-process buffer-name))) | |
272 | |
273 (switch-to-buffer buffer-name) | |
274 ;; Set default-directory to the file's directory. | |
275 (and file-word | |
276 gud-chdir-before-run | |
277 ;; Don't set default-directory if no directory was specified. | |
278 ;; In that case, either the file is found in the current directory, | |
279 ;; in which case this setq is a no-op, | |
280 ;; or it is found by searching PATH, | |
281 ;; in which case we don't know what directory it was found in. | |
282 (file-name-directory file) | |
283 (setq default-directory (file-name-directory file))) | |
284 (or (bolp) (newline)) | |
285 (insert "Current directory is " default-directory "\n") | |
286 ;; Put the substituted and expanded file name back in its place. | |
287 (let ((w args)) | |
288 (while (and w (not (eq (car w) t))) | |
289 (setq w (cdr w))) | |
290 (if w | |
291 (setcar w file))) | |
292 (let ((old-instance gdb-buffer-instance)) | |
293 (apply 'make-comint (concat "gdb-" filepart) program nil args) | |
294 (gud-mode) | |
295 (make-variable-buffer-local 'old-gdb-buffer-instance) | |
296 (setq old-gdb-buffer-instance old-instance)) | |
297 (setq gdb-target-name filepart)) | |
298 (make-local-variable 'gud-marker-filter) | |
299 (setq gud-marker-filter marker-filter) | |
300 (if find-file (set (make-local-variable 'gud-find-file) find-file)) | |
301 | |
302 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter) | |
303 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel) | |
304 (gud-set-buffer)) | |
305 | |
306 | |
307 ;; ====================================================================== | |
308 ;; | |
309 ;; In this world, there are gdb instance objects (of unspecified | |
310 ;; representation) and buffers associated with those objects. | |
311 ;; | |
312 | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
313 ;; |
48292 | 314 ;; gdb-instance objects |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
315 ;; |
48292 | 316 |
317 (defun make-gdb-instance (proc) | |
318 "Create a gdb instance object from a gdb process." | |
319 (let ((instance (cons 'gdb-instance proc))) | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
320 (with-current-buffer (process-buffer proc) |
48292 | 321 (setq gdb-buffer-instance instance) |
322 (progn | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
323 (mapc 'make-local-variable gdb-instance-variables) |
48292 | 324 (setq gdb-buffer-type 'gdba) |
325 ;; If we're taking over the buffer of another process, | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
326 ;; take over it's ancillary buffers as well. |
48292 | 327 ;; |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
328 (let ((dead old-gdb-buffer-instance)) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
329 (dolist (b (buffer-list)) |
48292 | 330 (set-buffer b) |
331 (if (eq dead gdb-buffer-instance) | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
332 (setq gdb-buffer-instance instance)))))) |
48292 | 333 instance)) |
334 | |
335 (defun gdb-instance-process (inst) (cdr inst)) | |
336 | |
337 ;;; The list of instance variables is built up by the expansions of | |
338 ;;; DEF-GDB-VARIABLE | |
339 ;;; | |
340 (defvar gdb-instance-variables '() | |
341 "A list of variables that are local to the GUD buffer associated | |
342 with a gdb instance.") | |
343 | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
344 (defmacro def-gdb-variable (name accessor setter &optional default doc) |
48292 | 345 `(progn |
346 (defvar ,name ,default ,(or doc "undocumented")) | |
347 (if (not (memq ',name gdb-instance-variables)) | |
348 (setq gdb-instance-variables | |
349 (cons ',name gdb-instance-variables))) | |
350 ,(and accessor | |
351 `(defun ,accessor (instance) | |
352 (let | |
353 ((buffer (gdb-get-instance-buffer instance 'gdba))) | |
354 (and buffer | |
355 (save-excursion | |
356 (set-buffer buffer) | |
357 ,name))))) | |
358 ,(and setter | |
359 `(defun ,setter (instance val) | |
360 (let | |
361 ((buffer (gdb-get-instance-buffer instance 'gdba))) | |
362 (and buffer | |
363 (save-excursion | |
364 (set-buffer buffer) | |
365 (setq ,name val)))))))) | |
366 | |
367 (defmacro def-gdb-var (root-symbol &optional default doc) | |
368 (let* ((root (symbol-name root-symbol)) | |
369 (accessor (intern (concat "gdb-instance-" root))) | |
370 (setter (intern (concat "set-gdb-instance-" root))) | |
371 (var-name (intern (concat "gdb-" root)))) | |
372 `(def-gdb-variable | |
373 ,var-name ,accessor ,setter | |
374 ,default ,doc))) | |
375 | |
376 (def-gdb-var buffer-instance nil | |
377 "In an instance buffer, the buffer's instance.") | |
378 | |
379 (def-gdb-var buffer-type nil | |
380 "One of the symbols bound in gdb-instance-buffer-rules") | |
381 | |
382 (def-gdb-var burst "" | |
383 "A string of characters from gdb that have not yet been processed.") | |
384 | |
385 (def-gdb-var input-queue () | |
386 "A list of high priority gdb command objects.") | |
387 | |
388 (def-gdb-var idle-input-queue () | |
389 "A list of low priority gdb command objects.") | |
390 | |
391 (def-gdb-var prompting nil | |
392 "True when gdb is idle with no pending input.") | |
393 | |
394 (def-gdb-var output-sink 'user | |
395 "The disposition of the output of the current gdb command. | |
396 Possible values are these symbols: | |
397 | |
398 user -- gdb output should be copied to the GUD buffer | |
399 for the user to see. | |
400 | |
401 inferior -- gdb output should be copied to the inferior-io buffer | |
402 | |
403 pre-emacs -- output should be ignored util the post-prompt | |
404 annotation is received. Then the output-sink | |
405 becomes:... | |
406 emacs -- output should be collected in the partial-output-buffer | |
407 for subsequent processing by a command. This is the | |
408 disposition of output generated by commands that | |
409 gdb mode sends to gdb on its own behalf. | |
410 post-emacs -- ignore input until the prompt annotation is | |
411 received, then go to USER disposition. | |
412 ") | |
413 | |
414 (def-gdb-var current-item nil | |
415 "The most recent command item sent to gdb.") | |
416 | |
417 (def-gdb-var pending-triggers '() | |
418 "A list of trigger functions that have run later than their output | |
419 handlers.") | |
420 | |
421 (defun in-gdb-instance-context (instance form) | |
422 "Funcall FORM in the GUD buffer of INSTANCE." | |
423 (save-excursion | |
424 (set-buffer (gdb-get-instance-buffer instance 'gdba)) | |
425 (funcall form))) | |
426 | |
427 ;; end of instance vars | |
428 | |
429 ;; | |
430 ;; finding instances | |
431 ;; | |
432 | |
433 (defun gdb-proc->instance (proc) | |
434 (save-excursion | |
435 (set-buffer (process-buffer proc)) | |
436 gdb-buffer-instance)) | |
437 | |
438 (defun gdb-mru-instance-buffer () | |
439 "Return the most recently used (non-auxiliary) GUD buffer." | |
440 (save-excursion | |
441 (gdb-goto-first-gdb-instance (buffer-list)))) | |
442 | |
443 (defun gdb-goto-first-gdb-instance (blist) | |
444 "Use gdb-mru-instance-buffer -- not this." | |
445 (and blist | |
446 (progn | |
447 (set-buffer (car blist)) | |
448 (or (and gdb-buffer-instance | |
449 (eq gdb-buffer-type 'gdba) | |
450 (car blist)) | |
451 (gdb-goto-first-gdb-instance (cdr blist)))))) | |
452 | |
453 (defun buffer-gdb-instance (buf) | |
454 (save-excursion | |
455 (set-buffer buf) | |
456 gdb-buffer-instance)) | |
457 | |
458 (defun gdb-needed-default-instance () | |
459 "Return the most recently used gdb instance or signal an error." | |
460 (let ((buffer (gdb-mru-instance-buffer))) | |
461 (or (and buffer (buffer-gdb-instance buffer)) | |
462 (error "No instance of gdb found")))) | |
463 | |
464 (defun gdb-instance-target-string (instance) | |
465 "The apparent name of the program being debugged by a gdb instance. | |
466 For sure this the root string used in smashing together the gdb | |
467 buffer's name, even if that doesn't happen to be the name of a | |
468 program." | |
469 (in-gdb-instance-context | |
470 instance | |
471 (function (lambda () gdb-target-name)))) | |
472 | |
473 | |
474 | |
475 ;; | |
476 ;; Instance Buffers. | |
477 ;; | |
478 | |
479 ;; More than one buffer can be associated with a gdb instance. | |
480 ;; | |
481 ;; Each buffer has a TYPE -- a symbol that identifies the function | |
482 ;; of that particular buffer. | |
483 ;; | |
484 ;; The usual gdb interaction buffer is given the type `gdb' and | |
485 ;; is constructed specially. | |
486 ;; | |
487 ;; Others are constructed by gdb-get-create-instance-buffer and | |
488 ;; named according to the rules set forth in the gdb-instance-buffer-rules-assoc | |
489 | |
490 (defun gdb-get-instance-buffer (instance key) | |
491 "Return the instance buffer for INSTANCE tagged with type KEY. | |
492 The key should be one of the cars in `gdb-instance-buffer-rules-assoc'." | |
493 (save-excursion | |
494 (gdb-look-for-tagged-buffer instance key (buffer-list)))) | |
495 | |
496 (defun gdb-get-create-instance-buffer (instance key) | |
497 "Create a new gdb instance buffer of the type specified by KEY. | |
498 The key should be one of the cars in `gdb-instance-buffer-rules-assoc'." | |
499 (or (gdb-get-instance-buffer instance key) | |
500 (let* ((rules (assoc key gdb-instance-buffer-rules-assoc)) | |
501 (name (funcall (gdb-rules-name-maker rules) instance)) | |
502 (new (get-buffer-create name))) | |
503 (save-excursion | |
504 (set-buffer new) | |
505 (make-variable-buffer-local 'gdb-buffer-type) | |
506 (setq gdb-buffer-type key) | |
507 (make-variable-buffer-local 'gdb-buffer-instance) | |
508 (setq gdb-buffer-instance instance) | |
509 (if (cdr (cdr rules)) | |
510 (funcall (car (cdr (cdr rules))))) | |
511 new)))) | |
512 | |
513 (defun gdb-rules-name-maker (rules) (car (cdr rules))) | |
514 | |
515 (defun gdb-look-for-tagged-buffer (instance key bufs) | |
516 (let ((retval nil)) | |
517 (while (and (not retval) bufs) | |
518 (set-buffer (car bufs)) | |
519 (if (and (eq gdb-buffer-instance instance) | |
520 (eq gdb-buffer-type key)) | |
521 (setq retval (car bufs))) | |
522 (setq bufs (cdr bufs))) | |
523 retval)) | |
524 | |
525 (defun gdb-instance-buffer-p (buf) | |
526 (save-excursion | |
527 (set-buffer buf) | |
528 (and gdb-buffer-type | |
529 (not (eq gdb-buffer-type 'gdba))))) | |
530 | |
531 ;; | |
532 ;; This assoc maps buffer type symbols to rules. Each rule is a list of | |
533 ;; at least one and possible more functions. The functions have these | |
534 ;; roles in defining a buffer type: | |
535 ;; | |
536 ;; NAME - take an instance, return a name for this type buffer for that | |
537 ;; instance. | |
538 ;; The remaining function(s) are optional: | |
539 ;; | |
540 ;; MODE - called in new new buffer with no arguments, should establish | |
541 ;; the proper mode for the buffer. | |
542 ;; | |
543 | |
544 (defvar gdb-instance-buffer-rules-assoc '()) | |
545 | |
546 (defun gdb-set-instance-buffer-rules (buffer-type &rest rules) | |
547 (let ((binding (assoc buffer-type gdb-instance-buffer-rules-assoc))) | |
548 (if binding | |
549 (setcdr binding rules) | |
550 (setq gdb-instance-buffer-rules-assoc | |
551 (cons (cons buffer-type rules) | |
552 gdb-instance-buffer-rules-assoc))))) | |
553 | |
554 ; GUD buffers are an exception to the rules | |
555 (gdb-set-instance-buffer-rules 'gdba 'error) | |
556 | |
557 ;; | |
558 ;; partial-output buffers | |
559 ;; | |
560 ;; These accumulate output from a command executed on | |
561 ;; behalf of emacs (rather than the user). | |
562 ;; | |
563 | |
564 (gdb-set-instance-buffer-rules 'gdb-partial-output-buffer | |
565 'gdb-partial-output-name) | |
566 | |
567 (defun gdb-partial-output-name (instance) | |
568 (concat "*partial-output-" | |
569 (gdb-instance-target-string instance) | |
570 "*")) | |
571 | |
572 | |
573 (gdb-set-instance-buffer-rules 'gdb-inferior-io | |
574 'gdb-inferior-io-name | |
575 'gdb-inferior-io-mode) | |
576 | |
577 (defun gdb-inferior-io-name (instance) | |
578 (concat "*input/output of " | |
579 (gdb-instance-target-string instance) | |
580 "*")) | |
581 | |
582 (defvar gdb-inferior-io-mode-map (copy-keymap comint-mode-map)) | |
583 (define-key comint-mode-map "\C-c\C-c" 'gdb-inferior-io-interrupt) | |
584 (define-key comint-mode-map "\C-c\C-z" 'gdb-inferior-io-stop) | |
585 (define-key comint-mode-map "\C-c\C-\\" 'gdb-inferior-io-quit) | |
586 (define-key comint-mode-map "\C-c\C-d" 'gdb-inferior-io-eof) | |
587 | |
588 (defun gdb-inferior-io-mode () | |
589 "Major mode for gdb inferior-io. | |
590 | |
591 \\{comint-mode-map}" | |
592 ;; We want to use comint because it has various nifty and familiar | |
593 ;; features. We don't need a process, but comint wants one, so create | |
594 ;; a dummy one. | |
595 (make-comint (substring (buffer-name) 1 (- (length (buffer-name)) 1)) | |
596 "/bin/cat") | |
597 (setq major-mode 'gdb-inferior-io-mode) | |
598 (setq mode-name "Debuggee I/O") | |
599 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
600 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
601 (setq comint-input-sender 'gdb-inferior-io-sender)) | |
602 | |
603 (defun gdb-inferior-io-sender (proc string) | |
604 (save-excursion | |
605 (set-buffer (process-buffer proc)) | |
606 (let ((instance gdb-buffer-instance)) | |
607 (set-buffer (gdb-get-instance-buffer instance 'gdba)) | |
608 (let ((gdb-proc (get-buffer-process (current-buffer)))) | |
609 (process-send-string gdb-proc string) | |
610 (process-send-string gdb-proc "\n"))))) | |
611 | |
612 (defun gdb-inferior-io-interrupt (instance) | |
613 "Interrupt the program being debugged." | |
614 (interactive (list (gdb-needed-default-instance))) | |
615 (interrupt-process | |
616 (get-buffer-process (gdb-get-instance-buffer instance 'gdba)) comint-ptyp)) | |
617 | |
618 (defun gdb-inferior-io-quit (instance) | |
619 "Send quit signal to the program being debugged." | |
620 (interactive (list (gdb-needed-default-instance))) | |
621 (quit-process | |
622 (get-buffer-process (gdb-get-instance-buffer instance 'gdba)) comint-ptyp)) | |
623 | |
624 (defun gdb-inferior-io-stop (instance) | |
625 "Stop the program being debugged." | |
626 (interactive (list (gdb-needed-default-instance))) | |
627 (stop-process | |
628 (get-buffer-process (gdb-get-instance-buffer instance 'gdba)) comint-ptyp)) | |
629 | |
630 (defun gdb-inferior-io-eof (instance) | |
631 "Send end-of-file to the program being debugged." | |
632 (interactive (list (gdb-needed-default-instance))) | |
633 (process-send-eof | |
634 (get-buffer-process (gdb-get-instance-buffer instance 'gdba)))) | |
635 | |
636 | |
637 ;; | |
638 ;; gdb communications | |
639 ;; | |
640 | |
641 ;; INPUT: things sent to gdb | |
642 ;; | |
643 ;; Each instance has a high and low priority | |
644 ;; input queue. Low priority input is sent only | |
645 ;; when the high priority queue is idle. | |
646 ;; | |
647 ;; The queues are lists. Each element is either | |
648 ;; a string (indicating user or user-like input) | |
649 ;; or a list of the form: | |
650 ;; | |
651 ;; (INPUT-STRING HANDLER-FN) | |
652 ;; | |
653 ;; | |
654 ;; The handler function will be called from the | |
655 ;; partial-output buffer when the command completes. | |
656 ;; This is the way to write commands which | |
657 ;; invoke gdb commands autonomously. | |
658 ;; | |
659 ;; These lists are consumed tail first. | |
660 ;; | |
661 | |
662 (defun gdb-send (proc string) | |
663 "A comint send filter for gdb. | |
664 This filter may simply queue output for a later time." | |
665 (let ((instance (gdb-proc->instance proc))) | |
666 (gdb-instance-enqueue-input instance (concat string "\n")))) | |
667 | |
668 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it | |
669 ;; is a query, or other non-top-level prompt. To guarantee stuff will get | |
670 ;; sent to the top-level prompt, currently it must be put in the idle queue. | |
671 ;; ^^^^^^^^^ | |
672 ;; [This should encourage gdb extensions that invoke gdb commands to let | |
673 ;; the user go first; it is not a bug. -t] | |
674 ;; | |
675 | |
676 (defun gdb-instance-enqueue-input (instance item) | |
677 (if (gdb-instance-prompting instance) | |
678 (progn | |
679 (gdb-send-item instance item) | |
680 (set-gdb-instance-prompting instance nil)) | |
681 (set-gdb-instance-input-queue | |
682 instance | |
683 (cons item (gdb-instance-input-queue instance))))) | |
684 | |
685 (defun gdb-instance-dequeue-input (instance) | |
686 (let ((queue (gdb-instance-input-queue instance))) | |
687 (and queue | |
688 (if (not (cdr queue)) | |
689 (let ((answer (car queue))) | |
690 (set-gdb-instance-input-queue instance '()) | |
691 answer) | |
692 (gdb-take-last-elt queue))))) | |
693 | |
694 (defun gdb-instance-enqueue-idle-input (instance item) | |
695 (if (and (gdb-instance-prompting instance) | |
696 (not (gdb-instance-input-queue instance))) | |
697 (progn | |
698 (gdb-send-item instance item) | |
699 (set-gdb-instance-prompting instance nil)) | |
700 (set-gdb-instance-idle-input-queue | |
701 instance | |
702 (cons item (gdb-instance-idle-input-queue instance))))) | |
703 | |
704 (defun gdb-instance-dequeue-idle-input (instance) | |
705 (let ((queue (gdb-instance-idle-input-queue instance))) | |
706 (and queue | |
707 (if (not (cdr queue)) | |
708 (let ((answer (car queue))) | |
709 (set-gdb-instance-idle-input-queue instance '()) | |
710 answer) | |
711 (gdb-take-last-elt queue))))) | |
712 | |
713 ; Don't use this in general. | |
714 (defun gdb-take-last-elt (l) | |
715 (if (cdr (cdr l)) | |
716 (gdb-take-last-elt (cdr l)) | |
717 (let ((answer (car (cdr l)))) | |
718 (setcdr l '()) | |
719 answer))) | |
720 | |
721 | |
722 ;; | |
723 ;; output -- things gdb prints to emacs | |
724 ;; | |
725 ;; GDB output is a stream interrupted by annotations. | |
726 ;; Annotations can be recognized by their beginning | |
727 ;; with \C-j\C-z\C-z<tag><opt>\C-j | |
728 ;; | |
729 ;; The tag is a string obeying symbol syntax. | |
730 ;; | |
731 ;; The optional part `<opt>' can be either the empty string | |
732 ;; or a space followed by more data relating to the annotation. | |
733 ;; For example, the SOURCE annotation is followed by a filename, | |
734 ;; line number and various useless goo. This data must not include | |
735 ;; any newlines. | |
736 ;; | |
737 | |
738 (defcustom gud-gdba-command-name "gdb -annotate=2" | |
739 "Default command to execute an executable under the GDB debugger (gdb-ui.el)." | |
740 :type 'string | |
741 :group 'gud) | |
742 | |
743 (defun gdba-marker-filter (string) | |
744 "A gud marker filter for gdb." | |
745 ;; Bogons don't tell us the process except through scoping crud. | |
746 (let ((instance (gdb-proc->instance proc))) | |
747 (gdb-output-burst instance string))) | |
748 | |
749 (defvar gdb-annotation-rules | |
750 '(("frames-invalid" gdb-invalidate-frame-and-assembler) | |
751 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler) | |
752 ("pre-prompt" gdb-pre-prompt) | |
753 ("prompt" gdb-prompt) | |
754 ("commands" gdb-subprompt) | |
755 ("overload-choice" gdb-subprompt) | |
756 ("query" gdb-subprompt) | |
757 ("prompt-for-continue" gdb-subprompt) | |
758 ("post-prompt" gdb-post-prompt) | |
759 ("source" gdb-source) | |
760 ("starting" gdb-starting) | |
761 ("exited" gdb-stopping) | |
762 ("signalled" gdb-stopping) | |
763 ("signal" gdb-stopping) | |
764 ("breakpoint" gdb-stopping) | |
765 ("watchpoint" gdb-stopping) | |
766 ("frame-begin" gdb-frame-begin) | |
767 ("stopped" gdb-stopped) | |
768 ("display-begin" gdb-display-begin) | |
769 ("display-end" gdb-display-end) | |
770 ("display-number-end" gdb-display-number-end) | |
771 ("array-section-begin" gdb-array-section-begin) | |
772 ("array-section-end" gdb-array-section-end) | |
773 ; ("elt" gdb-elt) | |
774 ("field-begin" gdb-field-begin) | |
775 ("field-end" gdb-field-end) | |
776 ) "An assoc mapping annotation tags to functions which process them.") | |
777 | |
778 (defun gdb-ignore-annotation (instance args) | |
779 nil) | |
780 | |
781 (defconst gdb-source-spec-regexp | |
782 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:\\(0x[a-f0-9]*\\)") | |
783 | |
784 ;; Do not use this except as an annotation handler." | |
785 (defun gdb-source (instance args) | |
786 (string-match gdb-source-spec-regexp args) | |
787 ;; Extract the frame position from the marker. | |
788 (setq gud-last-frame | |
789 (cons | |
790 (substring args (match-beginning 1) (match-end 1)) | |
791 (string-to-int (substring args | |
792 (match-beginning 2) | |
793 (match-end 2))))) | |
794 (setq gdb-current-address (substring args (match-beginning 3) | |
795 (match-end 3))) | |
796 (setq gdb-main-or-pc gdb-current-address) | |
797 ;update with new frame for machine code if necessary | |
798 (gdb-invalidate-assembler instance)) | |
799 | |
800 ;; An annotation handler for `prompt'. | |
801 ;; This sends the next command (if any) to gdb. | |
802 (defun gdb-prompt (instance ignored) | |
803 (let ((sink (gdb-instance-output-sink instance))) | |
804 (cond | |
805 ((eq sink 'user) t) | |
806 ((eq sink 'post-emacs) | |
807 (set-gdb-instance-output-sink instance 'user)) | |
808 (t | |
809 (set-gdb-instance-output-sink instance 'user) | |
810 (error "Phase error in gdb-prompt (got %s)" sink)))) | |
811 (let ((highest (gdb-instance-dequeue-input instance))) | |
812 (if highest | |
813 (gdb-send-item instance highest) | |
814 (let ((lowest (gdb-instance-dequeue-idle-input instance))) | |
815 (if lowest | |
816 (gdb-send-item instance lowest) | |
817 (progn | |
818 (set-gdb-instance-prompting instance t) | |
819 (gud-display-frame))))))) | |
820 | |
821 ;; An annotation handler for non-top-level prompts. | |
822 (defun gdb-subprompt (instance ignored) | |
823 (let ((highest (gdb-instance-dequeue-input instance))) | |
824 (if highest | |
825 (gdb-send-item instance highest) | |
826 (set-gdb-instance-prompting instance t)))) | |
827 | |
828 (defun gdb-send-item (instance item) | |
829 (set-gdb-instance-current-item instance item) | |
830 (if (stringp item) | |
831 (progn | |
832 (set-gdb-instance-output-sink instance 'user) | |
833 (process-send-string (gdb-instance-process instance) | |
834 item)) | |
835 (progn | |
836 (gdb-clear-partial-output instance) | |
837 (set-gdb-instance-output-sink instance 'pre-emacs) | |
838 (process-send-string (gdb-instance-process instance) | |
839 (car item))))) | |
840 | |
841 ;; An annotation handler for `pre-prompt'. | |
842 ;; This terminates the collection of output from a previous | |
843 ;; command if that happens to be in effect. | |
844 (defun gdb-pre-prompt (instance ignored) | |
845 (let ((sink (gdb-instance-output-sink instance))) | |
846 (cond | |
847 ((eq sink 'user) t) | |
848 ((eq sink 'emacs) | |
849 (set-gdb-instance-output-sink instance 'post-emacs) | |
850 (let ((handler | |
851 (car (cdr (gdb-instance-current-item instance))))) | |
852 (save-excursion | |
853 (set-buffer (gdb-get-create-instance-buffer | |
854 instance 'gdb-partial-output-buffer)) | |
855 (funcall handler)))) | |
856 (t | |
857 (set-gdb-instance-output-sink instance 'user) | |
858 (error "Output sink phase error 1"))))) | |
859 | |
860 ;; An annotation handler for `starting'. This says that I/O for the subprocess | |
861 ;; is now the program being debugged, not GDB. | |
862 (defun gdb-starting (instance ignored) | |
863 (let ((sink (gdb-instance-output-sink instance))) | |
864 (cond | |
865 ((eq sink 'user) | |
866 (set-gdb-instance-output-sink instance 'inferior)) | |
867 (t (error "Unexpected `starting' annotation"))))) | |
868 | |
869 ;; An annotation handler for `exited' and other annotations which say that | |
870 ;; I/O for the subprocess is now GDB, not the program being debugged. | |
871 (defun gdb-stopping (instance ignored) | |
872 (let ((sink (gdb-instance-output-sink instance))) | |
873 (cond | |
874 ((eq sink 'inferior) | |
875 (set-gdb-instance-output-sink instance 'user)) | |
876 (t (error "Unexpected stopping annotation"))))) | |
877 | |
878 ;; An annotation handler for `stopped'. It is just like gdb-stopping, except | |
879 ;; that if we already set the output sink to 'user in gdb-stopping, that is | |
880 ;; fine. | |
881 (defun gdb-stopped (instance ignored) | |
882 (let ((sink (gdb-instance-output-sink instance))) | |
883 (cond | |
884 ((eq sink 'inferior) | |
885 (set-gdb-instance-output-sink instance 'user)) | |
886 ((eq sink 'user) t) | |
887 (t (error "Unexpected stopped annotation"))))) | |
888 | |
889 (defun gdb-frame-begin (instance ignored) | |
890 (let ((sink (gdb-instance-output-sink instance))) | |
891 (cond | |
892 ((eq sink 'inferior) | |
893 (set-gdb-instance-output-sink instance 'user)) | |
894 ((eq sink 'user) t) | |
895 ((eq sink 'emacs) t) | |
896 (t (error "Unexpected frame-begin annotation (%S)" sink))))) | |
897 | |
898 ;; An annotation handler for `post-prompt'. | |
899 ;; This begins the collection of output from the current | |
900 ;; command if that happens to be appropriate." | |
901 (defun gdb-post-prompt (instance ignored) | |
902 (if (not (gdb-instance-pending-triggers instance)) | |
903 (progn | |
904 (gdb-invalidate-registers instance ignored) | |
905 (gdb-invalidate-locals instance ignored) | |
906 (gdb-invalidate-display instance ignored))) | |
907 (let ((sink (gdb-instance-output-sink instance))) | |
908 (cond | |
909 ((eq sink 'user) t) | |
910 ((eq sink 'pre-emacs) | |
911 (set-gdb-instance-output-sink instance 'emacs)) | |
912 | |
913 (t | |
914 (set-gdb-instance-output-sink instance 'user) | |
915 (error "Output sink phase error 3"))))) | |
916 | |
917 ;; If we get an error whilst evaluating one of the expressions | |
918 ;; we won't get the display-end annotation. Set the sink back to | |
919 ;; user to make sure that the error message is seen | |
920 | |
921 (defun gdb-error-begin (instance ignored) | |
922 (set-gdb-instance-output-sink instance 'user)) | |
923 | |
924 (defun gdb-display-begin (instance ignored) | |
925 (if (gdb-get-instance-buffer instance 'gdb-display-buffer) | |
926 (progn | |
927 (set-gdb-instance-output-sink instance 'emacs) | |
928 (gdb-clear-partial-output instance) | |
929 (setq gdb-display-in-progress t)) | |
930 (set-gdb-instance-output-sink instance 'user))) | |
931 | |
932 (defun gdb-display-number-end (instance ignored) | |
933 (set-buffer (gdb-get-instance-buffer | |
934 instance 'gdb-partial-output-buffer)) | |
935 (setq gdb-display-number (buffer-string)) | |
936 (setq gdb-expression-buffer-name | |
937 (concat "*display " gdb-display-number "*")) | |
938 (save-excursion | |
939 (if (progn | |
940 (set-buffer (window-buffer)) | |
941 gdb-dive) | |
942 (progn | |
943 (let ((number gdb-display-number)) | |
944 (switch-to-buffer | |
945 (set-buffer (get-buffer-create gdb-expression-buffer-name))) | |
946 (gdb-expressions-mode) | |
947 (setq gdb-dive-display-number number))) | |
948 ;else | |
949 (set-buffer (get-buffer-create gdb-expression-buffer-name)) | |
950 (if (and (display-graphic-p) (not gdb-dive)) | |
951 (catch 'frame-exists | |
952 (let ((frames (frame-list))) | |
953 (while frames | |
954 (if (string-equal (frame-parameter (car frames) 'name) | |
955 gdb-expression-buffer-name) | |
956 (throw 'frame-exists nil)) | |
957 (setq frames (cdr frames))) | |
958 (if (not frames) | |
959 (progn | |
960 (gdb-expressions-mode) | |
961 (make-frame '((height . 20) (width . 40) | |
962 (tool-bar-lines . nil) | |
963 (menu-bar-lines . nil) | |
964 (minibuffer . nil)))))))))) | |
965 (set-buffer (gdb-get-instance-buffer | |
966 instance 'gdb-partial-output-buffer)) | |
967 (setq gdb-dive nil)) | |
968 | |
969 (defun gdb-display-end (instance ignored) | |
970 (set-buffer (gdb-get-instance-buffer instance 'gdb-partial-output-buffer)) | |
971 (goto-char (point-min)) | |
972 (search-forward ": ") | |
973 (looking-at "\\(.*?\\) =") | |
974 (let ((char "") | |
975 (gdb-temp-value (buffer-substring (match-beginning 1) | |
976 (match-end 1)))) | |
977 ;move * to front of expression if necessary | |
978 (if (looking-at ".*\\*") | |
979 (progn | |
980 (setq char "*") | |
981 (setq gdb-temp-value (substring gdb-temp-value 1 nil)))) | |
982 (save-excursion | |
983 (set-buffer gdb-expression-buffer-name) | |
984 (setq gdb-expression gdb-temp-value) | |
985 (if (not (string-match "::" gdb-expression)) | |
986 (setq gdb-expression (concat char gdb-current-frame | |
987 "::" gdb-expression)) | |
988 ;else put * back on if necessary | |
989 (setq gdb-expression (concat char gdb-expression))) | |
990 (setq header-line-format (concat "-- " gdb-expression " %-")))) | |
991 | |
992 ;-if scalar/string | |
993 (if (not (re-search-forward "##" nil t)) | |
994 (progn | |
995 (save-excursion | |
996 (set-buffer gdb-expression-buffer-name) | |
997 (setq buffer-read-only nil) | |
998 (delete-region (point-min) (point-max)) | |
999 (insert-buffer (gdb-get-instance-buffer | |
1000 instance 'gdb-partial-output-buffer)) | |
1001 (setq buffer-read-only t))) | |
1002 ; else | |
1003 ; display expression name... | |
1004 (goto-char (point-min)) | |
1005 (let ((start (progn (point))) | |
1006 (end (progn (end-of-line) (point)))) | |
1007 (save-excursion | |
1008 (set-buffer gdb-expression-buffer-name) | |
1009 (setq buffer-read-only nil) | |
1010 (delete-region (point-min) (point-max)) | |
1011 (insert-buffer-substring (gdb-get-instance-buffer | |
1012 gdb-buffer-instance | |
1013 'gdb-partial-output-buffer) | |
1014 start end) | |
1015 (insert "\n"))) | |
1016 | |
1017 (goto-char (point-min)) | |
1018 (re-search-forward "##" nil t) | |
1019 (setq gdb-nesting-level 0) | |
1020 (if (looking-at "array-section-begin") | |
1021 (progn | |
1022 (gdb-delete-line) | |
1023 (beginning-of-line) | |
1024 (setq gdb-point (point)) | |
1025 (gdb-array-format))) | |
1026 (if (looking-at "field-begin \\(.\\)") | |
1027 (progn | |
1028 (setq gdb-annotation-arg (buffer-substring (match-beginning 1) | |
1029 (match-end 1))) | |
1030 (gdb-field-format-begin)))) | |
1031 (save-excursion | |
1032 (set-buffer gdb-expression-buffer-name) | |
1033 (if gdb-dive-display-number | |
1034 (progn | |
1035 (setq buffer-read-only nil) | |
1036 (goto-char (point-max)) | |
1037 (insert "\n") | |
1038 (insert-text-button "[back]" 'type 'gdb-display-back) | |
1039 (setq buffer-read-only t)))) | |
1040 (gdb-clear-partial-output instance) | |
1041 (set-gdb-instance-output-sink instance 'user) | |
1042 (setq gdb-display-in-progress nil)) | |
1043 | |
1044 (define-button-type 'gdb-display-back | |
1045 'help-echo (purecopy "mouse-2, RET: go back to previous display buffer") | |
1046 'action (lambda (button) (gdb-display-go-back))) | |
1047 | |
1048 (defun gdb-display-go-back () | |
1049 ; delete display so they don't accumulate and delete buffer | |
1050 (let ((number gdb-display-number)) | |
1051 (gdb-instance-enqueue-idle-input | |
1052 gdb-buffer-instance | |
1053 (list (concat "server delete display " number "\n") | |
1054 '(lambda () nil))) | |
1055 (switch-to-buffer (concat "*display " gdb-dive-display-number "*")) | |
1056 (kill-buffer (get-buffer (concat "*display " number "*"))))) | |
1057 | |
1058 ; prefix annotations with ## and process whole output in one chunk | |
1059 ; in gdb-partial-output-buffer (to allow recursion). | |
1060 | |
1061 ; array-section flags are just removed again but after counting. They | |
1062 ; might also be useful for arrays of structures and structures with arrays. | |
1063 (defun gdb-array-section-begin (instance args) | |
1064 (if gdb-display-in-progress | |
1065 (progn | |
1066 (save-excursion | |
1067 (set-buffer (gdb-get-instance-buffer | |
1068 instance 'gdb-partial-output-buffer)) | |
1069 (goto-char (point-max)) | |
1070 (insert (concat "\n##array-section-begin " args "\n")))))) | |
1071 | |
1072 (defun gdb-array-section-end (instance ignored) | |
1073 (if gdb-display-in-progress | |
1074 (progn | |
1075 (save-excursion | |
1076 (set-buffer (gdb-get-instance-buffer | |
1077 instance 'gdb-partial-output-buffer)) | |
1078 (goto-char (point-max)) | |
1079 (insert "\n##array-section-end\n"))))) | |
1080 | |
1081 (defun gdb-field-begin (instance args) | |
1082 (if gdb-display-in-progress | |
1083 (progn | |
1084 (save-excursion | |
1085 (set-buffer (gdb-get-instance-buffer | |
1086 instance 'gdb-partial-output-buffer)) | |
1087 (goto-char (point-max)) | |
1088 (insert (concat "\n##field-begin " args "\n")))))) | |
1089 | |
1090 (defun gdb-field-end (instance ignored) | |
1091 (if gdb-display-in-progress | |
1092 (progn | |
1093 (save-excursion | |
1094 (set-buffer (gdb-get-instance-buffer | |
1095 instance 'gdb-partial-output-buffer)) | |
1096 (goto-char (point-max)) | |
1097 (insert "\n##field-end\n"))))) | |
1098 | |
1099 (defun gdb-elt (instance ignored) | |
1100 (if gdb-display-in-progress | |
1101 (progn | |
1102 (goto-char (point-max)) | |
1103 (insert "\n##elt\n")))) | |
1104 | |
1105 (defun gdb-field-format-begin () | |
1106 ; get rid of ##field-begin | |
1107 (gdb-delete-line) | |
1108 (gdb-insert-field) | |
1109 (setq gdb-nesting-level (+ gdb-nesting-level 1)) | |
1110 (while (re-search-forward "##" nil t) | |
1111 ; keep making recursive calls... | |
1112 (if (looking-at "field-begin \\(.\\)") | |
1113 (progn | |
1114 (setq gdb-annotation-arg (buffer-substring (match-beginning 1) | |
1115 (match-end 1))) | |
1116 (gdb-field-format-begin))) | |
1117 ; until field-end. | |
1118 (if (looking-at "field-end") (gdb-field-format-end)))) | |
1119 | |
1120 (defun gdb-field-format-end () | |
1121 ; get rid of ##field-end and `,' or `}' | |
1122 (gdb-delete-line) | |
1123 (gdb-delete-line) | |
1124 (setq gdb-nesting-level (- gdb-nesting-level 1))) | |
1125 | |
1126 (defun gdb-insert-field () | |
1127 (let ((start (progn (point))) | |
1128 (end (progn (next-line) (point))) | |
1129 (num 0)) | |
1130 (save-excursion | |
1131 (set-buffer gdb-expression-buffer-name) | |
1132 (setq buffer-read-only nil) | |
1133 (if (string-equal gdb-annotation-arg "\*") (insert "\*")) | |
1134 (while (<= num gdb-nesting-level) | |
1135 (insert "\t") | |
1136 (setq num (+ num 1))) | |
1137 (insert-buffer-substring (gdb-get-instance-buffer | |
1138 gdb-buffer-instance | |
1139 'gdb-partial-output-buffer) | |
1140 start end) | |
1141 (put-text-property (- (point) (- end start)) (- (point) 1) | |
1142 'mouse-face 'highlight) | |
1143 (put-text-property (- (point) (- end start)) (- (point) 1) | |
1144 'local-map gdb-dive-map) | |
1145 (setq buffer-read-only t)) | |
1146 (delete-region start end))) | |
1147 | |
1148 (defun gdb-array-format () | |
1149 (while (re-search-forward "##" nil t) | |
1150 ; keep making recursive calls... | |
1151 (if (looking-at "array-section-begin") | |
1152 (progn | |
1153 ;get rid of ##array-section-begin | |
1154 (gdb-delete-line) | |
1155 (setq gdb-nesting-level (+ gdb-nesting-level 1)) | |
1156 (gdb-array-format))) | |
1157 ;until *matching* array-section-end is found | |
1158 (if (looking-at "array-section-end") | |
1159 (if (eq gdb-nesting-level 0) | |
1160 (progn | |
1161 (let ((values (buffer-substring gdb-point (- (point) 2)))) | |
1162 (save-excursion | |
1163 (set-buffer gdb-expression-buffer-name) | |
1164 (setq gdb-values | |
1165 (concat "{" (replace-regexp-in-string "\n" "" values) | |
1166 "}")) | |
1167 (gdb-array-format1)))) | |
1168 ;else get rid of ##array-section-end etc | |
1169 (gdb-delete-line) | |
1170 (setq gdb-nesting-level (- gdb-nesting-level 1)) | |
1171 (gdb-array-format))))) | |
1172 | |
1173 (defun gdb-array-format1 () | |
1174 (setq gdb-display-string "") | |
1175 (setq buffer-read-only nil) | |
1176 (delete-region (point-min) (point-max)) | |
1177 (let ((gdb-value-list (split-string gdb-values ", "))) | |
1178 (string-match "\\({+\\)" (car gdb-value-list)) | |
1179 (let* ((depth (- (match-end 1) (match-beginning 1))) | |
1180 (indices (make-vector depth '0)) | |
1181 (index 0) (num 0) (array-start "") | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
1182 (array-stop "") (array-slice "") (array-range nil) |
48292 | 1183 (flag t) (indices-string "")) |
1184 (while gdb-value-list | |
1185 (string-match "{*\\([^}]*\\)\\(}*\\)" (car gdb-value-list)) | |
1186 (setq num 0) | |
1187 (while (< num depth) | |
1188 (setq indices-string | |
1189 (concat indices-string | |
1190 "[" (int-to-string (aref indices num)) "]")) | |
1191 (if (not (= (aref gdb-array-start num) -1)) | |
1192 (if (or (< (aref indices num) (aref gdb-array-start num)) | |
1193 (> (aref indices num) (aref gdb-array-stop num))) | |
1194 (setq flag nil)) | |
1195 (aset gdb-array-size num (aref indices num))) | |
1196 (setq num (+ num 1))) | |
1197 (if flag | |
1198 (let ((gdb-display-value (substring (car gdb-value-list) | |
1199 (match-beginning 1) | |
1200 (match-end 1)))) | |
1201 (setq gdb-display-string (concat gdb-display-string " " | |
1202 gdb-display-value)) | |
1203 (insert | |
1204 (concat indices-string "\t" gdb-display-value "\n")))) | |
1205 (setq indices-string "") | |
1206 (setq flag t) | |
1207 ; 0<= index < depth, start at right : (- depth 1) | |
1208 (setq index (- (- depth 1) | |
1209 (- (match-end 2) (match-beginning 2)))) | |
1210 ;don't set for very last brackets | |
1211 (if (>= index 0) | |
1212 (progn | |
1213 (aset indices index (+ 1 (aref indices index))) | |
1214 (setq num (+ 1 index)) | |
1215 (while (< num depth) | |
1216 (aset indices num 0) | |
1217 (setq num (+ num 1))))) | |
1218 (setq gdb-value-list (cdr gdb-value-list))) | |
1219 (setq num 0) | |
1220 (while (< num depth) | |
1221 (if (= (aref gdb-array-start num) -1) | |
1222 (progn | |
1223 (aset gdb-array-start num 0) | |
1224 (aset gdb-array-stop num (aref indices num)))) | |
1225 (setq array-start (int-to-string (aref gdb-array-start num))) | |
1226 (setq array-stop (int-to-string (aref gdb-array-stop num))) | |
1227 (setq array-range (concat "[" array-start | |
1228 ":" array-stop "]")) | |
1229 (put-text-property 1 (+ (length array-start) | |
1230 (length array-stop) 2) | |
1231 'mouse-face 'highlight array-range) | |
1232 (put-text-property 1 (+ (length array-start) | |
1233 (length array-stop) 2) | |
1234 'local-map gdb-array-slice-map array-range) | |
1235 (goto-char (point-min)) | |
1236 (setq array-slice (concat array-slice array-range)) | |
1237 (setq num (+ num 1))) | |
1238 (goto-char (point-min)) | |
1239 (insert "Array Size : ") | |
1240 (setq num 0) | |
1241 (while (< num depth) | |
1242 (insert | |
1243 (concat "[" | |
1244 (int-to-string (+ (aref gdb-array-size num) 1)) "]")) | |
1245 (setq num (+ num 1))) | |
1246 (insert | |
1247 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n")))) | |
1248 (setq buffer-read-only t)) | |
1249 | |
1250 (setq gdb-dive-map (make-keymap)) | |
1251 (define-key gdb-dive-map [mouse-2] 'gdb-dive) | |
1252 (define-key gdb-dive-map [S-mouse-2] 'gdb-dive-new-frame) | |
1253 | |
1254 (defun gdb-dive (event) | |
1255 "Dive into structure." | |
1256 (interactive "e") | |
1257 (setq gdb-dive t) | |
1258 (gdb-dive-new-frame event)) | |
1259 | |
1260 (defun gdb-dive-new-frame (event) | |
1261 "Dive into structure and display in a new frame." | |
1262 (interactive "e") | |
1263 (save-excursion | |
1264 (mouse-set-point event) | |
1265 (let ((point (point)) (gdb-full-expression gdb-expression) | |
1266 (end (progn (end-of-line) (point))) | |
1267 (gdb-part-expression "") (gdb-last-field nil) (gdb-display-char nil)) | |
1268 (beginning-of-line) | |
1269 (if (looking-at "\*") (setq gdb-display-char "*")) | |
1270 (re-search-forward "\\(\\S-+\\) = " end t) | |
1271 (setq gdb-last-field (buffer-substring-no-properties | |
1272 (match-beginning 1) | |
1273 (match-end 1))) | |
1274 (goto-char (match-beginning 1)) | |
1275 (let ((last-column (current-column))) | |
1276 (while (re-search-backward "\\s-\\(\\S-+\\) = {" nil t) | |
1277 (goto-char (match-beginning 1)) | |
1278 (if (and (< (current-column) last-column) | |
1279 (> (count-lines 1 (point)) 1)) | |
1280 (progn | |
1281 (setq gdb-part-expression | |
1282 (concat "." (buffer-substring-no-properties | |
1283 (match-beginning 1) | |
1284 (match-end 1)) gdb-part-expression)) | |
1285 (setq last-column (current-column)))))) | |
1286 ; * not needed for components of a pointer to a structure in gdb | |
1287 (if (string-equal "*" (substring gdb-full-expression 0 1)) | |
1288 (setq gdb-full-expression (substring gdb-full-expression 1 nil))) | |
1289 (setq gdb-full-expression | |
1290 (concat gdb-full-expression gdb-part-expression "." gdb-last-field)) | |
1291 (gdb-instance-enqueue-idle-input gdb-buffer-instance | |
1292 (list | |
1293 (concat "server display" gdb-display-char | |
1294 " " gdb-full-expression "\n") | |
1295 '(lambda () nil)))))) | |
1296 | |
1297 ;; Handle a burst of output from a gdb instance. | |
1298 ;; This function is (indirectly) used as a gud-marker-filter. | |
1299 ;; It must return output (if any) to be insterted in the gdb | |
1300 ;; buffer. | |
1301 | |
1302 (defun gdb-output-burst (instance string) | |
1303 "Handle a burst of output from a gdb instance. | |
1304 This function is (indirectly) used as a gud-marker-filter. | |
1305 It must return output (if any) to be insterted in the gdb | |
1306 buffer." | |
1307 | |
1308 (save-match-data | |
1309 (let ( | |
1310 ;; Recall the left over burst from last time | |
1311 (burst (concat (gdb-instance-burst instance) string)) | |
1312 ;; Start accumulating output for the GUD buffer | |
1313 (output "")) | |
1314 | |
1315 ;; Process all the complete markers in this chunk. | |
1316 | |
1317 (while (string-match "\n\032\032\\(.*\\)\n" burst) | |
1318 (let ((annotation (substring burst | |
1319 (match-beginning 1) | |
1320 (match-end 1)))) | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
1321 |
48292 | 1322 ;; Stuff prior to the match is just ordinary output. |
1323 ;; It is either concatenated to OUTPUT or directed | |
1324 ;; elsewhere. | |
1325 (setq output | |
1326 (gdb-concat-output | |
1327 instance | |
1328 output | |
1329 (substring burst 0 (match-beginning 0)))) | |
1330 | |
1331 ;; Take that stuff off the burst. | |
1332 (setq burst (substring burst (match-end 0))) | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
1333 |
48292 | 1334 ;; Parse the tag from the annotation, and maybe its arguments. |
1335 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation) | |
1336 (let* ((annotation-type (substring annotation | |
1337 (match-beginning 1) | |
1338 (match-end 1))) | |
1339 (annotation-arguments (substring annotation | |
1340 (match-beginning 2) | |
1341 (match-end 2))) | |
1342 (annotation-rule (assoc annotation-type | |
1343 gdb-annotation-rules))) | |
1344 ;; Call the handler for this annotation. | |
1345 (if annotation-rule | |
1346 (funcall (car (cdr annotation-rule)) | |
1347 instance | |
1348 annotation-arguments) | |
1349 ;; Else the annotation is not recognized. Ignore it silently, | |
1350 ;; so that GDB can add new annotations without causing | |
1351 ;; us to blow up. | |
1352 )))) | |
1353 | |
1354 | |
1355 ;; Does the remaining text end in a partial line? | |
1356 ;; If it does, then keep part of the burst until we get more. | |
1357 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'" | |
1358 burst) | |
1359 (progn | |
1360 ;; Everything before the potential marker start can be output. | |
1361 (setq output | |
1362 (gdb-concat-output | |
1363 instance | |
1364 output | |
1365 (substring burst 0 (match-beginning 0)))) | |
1366 | |
1367 ;; Everything after, we save, to combine with later input. | |
1368 (setq burst (substring burst (match-beginning 0)))) | |
1369 | |
1370 ;; In case we know the burst contains no partial annotations: | |
1371 (progn | |
1372 (setq output (gdb-concat-output instance output burst)) | |
1373 (setq burst ""))) | |
1374 | |
1375 ;; Save the remaining burst for the next call to this function. | |
1376 (set-gdb-instance-burst instance burst) | |
1377 output))) | |
1378 | |
1379 (defun gdb-concat-output (instance so-far new) | |
1380 (let ((sink (gdb-instance-output-sink instance))) | |
1381 (cond | |
1382 ((eq sink 'user) (concat so-far new)) | |
1383 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far) | |
1384 ((eq sink 'emacs) | |
1385 (gdb-append-to-partial-output instance new) | |
1386 so-far) | |
1387 ((eq sink 'inferior) | |
1388 (gdb-append-to-inferior-io instance new) | |
1389 so-far) | |
1390 (t (error "Bogon output sink %S" sink))))) | |
1391 | |
1392 (defun gdb-append-to-partial-output (instance string) | |
1393 (save-excursion | |
1394 (set-buffer | |
1395 (gdb-get-create-instance-buffer | |
1396 instance 'gdb-partial-output-buffer)) | |
1397 (goto-char (point-max)) | |
1398 (insert string))) | |
1399 | |
1400 (defun gdb-clear-partial-output (instance) | |
1401 (save-excursion | |
1402 (set-buffer | |
1403 (gdb-get-create-instance-buffer | |
1404 instance 'gdb-partial-output-buffer)) | |
1405 (delete-region (point-min) (point-max)))) | |
1406 | |
1407 (defun gdb-append-to-inferior-io (instance string) | |
1408 (save-excursion | |
1409 (set-buffer | |
1410 (gdb-get-create-instance-buffer | |
1411 instance 'gdb-inferior-io)) | |
1412 (goto-char (point-max)) | |
1413 (insert-before-markers string)) | |
1414 (gdb-display-buffer | |
1415 (gdb-get-create-instance-buffer instance | |
1416 'gdb-inferior-io))) | |
1417 | |
1418 (defun gdb-clear-inferior-io (instance) | |
1419 (save-excursion | |
1420 (set-buffer | |
1421 (gdb-get-create-instance-buffer | |
1422 instance 'gdb-inferior-io)) | |
1423 (delete-region (point-min) (point-max)))) | |
1424 | |
1425 | |
1426 | |
1427 ;; One trick is to have a command who's output is always available in | |
1428 ;; a buffer of it's own, and is always up to date. We build several | |
1429 ;; buffers of this type. | |
1430 ;; | |
1431 ;; There are two aspects to this: gdb has to tell us when the output | |
1432 ;; for that command might have changed, and we have to be able to run | |
1433 ;; the command behind the user's back. | |
1434 ;; | |
1435 ;; The idle input queue and the output phasing associated with | |
1436 ;; the instance variable `(gdb-instance-output-sink instance)' help | |
1437 ;; us to run commands behind the user's back. | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
1438 ;; |
48292 | 1439 ;; Below is the code for specificly managing buffers of output from one |
1440 ;; command. | |
1441 ;; | |
1442 | |
1443 | |
1444 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES | |
1445 ;; It adds an idle input for the command we are tracking. It should be the | |
1446 ;; annotation rule binding of whatever gdb sends to tell us this command | |
1447 ;; might have changed it's output. | |
1448 ;; | |
1449 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed. | |
1450 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the | |
1451 ;; input in the input queue (see comment about ``gdb communications'' above). | |
1452 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command output-handler) | |
1453 `(defun ,name (instance &optional ignored) | |
1454 (if (and (,demand-predicate instance) | |
1455 (not (member ',name | |
1456 (gdb-instance-pending-triggers instance)))) | |
1457 (progn | |
1458 (gdb-instance-enqueue-idle-input | |
1459 instance | |
1460 (list ,gdb-command ',output-handler)) | |
1461 (set-gdb-instance-pending-triggers | |
1462 instance | |
1463 (cons ',name | |
1464 (gdb-instance-pending-triggers instance))))))) | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
1465 |
48292 | 1466 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun) |
1467 `(defun ,name () | |
1468 (set-gdb-instance-pending-triggers | |
1469 instance | |
1470 (delq ',trigger | |
1471 (gdb-instance-pending-triggers instance))) | |
1472 (let ((buf (gdb-get-instance-buffer instance | |
1473 ',buf-key))) | |
1474 (and buf | |
1475 (save-excursion | |
1476 (set-buffer buf) | |
1477 (let ((p (point)) | |
1478 (buffer-read-only nil)) | |
1479 (delete-region (point-min) (point-max)) | |
1480 (insert-buffer (gdb-get-create-instance-buffer | |
1481 instance | |
1482 'gdb-partial-output-buffer)) | |
1483 (goto-char p))))) | |
1484 ; put customisation here | |
1485 (,custom-defun))) | |
1486 | |
1487 (defmacro def-gdb-auto-updated-buffer | |
1488 (buffer-key trigger-name gdb-command output-handler-name custom-defun) | |
1489 `(progn | |
1490 (def-gdb-auto-update-trigger ,trigger-name | |
1491 ;; The demand predicate: | |
1492 (lambda (instance) | |
1493 (gdb-get-instance-buffer instance ',buffer-key)) | |
1494 ,gdb-command | |
1495 ,output-handler-name) | |
1496 (def-gdb-auto-update-handler ,output-handler-name | |
1497 ,trigger-name ,buffer-key ,custom-defun))) | |
1498 | |
1499 | |
1500 ;; | |
1501 ;; Breakpoint buffers | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
1502 ;; |
48292 | 1503 ;; These display the output of `info breakpoints'. |
1504 ;; | |
1505 | |
1506 | |
1507 (gdb-set-instance-buffer-rules 'gdb-breakpoints-buffer | |
1508 'gdb-breakpoints-buffer-name | |
1509 'gdb-breakpoints-mode) | |
1510 | |
1511 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer | |
1512 ;; This defines the auto update rule for buffers of type | |
1513 ;; `gdb-breakpoints-buffer'. | |
1514 ;; | |
1515 ;; It defines a function to serve as the annotation handler that | |
1516 ;; handles the `foo-invalidated' message. That function is called: | |
1517 gdb-invalidate-breakpoints | |
1518 | |
1519 ;; To update the buffer, this command is sent to gdb. | |
1520 "server info breakpoints\n" | |
1521 | |
1522 ;; This also defines a function to be the handler for the output | |
1523 ;; from the command above. That function will copy the output into | |
1524 ;; the appropriately typed buffer. That function will be called: | |
1525 gdb-info-breakpoints-handler | |
1526 ;; buffer specific functions | |
1527 gdb-info-breakpoints-custom) | |
1528 | |
1529 ;-put breakpoint icons in relevant margins (even those set in the GUD buffer) | |
1530 (defun gdb-info-breakpoints-custom () | |
1531 (let ((flag)(address)) | |
1532 | |
1533 ; remove all breakpoint-icons in source buffers but not assembler buffer | |
1534 (let ((buffers (buffer-list))) | |
1535 (save-excursion | |
1536 (while buffers | |
1537 (set-buffer (car buffers)) | |
1538 (if (and (eq gud-minor-mode 'gdba) | |
1539 (not (string-match "^\*" (buffer-name)))) | |
1540 (if (display-graphic-p) | |
1541 (remove-images (point-min) (point-max)) | |
1542 (remove-strings (point-min) (point-max)))) | |
1543 (setq buffers (cdr buffers))))) | |
1544 | |
1545 (save-excursion | |
1546 (set-buffer (gdb-get-instance-buffer instance 'gdb-breakpoints-buffer)) | |
1547 (save-excursion | |
1548 (goto-char (point-min)) | |
1549 (while (< (point) (- (point-max) 1)) | |
1550 (forward-line 1) | |
1551 (if (looking-at "[^\t].*breakpoint") | |
1552 (progn | |
1553 (looking-at "\\([0-9]*\\)\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)") | |
1554 (setq flag (char-after (match-beginning 2))) | |
1555 (beginning-of-line) | |
1556 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+") | |
1557 (looking-at "\\(\\S-*\\):\\([0-9]+\\)") | |
1558 (let ((line (buffer-substring (match-beginning 2) | |
1559 (match-end 2))) | |
1560 (file (buffer-substring (match-beginning 1) | |
1561 (match-end 1)))) | |
1562 (save-excursion | |
1563 (set-buffer | |
1564 (if (file-exists-p file) | |
1565 (find-file-noselect file) | |
1566 ;else | |
1567 (find-file-noselect (concat gdb-cdir "/" file)))) | |
1568 (with-current-buffer (current-buffer) | |
1569 (progn | |
1570 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
1571 (set (make-local-variable 'tool-bar-map) | |
1572 gud-tool-bar-map) | |
1573 (set (make-variable-buffer-local 'left-margin-width) 2) | |
1574 (if (get-buffer-window (current-buffer)) | |
1575 (set-window-margins (get-buffer-window | |
1576 (current-buffer)) | |
1577 left-margin-width | |
1578 right-margin-width)))) | |
1579 ; only want one breakpoint icon at each location | |
1580 (save-excursion | |
1581 (goto-line (string-to-number line)) | |
1582 (let ((start (progn (beginning-of-line) (- (point) 1))) | |
1583 (end (progn (end-of-line) (+ (point) 1)))) | |
1584 (if (display-graphic-p) | |
1585 (progn | |
1586 (remove-images start end) | |
1587 (if (eq ?y flag) | |
1588 (put-image breakpoint-enabled-icon (point) | |
1589 "breakpoint icon enabled" | |
1590 'left-margin) | |
1591 (put-image breakpoint-disabled-icon (point) | |
1592 "breakpoint icon disabled" | |
1593 'left-margin))) | |
1594 (remove-strings start end) | |
1595 (if (eq ?y flag) | |
1596 (put-string "B" (point) "enabled" | |
1597 'left-margin) | |
1598 (put-string "b" (point) "disabled" | |
1599 'left-margin))))))))) | |
1600 (end-of-line)))))) | |
1601 | |
1602 (defun gdb-breakpoints-buffer-name (instance) | |
1603 (save-excursion | |
1604 (set-buffer (process-buffer (gdb-instance-process instance))) | |
1605 (concat "*breakpoints of " (gdb-instance-target-string instance) "*"))) | |
1606 | |
1607 (defun gdb-display-breakpoints-buffer (instance) | |
1608 (interactive (list (gdb-needed-default-instance))) | |
1609 (gdb-display-buffer | |
1610 (gdb-get-create-instance-buffer instance | |
1611 'gdb-breakpoints-buffer))) | |
1612 | |
1613 (defun gdb-frame-breakpoints-buffer (instance) | |
1614 (interactive (list (gdb-needed-default-instance))) | |
1615 (switch-to-buffer-other-frame | |
1616 (gdb-get-create-instance-buffer instance | |
1617 'gdb-breakpoints-buffer))) | |
1618 | |
1619 (defvar gdb-breakpoints-mode-map nil) | |
1620 (setq gdb-breakpoints-mode-map (make-keymap)) | |
1621 (suppress-keymap gdb-breakpoints-mode-map) | |
1622 | |
1623 (define-key gdb-breakpoints-mode-map [menu-bar breakpoints] | |
1624 (cons "Breakpoints" (make-sparse-keymap "Breakpoints"))) | |
1625 (define-key gdb-breakpoints-mode-map [menu-bar breakpoints toggle] | |
1626 '("Toggle" . gdb-toggle-bp-this-line)) | |
1627 (define-key gdb-breakpoints-mode-map [menu-bar breakpoints delete] | |
1628 '("Delete" . gdb-delete-bp-this-line)) | |
1629 (define-key gdb-breakpoints-mode-map [menu-bar breakpoints goto] | |
1630 '("Goto" . gdb-goto-bp-this-line)) | |
1631 | |
1632 (define-key gdb-breakpoints-mode-map " " 'gdb-toggle-bp-this-line) | |
1633 (define-key gdb-breakpoints-mode-map "d" 'gdb-delete-bp-this-line) | |
1634 (define-key gdb-breakpoints-mode-map "g" 'gdb-goto-bp-this-line) | |
1635 | |
1636 (defun gdb-breakpoints-mode () | |
1637 "Major mode for gdb breakpoints. | |
1638 | |
1639 \\{gdb-breakpoints-mode-map}" | |
1640 (setq major-mode 'gdb-breakpoints-mode) | |
1641 (setq mode-name "Breakpoints") | |
1642 (use-local-map gdb-breakpoints-mode-map) | |
1643 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
1644 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
1645 (setq buffer-read-only t) | |
1646 (gdb-invalidate-breakpoints gdb-buffer-instance)) | |
1647 | |
1648 (defun gdb-toggle-bp-this-line () | |
1649 (interactive) | |
1650 (save-excursion | |
1651 (beginning-of-line 1) | |
1652 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | |
1653 (error "Not recognized as break/watchpoint line") | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
1654 (gdb-instance-enqueue-idle-input |
48292 | 1655 gdb-buffer-instance |
1656 (list | |
1657 (concat | |
1658 (if (eq ?y (char-after (match-beginning 2))) | |
1659 "server disable " | |
1660 "server enable ") | |
1661 (buffer-substring (match-beginning 0) | |
1662 (match-end 1)) | |
1663 "\n") | |
1664 '(lambda () nil)))))) | |
1665 | |
1666 (defun gdb-delete-bp-this-line () | |
1667 (interactive) | |
1668 (beginning-of-line 1) | |
1669 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | |
1670 (error "Not recognized as break/watchpoint line") | |
1671 (gdb-instance-enqueue-idle-input | |
1672 gdb-buffer-instance | |
1673 (list | |
1674 (concat | |
1675 "server delete " | |
1676 (buffer-substring (match-beginning 0) | |
1677 (match-end 1)) | |
1678 "\n") | |
1679 '(lambda () nil))))) | |
1680 | |
1681 (defun gdb-goto-bp-this-line () | |
1682 "Display the file at the breakpoint specified." | |
1683 (interactive) | |
1684 (save-excursion | |
1685 (beginning-of-line 1) | |
1686 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+") | |
1687 (looking-at "\\(\\S-*\\):\\([0-9]+\\)")) | |
1688 (let ((line (buffer-substring (match-beginning 2) | |
1689 (match-end 2))) | |
1690 (file (buffer-substring (match-beginning 1) | |
1691 (match-end 1)))) | |
1692 (if (file-exists-p file) | |
1693 (set-window-buffer gdb-source-window (find-file-noselect file)) | |
1694 ;else | |
1695 (setq file (concat gdb-cdir "/" file)) | |
1696 (set-window-buffer gdb-source-window (find-file-noselect file))) | |
1697 (goto-line (string-to-number line)))) | |
1698 | |
1699 ;; | |
1700 ;; Frames buffers. These display a perpetually correct bactracktrace | |
1701 ;; (from the command `where'). | |
1702 ;; | |
1703 ;; Alas, if your stack is deep, they are costly. | |
1704 ;; | |
1705 | |
1706 (gdb-set-instance-buffer-rules 'gdb-stack-buffer | |
1707 'gdb-stack-buffer-name | |
1708 'gdb-frames-mode) | |
1709 | |
1710 (def-gdb-auto-updated-buffer gdb-stack-buffer | |
1711 gdb-invalidate-frames | |
1712 "server where\n" | |
1713 gdb-info-frames-handler | |
1714 gdb-info-frames-custom) | |
1715 | |
1716 (defun gdb-info-frames-custom () | |
1717 (save-excursion | |
1718 (set-buffer (gdb-get-instance-buffer instance 'gdb-stack-buffer)) | |
1719 (let ((buffer-read-only nil)) | |
1720 (goto-char (point-min)) | |
1721 (looking-at "\\S-*\\s-*\\(\\S-*\\)") | |
1722 (setq gdb-current-frame (buffer-substring (match-beginning 1) (match-end 1))) | |
1723 (while (< (point) (point-max)) | |
1724 (put-text-property (progn (beginning-of-line) (point)) | |
1725 (progn (end-of-line) (point)) | |
1726 'mouse-face 'highlight) | |
1727 (forward-line 1))))) | |
1728 | |
1729 (defun gdb-stack-buffer-name (instance) | |
1730 (save-excursion | |
1731 (set-buffer (process-buffer (gdb-instance-process instance))) | |
1732 (concat "*stack frames of " | |
1733 (gdb-instance-target-string instance) "*"))) | |
1734 | |
1735 (defun gdb-display-stack-buffer (instance) | |
1736 (interactive (list (gdb-needed-default-instance))) | |
1737 (gdb-display-buffer | |
1738 (gdb-get-create-instance-buffer instance | |
1739 'gdb-stack-buffer))) | |
1740 | |
1741 (defun gdb-frame-stack-buffer (instance) | |
1742 (interactive (list (gdb-needed-default-instance))) | |
1743 (switch-to-buffer-other-frame | |
1744 (gdb-get-create-instance-buffer instance | |
1745 'gdb-stack-buffer))) | |
1746 | |
1747 (defvar gdb-frames-mode-map nil) | |
1748 (setq gdb-frames-mode-map (make-keymap)) | |
1749 (suppress-keymap gdb-frames-mode-map) | |
1750 (define-key gdb-frames-mode-map [mouse-2] | |
1751 'gdb-frames-select-by-mouse) | |
1752 | |
1753 (defun gdb-frames-mode () | |
1754 "Major mode for gdb frames. | |
1755 | |
1756 \\{gdb-frames-mode-map}" | |
1757 (setq major-mode 'gdb-frames-mode) | |
1758 (setq mode-name "Frames") | |
1759 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
1760 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
1761 (setq buffer-read-only t) | |
1762 (use-local-map gdb-frames-mode-map) | |
1763 (gdb-invalidate-frames gdb-buffer-instance)) | |
1764 | |
1765 (defun gdb-get-frame-number () | |
1766 (save-excursion | |
1767 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t)) | |
1768 (n (or (and pos | |
1769 (string-to-int | |
1770 (buffer-substring (match-beginning 1) | |
1771 (match-end 1)))) | |
1772 0))) | |
1773 n))) | |
1774 | |
1775 (defun gdb-frames-select-by-mouse (e) | |
1776 "Display the source of the selected frame." | |
1777 (interactive "e") | |
1778 (let (selection) | |
1779 (save-excursion | |
1780 (set-buffer (window-buffer (posn-window (event-end e)))) | |
1781 (save-excursion | |
1782 (goto-char (posn-point (event-end e))) | |
1783 (setq selection (gdb-get-frame-number)))) | |
1784 (select-window (posn-window (event-end e))) | |
1785 (save-excursion | |
1786 (set-buffer (gdb-get-instance-buffer (gdb-needed-default-instance) 'gdba)) | |
1787 (gdb-instance-enqueue-idle-input | |
1788 gdb-buffer-instance | |
1789 (list | |
1790 (concat (gud-format-command "server frame %p" selection) | |
1791 "\n") | |
1792 '(lambda () nil))) | |
1793 (gud-display-frame)))) | |
1794 | |
1795 | |
1796 ;; | |
1797 ;; Registers buffers | |
1798 ;; | |
1799 | |
1800 (def-gdb-auto-updated-buffer gdb-registers-buffer | |
1801 gdb-invalidate-registers | |
1802 "server info registers\n" | |
1803 gdb-info-registers-handler | |
1804 gdb-info-registers-custom) | |
1805 | |
1806 (defun gdb-info-registers-custom ()) | |
1807 | |
1808 (gdb-set-instance-buffer-rules 'gdb-registers-buffer | |
1809 'gdb-registers-buffer-name | |
1810 'gdb-registers-mode) | |
1811 | |
1812 (defvar gdb-registers-mode-map nil) | |
1813 (setq gdb-registers-mode-map (make-keymap)) | |
1814 (suppress-keymap gdb-registers-mode-map) | |
1815 | |
1816 (defun gdb-registers-mode () | |
1817 "Major mode for gdb registers. | |
1818 | |
1819 \\{gdb-registers-mode-map}" | |
1820 (setq major-mode 'gdb-registers-mode) | |
1821 (setq mode-name "Registers") | |
1822 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
1823 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
1824 (setq buffer-read-only t) | |
1825 (use-local-map gdb-registers-mode-map) | |
1826 (gdb-invalidate-registers gdb-buffer-instance)) | |
1827 | |
1828 (defun gdb-registers-buffer-name (instance) | |
1829 (save-excursion | |
1830 (set-buffer (process-buffer (gdb-instance-process instance))) | |
1831 (concat "*registers of " (gdb-instance-target-string instance) "*"))) | |
1832 | |
1833 (defun gdb-display-registers-buffer (instance) | |
1834 (interactive (list (gdb-needed-default-instance))) | |
1835 (gdb-display-buffer | |
1836 (gdb-get-create-instance-buffer instance | |
1837 'gdb-registers-buffer))) | |
1838 | |
1839 (defun gdb-frame-registers-buffer (instance) | |
1840 (interactive (list (gdb-needed-default-instance))) | |
1841 (switch-to-buffer-other-frame | |
1842 (gdb-get-create-instance-buffer instance | |
1843 'gdb-registers-buffer))) | |
1844 | |
1845 ;; | |
1846 ;; Locals buffers | |
1847 ;; | |
1848 | |
1849 (def-gdb-auto-updated-buffer gdb-locals-buffer | |
1850 gdb-invalidate-locals | |
1851 "server info locals\n" | |
1852 gdb-info-locals-handler | |
1853 gdb-info-locals-custom) | |
1854 | |
1855 | |
1856 ;Abbreviate for arrays and structures. These can be expanded using gud-display | |
1857 (defun gdb-info-locals-handler nil | |
1858 (set-gdb-instance-pending-triggers | |
1859 instance (delq (quote gdb-invalidate-locals) | |
1860 (gdb-instance-pending-triggers instance))) | |
1861 (let ((buf (gdb-get-instance-buffer instance | |
1862 (quote gdb-partial-output-buffer)))) | |
1863 (save-excursion | |
1864 (set-buffer buf) | |
1865 (goto-char (point-min)) | |
1866 (replace-regexp "^ .*\n" "") | |
1867 (goto-char (point-min)) | |
1868 (replace-regexp "{[-0-9, {}\]*\n" "(array);\n"))) | |
1869 (goto-char (point-min)) | |
1870 (replace-regexp "{.*=.*\n" "(structure);\n") | |
1871 (let ((buf (gdb-get-instance-buffer instance (quote gdb-locals-buffer)))) | |
1872 (and buf (save-excursion | |
1873 (set-buffer buf) | |
1874 (let ((p (point)) | |
1875 (buffer-read-only nil)) | |
1876 (delete-region (point-min) (point-max)) | |
1877 (insert-buffer (gdb-get-create-instance-buffer | |
1878 instance | |
1879 (quote gdb-partial-output-buffer))) | |
1880 (goto-char p))))) | |
1881 (run-hooks (quote gdb-info-locals-hook))) | |
1882 | |
1883 (defun gdb-info-locals-custom () | |
1884 nil) | |
1885 | |
1886 (gdb-set-instance-buffer-rules 'gdb-locals-buffer | |
1887 'gdb-locals-buffer-name | |
1888 'gdb-locals-mode) | |
1889 | |
1890 (defvar gdb-locals-mode-map nil) | |
1891 (setq gdb-locals-mode-map (make-keymap)) | |
1892 (suppress-keymap gdb-locals-mode-map) | |
1893 | |
1894 (defun gdb-locals-mode () | |
1895 "Major mode for gdb locals. | |
1896 | |
1897 \\{gdb-locals-mode-map}" | |
1898 (setq major-mode 'gdb-locals-mode) | |
1899 (setq mode-name "Locals") | |
1900 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
1901 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
1902 (setq buffer-read-only t) | |
1903 (use-local-map gdb-locals-mode-map) | |
1904 (gdb-invalidate-locals gdb-buffer-instance)) | |
1905 | |
1906 (defun gdb-locals-buffer-name (instance) | |
1907 (save-excursion | |
1908 (set-buffer (process-buffer (gdb-instance-process instance))) | |
1909 (concat "*locals of " (gdb-instance-target-string instance) "*"))) | |
1910 | |
1911 (defun gdb-display-locals-buffer (instance) | |
1912 (interactive (list (gdb-needed-default-instance))) | |
1913 (gdb-display-buffer | |
1914 (gdb-get-create-instance-buffer instance | |
1915 'gdb-locals-buffer))) | |
1916 | |
1917 (defun gdb-frame-locals-buffer (instance) | |
1918 (interactive (list (gdb-needed-default-instance))) | |
1919 (switch-to-buffer-other-frame | |
1920 (gdb-get-create-instance-buffer instance | |
1921 'gdb-locals-buffer))) | |
1922 ;; | |
1923 ;; Display expression buffers (just allow one to start with) | |
1924 ;; | |
1925 (gdb-set-instance-buffer-rules 'gdb-display-buffer | |
1926 'gdb-display-buffer-name | |
1927 'gdb-display-mode) | |
1928 | |
1929 (def-gdb-auto-updated-buffer gdb-display-buffer | |
1930 ;; This defines the auto update rule for buffers of type | |
1931 ;; `gdb-display-buffer'. | |
1932 ;; | |
1933 ;; It defines a function to serve as the annotation handler that | |
1934 ;; handles the `foo-invalidated' message. That function is called: | |
1935 gdb-invalidate-display | |
1936 | |
1937 ;; To update the buffer, this command is sent to gdb. | |
1938 "server info display\n" | |
1939 | |
1940 ;; This also defines a function to be the handler for the output | |
1941 ;; from the command above. That function will copy the output into | |
1942 ;; the appropriately typed buffer. That function will be called: | |
1943 gdb-info-display-handler | |
1944 ; buffer specific functions | |
1945 gdb-info-display-custom) | |
1946 | |
1947 (defun gdb-info-display-custom () | |
1948 ; TODO: ensure frames of expressions that have been deleted are also deleted | |
1949 ; these can be missed currently eg through GUD buffer, restarting a | |
1950 ; recompiled program. | |
1951 ) | |
1952 | |
1953 (defvar gdb-display-mode-map nil) | |
1954 (setq gdb-display-mode-map (make-keymap)) | |
1955 (suppress-keymap gdb-display-mode-map) | |
1956 | |
1957 (define-key gdb-display-mode-map [menu-bar display] | |
1958 (cons "Display" (make-sparse-keymap "Display"))) | |
1959 (define-key gdb-display-mode-map [menu-bar display toggle] | |
1960 '("Toggle" . gdb-toggle-disp-this-line)) | |
1961 (define-key gdb-display-mode-map [menu-bar display delete] | |
1962 '("Delete" . gdb-delete-disp-this-line)) | |
1963 | |
1964 (define-key gdb-display-mode-map " " 'gdb-toggle-disp-this-line) | |
1965 (define-key gdb-display-mode-map "d" 'gdb-delete-disp-this-line) | |
1966 | |
1967 (defun gdb-display-mode () | |
1968 "Major mode for gdb display. | |
1969 | |
1970 \\{gdb-display-mode-map}" | |
1971 (setq major-mode 'gdb-display-mode) | |
1972 (setq mode-name "Display") | |
1973 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
1974 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
1975 (setq buffer-read-only t) | |
1976 (use-local-map gdb-display-mode-map) | |
1977 (gdb-invalidate-display gdb-buffer-instance)) | |
1978 | |
1979 (defun gdb-display-buffer-name (instance) | |
1980 (save-excursion | |
1981 (set-buffer (process-buffer (gdb-instance-process instance))) | |
1982 (concat "*Displayed expressions of " (gdb-instance-target-string instance) "*"))) | |
1983 | |
1984 (defun gdb-display-display-buffer (instance) | |
1985 (interactive (list (gdb-needed-default-instance))) | |
1986 (gdb-display-buffer | |
1987 (gdb-get-create-instance-buffer instance | |
1988 'gdb-display-buffer))) | |
1989 | |
1990 (defun gdb-frame-display-buffer (instance) | |
1991 (interactive (list (gdb-needed-default-instance))) | |
1992 (switch-to-buffer-other-frame | |
1993 (gdb-get-create-instance-buffer instance | |
1994 'gdb-display-buffer))) | |
1995 | |
1996 (defun gdb-toggle-disp-this-line () | |
1997 (interactive) | |
1998 (save-excursion | |
1999 (beginning-of-line 1) | |
2000 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) | |
2001 (error "No expression on this line") | |
2002 (gdb-instance-enqueue-idle-input | |
2003 gdb-buffer-instance | |
2004 (list | |
2005 (concat | |
2006 (if (eq ?y (char-after (match-beginning 2))) | |
2007 "server disable display " | |
2008 "server enable display ") | |
2009 (buffer-substring (match-beginning 0) | |
2010 (match-end 1)) | |
2011 "\n") | |
2012 '(lambda () nil)))))) | |
2013 | |
2014 (defun gdb-delete-disp-this-line () | |
2015 (interactive) | |
2016 (save-excursion | |
2017 (set-buffer | |
2018 (gdb-get-instance-buffer gdb-buffer-instance 'gdb-display-buffer)) | |
2019 (beginning-of-line 1) | |
2020 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) | |
2021 (error "No expression on this line") | |
2022 (let ((number (buffer-substring (match-beginning 0) | |
2023 (match-end 1)))) | |
2024 (gdb-instance-enqueue-idle-input | |
2025 gdb-buffer-instance | |
2026 (list (concat "server delete display " number "\n") | |
2027 '(lambda () nil))) | |
2028 (if (not (display-graphic-p)) | |
2029 (kill-buffer (get-buffer (concat "*display " number "*"))) | |
2030 ;else | |
2031 (catch 'frame-found | |
2032 (let ((frames (frame-list))) | |
2033 (while frames | |
2034 (if (string-equal (frame-parameter (car frames) 'name) | |
2035 (concat "*display " number "*")) | |
2036 (progn (kill-buffer | |
2037 (get-buffer (concat "*display " number "*"))) | |
2038 (delete-frame (car frames)) | |
2039 (throw 'frame-found nil))) | |
2040 (setq frames (cdr frames)))))))))) | |
2041 | |
2042 (defvar gdb-expressions-mode-map nil) | |
2043 (setq gdb-expressions-mode-map (make-keymap)) | |
2044 (suppress-keymap gdb-expressions-mode-map) | |
2045 | |
2046 (defvar gdb-expressions-mode-menu | |
2047 '("GDB Expressions Commands" | |
2048 "----" | |
2049 ["Visualise" gdb-array-visualise t] | |
2050 ["Delete" gdb-delete-display t]) | |
2051 "Menu for `gdb-expressions-mode'.") | |
2052 | |
2053 (define-key gdb-expressions-mode-map "v" 'gdb-array-visualise) | |
2054 (define-key gdb-expressions-mode-map "q" 'gdb-delete-display) | |
2055 (define-key gdb-expressions-mode-map [mouse-3] 'gdb-expressions-popup-menu) | |
2056 | |
2057 (defun gdb-expressions-popup-menu (event) | |
2058 "Explicit Popup menu as this buffer doesn't have a menubar." | |
2059 (interactive "@e") | |
2060 (mouse-set-point event) | |
2061 (popup-menu gdb-expressions-mode-menu)) | |
2062 | |
2063 (defun gdb-expressions-mode () | |
2064 "Major mode for display expressions. | |
2065 | |
2066 \\{gdb-expressions-mode-map}" | |
2067 (setq major-mode 'gdb-expressions-mode) | |
2068 (setq mode-name "Expressions") | |
2069 (use-local-map gdb-expressions-mode-map) | |
2070 (make-local-variable 'gdb-display-number) | |
2071 (make-local-variable 'gdb-values) | |
2072 (make-local-variable 'gdb-expression) | |
2073 (set (make-local-variable 'gdb-display-string) nil) | |
2074 (set (make-local-variable 'gdb-dive-display-number) nil) | |
2075 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
2076 (set (make-local-variable 'gdb-array-start) (make-vector 16 '-1)) | |
2077 (set (make-local-variable 'gdb-array-stop) (make-vector 16 '-1)) | |
2078 (set (make-local-variable 'gdb-array-size) (make-vector 16 '-1)) | |
2079 (setq buffer-read-only t)) | |
2080 | |
2081 | |
2082 ;;;; Window management | |
2083 | |
2084 ;;; FIXME: This should only return true for buffers in the current instance | |
2085 (defun gdb-protected-buffer-p (buffer) | |
2086 "Is BUFFER a buffer which we want to leave displayed?" | |
2087 (save-excursion | |
2088 (set-buffer buffer) | |
2089 (or gdb-buffer-type | |
2090 overlay-arrow-position))) | |
2091 | |
2092 ;;; The way we abuse the dedicated-p flag is pretty gross, but seems | |
2093 ;;; to do the right thing. Seeing as there is no way for Lisp code to | |
2094 ;;; get at the use_time field of a window, I'm not sure there exists a | |
2095 ;;; more elegant solution without writing C code. | |
2096 | |
2097 (defun gdb-display-buffer (buf &optional size) | |
2098 (let ((must-split nil) | |
2099 (answer nil)) | |
2100 (unwind-protect | |
2101 (progn | |
2102 (walk-windows | |
2103 '(lambda (win) | |
2104 (if (gdb-protected-buffer-p (window-buffer win)) | |
2105 (set-window-dedicated-p win t)))) | |
2106 (setq answer (get-buffer-window buf)) | |
2107 (if (not answer) | |
2108 (let ((window (get-lru-window))) | |
2109 (if window | |
2110 (progn | |
2111 (set-window-buffer window buf) | |
2112 (setq answer window)) | |
2113 (setq must-split t))))) | |
2114 (walk-windows | |
2115 '(lambda (win) | |
2116 (if (gdb-protected-buffer-p (window-buffer win)) | |
2117 (set-window-dedicated-p win nil))))) | |
2118 (if must-split | |
2119 (let* ((largest (get-largest-window)) | |
2120 (cur-size (window-height largest)) | |
2121 (new-size (and size (< size cur-size) (- cur-size size)))) | |
2122 (setq answer (split-window largest new-size)) | |
2123 (set-window-buffer answer buf))) | |
2124 answer)) | |
48300
69646014abb3
Fix feature name in `require'.
Juanma Barranquero <lekktu@gmail.com>
parents:
48292
diff
changeset
|
2125 |
48292 | 2126 (defun gdb-display-source-buffer (buffer) |
2127 (set-window-buffer gdb-source-window buffer)) | |
2128 | |
2129 | |
2130 ;;; Shared keymap initialization: | |
2131 | |
2132 (defun gdb-display-gdb-buffer (instance) | |
2133 (interactive (list (gdb-needed-default-instance))) | |
2134 (gdb-display-buffer | |
2135 (gdb-get-create-instance-buffer instance 'gdba))) | |
2136 | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2137 (defun gdb-make-windows-menu (map) |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2138 ;; FIXME: This adds to the DBX, PerlDB, ... menu as well :-( |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2139 ;; Probably we should create gdb-many-windows-map and put those menus |
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2140 ;; on that map. |
48292 | 2141 (define-key map [menu-bar displays] |
2142 (cons "GDB-Windows" (make-sparse-keymap "GDB-Windows"))) | |
2143 (define-key map [menu-bar displays gdb] | |
2144 '("Gdb" . gdb-display-gdb-buffer)) | |
2145 (define-key map [menu-bar displays locals] | |
2146 '("Locals" . gdb-display-locals-buffer)) | |
2147 (define-key map [menu-bar displays registers] | |
2148 '("Registers" . gdb-display-registers-buffer)) | |
2149 (define-key map [menu-bar displays frames] | |
2150 '("Stack" . gdb-display-stack-buffer)) | |
2151 (define-key map [menu-bar displays breakpoints] | |
2152 '("Breakpoints" . gdb-display-breakpoints-buffer)) | |
2153 (define-key map [menu-bar displays display] | |
2154 '("Display" . gdb-display-display-buffer)) | |
2155 (define-key map [menu-bar displays assembler] | |
2156 '("Assembler" . gdb-display-assembler-buffer))) | |
2157 | |
2158 (define-key gud-minor-mode-map "\C-c\M-\C-r" 'gdb-display-registers-buffer) | |
2159 (define-key gud-minor-mode-map "\C-c\M-\C-f" 'gdb-display-stack-buffer) | |
2160 (define-key gud-minor-mode-map "\C-c\M-\C-b" 'gdb-display-breakpoints-buffer) | |
2161 | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2162 (gdb-make-windows-menu gud-minor-mode-map) |
48292 | 2163 |
2164 (defun gdb-frame-gdb-buffer (instance) | |
2165 (interactive (list (gdb-needed-default-instance))) | |
2166 (switch-to-buffer-other-frame | |
2167 (gdb-get-create-instance-buffer instance 'gdba))) | |
2168 | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2169 (defun gdb-make-frames-menu (map) |
48292 | 2170 (define-key map [menu-bar frames] |
2171 (cons "GDB-Frames" (make-sparse-keymap "GDB-Frames"))) | |
2172 (define-key map [menu-bar frames gdb] | |
2173 '("Gdb" . gdb-frame-gdb-buffer)) | |
2174 (define-key map [menu-bar frames locals] | |
2175 '("Locals" . gdb-frame-locals-buffer)) | |
2176 (define-key map [menu-bar frames registers] | |
2177 '("Registers" . gdb-frame-registers-buffer)) | |
2178 (define-key map [menu-bar frames frames] | |
2179 '("Stack" . gdb-frame-stack-buffer)) | |
2180 (define-key map [menu-bar frames breakpoints] | |
2181 '("Breakpoints" . gdb-frame-breakpoints-buffer)) | |
2182 (define-key map [menu-bar frames display] | |
2183 '("Display" . gdb-frame-display-buffer)) | |
2184 (define-key map [menu-bar frames assembler] | |
2185 '("Assembler" . gdb-frame-assembler-buffer))) | |
2186 | |
2187 (if (display-graphic-p) | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2188 (gdb-make-frames-menu gud-minor-mode-map)) |
48292 | 2189 |
2190 (defun gdb-proc-died (proc) | |
2191 ;; Stop displaying an arrow in a source file. | |
2192 (setq overlay-arrow-position nil) | |
2193 | |
2194 ;; Kill the dummy process, so that C-x C-c won't worry about it. | |
2195 (save-excursion | |
2196 (set-buffer (process-buffer proc)) | |
2197 (kill-process | |
2198 (get-buffer-process | |
2199 (gdb-get-instance-buffer gdb-buffer-instance 'gdb-inferior-io))))) | |
2200 ;; end of functions from gdba.el | |
2201 | |
2202 ;; new functions for gdb-ui.el | |
2203 ;; layout for all the windows | |
2204 (defun gdb-setup-windows (instance) | |
2205 (gdb-display-locals-buffer instance) | |
2206 (gdb-display-stack-buffer instance) | |
2207 (delete-other-windows) | |
2208 (gdb-display-breakpoints-buffer instance) | |
2209 (gdb-display-display-buffer instance) | |
2210 (delete-other-windows) | |
2211 (split-window nil ( / ( * (window-height) 3) 4)) | |
2212 (split-window nil ( / (window-height) 3)) | |
2213 (split-window-horizontally) | |
2214 (other-window 1) | |
2215 (switch-to-buffer (gdb-locals-buffer-name instance)) | |
2216 (other-window 1) | |
2217 (switch-to-buffer | |
2218 (if gud-last-last-frame | |
2219 (gud-find-file (car gud-last-last-frame)) | |
2220 (gud-find-file gdb-main-file))) | |
2221 (setq gdb-source-window (get-buffer-window (current-buffer))) | |
2222 (split-window-horizontally) | |
2223 (other-window 1) | |
2224 (switch-to-buffer (gdb-inferior-io-name instance)) | |
2225 (other-window 1) | |
2226 (switch-to-buffer (gdb-stack-buffer-name instance)) | |
2227 (split-window-horizontally) | |
2228 (other-window 1) | |
2229 (switch-to-buffer (gdb-breakpoints-buffer-name instance)) | |
2230 (other-window 1)) | |
2231 | |
2232 (defun gdb-restore-windows () | |
2233 "Restore the basic arrangement of windows used by gdba. | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2234 This arrangement depends on the value of `gdb-many-windows'." |
48292 | 2235 (interactive) |
2236 (if gdb-many-windows | |
2237 (progn | |
2238 (switch-to-buffer gud-comint-buffer) | |
2239 (delete-other-windows) | |
2240 (gdb-setup-windows gdb-buffer-instance)) | |
2241 ;else | |
2242 (switch-to-buffer gud-comint-buffer) | |
2243 (delete-other-windows) | |
2244 (split-window) | |
2245 (other-window 1) | |
2246 (switch-to-buffer | |
2247 (if gud-last-last-frame | |
2248 (gud-find-file (car gud-last-last-frame)) | |
2249 (gud-find-file gdb-main-file))) | |
2250 (other-window 1))) | |
2251 | |
2252 (defun toggle-gdb-windows () | |
2253 "Toggle the number of windows in the basic arrangement." | |
2254 (interactive) | |
2255 (if gdb-many-windows | |
2256 (progn | |
2257 (switch-to-buffer gud-comint-buffer) | |
2258 (delete-other-windows) | |
2259 (split-window) | |
2260 (other-window 1) | |
2261 (switch-to-buffer | |
2262 (if gud-last-last-frame | |
2263 (gud-find-file (car gud-last-last-frame)) | |
2264 (gud-find-file gdb-main-file))) | |
2265 (other-window 1) | |
2266 (setq gdb-many-windows nil)) | |
2267 ;else | |
2268 (switch-to-buffer gud-comint-buffer) | |
2269 (delete-other-windows) | |
2270 (gdb-setup-windows gdb-buffer-instance) | |
2271 (setq gdb-many-windows t))) | |
2272 | |
2273 (defconst breakpoint-xpm-data "/* XPM */ | |
2274 static char *magick[] = { | |
2275 /* columns rows colors chars-per-pixel */ | |
2276 \"12 12 2 1\", | |
2277 \" c red\", | |
2278 \"+ c None\", | |
2279 /* pixels */ | |
2280 \"+++++ +++++\", | |
2281 \"+++ +++\", | |
2282 \"++ ++\", | |
2283 \"+ +\", | |
2284 \"+ +\", | |
2285 \" \", | |
2286 \" \", | |
2287 \"+ +\", | |
2288 \"+ +\", | |
2289 \"++ ++\", | |
2290 \"+++ +++\", | |
2291 \"+++++ +++++\" | |
2292 };" | |
2293 "XPM file used for breakpoint icon.") | |
2294 | |
2295 (setq breakpoint-enabled-icon (find-image | |
2296 `((:type xpm :data ,breakpoint-xpm-data)))) | |
2297 (setq breakpoint-disabled-icon (find-image | |
2298 `((:type xpm :data ,breakpoint-xpm-data | |
2299 :conversion laplace)))) | |
2300 | |
2301 (defun gdb-quit () | |
2302 "Kill the GUD and ancillary (including source) buffers. | |
2303 Just the partial-output buffer is left." | |
2304 (interactive) | |
2305 (let ((buffers (buffer-list))) | |
2306 (save-excursion | |
2307 (while buffers | |
2308 (set-buffer (car buffers)) | |
2309 (if (eq gud-minor-mode 'gdba) | |
2310 (if (string-match "^\*" (buffer-name)) | |
2311 (kill-buffer nil) | |
2312 (if (display-graphic-p) | |
2313 (remove-images (point-min) (point-max)) | |
2314 (remove-strings (point-min) (point-max))) | |
2315 (setq left-margin-width 0) | |
2316 (if (get-buffer-window (current-buffer)) | |
2317 (set-window-margins (get-buffer-window | |
2318 (current-buffer)) | |
2319 left-margin-width | |
2320 right-margin-width)))) | |
2321 (setq buffers (cdr buffers))))) | |
2322 (if (eq (selected-window) (minibuffer-window)) | |
2323 (other-window 1)) | |
2324 (delete-other-windows)) | |
2325 | |
2326 (defun gdb-source-info () | |
2327 (goto-char (point-min)) | |
2328 (re-search-forward "directory is ") | |
2329 (looking-at "\\(\\S-*\\)") | |
2330 (setq gdb-cdir (buffer-substring (match-beginning 1) (match-end 1))) | |
2331 (re-search-forward "Located in ") | |
2332 (looking-at "\\(\\S-*\\)") | |
2333 (setq gdb-main-file (buffer-substring (match-beginning 1) (match-end 1))) | |
2334 ;; Make sure we are not in the minibuffer window when we try to delete | |
2335 ;; all other windows. | |
2336 (if (eq (selected-window) (minibuffer-window)) | |
2337 (other-window 1)) | |
2338 (delete-other-windows) | |
2339 (if gdb-many-windows | |
2340 (gdb-setup-windows gdb-buffer-instance) | |
2341 ;else | |
2342 (gdb-display-breakpoints-buffer gdb-buffer-instance) | |
2343 (gdb-display-display-buffer instance) | |
2344 (gdb-display-stack-buffer instance) | |
2345 (delete-other-windows) | |
2346 (split-window) | |
2347 (other-window 1) | |
2348 (switch-to-buffer (gud-find-file gdb-main-file)) | |
2349 (other-window 1) | |
2350 (setq gdb-source-window (get-buffer-window (current-buffer))))) | |
2351 | |
2352 ;from put-image | |
2353 (defun put-string (putstring pos &optional string area) | |
2354 "Put string PUTSTRING in front of POS in the current buffer. | |
2355 PUTSTRING is displayed by putting an overlay into the current buffer with a | |
2356 `before-string' STRING that has a `display' property whose value is | |
2357 PUTSTRING. STRING is defaulted if you omit it. | |
2358 POS may be an integer or marker. | |
2359 AREA is where to display the string. AREA nil or omitted means | |
2360 display it in the text area, a value of `left-margin' means | |
2361 display it in the left marginal area, a value of `right-margin' | |
2362 means display it in the right marginal area." | |
2363 (unless string (setq string "x")) | |
2364 (let ((buffer (current-buffer))) | |
2365 (unless (or (null area) (memq area '(left-margin right-margin))) | |
2366 (error "Invalid area %s" area)) | |
2367 (setq string (copy-sequence string)) | |
2368 (let ((overlay (make-overlay pos pos buffer)) | |
2369 (prop (if (null area) putstring (list (list 'margin area) putstring)))) | |
2370 (put-text-property 0 (length string) 'display prop string) | |
2371 (overlay-put overlay 'put-text t) | |
2372 (overlay-put overlay 'before-string string)))) | |
2373 | |
2374 ;from remove-images | |
2375 (defun remove-strings (start end &optional buffer) | |
2376 "Remove strings between START and END in BUFFER. | |
2377 Remove only images that were put in BUFFER with calls to `put-string'. | |
2378 BUFFER nil or omitted means use the current buffer." | |
2379 (unless buffer | |
2380 (setq buffer (current-buffer))) | |
2381 (let ((overlays (overlays-in start end))) | |
2382 (while overlays | |
2383 (let ((overlay (car overlays))) | |
2384 (when (overlay-get overlay 'put-text) | |
2385 (delete-overlay overlay))) | |
2386 (setq overlays (cdr overlays))))) | |
2387 | |
2388 (defun put-arrow (putstring pos &optional string area) | |
2389 "Put arrow string PUTSTRING in front of POS in the current buffer. | |
2390 PUTSTRING is displayed by putting an overlay into the current buffer with a | |
2391 `before-string' \"gdb-arrow\" that has a `display' property whose value is | |
2392 PUTSTRING. STRING is defaulted if you omit it. | |
2393 POS may be an integer or marker. | |
2394 AREA is where to display the string. AREA nil or omitted means | |
2395 display it in the text area, a value of `left-margin' means | |
2396 display it in the left marginal area, a value of `right-margin' | |
2397 means display it in the right marginal area." | |
2398 (setq string "gdb-arrow") | |
2399 (let ((buffer (current-buffer))) | |
2400 (unless (or (null area) (memq area '(left-margin right-margin))) | |
2401 (error "Invalid area %s" area)) | |
2402 (setq string (copy-sequence string)) | |
2403 (let ((overlay (make-overlay pos pos buffer)) | |
2404 (prop (if (null area) putstring (list (list 'margin area) putstring)))) | |
2405 (put-text-property 0 (length string) 'display prop string) | |
2406 (overlay-put overlay 'put-text t) | |
2407 (overlay-put overlay 'before-string string)))) | |
2408 | |
2409 (defun remove-arrow (&optional buffer) | |
2410 "Remove arrow in BUFFER. | |
2411 Remove only images that were put in BUFFER with calls to `put-arrow'. | |
2412 BUFFER nil or omitted means use the current buffer." | |
2413 (unless buffer | |
2414 (setq buffer (current-buffer))) | |
2415 (let ((overlays (overlays-in (point-min) (point-max)))) | |
2416 (while overlays | |
2417 (let ((overlay (car overlays))) | |
2418 (when (string-equal (overlay-get overlay 'before-string) "gdb-arrow") | |
2419 (delete-overlay overlay))) | |
2420 (setq overlays (cdr overlays))))) | |
2421 | |
2422 (defvar gdb-array-slice-map nil) | |
2423 (setq gdb-array-slice-map (make-keymap)) | |
2424 (define-key gdb-array-slice-map [mouse-2] 'gdb-array-slice) | |
2425 | |
2426 (defun gdb-array-slice (event) | |
2427 "Select an array slice to display." | |
2428 (interactive "e") | |
2429 (mouse-set-point event) | |
2430 (save-excursion | |
2431 (let ((n -1) (stop 0) (start 0) (point (point))) | |
2432 (beginning-of-line) | |
2433 (while (search-forward "[" point t) | |
2434 (setq n (+ n 1))) | |
2435 (setq start (string-to-int (read-string "Start index: "))) | |
2436 (aset gdb-array-start n start) | |
2437 (setq stop (string-to-int (read-string "Stop index: "))) | |
2438 (aset gdb-array-stop n stop))) | |
2439 (gdb-array-format1)) | |
2440 | |
2441 (defun gdb-array-visualise () | |
2442 "Visualise arrays and slices using graph program from plotutils." | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2443 (interactive) |
48292 | 2444 (if (and (display-graphic-p) gdb-display-string) |
2445 (let ((n 0) m) | |
2446 (catch 'multi-dimensional | |
2447 (while (eq (aref gdb-array-start n) (aref gdb-array-stop n)) | |
2448 (setq n (+ n 1))) | |
2449 (setq m (+ n 1)) | |
2450 (while (< m (length gdb-array-start)) | |
2451 (if (not (eq (aref gdb-array-start m) (aref gdb-array-stop m))) | |
2452 (progn | |
2453 (x-popup-dialog | |
2454 t `(,(concat "Only one dimensional data can be visualised.\n" | |
2455 "Use an array slice to reduce the number of\n" | |
2456 "dimensions") ("OK" t))) | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2457 (throw 'multi-dimensional nil)) |
48292 | 2458 (setq m (+ m 1)))) |
2459 (shell-command (concat "echo" gdb-display-string " | graph -a 1 " | |
2460 (int-to-string (aref gdb-array-start n)) | |
2461 " -x " | |
2462 (int-to-string (aref gdb-array-start n)) | |
2463 " " | |
2464 (int-to-string (aref gdb-array-stop n)) | |
2465 " 1 -T X")))))) | |
2466 | |
2467 (defun gdb-delete-display () | |
2468 "Delete displayed expression and its frame." | |
2469 (interactive) | |
2470 (gdb-instance-enqueue-idle-input | |
2471 gdb-buffer-instance | |
2472 (list (concat "server delete display " gdb-display-number "\n") | |
2473 '(lambda () nil))) | |
2474 (kill-buffer nil) | |
2475 (delete-frame)) | |
2476 | |
2477 ;; | |
2478 ;; Assembler buffer | |
2479 ;; | |
2480 | |
2481 (def-gdb-auto-updated-buffer gdb-assembler-buffer | |
2482 gdb-invalidate-assembler | |
2483 (concat "server disassemble " gdb-main-or-pc "\n") | |
2484 gdb-assembler-handler | |
2485 gdb-assembler-custom) | |
2486 | |
2487 (defun gdb-assembler-custom () | |
2488 (let ((buffer (gdb-get-instance-buffer gdb-buffer-instance | |
2489 'gdb-assembler-buffer)) | |
48498
8fdedd7dca85
General tidying. Patches from Stefan Monnier.
Nick Roberts <nickrob@snap.net.nz>
parents:
48300
diff
changeset
|
2490 (gdb-arrow-position) (address) (flag)) |
48292 | 2491 (if gdb-current-address |
2492 (progn | |
2493 (save-excursion | |
2494 (set-buffer buffer) | |
2495 (remove-arrow) | |
2496 (goto-char (point-min)) | |
2497 (re-search-forward gdb-current-address) | |
2498 (setq gdb-arrow-position (point)) | |
2499 (put-arrow "=>" gdb-arrow-position nil 'left-margin)))) | |
2500 | |
2501 ; remove all breakpoint-icons in assembler buffer before updating. | |
2502 (save-excursion | |
2503 (set-buffer buffer) | |
2504 (if (display-graphic-p) | |
2505 (remove-images (point-min) (point-max)) | |
2506 (remove-strings (point-min) (point-max)))) | |
2507 (save-excursion | |
2508 (set-buffer (gdb-get-instance-buffer instance 'gdb-breakpoints-buffer)) | |
2509 (goto-char (point-min)) | |
2510 (while (< (point) (- (point-max) 1)) | |
2511 (forward-line 1) | |
2512 (if (looking-at "[^\t].*breakpoint") | |
2513 (progn | |
2514 (looking-at | |
2515 "\\([0-9]*\\)\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)\\s-*0x0\\(\\S-*\\)") | |
2516 ; info break gives '0x0' (8 digit) while dump gives '0x' (7 digit) | |
2517 (setq address (concat "0x" (buffer-substring (match-beginning 3) | |
2518 (match-end 3)))) | |
2519 (setq flag (char-after (match-beginning 2))) | |
2520 (save-excursion | |
2521 (set-buffer buffer) | |
2522 (goto-char (point-min)) | |
2523 (if (re-search-forward address nil t) | |
2524 (let ((start (progn (beginning-of-line) (- (point) 1))) | |
2525 (end (progn (end-of-line) (+ (point) 1)))) | |
2526 (if (display-graphic-p) | |
2527 (progn | |
2528 (remove-images start end) | |
2529 (if (eq ?y flag) | |
2530 (put-image breakpoint-enabled-icon (point) | |
2531 "breakpoint icon enabled" | |
2532 'left-margin) | |
2533 (put-image breakpoint-disabled-icon (point) | |
2534 "breakpoint icon disabled" | |
2535 'left-margin))) | |
2536 (remove-strings start end) | |
2537 (if (eq ?y flag) | |
2538 (put-string "B" (point) "enabled" 'left-margin) | |
2539 (put-string "b" (point) "disabled" | |
2540 'left-margin)))))))))) | |
2541 (if gdb-current-address | |
2542 (set-window-point (get-buffer-window buffer) gdb-arrow-position)))) | |
2543 | |
2544 (gdb-set-instance-buffer-rules 'gdb-assembler-buffer | |
2545 'gdb-assembler-buffer-name | |
2546 'gdb-assembler-mode) | |
2547 | |
2548 (defvar gdb-assembler-mode-map nil) | |
2549 (setq gdb-assembler-mode-map (make-keymap)) | |
2550 (suppress-keymap gdb-assembler-mode-map) | |
2551 | |
2552 (defun gdb-assembler-mode () | |
2553 "Major mode for viewing code assembler. | |
2554 | |
2555 \\{gdb-assembler-mode-map}" | |
2556 (setq major-mode 'gdb-assembler-mode) | |
2557 (setq mode-name "Assembler") | |
2558 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
2559 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
2560 (set (make-variable-buffer-local 'left-margin-width) 2) | |
2561 (setq buffer-read-only t) | |
2562 (use-local-map gdb-assembler-mode-map) | |
2563 (gdb-invalidate-assembler gdb-buffer-instance) | |
2564 (gdb-invalidate-breakpoints gdb-buffer-instance)) | |
2565 | |
2566 (defun gdb-assembler-buffer-name (instance) | |
2567 (save-excursion | |
2568 (set-buffer (process-buffer (gdb-instance-process instance))) | |
2569 (concat "*Machine Code " (gdb-instance-target-string instance) "*"))) | |
2570 | |
2571 (defun gdb-display-assembler-buffer (instance) | |
2572 (interactive (list (gdb-needed-default-instance))) | |
2573 (gdb-display-buffer | |
2574 (gdb-get-create-instance-buffer instance | |
2575 'gdb-assembler-buffer))) | |
2576 | |
2577 (defun gdb-frame-assembler-buffer (instance) | |
2578 (interactive (list (gdb-needed-default-instance))) | |
2579 (switch-to-buffer-other-frame | |
2580 (gdb-get-create-instance-buffer instance | |
2581 'gdb-assembler-buffer))) | |
2582 | |
2583 (defun gdb-invalidate-frame-and-assembler (instance &optional ignored) | |
2584 (gdb-invalidate-frames instance) | |
2585 (gdb-invalidate-assembler instance)) | |
2586 | |
2587 (defun gdb-invalidate-breakpoints-and-assembler (instance &optional ignored) | |
2588 (gdb-invalidate-breakpoints instance) | |
2589 (gdb-invalidate-assembler instance)) | |
2590 | |
2591 ; modified because if gdb-main-or-pc has changed value a new command | |
2592 ; must be enqueued to update the buffer with the new output | |
2593 (defun gdb-invalidate-assembler (instance &optional ignored) | |
2594 (if (and ((lambda (instance) | |
2595 (gdb-get-instance-buffer instance | |
2596 (quote gdb-assembler-buffer))) instance) | |
2597 (or (not (member (quote gdb-invalidate-assembler) | |
2598 (gdb-instance-pending-triggers instance))) | |
2599 (not (string-equal gdb-main-or-pc gdb-prev-main-or-pc)))) | |
2600 (progn | |
2601 | |
2602 ; take previous disassemble command off the queue | |
2603 (save-excursion | |
2604 (set-buffer (gdb-get-instance-buffer instance 'gdba)) | |
2605 (let ((queue gdb-idle-input-queue) (item)) | |
2606 (while queue | |
2607 (setq item (car queue)) | |
2608 (if (equal (cdr item) '(gdb-assembler-handler)) | |
2609 (delete item gdb-idle-input-queue)) | |
2610 (setq queue (cdr queue))))) | |
2611 | |
2612 (gdb-instance-enqueue-idle-input | |
2613 instance (list (concat "server disassemble " gdb-main-or-pc "\n") | |
2614 (quote gdb-assembler-handler))) | |
2615 (set-gdb-instance-pending-triggers | |
2616 instance (cons (quote gdb-invalidate-assembler) | |
2617 (gdb-instance-pending-triggers instance))) | |
2618 (setq gdb-prev-main-or-pc gdb-main-or-pc)))) | |
2619 | |
2620 (defun gdb-delete-line () | |
2621 "Delete current line." | |
2622 (interactive) | |
2623 (let ((start (progn (beginning-of-line) (point))) | |
2624 (end (progn (end-of-line) (+ (point) 1)))) | |
2625 (delete-region start end))) | |
2626 | |
2627 (provide 'gdb-ui) | |
2628 | |
2629 ;;; gdb-ui.el ends here |