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