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