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