Mercurial > emacs
annotate lisp/progmodes/gdb-ui.el @ 54721:5b50970ffa95
2004-04-05 Per Abrahamsen <abraham@dina.kvl.dk>
* cus-edit.el (custom-add-parent-links): Changed unbound variable
`symbol' to `name'.
author | Per Abrahamsen <abraham@dina.kvl.dk> |
---|---|
date | Mon, 05 Apr 2004 17:21:09 +0000 |
parents | 69a699e79a0d |
children | 7bfccd78beed |
rev | line source |
---|---|
54538 | 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, 2003, 2004 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 ;; This mode acts as a graphical user interface to GDB. You can interact with | |
29 ;; GDB through the GUD buffer in the usual way, but there are also further | |
30 ;; buffers which control the execution and describe the state of your program. | |
31 ;; It separates the input/output of your program from that of GDB and displays | |
32 ;; expressions and their current values in their own buffers. It also uses | |
33 ;; features of Emacs 21 such as the display margin for breakpoints, and the | |
34 ;; toolbar (see the GDB Graphical Interface section in the Emacs info manual). | |
35 | |
36 ;; Start the debugger with M-x gdba. | |
37 | |
38 ;; This file has evolved from gdba.el from GDB 5.0 written by Tom Lord and Jim | |
39 ;; Kingdon and uses GDB's annotation interface. You don't need to know about | |
40 ;; annotations to use this mode as a debugger, but if you are interested | |
41 ;; developing the mode itself, then see the Annotations section in the GDB | |
42 ;; info manual. Some GDB/MI commands are also used through th CLI command | |
43 ;; 'interpreter mi <mi-command>'. | |
44 ;; | |
45 ;; Known Bugs: | |
46 ;; | |
47 | |
48 ;;; Code: | |
49 | |
50 (require 'gud) | |
51 | |
52 (defvar gdb-current-address "main" "Initialisation for Assembler buffer.") | |
53 (defvar gdb-previous-address nil) | |
54 (defvar gdb-previous-frame nil) | |
55 (defvar gdb-current-frame "main") | |
56 (defvar gdb-current-language nil) | |
57 (defvar gdb-view-source t "Non-nil means that source code can be viewed.") | |
58 (defvar gdb-selected-view 'source "Code type that user wishes to view.") | |
59 (defvar gdb-var-list nil "List of variables in watch window") | |
60 (defvar gdb-var-changed nil "Non-nil means that gdb-var-list has changed.") | |
61 (defvar gdb-buffer-type nil) | |
62 (defvar gdb-overlay-arrow-position nil) | |
63 (defvar gdb-variables '() | |
64 "A list of variables that are local to the GUD buffer.") | |
65 | |
66 ;;;###autoload | |
67 (defun gdba (command-line) | |
68 "Run gdb on program FILE in buffer *gud-FILE*. | |
69 The directory containing FILE becomes the initial working directory | |
70 and source-file directory for your debugger. | |
71 | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
72 If `gdb-many-windows' is nil (the default value) then gdb just |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
73 pops up the GUD buffer unless `gdb-show-main' is t. In this case |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
74 it starts with two windows: one displaying the GUD buffer and the |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
75 other with the source file with the main routine of the debugee. |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
76 |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
77 If `gdb-many-windows' is t the layout below will appear |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
78 regardless of the value of `gdb-show-main'. Keybindings are given |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
79 in relevant buffer. |
54538 | 80 |
81 --------------------------------------------------------------------- | |
82 GDB Toolbar | |
83 --------------------------------------------------------------------- | |
84 GUD buffer (I/O of GDB) | Locals buffer | |
85 | | |
86 | | |
87 | | |
88 --------------------------------------------------------------------- | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
89 Source buffer | Input/Output (of debugee) buffer |
54538 | 90 | (comint-mode) |
91 | | |
92 | | |
93 | | |
94 | | |
95 | | |
96 | | |
97 --------------------------------------------------------------------- | |
98 Stack buffer | Breakpoints buffer | |
99 RET gdb-frames-select | SPC gdb-toggle-breakpoint | |
100 | RET gdb-goto-breakpoint | |
101 | d gdb-delete-breakpoint | |
102 --------------------------------------------------------------------- | |
103 | |
104 All the buffers share the toolbar and source should always display in the same | |
105 window e.g after typing g on a breakpoint in the breakpoints buffer. Breakpoint | |
106 icons are displayed both by setting a break with gud-break and by typing break | |
107 in the GUD buffer. | |
108 | |
109 This works best (depending on the size of your monitor) using most of the | |
110 screen. | |
111 | |
112 Displayed expressions appear in separate frames. Arrays may be displayed | |
113 as slices and visualised using the graph program from plotutils if installed. | |
114 Pointers in structures may be followed in a tree-like fashion. | |
115 | |
116 The following interactive lisp functions help control operation : | |
117 | |
118 `gdb-many-windows' - Toggle the number of windows gdb uses. | |
119 `gdb-restore-windows' - To restore the window layout." | |
120 ;; | |
121 (interactive (list (gud-query-cmdline 'gdba))) | |
122 ;; | |
123 ;; Let's start with a basic gud-gdb buffer and then modify it a bit. | |
124 (gdb command-line) | |
125 (gdb-ann3)) | |
126 | |
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
127 (defvar gdb-debug-log nil) |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
128 |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
129 (defcustom gdb-enable-debug-log nil |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
130 "Non-nil means record the process input and output in `gdb-debug-log'." |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
131 :type 'boolean |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
132 :group 'gud) |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
133 |
54538 | 134 (defun gdb-ann3 () |
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
135 (setq gdb-debug-log nil) |
54538 | 136 (set (make-local-variable 'gud-minor-mode) 'gdba) |
137 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter) | |
138 ;; | |
139 (gud-def gud-break (if (not (string-equal mode-name "Machine")) | |
140 (gud-call "break %f:%l" arg) | |
141 (save-excursion | |
142 (beginning-of-line) | |
143 (forward-char 2) | |
144 (gud-call "break *%a" arg))) | |
145 "\C-b" "Set breakpoint at current line or address.") | |
146 ;; | |
147 (gud-def gud-remove (if (not (string-equal mode-name "Machine")) | |
148 (gud-call "clear %f:%l" arg) | |
149 (save-excursion | |
150 (beginning-of-line) | |
151 (forward-char 2) | |
152 (gud-call "clear *%a" arg))) | |
153 "\C-d" "Remove breakpoint at current line or address.") | |
154 ;; | |
155 (gud-def gud-until (if (not (string-equal mode-name "Machine")) | |
156 (gud-call "until %f:%l" arg) | |
157 (save-excursion | |
158 (beginning-of-line) | |
159 (forward-char 2) | |
160 (gud-call "until *%a" arg))) | |
161 "\C-u" "Continue to current line or address.") | |
162 | |
163 (define-key gud-minor-mode-map [left-margin mouse-1] | |
164 'gdb-mouse-toggle-breakpoint) | |
165 (define-key gud-minor-mode-map [left-fringe mouse-1] | |
166 'gdb-mouse-toggle-breakpoint) | |
167 | |
168 (setq comint-input-sender 'gdb-send) | |
169 ;; | |
170 ;; (re-)initialise | |
171 (setq gdb-current-address "main") | |
172 (setq gdb-previous-address nil) | |
173 (setq gdb-previous-frame nil) | |
174 (setq gdb-current-frame "main") | |
175 (setq gdb-view-source t) | |
176 (setq gdb-selected-view 'source) | |
177 (setq gdb-var-list nil) | |
178 (setq gdb-var-changed nil) | |
179 (setq gdb-first-prompt nil) | |
180 ;; | |
181 (mapc 'make-local-variable gdb-variables) | |
182 (setq gdb-buffer-type 'gdba) | |
183 ;; | |
184 (gdb-clear-inferior-io) | |
185 ;; | |
186 (if (eq window-system 'w32) | |
187 (gdb-enqueue-input (list "set new-console off\n" 'ignore))) | |
188 (gdb-enqueue-input (list "set height 0\n" 'ignore)) | |
189 ;; find source file and compilation directory here | |
190 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program | |
191 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program | |
192 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info)) | |
193 ;; | |
194 (run-hooks 'gdba-mode-hook)) | |
195 | |
196 (defcustom gdb-use-colon-colon-notation nil | |
197 "Non-nil means use FUNCTION::VARIABLE format to display variables in the | |
198 speedbar." | |
199 :type 'boolean | |
200 :group 'gud) | |
201 | |
202 (defun gud-watch () | |
203 "Watch expression at point." | |
204 (interactive) | |
205 (require 'tooltip) | |
206 (let ((expr (tooltip-identifier-from-point (point)))) | |
207 (if (and (string-equal gdb-current-language "c") | |
208 gdb-use-colon-colon-notation) | |
209 (setq expr (concat gdb-current-frame "::" expr))) | |
210 (catch 'already-watched | |
211 (dolist (var gdb-var-list) | |
212 (if (string-equal expr (car var)) (throw 'already-watched nil))) | |
213 (set-text-properties 0 (length expr) nil expr) | |
214 (gdb-enqueue-input | |
215 (list (concat "server interpreter mi \"-var-create - * " expr "\"\n") | |
216 `(lambda () (gdb-var-create-handler ,expr)))))) | |
217 (select-window (get-buffer-window gud-comint-buffer))) | |
218 | |
219 (defconst gdb-var-create-regexp | |
220 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"") | |
221 | |
222 (defun gdb-var-create-handler (expr) | |
223 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
224 (goto-char (point-min)) | |
225 (if (re-search-forward gdb-var-create-regexp nil t) | |
226 (let ((var (list expr | |
227 (match-string 1) | |
228 (match-string 2) | |
229 (match-string 3) | |
230 nil nil))) | |
231 (push var gdb-var-list) | |
232 (setq speedbar-update-flag t) | |
233 (speedbar 1) | |
234 (if (equal (nth 2 var) "0") | |
235 (gdb-enqueue-input | |
236 (list (concat "server interpreter mi \"-var-evaluate-expression " | |
237 (nth 1 var) "\"\n") | |
238 `(lambda () (gdb-var-evaluate-expression-handler | |
239 ,(nth 1 var) nil)))) | |
240 (setq gdb-var-changed t))) | |
241 (if (re-search-forward "Undefined command" nil t) | |
242 (message "Watching expressions requires gdb 6.0 onwards") | |
243 (message "No symbol %s in current context." expr))))) | |
244 | |
245 (defun gdb-var-evaluate-expression-handler (varnum changed) | |
246 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
247 (goto-char (point-min)) | |
248 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t) | |
249 (catch 'var-found | |
250 (let ((var-list nil) (num 0)) | |
251 (dolist (var gdb-var-list) | |
252 (if (string-equal varnum (cadr var)) | |
253 (progn | |
254 (if changed (setcar (nthcdr 5 var) t)) | |
255 (setcar (nthcdr 4 var) (match-string 1)) | |
256 (setcar (nthcdr num gdb-var-list) var) | |
257 (throw 'var-found nil))) | |
258 (setq num (+ num 1)))))) | |
259 (setq gdb-var-changed t)) | |
260 | |
261 (defun gdb-var-list-children (varnum) | |
262 (gdb-enqueue-input | |
263 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n") | |
264 `(lambda () (gdb-var-list-children-handler ,varnum))))) | |
265 | |
266 (defconst gdb-var-list-children-regexp | |
267 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"") | |
268 | |
269 (defun gdb-var-list-children-handler (varnum) | |
270 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
271 (goto-char (point-min)) | |
272 (let ((var-list nil)) | |
273 (catch 'child-already-watched | |
274 (dolist (var gdb-var-list) | |
275 (if (string-equal varnum (cadr var)) | |
276 (progn | |
277 (push var var-list) | |
278 (while (re-search-forward gdb-var-list-children-regexp nil t) | |
279 (let ((varchild (list (match-string 2) | |
280 (match-string 1) | |
281 (match-string 3) | |
282 nil nil nil))) | |
283 (if (looking-at ",type=\"\\(.*?\\)\"") | |
284 (setcar (nthcdr 3 varchild) (match-string 1))) | |
285 (dolist (var1 gdb-var-list) | |
286 (if (string-equal (cadr var1) (cadr varchild)) | |
287 (throw 'child-already-watched nil))) | |
288 (push varchild var-list) | |
289 (if (equal (nth 2 varchild) "0") | |
290 (gdb-enqueue-input | |
291 (list | |
292 (concat | |
293 "server interpreter mi \"-var-evaluate-expression " | |
294 (nth 1 varchild) "\"\n") | |
295 `(lambda () (gdb-var-evaluate-expression-handler | |
296 ,(nth 1 varchild) nil)))))))) | |
297 (push var var-list))) | |
298 (setq gdb-var-list (nreverse var-list)))))) | |
299 | |
300 (defun gdb-var-update () | |
301 (if (not (member 'gdb-var-update (gdb-get-pending-triggers))) | |
302 (progn | |
303 (gdb-enqueue-input (list "server interpreter mi \"-var-update *\"\n" | |
304 'gdb-var-update-handler)) | |
305 (gdb-set-pending-triggers (cons 'gdb-var-update | |
306 (gdb-get-pending-triggers)))))) | |
307 | |
308 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"") | |
309 | |
310 (defun gdb-var-update-handler () | |
311 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
312 (goto-char (point-min)) | |
313 (while (re-search-forward gdb-var-update-regexp nil t) | |
314 (let ((varnum (match-string 1))) | |
315 (gdb-enqueue-input | |
316 (list (concat "server interpreter mi \"-var-evaluate-expression " | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
317 varnum "\"\n") |
54538 | 318 `(lambda () (gdb-var-evaluate-expression-handler |
319 ,varnum t))))))) | |
320 (gdb-set-pending-triggers | |
321 (delq 'gdb-var-update (gdb-get-pending-triggers)))) | |
322 | |
323 (defun gdb-var-delete () | |
324 "Delete watched expression from the speedbar." | |
325 (interactive) | |
326 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)) | |
327 (let ((text (speedbar-line-text))) | |
328 (string-match "\\(\\S-+\\)" text) | |
329 (let* ((expr (match-string 1 text)) | |
330 (var (assoc expr gdb-var-list)) | |
331 (varnum (cadr var))) | |
332 (unless (string-match "\\." varnum) | |
333 (gdb-enqueue-input | |
334 (list (concat "server interpreter mi \"-var-delete " | |
335 varnum "\"\n") | |
336 'ignore)) | |
337 (setq gdb-var-list (delq var gdb-var-list)) | |
338 (dolist (varchild gdb-var-list) | |
339 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild)) | |
340 (setq gdb-var-list (delq varchild gdb-var-list)))) | |
341 (setq gdb-var-changed t)))))) | |
342 | |
343 (defun gdb-edit-value (text token indent) | |
344 "Assign a value to a variable displayed in the speedbar" | |
345 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list)) | |
346 (varnum (cadr var)) (value)) | |
347 (setq value (read-string "New value: ")) | |
348 (gdb-enqueue-input | |
349 (list (concat "server interpreter mi \"-var-assign " | |
350 varnum " " value "\"\n") | |
351 'ignore)))) | |
352 | |
353 (defcustom gdb-show-changed-values t | |
354 "Non-nil means use font-lock-warning-face to display values that have | |
355 recently changed in the speedbar." | |
356 :type 'boolean | |
357 :group 'gud) | |
358 | |
359 (defun gdb-speedbar-expand-node (text token indent) | |
360 "Expand the node the user clicked on. | |
361 TEXT is the text of the button we clicked on, a + or - item. | |
362 TOKEN is data related to this node. | |
363 INDENT is the current indentation depth." | |
364 (cond ((string-match "+" text) ;expand this node | |
365 (gdb-var-list-children token)) | |
366 ((string-match "-" text) ;contract this node | |
367 (dolist (var gdb-var-list) | |
368 (if (string-match (concat token "\\.") (nth 1 var)) | |
369 (setq gdb-var-list (delq var gdb-var-list)))) | |
370 (setq gdb-var-changed t)))) | |
371 | |
372 | |
373 ;; ====================================================================== | |
374 ;; | |
375 ;; In this world, there are gdb variables (of unspecified | |
376 ;; representation) and buffers associated with those objects. | |
377 ;; The list of variables is built up by the expansions of | |
378 ;; def-gdb-variable | |
379 | |
380 (defmacro def-gdb-var (root-symbol &optional default doc) | |
381 (let* ((root (symbol-name root-symbol)) | |
382 (accessor (intern (concat "gdb-get-" root))) | |
383 (setter (intern (concat "gdb-set-" root))) | |
384 (name (intern (concat "gdb-" root)))) | |
385 `(progn | |
386 (defvar ,name ,default ,doc) | |
387 (if (not (memq ',name gdb-variables)) | |
388 (push ',name gdb-variables)) | |
389 (defun ,accessor () | |
390 (buffer-local-value ',name gud-comint-buffer)) | |
391 (defun ,setter (val) | |
392 (with-current-buffer gud-comint-buffer | |
393 (setq ,name val)))))) | |
394 | |
395 (def-gdb-var buffer-type nil | |
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
396 "One of the symbols bound in `gdb-buffer-rules'.") |
54538 | 397 |
398 (def-gdb-var burst "" | |
399 "A string of characters from gdb that have not yet been processed.") | |
400 | |
401 (def-gdb-var input-queue () | |
402 "A list of gdb command objects.") | |
403 | |
404 (def-gdb-var prompting nil | |
405 "True when gdb is idle with no pending input.") | |
406 | |
407 (def-gdb-var output-sink 'user | |
408 "The disposition of the output of the current gdb command. | |
409 Possible values are these symbols: | |
410 | |
411 user -- gdb output should be copied to the GUD buffer | |
412 for the user to see. | |
413 | |
414 inferior -- gdb output should be copied to the inferior-io buffer | |
415 | |
416 pre-emacs -- output should be ignored util the post-prompt | |
417 annotation is received. Then the output-sink | |
418 becomes:... | |
419 emacs -- output should be collected in the partial-output-buffer | |
420 for subsequent processing by a command. This is the | |
421 disposition of output generated by commands that | |
422 gdb mode sends to gdb on its own behalf. | |
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
423 post-emacs -- ignore output until the prompt annotation is |
54538 | 424 received, then go to USER disposition. |
425 ") | |
426 | |
427 (def-gdb-var current-item nil | |
428 "The most recent command item sent to gdb.") | |
429 | |
430 (def-gdb-var pending-triggers '() | |
431 "A list of trigger functions that have run later than their output | |
432 handlers.") | |
433 | |
434 ;; end of gdb variables | |
435 | |
436 (defun gdb-get-target-string () | |
437 (with-current-buffer gud-comint-buffer | |
438 gud-target-name)) | |
439 | |
440 | |
441 ;; | |
442 ;; gdb buffers. | |
443 ;; | |
444 ;; Each buffer has a TYPE -- a symbol that identifies the function | |
445 ;; of that particular buffer. | |
446 ;; | |
447 ;; The usual gdb interaction buffer is given the type `gdba' and | |
448 ;; is constructed specially. | |
449 ;; | |
450 ;; Others are constructed by gdb-get-create-buffer and | |
451 ;; named according to the rules set forth in the gdb-buffer-rules-assoc | |
452 | |
453 (defvar gdb-buffer-rules-assoc '()) | |
454 | |
455 (defun gdb-get-buffer (key) | |
456 "Return the gdb buffer tagged with type KEY. | |
457 The key should be one of the cars in `gdb-buffer-rules-assoc'." | |
458 (save-excursion | |
459 (gdb-look-for-tagged-buffer key (buffer-list)))) | |
460 | |
461 (defun gdb-get-create-buffer (key) | |
462 "Create a new gdb buffer of the type specified by KEY. | |
463 The key should be one of the cars in `gdb-buffer-rules-assoc'." | |
464 (or (gdb-get-buffer key) | |
465 (let* ((rules (assoc key gdb-buffer-rules-assoc)) | |
466 (name (funcall (gdb-rules-name-maker rules))) | |
467 (new (get-buffer-create name))) | |
468 (with-current-buffer new | |
469 ;; FIXME: This should be set after calling the function, since the | |
470 ;; function should run kill-all-local-variables. | |
471 (set (make-local-variable 'gdb-buffer-type) key) | |
472 (if (cdr (cdr rules)) | |
473 (funcall (car (cdr (cdr rules))))) | |
474 (set (make-local-variable 'gud-comint-buffer) gud-comint-buffer) | |
475 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
476 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
477 new)))) | |
478 | |
479 (defun gdb-rules-name-maker (rules) (car (cdr rules))) | |
480 | |
481 (defun gdb-look-for-tagged-buffer (key bufs) | |
482 (let ((retval nil)) | |
483 (while (and (not retval) bufs) | |
484 (set-buffer (car bufs)) | |
485 (if (eq gdb-buffer-type key) | |
486 (setq retval (car bufs))) | |
487 (setq bufs (cdr bufs))) | |
488 retval)) | |
489 | |
490 ;; | |
491 ;; This assoc maps buffer type symbols to rules. Each rule is a list of | |
492 ;; at least one and possible more functions. The functions have these | |
493 ;; roles in defining a buffer type: | |
494 ;; | |
495 ;; NAME - Return a name for this buffer type. | |
496 ;; | |
497 ;; The remaining function(s) are optional: | |
498 ;; | |
499 ;; MODE - called in a new buffer with no arguments, should establish | |
500 ;; the proper mode for the buffer. | |
501 ;; | |
502 | |
503 (defun gdb-set-buffer-rules (buffer-type &rest rules) | |
504 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc))) | |
505 (if binding | |
506 (setcdr binding rules) | |
507 (push (cons buffer-type rules) | |
508 gdb-buffer-rules-assoc)))) | |
509 | |
510 ;; GUD buffers are an exception to the rules | |
511 (gdb-set-buffer-rules 'gdba 'error) | |
512 | |
513 ;; | |
514 ;; Partial-output buffer : This accumulates output from a command executed on | |
515 ;; behalf of emacs (rather than the user). | |
516 ;; | |
517 (gdb-set-buffer-rules 'gdb-partial-output-buffer | |
518 'gdb-partial-output-name) | |
519 | |
520 (defun gdb-partial-output-name () | |
521 (concat "*partial-output-" | |
522 (gdb-get-target-string) | |
523 "*")) | |
524 | |
525 | |
526 (gdb-set-buffer-rules 'gdb-inferior-io | |
527 'gdb-inferior-io-name | |
528 'gdb-inferior-io-mode) | |
529 | |
530 (defun gdb-inferior-io-name () | |
531 (concat "*input/output of " | |
532 (gdb-get-target-string) | |
533 "*")) | |
534 | |
535 (defvar gdb-inferior-io-mode-map | |
536 (let ((map (make-sparse-keymap))) | |
537 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt) | |
538 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop) | |
539 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit) | |
540 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof) | |
541 map)) | |
542 | |
543 (define-derived-mode gdb-inferior-io-mode comint-mode "Debuggee I/O" | |
544 "Major mode for gdb inferior-io." | |
545 :syntax-table nil :abbrev-table nil | |
546 ;; We want to use comint because it has various nifty and familiar | |
547 ;; features. We don't need a process, but comint wants one, so create | |
548 ;; a dummy one. | |
549 (make-comint-in-buffer | |
550 (substring (buffer-name) 1 (- (length (buffer-name)) 1)) | |
551 (current-buffer) "hexl") | |
552 (setq comint-input-sender 'gdb-inferior-io-sender)) | |
553 | |
554 (defun gdb-inferior-io-sender (proc string) | |
555 ;; PROC is the pseudo-process created to satisfy comint. | |
556 (with-current-buffer (process-buffer proc) | |
557 (setq proc (get-buffer-process gud-comint-buffer)) | |
558 (process-send-string proc string) | |
559 (process-send-string proc "\n"))) | |
560 | |
561 (defun gdb-inferior-io-interrupt () | |
562 "Interrupt the program being debugged." | |
563 (interactive) | |
564 (interrupt-process | |
565 (get-buffer-process gud-comint-buffer) comint-ptyp)) | |
566 | |
567 (defun gdb-inferior-io-quit () | |
568 "Send quit signal to the program being debugged." | |
569 (interactive) | |
570 (quit-process | |
571 (get-buffer-process gud-comint-buffer) comint-ptyp)) | |
572 | |
573 (defun gdb-inferior-io-stop () | |
574 "Stop the program being debugged." | |
575 (interactive) | |
576 (stop-process | |
577 (get-buffer-process gud-comint-buffer) comint-ptyp)) | |
578 | |
579 (defun gdb-inferior-io-eof () | |
580 "Send end-of-file to the program being debugged." | |
581 (interactive) | |
582 (process-send-eof | |
583 (get-buffer-process gud-comint-buffer))) | |
584 | |
585 | |
586 ;; | |
587 ;; gdb communications | |
588 ;; | |
589 | |
590 ;; INPUT: things sent to gdb | |
591 ;; | |
592 ;; The queues are lists. Each element is either a string (indicating user or | |
593 ;; user-like input) or a list of the form: | |
594 ;; | |
595 ;; (INPUT-STRING HANDLER-FN) | |
596 ;; | |
597 ;; The handler function will be called from the partial-output buffer when the | |
598 ;; command completes. This is the way to write commands which invoke gdb | |
599 ;; commands autonomously. | |
600 ;; | |
601 ;; These lists are consumed tail first. | |
602 ;; | |
603 | |
604 (defun gdb-send (proc string) | |
605 "A comint send filter for gdb. | |
606 This filter may simply queue output for a later time." | |
607 (gdb-enqueue-input (concat string "\n"))) | |
608 | |
609 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it | |
610 ;; is a query, or other non-top-level prompt. | |
611 | |
612 (defun gdb-enqueue-input (item) | |
613 (if (gdb-get-prompting) | |
614 (progn | |
615 (gdb-send-item item) | |
616 (gdb-set-prompting nil)) | |
617 (gdb-set-input-queue | |
618 (cons item (gdb-get-input-queue))))) | |
619 | |
620 (defun gdb-dequeue-input () | |
621 (let ((queue (gdb-get-input-queue))) | |
622 (and queue | |
623 (let ((last (car (last queue)))) | |
624 (unless (nbutlast queue) (gdb-set-input-queue '())) | |
625 last)))) | |
626 | |
627 | |
628 ;; | |
629 ;; output -- things gdb prints to emacs | |
630 ;; | |
631 ;; GDB output is a stream interrupted by annotations. | |
632 ;; Annotations can be recognized by their beginning | |
633 ;; with \C-j\C-z\C-z<tag><opt>\C-j | |
634 ;; | |
635 ;; The tag is a string obeying symbol syntax. | |
636 ;; | |
637 ;; The optional part `<opt>' can be either the empty string | |
638 ;; or a space followed by more data relating to the annotation. | |
639 ;; For example, the SOURCE annotation is followed by a filename, | |
640 ;; line number and various useless goo. This data must not include | |
641 ;; any newlines. | |
642 ;; | |
643 | |
644 (defcustom gud-gdba-command-name "gdb -annotate=3" | |
645 "Default command to execute an executable under the GDB-UI debugger." | |
646 :type 'string | |
647 :group 'gud) | |
648 | |
649 (defvar gdb-annotation-rules | |
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 ) "An assoc mapping annotation tags to functions which process them.") | |
667 | |
668 (defconst gdb-source-spec-regexp | |
669 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:\\(0x[a-f0-9]*\\)") | |
670 | |
671 ;; Do not use this except as an annotation handler. | |
672 (defun gdb-source (args) | |
673 (string-match gdb-source-spec-regexp args) | |
674 ;; Extract the frame position from the marker. | |
675 (setq gud-last-frame | |
676 (cons | |
677 (match-string 1 args) | |
678 (string-to-int (match-string 2 args)))) | |
679 (setq gdb-current-address (match-string 3 args)) | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
680 (setq gdb-view-source t) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
681 ;; cover for auto-display output which comes *before* |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
682 ;; stopped annotation |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
683 (if (eq (gdb-get-output-sink) 'inferior) (gdb-set-output-sink 'user))) |
54538 | 684 |
685 (defun gdb-send-item (item) | |
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
686 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log)) |
54538 | 687 (gdb-set-current-item item) |
688 (if (stringp item) | |
689 (progn | |
690 (gdb-set-output-sink 'user) | |
691 (process-send-string (get-buffer-process gud-comint-buffer) item)) | |
692 (progn | |
693 (gdb-clear-partial-output) | |
694 (gdb-set-output-sink 'pre-emacs) | |
695 (process-send-string (get-buffer-process gud-comint-buffer) | |
696 (car item))))) | |
697 | |
698 (defun gdb-pre-prompt (ignored) | |
699 "An annotation handler for `pre-prompt'. This terminates the collection of | |
700 output from a previous command if that happens to be in effect." | |
701 (let ((sink (gdb-get-output-sink))) | |
702 (cond | |
703 ((eq sink 'user) t) | |
704 ((eq sink 'emacs) | |
705 (gdb-set-output-sink 'post-emacs)) | |
706 (t | |
707 (gdb-set-output-sink 'user) | |
708 (error "Phase error in gdb-pre-prompt (got %s)" sink))))) | |
709 | |
710 (defun gdb-prompt (ignored) | |
711 "An annotation handler for `prompt'. | |
712 This sends the next command (if any) to gdb." | |
713 (when gdb-first-prompt (gdb-ann3)) | |
714 (let ((sink (gdb-get-output-sink))) | |
715 (cond | |
716 ((eq sink 'user) t) | |
717 ((eq sink 'post-emacs) | |
718 (gdb-set-output-sink 'user) | |
719 (let ((handler | |
720 (car (cdr (gdb-get-current-item))))) | |
721 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
722 (funcall handler)))) | |
723 (t | |
724 (gdb-set-output-sink 'user) | |
725 (error "Phase error in gdb-prompt (got %s)" sink)))) | |
726 (let ((input (gdb-dequeue-input))) | |
727 (if input | |
728 (gdb-send-item input) | |
729 (progn | |
730 (gdb-set-prompting t) | |
731 (gud-display-frame))))) | |
732 | |
733 (defun gdb-subprompt (ignored) | |
734 "An annotation handler for non-top-level prompts." | |
735 (gdb-set-prompting t)) | |
736 | |
737 (defun gdb-starting (ignored) | |
738 "An annotation handler for `starting'. This says that I/O for the | |
739 subprocess is now the program being debugged, not GDB." | |
740 (let ((sink (gdb-get-output-sink))) | |
741 (cond | |
742 ((eq sink 'user) | |
743 (progn | |
744 (setq gud-running t) | |
745 (gdb-set-output-sink 'inferior))) | |
746 (t (error "Unexpected `starting' annotation"))))) | |
747 | |
748 (defun gdb-stopping (ignored) | |
749 "An annotation handler for `exited' and other annotations which say that I/O | |
750 for the subprocess is now GDB, not the program being debugged." | |
751 (let ((sink (gdb-get-output-sink))) | |
752 (cond | |
753 ((eq sink 'inferior) | |
754 (gdb-set-output-sink 'user)) | |
755 (t (error "Unexpected stopping annotation"))))) | |
756 | |
757 (defun gdb-frame-begin (ignored) | |
758 (let ((sink (gdb-get-output-sink))) | |
759 (cond | |
760 ((eq sink 'inferior) | |
761 (gdb-set-output-sink 'user)) | |
762 ((eq sink 'user) t) | |
763 ((eq sink 'emacs) t) | |
764 (t (error "Unexpected frame-begin annotation (%S)" sink))))) | |
765 | |
766 (defun gdb-stopped (ignored) | |
767 "An annotation handler for `stopped'. It is just like gdb-stopping, except | |
768 that if we already set the output sink to 'user in gdb-stopping, that is fine." | |
769 (setq gud-running nil) | |
770 (let ((sink (gdb-get-output-sink))) | |
771 (cond | |
772 ((eq sink 'inferior) | |
773 (gdb-set-output-sink 'user)) | |
774 ((eq sink 'user) t) | |
775 (t (error "Unexpected stopped annotation"))))) | |
776 | |
777 (defun gdb-post-prompt (ignored) | |
778 "An annotation handler for `post-prompt'. This begins the collection of | |
779 output from the current command if that happens to be appropriate." | |
780 (if (not (gdb-get-pending-triggers)) | |
781 (progn | |
782 (gdb-get-current-frame) | |
783 (gdb-invalidate-frames) | |
784 (gdb-invalidate-breakpoints) | |
785 (gdb-invalidate-assembler) | |
786 (gdb-invalidate-registers) | |
787 (gdb-invalidate-locals) | |
788 (gdb-invalidate-threads) | |
54617
9049edac1117
(gdb-post-prompt): Fix test.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54616
diff
changeset
|
789 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3. |
9049edac1117
(gdb-post-prompt): Fix test.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54616
diff
changeset
|
790 ;; FIXME: with GDB-6 on Darwin, this might very well work. |
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
791 (dolist (frame (frame-list)) |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
792 (when (string-equal (frame-parameter frame 'name) "Speedbar") |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
793 (setq gdb-var-changed t) ; force update |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
794 (dolist (var gdb-var-list) |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
795 (setcar (nthcdr 5 var) nil)))) |
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
796 (gdb-var-update)))) |
54538 | 797 (let ((sink (gdb-get-output-sink))) |
798 (cond | |
799 ((eq sink 'user) t) | |
800 ((eq sink 'pre-emacs) | |
801 (gdb-set-output-sink 'emacs)) | |
802 (t | |
803 (gdb-set-output-sink 'user) | |
804 (error "Phase error in gdb-post-prompt (got %s)" sink))))) | |
805 | |
806 (defun gud-gdba-marker-filter (string) | |
807 "A gud marker filter for gdb. Handle a burst of output from GDB." | |
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
808 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log)) |
54538 | 809 ;; Recall the left over gud-marker-acc from last time |
810 (setq gud-marker-acc (concat gud-marker-acc string)) | |
811 ;; Start accumulating output for the GUD buffer | |
812 (let ((output "")) | |
813 ;; | |
814 ;; Process all the complete markers in this chunk. | |
815 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc) | |
816 (let ((annotation (match-string 1 gud-marker-acc))) | |
817 ;; | |
818 ;; Stuff prior to the match is just ordinary output. | |
819 ;; It is either concatenated to OUTPUT or directed | |
820 ;; elsewhere. | |
821 (setq output | |
822 (gdb-concat-output | |
823 output | |
824 (substring gud-marker-acc 0 (match-beginning 0)))) | |
825 ;; | |
826 ;; Take that stuff off the gud-marker-acc. | |
827 (setq gud-marker-acc (substring gud-marker-acc (match-end 0))) | |
828 ;; | |
829 ;; Parse the tag from the annotation, and maybe its arguments. | |
830 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation) | |
831 (let* ((annotation-type (match-string 1 annotation)) | |
832 (annotation-arguments (match-string 2 annotation)) | |
833 (annotation-rule (assoc annotation-type | |
834 gdb-annotation-rules))) | |
835 ;; Call the handler for this annotation. | |
836 (if annotation-rule | |
837 (funcall (car (cdr annotation-rule)) | |
838 annotation-arguments) | |
839 ;; Else the annotation is not recognized. Ignore it silently, | |
840 ;; so that GDB can add new annotations without causing | |
841 ;; us to blow up. | |
842 )))) | |
843 ;; | |
844 ;; Does the remaining text end in a partial line? | |
845 ;; If it does, then keep part of the gud-marker-acc until we get more. | |
846 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'" | |
847 gud-marker-acc) | |
848 (progn | |
849 ;; Everything before the potential marker start can be output. | |
850 (setq output | |
851 (gdb-concat-output output | |
852 (substring gud-marker-acc 0 | |
853 (match-beginning 0)))) | |
854 ;; | |
855 ;; Everything after, we save, to combine with later input. | |
856 (setq gud-marker-acc (substring gud-marker-acc (match-beginning 0)))) | |
857 ;; | |
858 ;; In case we know the gud-marker-acc contains no partial annotations: | |
859 (progn | |
860 (setq output (gdb-concat-output output gud-marker-acc)) | |
861 (setq gud-marker-acc ""))) | |
862 output)) | |
863 | |
864 (defun gdb-concat-output (so-far new) | |
865 (let ((sink (gdb-get-output-sink ))) | |
866 (cond | |
867 ((eq sink 'user) (concat so-far new)) | |
868 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far) | |
869 ((eq sink 'emacs) | |
870 (gdb-append-to-partial-output new) | |
871 so-far) | |
872 ((eq sink 'inferior) | |
873 (gdb-append-to-inferior-io new) | |
874 so-far) | |
875 (t (error "Bogon output sink %S" sink))))) | |
876 | |
877 (defun gdb-append-to-partial-output (string) | |
878 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
879 (goto-char (point-max)) | |
880 (insert string))) | |
881 | |
882 (defun gdb-clear-partial-output () | |
883 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
884 (erase-buffer))) | |
885 | |
886 (defun gdb-append-to-inferior-io (string) | |
887 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io) | |
888 (goto-char (point-max)) | |
889 (insert-before-markers string)) | |
890 (if (not (string-equal string "")) | |
891 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))) | |
892 | |
893 (defun gdb-clear-inferior-io () | |
894 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io) | |
895 (erase-buffer))) | |
896 | |
897 | |
898 ;; One trick is to have a command who's output is always available in a buffer | |
899 ;; of it's own, and is always up to date. We build several buffers of this | |
900 ;; type. | |
901 ;; | |
902 ;; There are two aspects to this: gdb has to tell us when the output for that | |
903 ;; command might have changed, and we have to be able to run the command | |
904 ;; behind the user's back. | |
905 ;; | |
906 ;; The output phasing associated with the variable gdb-output-sink | |
907 ;; help us to run commands behind the user's back. | |
908 ;; | |
909 ;; Below is the code for specificly managing buffers of output from one | |
910 ;; command. | |
911 ;; | |
912 | |
913 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES | |
914 ;; It adds an input for the command we are tracking. It should be the | |
915 ;; annotation rule binding of whatever gdb sends to tell us this command | |
916 ;; might have changed it's output. | |
917 ;; | |
918 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed. | |
919 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the | |
920 ;; input in the input queue (see comment about ``gdb communications'' above). | |
921 | |
922 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command | |
923 output-handler) | |
924 `(defun ,name (&optional ignored) | |
925 (if (and (,demand-predicate) | |
926 (not (member ',name | |
927 (gdb-get-pending-triggers)))) | |
928 (progn | |
929 (gdb-enqueue-input | |
930 (list ,gdb-command ',output-handler)) | |
931 (gdb-set-pending-triggers | |
932 (cons ',name | |
933 (gdb-get-pending-triggers))))))) | |
934 | |
935 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun) | |
936 `(defun ,name () | |
937 (gdb-set-pending-triggers | |
938 (delq ',trigger | |
939 (gdb-get-pending-triggers))) | |
940 (let ((buf (gdb-get-buffer ',buf-key))) | |
941 (and buf | |
942 (with-current-buffer buf | |
943 (let ((p (point)) | |
944 (buffer-read-only nil)) | |
945 (erase-buffer) | |
946 (insert-buffer-substring (gdb-get-create-buffer | |
947 'gdb-partial-output-buffer)) | |
948 (goto-char p))))) | |
949 ;; put customisation here | |
950 (,custom-defun))) | |
951 | |
952 (defmacro def-gdb-auto-updated-buffer (buffer-key trigger-name gdb-command | |
953 output-handler-name custom-defun) | |
954 `(progn | |
955 (def-gdb-auto-update-trigger ,trigger-name | |
956 ;; The demand predicate: | |
957 (lambda () (gdb-get-buffer ',buffer-key)) | |
958 ,gdb-command | |
959 ,output-handler-name) | |
960 (def-gdb-auto-update-handler ,output-handler-name | |
961 ,trigger-name ,buffer-key ,custom-defun))) | |
962 | |
963 | |
964 ;; | |
965 ;; Breakpoint buffer : This displays the output of `info breakpoints'. | |
966 ;; | |
967 (gdb-set-buffer-rules 'gdb-breakpoints-buffer | |
968 'gdb-breakpoints-buffer-name | |
969 'gdb-breakpoints-mode) | |
970 | |
971 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer | |
972 ;; This defines the auto update rule for buffers of type | |
973 ;; `gdb-breakpoints-buffer'. | |
974 ;; | |
975 ;; It defines a function to serve as the annotation handler that | |
976 ;; handles the `foo-invalidated' message. That function is called: | |
977 gdb-invalidate-breakpoints | |
978 ;; | |
979 ;; To update the buffer, this command is sent to gdb. | |
980 "server info breakpoints\n" | |
981 ;; | |
982 ;; This also defines a function to be the handler for the output | |
983 ;; from the command above. That function will copy the output into | |
984 ;; the appropriately typed buffer. That function will be called: | |
985 gdb-info-breakpoints-handler | |
986 ;; buffer specific functions | |
987 gdb-info-breakpoints-custom) | |
988 | |
989 (defvar gdb-cdir nil "Compilation directory.") | |
990 | |
991 (defconst breakpoint-xpm-data "/* XPM */ | |
992 static char *magick[] = { | |
993 /* columns rows colors chars-per-pixel */ | |
994 \"10 10 2 1\", | |
995 \" c red\", | |
996 \"+ c None\", | |
997 /* pixels */ | |
998 \"+++ +++\", | |
999 \"++ ++\", | |
1000 \"+ +\", | |
1001 \" \", | |
1002 \" \", | |
1003 \" \", | |
1004 \" \", | |
1005 \"+ +\", | |
1006 \"++ ++\", | |
1007 \"+++ +++\", | |
1008 };" | |
1009 "XPM data used for breakpoint icon.") | |
1010 | |
1011 (defconst breakpoint-enabled-pbm-data | |
1012 "P1 | |
1013 10 10\", | |
1014 0 0 0 0 1 1 1 1 0 0 0 0 | |
1015 0 0 0 1 1 1 1 1 1 0 0 0 | |
1016 0 0 1 1 1 1 1 1 1 1 0 0 | |
1017 0 1 1 1 1 1 1 1 1 1 1 0 | |
1018 0 1 1 1 1 1 1 1 1 1 1 0 | |
1019 0 1 1 1 1 1 1 1 1 1 1 0 | |
1020 0 1 1 1 1 1 1 1 1 1 1 0 | |
1021 0 0 1 1 1 1 1 1 1 1 0 0 | |
1022 0 0 0 1 1 1 1 1 1 0 0 0 | |
1023 0 0 0 0 1 1 1 1 0 0 0 0" | |
1024 "PBM data used for enabled breakpoint icon.") | |
1025 | |
1026 (defconst breakpoint-disabled-pbm-data | |
1027 "P1 | |
1028 10 10\", | |
1029 0 0 1 0 1 0 1 0 0 0 | |
1030 0 1 0 1 0 1 0 1 0 0 | |
1031 1 0 1 0 1 0 1 0 1 0 | |
1032 0 1 0 1 0 1 0 1 0 1 | |
1033 1 0 1 0 1 0 1 0 1 0 | |
1034 0 1 0 1 0 1 0 1 0 1 | |
1035 1 0 1 0 1 0 1 0 1 0 | |
1036 0 1 0 1 0 1 0 1 0 1 | |
1037 0 0 1 0 1 0 1 0 1 0 | |
1038 0 0 0 1 0 1 0 1 0 0" | |
1039 "PBM data used for disabled breakpoint icon.") | |
1040 | |
1041 (defvar breakpoint-enabled-icon nil | |
1042 "Icon for enabled breakpoint in display margin") | |
1043 | |
1044 (defvar breakpoint-disabled-icon nil | |
1045 "Icon for disabled breakpoint in display margin") | |
1046 | |
1047 (defvar breakpoint-bitmap nil | |
1048 "Bitmap for breakpoint in fringe") | |
1049 | |
1050 (defface breakpoint-enabled-bitmap-face | |
1051 '((t | |
1052 :inherit fringe | |
1053 :foreground "red")) | |
1054 "Face for enabled breakpoint icon in fringe.") | |
1055 | |
1056 (defface breakpoint-disabled-bitmap-face | |
1057 '((t | |
1058 :inherit fringe | |
1059 :foreground "grey60")) | |
1060 "Face for disabled breakpoint icon in fringe.") | |
1061 | |
1062 | |
1063 ;;-put breakpoint icons in relevant margins (even those set in the GUD buffer) | |
1064 (defun gdb-info-breakpoints-custom () | |
1065 (let ((flag)(address)) | |
1066 ;; | |
1067 ;; remove all breakpoint-icons in source buffers but not assembler buffer | |
1068 (dolist (buffer (buffer-list)) | |
1069 (with-current-buffer buffer | |
1070 (if (and (eq gud-minor-mode 'gdba) | |
1071 (not (string-match "^\*" (buffer-name)))) | |
1072 (gdb-remove-breakpoint-icons (point-min) (point-max))))) | |
1073 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer) | |
1074 (save-excursion | |
1075 (goto-char (point-min)) | |
1076 (while (< (point) (- (point-max) 1)) | |
1077 (forward-line 1) | |
1078 (if (looking-at "[^\t].*breakpoint") | |
1079 (progn | |
1080 (looking-at "[0-9]*\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)") | |
1081 (setq flag (char-after (match-beginning 1))) | |
1082 (beginning-of-line) | |
1083 (if (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t) | |
1084 (progn | |
1085 (looking-at "\\(\\S-*\\):\\([0-9]+\\)") | |
1086 (let ((line (match-string 2)) (buffer-read-only nil) | |
1087 (file (match-string 1))) | |
1088 (add-text-properties (point-at-bol) (point-at-eol) | |
1089 '(mouse-face highlight | |
1090 help-echo "mouse-2, RET: visit breakpoint")) | |
1091 (with-current-buffer | |
1092 (find-file-noselect | |
1093 (if (file-exists-p file) file | |
1094 (expand-file-name file gdb-cdir))) | |
1095 (save-current-buffer | |
1096 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
1097 (set (make-local-variable 'tool-bar-map) | |
1098 gud-tool-bar-map)) | |
1099 ;; only want one breakpoint icon at each location | |
1100 (save-excursion | |
1101 (goto-line (string-to-number line)) | |
1102 (gdb-put-breakpoint-icon (eq flag ?y))))))))) | |
1103 (end-of-line))))) | |
1104 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom))) | |
1105 | |
1106 (defun gdb-mouse-toggle-breakpoint (event) | |
1107 "Toggle breakpoint with mouse click in left margin." | |
1108 (interactive "e") | |
1109 (mouse-minibuffer-check event) | |
1110 (let ((posn (event-end event))) | |
1111 (if (numberp (posn-point posn)) | |
1112 (with-selected-window (posn-window posn) | |
1113 (save-excursion | |
1114 (goto-char (posn-point posn)) | |
1115 (if (or (posn-object posn) | |
1116 (and breakpoint-bitmap | |
1117 (eq (car (fringe-bitmaps-at-pos (posn-point posn))) | |
1118 breakpoint-bitmap))) | |
1119 (gud-remove nil) | |
1120 (gud-break nil))))))) | |
1121 | |
1122 (defun gdb-breakpoints-buffer-name () | |
1123 (with-current-buffer gud-comint-buffer | |
1124 (concat "*breakpoints of " (gdb-get-target-string) "*"))) | |
1125 | |
1126 (defun gdb-display-breakpoints-buffer () | |
1127 (interactive) | |
1128 (gdb-display-buffer | |
1129 (gdb-get-create-buffer 'gdb-breakpoints-buffer))) | |
1130 | |
1131 (defun gdb-frame-breakpoints-buffer () | |
1132 (interactive) | |
1133 (switch-to-buffer-other-frame | |
1134 (gdb-get-create-buffer 'gdb-breakpoints-buffer))) | |
1135 | |
1136 (defvar gdb-breakpoints-mode-map | |
1137 (let ((map (make-sparse-keymap)) | |
1138 (menu (make-sparse-keymap "Breakpoints"))) | |
1139 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint)) | |
1140 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint)) | |
1141 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint)) | |
1142 | |
1143 (suppress-keymap map) | |
1144 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu)) | |
1145 (define-key map " " 'gdb-toggle-breakpoint) | |
1146 (define-key map "d" 'gdb-delete-breakpoint) | |
1147 (define-key map "\r" 'gdb-goto-breakpoint) | |
1148 (define-key map [mouse-2] 'gdb-mouse-goto-breakpoint) | |
1149 map)) | |
1150 | |
1151 (defun gdb-breakpoints-mode () | |
1152 "Major mode for gdb breakpoints. | |
1153 | |
1154 \\{gdb-breakpoints-mode-map}" | |
1155 (setq major-mode 'gdb-breakpoints-mode) | |
1156 (setq mode-name "Breakpoints") | |
1157 (use-local-map gdb-breakpoints-mode-map) | |
1158 (setq buffer-read-only t) | |
1159 (gdb-invalidate-breakpoints)) | |
1160 | |
1161 (defun gdb-toggle-breakpoint () | |
1162 "Enable/disable the breakpoint at current line." | |
1163 (interactive) | |
1164 (save-excursion | |
1165 (beginning-of-line 1) | |
1166 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | |
1167 (error "Not recognized as break/watchpoint line") | |
1168 (gdb-enqueue-input | |
1169 (list | |
1170 (concat | |
1171 (if (eq ?y (char-after (match-beginning 2))) | |
1172 "server disable " | |
1173 "server enable ") | |
1174 (match-string 1) "\n") | |
1175 'ignore))))) | |
1176 | |
1177 (defun gdb-delete-breakpoint () | |
1178 "Delete the breakpoint at current line." | |
1179 (interactive) | |
1180 (beginning-of-line 1) | |
1181 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | |
1182 (error "Not recognized as break/watchpoint line") | |
1183 (gdb-enqueue-input | |
1184 (list (concat "server delete " (match-string 1) "\n") 'ignore)))) | |
1185 | |
1186 (defvar gdb-source-window nil) | |
1187 | |
1188 (defun gdb-goto-breakpoint () | |
1189 "Display the file in the source buffer at the breakpoint specified on the | |
1190 current line." | |
1191 (interactive) | |
1192 (save-excursion | |
1193 (beginning-of-line 1) | |
1194 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t) | |
1195 (looking-at "\\(\\S-*\\):\\([0-9]+\\)")) | |
1196 (if (match-string 2) | |
1197 (let ((line (match-string 2)) | |
1198 (file (match-string 1))) | |
1199 (save-selected-window | |
1200 (select-window gdb-source-window) | |
1201 (switch-to-buffer (find-file-noselect | |
1202 (if (file-exists-p file) | |
1203 file | |
1204 (expand-file-name file gdb-cdir)))) | |
1205 (goto-line (string-to-number line)))))) | |
1206 | |
1207 (defun gdb-mouse-goto-breakpoint (event) | |
1208 "Display the file in the source buffer at the selected breakpoint." | |
1209 (interactive "e") | |
1210 (mouse-set-point event) | |
1211 (gdb-goto-breakpoint)) | |
1212 | |
1213 ;; | |
1214 ;; Frames buffer. This displays a perpetually correct bactracktrace | |
1215 ;; (from the command `where'). | |
1216 ;; | |
1217 ;; Alas, if your stack is deep, it is costly. | |
1218 ;; | |
1219 (gdb-set-buffer-rules 'gdb-stack-buffer | |
1220 'gdb-stack-buffer-name | |
1221 'gdb-frames-mode) | |
1222 | |
1223 (def-gdb-auto-updated-buffer gdb-stack-buffer | |
1224 gdb-invalidate-frames | |
1225 "server where\n" | |
1226 gdb-info-frames-handler | |
1227 gdb-info-frames-custom) | |
1228 | |
1229 (defun gdb-info-frames-custom () | |
1230 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer) | |
1231 (save-excursion | |
1232 (let ((buffer-read-only nil)) | |
1233 (goto-char (point-min)) | |
1234 (while (< (point) (point-max)) | |
1235 (add-text-properties (point-at-bol) (point-at-eol) | |
1236 '(mouse-face highlight | |
1237 help-echo "mouse-2, RET: Select frame")) | |
1238 (beginning-of-line) | |
1239 (when (and (or (looking-at "^#[0-9]*\\s-*\\S-* in \\(\\S-*\\)") | |
1240 (looking-at "^#[0-9]*\\s-*\\(\\S-*\\)")) | |
1241 (equal (match-string 1) gdb-current-frame)) | |
1242 (put-text-property (point-at-bol) (point-at-eol) | |
1243 'face '(:inverse-video t))) | |
1244 (forward-line 1)))))) | |
1245 | |
1246 (defun gdb-stack-buffer-name () | |
1247 (with-current-buffer gud-comint-buffer | |
1248 (concat "*stack frames of " (gdb-get-target-string) "*"))) | |
1249 | |
1250 (defun gdb-display-stack-buffer () | |
1251 (interactive) | |
1252 (gdb-display-buffer | |
1253 (gdb-get-create-buffer 'gdb-stack-buffer))) | |
1254 | |
1255 (defun gdb-frame-stack-buffer () | |
1256 (interactive) | |
1257 (switch-to-buffer-other-frame | |
1258 (gdb-get-create-buffer 'gdb-stack-buffer))) | |
1259 | |
1260 (defvar gdb-frames-mode-map | |
1261 (let ((map (make-sparse-keymap))) | |
1262 (suppress-keymap map) | |
1263 (define-key map "\r" 'gdb-frames-select) | |
1264 (define-key map [mouse-2] 'gdb-frames-mouse-select) | |
1265 map)) | |
1266 | |
1267 (defun gdb-frames-mode () | |
1268 "Major mode for gdb frames. | |
1269 | |
1270 \\{gdb-frames-mode-map}" | |
1271 (setq major-mode 'gdb-frames-mode) | |
1272 (setq mode-name "Frames") | |
1273 (setq buffer-read-only t) | |
1274 (use-local-map gdb-frames-mode-map) | |
1275 (font-lock-mode -1) | |
1276 (gdb-invalidate-frames)) | |
1277 | |
1278 (defun gdb-get-frame-number () | |
1279 (save-excursion | |
1280 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t)) | |
1281 (n (or (and pos (match-string-no-properties 1)) "0"))) | |
1282 n))) | |
1283 | |
1284 (defun gdb-frames-select () | |
1285 "Make the frame on the current line become the current frame and display the | |
1286 source in the source buffer." | |
1287 (interactive) | |
1288 (gdb-enqueue-input | |
1289 (list (concat "server frame " (gdb-get-frame-number) "\n") 'ignore)) | |
1290 (gud-display-frame)) | |
1291 | |
1292 (defun gdb-frames-mouse-select (event) | |
1293 "Make the selected frame become the current frame and display the source in | |
1294 the source buffer." | |
1295 (interactive "e") | |
1296 (mouse-set-point event) | |
1297 (gdb-frames-select)) | |
1298 | |
1299 ;; | |
1300 ;; Threads buffer. This displays a selectable thread list. | |
1301 ;; | |
1302 (gdb-set-buffer-rules 'gdb-threads-buffer | |
1303 'gdb-threads-buffer-name | |
1304 'gdb-threads-mode) | |
1305 | |
1306 (def-gdb-auto-updated-buffer gdb-threads-buffer | |
1307 gdb-invalidate-threads | |
1308 "server info threads\n" | |
1309 gdb-info-threads-handler | |
1310 gdb-info-threads-custom) | |
1311 | |
1312 (defun gdb-info-threads-custom () | |
1313 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer) | |
1314 (let ((buffer-read-only nil)) | |
1315 (goto-char (point-min)) | |
1316 (while (< (point) (point-max)) | |
1317 (add-text-properties (point-at-bol) (point-at-eol) | |
1318 '(mouse-face highlight | |
1319 help-echo "mouse-2, RET: select thread")) | |
1320 (forward-line 1))))) | |
1321 | |
1322 (defun gdb-threads-buffer-name () | |
1323 (with-current-buffer gud-comint-buffer | |
1324 (concat "*threads of " (gdb-get-target-string) "*"))) | |
1325 | |
1326 (defun gdb-display-threads-buffer () | |
1327 (interactive) | |
1328 (gdb-display-buffer | |
1329 (gdb-get-create-buffer 'gdb-threads-buffer))) | |
1330 | |
1331 (defun gdb-frame-threads-buffer () | |
1332 (interactive) | |
1333 (switch-to-buffer-other-frame | |
1334 (gdb-get-create-buffer 'gdb-threads-buffer))) | |
1335 | |
1336 (defvar gdb-threads-mode-map | |
1337 (let ((map (make-sparse-keymap))) | |
1338 (suppress-keymap map) | |
1339 (define-key map "\r" 'gdb-threads-select) | |
1340 (define-key map [mouse-2] 'gdb-threads-mouse-select) | |
1341 map)) | |
1342 | |
1343 (defun gdb-threads-mode () | |
1344 "Major mode for gdb frames. | |
1345 | |
1346 \\{gdb-frames-mode-map}" | |
1347 (setq major-mode 'gdb-threads-mode) | |
1348 (setq mode-name "Threads") | |
1349 (setq buffer-read-only t) | |
1350 (use-local-map gdb-threads-mode-map) | |
1351 (gdb-invalidate-threads)) | |
1352 | |
1353 (defun gdb-get-thread-number () | |
1354 (save-excursion | |
1355 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t) | |
1356 (match-string-no-properties 1))) | |
1357 | |
1358 (defun gdb-threads-select () | |
1359 "Make the thread on the current line become the current thread and display the | |
1360 source in the source buffer." | |
1361 (interactive) | |
1362 (gdb-enqueue-input | |
1363 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore)) | |
1364 (gud-display-frame)) | |
1365 | |
1366 (defun gdb-threads-mouse-select (event) | |
1367 "Make the selected frame become the current frame and display the source in | |
1368 the source buffer." | |
1369 (interactive "e") | |
1370 (mouse-set-point event) | |
1371 (gdb-threads-select)) | |
1372 | |
1373 ;; | |
1374 ;; Registers buffer. | |
1375 ;; | |
1376 (gdb-set-buffer-rules 'gdb-registers-buffer | |
1377 'gdb-registers-buffer-name | |
1378 'gdb-registers-mode) | |
1379 | |
1380 (def-gdb-auto-updated-buffer gdb-registers-buffer | |
1381 gdb-invalidate-registers | |
1382 "server info registers\n" | |
1383 gdb-info-registers-handler | |
1384 gdb-info-registers-custom) | |
1385 | |
1386 (defun gdb-info-registers-custom ()) | |
1387 | |
1388 (defvar gdb-registers-mode-map | |
1389 (let ((map (make-sparse-keymap))) | |
1390 (suppress-keymap map) | |
1391 map)) | |
1392 | |
1393 (defun gdb-registers-mode () | |
1394 "Major mode for gdb registers. | |
1395 | |
1396 \\{gdb-registers-mode-map}" | |
1397 (setq major-mode 'gdb-registers-mode) | |
1398 (setq mode-name "Registers") | |
1399 (setq buffer-read-only t) | |
1400 (use-local-map gdb-registers-mode-map) | |
1401 (gdb-invalidate-registers)) | |
1402 | |
1403 (defun gdb-registers-buffer-name () | |
1404 (with-current-buffer gud-comint-buffer | |
1405 (concat "*registers of " (gdb-get-target-string) "*"))) | |
1406 | |
1407 (defun gdb-display-registers-buffer () | |
1408 (interactive) | |
1409 (gdb-display-buffer | |
1410 (gdb-get-create-buffer 'gdb-registers-buffer))) | |
1411 | |
1412 (defun gdb-frame-registers-buffer () | |
1413 (interactive) | |
1414 (switch-to-buffer-other-frame | |
1415 (gdb-get-create-buffer 'gdb-registers-buffer))) | |
1416 | |
1417 ;; | |
1418 ;; Locals buffer. | |
1419 ;; | |
1420 (gdb-set-buffer-rules 'gdb-locals-buffer | |
1421 'gdb-locals-buffer-name | |
1422 'gdb-locals-mode) | |
1423 | |
1424 (def-gdb-auto-updated-buffer gdb-locals-buffer | |
1425 gdb-invalidate-locals | |
1426 "server info locals\n" | |
1427 gdb-info-locals-handler | |
1428 gdb-info-locals-custom) | |
1429 | |
1430 ;; Abbreviate for arrays and structures. | |
1431 ;; These can be expanded using gud-display. | |
1432 (defun gdb-info-locals-handler nil | |
1433 (gdb-set-pending-triggers (delq 'gdb-invalidate-locals | |
1434 (gdb-get-pending-triggers))) | |
1435 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer))) | |
1436 (with-current-buffer buf | |
1437 (goto-char (point-min)) | |
1438 (while (re-search-forward "^ .*\n" nil t) | |
1439 (replace-match "" nil nil)) | |
1440 (goto-char (point-min)) | |
1441 (while (re-search-forward "{[-0-9, {}\]*\n" nil t) | |
1442 (replace-match "(array);\n" nil nil)) | |
1443 (goto-char (point-min)) | |
1444 (while (re-search-forward "{.*=.*\n" nil t) | |
1445 (replace-match "(structure);\n" nil nil)))) | |
1446 (let ((buf (gdb-get-buffer 'gdb-locals-buffer))) | |
1447 (and buf (with-current-buffer buf | |
1448 (let ((p (point)) | |
1449 (buffer-read-only nil)) | |
1450 (delete-region (point-min) (point-max)) | |
1451 (insert-buffer-substring (gdb-get-create-buffer | |
1452 'gdb-partial-output-buffer)) | |
1453 (goto-char p))))) | |
1454 (run-hooks 'gdb-info-locals-hook)) | |
1455 | |
1456 (defun gdb-info-locals-custom () | |
1457 nil) | |
1458 | |
1459 (defvar gdb-locals-mode-map | |
1460 (let ((map (make-sparse-keymap))) | |
1461 (suppress-keymap map) | |
1462 map)) | |
1463 | |
1464 (defun gdb-locals-mode () | |
1465 "Major mode for gdb locals. | |
1466 | |
1467 \\{gdb-locals-mode-map}" | |
1468 (setq major-mode 'gdb-locals-mode) | |
1469 (setq mode-name "Locals") | |
1470 (setq buffer-read-only t) | |
1471 (use-local-map gdb-locals-mode-map) | |
1472 (gdb-invalidate-locals)) | |
1473 | |
1474 (defun gdb-locals-buffer-name () | |
1475 (with-current-buffer gud-comint-buffer | |
1476 (concat "*locals of " (gdb-get-target-string) "*"))) | |
1477 | |
1478 (defun gdb-display-locals-buffer () | |
1479 (interactive) | |
1480 (gdb-display-buffer | |
1481 (gdb-get-create-buffer 'gdb-locals-buffer))) | |
1482 | |
1483 (defun gdb-frame-locals-buffer () | |
1484 (interactive) | |
1485 (switch-to-buffer-other-frame | |
1486 (gdb-get-create-buffer 'gdb-locals-buffer))) | |
1487 | |
1488 | |
1489 ;;;; Window management | |
1490 | |
1491 ;;; The way we abuse the dedicated-p flag is pretty gross, but seems | |
1492 ;;; to do the right thing. Seeing as there is no way for Lisp code to | |
1493 ;;; get at the use_time field of a window, I'm not sure there exists a | |
1494 ;;; more elegant solution without writing C code. | |
1495 | |
1496 (defun gdb-display-buffer (buf &optional size) | |
1497 (let ((must-split nil) | |
1498 (answer nil)) | |
1499 (unwind-protect | |
1500 (progn | |
1501 (walk-windows | |
1502 #'(lambda (win) | |
1503 (if (or (eq gud-comint-buffer (window-buffer win)) | |
1504 (eq gdb-source-window win)) | |
1505 (set-window-dedicated-p win t)))) | |
1506 (setq answer (get-buffer-window buf)) | |
1507 (if (not answer) | |
1508 (let ((window (get-lru-window))) | |
1509 (if window | |
1510 (progn | |
1511 (set-window-buffer window buf) | |
1512 (setq answer window)) | |
1513 (setq must-split t))))) | |
1514 (walk-windows | |
1515 #'(lambda (win) | |
1516 (if (or (eq gud-comint-buffer (window-buffer win)) | |
1517 (eq gdb-source-window win)) | |
1518 (set-window-dedicated-p win nil))))) | |
1519 (if must-split | |
1520 (let* ((largest (get-largest-window)) | |
1521 (cur-size (window-height largest)) | |
1522 (new-size (and size (< size cur-size) (- cur-size size)))) | |
1523 (setq answer (split-window largest new-size)) | |
1524 (set-window-buffer answer buf))) | |
1525 answer)) | |
1526 | |
1527 (defun gdb-display-source-buffer (buffer) | |
1528 (if (eq gdb-selected-view 'source) | |
1529 (progn | |
1530 (if (window-live-p gdb-source-window) | |
1531 (set-window-buffer gdb-source-window buffer) | |
1532 (gdb-display-buffer buffer) | |
1533 (setq gdb-source-window (get-buffer-window buffer))) | |
1534 gdb-source-window) | |
1535 (if (window-live-p gdb-source-window) | |
1536 (set-window-buffer gdb-source-window | |
1537 (gdb-get-buffer 'gdb-assembler-buffer)) | |
1538 (let ((buf (gdb-get-buffer 'gdb-assembler-buffer))) | |
1539 (gdb-display-buffer buf) | |
1540 (setq gdb-source-window (get-buffer-window buf)))) | |
1541 nil)) | |
1542 | |
1543 | |
1544 ;;; Shared keymap initialization: | |
1545 | |
1546 (let ((menu (make-sparse-keymap "GDB-Frames"))) | |
1547 (define-key gud-menu-map [frames] | |
1548 `(menu-item "GDB-Frames" ,menu :visible (eq gud-minor-mode 'gdba))) | |
1549 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer)) | |
1550 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer)) | |
1551 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer)) | |
1552 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)) | |
1553 (define-key menu [breakpoints] '("Breakpoints" . gdb-frame-breakpoints-buffer)) | |
1554 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer)) | |
1555 ; (define-key menu [assembler] '("Machine" . gdb-frame-assembler-buffer)) | |
1556 ) | |
1557 | |
1558 (let ((menu (make-sparse-keymap "GDB-Windows"))) | |
1559 (define-key gud-menu-map [displays] | |
1560 `(menu-item "GDB-Windows" ,menu :visible (eq gud-minor-mode 'gdba))) | |
1561 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer)) | |
1562 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer)) | |
1563 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer)) | |
1564 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)) | |
1565 (define-key menu [breakpoints] '("Breakpoints" . gdb-display-breakpoints-buffer)) | |
1566 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer)) | |
1567 ; (define-key menu [assembler] '("Machine" . gdb-display-assembler-buffer)) | |
1568 ) | |
1569 | |
1570 (let ((menu (make-sparse-keymap "View"))) | |
1571 (define-key gud-menu-map [view] | |
1572 `(menu-item "View" ,menu :visible (eq gud-minor-mode 'gdba))) | |
1573 ; (define-key menu [both] '(menu-item "Both" gdb-view-both | |
1574 ; :help "Display both source and assembler" | |
1575 ; :button (:radio . (eq gdb-selected-view 'both)))) | |
1576 (define-key menu [assembler] '(menu-item "Machine" gdb-view-assembler | |
1577 :help "Display assembler only" | |
1578 :button (:radio . (eq gdb-selected-view 'assembler)))) | |
1579 (define-key menu [source] '(menu-item "Source" gdb-view-source-function | |
1580 :help "Display source only" | |
1581 :button (:radio . (eq gdb-selected-view 'source))))) | |
1582 | |
1583 (let ((menu (make-sparse-keymap "GDB-UI"))) | |
1584 (define-key gud-menu-map [ui] | |
1585 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba))) | |
1586 (define-key menu [gdb-restore-windows] | |
1587 '("Restore window layout" . gdb-restore-windows)) | |
1588 (define-key menu [gdb-many-windows] | |
1589 (menu-bar-make-toggle gdb-many-windows gdb-many-windows | |
1590 "Display other windows" "Many Windows %s" | |
1591 "Display locals, stack and breakpoint information"))) | |
1592 | |
1593 (defun gdb-frame-gdb-buffer () | |
1594 (interactive) | |
1595 (switch-to-buffer-other-frame | |
1596 (gdb-get-create-buffer 'gdba))) | |
1597 | |
1598 (defun gdb-display-gdb-buffer () | |
1599 (interactive) | |
1600 (gdb-display-buffer | |
1601 (gdb-get-create-buffer 'gdba))) | |
1602 | |
1603 (defvar gdb-main-file nil "Source file from which program execution begins.") | |
1604 | |
1605 (defun gdb-view-source-function () | |
1606 (interactive) | |
1607 (if gdb-view-source | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1608 (if (window-live-p gdb-source-window) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1609 (set-window-buffer gdb-source-window |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1610 (if gud-last-last-frame |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1611 (gud-find-file (car gud-last-last-frame)) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1612 (gud-find-file gdb-main-file))) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1613 (setq gdb-source-window |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1614 (display-buffer |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1615 (if gud-last-last-frame |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1616 (gud-find-file (car gud-last-last-frame)) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1617 (gud-find-file gdb-main-file)))))) |
54538 | 1618 (setq gdb-selected-view 'source)) |
1619 | |
1620 (defun gdb-view-assembler() | |
1621 (interactive) | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1622 (if (window-live-p gdb-source-window) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1623 (set-window-buffer gdb-source-window |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1624 (gdb-get-create-buffer 'gdb-assembler-buffer)) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1625 (setq gdb-source-window |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1626 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer)))) |
54538 | 1627 (setq gdb-selected-view 'assembler)) |
1628 | |
1629 ;(defun gdb-view-both() | |
1630 ;(interactive) | |
1631 ;(setq gdb-selected-view 'both)) | |
1632 | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1633 (defcustom gdb-show-main nil |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1634 "Nil means don't display source file containing the main routine." |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1635 :type 'boolean |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1636 :group 'gud) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1637 |
54538 | 1638 (defun gdb-setup-windows () |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1639 "Layout the window pattern for gdb-many-windows." |
54538 | 1640 (gdb-display-locals-buffer) |
1641 (gdb-display-stack-buffer) | |
1642 (delete-other-windows) | |
1643 (gdb-display-breakpoints-buffer) | |
1644 (delete-other-windows) | |
1645 (switch-to-buffer gud-comint-buffer) | |
1646 (split-window nil ( / ( * (window-height) 3) 4)) | |
1647 (split-window nil ( / (window-height) 3)) | |
1648 (split-window-horizontally) | |
1649 (other-window 1) | |
1650 (switch-to-buffer (gdb-locals-buffer-name)) | |
1651 (other-window 1) | |
1652 (switch-to-buffer | |
1653 (if (and gdb-view-source | |
1654 (eq gdb-selected-view 'source)) | |
1655 (if gud-last-last-frame | |
1656 (gud-find-file (car gud-last-last-frame)) | |
1657 (gud-find-file gdb-main-file)) | |
1658 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
1659 (setq gdb-source-window (get-buffer-window (current-buffer))) | |
1660 (split-window-horizontally) | |
1661 (other-window 1) | |
1662 (switch-to-buffer (gdb-inferior-io-name)) | |
1663 (other-window 1) | |
1664 (switch-to-buffer (gdb-stack-buffer-name)) | |
1665 (split-window-horizontally) | |
1666 (other-window 1) | |
1667 (switch-to-buffer (gdb-breakpoints-buffer-name)) | |
1668 (other-window 1)) | |
1669 | |
1670 (defcustom gdb-many-windows nil | |
1671 "Nil means that gdb starts with just two windows : the GUD and | |
1672 the source buffer." | |
1673 :type 'boolean | |
1674 :group 'gud) | |
1675 | |
1676 (defun gdb-many-windows (arg) | |
1677 "Toggle the number of windows in the basic arrangement." | |
1678 (interactive "P") | |
1679 (setq gdb-many-windows | |
1680 (if (null arg) | |
1681 (not gdb-many-windows) | |
1682 (> (prefix-numeric-value arg) 0))) | |
1683 (gdb-restore-windows)) | |
1684 | |
1685 (defun gdb-restore-windows () | |
1686 "Restore the basic arrangement of windows used by gdba. | |
1687 This arrangement depends on the value of `gdb-many-windows'." | |
1688 (interactive) | |
1689 (if gdb-many-windows | |
1690 (progn | |
1691 (switch-to-buffer gud-comint-buffer) | |
1692 (delete-other-windows) | |
1693 (gdb-setup-windows)) | |
1694 (switch-to-buffer gud-comint-buffer) | |
1695 (delete-other-windows) | |
1696 (split-window) | |
1697 (other-window 1) | |
1698 (switch-to-buffer | |
1699 (if (and gdb-view-source | |
1700 (eq gdb-selected-view 'source)) | |
1701 (if gud-last-last-frame | |
1702 (gud-find-file (car gud-last-last-frame)) | |
1703 (gud-find-file gdb-main-file)) | |
1704 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
1705 (setq gdb-source-window (get-buffer-window (current-buffer))) | |
1706 (other-window 1))) | |
1707 | |
1708 (defun gdb-reset () | |
1709 "Exit a debugging session cleanly by killing the gdb buffers and resetting | |
1710 the source buffers." | |
1711 (dolist (buffer (buffer-list)) | |
1712 (if (not (eq buffer gud-comint-buffer)) | |
1713 (with-current-buffer buffer | |
1714 (if (memq gud-minor-mode '(gdba pdb)) | |
1715 (if (string-match "^\*.+*$" (buffer-name)) | |
1716 (kill-buffer nil) | |
1717 (gdb-remove-breakpoint-icons (point-min) (point-max) t) | |
1718 (setq gud-minor-mode nil) | |
1719 (kill-local-variable 'tool-bar-map) | |
1720 (setq gud-running nil)))))) | |
1721 (when (markerp gdb-overlay-arrow-position) | |
1722 (move-marker gdb-overlay-arrow-position nil) | |
1723 (setq gdb-overlay-arrow-position nil)) | |
1724 (setq overlay-arrow-variable-list | |
1725 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))) | |
1726 | |
1727 (defun gdb-source-info () | |
1728 "Find the source file where the program starts and displays it with related | |
1729 buffers." | |
1730 (goto-char (point-min)) | |
1731 (if (search-forward "directory is " nil t) | |
1732 (if (looking-at "\\S-*:\\(\\S-*\\)") | |
1733 (setq gdb-cdir (match-string 1)) | |
1734 (looking-at "\\S-*") | |
1735 (setq gdb-cdir (match-string 0)))) | |
1736 (if (search-forward "Located in " nil t) | |
1737 (if (looking-at "\\S-*") | |
1738 (setq gdb-main-file (match-string 0))) | |
1739 (setq gdb-view-source nil)) | |
1740 (if gdb-many-windows | |
1741 (gdb-setup-windows) | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1742 (gdb-get-create-buffer 'gdb-breakpoints-buffer) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1743 (when gdb-show-main |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1744 (switch-to-buffer gud-comint-buffer) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1745 (delete-other-windows) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1746 (split-window) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1747 (other-window 1) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1748 (switch-to-buffer |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1749 (if gdb-view-source |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1750 (gud-find-file gdb-main-file) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1751 (gdb-get-create-buffer 'gdb-assembler-buffer))) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1752 (setq gdb-source-window (get-buffer-window (current-buffer))) |
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1753 (other-window 1)))) |
54538 | 1754 |
1755 ;;from put-image | |
1756 (defun gdb-put-string (putstring pos &optional dprop) | |
1757 "Put string PUTSTRING in front of POS in the current buffer. | |
1758 PUTSTRING is displayed by putting an overlay into the current buffer with a | |
1759 `before-string' STRING that has a `display' property whose value is | |
1760 PUTSTRING." | |
1761 (let ((gdb-string "x") | |
1762 (buffer (current-buffer))) | |
1763 (let ((overlay (make-overlay pos pos buffer)) | |
1764 (prop (or dprop | |
1765 (list (list 'margin 'left-margin) putstring)))) | |
1766 (put-text-property 0 (length gdb-string) 'display prop gdb-string) | |
1767 (overlay-put overlay 'put-break t) | |
1768 (overlay-put overlay 'before-string gdb-string)))) | |
1769 | |
1770 ;;from remove-images | |
1771 (defun gdb-remove-strings (start end &optional buffer) | |
1772 "Remove strings between START and END in BUFFER. | |
1773 Remove only strings that were put in BUFFER with calls to `gdb-put-string'. | |
1774 BUFFER nil or omitted means use the current buffer." | |
1775 (unless buffer | |
1776 (setq buffer (current-buffer))) | |
1777 (let ((overlays (overlays-in start end))) | |
1778 (while overlays | |
1779 (let ((overlay (car overlays))) | |
1780 (when (overlay-get overlay 'put-break) | |
1781 (delete-overlay overlay))) | |
1782 (setq overlays (cdr overlays))))) | |
1783 | |
1784 (defun gdb-put-breakpoint-icon (enabled) | |
1785 (let ((start (progn (beginning-of-line) (- (point) 1))) | |
1786 (end (progn (end-of-line) (+ (point) 1)))) | |
1787 (gdb-remove-breakpoint-icons start end) | |
1788 (if (display-images-p) | |
1789 (if (>= (car (window-fringes)) 8) | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1790 (gdb-put-string |
54538 | 1791 nil (1+ start) |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1792 `(left-fringe |
54538 | 1793 ,(or breakpoint-bitmap |
1794 (setq breakpoint-bitmap | |
1795 (define-fringe-bitmap | |
1796 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))) | |
1797 ,(if enabled | |
1798 'breakpoint-enabled-bitmap-face | |
1799 'breakpoint-disabled-bitmap-face))) | |
1800 (when (< left-margin-width 2) | |
1801 (save-current-buffer | |
1802 (setq left-margin-width 2) | |
1803 (if (get-buffer-window (current-buffer)) | |
1804 (set-window-margins (get-buffer-window | |
1805 (current-buffer)) | |
1806 left-margin-width | |
1807 right-margin-width)))) | |
1808 (put-image | |
1809 (if enabled | |
1810 (or breakpoint-enabled-icon | |
1811 (setq breakpoint-enabled-icon | |
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1812 (find-image `((:type xpm :data |
54538 | 1813 ,breakpoint-xpm-data |
1814 :ascent 100 :pointer hand) | |
1815 (:type pbm :data | |
1816 ,breakpoint-enabled-pbm-data | |
1817 :ascent 100 :pointer hand))))) | |
1818 (or breakpoint-disabled-icon | |
1819 (setq breakpoint-disabled-icon | |
1820 (find-image `((:type xpm :data | |
1821 ,breakpoint-xpm-data | |
1822 :conversion disabled | |
1823 :ascent 100) | |
1824 (:type pbm :data | |
1825 ,breakpoint-disabled-pbm-data | |
1826 :ascent 100)))))) | |
1827 (+ start 1) nil 'left-margin)) | |
1828 (when (< left-margin-width 2) | |
1829 (save-current-buffer | |
1830 (setq left-margin-width 2) | |
1831 (if (get-buffer-window (current-buffer)) | |
1832 (set-window-margins (get-buffer-window | |
1833 (current-buffer)) | |
1834 left-margin-width | |
1835 right-margin-width)))) | |
1836 (gdb-put-string (if enabled "B" "b") (1+ start))))) | |
1837 | |
1838 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin) | |
1839 (gdb-remove-strings start end) | |
1840 (if (display-images-p) | |
1841 (remove-images start end)) | |
1842 (when remove-margin | |
1843 (setq left-margin-width 0) | |
1844 (if (get-buffer-window (current-buffer)) | |
1845 (set-window-margins (get-buffer-window | |
1846 (current-buffer)) | |
1847 left-margin-width | |
1848 right-margin-width)))) | |
1849 | |
1850 | |
1851 ;; | |
1852 ;; Assembler buffer. | |
1853 ;; | |
1854 (gdb-set-buffer-rules 'gdb-assembler-buffer | |
1855 'gdb-assembler-buffer-name | |
1856 'gdb-assembler-mode) | |
1857 | |
1858 (def-gdb-auto-updated-buffer gdb-assembler-buffer | |
1859 gdb-invalidate-assembler | |
1860 (concat "server disassemble " gdb-current-address "\n") | |
1861 gdb-assembler-handler | |
1862 gdb-assembler-custom) | |
1863 | |
1864 (defun gdb-assembler-custom () | |
1865 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer)) | |
1866 (pos 1) (address) (flag)) | |
1867 (with-current-buffer buffer | |
1868 (if (not (equal gdb-current-address "main")) | |
1869 (progn | |
1870 (goto-char (point-min)) | |
1871 (if (re-search-forward gdb-current-address nil t) | |
1872 (progn | |
1873 (setq pos (point)) | |
1874 (beginning-of-line) | |
1875 (or gdb-overlay-arrow-position | |
1876 (setq gdb-overlay-arrow-position (make-marker))) | |
1877 (set-marker gdb-overlay-arrow-position | |
1878 (point) (current-buffer)))))) | |
1879 ;; remove all breakpoint-icons in assembler buffer before updating. | |
1880 (gdb-remove-breakpoint-icons (point-min) (point-max))) | |
1881 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer) | |
1882 (goto-char (point-min)) | |
1883 (while (< (point) (- (point-max) 1)) | |
1884 (forward-line 1) | |
1885 (if (looking-at "[^\t].*breakpoint") | |
1886 (progn | |
1887 (looking-at | |
1888 "[0-9]*\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)\\s-*0x\\(\\S-*\\)") | |
1889 (setq flag (char-after (match-beginning 1))) | |
1890 (setq address (match-string 2)) | |
1891 ;; remove leading 0s from output of info break. | |
1892 (if (string-match "^0+\\(.*\\)" address) | |
1893 (setq address (match-string 1 address))) | |
1894 (with-current-buffer buffer | |
1895 (goto-char (point-min)) | |
1896 (if (re-search-forward address nil t) | |
1897 (gdb-put-breakpoint-icon (eq flag ?y)))))))) | |
1898 (if (not (equal gdb-current-address "main")) | |
1899 (set-window-point (get-buffer-window buffer) pos)))) | |
1900 | |
1901 (defvar gdb-assembler-mode-map | |
1902 (let ((map (make-sparse-keymap))) | |
1903 (suppress-keymap map) | |
1904 map)) | |
1905 | |
1906 (defun gdb-assembler-mode () | |
1907 "Major mode for viewing code assembler. | |
1908 | |
1909 \\{gdb-assembler-mode-map}" | |
1910 (setq major-mode 'gdb-assembler-mode) | |
1911 (setq mode-name "Machine") | |
1912 (setq gdb-overlay-arrow-position nil) | |
1913 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position) | |
1914 (put 'gdb-overlay-arrow-position 'overlay-arrow-string "=>") | |
1915 (setq fringes-outside-margins t) | |
1916 (setq buffer-read-only t) | |
1917 (use-local-map gdb-assembler-mode-map) | |
1918 (gdb-invalidate-assembler)) | |
1919 | |
1920 (defun gdb-assembler-buffer-name () | |
1921 (with-current-buffer gud-comint-buffer | |
1922 (concat "*Machine Code " (gdb-get-target-string) "*"))) | |
1923 | |
1924 (defun gdb-display-assembler-buffer () | |
1925 (interactive) | |
1926 (gdb-display-buffer | |
1927 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
1928 | |
1929 (defun gdb-frame-assembler-buffer () | |
1930 (interactive) | |
1931 (switch-to-buffer-other-frame | |
1932 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
1933 | |
1934 ;; modified because if gdb-current-address has changed value a new command | |
1935 ;; must be enqueued to update the buffer with the new output | |
1936 (defun gdb-invalidate-assembler (&optional ignored) | |
1937 (if (gdb-get-buffer 'gdb-assembler-buffer) | |
1938 (progn | |
1939 (unless (string-equal gdb-current-frame gdb-previous-frame) | |
1940 (if (or (not (member 'gdb-invalidate-assembler | |
1941 (gdb-get-pending-triggers))) | |
1942 (not (string-equal gdb-current-address | |
1943 gdb-previous-address))) | |
1944 (progn | |
1945 ;; take previous disassemble command off the queue | |
1946 (with-current-buffer gud-comint-buffer | |
1947 (let ((queue (gdb-get-input-queue)) (item)) | |
1948 (dolist (item queue) | |
1949 (if (equal (cdr item) '(gdb-assembler-handler)) | |
1950 (gdb-set-input-queue | |
1951 (delete item (gdb-get-input-queue))))))) | |
1952 (gdb-enqueue-input | |
1953 (list (concat "server disassemble " gdb-current-address "\n") | |
1954 'gdb-assembler-handler)) | |
1955 (gdb-set-pending-triggers | |
1956 (cons 'gdb-invalidate-assembler | |
1957 (gdb-get-pending-triggers))) | |
1958 (setq gdb-previous-address gdb-current-address) | |
1959 (setq gdb-previous-frame gdb-current-frame))))))) | |
1960 | |
1961 (defun gdb-get-current-frame () | |
1962 (if (not (member 'gdb-get-current-frame (gdb-get-pending-triggers))) | |
1963 (progn | |
1964 (gdb-enqueue-input | |
1965 (list (concat "server info frame\n") 'gdb-frame-handler)) | |
1966 (gdb-set-pending-triggers | |
1967 (cons 'gdb-get-current-frame | |
1968 (gdb-get-pending-triggers)))))) | |
1969 | |
1970 (defun gdb-frame-handler () | |
1971 (gdb-set-pending-triggers | |
1972 (delq 'gdb-get-current-frame (gdb-get-pending-triggers))) | |
1973 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
1974 (goto-char (point-min)) | |
1975 (forward-line) | |
1976 (if (looking-at ".*=\\s-+0x\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*\\)") | |
1977 (progn | |
1978 (setq gdb-current-frame (match-string 2)) | |
1979 (let ((address (match-string 1))) | |
1980 ;; remove leading 0s from output of info frame command. | |
1981 (if (string-match "^0+\\(.*\\)" address) | |
1982 (setq gdb-current-address | |
1983 (concat "0x" (match-string 1 address))) | |
1984 (setq gdb-current-address (concat "0x" address)))) | |
1985 (if (or (if (not (re-search-forward "(\\S-*:[0-9]*);" nil t)) | |
1986 (progn (setq gdb-view-source nil) t)) | |
1987 (eq gdb-selected-view 'assembler)) | |
1988 (progn | |
1989 (set-window-buffer | |
1990 gdb-source-window | |
1991 (gdb-get-create-buffer 'gdb-assembler-buffer)) | |
1992 ;;update with new frame for machine code if necessary | |
1993 (gdb-invalidate-assembler)))))) | |
1994 (if (re-search-forward " source language \\(\\S-*\\)\." nil t) | |
1995 (setq gdb-current-language (match-string 1)))) | |
1996 | |
1997 (provide 'gdb-ui) | |
1998 | |
1999 ;;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352 | |
2000 ;;; gdb-ui.el ends here |