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