]> code.delx.au - gnu-emacs/blob - lisp/progmodes/gdb-ui.el
(gdb-reset): Set buffer local value of
[gnu-emacs] / lisp / progmodes / gdb-ui.el
1 ;;; gdb-ui.el --- User Interface for running GDB
2
3 ;; Author: Nick Roberts <nickrob@gnu.org>
4 ;; Maintainer: FSF
5 ;; Keywords: unix, tools
6
7 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006
8 ;; Free Software Foundation, Inc.
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; This mode acts as a graphical user interface to GDB. You can interact with
30 ;; GDB through the GUD buffer in the usual way, but there are also further
31 ;; buffers which control the execution and describe the state of your program.
32 ;; It separates the input/output of your program from that of GDB, if
33 ;; required, and watches expressions in the speedbar. It also uses features of
34 ;; Emacs 21 such as the fringe/display margin for breakpoints, and the toolbar
35 ;; (see the GDB Graphical Interface section in the Emacs info manual).
36
37 ;; By default, M-x gdb will start the debugger. However, if you have customised
38 ;; gud-gdb-command-name, then start it with M-x gdba.
39
40 ;; This file has evolved from gdba.el that was included with GDB 5.0 and
41 ;; written by Tom Lord and Jim Kingdon. It uses GDB's annotation interface.
42 ;; You don't need to know about annotations to use this mode as a debugger,
43 ;; but if you are interested developing the mode itself, then see the
44 ;; Annotations section in the GDB info manual.
45
46 ;; GDB developers plan to make the annotation interface obsolete. A new
47 ;; interface called GDB/MI (machine interface) has been designed to replace
48 ;; it. Some GDB/MI commands are used in this file through the CLI command
49 ;; 'interpreter mi <mi-command>'. A file called gdb-mi.el is included with
50 ;; GDB (6.2 onwards) that uses GDB/MI as the primary interface to GDB. It is
51 ;; still under development and is part of a process to migrate Emacs from
52 ;; annotations to GDB/MI.
53
54 ;; This mode SHOULD WORK WITH GDB 5.0 onwards but you will NEED GDB 6.0
55 ;; onwards to use watch expressions. It works best with GDB 6.4 where
56 ;; watch expressions will update more quickly.
57
58 ;;; Windows Platforms:
59
60 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
61 ;; explicitly in your program if you want timely display of I/O in Emacs.
62 ;; Alternatively you can make the output stream unbuffered, for example, by
63 ;; using a macro:
64
65 ;; #ifdef UNBUFFERED
66 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
67 ;; #endif
68
69 ;; and compiling with -DUNBUFFERED while debugging.
70
71 ;;; Known Bugs:
72
73 ;; 1) Strings that are watched don't update in the speedbar when their
74 ;; contents change unless the first character changes.
75 ;; 2) Cannot handle multiple debug sessions.
76 ;; 3) Initially, the assembler buffer does not display the cursor at the
77 ;; current line if the line is not visible in the window (but when testing
78 ;; gdb-assembler-custom with a lisp debugger it does!).
79
80 ;;; Problems with watch expressions, GDB/MI:
81
82 ;; 1) They go out of scope when the inferior is re-run.
83 ;; 2) -stack-list-locals has a type field but also prints type in values field.
84 ;; 3) VARNUM increments even when variable object is not created (maybe trivial).
85
86 ;;; TODO:
87
88 ;; 1) Use MI command -data-read-memory for memory window.
89 ;; 2) Use tree-widget.el instead of the speedbar for watch-expressions?
90 ;; 3) Mark breakpoint locations on scroll-bar of source buffer?
91 ;; 4) With gud-print and gud-pstar, print the variable name in the GUD
92 ;; buffer instead of the value's history number.
93
94 ;;; Code:
95
96 (require 'gud)
97
98 (defvar tool-bar-map)
99 (defvar speedbar-initial-expansion-list-name)
100
101 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
102 (defvar gdb-previous-frame-address nil)
103 (defvar gdb-memory-address "main")
104 (defvar gdb-previous-frame nil)
105 (defvar gdb-selected-frame nil)
106 (defvar gdb-frame-number nil)
107 (defvar gdb-current-language nil)
108 (defvar gdb-var-list nil
109 "List of variables in watch window.
110 Each element has the form (VARNUM EXPRESSION NUMCHILD TYPE VALUE STATUS) where
111 STATUS is nil (unchanged), `changed' or `out-of-scope'.")
112 (defvar gdb-force-update t
113 "Non-nil means that view of watch expressions will be updated in the speedbar.")
114 (defvar gdb-main-file nil "Source file from which program execution begins.")
115 (defvar gdb-overlay-arrow-position nil)
116 (defvar gdb-server-prefix nil)
117 (defvar gdb-flush-pending-output nil)
118 (defvar gdb-location-alist nil
119 "Alist of breakpoint numbers and full filenames.")
120 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
121 and #define directives otherwise.")
122 (defvar gdb-error "Non-nil when GDB is reporting an error.")
123 (defvar gdb-macro-info nil
124 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
125 (defvar gdb-buffer-fringe-width nil)
126 (defvar gdb-signalled nil)
127 (defvar gdb-source-window nil)
128 (defvar gdb-inferior-status nil)
129
130 (defvar gdb-buffer-type nil
131 "One of the symbols bound in `gdb-buffer-rules'.")
132 (make-variable-buffer-local 'gdb-buffer-type)
133
134 (defvar gdb-input-queue ()
135 "A list of gdb command objects.")
136
137 (defvar gdb-prompting nil
138 "True when gdb is idle with no pending input.")
139
140 (defvar gdb-output-sink 'user
141 "The disposition of the output of the current gdb command.
142 Possible values are these symbols:
143
144 `user' -- gdb output should be copied to the GUD buffer
145 for the user to see.
146
147 `inferior' -- gdb output should be copied to the inferior-io buffer.
148
149 `pre-emacs' -- output should be ignored util the post-prompt
150 annotation is received. Then the output-sink
151 becomes:...
152 `emacs' -- output should be collected in the partial-output-buffer
153 for subsequent processing by a command. This is the
154 disposition of output generated by commands that
155 gdb mode sends to gdb on its own behalf.
156 `post-emacs' -- ignore output until the prompt annotation is
157 received, then go to USER disposition.
158
159 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
160 \(`user' and `emacs').")
161
162 (defvar gdb-current-item nil
163 "The most recent command item sent to gdb.")
164
165 (defvar gdb-pending-triggers '()
166 "A list of trigger functions that have run later than their output
167 handlers.")
168
169 (defvar gdb-first-post-prompt nil)
170 (defvar gdb-version nil)
171 (defvar gdb-locals-font-lock-keywords nil)
172 (defvar gdb-source-file-list nil
173 "List of source files for the current executable")
174 (defconst gdb-error-regexp "\\^error,msg=\"\\(.+\\)\"")
175
176 (defvar gdb-locals-font-lock-keywords-1
177 '(
178 ;; var = (struct struct_tag) value
179 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
180 (1 font-lock-variable-name-face)
181 (3 font-lock-keyword-face)
182 (4 font-lock-type-face))
183 ;; var = (type) value
184 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
185 (1 font-lock-variable-name-face)
186 (3 font-lock-type-face))
187 ;; var = val
188 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
189 (1 font-lock-variable-name-face))
190 )
191 "Font lock keywords used in `gdb-local-mode'.")
192
193 (defvar gdb-locals-font-lock-keywords-2
194 '(
195 ;; var = type value
196 ( "\\(^\\(\\sw\\|[_.]\\)+\\)\t+\\(\\(\\sw\\|[_.]\\)+\\)"
197 (1 font-lock-variable-name-face)
198 (3 font-lock-type-face))
199 )
200 "Font lock keywords used in `gdb-local-mode'.")
201
202 ;; Variables for GDB 6.4+
203 (defvar gdb-register-names nil "List of register names.")
204 (defvar gdb-changed-registers nil
205 "List of changed register numbers (strings).")
206
207 ;;;###autoload
208 (defun gdba (command-line)
209 "Run gdb on program FILE in buffer *gud-FILE*.
210 The directory containing FILE becomes the initial working directory
211 and source-file directory for your debugger.
212
213 If `gdb-many-windows' is nil (the default value) then gdb just
214 pops up the GUD buffer unless `gdb-show-main' is t. In this case
215 it starts with two windows: one displaying the GUD buffer and the
216 other with the source file with the main routine of the inferior.
217
218 If `gdb-many-windows' is t, regardless of the value of
219 `gdb-show-main', the layout below will appear unless
220 `gdb-use-separate-io-buffer' is nil when the source buffer
221 occupies the full width of the frame. Keybindings are shown in
222 some of the buffers.
223
224 Watch expressions appear in the speedbar/slowbar.
225
226 The following commands help control operation :
227
228 `gdb-many-windows' - Toggle the number of windows gdb uses.
229 `gdb-restore-windows' - To restore the window layout.
230
231 See Info node `(emacs)GDB Graphical Interface' for a more
232 detailed description of this mode.
233
234
235 +----------------------------------------------------------------------+
236 | GDB Toolbar |
237 +-----------------------------------+----------------------------------+
238 | GUD buffer (I/O of GDB) | Locals buffer |
239 | | |
240 | | |
241 | | |
242 +-----------------------------------+----------------------------------+
243 | Source buffer | I/O buffer (of debugged program) |
244 | | (comint-mode) |
245 | | |
246 | | |
247 | | |
248 | | |
249 | | |
250 | | |
251 +-----------------------------------+----------------------------------+
252 | Stack buffer | Breakpoints buffer |
253 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
254 | | RET gdb-goto-breakpoint |
255 | | D gdb-delete-breakpoint |
256 +-----------------------------------+----------------------------------+"
257 ;;
258 (interactive (list (gud-query-cmdline 'gdba)))
259 ;;
260 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
261 (gdb command-line))
262
263 (defcustom gdb-debug-ring-max 128
264 "Maximum size of `gdb-debug-ring'."
265 :group 'gud
266 :type 'integer
267 :version "22.1")
268
269 (defvar gdb-debug-ring nil
270 "List of commands, most recent first, sent to and replies received from GDB.
271 This variable is used to debug GDB-UI.")
272
273 ;;;###autoload
274 (defcustom gdb-enable-debug nil
275 "Non-nil means record the process input and output in `gdb-debug-ring'."
276 :type 'boolean
277 :group 'gud
278 :version "22.1")
279
280 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
281 "Shell command for generating a list of defined macros in a source file.
282 This list is used to display the #define directive associated
283 with an identifier as a tooltip. It works in a debug session with
284 GDB, when gud-tooltip-mode is t.
285
286 Set `gdb-cpp-define-alist-flags' for any include paths or
287 predefined macros."
288 :type 'string
289 :group 'gud
290 :version "22.1")
291
292 (defcustom gdb-cpp-define-alist-flags ""
293 "Preprocessor flags for `gdb-cpp-define-alist-program'."
294 :type 'string
295 :group 'gud
296 :version "22.1")
297
298 (defcustom gdb-show-main nil
299 "Non-nil means display source file containing the main routine at startup.
300 Also display the main routine in the disassembly buffer if present."
301 :type 'boolean
302 :group 'gud
303 :version "22.1")
304
305 (defcustom gdb-many-windows nil
306 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
307 In this case it starts with two windows: one displaying the GUD
308 buffer and the other with the source file with the main routine
309 of the inferior. Non-nil means display the layout shown for
310 `gdba'."
311 :type 'boolean
312 :group 'gud
313 :version "22.1")
314
315 (defcustom gdb-use-separate-io-buffer nil
316 "Non-nil means display output from the inferior in a separate buffer."
317 :type 'boolean
318 :group 'gud
319 :version "22.1")
320
321 (defun gdb-force-mode-line-update (status)
322 (let ((buffer gud-comint-buffer))
323 (if (and buffer (buffer-name buffer))
324 (with-current-buffer buffer
325 (setq mode-line-process
326 (format ":%s [%s]"
327 (process-status (get-buffer-process buffer)) status))
328 ;; Force mode line redisplay soon.
329 (force-mode-line-update)))))
330
331 (defun gdb-many-windows (arg)
332 "Toggle the number of windows in the basic arrangement.
333 With arg, display additional buffers iff arg is positive."
334 (interactive "P")
335 (setq gdb-many-windows
336 (if (null arg)
337 (not gdb-many-windows)
338 (> (prefix-numeric-value arg) 0)))
339 (message (format "Display of other windows %sabled"
340 (if gdb-many-windows "en" "dis")))
341 (if (and gud-comint-buffer
342 (buffer-name gud-comint-buffer))
343 (condition-case nil
344 (gdb-restore-windows)
345 (error nil))))
346
347 (defun gdb-use-separate-io-buffer (arg)
348 "Toggle separate IO for inferior.
349 With arg, use separate IO iff arg is positive."
350 (interactive "P")
351 (setq gdb-use-separate-io-buffer
352 (if (null arg)
353 (not gdb-use-separate-io-buffer)
354 (> (prefix-numeric-value arg) 0)))
355 (message (format "Separate inferior IO %sabled"
356 (if gdb-use-separate-io-buffer "en" "dis")))
357 (if (and gud-comint-buffer
358 (buffer-name gud-comint-buffer))
359 (condition-case nil
360 (if gdb-use-separate-io-buffer
361 (if gdb-many-windows (gdb-restore-windows))
362 (kill-buffer (gdb-inferior-io-name)))
363 (error nil))))
364
365 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
366
367 (defun gdb-create-define-alist ()
368 "Create an alist of #define directives for GUD tooltips."
369 (let* ((file (buffer-file-name))
370 (output
371 (with-output-to-string
372 (with-current-buffer standard-output
373 (call-process shell-file-name
374 (if (file-exists-p file) file nil)
375 (list t nil) nil "-c"
376 (concat gdb-cpp-define-alist-program " "
377 gdb-cpp-define-alist-flags)))))
378 (define-list (split-string output "\n" t))
379 (name))
380 (setq gdb-define-alist nil)
381 (dolist (define define-list)
382 (setq name (nth 1 (split-string define "[( ]")))
383 (push (cons name define) gdb-define-alist))))
384
385 (defun gdb-tooltip-print (expr)
386 (tooltip-show
387 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
388 (goto-char (point-min))
389 (let ((string
390 (if (search-forward "=" nil t)
391 (concat expr (buffer-substring (- (point) 2) (point-max)))
392 (buffer-string))))
393 ;; remove newline for gud-tooltip-echo-area
394 (substring string 0 (- (length string) 1))))
395 (or gud-tooltip-echo-area tooltip-use-echo-area)))
396
397 ;; If expr is a macro for a function don't print because of possible dangerous
398 ;; side-effects. Also printing a function within a tooltip generates an
399 ;; unexpected starting annotation (phase error).
400 (defun gdb-tooltip-print-1 (expr)
401 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
402 (goto-char (point-min))
403 (if (search-forward "expands to: " nil t)
404 (unless (looking-at "\\S-+.*(.*).*")
405 (gdb-enqueue-input
406 (list (concat gdb-server-prefix "print " expr "\n")
407 `(lambda () (gdb-tooltip-print ,expr))))))))
408
409 (defconst gdb-source-file-regexp "\\(.+?\\), \\|\\([^, \n].*$\\)")
410
411 (defun gdb-set-gud-minor-mode-existing-buffers ()
412 "Create list of source files for current GDB session."
413 (goto-char (point-min))
414 (when (search-forward "read in on demand:" nil t)
415 (while (re-search-forward gdb-source-file-regexp nil t)
416 (push (or (match-string 1) (match-string 2)) gdb-source-file-list))
417 (dolist (buffer (buffer-list))
418 (with-current-buffer buffer
419 (when (and buffer-file-name
420 (member (file-name-nondirectory buffer-file-name)
421 gdb-source-file-list))
422 (set (make-local-variable 'gud-minor-mode) 'gdba)
423 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
424 (when gud-tooltip-mode
425 (make-local-variable 'gdb-define-alist)
426 (gdb-create-define-alist)
427 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))))
428
429 (defun gdb-find-watch-expression ()
430 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
431 (varnum (car var)) expr array)
432 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varnum)
433 (let ((var1 (assoc (match-string 1 varnum) gdb-var-list)) var2 varnumlet
434 (component-list (split-string (match-string 2 varnum) "\\." t)))
435 (setq expr (nth 1 var1))
436 (setq varnumlet (car var1))
437 (dolist (component component-list)
438 (setq var2 (assoc varnumlet gdb-var-list))
439 (setq expr (concat expr
440 (if (string-match ".*\\[[0-9]+\\]$" (nth 3 var2))
441 (concat "[" component "]")
442 (concat "." component))))
443 (setq varnumlet (concat varnumlet "." component)))
444 expr)))
445
446 (defun gdb-init-1 ()
447 (set (make-local-variable 'gud-minor-mode) 'gdba)
448 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
449 ;;
450 (gud-def gud-break (if (not (string-match "Machine" mode-name))
451 (gud-call "break %f:%l" arg)
452 (save-excursion
453 (beginning-of-line)
454 (forward-char 2)
455 (gud-call "break *%a" arg)))
456 "\C-b" "Set breakpoint at current line or address.")
457 ;;
458 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
459 (gud-call "clear %f:%l" arg)
460 (save-excursion
461 (beginning-of-line)
462 (forward-char 2)
463 (gud-call "clear *%a" arg)))
464 "\C-d" "Remove breakpoint at current line or address.")
465 ;;
466 (gud-def gud-until (if (not (string-match "Machine" mode-name))
467 (gud-call "until %f:%l" arg)
468 (save-excursion
469 (beginning-of-line)
470 (forward-char 2)
471 (gud-call "until *%a" arg)))
472 "\C-u" "Continue to current line or address.")
473 ;;
474 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
475 nil "Start or continue execution.")
476
477 ;; For debugging Emacs only.
478 (gud-def gud-pp
479 (gud-call
480 (concat
481 "pp1 " (if (eq (buffer-local-value
482 'major-mode (window-buffer)) 'speedbar-mode)
483 (gdb-find-watch-expression) "%e")) arg)
484 nil "Print the emacs s-expression.")
485
486 (define-key gud-minor-mode-map [left-margin mouse-1]
487 'gdb-mouse-set-clear-breakpoint)
488 (define-key gud-minor-mode-map [left-fringe mouse-1]
489 'gdb-mouse-set-clear-breakpoint)
490 (define-key gud-minor-mode-map [left-fringe mouse-2]
491 'gdb-mouse-until)
492 (define-key gud-minor-mode-map [left-margin drag-mouse-1]
493 'gdb-mouse-until)
494 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
495 'gdb-mouse-until)
496 (define-key gud-minor-mode-map [left-margin mouse-2]
497 'gdb-mouse-until)
498 (define-key gud-minor-mode-map [left-margin C-drag-mouse-1]
499 'gdb-mouse-jump)
500 (define-key gud-minor-mode-map [left-fringe C-drag-mouse-1]
501 'gdb-mouse-jump)
502 (define-key gud-minor-mode-map [left-fringe C-mouse-2]
503 'gdb-mouse-jump)
504 (define-key gud-minor-mode-map [left-margin C-mouse-2]
505 'gdb-mouse-jump)
506 (define-key gud-minor-mode-map [left-margin mouse-3]
507 'gdb-mouse-toggle-breakpoint-margin)
508 (define-key gud-minor-mode-map [left-fringe mouse-3]
509 'gdb-mouse-toggle-breakpoint-fringe)
510
511 (setq comint-input-sender 'gdb-send)
512
513 ;; (re-)initialize
514 (setq gdb-frame-address (if gdb-show-main "main" nil))
515 (setq gdb-previous-frame-address nil
516 gdb-memory-address "main"
517 gdb-previous-frame nil
518 gdb-selected-frame nil
519 gdb-current-language nil
520 gdb-frame-number nil
521 gdb-var-list nil
522 gdb-force-update t
523 gdb-first-post-prompt t
524 gdb-prompting nil
525 gdb-input-queue nil
526 gdb-current-item nil
527 gdb-pending-triggers nil
528 gdb-output-sink 'user
529 gdb-server-prefix "server "
530 gdb-flush-pending-output nil
531 gdb-location-alist nil
532 gdb-source-file-list nil
533 gdb-error nil
534 gdb-macro-info nil
535 gdb-buffer-fringe-width (car (window-fringes))
536 gdb-debug-ring nil
537 gdb-signalled nil
538 gdb-source-window nil
539 gdb-inferior-status nil
540 gdb-continuation nil)
541
542 (setq gdb-buffer-type 'gdba)
543
544 (if gdb-use-separate-io-buffer (gdb-clear-inferior-io))
545
546 ;; Hack to see test for GDB 6.4+ (-stack-info-frame was implemented in 6.4)
547 (gdb-enqueue-input (list "server interpreter mi -stack-info-frame\n"
548 'gdb-get-version)))
549
550 (defun gdb-init-2 ()
551 (if (eq window-system 'w32)
552 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
553 (gdb-enqueue-input (list "set height 0\n" 'ignore))
554 (gdb-enqueue-input (list "set width 0\n" 'ignore))
555
556 (if (string-equal gdb-version "pre-6.4")
557 (progn
558 (gdb-enqueue-input (list (concat gdb-server-prefix "info sources\n")
559 'gdb-set-gud-minor-mode-existing-buffers))
560 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-1))
561 (gdb-enqueue-input
562 (list "server interpreter mi -data-list-register-names\n"
563 'gdb-get-register-names))
564 ; Needs GDB 6.2 onwards.
565 (gdb-enqueue-input
566 (list "server interpreter mi \"-file-list-exec-source-files\"\n"
567 'gdb-set-gud-minor-mode-existing-buffers-1))
568 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-2))
569
570 ;; find source file and compilation directory here
571 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
572 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
573 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
574
575 (run-hooks 'gdba-mode-hook))
576
577 (defun gdb-get-version ()
578 (goto-char (point-min))
579 (if (and (re-search-forward gdb-error-regexp nil t)
580 (string-match ".*(missing implementation)" (match-string 1)))
581 (setq gdb-version "pre-6.4")
582 (setq gdb-version "6.4+"))
583 (gdb-init-2))
584
585 (defun gdb-mouse-until (event)
586 "Continue running until a source line past the current line.
587 The destination source line can be selected either by clicking with mouse-2
588 on the fringe/margin or dragging the arrow with mouse-1 (default bindings)."
589 (interactive "e")
590 (if gud-overlay-arrow-position
591 (let ((start (event-start event))
592 (end (event-end event))
593 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
594 (if (not (string-match "Machine" mode-name))
595 (if (equal buffer (window-buffer (posn-window end)))
596 (with-current-buffer buffer
597 (when (or (equal start end)
598 (equal (posn-point start)
599 (marker-position
600 gud-overlay-arrow-position)))
601 (setq line (line-number-at-pos (posn-point end)))
602 (gud-call (concat "until " (number-to-string line))))))
603 (if (equal (marker-buffer gdb-overlay-arrow-position)
604 (window-buffer (posn-window end)))
605 (when (or (equal start end)
606 (equal (posn-point start)
607 (marker-position
608 gdb-overlay-arrow-position)))
609 (save-excursion
610 (goto-line (line-number-at-pos (posn-point end)))
611 (forward-char 2)
612 (gud-call (concat "until *%a")))))))))
613
614 (defun gdb-mouse-jump (event)
615 "Set execution address/line.
616 The destination source line can be selected either by clicking with mouse-2
617 on the fringe/margin or dragging the arrow with mouse-1 (default bindings).
618 Unlike gdb-mouse-until the destination address can be before the current
619 line, and no execution takes place."
620 (interactive "e")
621 (if gud-overlay-arrow-position
622 (let ((start (event-start event))
623 (end (event-end event))
624 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
625 (if (not (string-match "Machine" mode-name))
626 (if (equal buffer (window-buffer (posn-window end)))
627 (with-current-buffer buffer
628 (when (or (equal start end)
629 (equal (posn-point start)
630 (marker-position
631 gud-overlay-arrow-position)))
632 (setq line (line-number-at-pos (posn-point end)))
633 (progn (gud-call (concat "tbreak " (number-to-string line)))
634 (gud-call (concat "jump " (number-to-string line)))))))
635 (if (equal (marker-buffer gdb-overlay-arrow-position)
636 (window-buffer (posn-window end)))
637 (when (or (equal start end)
638 (equal (posn-point start)
639 (marker-position
640 gdb-overlay-arrow-position)))
641 (save-excursion
642 (goto-line (line-number-at-pos (posn-point end)))
643 (forward-char 2)
644 (progn
645 (gud-call (concat "tbreak *%a"))
646 (gud-call (concat "jump *%a"))))))))))
647
648 (defcustom gdb-speedbar-auto-raise nil
649 "If non-nil raise speedbar every time display of watch expressions is\
650 updated."
651 :type 'boolean
652 :group 'gud
653 :version "22.1")
654
655 (defun gdb-speedbar-auto-raise (arg)
656 "Toggle automatic raising of the speedbar for watch expressions.
657 With arg, automatically raise speedbar iff arg is positive."
658 (interactive "P")
659 (setq gdb-speedbar-auto-raise
660 (if (null arg)
661 (not gdb-speedbar-auto-raise)
662 (> (prefix-numeric-value arg) 0)))
663 (message (format "Auto raising %sabled"
664 (if gdb-speedbar-auto-raise "en" "dis"))))
665
666 (defcustom gdb-use-colon-colon-notation nil
667 "If non-nil use FUN::VAR format to display variables in the speedbar."
668 :type 'boolean
669 :group 'gud
670 :version "22.1")
671
672 (define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch)
673 (define-key global-map (concat gud-key-prefix "\C-w") 'gud-watch)
674
675 (defun gud-watch (&optional arg event)
676 "Watch expression at point.
677 With arg, enter name of variable to be watched in the minibuffer."
678 (interactive (list current-prefix-arg last-input-event))
679 (let ((minor-mode (buffer-local-value 'gud-minor-mode gud-comint-buffer)))
680 (if (memq minor-mode '(gdbmi gdba))
681 (progn
682 (if event (posn-set-point (event-end event)))
683 (require 'tooltip)
684 (save-selected-window
685 (let ((expr (if arg
686 (completing-read "Name of variable: "
687 'gud-gdb-complete-command)
688 (tooltip-identifier-from-point (point)))))
689 (catch 'already-watched
690 (dolist (var gdb-var-list)
691 (unless (string-match "\\." (car var))
692 (if (string-equal expr (nth 1 var))
693 (throw 'already-watched nil))))
694 (set-text-properties 0 (length expr) nil expr)
695 (gdb-enqueue-input
696 (list
697 (if (eq minor-mode 'gdba)
698 (concat
699 "server interpreter mi \"-var-create - * " expr "\"\n")
700 (concat"-var-create - * " expr "\n"))
701 `(lambda () (gdb-var-create-handler ,expr))))))))
702 (message "gud-watch is a no-op in this mode."))))
703
704 (defconst gdb-var-create-regexp
705 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
706
707 (defun gdb-var-create-handler (expr)
708 (goto-char (point-min))
709 (if (re-search-forward gdb-var-create-regexp nil t)
710 (let ((var (list
711 (match-string 1)
712 (if (and (string-equal gdb-current-language "c")
713 gdb-use-colon-colon-notation gdb-selected-frame)
714 (setq expr (concat gdb-selected-frame "::" expr))
715 expr)
716 (match-string 2)
717 (match-string 3)
718 nil nil)))
719 (push var gdb-var-list)
720 (speedbar 1)
721 (unless (string-equal
722 speedbar-initial-expansion-list-name "GUD")
723 (speedbar-change-initial-expansion-list "GUD"))
724 (gdb-enqueue-input
725 (list
726 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
727 (concat "server interpreter mi \"-var-evaluate-expression "
728 (car var) "\"\n")
729 (concat "-var-evaluate-expression " (car var) "\n"))
730 `(lambda () (gdb-var-evaluate-expression-handler
731 ,(car var) nil)))))
732 (if (search-forward "Undefined command" nil t)
733 (message-box "Watching expressions requires gdb 6.0 onwards")
734 (message-box "No symbol \"%s\" in current context." expr))))
735
736 (defun gdb-var-evaluate-expression-handler (varnum changed)
737 (goto-char (point-min))
738 (re-search-forward ".*value=\\(\".*\"\\)" nil t)
739 (let ((var (assoc varnum gdb-var-list)))
740 (when var
741 (if changed (setcar (nthcdr 5 var) 'changed))
742 (setcar (nthcdr 4 var) (read (match-string 1))))))
743
744 (defun gdb-var-list-children (varnum)
745 (gdb-enqueue-input
746 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
747 `(lambda () (gdb-var-list-children-handler ,varnum)))))
748
749 (defconst gdb-var-list-children-regexp
750 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",\
751 type=\"\\(.*?\\)\"")
752
753 (defun gdb-var-list-children-handler (varnum)
754 (goto-char (point-min))
755 (let ((var-list nil))
756 (catch 'child-already-watched
757 (dolist (var gdb-var-list)
758 (if (string-equal varnum (car var))
759 (progn
760 (push var var-list)
761 (while (re-search-forward gdb-var-list-children-regexp nil t)
762 (let ((varchild (list (match-string 1)
763 (match-string 2)
764 (match-string 3)
765 (match-string 4)
766 nil nil)))
767 (if (assoc (car varchild) gdb-var-list)
768 (throw 'child-already-watched nil))
769 (push varchild var-list)
770 (gdb-enqueue-input
771 (list
772 (concat
773 "server interpreter mi \"-var-evaluate-expression "
774 (car varchild) "\"\n")
775 `(lambda () (gdb-var-evaluate-expression-handler
776 ,(car varchild) nil)))))))
777 (push var var-list)))
778 (setq gdb-var-list (nreverse var-list)))))
779
780 (defun gdb-var-update ()
781 (when (not (member 'gdb-var-update gdb-pending-triggers))
782 (gdb-enqueue-input
783 (list "server interpreter mi \"-var-update *\"\n"
784 'gdb-var-update-handler))
785 (push 'gdb-var-update gdb-pending-triggers)))
786
787 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\",in_scope=\"\\(.*?\\)\"")
788
789 (defun gdb-var-update-handler ()
790 (dolist (var gdb-var-list)
791 (setcar (nthcdr 5 var) nil))
792 (goto-char (point-min))
793 (while (re-search-forward gdb-var-update-regexp nil t)
794 (let ((varnum (match-string 1)))
795 (if (string-equal (match-string 2) "false")
796 (let ((var (assoc varnum gdb-var-list)))
797 (if var (setcar (nthcdr 5 var) 'out-of-scope)))
798 (gdb-enqueue-input
799 (list
800 (concat "server interpreter mi \"-var-evaluate-expression "
801 varnum "\"\n")
802 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
803 (setq gdb-pending-triggers
804 (delq 'gdb-var-update gdb-pending-triggers))
805 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
806 ;; Dummy command to update speedbar at right time.
807 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-refresh))
808 ;; Keep gdb-pending-triggers non-nil till end.
809 (push 'gdb-speedbar-refresh gdb-pending-triggers)))
810
811 (defun gdb-speedbar-refresh ()
812 (setq gdb-pending-triggers
813 (delq 'gdb-speedbar-refresh gdb-pending-triggers))
814 (with-current-buffer gud-comint-buffer
815 (let ((speedbar-verbosity-level 0)
816 (speedbar-shown-directories nil))
817 (save-excursion
818 (speedbar-refresh)))))
819
820 (defun gdb-var-delete ()
821 "Delete watch expression at point from the speedbar."
822 (interactive)
823 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
824 '(gdbmi gdba))
825 (let ((text (speedbar-line-text)))
826 (string-match "\\(\\S-+\\)" text)
827 (let ((expr (match-string 1 text)) var varnum)
828 (catch 'expr-found
829 (dolist (var1 gdb-var-list)
830 (when (string-equal expr (nth 1 var1))
831 (setq var var1)
832 (setq varnum (car var1))
833 (throw 'expr-found nil))))
834 (unless (string-match "\\." (car var))
835 (gdb-enqueue-input
836 (list
837 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
838 'gdba)
839 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
840 (concat "-var-delete " varnum "\n"))
841 'ignore))
842 (setq gdb-var-list (delq var gdb-var-list))
843 (dolist (varchild gdb-var-list)
844 (if (string-match (concat (car var) "\\.") (car varchild))
845 (setq gdb-var-list (delq varchild gdb-var-list)))))))))
846
847 (defun gdb-edit-value (text token indent)
848 "Assign a value to a variable displayed in the speedbar."
849 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
850 (varnum (car var)) (value))
851 (setq value (read-string "New value: "))
852 (gdb-enqueue-input
853 (list
854 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
855 (concat "server interpreter mi \"-var-assign "
856 varnum " " value "\"\n")
857 (concat "-var-assign " varnum " " value "\n"))
858 `(lambda () (gdb-edit-value-handler ,value))))))
859
860 (defun gdb-edit-value-handler (value)
861 (goto-char (point-min))
862 (if (re-search-forward gdb-error-regexp nil t)
863 (message-box "Invalid number or expression (%s)" value)))
864
865 (defcustom gdb-show-changed-values t
866 "If non-nil change the face of out of scope variables and changed values.
867 Out of scope variables are suppressed with `shadow' face.
868 Changed values are highlighted with the face `font-lock-warning-face'."
869 :type 'boolean
870 :group 'gud
871 :version "22.1")
872
873 (defun gdb-speedbar-expand-node (text token indent)
874 "Expand the node the user clicked on.
875 TEXT is the text of the button we clicked on, a + or - item.
876 TOKEN is data related to this node.
877 INDENT is the current indentation depth."
878 (cond ((string-match "+" text) ;expand this node
879 (if (and
880 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
881 (string-equal gdb-version "pre-6.4"))
882 (gdb-var-list-children token)
883 (gdb-var-list-children-1 token)))
884 ((string-match "-" text) ;contract this node
885 (dolist (var gdb-var-list)
886 (if (string-match (concat token "\\.") (car var))
887 (setq gdb-var-list (delq var gdb-var-list))))
888 (speedbar-change-expand-button-char ?+)
889 (speedbar-delete-subblock indent))
890 (t (error "Ooops... not sure what to do")))
891 (speedbar-center-buffer-smartly))
892
893 (defun gdb-get-target-string ()
894 (with-current-buffer gud-comint-buffer
895 gud-target-name))
896 \f
897
898 ;;
899 ;; gdb buffers.
900 ;;
901 ;; Each buffer has a TYPE -- a symbol that identifies the function
902 ;; of that particular buffer.
903 ;;
904 ;; The usual gdb interaction buffer is given the type `gdba' and
905 ;; is constructed specially.
906 ;;
907 ;; Others are constructed by gdb-get-buffer-create and
908 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
909
910 (defvar gdb-buffer-rules-assoc '())
911
912 (defun gdb-get-buffer (key)
913 "Return the gdb buffer tagged with type KEY.
914 The key should be one of the cars in `gdb-buffer-rules-assoc'."
915 (save-excursion
916 (gdb-look-for-tagged-buffer key (buffer-list))))
917
918 (defun gdb-get-buffer-create (key)
919 "Create a new gdb buffer of the type specified by KEY.
920 The key should be one of the cars in `gdb-buffer-rules-assoc'."
921 (or (gdb-get-buffer key)
922 (let* ((rules (assoc key gdb-buffer-rules-assoc))
923 (name (funcall (gdb-rules-name-maker rules)))
924 (new (get-buffer-create name)))
925 (with-current-buffer new
926 (let ((trigger))
927 (if (cdr (cdr rules))
928 (setq trigger (funcall (car (cdr (cdr rules))))))
929 (setq gdb-buffer-type key)
930 (set (make-local-variable 'gud-minor-mode)
931 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
932 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
933 (if trigger (funcall trigger)))
934 new))))
935
936 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
937
938 (defun gdb-look-for-tagged-buffer (key bufs)
939 (let ((retval nil))
940 (while (and (not retval) bufs)
941 (set-buffer (car bufs))
942 (if (eq gdb-buffer-type key)
943 (setq retval (car bufs)))
944 (setq bufs (cdr bufs)))
945 retval))
946
947 ;;
948 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
949 ;; at least one and possible more functions. The functions have these
950 ;; roles in defining a buffer type:
951 ;;
952 ;; NAME - Return a name for this buffer type.
953 ;;
954 ;; The remaining function(s) are optional:
955 ;;
956 ;; MODE - called in a new buffer with no arguments, should establish
957 ;; the proper mode for the buffer.
958 ;;
959
960 (defun gdb-set-buffer-rules (buffer-type &rest rules)
961 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
962 (if binding
963 (setcdr binding rules)
964 (push (cons buffer-type rules)
965 gdb-buffer-rules-assoc))))
966
967 ;; GUD buffers are an exception to the rules
968 (gdb-set-buffer-rules 'gdba 'error)
969
970 ;; Partial-output buffer : This accumulates output from a command executed on
971 ;; behalf of emacs (rather than the user).
972 ;;
973 (gdb-set-buffer-rules 'gdb-partial-output-buffer
974 'gdb-partial-output-name)
975
976 (defun gdb-partial-output-name ()
977 (concat "*partial-output-"
978 (gdb-get-target-string)
979 "*"))
980
981 \f
982 (gdb-set-buffer-rules 'gdb-inferior-io
983 'gdb-inferior-io-name
984 'gdb-inferior-io-mode)
985
986 (defun gdb-inferior-io-name ()
987 (concat "*input/output of "
988 (gdb-get-target-string)
989 "*"))
990
991 (defun gdb-display-separate-io-buffer ()
992 "Display IO of debugged program in a separate window."
993 (interactive)
994 (if gdb-use-separate-io-buffer
995 (gdb-display-buffer
996 (gdb-get-buffer-create 'gdb-inferior-io))))
997
998 (defconst gdb-frame-parameters
999 '((height . 14) (width . 80)
1000 (unsplittable . t)
1001 (tool-bar-lines . nil)
1002 (menu-bar-lines . nil)
1003 (minibuffer . nil)))
1004
1005 (defun gdb-frame-separate-io-buffer ()
1006 "Display IO of inferior in a new frame."
1007 (interactive)
1008 (if gdb-use-separate-io-buffer
1009 (let ((special-display-regexps (append special-display-regexps '(".*")))
1010 (special-display-frame-alist gdb-frame-parameters))
1011 (display-buffer (gdb-get-buffer-create 'gdb-inferior-io)))))
1012
1013 (defvar gdb-inferior-io-mode-map
1014 (let ((map (make-sparse-keymap)))
1015 (define-key map "\C-c\C-c" 'gdb-separate-io-interrupt)
1016 (define-key map "\C-c\C-z" 'gdb-separate-io-stop)
1017 (define-key map "\C-c\C-\\" 'gdb-separate-io-quit)
1018 (define-key map "\C-c\C-d" 'gdb-separate-io-eof)
1019 (define-key map "\C-d" 'gdb-separate-io-eof)
1020 map))
1021
1022 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
1023 "Major mode for gdb inferior-io."
1024 :syntax-table nil :abbrev-table nil
1025 ;; We want to use comint because it has various nifty and familiar
1026 ;; features. We don't need a process, but comint wants one, so create
1027 ;; a dummy one.
1028 (make-comint-in-buffer
1029 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
1030 (current-buffer) "hexl")
1031 (setq comint-input-sender 'gdb-inferior-io-sender))
1032
1033 (defun gdb-inferior-io-sender (proc string)
1034 ;; PROC is the pseudo-process created to satisfy comint.
1035 (with-current-buffer (process-buffer proc)
1036 (setq proc (get-buffer-process gud-comint-buffer))
1037 (process-send-string proc string)
1038 (process-send-string proc "\n")))
1039
1040 (defun gdb-separate-io-interrupt ()
1041 "Interrupt the program being debugged."
1042 (interactive)
1043 (interrupt-process
1044 (get-buffer-process gud-comint-buffer) comint-ptyp))
1045
1046 (defun gdb-separate-io-quit ()
1047 "Send quit signal to the program being debugged."
1048 (interactive)
1049 (quit-process
1050 (get-buffer-process gud-comint-buffer) comint-ptyp))
1051
1052 (defun gdb-separate-io-stop ()
1053 "Stop the program being debugged."
1054 (interactive)
1055 (stop-process
1056 (get-buffer-process gud-comint-buffer) comint-ptyp))
1057
1058 (defun gdb-separate-io-eof ()
1059 "Send end-of-file to the program being debugged."
1060 (interactive)
1061 (process-send-eof
1062 (get-buffer-process gud-comint-buffer)))
1063 \f
1064
1065 ;; gdb communications
1066 ;;
1067
1068 ;; INPUT: things sent to gdb
1069 ;;
1070 ;; The queues are lists. Each element is either a string (indicating user or
1071 ;; user-like input) or a list of the form:
1072 ;;
1073 ;; (INPUT-STRING HANDLER-FN)
1074 ;;
1075 ;; The handler function will be called from the partial-output buffer when the
1076 ;; command completes. This is the way to write commands which invoke gdb
1077 ;; commands autonomously.
1078 ;;
1079 ;; These lists are consumed tail first.
1080 ;;
1081 (defvar gdb-continuation nil)
1082
1083 (defun gdb-send (proc string)
1084 "A comint send filter for gdb.
1085 This filter may simply queue input for a later time."
1086 (with-current-buffer gud-comint-buffer
1087 (let ((inhibit-read-only t))
1088 (remove-text-properties (point-min) (point-max) '(face))))
1089 (if (string-match "\\\\$" string)
1090 (setq gdb-continuation (concat gdb-continuation string "\n"))
1091 (let ((item (concat gdb-continuation string "\n")))
1092 (if gud-running
1093 (progn
1094 (if gdb-enable-debug (push (cons 'send item) gdb-debug-ring))
1095 (process-send-string proc item))
1096 (gdb-enqueue-input item)))
1097 (setq gdb-continuation nil)))
1098
1099 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
1100 ;; is a query, or other non-top-level prompt.
1101
1102 (defun gdb-enqueue-input (item)
1103 (if (not gud-running)
1104 (if gdb-prompting
1105 (progn
1106 (gdb-send-item item)
1107 (setq gdb-prompting nil))
1108 (push item gdb-input-queue))))
1109
1110 (defun gdb-dequeue-input ()
1111 (let ((queue gdb-input-queue))
1112 (and queue
1113 (let ((last (car (last queue))))
1114 (unless (nbutlast queue) (setq gdb-input-queue '()))
1115 last))))
1116
1117 (defun gdb-send-item (item)
1118 (setq gdb-flush-pending-output nil)
1119 (if gdb-enable-debug (push (cons 'send-item item) gdb-debug-ring))
1120 (setq gdb-current-item item)
1121 (let ((process (get-buffer-process gud-comint-buffer)))
1122 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1123 (if (stringp item)
1124 (progn
1125 (setq gdb-output-sink 'user)
1126 (process-send-string process item))
1127 (progn
1128 (gdb-clear-partial-output)
1129 (setq gdb-output-sink 'pre-emacs)
1130 (process-send-string process
1131 (car item))))
1132 ;; case: eq gud-minor-mode 'gdbmi
1133 (gdb-clear-partial-output)
1134 (setq gdb-output-sink 'emacs)
1135 (process-send-string process (car item)))))
1136 \f
1137 ;;
1138 ;; output -- things gdb prints to emacs
1139 ;;
1140 ;; GDB output is a stream interrupted by annotations.
1141 ;; Annotations can be recognized by their beginning
1142 ;; with \C-j\C-z\C-z<tag><opt>\C-j
1143 ;;
1144 ;; The tag is a string obeying symbol syntax.
1145 ;;
1146 ;; The optional part `<opt>' can be either the empty string
1147 ;; or a space followed by more data relating to the annotation.
1148 ;; For example, the SOURCE annotation is followed by a filename,
1149 ;; line number and various useless goo. This data must not include
1150 ;; any newlines.
1151 ;;
1152
1153 (defcustom gud-gdba-command-name "gdb -annotate=3"
1154 "Default command to execute an executable under the GDB-UI debugger."
1155 :type 'string
1156 :group 'gud
1157 :version "22.1")
1158
1159 (defvar gdb-annotation-rules
1160 '(("pre-prompt" gdb-pre-prompt)
1161 ("prompt" gdb-prompt)
1162 ("commands" gdb-subprompt)
1163 ("overload-choice" gdb-subprompt)
1164 ("query" gdb-subprompt)
1165 ;; Need this prompt for GDB 6.1
1166 ("nquery" gdb-subprompt)
1167 ("prompt-for-continue" gdb-subprompt)
1168 ("post-prompt" gdb-post-prompt)
1169 ("source" gdb-source)
1170 ("starting" gdb-starting)
1171 ("exited" gdb-exited)
1172 ("signalled" gdb-signalled)
1173 ("signal" gdb-signal)
1174 ("breakpoint" gdb-stopping)
1175 ("watchpoint" gdb-stopping)
1176 ("frame-begin" gdb-frame-begin)
1177 ("stopped" gdb-stopped)
1178 ("error-begin" gdb-error)
1179 ("error" gdb-error)
1180 ) "An assoc mapping annotation tags to functions which process them.")
1181
1182 (defun gdb-resync()
1183 (setq gdb-flush-pending-output t)
1184 (setq gud-running nil)
1185 (gdb-force-mode-line-update "stopped")
1186 (setq gdb-output-sink 'user)
1187 (setq gdb-input-queue nil)
1188 (setq gdb-pending-triggers nil)
1189 (setq gdb-prompting t))
1190
1191 (defconst gdb-source-spec-regexp
1192 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
1193
1194 ;; Do not use this except as an annotation handler.
1195 (defun gdb-source (args)
1196 (string-match gdb-source-spec-regexp args)
1197 ;; Extract the frame position from the marker.
1198 (setq gud-last-frame
1199 (cons
1200 (match-string 1 args)
1201 (string-to-number (match-string 2 args))))
1202 (setq gdb-frame-address (match-string 3 args))
1203 ;; cover for auto-display output which comes *before*
1204 ;; stopped annotation
1205 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1206
1207 (defun gdb-pre-prompt (ignored)
1208 "An annotation handler for `pre-prompt'.
1209 This terminates the collection of output from a previous command if that
1210 happens to be in effect."
1211 (setq gdb-error nil)
1212 (let ((sink gdb-output-sink))
1213 (cond
1214 ((eq sink 'user) t)
1215 ((eq sink 'emacs)
1216 (setq gdb-output-sink 'post-emacs))
1217 (t
1218 (gdb-resync)
1219 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1220
1221 (defun gdb-prompt (ignored)
1222 "An annotation handler for `prompt'.
1223 This sends the next command (if any) to gdb."
1224 (when gdb-first-prompt
1225 (gdb-init-1)
1226 (setq gdb-first-prompt nil))
1227 (let ((sink gdb-output-sink))
1228 (cond
1229 ((eq sink 'user) t)
1230 ((eq sink 'post-emacs)
1231 (setq gdb-output-sink 'user)
1232 (let ((handler
1233 (car (cdr gdb-current-item))))
1234 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1235 (funcall handler))))
1236 (t
1237 (gdb-resync)
1238 (error "Phase error in gdb-prompt (got %s)" sink))))
1239 (let ((input (gdb-dequeue-input)))
1240 (if input
1241 (gdb-send-item input)
1242 (progn
1243 (setq gdb-prompting t)
1244 (gud-display-frame)))))
1245
1246 (defun gdb-subprompt (ignored)
1247 "An annotation handler for non-top-level prompts."
1248 (setq gdb-prompting t))
1249
1250 (defun gdb-starting (ignored)
1251 "An annotation handler for `starting'.
1252 This says that I/O for the subprocess is now the program being debugged,
1253 not GDB."
1254 (setq gdb-active-process t)
1255 (let ((sink gdb-output-sink))
1256 (cond
1257 ((eq sink 'user)
1258 (progn
1259 (setq gud-running t)
1260 (setq gdb-inferior-status "running")
1261 (gdb-force-mode-line-update gdb-inferior-status)
1262 (gdb-remove-text-properties)
1263 (setq gud-overlay-arrow-position nil)
1264 (setq gdb-overlay-arrow-position nil)
1265 (if gdb-use-separate-io-buffer
1266 (setq gdb-output-sink 'inferior))))
1267 (t
1268 (gdb-resync)
1269 (error "Unexpected `starting' annotation")))))
1270
1271 (defun gdb-signal (ignored)
1272 (setq gdb-inferior-status "signal")
1273 (gdb-force-mode-line-update gdb-inferior-status)
1274 (gdb-stopping ignored))
1275
1276 (defun gdb-stopping (ignored)
1277 "An annotation handler for `breakpoint' and other annotations.
1278 They say that I/O for the subprocess is now GDB, not the program
1279 being debugged."
1280 (if gdb-use-separate-io-buffer
1281 (let ((sink gdb-output-sink))
1282 (cond
1283 ((eq sink 'inferior)
1284 (setq gdb-output-sink 'user))
1285 (t
1286 (gdb-resync)
1287 (error "Unexpected stopping annotation"))))))
1288
1289 (defun gdb-exited (ignored)
1290 "An annotation handler for `exited' and `signalled'.
1291 They say that I/O for the subprocess is now GDB, not the program
1292 being debugged and that the program is no longer running. This
1293 function is used to change the focus of GUD tooltips to #define
1294 directives."
1295 (setq gdb-active-process nil)
1296 (setq gud-overlay-arrow-position nil)
1297 (setq gdb-overlay-arrow-position nil)
1298 (setq gdb-inferior-status "exited")
1299 (gdb-force-mode-line-update gdb-inferior-status)
1300 (gdb-stopping ignored))
1301
1302 (defun gdb-signalled (ignored)
1303 (setq gdb-signalled t))
1304
1305 (defun gdb-frame-begin (ignored)
1306 (let ((sink gdb-output-sink))
1307 (cond
1308 ((eq sink 'inferior)
1309 (setq gdb-output-sink 'user))
1310 ((eq sink 'user) t)
1311 ((eq sink 'emacs) t)
1312 (t
1313 (gdb-resync)
1314 (error "Unexpected frame-begin annotation (%S)" sink)))))
1315
1316 (defun gdb-stopped (ignored)
1317 "An annotation handler for `stopped'.
1318 It is just like `gdb-stopping', except that if we already set the output
1319 sink to `user' in `gdb-stopping', that is fine."
1320 (setq gud-running nil)
1321 (unless (or gud-overlay-arrow-position gud-last-frame)
1322 (gud-display-line (car gud-last-last-frame) (cdr gud-last-last-frame)))
1323 (unless (member gdb-inferior-status '("exited" "signal"))
1324 (setq gdb-inferior-status "stopped")
1325 (gdb-force-mode-line-update gdb-inferior-status))
1326 (let ((sink gdb-output-sink))
1327 (cond
1328 ((eq sink 'inferior)
1329 (setq gdb-output-sink 'user))
1330 ((eq sink 'user) t)
1331 (t
1332 (gdb-resync)
1333 (error "Unexpected stopped annotation"))))
1334 (if gdb-signalled (gdb-exited ignored)))
1335
1336 (defun gdb-error (ignored)
1337 (setq gdb-error (not gdb-error)))
1338
1339 (defun gdb-post-prompt (ignored)
1340 "An annotation handler for `post-prompt'.
1341 This begins the collection of output from the current command if that
1342 happens to be appropriate."
1343 ;; Don't add to queue if there outstanding items or gdb-version is not known
1344 ;; yet.
1345 (unless (or gdb-pending-triggers gdb-first-post-prompt)
1346 (gdb-get-selected-frame)
1347 (gdb-invalidate-frames)
1348 ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
1349 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
1350 (gdb-invalidate-breakpoints)
1351 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1352 ;; so gdb-frame-address is updated.
1353 ;; (gdb-invalidate-assembler)
1354
1355 (if (string-equal gdb-version "pre-6.4")
1356 (gdb-invalidate-registers)
1357 (gdb-get-changed-registers)
1358 (gdb-invalidate-registers-1))
1359
1360 (gdb-invalidate-memory)
1361 (if (string-equal gdb-version "pre-6.4")
1362 (gdb-invalidate-locals)
1363 (gdb-invalidate-locals-1))
1364
1365 (gdb-invalidate-threads)
1366 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1367 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1368 ;; Only needed/used with speedbar/watch expressions.
1369 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1370 (setq gdb-force-update t)
1371 (if (string-equal gdb-version "pre-6.4")
1372 (gdb-var-update)
1373 (gdb-var-update-1)))))
1374 (setq gdb-first-post-prompt nil)
1375 (let ((sink gdb-output-sink))
1376 (cond
1377 ((eq sink 'user) t)
1378 ((eq sink 'pre-emacs)
1379 (setq gdb-output-sink 'emacs))
1380 (t
1381 (gdb-resync)
1382 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1383
1384 (defconst gdb-buffer-list
1385 '(gdb-stack-buffer gdb-locals-buffer gdb-registers-buffer gdb-threads-buffer))
1386
1387 (defun gdb-remove-text-properties ()
1388 (dolist (buffertype gdb-buffer-list)
1389 (let ((buffer (gdb-get-buffer buffertype)))
1390 (if buffer
1391 (with-current-buffer buffer
1392 (let ((inhibit-read-only t))
1393 (remove-text-properties
1394 (point-min) (point-max) '(mouse-face nil help-echo nil))))))))
1395
1396 ;; GUD displays the selected GDB frame. This might might not be the current
1397 ;; GDB frame (after up, down etc). If no GDB frame is visible but the last
1398 ;; visited breakpoint is, use that window.
1399 (defun gdb-display-source-buffer (buffer)
1400 (let* ((last-window (if gud-last-last-frame
1401 (get-buffer-window
1402 (gud-find-file (car gud-last-last-frame)))))
1403 (source-window (or last-window
1404 (if (and gdb-source-window
1405 (window-live-p gdb-source-window))
1406 gdb-source-window))))
1407 (when source-window
1408 (setq gdb-source-window source-window)
1409 (set-window-buffer source-window buffer))
1410 source-window))
1411
1412 (defun gud-gdba-marker-filter (string)
1413 "A gud marker filter for gdb. Handle a burst of output from GDB."
1414 (if gdb-flush-pending-output
1415 nil
1416 (when gdb-enable-debug
1417 (push (cons 'recv string) gdb-debug-ring)
1418 (if (> (length gdb-debug-ring) gdb-debug-ring-max)
1419 (setcdr (nthcdr (1- gdb-debug-ring-max) gdb-debug-ring) nil)))
1420 ;; Recall the left over gud-marker-acc from last time.
1421 (setq gud-marker-acc (concat gud-marker-acc string))
1422 ;; Start accumulating output for the GUD buffer.
1423 (let ((output ""))
1424 ;;
1425 ;; Process all the complete markers in this chunk.
1426 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1427 (let ((annotation (match-string 1 gud-marker-acc)))
1428 ;;
1429 ;; Stuff prior to the match is just ordinary output.
1430 ;; It is either concatenated to OUTPUT or directed
1431 ;; elsewhere.
1432 (setq output
1433 (gdb-concat-output
1434 output
1435 (substring gud-marker-acc 0 (match-beginning 0))))
1436 ;;
1437 ;; Take that stuff off the gud-marker-acc.
1438 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1439 ;;
1440 ;; Parse the tag from the annotation, and maybe its arguments.
1441 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1442 (let* ((annotation-type (match-string 1 annotation))
1443 (annotation-arguments (match-string 2 annotation))
1444 (annotation-rule (assoc annotation-type
1445 gdb-annotation-rules)))
1446 ;; Call the handler for this annotation.
1447 (if annotation-rule
1448 (funcall (car (cdr annotation-rule))
1449 annotation-arguments)
1450 ;; Else the annotation is not recognized. Ignore it silently,
1451 ;; so that GDB can add new annotations without causing
1452 ;; us to blow up.
1453 ))))
1454 ;;
1455 ;; Does the remaining text end in a partial line?
1456 ;; If it does, then keep part of the gud-marker-acc until we get more.
1457 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1458 gud-marker-acc)
1459 (progn
1460 ;; Everything before the potential marker start can be output.
1461 (setq output
1462 (gdb-concat-output output
1463 (substring gud-marker-acc 0
1464 (match-beginning 0))))
1465 ;;
1466 ;; Everything after, we save, to combine with later input.
1467 (setq gud-marker-acc (substring gud-marker-acc
1468 (match-beginning 0))))
1469 ;;
1470 ;; In case we know the gud-marker-acc contains no partial annotations:
1471 (progn
1472 (setq output (gdb-concat-output output gud-marker-acc))
1473 (setq gud-marker-acc "")))
1474 output)))
1475
1476 (defun gdb-concat-output (so-far new)
1477 (if gdb-error
1478 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1479 (let ((sink gdb-output-sink))
1480 (cond
1481 ((eq sink 'user) (concat so-far new))
1482 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1483 ((eq sink 'emacs)
1484 (gdb-append-to-partial-output new)
1485 so-far)
1486 ((eq sink 'inferior)
1487 (gdb-append-to-inferior-io new)
1488 so-far)
1489 (t
1490 (gdb-resync)
1491 (error "Bogon output sink %S" sink)))))
1492
1493 (defun gdb-append-to-partial-output (string)
1494 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1495 (goto-char (point-max))
1496 (insert string)))
1497
1498 (defun gdb-clear-partial-output ()
1499 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1500 (erase-buffer)))
1501
1502 (defun gdb-append-to-inferior-io (string)
1503 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1504 (goto-char (point-max))
1505 (insert-before-markers string))
1506 (if (not (string-equal string ""))
1507 (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io))))
1508
1509 (defun gdb-clear-inferior-io ()
1510 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1511 (erase-buffer)))
1512 \f
1513
1514 ;; One trick is to have a command who's output is always available in a buffer
1515 ;; of it's own, and is always up to date. We build several buffers of this
1516 ;; type.
1517 ;;
1518 ;; There are two aspects to this: gdb has to tell us when the output for that
1519 ;; command might have changed, and we have to be able to run the command
1520 ;; behind the user's back.
1521 ;;
1522 ;; The output phasing associated with the variable gdb-output-sink
1523 ;; help us to run commands behind the user's back.
1524 ;;
1525 ;; Below is the code for specificly managing buffers of output from one
1526 ;; command.
1527 ;;
1528
1529 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1530 ;; It adds an input for the command we are tracking. It should be the
1531 ;; annotation rule binding of whatever gdb sends to tell us this command
1532 ;; might have changed it's output.
1533 ;;
1534 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1535 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1536 ;; input in the input queue (see comment about ``gdb communications'' above).
1537
1538 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1539 output-handler)
1540 `(defun ,name (&optional ignored)
1541 (if (and ,demand-predicate
1542 (not (member ',name
1543 gdb-pending-triggers)))
1544 (progn
1545 (gdb-enqueue-input
1546 (list ,gdb-command ',output-handler))
1547 (push ',name gdb-pending-triggers)))))
1548
1549 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1550 `(defun ,name ()
1551 (setq gdb-pending-triggers
1552 (delq ',trigger
1553 gdb-pending-triggers))
1554 (let ((buf (gdb-get-buffer ',buf-key)))
1555 (and buf
1556 (with-current-buffer buf
1557 (let* ((window (get-buffer-window buf 0))
1558 (start (window-start window))
1559 (p (window-point window))
1560 (buffer-read-only nil))
1561 (erase-buffer)
1562 (insert-buffer-substring (gdb-get-buffer-create
1563 'gdb-partial-output-buffer))
1564 (set-window-start window start)
1565 (set-window-point window p)))))
1566 ;; put customisation here
1567 (,custom-defun)))
1568
1569 (defmacro def-gdb-auto-updated-buffer (buffer-key
1570 trigger-name gdb-command
1571 output-handler-name custom-defun)
1572 `(progn
1573 (def-gdb-auto-update-trigger ,trigger-name
1574 ;; The demand predicate:
1575 (gdb-get-buffer ',buffer-key)
1576 ,gdb-command
1577 ,output-handler-name)
1578 (def-gdb-auto-update-handler ,output-handler-name
1579 ,trigger-name ,buffer-key ,custom-defun)))
1580
1581 \f
1582 ;;
1583 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1584 ;;
1585 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1586 'gdb-breakpoints-buffer-name
1587 'gdb-breakpoints-mode)
1588
1589 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1590 ;; This defines the auto update rule for buffers of type
1591 ;; `gdb-breakpoints-buffer'.
1592 ;;
1593 ;; It defines a function to serve as the annotation handler that
1594 ;; handles the `foo-invalidated' message. That function is called:
1595 gdb-invalidate-breakpoints
1596 ;;
1597 ;; To update the buffer, this command is sent to gdb.
1598 "server info breakpoints\n"
1599 ;;
1600 ;; This also defines a function to be the handler for the output
1601 ;; from the command above. That function will copy the output into
1602 ;; the appropriately typed buffer. That function will be called:
1603 gdb-info-breakpoints-handler
1604 ;; buffer specific functions
1605 gdb-info-breakpoints-custom)
1606
1607 (defconst breakpoint-xpm-data
1608 "/* XPM */
1609 static char *magick[] = {
1610 /* columns rows colors chars-per-pixel */
1611 \"10 10 2 1\",
1612 \" c red\",
1613 \"+ c None\",
1614 /* pixels */
1615 \"+++ +++\",
1616 \"++ ++\",
1617 \"+ +\",
1618 \" \",
1619 \" \",
1620 \" \",
1621 \" \",
1622 \"+ +\",
1623 \"++ ++\",
1624 \"+++ +++\",
1625 };"
1626 "XPM data used for breakpoint icon.")
1627
1628 (defconst breakpoint-enabled-pbm-data
1629 "P1
1630 10 10\",
1631 0 0 0 0 1 1 1 1 0 0 0 0
1632 0 0 0 1 1 1 1 1 1 0 0 0
1633 0 0 1 1 1 1 1 1 1 1 0 0
1634 0 1 1 1 1 1 1 1 1 1 1 0
1635 0 1 1 1 1 1 1 1 1 1 1 0
1636 0 1 1 1 1 1 1 1 1 1 1 0
1637 0 1 1 1 1 1 1 1 1 1 1 0
1638 0 0 1 1 1 1 1 1 1 1 0 0
1639 0 0 0 1 1 1 1 1 1 0 0 0
1640 0 0 0 0 1 1 1 1 0 0 0 0"
1641 "PBM data used for enabled breakpoint icon.")
1642
1643 (defconst breakpoint-disabled-pbm-data
1644 "P1
1645 10 10\",
1646 0 0 1 0 1 0 1 0 0 0
1647 0 1 0 1 0 1 0 1 0 0
1648 1 0 1 0 1 0 1 0 1 0
1649 0 1 0 1 0 1 0 1 0 1
1650 1 0 1 0 1 0 1 0 1 0
1651 0 1 0 1 0 1 0 1 0 1
1652 1 0 1 0 1 0 1 0 1 0
1653 0 1 0 1 0 1 0 1 0 1
1654 0 0 1 0 1 0 1 0 1 0
1655 0 0 0 1 0 1 0 1 0 0"
1656 "PBM data used for disabled breakpoint icon.")
1657
1658 (defvar breakpoint-enabled-icon nil
1659 "Icon for enabled breakpoint in display margin.")
1660
1661 (defvar breakpoint-disabled-icon nil
1662 "Icon for disabled breakpoint in display margin.")
1663
1664 (and (display-images-p)
1665 ;; Bitmap for breakpoint in fringe
1666 (define-fringe-bitmap 'breakpoint
1667 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c")
1668 ;; Bitmap for gud-overlay-arrow in fringe
1669 (define-fringe-bitmap 'hollow-right-triangle
1670 "\xe0\x90\x88\x84\x84\x88\x90\xe0"))
1671
1672 (defface breakpoint-enabled
1673 '((t
1674 :foreground "red"
1675 :weight bold))
1676 "Face for enabled breakpoint icon in fringe."
1677 :group 'gud)
1678
1679 (defface breakpoint-disabled
1680 ;; We use different values of grey for different background types,
1681 ;; so that on low-color displays it will end up as something visible
1682 ;; if it has to be approximated.
1683 '((((background dark)) :foreground "grey60")
1684 (((background light)) :foreground "grey40"))
1685 "Face for disabled breakpoint icon in fringe."
1686 :group 'gud)
1687
1688 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1689 (defun gdb-info-breakpoints-custom ()
1690 (let ((flag) (bptno))
1691 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1692 (dolist (buffer (buffer-list))
1693 (with-current-buffer buffer
1694 (if (and (memq gud-minor-mode '(gdba gdbmi))
1695 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1696 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1697 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1698 (save-excursion
1699 (goto-char (point-min))
1700 (while (< (point) (- (point-max) 1))
1701 (forward-line 1)
1702 (if (looking-at "[^\t].*?breakpoint")
1703 (progn
1704 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1705 (setq bptno (match-string 1))
1706 (setq flag (char-after (match-beginning 2)))
1707 (beginning-of-line)
1708 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1709 (progn
1710 (let ((buffer-read-only nil))
1711 (add-text-properties (match-beginning 1) (match-end 1)
1712 '(face font-lock-function-name-face)))
1713 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1714 (let ((line (match-string 2)) (buffer-read-only nil)
1715 (file (match-string 1)))
1716 (add-text-properties (line-beginning-position)
1717 (line-end-position)
1718 '(mouse-face highlight
1719 help-echo "mouse-2, RET: visit breakpoint"))
1720 (unless (file-exists-p file)
1721 (setq file (cdr (assoc bptno gdb-location-alist))))
1722 (if (and file
1723 (not (string-equal file "File not found")))
1724 (with-current-buffer
1725 (find-file-noselect file 'nowarn)
1726 (set (make-local-variable 'gud-minor-mode)
1727 'gdba)
1728 (set (make-local-variable 'tool-bar-map)
1729 gud-tool-bar-map)
1730 ;; Only want one breakpoint icon at each
1731 ;; location.
1732 (save-excursion
1733 (goto-line (string-to-number line))
1734 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1735 (gdb-enqueue-input
1736 (list
1737 (concat gdb-server-prefix "list "
1738 (match-string-no-properties 1) ":1\n")
1739 'ignore))
1740 (gdb-enqueue-input
1741 (list (concat gdb-server-prefix "info source\n")
1742 `(lambda () (gdb-get-location
1743 ,bptno ,line ,flag))))))))))
1744 (end-of-line)))))
1745 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1746
1747 (defun gdb-mouse-set-clear-breakpoint (event)
1748 "Set/clear breakpoint in left fringe/margin with mouse click."
1749 (interactive "e")
1750 (mouse-minibuffer-check event)
1751 (let ((posn (event-end event)))
1752 (if (numberp (posn-point posn))
1753 (with-selected-window (posn-window posn)
1754 (save-excursion
1755 (goto-char (posn-point posn))
1756 (if (or (posn-object posn)
1757 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1758 'breakpoint))
1759 (gud-remove nil)
1760 (gud-break nil)))))))
1761
1762 (defun gdb-mouse-toggle-breakpoint-margin (event)
1763 "Enable/disable breakpoint in left margin with mouse click."
1764 (interactive "e")
1765 (mouse-minibuffer-check event)
1766 (let ((posn (event-end event)))
1767 (if (numberp (posn-point posn))
1768 (with-selected-window (posn-window posn)
1769 (save-excursion
1770 (goto-char (posn-point posn))
1771 (if (posn-object posn)
1772 (gdb-enqueue-input
1773 (list
1774 (let ((bptno (get-text-property
1775 0 'gdb-bptno (car (posn-string posn)))))
1776 (concat gdb-server-prefix
1777 (if (get-text-property
1778 0 'gdb-enabled (car (posn-string posn)))
1779 "disable "
1780 "enable ")
1781 bptno "\n"))
1782 'ignore))))))))
1783
1784 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1785 "Enable/disable breakpoint in left fringe with mouse click."
1786 (interactive "e")
1787 (mouse-minibuffer-check event)
1788 (let* ((posn (event-end event))
1789 (pos (posn-point posn))
1790 obj)
1791 (when (numberp pos)
1792 (with-selected-window (posn-window posn)
1793 (save-excursion
1794 (set-buffer (window-buffer (selected-window)))
1795 (goto-char pos)
1796 (dolist (overlay (overlays-in pos pos))
1797 (when (overlay-get overlay 'put-break)
1798 (setq obj (overlay-get overlay 'before-string))))
1799 (when (stringp obj)
1800 (gdb-enqueue-input
1801 (list
1802 (concat gdb-server-prefix
1803 (if (get-text-property 0 'gdb-enabled obj)
1804 "disable "
1805 "enable ")
1806 (get-text-property 0 'gdb-bptno obj) "\n")
1807 'ignore))))))))
1808
1809 (defun gdb-breakpoints-buffer-name ()
1810 (with-current-buffer gud-comint-buffer
1811 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1812
1813 (defun gdb-display-breakpoints-buffer ()
1814 "Display status of user-settable breakpoints."
1815 (interactive)
1816 (gdb-display-buffer
1817 (gdb-get-buffer-create 'gdb-breakpoints-buffer)))
1818
1819 (defun gdb-frame-breakpoints-buffer ()
1820 "Display status of user-settable breakpoints in a new frame."
1821 (interactive)
1822 (let ((special-display-regexps (append special-display-regexps '(".*")))
1823 (special-display-frame-alist gdb-frame-parameters))
1824 (display-buffer (gdb-get-buffer-create 'gdb-breakpoints-buffer))))
1825
1826 (defvar gdb-breakpoints-mode-map
1827 (let ((map (make-sparse-keymap))
1828 (menu (make-sparse-keymap "Breakpoints")))
1829 (define-key menu [quit] '("Quit" . gdb-delete-frame-or-window))
1830 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1831 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1832 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1833 (suppress-keymap map)
1834 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1835 (define-key map " " 'gdb-toggle-breakpoint)
1836 (define-key map "D" 'gdb-delete-breakpoint)
1837 ;; Don't bind "q" to kill-this-buffer as we need it for breakpoint icons.
1838 (define-key map "q" 'gdb-delete-frame-or-window)
1839 (define-key map "\r" 'gdb-goto-breakpoint)
1840 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1841 (define-key map [follow-link] 'mouse-face)
1842 map))
1843
1844 (defun gdb-delete-frame-or-window ()
1845 "Delete frame if there is only one window. Otherwise delete the window."
1846 (interactive)
1847 (if (one-window-p) (delete-frame)
1848 (delete-window)))
1849
1850 (defun gdb-breakpoints-mode ()
1851 "Major mode for gdb breakpoints.
1852
1853 \\{gdb-breakpoints-mode-map}"
1854 (kill-all-local-variables)
1855 (setq major-mode 'gdb-breakpoints-mode)
1856 (setq mode-name "Breakpoints")
1857 (use-local-map gdb-breakpoints-mode-map)
1858 (setq buffer-read-only t)
1859 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1860 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1861 'gdb-invalidate-breakpoints
1862 'gdbmi-invalidate-breakpoints))
1863
1864 (defconst gdb-breakpoint-regexp
1865 "\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1866
1867 (defun gdb-toggle-breakpoint ()
1868 "Enable/disable breakpoint at current line."
1869 (interactive)
1870 (save-excursion
1871 (beginning-of-line 1)
1872 (if (looking-at gdb-breakpoint-regexp)
1873 (gdb-enqueue-input
1874 (list
1875 (concat gdb-server-prefix
1876 (if (eq ?y (char-after (match-beginning 2)))
1877 "disable "
1878 "enable ")
1879 (match-string 1) "\n") 'ignore))
1880 (error "Not recognized as break/watchpoint line"))))
1881
1882 (defun gdb-delete-breakpoint ()
1883 "Delete the breakpoint at current line."
1884 (interactive)
1885 (beginning-of-line 1)
1886 (if (looking-at gdb-breakpoint-regexp)
1887 (gdb-enqueue-input
1888 (list
1889 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1890 (error "Not recognized as break/watchpoint line")))
1891
1892 (defun gdb-goto-breakpoint (&optional event)
1893 "Display the breakpoint location specified at current line."
1894 (interactive (list last-input-event))
1895 (if event (posn-set-point (event-end event)))
1896 (save-excursion
1897 (beginning-of-line 1)
1898 (if (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1899 (let ((bptno (match-string 1))
1900 (file (match-string 2))
1901 (line (match-string 3)))
1902 (save-selected-window
1903 (let* ((buffer (find-file-noselect
1904 (if (file-exists-p file) file
1905 (cdr (assoc bptno gdb-location-alist)))))
1906 (window (unless (gdb-display-source-buffer buffer)
1907 (display-buffer buffer))))
1908 (setq gdb-source-window window)
1909 (with-current-buffer buffer
1910 (goto-line (string-to-number line))
1911 (set-window-point window (point))))))
1912 (error "No location specified."))))
1913 \f
1914
1915 ;; Frames buffer. This displays a perpetually correct bactracktrace
1916 ;; (from the command `where').
1917 ;;
1918 ;; Alas, if your stack is deep, it is costly.
1919 ;;
1920 (gdb-set-buffer-rules 'gdb-stack-buffer
1921 'gdb-stack-buffer-name
1922 'gdb-frames-mode)
1923
1924 (def-gdb-auto-updated-buffer gdb-stack-buffer
1925 gdb-invalidate-frames
1926 "server info stack\n"
1927 gdb-info-stack-handler
1928 gdb-info-stack-custom)
1929
1930 (defun gdb-info-stack-custom ()
1931 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1932 (save-excursion
1933 (let ((buffer-read-only nil)
1934 bl el)
1935 (goto-char (point-min))
1936 (while (< (point) (point-max))
1937 (setq bl (line-beginning-position)
1938 el (line-end-position))
1939 (when (looking-at "#")
1940 (add-text-properties bl el
1941 '(mouse-face highlight
1942 help-echo "mouse-2, RET: Select frame")))
1943 (goto-char bl)
1944 (when (looking-at "^#\\([0-9]+\\)")
1945 (when (string-equal (match-string 1) gdb-frame-number)
1946 (put-text-property bl (+ bl 4)
1947 'face '(:inverse-video t)))
1948 (when (re-search-forward
1949 (concat
1950 (if (string-equal (match-string 1) "0") "" " in ")
1951 "\\([^ ]+\\) (") el t)
1952 (put-text-property (match-beginning 1) (match-end 1)
1953 'face font-lock-function-name-face)
1954 (setq bl (match-end 0))
1955 (while (re-search-forward "<\\([^>]+\\)>" el t)
1956 (put-text-property (match-beginning 1) (match-end 1)
1957 'face font-lock-function-name-face))
1958 (goto-char bl)
1959 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1960 (put-text-property (match-beginning 1) (match-end 1)
1961 'face font-lock-variable-name-face))))
1962 (forward-line 1))))))
1963
1964 (defun gdb-stack-buffer-name ()
1965 (with-current-buffer gud-comint-buffer
1966 (concat "*stack frames of " (gdb-get-target-string) "*")))
1967
1968 (defun gdb-display-stack-buffer ()
1969 "Display backtrace of current stack."
1970 (interactive)
1971 (gdb-display-buffer
1972 (gdb-get-buffer-create 'gdb-stack-buffer)))
1973
1974 (defun gdb-frame-stack-buffer ()
1975 "Display backtrace of current stack in a new frame."
1976 (interactive)
1977 (let ((special-display-regexps (append special-display-regexps '(".*")))
1978 (special-display-frame-alist gdb-frame-parameters))
1979 (display-buffer (gdb-get-buffer-create 'gdb-stack-buffer))))
1980
1981 (defvar gdb-frames-mode-map
1982 (let ((map (make-sparse-keymap)))
1983 (suppress-keymap map)
1984 (define-key map "q" 'kill-this-buffer)
1985 (define-key map "\r" 'gdb-frames-select)
1986 (define-key map [mouse-2] 'gdb-frames-select)
1987 (define-key map [follow-link] 'mouse-face)
1988 map))
1989
1990 (defun gdb-frames-mode ()
1991 "Major mode for gdb call stack.
1992
1993 \\{gdb-frames-mode-map}"
1994 (kill-all-local-variables)
1995 (setq major-mode 'gdb-frames-mode)
1996 (setq mode-name "Frames")
1997 (setq buffer-read-only t)
1998 (use-local-map gdb-frames-mode-map)
1999 (run-mode-hooks 'gdb-frames-mode-hook)
2000 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2001 'gdb-invalidate-frames
2002 'gdbmi-invalidate-frames))
2003
2004 (defun gdb-get-frame-number ()
2005 (save-excursion
2006 (end-of-line)
2007 (let* ((start (line-beginning-position))
2008 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
2009 (n (or (and pos (match-string-no-properties 1)) "0")))
2010 n)))
2011
2012 (defun gdb-frames-select (&optional event)
2013 "Select the frame and display the relevant source."
2014 (interactive (list last-input-event))
2015 (if event (posn-set-point (event-end event)))
2016 (gdb-enqueue-input
2017 (list (concat gdb-server-prefix "frame "
2018 (gdb-get-frame-number) "\n") 'ignore))
2019 (gud-display-frame))
2020 \f
2021
2022 ;; Threads buffer. This displays a selectable thread list.
2023 ;;
2024 (gdb-set-buffer-rules 'gdb-threads-buffer
2025 'gdb-threads-buffer-name
2026 'gdb-threads-mode)
2027
2028 (def-gdb-auto-updated-buffer gdb-threads-buffer
2029 gdb-invalidate-threads
2030 (concat gdb-server-prefix "info threads\n")
2031 gdb-info-threads-handler
2032 gdb-info-threads-custom)
2033
2034 (defun gdb-info-threads-custom ()
2035 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
2036 (let ((buffer-read-only nil))
2037 (goto-char (point-min))
2038 (while (< (point) (point-max))
2039 (unless (looking-at "No ")
2040 (add-text-properties (line-beginning-position) (line-end-position)
2041 '(mouse-face highlight
2042 help-echo "mouse-2, RET: select thread")))
2043 (forward-line 1)))))
2044
2045 (defun gdb-threads-buffer-name ()
2046 (with-current-buffer gud-comint-buffer
2047 (concat "*threads of " (gdb-get-target-string) "*")))
2048
2049 (defun gdb-display-threads-buffer ()
2050 "Display IDs of currently known threads."
2051 (interactive)
2052 (gdb-display-buffer
2053 (gdb-get-buffer-create 'gdb-threads-buffer)))
2054
2055 (defun gdb-frame-threads-buffer ()
2056 "Display IDs of currently known threads in a new frame."
2057 (interactive)
2058 (let ((special-display-regexps (append special-display-regexps '(".*")))
2059 (special-display-frame-alist gdb-frame-parameters))
2060 (display-buffer (gdb-get-buffer-create 'gdb-threads-buffer))))
2061
2062 (defvar gdb-threads-mode-map
2063 (let ((map (make-sparse-keymap)))
2064 (suppress-keymap map)
2065 (define-key map "q" 'kill-this-buffer)
2066 (define-key map "\r" 'gdb-threads-select)
2067 (define-key map [mouse-2] 'gdb-threads-select)
2068 (define-key map [follow-link] 'mouse-face)
2069 map))
2070
2071 (defvar gdb-threads-font-lock-keywords
2072 '((") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
2073 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
2074 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face)))
2075 "Font lock keywords used in `gdb-threads-mode'.")
2076
2077 (defun gdb-threads-mode ()
2078 "Major mode for gdb threads.
2079
2080 \\{gdb-threads-mode-map}"
2081 (kill-all-local-variables)
2082 (setq major-mode 'gdb-threads-mode)
2083 (setq mode-name "Threads")
2084 (setq buffer-read-only t)
2085 (use-local-map gdb-threads-mode-map)
2086 (set (make-local-variable 'font-lock-defaults)
2087 '(gdb-threads-font-lock-keywords))
2088 (run-mode-hooks 'gdb-threads-mode-hook)
2089 'gdb-invalidate-threads)
2090
2091 (defun gdb-get-thread-number ()
2092 (save-excursion
2093 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
2094 (match-string-no-properties 1)))
2095
2096 (defun gdb-threads-select (&optional event)
2097 "Select the thread and display the relevant source."
2098 (interactive (list last-input-event))
2099 (if event (posn-set-point (event-end event)))
2100 (gdb-enqueue-input
2101 (list (concat gdb-server-prefix "thread "
2102 (gdb-get-thread-number) "\n") 'ignore))
2103 (gud-display-frame))
2104 \f
2105
2106 ;; Registers buffer.
2107 ;;
2108 (defcustom gdb-all-registers nil
2109 "Non-nil means include floating-point registers."
2110 :type 'boolean
2111 :group 'gud
2112 :version "22.1")
2113
2114 (gdb-set-buffer-rules 'gdb-registers-buffer
2115 'gdb-registers-buffer-name
2116 'gdb-registers-mode)
2117
2118 (def-gdb-auto-updated-buffer gdb-registers-buffer
2119 gdb-invalidate-registers
2120 (concat
2121 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
2122 gdb-info-registers-handler
2123 gdb-info-registers-custom)
2124
2125 (defun gdb-info-registers-custom ()
2126 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2127 (save-excursion
2128 (let ((buffer-read-only nil)
2129 start end)
2130 (goto-char (point-min))
2131 (while (< (point) (point-max))
2132 (setq start (line-beginning-position))
2133 (setq end (line-end-position))
2134 (when (looking-at "^[^ ]+")
2135 (unless (string-equal (match-string 0) "The")
2136 (put-text-property start (match-end 0)
2137 'face font-lock-variable-name-face)
2138 (add-text-properties start end
2139 '(help-echo "mouse-2: edit value"
2140 mouse-face highlight))))
2141 (forward-line 1))))))
2142
2143 (defun gdb-edit-register-value (&optional event)
2144 (interactive (list last-input-event))
2145 (save-excursion
2146 (if event (posn-set-point (event-end event)))
2147 (beginning-of-line)
2148 (let* ((register (current-word))
2149 (value (read-string (format "New value (%s): " register))))
2150 (gdb-enqueue-input
2151 (list (concat gdb-server-prefix "set $" register "=" value "\n")
2152 'ignore)))))
2153
2154 (defvar gdb-registers-mode-map
2155 (let ((map (make-sparse-keymap)))
2156 (suppress-keymap map)
2157 (define-key map "\r" 'gdb-edit-register-value)
2158 (define-key map [mouse-2] 'gdb-edit-register-value)
2159 (define-key map " " 'gdb-all-registers)
2160 (define-key map "q" 'kill-this-buffer)
2161 map))
2162
2163 (defun gdb-registers-mode ()
2164 "Major mode for gdb registers.
2165
2166 \\{gdb-registers-mode-map}"
2167 (kill-all-local-variables)
2168 (setq major-mode 'gdb-registers-mode)
2169 (setq mode-name "Registers")
2170 (setq buffer-read-only t)
2171 (use-local-map gdb-registers-mode-map)
2172 (run-mode-hooks 'gdb-registers-mode-hook)
2173 (if (string-equal gdb-version "pre-6.4")
2174 (progn
2175 (if gdb-all-registers (setq mode-name "Registers:All"))
2176 'gdb-invalidate-registers)
2177 'gdb-invalidate-registers-1))
2178
2179 (defun gdb-registers-buffer-name ()
2180 (with-current-buffer gud-comint-buffer
2181 (concat "*registers of " (gdb-get-target-string) "*")))
2182
2183 (defun gdb-display-registers-buffer ()
2184 "Display integer register contents."
2185 (interactive)
2186 (gdb-display-buffer
2187 (gdb-get-buffer-create 'gdb-registers-buffer)))
2188
2189 (defun gdb-frame-registers-buffer ()
2190 "Display integer register contents in a new frame."
2191 (interactive)
2192 (let ((special-display-regexps (append special-display-regexps '(".*")))
2193 (special-display-frame-alist gdb-frame-parameters))
2194 (display-buffer (gdb-get-buffer-create 'gdb-registers-buffer))))
2195
2196 (defun gdb-all-registers ()
2197 "Toggle the display of floating-point registers (pre GDB 6.4 only)."
2198 (interactive)
2199 (when (string-equal gdb-version "pre-6.4")
2200 (if gdb-all-registers
2201 (progn
2202 (setq gdb-all-registers nil)
2203 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2204 (setq mode-name "Registers")))
2205 (setq gdb-all-registers t)
2206 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2207 (setq mode-name "Registers:All")))
2208 (message (format "Display of floating-point registers %sabled"
2209 (if gdb-all-registers "en" "dis")))
2210 (gdb-invalidate-registers)))
2211 \f
2212
2213 ;; Memory buffer.
2214 ;;
2215 (defcustom gdb-memory-repeat-count 32
2216 "Number of data items in memory window."
2217 :type 'integer
2218 :group 'gud
2219 :version "22.1")
2220
2221 (defcustom gdb-memory-format "x"
2222 "Display format of data items in memory window."
2223 :type '(choice (const :tag "Hexadecimal" "x")
2224 (const :tag "Signed decimal" "d")
2225 (const :tag "Unsigned decimal" "u")
2226 (const :tag "Octal" "o")
2227 (const :tag "Binary" "t"))
2228 :group 'gud
2229 :version "22.1")
2230
2231 (defcustom gdb-memory-unit "w"
2232 "Unit size of data items in memory window."
2233 :type '(choice (const :tag "Byte" "b")
2234 (const :tag "Halfword" "h")
2235 (const :tag "Word" "w")
2236 (const :tag "Giant word" "g"))
2237 :group 'gud
2238 :version "22.1")
2239
2240 (gdb-set-buffer-rules 'gdb-memory-buffer
2241 'gdb-memory-buffer-name
2242 'gdb-memory-mode)
2243
2244 (def-gdb-auto-updated-buffer gdb-memory-buffer
2245 gdb-invalidate-memory
2246 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
2247 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
2248 gdb-read-memory-handler
2249 gdb-read-memory-custom)
2250
2251 (defun gdb-read-memory-custom ()
2252 (save-excursion
2253 (goto-char (point-min))
2254 (if (looking-at "0x[[:xdigit:]]+")
2255 (setq gdb-memory-address (match-string 0)))))
2256
2257 (defvar gdb-memory-mode-map
2258 (let ((map (make-sparse-keymap)))
2259 (suppress-keymap map)
2260 (define-key map "q" 'kill-this-buffer)
2261 map))
2262
2263 (defun gdb-memory-set-address (event)
2264 "Set the start memory address."
2265 (interactive "e")
2266 (save-selected-window
2267 (select-window (posn-window (event-start event)))
2268 (let ((arg (read-from-minibuffer "Memory address: ")))
2269 (setq gdb-memory-address arg))
2270 (gdb-invalidate-memory)))
2271
2272 (defun gdb-memory-set-repeat-count (event)
2273 "Set the number of data items in memory window."
2274 (interactive "e")
2275 (save-selected-window
2276 (select-window (posn-window (event-start event)))
2277 (let* ((arg (read-from-minibuffer "Repeat count: "))
2278 (count (string-to-number arg)))
2279 (if (<= count 0)
2280 (error "Positive numbers only")
2281 (customize-set-variable 'gdb-memory-repeat-count count)
2282 (gdb-invalidate-memory)))))
2283
2284 (defun gdb-memory-format-binary ()
2285 "Set the display format to binary."
2286 (interactive)
2287 (customize-set-variable 'gdb-memory-format "t")
2288 (gdb-invalidate-memory))
2289
2290 (defun gdb-memory-format-octal ()
2291 "Set the display format to octal."
2292 (interactive)
2293 (customize-set-variable 'gdb-memory-format "o")
2294 (gdb-invalidate-memory))
2295
2296 (defun gdb-memory-format-unsigned ()
2297 "Set the display format to unsigned decimal."
2298 (interactive)
2299 (customize-set-variable 'gdb-memory-format "u")
2300 (gdb-invalidate-memory))
2301
2302 (defun gdb-memory-format-signed ()
2303 "Set the display format to decimal."
2304 (interactive)
2305 (customize-set-variable 'gdb-memory-format "d")
2306 (gdb-invalidate-memory))
2307
2308 (defun gdb-memory-format-hexadecimal ()
2309 "Set the display format to hexadecimal."
2310 (interactive)
2311 (customize-set-variable 'gdb-memory-format "x")
2312 (gdb-invalidate-memory))
2313
2314 (defvar gdb-memory-format-map
2315 (let ((map (make-sparse-keymap)))
2316 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2317 map)
2318 "Keymap to select format in the header line.")
2319
2320 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2321 "Menu of display formats in the header line.")
2322
2323 (define-key gdb-memory-format-menu [binary]
2324 '(menu-item "Binary" gdb-memory-format-binary
2325 :button (:radio . (equal gdb-memory-format "t"))))
2326 (define-key gdb-memory-format-menu [octal]
2327 '(menu-item "Octal" gdb-memory-format-octal
2328 :button (:radio . (equal gdb-memory-format "o"))))
2329 (define-key gdb-memory-format-menu [unsigned]
2330 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2331 :button (:radio . (equal gdb-memory-format "u"))))
2332 (define-key gdb-memory-format-menu [signed]
2333 '(menu-item "Signed Decimal" gdb-memory-format-signed
2334 :button (:radio . (equal gdb-memory-format "d"))))
2335 (define-key gdb-memory-format-menu [hexadecimal]
2336 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2337 :button (:radio . (equal gdb-memory-format "x"))))
2338
2339 (defun gdb-memory-format-menu (event)
2340 (interactive "@e")
2341 (x-popup-menu event gdb-memory-format-menu))
2342
2343 (defun gdb-memory-format-menu-1 (event)
2344 (interactive "e")
2345 (save-selected-window
2346 (select-window (posn-window (event-start event)))
2347 (let* ((selection (gdb-memory-format-menu event))
2348 (binding (and selection (lookup-key gdb-memory-format-menu
2349 (vector (car selection))))))
2350 (if binding (call-interactively binding)))))
2351
2352 (defun gdb-memory-unit-giant ()
2353 "Set the unit size to giant words (eight bytes)."
2354 (interactive)
2355 (customize-set-variable 'gdb-memory-unit "g")
2356 (gdb-invalidate-memory))
2357
2358 (defun gdb-memory-unit-word ()
2359 "Set the unit size to words (four bytes)."
2360 (interactive)
2361 (customize-set-variable 'gdb-memory-unit "w")
2362 (gdb-invalidate-memory))
2363
2364 (defun gdb-memory-unit-halfword ()
2365 "Set the unit size to halfwords (two bytes)."
2366 (interactive)
2367 (customize-set-variable 'gdb-memory-unit "h")
2368 (gdb-invalidate-memory))
2369
2370 (defun gdb-memory-unit-byte ()
2371 "Set the unit size to bytes."
2372 (interactive)
2373 (customize-set-variable 'gdb-memory-unit "b")
2374 (gdb-invalidate-memory))
2375
2376 (defvar gdb-memory-unit-map
2377 (let ((map (make-sparse-keymap)))
2378 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2379 map)
2380 "Keymap to select units in the header line.")
2381
2382 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2383 "Menu of units in the header line.")
2384
2385 (define-key gdb-memory-unit-menu [giantwords]
2386 '(menu-item "Giant words" gdb-memory-unit-giant
2387 :button (:radio . (equal gdb-memory-unit "g"))))
2388 (define-key gdb-memory-unit-menu [words]
2389 '(menu-item "Words" gdb-memory-unit-word
2390 :button (:radio . (equal gdb-memory-unit "w"))))
2391 (define-key gdb-memory-unit-menu [halfwords]
2392 '(menu-item "Halfwords" gdb-memory-unit-halfword
2393 :button (:radio . (equal gdb-memory-unit "h"))))
2394 (define-key gdb-memory-unit-menu [bytes]
2395 '(menu-item "Bytes" gdb-memory-unit-byte
2396 :button (:radio . (equal gdb-memory-unit "b"))))
2397
2398 (defun gdb-memory-unit-menu (event)
2399 (interactive "@e")
2400 (x-popup-menu event gdb-memory-unit-menu))
2401
2402 (defun gdb-memory-unit-menu-1 (event)
2403 (interactive "e")
2404 (save-selected-window
2405 (select-window (posn-window (event-start event)))
2406 (let* ((selection (gdb-memory-unit-menu event))
2407 (binding (and selection (lookup-key gdb-memory-unit-menu
2408 (vector (car selection))))))
2409 (if binding (call-interactively binding)))))
2410
2411 ;;from make-mode-line-mouse-map
2412 (defun gdb-make-header-line-mouse-map (mouse function) "\
2413 Return a keymap with single entry for mouse key MOUSE on the header line.
2414 MOUSE is defined to run function FUNCTION with no args in the buffer
2415 corresponding to the mode line clicked."
2416 (let ((map (make-sparse-keymap)))
2417 (define-key map (vector 'header-line mouse) function)
2418 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2419 map))
2420
2421 (defvar gdb-memory-font-lock-keywords
2422 '(;; <__function.name+n>
2423 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2424 )
2425 "Font lock keywords used in `gdb-memory-mode'.")
2426
2427 (defun gdb-memory-mode ()
2428 "Major mode for examining memory.
2429
2430 \\{gdb-memory-mode-map}"
2431 (kill-all-local-variables)
2432 (setq major-mode 'gdb-memory-mode)
2433 (setq mode-name "Memory")
2434 (setq buffer-read-only t)
2435 (use-local-map gdb-memory-mode-map)
2436 (setq header-line-format
2437 '(:eval
2438 (concat
2439 "Read address["
2440 (propertize
2441 "-"
2442 'face font-lock-warning-face
2443 'help-echo "mouse-1: Decrement address"
2444 'mouse-face 'mode-line-highlight
2445 'local-map
2446 (gdb-make-header-line-mouse-map
2447 'mouse-1
2448 #'(lambda () (interactive)
2449 (let ((gdb-memory-address
2450 ;; Let GDB do the arithmetic.
2451 (concat
2452 gdb-memory-address " - "
2453 (number-to-string
2454 (* gdb-memory-repeat-count
2455 (cond ((string= gdb-memory-unit "b") 1)
2456 ((string= gdb-memory-unit "h") 2)
2457 ((string= gdb-memory-unit "w") 4)
2458 ((string= gdb-memory-unit "g") 8)))))))
2459 (gdb-invalidate-memory)))))
2460 "|"
2461 (propertize "+"
2462 'face font-lock-warning-face
2463 'help-echo "mouse-1: Increment address"
2464 'mouse-face 'mode-line-highlight
2465 'local-map (gdb-make-header-line-mouse-map
2466 'mouse-1
2467 #'(lambda () (interactive)
2468 (let ((gdb-memory-address nil))
2469 (gdb-invalidate-memory)))))
2470 "]: "
2471 (propertize gdb-memory-address
2472 'face font-lock-warning-face
2473 'help-echo "mouse-1: Set memory address"
2474 'mouse-face 'mode-line-highlight
2475 'local-map (gdb-make-header-line-mouse-map
2476 'mouse-1
2477 #'gdb-memory-set-address))
2478 " Repeat Count: "
2479 (propertize (number-to-string gdb-memory-repeat-count)
2480 'face font-lock-warning-face
2481 'help-echo "mouse-1: Set repeat count"
2482 'mouse-face 'mode-line-highlight
2483 'local-map (gdb-make-header-line-mouse-map
2484 'mouse-1
2485 #'gdb-memory-set-repeat-count))
2486 " Display Format: "
2487 (propertize gdb-memory-format
2488 'face font-lock-warning-face
2489 'help-echo "mouse-3: Select display format"
2490 'mouse-face 'mode-line-highlight
2491 'local-map gdb-memory-format-map)
2492 " Unit Size: "
2493 (propertize gdb-memory-unit
2494 'face font-lock-warning-face
2495 'help-echo "mouse-3: Select unit size"
2496 'mouse-face 'mode-line-highlight
2497 'local-map gdb-memory-unit-map))))
2498 (set (make-local-variable 'font-lock-defaults)
2499 '(gdb-memory-font-lock-keywords))
2500 (run-mode-hooks 'gdb-memory-mode-hook)
2501 'gdb-invalidate-memory)
2502
2503 (defun gdb-memory-buffer-name ()
2504 (with-current-buffer gud-comint-buffer
2505 (concat "*memory of " (gdb-get-target-string) "*")))
2506
2507 (defun gdb-display-memory-buffer ()
2508 "Display memory contents."
2509 (interactive)
2510 (gdb-display-buffer
2511 (gdb-get-buffer-create 'gdb-memory-buffer)))
2512
2513 (defun gdb-frame-memory-buffer ()
2514 "Display memory contents in a new frame."
2515 (interactive)
2516 (let ((special-display-regexps (append special-display-regexps '(".*")))
2517 (special-display-frame-alist gdb-frame-parameters))
2518 (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
2519 \f
2520
2521 ;; Locals buffer.
2522 ;;
2523 (gdb-set-buffer-rules 'gdb-locals-buffer
2524 'gdb-locals-buffer-name
2525 'gdb-locals-mode)
2526
2527 (def-gdb-auto-update-trigger gdb-invalidate-locals
2528 (gdb-get-buffer 'gdb-locals-buffer)
2529 "server info locals\n"
2530 gdb-info-locals-handler)
2531
2532 (defvar gdb-locals-watch-map
2533 (let ((map (make-sparse-keymap)))
2534 (define-key map "\r" '(lambda () (interactive)
2535 (beginning-of-line)
2536 (gud-watch)))
2537 (define-key map [mouse-2] '(lambda (event) (interactive "e")
2538 (mouse-set-point event)
2539 (beginning-of-line)
2540 (gud-watch)))
2541 map)
2542 "Keymap to create watch expression of a complex data type local variable.")
2543
2544 (defconst gdb-struct-string
2545 (concat (propertize "[struct/union]"
2546 'mouse-face 'highlight
2547 'help-echo "mouse-2: create watch expression"
2548 'local-map gdb-locals-watch-map) "\n"))
2549
2550 (defconst gdb-array-string
2551 (concat " " (propertize "[array]"
2552 'mouse-face 'highlight
2553 'help-echo "mouse-2: create watch expression"
2554 'local-map gdb-locals-watch-map) "\n"))
2555
2556 ;; Abbreviate for arrays and structures.
2557 ;; These can be expanded using gud-display.
2558 (defun gdb-info-locals-handler ()
2559 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2560 gdb-pending-triggers))
2561 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2562 (with-current-buffer buf
2563 (goto-char (point-min))
2564 (while (re-search-forward "^[ }].*\n" nil t)
2565 (replace-match "" nil nil))
2566 (goto-char (point-min))
2567 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2568 (replace-match gdb-struct-string nil nil))
2569 (goto-char (point-min))
2570 (while (re-search-forward "\\s-*{.*\n" nil t)
2571 (replace-match gdb-array-string nil nil))))
2572 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2573 (and buf
2574 (with-current-buffer buf
2575 (let* ((window (get-buffer-window buf 0))
2576 (start (window-start window))
2577 (p (window-point window))
2578 (buffer-read-only nil))
2579 (erase-buffer)
2580 (insert-buffer-substring (gdb-get-buffer-create
2581 'gdb-partial-output-buffer))
2582 (set-window-start window start)
2583 (set-window-point window p))
2584 )))
2585 (run-hooks 'gdb-info-locals-hook))
2586
2587 (defvar gdb-locals-mode-map
2588 (let ((map (make-sparse-keymap)))
2589 (suppress-keymap map)
2590 (define-key map "q" 'kill-this-buffer)
2591 map))
2592
2593 (defun gdb-locals-mode ()
2594 "Major mode for gdb locals.
2595
2596 \\{gdb-locals-mode-map}"
2597 (kill-all-local-variables)
2598 (setq major-mode 'gdb-locals-mode)
2599 (setq mode-name (concat "Locals:" gdb-selected-frame))
2600 (setq buffer-read-only t)
2601 (use-local-map gdb-locals-mode-map)
2602 (set (make-local-variable 'font-lock-defaults)
2603 '(gdb-locals-font-lock-keywords))
2604 (run-mode-hooks 'gdb-locals-mode-hook)
2605 (if (and (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2606 (string-equal gdb-version "pre-6.4"))
2607 'gdb-invalidate-locals
2608 'gdb-invalidate-locals-1))
2609
2610 (defun gdb-locals-buffer-name ()
2611 (with-current-buffer gud-comint-buffer
2612 (concat "*locals of " (gdb-get-target-string) "*")))
2613
2614 (defun gdb-display-locals-buffer ()
2615 "Display local variables of current stack and their values."
2616 (interactive)
2617 (gdb-display-buffer
2618 (gdb-get-buffer-create 'gdb-locals-buffer)))
2619
2620 (defun gdb-frame-locals-buffer ()
2621 "Display local variables of current stack and their values in a new frame."
2622 (interactive)
2623 (let ((special-display-regexps (append special-display-regexps '(".*")))
2624 (special-display-frame-alist gdb-frame-parameters))
2625 (display-buffer (gdb-get-buffer-create 'gdb-locals-buffer))))
2626 \f
2627
2628 ;;;; Window management
2629 (defun gdb-display-buffer (buf &optional size)
2630 (let ((answer (get-buffer-window buf 0))
2631 (must-split nil))
2632 (if answer
2633 (display-buffer buf nil 0) ;Raise the frame if necessary.
2634 ;; The buffer is not yet displayed.
2635 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2636 (let ((window (get-lru-window)))
2637 (if (and window
2638 (not (eq window (get-buffer-window gud-comint-buffer))))
2639 (progn
2640 (set-window-buffer window buf)
2641 (setq answer window))
2642 (setq must-split t)))
2643 (if must-split
2644 (let* ((largest (get-largest-window))
2645 (cur-size (window-height largest))
2646 (new-size (and size (< size cur-size) (- cur-size size))))
2647 (setq answer (split-window largest new-size))
2648 (set-window-buffer answer buf)
2649 (set-window-dedicated-p answer t)))
2650 answer)))
2651
2652 \f
2653 ;;; Shared keymap initialization:
2654
2655 (let ((menu (make-sparse-keymap "GDB-Windows")))
2656 (define-key gud-menu-map [displays]
2657 `(menu-item "GDB-Windows" ,menu
2658 :visible (memq gud-minor-mode '(gdbmi gdba))))
2659 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2660 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2661 (define-key menu [inferior]
2662 '(menu-item "Inferior IO" gdb-display-separate-io-buffer
2663 :enable gdb-use-separate-io-buffer))
2664 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2665 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2666 (define-key menu [disassembly]
2667 '("Disassembly" . gdb-display-assembler-buffer))
2668 (define-key menu [breakpoints]
2669 '("Breakpoints" . gdb-display-breakpoints-buffer))
2670 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2671 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)))
2672
2673 (let ((menu (make-sparse-keymap "GDB-Frames")))
2674 (define-key gud-menu-map [frames]
2675 `(menu-item "GDB-Frames" ,menu
2676 :visible (memq gud-minor-mode '(gdbmi gdba))))
2677 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2678 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2679 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2680 (define-key menu [inferior]
2681 '(menu-item "Inferior IO" gdb-frame-separate-io-buffer
2682 :enable gdb-use-separate-io-buffer))
2683 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2684 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2685 (define-key menu [breakpoints]
2686 '("Breakpoints" . gdb-frame-breakpoints-buffer))
2687 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2688 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)))
2689
2690 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2691 (define-key gud-menu-map [ui]
2692 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2693 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2694 (define-key menu [gdb-use-separate-io]
2695 '(menu-item "Separate inferior IO" gdb-use-separate-io-buffer
2696 :visible (eq gud-minor-mode 'gdba)
2697 :help "Toggle separate IO for inferior."
2698 :button (:toggle . gdb-use-separate-io-buffer)))
2699 (define-key menu [gdb-many-windows]
2700 '(menu-item "Display Other Windows" gdb-many-windows
2701 :help "Toggle display of locals, stack and breakpoint information"
2702 :button (:toggle . gdb-many-windows)))
2703 (define-key menu [gdb-restore-windows]
2704 '(menu-item "Restore Window Layout" gdb-restore-windows
2705 :help "Restore standard layout for debug session.")))
2706
2707 (defun gdb-frame-gdb-buffer ()
2708 "Display GUD buffer in a new frame."
2709 (interactive)
2710 (let ((special-display-regexps (append special-display-regexps '(".*")))
2711 (special-display-frame-alist gdb-frame-parameters)
2712 (same-window-regexps nil))
2713 (display-buffer gud-comint-buffer)))
2714
2715 (defun gdb-display-gdb-buffer ()
2716 "Display GUD buffer."
2717 (interactive)
2718 (let ((same-window-regexps nil))
2719 (pop-to-buffer gud-comint-buffer)))
2720
2721 (defun gdb-set-window-buffer (name)
2722 (set-window-buffer (selected-window) (get-buffer name))
2723 (set-window-dedicated-p (selected-window) t))
2724
2725 (defun gdb-setup-windows ()
2726 "Layout the window pattern for `gdb-many-windows'."
2727 (gdb-display-locals-buffer)
2728 (gdb-display-stack-buffer)
2729 (delete-other-windows)
2730 (gdb-display-breakpoints-buffer)
2731 (delete-other-windows)
2732 ; Don't dedicate.
2733 (pop-to-buffer gud-comint-buffer)
2734 (split-window nil ( / ( * (window-height) 3) 4))
2735 (split-window nil ( / (window-height) 3))
2736 (split-window-horizontally)
2737 (other-window 1)
2738 (gdb-set-window-buffer (gdb-locals-buffer-name))
2739 (other-window 1)
2740 (switch-to-buffer
2741 (if gud-last-last-frame
2742 (gud-find-file (car gud-last-last-frame))
2743 (gud-find-file gdb-main-file)))
2744 (when gdb-use-separate-io-buffer
2745 (split-window-horizontally)
2746 (other-window 1)
2747 (gdb-set-window-buffer
2748 (gdb-get-buffer-create 'gdb-inferior-io)))
2749 (other-window 1)
2750 (gdb-set-window-buffer (gdb-stack-buffer-name))
2751 (split-window-horizontally)
2752 (other-window 1)
2753 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2754 (other-window 1))
2755
2756 (defun gdb-restore-windows ()
2757 "Restore the basic arrangement of windows used by gdba.
2758 This arrangement depends on the value of `gdb-many-windows'."
2759 (interactive)
2760 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2761 (delete-other-windows)
2762 (if gdb-many-windows
2763 (gdb-setup-windows)
2764 (when (or gud-last-last-frame gdb-show-main)
2765 (split-window)
2766 (other-window 1)
2767 (switch-to-buffer
2768 (if gud-last-last-frame
2769 (gud-find-file (car gud-last-last-frame))
2770 (gud-find-file gdb-main-file)))
2771 (other-window 1))))
2772
2773 (defun gdb-reset ()
2774 "Exit a debugging session cleanly.
2775 Kills the gdb buffers, and resets variables and the source buffers."
2776 (dolist (buffer (buffer-list))
2777 (unless (eq buffer gud-comint-buffer)
2778 (with-current-buffer buffer
2779 (if (memq gud-minor-mode '(gdbmi gdba))
2780 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2781 (kill-buffer nil)
2782 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2783 (setq gud-minor-mode nil)
2784 (kill-local-variable 'tool-bar-map)
2785 (kill-local-variable 'gdb-define-alist))))))
2786 (when (markerp gdb-overlay-arrow-position)
2787 (move-marker gdb-overlay-arrow-position nil)
2788 (setq gdb-overlay-arrow-position nil))
2789 (setq overlay-arrow-variable-list
2790 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2791 (setq fringe-indicator-alist '((overlay-arrow . right-triangle)))
2792 (if (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
2793 (speedbar-refresh))
2794 (setq gud-running nil)
2795 (setq gdb-active-process nil)
2796 (setq gdb-var-list nil)
2797 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2798
2799 (defun gdb-source-info ()
2800 "Find the source file where the program starts and displays it with related
2801 buffers."
2802 (goto-char (point-min))
2803 (if (and (search-forward "Located in " nil t)
2804 (looking-at "\\S-+"))
2805 (setq gdb-main-file (match-string 0)))
2806 (goto-char (point-min))
2807 (if (search-forward "Includes preprocessor macro info." nil t)
2808 (setq gdb-macro-info t))
2809 (if gdb-many-windows
2810 (gdb-setup-windows)
2811 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
2812 (if gdb-show-main
2813 (let ((pop-up-windows t))
2814 (display-buffer (gud-find-file gdb-main-file))))))
2815
2816 (defun gdb-get-location (bptno line flag)
2817 "Find the directory containing the relevant source file.
2818 Put in buffer and place breakpoint icon."
2819 (goto-char (point-min))
2820 (catch 'file-not-found
2821 (if (search-forward "Located in " nil t)
2822 (when (looking-at "\\S-+")
2823 (delete (cons bptno "File not found") gdb-location-alist)
2824 (push (cons bptno (match-string 0)) gdb-location-alist))
2825 (gdb-resync)
2826 (unless (assoc bptno gdb-location-alist)
2827 (push (cons bptno "File not found") gdb-location-alist)
2828 (message-box "Cannot find source file for breakpoint location.\n\
2829 Add directory to search path for source files using the GDB command, dir."))
2830 (throw 'file-not-found nil))
2831 (with-current-buffer
2832 (find-file-noselect (match-string 0))
2833 (save-current-buffer
2834 (set (make-local-variable 'gud-minor-mode) 'gdba)
2835 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2836 ;; only want one breakpoint icon at each location
2837 (save-excursion
2838 (goto-line (string-to-number line))
2839 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2840
2841 (add-hook 'find-file-hook 'gdb-find-file-hook)
2842
2843 (defun gdb-find-file-hook ()
2844 "Set up buffer for debugging if file is part of the source code
2845 of the current session."
2846 (if (and (buffer-name gud-comint-buffer)
2847 ;; in case gud or gdb-ui is just loaded
2848 gud-comint-buffer
2849 (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2850 '(gdba gdbmi)))
2851 (if (member buffer-file-name gdb-source-file-list)
2852 (with-current-buffer (find-buffer-visiting buffer-file-name)
2853 (set (make-local-variable 'gud-minor-mode)
2854 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
2855 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)))))
2856
2857 ;;from put-image
2858 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2859 "Put string PUTSTRING in front of POS in the current buffer.
2860 PUTSTRING is displayed by putting an overlay into the current buffer with a
2861 `before-string' string that has a `display' property whose value is
2862 PUTSTRING."
2863 (let ((string (make-string 1 ?x))
2864 (buffer (current-buffer)))
2865 (setq putstring (copy-sequence putstring))
2866 (let ((overlay (make-overlay pos pos buffer))
2867 (prop (or dprop
2868 (list (list 'margin 'left-margin) putstring))))
2869 (put-text-property 0 1 'display prop string)
2870 (if sprops
2871 (add-text-properties 0 1 sprops string))
2872 (overlay-put overlay 'put-break t)
2873 (overlay-put overlay 'before-string string))))
2874
2875 ;;from remove-images
2876 (defun gdb-remove-strings (start end &optional buffer)
2877 "Remove strings between START and END in BUFFER.
2878 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2879 BUFFER nil or omitted means use the current buffer."
2880 (unless buffer
2881 (setq buffer (current-buffer)))
2882 (dolist (overlay (overlays-in start end))
2883 (when (overlay-get overlay 'put-break)
2884 (delete-overlay overlay))))
2885
2886 (defun gdb-put-breakpoint-icon (enabled bptno)
2887 (let ((start (- (line-beginning-position) 1))
2888 (end (+ (line-end-position) 1))
2889 (putstring (if enabled "B" "b"))
2890 (source-window (get-buffer-window (current-buffer) 0)))
2891 (add-text-properties
2892 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2893 putstring)
2894 (if enabled
2895 (add-text-properties
2896 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2897 (add-text-properties
2898 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2899 (gdb-remove-breakpoint-icons start end)
2900 (if (display-images-p)
2901 (if (>= (or left-fringe-width
2902 (if source-window (car (window-fringes source-window)))
2903 gdb-buffer-fringe-width) 8)
2904 (gdb-put-string
2905 nil (1+ start)
2906 `(left-fringe breakpoint
2907 ,(if enabled
2908 'breakpoint-enabled
2909 'breakpoint-disabled))
2910 'gdb-bptno bptno
2911 'gdb-enabled enabled)
2912 (when (< left-margin-width 2)
2913 (save-current-buffer
2914 (setq left-margin-width 2)
2915 (if source-window
2916 (set-window-margins
2917 source-window
2918 left-margin-width right-margin-width))))
2919 (put-image
2920 (if enabled
2921 (or breakpoint-enabled-icon
2922 (setq breakpoint-enabled-icon
2923 (find-image `((:type xpm :data
2924 ,breakpoint-xpm-data
2925 :ascent 100 :pointer hand)
2926 (:type pbm :data
2927 ,breakpoint-enabled-pbm-data
2928 :ascent 100 :pointer hand)))))
2929 (or breakpoint-disabled-icon
2930 (setq breakpoint-disabled-icon
2931 (find-image `((:type xpm :data
2932 ,breakpoint-xpm-data
2933 :conversion disabled
2934 :ascent 100 :pointer hand)
2935 (:type pbm :data
2936 ,breakpoint-disabled-pbm-data
2937 :ascent 100 :pointer hand))))))
2938 (+ start 1)
2939 putstring
2940 'left-margin))
2941 (when (< left-margin-width 2)
2942 (save-current-buffer
2943 (setq left-margin-width 2)
2944 (let ((window (get-buffer-window (current-buffer) 0)))
2945 (if window
2946 (set-window-margins
2947 window left-margin-width right-margin-width)))))
2948 (gdb-put-string
2949 (propertize putstring
2950 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2951 (1+ start)))))
2952
2953 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2954 (gdb-remove-strings start end)
2955 (if (display-images-p)
2956 (remove-images start end))
2957 (when remove-margin
2958 (setq left-margin-width 0)
2959 (let ((window (get-buffer-window (current-buffer) 0)))
2960 (if window
2961 (set-window-margins
2962 window left-margin-width right-margin-width)))))
2963
2964 \f
2965 ;;
2966 ;; Assembler buffer.
2967 ;;
2968 (gdb-set-buffer-rules 'gdb-assembler-buffer
2969 'gdb-assembler-buffer-name
2970 'gdb-assembler-mode)
2971
2972 (def-gdb-auto-update-handler gdb-assembler-handler
2973 gdb-invalidate-assembler
2974 gdb-assembler-buffer
2975 gdb-assembler-custom)
2976
2977 (defun gdb-assembler-custom ()
2978 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2979 (pos 1) (address) (flag) (bptno))
2980 (with-current-buffer buffer
2981 (save-excursion
2982 (if (not (equal gdb-frame-address "main"))
2983 (progn
2984 (goto-char (point-min))
2985 (if (and gdb-frame-address
2986 (search-forward gdb-frame-address nil t))
2987 (progn
2988 (setq pos (point))
2989 (beginning-of-line)
2990 (or gdb-overlay-arrow-position
2991 (setq gdb-overlay-arrow-position (make-marker)))
2992 (set-marker gdb-overlay-arrow-position
2993 (point) (current-buffer))))))
2994 ;; remove all breakpoint-icons in assembler buffer before updating.
2995 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2996 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2997 (goto-char (point-min))
2998 (while (< (point) (- (point-max) 1))
2999 (forward-line 1)
3000 (if (looking-at "[^\t].*?breakpoint")
3001 (progn
3002 (looking-at
3003 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
3004 (setq bptno (match-string 1))
3005 (setq flag (char-after (match-beginning 2)))
3006 (setq address (match-string 3))
3007 (with-current-buffer buffer
3008 (save-excursion
3009 (goto-char (point-min))
3010 (if (search-forward address nil t)
3011 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
3012 (if (not (equal gdb-frame-address "main"))
3013 (with-current-buffer buffer
3014 (set-window-point (get-buffer-window buffer 0) pos)))))
3015
3016 (defvar gdb-assembler-mode-map
3017 (let ((map (make-sparse-keymap)))
3018 (suppress-keymap map)
3019 (define-key map "q" 'kill-this-buffer)
3020 map))
3021
3022 (defvar gdb-assembler-font-lock-keywords
3023 '(;; <__function.name+n>
3024 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
3025 (1 font-lock-function-name-face))
3026 ;; 0xNNNNNNNN <__function.name+n>: opcode
3027 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
3028 (4 font-lock-keyword-face))
3029 ;; %register(at least i386)
3030 ("%\\sw+" . font-lock-variable-name-face)
3031 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
3032 (1 font-lock-comment-face)
3033 (2 font-lock-function-name-face))
3034 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
3035 "Font lock keywords used in `gdb-assembler-mode'.")
3036
3037 (defun gdb-assembler-mode ()
3038 "Major mode for viewing code assembler.
3039
3040 \\{gdb-assembler-mode-map}"
3041 (kill-all-local-variables)
3042 (setq major-mode 'gdb-assembler-mode)
3043 (setq mode-name (concat "Machine:" gdb-selected-frame))
3044 (setq gdb-overlay-arrow-position nil)
3045 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
3046 (setq fringes-outside-margins t)
3047 (setq buffer-read-only t)
3048 (use-local-map gdb-assembler-mode-map)
3049 (gdb-invalidate-assembler)
3050 (set (make-local-variable 'font-lock-defaults)
3051 '(gdb-assembler-font-lock-keywords))
3052 (run-mode-hooks 'gdb-assembler-mode-hook)
3053 'gdb-invalidate-assembler)
3054
3055 (defun gdb-assembler-buffer-name ()
3056 (with-current-buffer gud-comint-buffer
3057 (concat "*disassembly of " (gdb-get-target-string) "*")))
3058
3059 (defun gdb-display-assembler-buffer ()
3060 "Display disassembly view."
3061 (interactive)
3062 (setq gdb-previous-frame nil)
3063 (gdb-display-buffer
3064 (gdb-get-buffer-create 'gdb-assembler-buffer)))
3065
3066 (defun gdb-frame-assembler-buffer ()
3067 "Display disassembly view in a new frame."
3068 (interactive)
3069 (setq gdb-previous-frame nil)
3070 (let ((special-display-regexps (append special-display-regexps '(".*")))
3071 (special-display-frame-alist gdb-frame-parameters))
3072 (display-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))))
3073
3074 ;; modified because if gdb-frame-address has changed value a new command
3075 ;; must be enqueued to update the buffer with the new output
3076 (defun gdb-invalidate-assembler (&optional ignored)
3077 (if (gdb-get-buffer 'gdb-assembler-buffer)
3078 (progn
3079 (unless (and gdb-selected-frame
3080 (string-equal gdb-selected-frame gdb-previous-frame))
3081 (if (or (not (member 'gdb-invalidate-assembler
3082 gdb-pending-triggers))
3083 (not (string-equal gdb-frame-address
3084 gdb-previous-frame-address)))
3085 (progn
3086 ;; take previous disassemble command, if any, off the queue
3087 (with-current-buffer gud-comint-buffer
3088 (let ((queue gdb-input-queue))
3089 (dolist (item queue)
3090 (if (equal (cdr item) '(gdb-assembler-handler))
3091 (setq gdb-input-queue
3092 (delete item gdb-input-queue))))))
3093 (gdb-enqueue-input
3094 (list
3095 (concat gdb-server-prefix "disassemble "
3096 (if (member gdb-frame-address '(nil "main")) nil "0x")
3097 gdb-frame-address "\n")
3098 'gdb-assembler-handler))
3099 (push 'gdb-invalidate-assembler gdb-pending-triggers)
3100 (setq gdb-previous-frame-address gdb-frame-address)
3101 (setq gdb-previous-frame gdb-selected-frame)))))))
3102
3103 (defun gdb-get-selected-frame ()
3104 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
3105 (progn
3106 (gdb-enqueue-input
3107 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
3108 (push 'gdb-get-selected-frame
3109 gdb-pending-triggers))))
3110
3111 (defun gdb-frame-handler ()
3112 (setq gdb-pending-triggers
3113 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3114 (goto-char (point-min))
3115 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
3116 (setq gdb-frame-number (match-string 1)))
3117 (if gud-overlay-arrow-position
3118 (let ((buffer (marker-buffer gud-overlay-arrow-position))
3119 (position (marker-position gud-overlay-arrow-position)))
3120 (when buffer
3121 (with-current-buffer buffer
3122 (setq fringe-indicator-alist
3123 (if (string-equal gdb-frame-number "0")
3124 nil
3125 '((overlay-arrow . hollow-right-triangle))))
3126 (setq gud-overlay-arrow-position (make-marker))
3127 (set-marker gud-overlay-arrow-position position)))))
3128 (goto-char (point-min))
3129 (if (re-search-forward
3130 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
3131 (progn
3132 (setq gdb-selected-frame (match-string 2))
3133 (if (gdb-get-buffer 'gdb-locals-buffer)
3134 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3135 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3136 (if (gdb-get-buffer 'gdb-assembler-buffer)
3137 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3138 (setq mode-name (concat "Machine:" gdb-selected-frame))))
3139 (setq gdb-frame-address (match-string 1))))
3140 (goto-char (point-min))
3141 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
3142 (setq gdb-current-language (match-string 1)))
3143 (gdb-invalidate-assembler))
3144
3145 \f
3146 ;; Code specific to GDB 6.4
3147 (defconst gdb-source-file-regexp-1 "fullname=\"\\(.*?\\)\"")
3148
3149 (defun gdb-set-gud-minor-mode-existing-buffers-1 ()
3150 "Create list of source files for current GDB session.
3151 If buffers already exist for any of these files, gud-minor-mode
3152 is set in them."
3153 (goto-char (point-min))
3154 (while (re-search-forward gdb-source-file-regexp-1 nil t)
3155 (push (match-string 1) gdb-source-file-list))
3156 (dolist (buffer (buffer-list))
3157 (with-current-buffer buffer
3158 (when (member buffer-file-name gdb-source-file-list)
3159 (set (make-local-variable 'gud-minor-mode)
3160 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
3161 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
3162 (when gud-tooltip-mode
3163 (make-local-variable 'gdb-define-alist)
3164 (gdb-create-define-alist)
3165 (add-hook 'after-save-hook 'gdb-create-define-alist nil t))))))
3166
3167 ; Uses "-var-list-children --all-values". Needs GDB 6.1 onwards.
3168 (defun gdb-var-list-children-1 (varnum)
3169 (gdb-enqueue-input
3170 (list
3171 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3172 (concat "server interpreter mi \"-var-list-children --all-values "
3173 varnum "\"\n")
3174 (concat "-var-list-children --all-values " varnum "\n"))
3175 `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
3176
3177 (defconst gdb-var-list-children-regexp-1
3178 "name=\"\\(.+?\\)\",exp=\"\\(.+?\\)\",numchild=\"\\(.+?\\)\",\
3179 value=\\(\".*?\"\\),type=\"\\(.+?\\)\"}")
3180
3181 (defun gdb-var-list-children-handler-1 (varnum)
3182 (goto-char (point-min))
3183 (let ((var-list nil))
3184 (catch 'child-already-watched
3185 (dolist (var gdb-var-list)
3186 (if (string-equal varnum (car var))
3187 (progn
3188 (push var var-list)
3189 (while (re-search-forward gdb-var-list-children-regexp-1 nil t)
3190 (let ((varchild (list (match-string 1)
3191 (match-string 2)
3192 (match-string 3)
3193 (match-string 5)
3194 (read (match-string 4))
3195 nil)))
3196 (if (assoc (car varchild) gdb-var-list)
3197 (throw 'child-already-watched nil))
3198 (push varchild var-list))))
3199 (push var var-list)))
3200 (setq gdb-var-list (nreverse var-list)))))
3201
3202 ; Uses "-var-update --all-values". Needs GDB 6.4 onwards.
3203 (defun gdb-var-update-1 ()
3204 (if (not (member 'gdb-var-update gdb-pending-triggers))
3205 (progn
3206 (gdb-enqueue-input
3207 (list
3208 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3209 "server interpreter mi \"-var-update --all-values *\"\n"
3210 "-var-update --all-values *\n")
3211 'gdb-var-update-handler-1))
3212 (push 'gdb-var-update gdb-pending-triggers))))
3213
3214 (defconst gdb-var-update-regexp-1
3215 "name=\"\\(.*?\\)\",\\(?:value=\\(\".*?\"\\),\\)?in_scope=\"\\(.*?\\)\"")
3216
3217 (defun gdb-var-update-handler-1 ()
3218 (dolist (var gdb-var-list)
3219 (setcar (nthcdr 5 var) nil))
3220 (goto-char (point-min))
3221 (while (re-search-forward gdb-var-update-regexp-1 nil t)
3222 (let* ((varnum (match-string 1))
3223 (var (assoc varnum gdb-var-list)))
3224 (when var
3225 (if (string-equal (match-string 3) "false")
3226 (setcar (nthcdr 5 var) 'out-of-scope)
3227 (setcar (nthcdr 5 var) 'changed)
3228 (setcar (nthcdr 4 var)
3229 (read (match-string 2)))))))
3230 (setq gdb-pending-triggers
3231 (delq 'gdb-var-update gdb-pending-triggers))
3232 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
3233 ;; dummy command to update speedbar at right time
3234 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-refresh))
3235 ;; keep gdb-pending-triggers non-nil till end
3236 (push 'gdb-speedbar-refresh gdb-pending-triggers)))
3237
3238 ;; Registers buffer.
3239 ;;
3240 (gdb-set-buffer-rules 'gdb-registers-buffer
3241 'gdb-registers-buffer-name
3242 'gdb-registers-mode)
3243
3244 (def-gdb-auto-update-trigger gdb-invalidate-registers-1
3245 (gdb-get-buffer 'gdb-registers-buffer)
3246 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3247 "server interpreter mi \"-data-list-register-values x\"\n"
3248 "-data-list-register-values x\n")
3249 gdb-data-list-register-values-handler)
3250
3251 (defconst gdb-data-list-register-values-regexp
3252 "number=\"\\(.*?\\)\",value=\"\\(.*?\\)\"")
3253
3254 (defun gdb-data-list-register-values-handler ()
3255 (setq gdb-pending-triggers (delq 'gdb-invalidate-registers-1
3256 gdb-pending-triggers))
3257 (goto-char (point-min))
3258 (if (re-search-forward gdb-error-regexp nil t)
3259 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3260 (let ((buffer-read-only nil))
3261 (erase-buffer)
3262 (insert (match-string 1))
3263 (goto-char (point-min))))
3264 (let ((register-list (reverse gdb-register-names))
3265 (register nil) (register-string nil) (register-values nil))
3266 (goto-char (point-min))
3267 (while (re-search-forward gdb-data-list-register-values-regexp nil t)
3268 (setq register (pop register-list))
3269 (setq register-string (concat register "\t" (match-string 2) "\n"))
3270 (if (member (match-string 1) gdb-changed-registers)
3271 (put-text-property 0 (length register-string)
3272 'face 'font-lock-warning-face
3273 register-string))
3274 (setq register-values
3275 (concat register-values register-string)))
3276 (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
3277 (with-current-buffer buf
3278 (let* ((window (get-buffer-window buf 0))
3279 (start (window-start window))
3280 (p (window-point window))
3281 (buffer-read-only nil))
3282 (erase-buffer)
3283 (insert register-values)
3284 (set-window-start window start)
3285 (set-window-point window p))))))
3286 (gdb-data-list-register-values-custom))
3287
3288 (defun gdb-data-list-register-values-custom ()
3289 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3290 (save-excursion
3291 (let ((buffer-read-only nil)
3292 start end)
3293 (goto-char (point-min))
3294 (while (< (point) (point-max))
3295 (setq start (line-beginning-position))
3296 (setq end (line-end-position))
3297 (when (looking-at "^[^\t]+")
3298 (unless (string-equal (match-string 0) "No registers.")
3299 (put-text-property start (match-end 0)
3300 'face font-lock-variable-name-face)
3301 (add-text-properties start end
3302 '(help-echo "mouse-2: edit value"
3303 mouse-face highlight))))
3304 (forward-line 1))))))
3305
3306 ;; Needs GDB 6.4 onwards (used to fail with no stack).
3307 (defun gdb-get-changed-registers ()
3308 (if (and (gdb-get-buffer 'gdb-registers-buffer)
3309 (not (member 'gdb-get-changed-registers gdb-pending-triggers)))
3310 (progn
3311 (gdb-enqueue-input
3312 (list
3313 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3314 "server interpreter mi -data-list-changed-registers\n"
3315 "-data-list-changed-registers\n")
3316 'gdb-get-changed-registers-handler))
3317 (push 'gdb-get-changed-registers gdb-pending-triggers))))
3318
3319 (defconst gdb-data-list-register-names-regexp "\"\\(.*?\\)\"")
3320
3321 (defun gdb-get-changed-registers-handler ()
3322 (setq gdb-pending-triggers
3323 (delq 'gdb-get-changed-registers gdb-pending-triggers))
3324 (setq gdb-changed-registers nil)
3325 (goto-char (point-min))
3326 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3327 (push (match-string 1) gdb-changed-registers)))
3328 \f
3329
3330 ;; Locals buffer.
3331 ;;
3332 ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards.
3333 (gdb-set-buffer-rules 'gdb-locals-buffer
3334 'gdb-locals-buffer-name
3335 'gdb-locals-mode)
3336
3337 (def-gdb-auto-update-trigger gdb-invalidate-locals-1
3338 (gdb-get-buffer 'gdb-locals-buffer)
3339 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3340 "server interpreter mi -\"stack-list-locals --simple-values\"\n"
3341 "-stack-list-locals --simple-values\n")
3342 gdb-stack-list-locals-handler)
3343
3344 (defconst gdb-stack-list-locals-regexp
3345 "name=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
3346
3347 (defvar gdb-locals-watch-map-1
3348 (let ((map (make-sparse-keymap)))
3349 (define-key map [mouse-2] 'gud-watch)
3350 map)
3351 "Keymap to create watch expression of a complex data type local variable.")
3352
3353 ;; Dont display values of arrays or structures.
3354 ;; These can be expanded using gud-watch.
3355 (defun gdb-stack-list-locals-handler ()
3356 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals-1
3357 gdb-pending-triggers))
3358 (let (local locals-list)
3359 (goto-char (point-min))
3360 (while (re-search-forward gdb-stack-list-locals-regexp nil t)
3361 (let ((local (list (match-string 1)
3362 (match-string 2)
3363 nil)))
3364 (if (looking-at ",value=\\(\".*\"\\)}")
3365 (setcar (nthcdr 2 local) (read (match-string 1))))
3366 (push local locals-list)))
3367 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
3368 (and buf (with-current-buffer buf
3369 (let* ((window (get-buffer-window buf 0))
3370 (start (window-start window))
3371 (p (window-point window))
3372 (buffer-read-only nil))
3373 (erase-buffer)
3374 (dolist (local locals-list)
3375 (setq name (car local))
3376 (if (or (not (nth 2 local))
3377 (string-match "\\0x" (nth 2 local)))
3378 (add-text-properties 0 (length name)
3379 `(mouse-face highlight
3380 help-echo "mouse-2: create watch expression"
3381 local-map ,gdb-locals-watch-map-1)
3382 name))
3383 (insert
3384 (concat name "\t" (nth 1 local)
3385 "\t" (nth 2 local) "\n")))
3386 (set-window-start window start)
3387 (set-window-point window p)))))))
3388
3389 (defun gdb-get-register-names ()
3390 "Create a list of register names."
3391 (goto-char (point-min))
3392 (setq gdb-register-names nil)
3393 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3394 (push (match-string 1) gdb-register-names)))
3395
3396 (provide 'gdb-ui)
3397
3398 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
3399 ;;; gdb-ui.el ends here