1 ;;; gdb-ui.el --- User Interface for running GDB
3 ;; Author: Nick Roberts <nickrob@gnu.org>
5 ;; Keywords: unix, tools
7 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006
8 ;; Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
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)
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.
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.
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).
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.
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.
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.
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.
58 ;;; Windows Platforms:
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
66 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
69 ;; and compiling with -DUNBUFFERED while debugging.
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!).
80 ;;; Problems with watch expressions, GDB/MI:
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 vairable object is not created (maybe trivial).
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.
99 (defvar speedbar-initial-expansion-list-name)
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 (EXPRESSION VARNUM 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)
129 (defvar gdb-buffer-type nil
130 "One of the symbols bound in `gdb-buffer-rules'.")
131 (make-variable-buffer-local 'gdb-buffer-type)
133 (defvar gdb-input-queue ()
134 "A list of gdb command objects.")
136 (defvar gdb-prompting nil
137 "True when gdb is idle with no pending input.")
139 (defvar gdb-output-sink 'user
140 "The disposition of the output of the current gdb command.
141 Possible values are these symbols:
143 `user' -- gdb output should be copied to the GUD buffer
146 `inferior' -- gdb output should be copied to the inferior-io buffer.
148 `pre-emacs' -- output should be ignored util the post-prompt
149 annotation is received. Then the output-sink
151 `emacs' -- output should be collected in the partial-output-buffer
152 for subsequent processing by a command. This is the
153 disposition of output generated by commands that
154 gdb mode sends to gdb on its own behalf.
155 `post-emacs' -- ignore output until the prompt annotation is
156 received, then go to USER disposition.
158 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
159 \(`user' and `emacs').")
161 (defvar gdb-current-item nil
162 "The most recent command item sent to gdb.")
164 (defvar gdb-pending-triggers '()
165 "A list of trigger functions that have run later than their output
168 (defvar gdb-first-post-prompt nil)
169 (defvar gdb-version nil)
170 (defvar gdb-locals-font-lock-keywords nil)
171 (defvar gdb-source-file-list nil
172 "List of source files for the current executable")
173 (defconst gdb-error-regexp "\\^error,msg=\"\\(.+\\)\"")
175 (defvar gdb-locals-font-lock-keywords-1
177 ;; var = (struct struct_tag) value
178 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
179 (1 font-lock-variable-name-face)
180 (3 font-lock-keyword-face)
181 (4 font-lock-type-face))
182 ;; var = (type) value
183 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
184 (1 font-lock-variable-name-face)
185 (3 font-lock-type-face))
187 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
188 (1 font-lock-variable-name-face))
190 "Font lock keywords used in `gdb-local-mode'.")
192 (defvar gdb-locals-font-lock-keywords-2
195 ( "\\(^\\(\\sw\\|[_.]\\)+\\)\t+\\(\\(\\sw\\|[_.]\\)+\\)"
196 (1 font-lock-variable-name-face)
197 (3 font-lock-type-face))
199 "Font lock keywords used in `gdb-local-mode'.")
201 ;; Variables for GDB 6.4+
202 (defvar gdb-register-names nil "List of register names.")
203 (defvar gdb-changed-registers nil
204 "List of changed register numbers (strings).")
207 (defun gdba (command-line)
208 "Run gdb on program FILE in buffer *gud-FILE*.
209 The directory containing FILE becomes the initial working directory
210 and source-file directory for your debugger.
212 If `gdb-many-windows' is nil (the default value) then gdb just
213 pops up the GUD buffer unless `gdb-show-main' is t. In this case
214 it starts with two windows: one displaying the GUD buffer and the
215 other with the source file with the main routine of the inferior.
217 If `gdb-many-windows' is t, regardless of the value of
218 `gdb-show-main', the layout below will appear unless
219 `gdb-use-separate-io-buffer' is nil when the source buffer
220 occupies the full width of the frame. Keybindings are shown in
223 Watch expressions appear in the speedbar/slowbar.
225 The following commands help control operation :
227 `gdb-many-windows' - Toggle the number of windows gdb uses.
228 `gdb-restore-windows' - To restore the window layout.
230 See Info node `(emacs)GDB Graphical Interface' for a more
231 detailed description of this mode.
234 +----------------------------------------------------------------------+
236 +-----------------------------------+----------------------------------+
237 | GUD buffer (I/O of GDB) | Locals buffer |
241 +-----------------------------------+----------------------------------+
242 | Source buffer | I/O buffer (of debugged program) |
250 +-----------------------------------+----------------------------------+
251 | Stack buffer | Breakpoints buffer |
252 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
253 | | RET gdb-goto-breakpoint |
254 | | D gdb-delete-breakpoint |
255 +-----------------------------------+----------------------------------+"
257 (interactive (list (gud-query-cmdline 'gdba)))
259 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
263 (defcustom gdb-debug-ring-max 128
264 "Maximum size of `gdb-debug-ring'."
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.")
274 (defcustom gdb-enable-debug nil
275 "Non-nil means record the process input and output in `gdb-debug-ring'."
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.
286 Set `gdb-cpp-define-alist-flags' for any include paths or
292 (defcustom gdb-cpp-define-alist-flags ""
293 "Preprocessor flags for `gdb-cpp-define-alist-program'."
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."
305 (defcustom gdb-use-separate-io-buffer nil
306 "Non-nil means display output from the inferior in a separate buffer."
311 (defun gdb-use-separate-io-buffer (arg)
312 "Toggle separate IO for inferior.
313 With arg, use separate IO iff arg is positive."
315 (setq gdb-use-separate-io-buffer
317 (not gdb-use-separate-io-buffer)
318 (> (prefix-numeric-value arg) 0)))
319 (message (format "Separate inferior IO %sabled"
320 (if gdb-use-separate-io-buffer "en" "dis")))
321 (if (and gud-comint-buffer
322 (buffer-name gud-comint-buffer))
324 (if gdb-use-separate-io-buffer
325 (gdb-restore-windows)
326 (kill-buffer (gdb-inferior-io-name)))
329 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
331 (defun gdb-create-define-alist ()
332 "Create an alist of #define directives for GUD tooltips."
333 (let* ((file (buffer-file-name))
335 (with-output-to-string
336 (with-current-buffer standard-output
337 (call-process shell-file-name
338 (if (file-exists-p file) file nil)
339 (list t nil) nil "-c"
340 (concat gdb-cpp-define-alist-program " "
341 gdb-cpp-define-alist-flags)))))
342 (define-list (split-string output "\n" t))
344 (setq gdb-define-alist nil)
345 (dolist (define define-list)
346 (setq name (nth 1 (split-string define "[( ]")))
347 (push (cons name define) gdb-define-alist))))
349 (defun gdb-tooltip-print (expr)
351 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
352 (goto-char (point-min))
354 (if (search-forward "=" nil t)
355 (concat expr (buffer-substring (- (point) 2) (point-max)))
357 ;; remove newline for gud-tooltip-echo-area
358 (substring string 0 (- (length string) 1))))
359 (or gud-tooltip-echo-area tooltip-use-echo-area)))
361 ;; If expr is a macro for a function don't print because of possible dangerous
362 ;; side-effects. Also printing a function within a tooltip generates an
363 ;; unexpected starting annotation (phase error).
364 (defun gdb-tooltip-print-1 (expr)
365 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
366 (goto-char (point-min))
367 (if (search-forward "expands to: " nil t)
368 (unless (looking-at "\\S-+.*(.*).*")
370 (list (concat gdb-server-prefix "print " expr "\n")
371 `(lambda () (gdb-tooltip-print ,expr))))))))
373 (defconst gdb-source-file-regexp "\\(.+?\\), \\|\\([^, \n].*$\\)")
375 (defun gdb-set-gud-minor-mode-existing-buffers ()
376 "Create list of source files for current GDB session."
377 (goto-char (point-min))
378 (when (search-forward "read in on demand:" nil t)
379 (while (re-search-forward gdb-source-file-regexp nil t)
380 (push (or (match-string 1) (match-string 2)) gdb-source-file-list))
381 (dolist (buffer (buffer-list))
382 (with-current-buffer buffer
383 (when (and buffer-file-name
384 (member (file-name-nondirectory buffer-file-name)
385 gdb-source-file-list))
386 (set (make-local-variable 'gud-minor-mode) 'gdba)
387 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
388 (when gud-tooltip-mode
389 (make-local-variable 'gdb-define-alist)
390 (gdb-create-define-alist)
391 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))))
393 (defun gdb-find-watch-expression ()
394 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
395 (varno (nth 1 var)) (expr))
396 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varno)
397 (dolist (var1 gdb-var-list)
398 (if (string-equal (nth 1 var1) (match-string 1 varno))
399 (setq expr (concat (car var1) "." (match-string 2 varno)))))
403 (set (make-local-variable 'gud-minor-mode) 'gdba)
404 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
406 (gud-def gud-break (if (not (string-match "Machine" mode-name))
407 (gud-call "break %f:%l" arg)
411 (gud-call "break *%a" arg)))
412 "\C-b" "Set breakpoint at current line or address.")
414 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
415 (gud-call "clear %f:%l" arg)
419 (gud-call "clear *%a" arg)))
420 "\C-d" "Remove breakpoint at current line or address.")
422 (gud-def gud-until (if (not (string-match "Machine" mode-name))
423 (gud-call "until %f:%l" arg)
427 (gud-call "until *%a" arg)))
428 "\C-u" "Continue to current line or address.")
430 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
431 nil "Start or continue execution.")
433 ;; For debugging Emacs only.
437 "pp1 " (if (eq (buffer-local-value
438 'major-mode (window-buffer)) 'speedbar-mode)
439 (gdb-find-watch-expression) "%e")) arg)
440 nil "Print the emacs s-expression.")
442 (define-key gud-minor-mode-map [left-margin mouse-1]
443 'gdb-mouse-set-clear-breakpoint)
444 (define-key gud-minor-mode-map [left-fringe mouse-1]
445 'gdb-mouse-set-clear-breakpoint)
446 (define-key gud-minor-mode-map [left-fringe mouse-2]
448 (define-key gud-minor-mode-map [left-margin drag-mouse-1]
450 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
452 (define-key gud-minor-mode-map [left-margin mouse-2]
454 (define-key gud-minor-mode-map [left-margin C-drag-mouse-1]
456 (define-key gud-minor-mode-map [left-fringe C-drag-mouse-1]
458 (define-key gud-minor-mode-map [left-fringe C-mouse-2]
460 (define-key gud-minor-mode-map [left-margin C-mouse-2]
462 (define-key gud-minor-mode-map [left-margin mouse-3]
463 'gdb-mouse-toggle-breakpoint-margin)
464 (define-key gud-minor-mode-map [left-fringe mouse-3]
465 'gdb-mouse-toggle-breakpoint-fringe)
467 (setq comint-input-sender 'gdb-send)
470 (setq gdb-frame-address (if gdb-show-main "main" nil))
471 (setq gdb-previous-frame-address nil
472 gdb-memory-address "main"
473 gdb-previous-frame nil
474 gdb-selected-frame nil
475 gdb-current-language nil
479 gdb-first-post-prompt t
483 gdb-pending-triggers nil
484 gdb-output-sink 'user
485 gdb-server-prefix "server "
486 gdb-flush-pending-output nil
487 gdb-location-alist nil
488 gdb-source-file-list nil
491 gdb-buffer-fringe-width (car (window-fringes))
494 gdb-source-window nil)
496 (setq gdb-buffer-type 'gdba)
498 (if gdb-use-separate-io-buffer (gdb-clear-inferior-io))
500 ;; Hack to see test for GDB 6.4+ (-stack-info-frame was implemented in 6.4)
501 (gdb-enqueue-input (list "server interpreter mi -stack-info-frame\n"
505 (if (eq window-system 'w32)
506 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
507 (gdb-enqueue-input (list "set height 0\n" 'ignore))
508 (gdb-enqueue-input (list "set width 0\n" 'ignore))
510 (if (string-equal gdb-version "pre-6.4")
512 (gdb-enqueue-input (list (concat gdb-server-prefix "info sources\n")
513 'gdb-set-gud-minor-mode-existing-buffers))
514 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-1))
516 (list "server interpreter mi -data-list-register-names\n"
517 'gdb-get-register-names))
518 ; Needs GDB 6.2 onwards.
520 (list "server interpreter mi \"-file-list-exec-source-files\"\n"
521 'gdb-set-gud-minor-mode-existing-buffers-1))
522 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-2))
524 ;; find source file and compilation directory here
525 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
526 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
527 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
529 (run-hooks 'gdba-mode-hook))
531 (defun gdb-get-version ()
532 (goto-char (point-min))
533 (if (and (re-search-forward gdb-error-regexp nil t)
534 (string-match ".*(missing implementation)" (match-string 1)))
535 (setq gdb-version "pre-6.4")
536 (setq gdb-version "6.4+"))
539 (defun gdb-mouse-until (event)
540 "Continue running until a source line past the current line.
541 The destination source line can be selected either by clicking with mouse-2
542 on the fringe/margin or dragging the arrow with mouse-1 (default bindings)."
544 (if gud-overlay-arrow-position
545 (let ((start (event-start event))
546 (end (event-end event))
547 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
548 (if (not (string-match "Machine" mode-name))
549 (if (equal buffer (window-buffer (posn-window end)))
550 (with-current-buffer buffer
551 (when (or (equal start end)
552 (equal (posn-point start)
554 gud-overlay-arrow-position)))
555 (setq line (line-number-at-pos (posn-point end)))
556 (gud-call (concat "until " (number-to-string line))))))
557 (if (equal (marker-buffer gdb-overlay-arrow-position)
558 (window-buffer (posn-window end)))
559 (when (or (equal start end)
560 (equal (posn-point start)
562 gdb-overlay-arrow-position)))
564 (goto-line (line-number-at-pos (posn-point end)))
566 (gud-call (concat "until *%a")))))))))
568 (defun gdb-mouse-jump (event)
569 "Set execution address/line.
570 The destination source line can be selected either by clicking with mouse-2
571 on the fringe/margin or dragging the arrow with mouse-1 (default bindings).
572 Unlike gdb-mouse-until the destination address can be before the current
573 line, and no execution takes place."
575 (if gud-overlay-arrow-position
576 (let ((start (event-start event))
577 (end (event-end event))
578 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
579 (if (not (string-match "Machine" mode-name))
580 (if (equal buffer (window-buffer (posn-window end)))
581 (with-current-buffer buffer
582 (when (or (equal start end)
583 (equal (posn-point start)
585 gud-overlay-arrow-position)))
586 (setq line (line-number-at-pos (posn-point end)))
587 (progn (gud-call (concat "tbreak " (number-to-string line)))
588 (gud-call (concat "jump " (number-to-string line)))))))
589 (if (equal (marker-buffer gdb-overlay-arrow-position)
590 (window-buffer (posn-window end)))
591 (when (or (equal start end)
592 (equal (posn-point start)
594 gdb-overlay-arrow-position)))
596 (goto-line (line-number-at-pos (posn-point end)))
599 (gud-call (concat "tbreak *%a"))
600 (gud-call (concat "jump *%a"))))))))))
602 (defcustom gdb-speedbar-auto-raise nil
603 "If non-nil raise speedbar every time display of watch expressions is\
609 (defun gdb-speedbar-auto-raise (arg)
610 "Toggle automatic raising of the speedbar for watch expressions.
611 With arg, automatically raise speedbar iff arg is positive."
613 (setq gdb-speedbar-auto-raise
615 (not gdb-speedbar-auto-raise)
616 (> (prefix-numeric-value arg) 0)))
617 (message (format "Auto raising %sabled"
618 (if gdb-speedbar-auto-raise "en" "dis"))))
620 (defcustom gdb-use-colon-colon-notation nil
621 "If non-nil use FUN::VAR format to display variables in the speedbar."
626 (defun gud-watch (&optional event)
627 "Watch expression at point."
628 (interactive (list last-input-event))
629 (if event (posn-set-point (event-end event)))
631 (save-selected-window
632 (let ((expr (tooltip-identifier-from-point (point))))
633 (catch 'already-watched
634 (dolist (var gdb-var-list)
635 (if (string-equal expr (car var)) (throw 'already-watched nil)))
636 (set-text-properties 0 (length expr) nil expr)
639 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
640 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
641 (concat"-var-create - * " expr "\n"))
642 `(lambda () (gdb-var-create-handler ,expr))))))))
644 (defconst gdb-var-create-regexp
645 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
647 (defun gdb-var-create-handler (expr)
648 (goto-char (point-min))
649 (if (re-search-forward gdb-var-create-regexp nil t)
651 (if (and (string-equal gdb-current-language "c")
652 gdb-use-colon-colon-notation gdb-selected-frame)
653 (setq expr (concat gdb-selected-frame "::" expr))
659 (push var gdb-var-list)
661 (unless (string-equal
662 speedbar-initial-expansion-list-name "GUD")
663 (speedbar-change-initial-expansion-list "GUD"))
666 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
667 (concat "server interpreter mi \"-var-evaluate-expression "
669 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
670 `(lambda () (gdb-var-evaluate-expression-handler
671 ,(nth 1 var) nil)))))
672 (if (search-forward "Undefined command" nil t)
673 (message-box "Watching expressions requires gdb 6.0 onwards")
674 (message-box "No symbol \"%s\" in current context." expr))))
676 (defun gdb-var-evaluate-expression-handler (varnum changed)
677 (goto-char (point-min))
678 (re-search-forward ".*value=\\(\".*\"\\)" nil t)
680 (dolist (var gdb-var-list)
681 (when (string-equal varnum (cadr var))
682 (if changed (setcar (nthcdr 5 var) 'changed))
683 (setcar (nthcdr 4 var) (read (match-string 1)))
684 (throw 'var-found nil)))))
686 (defun gdb-var-list-children (varnum)
688 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
689 `(lambda () (gdb-var-list-children-handler ,varnum)))))
691 (defconst gdb-var-list-children-regexp
692 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",\
695 (defun gdb-var-list-children-handler (varnum)
696 (goto-char (point-min))
697 (let ((var-list nil))
698 (catch 'child-already-watched
699 (dolist (var gdb-var-list)
700 (if (string-equal varnum (cadr var))
703 (while (re-search-forward gdb-var-list-children-regexp nil t)
704 (let ((varchild (list (match-string 2)
709 (dolist (var1 gdb-var-list)
710 (if (string-equal (cadr var1) (cadr varchild))
711 (throw 'child-already-watched nil)))
712 (push varchild var-list)
716 "server interpreter mi \"-var-evaluate-expression "
717 (nth 1 varchild) "\"\n")
718 `(lambda () (gdb-var-evaluate-expression-handler
719 ,(nth 1 varchild) nil)))))))
720 (push var var-list)))
721 (setq gdb-var-list (nreverse var-list)))))
723 (defun gdb-var-update ()
724 (when (not (member 'gdb-var-update gdb-pending-triggers))
726 (list "server interpreter mi \"-var-update *\"\n"
727 'gdb-var-update-handler))
728 (push 'gdb-var-update gdb-pending-triggers)))
730 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\",in_scope=\"\\(.*?\\)\"")
732 (defun gdb-var-update-handler ()
733 (dolist (var gdb-var-list)
734 (setcar (nthcdr 5 var) nil))
735 (goto-char (point-min))
736 (while (re-search-forward gdb-var-update-regexp nil t)
737 (let ((varnum (match-string 1)))
738 (if (string-equal (match-string 2) "false")
740 (dolist (var gdb-var-list)
741 (when (string-equal varnum (cadr var))
742 (setcar (nthcdr 5 var) 'out-of-scope)
743 (throw 'var-found nil))))
746 (concat "server interpreter mi \"-var-evaluate-expression "
748 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
749 (setq gdb-pending-triggers
750 (delq 'gdb-var-update gdb-pending-triggers))
751 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
752 ;; Dummy command to update speedbar at right time.
753 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-refresh))
754 ;; Keep gdb-pending-triggers non-nil till end.
755 (push 'gdb-speedbar-refresh gdb-pending-triggers)))
757 (defun gdb-speedbar-refresh ()
758 (setq gdb-pending-triggers
759 (delq 'gdb-speedbar-refresh gdb-pending-triggers))
760 (with-current-buffer gud-comint-buffer
761 (let ((speedbar-verbosity-level 0))
763 (speedbar-refresh)))))
765 (defun gdb-var-delete ()
766 "Delete watch expression at point from the speedbar."
768 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
770 (let ((text (speedbar-line-text)))
771 (string-match "\\(\\S-+\\)" text)
772 (let* ((expr (match-string 1 text))
773 (var (assoc expr gdb-var-list))
775 (unless (string-match "\\." varnum)
778 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
780 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
781 (concat "-var-delete " varnum "\n"))
783 (setq gdb-var-list (delq var gdb-var-list))
784 (dolist (varchild gdb-var-list)
785 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
786 (setq gdb-var-list (delq varchild gdb-var-list)))))))))
788 (defun gdb-edit-value (text token indent)
789 "Assign a value to a variable displayed in the speedbar."
790 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
791 (varnum (cadr var)) (value))
792 (setq value (read-string "New value: "))
795 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
796 (concat "server interpreter mi \"-var-assign "
797 varnum " " value "\"\n")
798 (concat "-var-assign " varnum " " value "\n"))
801 (defcustom gdb-show-changed-values t
802 "If non-nil change the face of out of scope variables and changed values.
803 Out of scope variables are suppressed with `shadow' face.
804 Changed values are highlighted with the face `font-lock-warning-face'."
809 (defun gdb-speedbar-expand-node (text token indent)
810 "Expand the node the user clicked on.
811 TEXT is the text of the button we clicked on, a + or - item.
812 TOKEN is data related to this node.
813 INDENT is the current indentation depth."
814 (cond ((string-match "+" text) ;expand this node
816 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
817 (string-equal gdb-version "pre-6.4"))
818 (gdb-var-list-children token)
819 (gdb-var-list-children-1 token)))
820 ((string-match "-" text) ;contract this node
821 (dolist (var gdb-var-list)
822 (if (string-match (concat token "\\.") (nth 1 var))
823 (setq gdb-var-list (delq var gdb-var-list))))
824 (speedbar-change-expand-button-char ?+)
825 (speedbar-delete-subblock indent))
826 (t (error "Ooops... not sure what to do")))
827 (speedbar-center-buffer-smartly))
829 (defun gdb-get-target-string ()
830 (with-current-buffer gud-comint-buffer
837 ;; Each buffer has a TYPE -- a symbol that identifies the function
838 ;; of that particular buffer.
840 ;; The usual gdb interaction buffer is given the type `gdba' and
841 ;; is constructed specially.
843 ;; Others are constructed by gdb-get-buffer-create and
844 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
846 (defvar gdb-buffer-rules-assoc '())
848 (defun gdb-get-buffer (key)
849 "Return the gdb buffer tagged with type KEY.
850 The key should be one of the cars in `gdb-buffer-rules-assoc'."
852 (gdb-look-for-tagged-buffer key (buffer-list))))
854 (defun gdb-get-buffer-create (key)
855 "Create a new gdb buffer of the type specified by KEY.
856 The key should be one of the cars in `gdb-buffer-rules-assoc'."
857 (or (gdb-get-buffer key)
858 (let* ((rules (assoc key gdb-buffer-rules-assoc))
859 (name (funcall (gdb-rules-name-maker rules)))
860 (new (get-buffer-create name)))
861 (with-current-buffer new
863 (if (cdr (cdr rules))
864 (setq trigger (funcall (car (cdr (cdr rules))))))
865 (setq gdb-buffer-type key)
866 (set (make-local-variable 'gud-minor-mode)
867 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
868 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
869 (if trigger (funcall trigger)))
872 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
874 (defun gdb-look-for-tagged-buffer (key bufs)
876 (while (and (not retval) bufs)
877 (set-buffer (car bufs))
878 (if (eq gdb-buffer-type key)
879 (setq retval (car bufs)))
880 (setq bufs (cdr bufs)))
884 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
885 ;; at least one and possible more functions. The functions have these
886 ;; roles in defining a buffer type:
888 ;; NAME - Return a name for this buffer type.
890 ;; The remaining function(s) are optional:
892 ;; MODE - called in a new buffer with no arguments, should establish
893 ;; the proper mode for the buffer.
896 (defun gdb-set-buffer-rules (buffer-type &rest rules)
897 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
899 (setcdr binding rules)
900 (push (cons buffer-type rules)
901 gdb-buffer-rules-assoc))))
903 ;; GUD buffers are an exception to the rules
904 (gdb-set-buffer-rules 'gdba 'error)
906 ;; Partial-output buffer : This accumulates output from a command executed on
907 ;; behalf of emacs (rather than the user).
909 (gdb-set-buffer-rules 'gdb-partial-output-buffer
910 'gdb-partial-output-name)
912 (defun gdb-partial-output-name ()
913 (concat "*partial-output-"
914 (gdb-get-target-string)
918 (gdb-set-buffer-rules 'gdb-inferior-io
919 'gdb-inferior-io-name
920 'gdb-inferior-io-mode)
922 (defun gdb-inferior-io-name ()
923 (concat "*input/output of "
924 (gdb-get-target-string)
927 (defun gdb-display-separate-io-buffer ()
928 "Display IO of debugged program in a separate window."
930 (if gdb-use-separate-io-buffer
932 (gdb-get-buffer-create 'gdb-inferior-io))))
934 (defconst gdb-frame-parameters
935 '((height . 14) (width . 80)
937 (tool-bar-lines . nil)
938 (menu-bar-lines . nil)
941 (defun gdb-frame-separate-io-buffer ()
942 "Display IO of inferior in a new frame."
944 (if gdb-use-separate-io-buffer
945 (let ((special-display-regexps (append special-display-regexps '(".*")))
946 (special-display-frame-alist gdb-frame-parameters))
947 (display-buffer (gdb-get-buffer-create 'gdb-inferior-io)))))
949 (defvar gdb-inferior-io-mode-map
950 (let ((map (make-sparse-keymap)))
951 (define-key map "\C-c\C-c" 'gdb-separate-io-interrupt)
952 (define-key map "\C-c\C-z" 'gdb-separate-io-stop)
953 (define-key map "\C-c\C-\\" 'gdb-separate-io-quit)
954 (define-key map "\C-c\C-d" 'gdb-separate-io-eof)
955 (define-key map "\C-d" 'gdb-separate-io-eof)
958 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
959 "Major mode for gdb inferior-io."
960 :syntax-table nil :abbrev-table nil
961 ;; We want to use comint because it has various nifty and familiar
962 ;; features. We don't need a process, but comint wants one, so create
964 (make-comint-in-buffer
965 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
966 (current-buffer) "hexl")
967 (setq comint-input-sender 'gdb-inferior-io-sender))
969 (defun gdb-inferior-io-sender (proc string)
970 ;; PROC is the pseudo-process created to satisfy comint.
971 (with-current-buffer (process-buffer proc)
972 (setq proc (get-buffer-process gud-comint-buffer))
973 (process-send-string proc string)
974 (process-send-string proc "\n")))
976 (defun gdb-separate-io-interrupt ()
977 "Interrupt the program being debugged."
980 (get-buffer-process gud-comint-buffer) comint-ptyp))
982 (defun gdb-separate-io-quit ()
983 "Send quit signal to the program being debugged."
986 (get-buffer-process gud-comint-buffer) comint-ptyp))
988 (defun gdb-separate-io-stop ()
989 "Stop the program being debugged."
992 (get-buffer-process gud-comint-buffer) comint-ptyp))
994 (defun gdb-separate-io-eof ()
995 "Send end-of-file to the program being debugged."
998 (get-buffer-process gud-comint-buffer)))
1001 ;; gdb communications
1004 ;; INPUT: things sent to gdb
1006 ;; The queues are lists. Each element is either a string (indicating user or
1007 ;; user-like input) or a list of the form:
1009 ;; (INPUT-STRING HANDLER-FN)
1011 ;; The handler function will be called from the partial-output buffer when the
1012 ;; command completes. This is the way to write commands which invoke gdb
1013 ;; commands autonomously.
1015 ;; These lists are consumed tail first.
1018 (defun gdb-send (proc string)
1019 "A comint send filter for gdb.
1020 This filter may simply queue input for a later time."
1021 (with-current-buffer gud-comint-buffer
1022 (let ((inhibit-read-only t))
1023 (remove-text-properties (point-min) (point-max) '(face))))
1024 (let ((item (concat string "\n")))
1027 (if gdb-enable-debug (push (cons 'send item) gdb-debug-ring))
1028 (process-send-string proc item))
1029 (gdb-enqueue-input item))))
1031 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
1032 ;; is a query, or other non-top-level prompt.
1034 (defun gdb-enqueue-input (item)
1037 (gdb-send-item item)
1038 (setq gdb-prompting nil))
1039 (push item gdb-input-queue)))
1041 (defun gdb-dequeue-input ()
1042 (let ((queue gdb-input-queue))
1044 (let ((last (car (last queue))))
1045 (unless (nbutlast queue) (setq gdb-input-queue '()))
1048 (defun gdb-send-item (item)
1049 (setq gdb-flush-pending-output nil)
1050 (if gdb-enable-debug (push (cons 'send-item item) gdb-debug-ring))
1051 (setq gdb-current-item item)
1052 (let ((process (get-buffer-process gud-comint-buffer)))
1053 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1056 (setq gdb-output-sink 'user)
1057 (process-send-string process item))
1059 (gdb-clear-partial-output)
1060 (setq gdb-output-sink 'pre-emacs)
1061 (process-send-string process
1063 ;; case: eq gud-minor-mode 'gdbmi
1064 (gdb-clear-partial-output)
1065 (setq gdb-output-sink 'emacs)
1066 (process-send-string process (car item)))))
1069 ;; output -- things gdb prints to emacs
1071 ;; GDB output is a stream interrupted by annotations.
1072 ;; Annotations can be recognized by their beginning
1073 ;; with \C-j\C-z\C-z<tag><opt>\C-j
1075 ;; The tag is a string obeying symbol syntax.
1077 ;; The optional part `<opt>' can be either the empty string
1078 ;; or a space followed by more data relating to the annotation.
1079 ;; For example, the SOURCE annotation is followed by a filename,
1080 ;; line number and various useless goo. This data must not include
1084 (defcustom gud-gdba-command-name "gdb -annotate=3"
1085 "Default command to execute an executable under the GDB-UI debugger."
1090 (defvar gdb-annotation-rules
1091 '(("pre-prompt" gdb-pre-prompt)
1092 ("prompt" gdb-prompt)
1093 ("commands" gdb-subprompt)
1094 ("overload-choice" gdb-subprompt)
1095 ("query" gdb-subprompt)
1096 ;; Need this prompt for GDB 6.1
1097 ("nquery" gdb-subprompt)
1098 ("prompt-for-continue" gdb-subprompt)
1099 ("post-prompt" gdb-post-prompt)
1100 ("source" gdb-source)
1101 ("starting" gdb-starting)
1102 ("exited" gdb-exited)
1103 ("signalled" gdb-signalled)
1104 ("signal" gdb-stopping)
1105 ("breakpoint" gdb-stopping)
1106 ("watchpoint" gdb-stopping)
1107 ("frame-begin" gdb-frame-begin)
1108 ("stopped" gdb-stopped)
1109 ("error-begin" gdb-error)
1111 ) "An assoc mapping annotation tags to functions which process them.")
1114 (setq gdb-flush-pending-output t)
1115 (setq gud-running nil)
1116 (setq gdb-output-sink 'user)
1117 (setq gdb-input-queue nil)
1118 (setq gdb-pending-triggers nil)
1119 (setq gdb-prompting t))
1121 (defconst gdb-source-spec-regexp
1122 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
1124 ;; Do not use this except as an annotation handler.
1125 (defun gdb-source (args)
1126 (string-match gdb-source-spec-regexp args)
1127 ;; Extract the frame position from the marker.
1128 (setq gud-last-frame
1130 (match-string 1 args)
1131 (string-to-number (match-string 2 args))))
1132 (setq gdb-frame-address (match-string 3 args))
1133 ;; cover for auto-display output which comes *before*
1134 ;; stopped annotation
1135 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1137 (defun gdb-pre-prompt (ignored)
1138 "An annotation handler for `pre-prompt'.
1139 This terminates the collection of output from a previous command if that
1140 happens to be in effect."
1141 (setq gdb-error nil)
1142 (let ((sink gdb-output-sink))
1146 (setq gdb-output-sink 'post-emacs))
1149 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1151 (defun gdb-prompt (ignored)
1152 "An annotation handler for `prompt'.
1153 This sends the next command (if any) to gdb."
1154 (when gdb-first-prompt
1156 (setq gdb-first-prompt nil))
1157 (let ((sink gdb-output-sink))
1160 ((eq sink 'post-emacs)
1161 (setq gdb-output-sink 'user)
1163 (car (cdr gdb-current-item))))
1164 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1165 (funcall handler))))
1168 (error "Phase error in gdb-prompt (got %s)" sink))))
1169 (let ((input (gdb-dequeue-input)))
1171 (gdb-send-item input)
1173 (setq gdb-prompting t)
1174 (gud-display-frame)))))
1176 (defun gdb-subprompt (ignored)
1177 "An annotation handler for non-top-level prompts."
1178 (setq gdb-prompting t))
1180 (defun gdb-starting (ignored)
1181 "An annotation handler for `starting'.
1182 This says that I/O for the subprocess is now the program being debugged,
1184 (setq gdb-active-process t)
1185 (let ((sink gdb-output-sink))
1189 (setq gud-running t)
1190 (if gdb-use-separate-io-buffer
1191 (setq gdb-output-sink 'inferior))))
1194 (error "Unexpected `starting' annotation")))))
1196 (defun gdb-stopping (ignored)
1197 "An annotation handler for `breakpoint' and other annotations.
1198 They say that I/O for the subprocess is now GDB, not the program
1200 (if gdb-use-separate-io-buffer
1201 (let ((sink gdb-output-sink))
1203 ((eq sink 'inferior)
1204 (setq gdb-output-sink 'user))
1207 (error "Unexpected stopping annotation"))))))
1209 (defun gdb-exited (ignored)
1210 "An annotation handler for `exited' and `signalled'.
1211 They say that I/O for the subprocess is now GDB, not the program
1212 being debugged and that the program is no longer running. This
1213 function is used to change the focus of GUD tooltips to #define
1215 (setq gdb-active-process nil)
1216 (setq gud-overlay-arrow-position nil)
1217 (setq gdb-overlay-arrow-position nil)
1218 (gdb-stopping ignored))
1220 (defun gdb-signalled (ignored)
1221 (setq gdb-signalled t))
1223 (defun gdb-frame-begin (ignored)
1224 (let ((sink gdb-output-sink))
1226 ((eq sink 'inferior)
1227 (setq gdb-output-sink 'user))
1229 ((eq sink 'emacs) t)
1232 (error "Unexpected frame-begin annotation (%S)" sink)))))
1234 (defun gdb-stopped (ignored)
1235 "An annotation handler for `stopped'.
1236 It is just like `gdb-stopping', except that if we already set the output
1237 sink to `user' in `gdb-stopping', that is fine."
1238 (setq gud-running nil)
1239 (let ((sink gdb-output-sink))
1241 ((eq sink 'inferior)
1242 (setq gdb-output-sink 'user))
1246 (error "Unexpected stopped annotation"))))
1247 (if gdb-signalled (gdb-exited ignored)))
1249 (defun gdb-error (ignored)
1250 (setq gdb-error (not gdb-error)))
1252 (defun gdb-post-prompt (ignored)
1253 "An annotation handler for `post-prompt'.
1254 This begins the collection of output from the current command if that
1255 happens to be appropriate."
1256 ;; Don't add to queue if there outstanding items or gdb-version is not known
1258 (unless (or gdb-pending-triggers gdb-first-post-prompt)
1259 (gdb-get-selected-frame)
1260 (gdb-invalidate-frames)
1261 ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
1262 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
1263 (gdb-invalidate-breakpoints)
1264 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1265 ;; so gdb-frame-address is updated.
1266 ;; (gdb-invalidate-assembler)
1268 (if (string-equal gdb-version "pre-6.4")
1269 (gdb-invalidate-registers)
1270 (gdb-get-changed-registers)
1271 (gdb-invalidate-registers-1))
1273 (gdb-invalidate-memory)
1274 (if (string-equal gdb-version "pre-6.4")
1275 (gdb-invalidate-locals)
1276 (gdb-invalidate-locals-1))
1278 (gdb-invalidate-threads)
1279 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1280 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1281 ;; Only needed/used with speedbar/watch expressions.
1282 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1283 (setq gdb-force-update t)
1284 (if (string-equal gdb-version "pre-6.4")
1286 (gdb-var-update-1)))))
1287 (setq gdb-first-post-prompt nil)
1288 (let ((sink gdb-output-sink))
1291 ((eq sink 'pre-emacs)
1292 (setq gdb-output-sink 'emacs))
1295 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1297 ;; GUD displays the selected GDB frame. This might might not be the current
1298 ;; GDB frame (after up, down etc). If no GDB frame is visible but the last
1299 ;; visited breakpoint is, use that window.
1300 (defun gdb-display-source-buffer (buffer)
1301 (let* ((last-window (if gud-last-last-frame
1303 (gud-find-file (car gud-last-last-frame)))))
1304 (source-window (or last-window
1305 (if (and gdb-source-window
1306 (window-live-p gdb-source-window))
1307 gdb-source-window))))
1309 (setq gdb-source-window source-window)
1310 (set-window-buffer source-window buffer))
1313 (defun gud-gdba-marker-filter (string)
1314 "A gud marker filter for gdb. Handle a burst of output from GDB."
1315 (if gdb-flush-pending-output
1317 (when gdb-enable-debug
1318 (push (cons 'recv string) gdb-debug-ring)
1319 (if (> (length gdb-debug-ring) gdb-debug-ring-max)
1320 (setcdr (nthcdr (1- gdb-debug-ring-max) gdb-debug-ring) nil)))
1321 ;; Recall the left over gud-marker-acc from last time.
1322 (setq gud-marker-acc (concat gud-marker-acc string))
1323 ;; Start accumulating output for the GUD buffer.
1326 ;; Process all the complete markers in this chunk.
1327 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1328 (let ((annotation (match-string 1 gud-marker-acc)))
1330 ;; Stuff prior to the match is just ordinary output.
1331 ;; It is either concatenated to OUTPUT or directed
1336 (substring gud-marker-acc 0 (match-beginning 0))))
1338 ;; Take that stuff off the gud-marker-acc.
1339 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1341 ;; Parse the tag from the annotation, and maybe its arguments.
1342 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1343 (let* ((annotation-type (match-string 1 annotation))
1344 (annotation-arguments (match-string 2 annotation))
1345 (annotation-rule (assoc annotation-type
1346 gdb-annotation-rules)))
1347 ;; Call the handler for this annotation.
1349 (funcall (car (cdr annotation-rule))
1350 annotation-arguments)
1351 ;; Else the annotation is not recognized. Ignore it silently,
1352 ;; so that GDB can add new annotations without causing
1356 ;; Does the remaining text end in a partial line?
1357 ;; If it does, then keep part of the gud-marker-acc until we get more.
1358 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1361 ;; Everything before the potential marker start can be output.
1363 (gdb-concat-output output
1364 (substring gud-marker-acc 0
1365 (match-beginning 0))))
1367 ;; Everything after, we save, to combine with later input.
1368 (setq gud-marker-acc (substring gud-marker-acc
1369 (match-beginning 0))))
1371 ;; In case we know the gud-marker-acc contains no partial annotations:
1373 (setq output (gdb-concat-output output gud-marker-acc))
1374 (setq gud-marker-acc "")))
1377 (defun gdb-concat-output (so-far new)
1379 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1380 (let ((sink gdb-output-sink))
1382 ((eq sink 'user) (concat so-far new))
1383 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1385 (gdb-append-to-partial-output new)
1387 ((eq sink 'inferior)
1388 (gdb-append-to-inferior-io new)
1392 (error "Bogon output sink %S" sink)))))
1394 (defun gdb-append-to-partial-output (string)
1395 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1396 (goto-char (point-max))
1399 (defun gdb-clear-partial-output ()
1400 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1403 (defun gdb-append-to-inferior-io (string)
1404 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1405 (goto-char (point-max))
1406 (insert-before-markers string))
1407 (if (not (string-equal string ""))
1408 (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io))))
1410 (defun gdb-clear-inferior-io ()
1411 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1415 ;; One trick is to have a command who's output is always available in a buffer
1416 ;; of it's own, and is always up to date. We build several buffers of this
1419 ;; There are two aspects to this: gdb has to tell us when the output for that
1420 ;; command might have changed, and we have to be able to run the command
1421 ;; behind the user's back.
1423 ;; The output phasing associated with the variable gdb-output-sink
1424 ;; help us to run commands behind the user's back.
1426 ;; Below is the code for specificly managing buffers of output from one
1430 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1431 ;; It adds an input for the command we are tracking. It should be the
1432 ;; annotation rule binding of whatever gdb sends to tell us this command
1433 ;; might have changed it's output.
1435 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1436 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1437 ;; input in the input queue (see comment about ``gdb communications'' above).
1439 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1441 `(defun ,name (&optional ignored)
1442 (if (and ,demand-predicate
1444 gdb-pending-triggers)))
1447 (list ,gdb-command ',output-handler))
1448 (push ',name gdb-pending-triggers)))))
1450 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1452 (setq gdb-pending-triggers
1454 gdb-pending-triggers))
1455 (let ((buf (gdb-get-buffer ',buf-key)))
1457 (with-current-buffer buf
1458 (let* ((window (get-buffer-window buf 0))
1459 (start (window-start window))
1460 (p (window-point window))
1461 (buffer-read-only nil))
1463 (insert-buffer-substring (gdb-get-buffer-create
1464 'gdb-partial-output-buffer))
1465 (set-window-start window start)
1466 (set-window-point window p)))))
1467 ;; put customisation here
1470 (defmacro def-gdb-auto-updated-buffer (buffer-key
1471 trigger-name gdb-command
1472 output-handler-name custom-defun)
1474 (def-gdb-auto-update-trigger ,trigger-name
1475 ;; The demand predicate:
1476 (gdb-get-buffer ',buffer-key)
1478 ,output-handler-name)
1479 (def-gdb-auto-update-handler ,output-handler-name
1480 ,trigger-name ,buffer-key ,custom-defun)))
1484 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1486 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1487 'gdb-breakpoints-buffer-name
1488 'gdb-breakpoints-mode)
1490 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1491 ;; This defines the auto update rule for buffers of type
1492 ;; `gdb-breakpoints-buffer'.
1494 ;; It defines a function to serve as the annotation handler that
1495 ;; handles the `foo-invalidated' message. That function is called:
1496 gdb-invalidate-breakpoints
1498 ;; To update the buffer, this command is sent to gdb.
1499 "server info breakpoints\n"
1501 ;; This also defines a function to be the handler for the output
1502 ;; from the command above. That function will copy the output into
1503 ;; the appropriately typed buffer. That function will be called:
1504 gdb-info-breakpoints-handler
1505 ;; buffer specific functions
1506 gdb-info-breakpoints-custom)
1508 (defconst breakpoint-xpm-data
1510 static char *magick[] = {
1511 /* columns rows colors chars-per-pixel */
1527 "XPM data used for breakpoint icon.")
1529 (defconst breakpoint-enabled-pbm-data
1532 0 0 0 0 1 1 1 1 0 0 0 0
1533 0 0 0 1 1 1 1 1 1 0 0 0
1534 0 0 1 1 1 1 1 1 1 1 0 0
1535 0 1 1 1 1 1 1 1 1 1 1 0
1536 0 1 1 1 1 1 1 1 1 1 1 0
1537 0 1 1 1 1 1 1 1 1 1 1 0
1538 0 1 1 1 1 1 1 1 1 1 1 0
1539 0 0 1 1 1 1 1 1 1 1 0 0
1540 0 0 0 1 1 1 1 1 1 0 0 0
1541 0 0 0 0 1 1 1 1 0 0 0 0"
1542 "PBM data used for enabled breakpoint icon.")
1544 (defconst breakpoint-disabled-pbm-data
1556 0 0 0 1 0 1 0 1 0 0"
1557 "PBM data used for disabled breakpoint icon.")
1559 (defvar breakpoint-enabled-icon nil
1560 "Icon for enabled breakpoint in display margin.")
1562 (defvar breakpoint-disabled-icon nil
1563 "Icon for disabled breakpoint in display margin.")
1565 ;; Bitmap for breakpoint in fringe
1566 (and (display-images-p)
1567 (define-fringe-bitmap 'breakpoint
1568 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1570 (defface breakpoint-enabled
1574 "Face for enabled breakpoint icon in fringe."
1577 (defface breakpoint-disabled
1578 ;; We use different values of grey for different background types,
1579 ;; so that on low-color displays it will end up as something visible
1580 ;; if it has to be approximated.
1581 '((((background dark)) :foreground "grey60")
1582 (((background light)) :foreground "grey40"))
1583 "Face for disabled breakpoint icon in fringe."
1586 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1587 (defun gdb-info-breakpoints-custom ()
1588 (let ((flag) (bptno))
1589 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1590 (dolist (buffer (buffer-list))
1591 (with-current-buffer buffer
1592 (if (and (memq gud-minor-mode '(gdba gdbmi))
1593 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1594 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1595 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1597 (goto-char (point-min))
1598 (while (< (point) (- (point-max) 1))
1600 (if (looking-at "[^\t].*?breakpoint")
1602 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1603 (setq bptno (match-string 1))
1604 (setq flag (char-after (match-beginning 2)))
1606 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1608 (let ((buffer-read-only nil))
1609 (add-text-properties (match-beginning 1) (match-end 1)
1610 '(face font-lock-function-name-face)))
1611 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1612 (let ((line (match-string 2)) (buffer-read-only nil)
1613 (file (match-string 1)))
1614 (add-text-properties (line-beginning-position)
1616 '(mouse-face highlight
1617 help-echo "mouse-2, RET: visit breakpoint"))
1618 (unless (file-exists-p file)
1619 (setq file (cdr (assoc bptno gdb-location-alist))))
1621 (not (string-equal file "File not found")))
1622 (with-current-buffer
1623 (find-file-noselect file 'nowarn)
1624 (set (make-local-variable 'gud-minor-mode)
1626 (set (make-local-variable 'tool-bar-map)
1628 ;; Only want one breakpoint icon at each
1631 (goto-line (string-to-number line))
1632 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1635 (concat gdb-server-prefix "list "
1636 (match-string-no-properties 1) ":1\n")
1639 (list (concat gdb-server-prefix "info source\n")
1640 `(lambda () (gdb-get-location
1641 ,bptno ,line ,flag))))))))))
1643 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1645 (defun gdb-mouse-set-clear-breakpoint (event)
1646 "Set/clear breakpoint in left fringe/margin with mouse click."
1648 (mouse-minibuffer-check event)
1649 (let ((posn (event-end event)))
1650 (if (numberp (posn-point posn))
1651 (with-selected-window (posn-window posn)
1653 (goto-char (posn-point posn))
1654 (if (or (posn-object posn)
1655 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1658 (gud-break nil)))))))
1660 (defun gdb-mouse-toggle-breakpoint-margin (event)
1661 "Enable/disable breakpoint in left margin with mouse click."
1663 (mouse-minibuffer-check event)
1664 (let ((posn (event-end event)))
1665 (if (numberp (posn-point posn))
1666 (with-selected-window (posn-window posn)
1668 (goto-char (posn-point posn))
1669 (if (posn-object posn)
1672 (let ((bptno (get-text-property
1673 0 'gdb-bptno (car (posn-string posn)))))
1674 (concat gdb-server-prefix
1675 (if (get-text-property
1676 0 'gdb-enabled (car (posn-string posn)))
1682 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1683 "Enable/disable breakpoint in left fringe with mouse click."
1685 (mouse-minibuffer-check event)
1686 (let* ((posn (event-end event))
1687 (pos (posn-point posn))
1690 (with-selected-window (posn-window posn)
1692 (set-buffer (window-buffer (selected-window)))
1694 (dolist (overlay (overlays-in pos pos))
1695 (when (overlay-get overlay 'put-break)
1696 (setq obj (overlay-get overlay 'before-string))))
1700 (concat gdb-server-prefix
1701 (if (get-text-property 0 'gdb-enabled obj)
1704 (get-text-property 0 'gdb-bptno obj) "\n")
1707 (defun gdb-breakpoints-buffer-name ()
1708 (with-current-buffer gud-comint-buffer
1709 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1711 (defun gdb-display-breakpoints-buffer ()
1712 "Display status of user-settable breakpoints."
1715 (gdb-get-buffer-create 'gdb-breakpoints-buffer)))
1717 (defun gdb-frame-breakpoints-buffer ()
1718 "Display status of user-settable breakpoints in a new frame."
1720 (let ((special-display-regexps (append special-display-regexps '(".*")))
1721 (special-display-frame-alist gdb-frame-parameters))
1722 (display-buffer (gdb-get-buffer-create 'gdb-breakpoints-buffer))))
1724 (defvar gdb-breakpoints-mode-map
1725 (let ((map (make-sparse-keymap))
1726 (menu (make-sparse-keymap "Breakpoints")))
1727 (define-key menu [quit] '("Quit" . gdb-delete-frame-or-window))
1728 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1729 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1730 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1731 (suppress-keymap map)
1732 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1733 (define-key map " " 'gdb-toggle-breakpoint)
1734 (define-key map "D" 'gdb-delete-breakpoint)
1735 ;; Don't bind "q" to kill-this-buffer as we need it for breakpoint icons.
1736 (define-key map "q" 'gdb-delete-frame-or-window)
1737 (define-key map "\r" 'gdb-goto-breakpoint)
1738 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1739 (define-key map [follow-link] 'mouse-face)
1742 (defun gdb-delete-frame-or-window ()
1743 "Delete frame if there is only one window. Otherwise delete the window."
1745 (if (one-window-p) (delete-frame)
1748 (defun gdb-breakpoints-mode ()
1749 "Major mode for gdb breakpoints.
1751 \\{gdb-breakpoints-mode-map}"
1752 (kill-all-local-variables)
1753 (setq major-mode 'gdb-breakpoints-mode)
1754 (setq mode-name "Breakpoints")
1755 (use-local-map gdb-breakpoints-mode-map)
1756 (setq buffer-read-only t)
1757 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1758 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1759 'gdb-invalidate-breakpoints
1760 'gdbmi-invalidate-breakpoints))
1762 (defconst gdb-breakpoint-regexp
1763 "\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1765 (defun gdb-toggle-breakpoint ()
1766 "Enable/disable breakpoint at current line."
1769 (beginning-of-line 1)
1770 (if (looking-at gdb-breakpoint-regexp)
1773 (concat gdb-server-prefix
1774 (if (eq ?y (char-after (match-beginning 2)))
1777 (match-string 1) "\n") 'ignore))
1778 (error "Not recognized as break/watchpoint line"))))
1780 (defun gdb-delete-breakpoint ()
1781 "Delete the breakpoint at current line."
1783 (beginning-of-line 1)
1784 (if (looking-at gdb-breakpoint-regexp)
1787 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1788 (error "Not recognized as break/watchpoint line")))
1790 (defun gdb-goto-breakpoint (&optional event)
1791 "Display the breakpoint location specified at current line."
1792 (interactive (list last-input-event))
1793 (if event (posn-set-point (event-end event)))
1795 (beginning-of-line 1)
1796 (if (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1797 (let ((bptno (match-string 1))
1798 (file (match-string 2))
1799 (line (match-string 3)))
1800 (save-selected-window
1801 (let* ((buffer (find-file-noselect
1802 (if (file-exists-p file) file
1803 (cdr (assoc bptno gdb-location-alist)))))
1804 (window (unless (gdb-display-source-buffer buffer)
1805 (display-buffer buffer))))
1806 (setq gdb-source-window window)
1807 (with-current-buffer buffer
1808 (goto-line (string-to-number line))
1809 (set-window-point window (point))))))
1810 (error "No location specified."))))
1813 ;; Frames buffer. This displays a perpetually correct bactracktrace
1814 ;; (from the command `where').
1816 ;; Alas, if your stack is deep, it is costly.
1818 (gdb-set-buffer-rules 'gdb-stack-buffer
1819 'gdb-stack-buffer-name
1822 (def-gdb-auto-updated-buffer gdb-stack-buffer
1823 gdb-invalidate-frames
1825 gdb-info-frames-handler
1826 gdb-info-frames-custom)
1828 (defun gdb-info-frames-custom ()
1829 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1831 (let ((buffer-read-only nil)
1833 (goto-char (point-min))
1834 (while (< (point) (point-max))
1835 (setq bl (line-beginning-position)
1836 el (line-end-position))
1837 (when (looking-at "#")
1838 (add-text-properties bl el
1839 '(mouse-face highlight
1840 help-echo "mouse-2, RET: Select frame")))
1842 (when (looking-at "^#\\([0-9]+\\)")
1843 (when (string-equal (match-string 1) gdb-frame-number)
1844 (put-text-property bl (+ bl 4)
1845 'face '(:inverse-video t)))
1846 (when (re-search-forward
1848 (if (string-equal (match-string 1) "0") "" " in ")
1849 "\\([^ ]+\\) (") el t)
1850 (put-text-property (match-beginning 1) (match-end 1)
1851 'face font-lock-function-name-face)
1852 (setq bl (match-end 0))
1853 (while (re-search-forward "<\\([^>]+\\)>" el t)
1854 (put-text-property (match-beginning 1) (match-end 1)
1855 'face font-lock-function-name-face))
1857 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1858 (put-text-property (match-beginning 1) (match-end 1)
1859 'face font-lock-variable-name-face))))
1860 (forward-line 1))))))
1862 (defun gdb-stack-buffer-name ()
1863 (with-current-buffer gud-comint-buffer
1864 (concat "*stack frames of " (gdb-get-target-string) "*")))
1866 (defun gdb-display-stack-buffer ()
1867 "Display backtrace of current stack."
1870 (gdb-get-buffer-create 'gdb-stack-buffer)))
1872 (defun gdb-frame-stack-buffer ()
1873 "Display backtrace of current stack in a new frame."
1875 (let ((special-display-regexps (append special-display-regexps '(".*")))
1876 (special-display-frame-alist gdb-frame-parameters))
1877 (display-buffer (gdb-get-buffer-create 'gdb-stack-buffer))))
1879 (defvar gdb-frames-mode-map
1880 (let ((map (make-sparse-keymap)))
1881 (suppress-keymap map)
1882 (define-key map "q" 'kill-this-buffer)
1883 (define-key map "\r" 'gdb-frames-select)
1884 (define-key map [mouse-2] 'gdb-frames-select)
1885 (define-key map [follow-link] 'mouse-face)
1888 (defun gdb-frames-mode ()
1889 "Major mode for gdb frames.
1891 \\{gdb-frames-mode-map}"
1892 (kill-all-local-variables)
1893 (setq major-mode 'gdb-frames-mode)
1894 (setq mode-name "Frames")
1895 (setq buffer-read-only t)
1896 (use-local-map gdb-frames-mode-map)
1897 (run-mode-hooks 'gdb-frames-mode-hook)
1898 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1899 'gdb-invalidate-frames
1900 'gdbmi-invalidate-frames))
1902 (defun gdb-get-frame-number ()
1905 (let* ((start (line-beginning-position))
1906 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
1907 (n (or (and pos (match-string-no-properties 1)) "0")))
1910 (defun gdb-frames-select (&optional event)
1911 "Select the frame and display the relevant source."
1912 (interactive (list last-input-event))
1913 (if event (posn-set-point (event-end event)))
1915 (list (concat gdb-server-prefix "frame "
1916 (gdb-get-frame-number) "\n") 'ignore))
1917 (gud-display-frame))
1920 ;; Threads buffer. This displays a selectable thread list.
1922 (gdb-set-buffer-rules 'gdb-threads-buffer
1923 'gdb-threads-buffer-name
1926 (def-gdb-auto-updated-buffer gdb-threads-buffer
1927 gdb-invalidate-threads
1928 (concat gdb-server-prefix "info threads\n")
1929 gdb-info-threads-handler
1930 gdb-info-threads-custom)
1932 (defun gdb-info-threads-custom ()
1933 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1934 (let ((buffer-read-only nil))
1935 (goto-char (point-min))
1936 (while (< (point) (point-max))
1937 (unless (looking-at "No ")
1938 (add-text-properties (line-beginning-position) (line-end-position)
1939 '(mouse-face highlight
1940 help-echo "mouse-2, RET: select thread")))
1941 (forward-line 1)))))
1943 (defun gdb-threads-buffer-name ()
1944 (with-current-buffer gud-comint-buffer
1945 (concat "*threads of " (gdb-get-target-string) "*")))
1947 (defun gdb-display-threads-buffer ()
1948 "Display IDs of currently known threads."
1951 (gdb-get-buffer-create 'gdb-threads-buffer)))
1953 (defun gdb-frame-threads-buffer ()
1954 "Display IDs of currently known threads in a new frame."
1956 (let ((special-display-regexps (append special-display-regexps '(".*")))
1957 (special-display-frame-alist gdb-frame-parameters))
1958 (display-buffer (gdb-get-buffer-create 'gdb-threads-buffer))))
1960 (defvar gdb-threads-mode-map
1961 (let ((map (make-sparse-keymap)))
1962 (suppress-keymap map)
1963 (define-key map "q" 'kill-this-buffer)
1964 (define-key map "\r" 'gdb-threads-select)
1965 (define-key map [mouse-2] 'gdb-threads-select)
1966 (define-key map [follow-link] 'mouse-face)
1969 (defvar gdb-threads-font-lock-keywords
1971 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1972 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1973 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1975 "Font lock keywords used in `gdb-threads-mode'.")
1977 (defun gdb-threads-mode ()
1978 "Major mode for gdb frames.
1980 \\{gdb-threads-mode-map}"
1981 (kill-all-local-variables)
1982 (setq major-mode 'gdb-threads-mode)
1983 (setq mode-name "Threads")
1984 (setq buffer-read-only t)
1985 (use-local-map gdb-threads-mode-map)
1986 (set (make-local-variable 'font-lock-defaults)
1987 '(gdb-threads-font-lock-keywords))
1988 (run-mode-hooks 'gdb-threads-mode-hook)
1989 'gdb-invalidate-threads)
1991 (defun gdb-get-thread-number ()
1993 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1994 (match-string-no-properties 1)))
1996 (defun gdb-threads-select (&optional event)
1997 "Select the thread and display the relevant source."
1998 (interactive (list last-input-event))
1999 (if event (posn-set-point (event-end event)))
2001 (list (concat gdb-server-prefix "thread "
2002 (gdb-get-thread-number) "\n") 'ignore))
2003 (gud-display-frame))
2006 ;; Registers buffer.
2008 (defcustom gdb-all-registers nil
2009 "Non-nil means include floating-point registers."
2014 (gdb-set-buffer-rules 'gdb-registers-buffer
2015 'gdb-registers-buffer-name
2016 'gdb-registers-mode)
2018 (def-gdb-auto-updated-buffer gdb-registers-buffer
2019 gdb-invalidate-registers
2021 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
2022 gdb-info-registers-handler
2023 gdb-info-registers-custom)
2025 (defun gdb-info-registers-custom ()
2026 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2028 (let ((buffer-read-only nil)
2030 (goto-char (point-min))
2031 (while (< (point) (point-max))
2032 (setq start (line-beginning-position))
2033 (setq end (line-end-position))
2034 (when (looking-at "^[^ ]+")
2035 (unless (string-equal (match-string 0) "The")
2036 (put-text-property start (match-end 0)
2037 'face font-lock-variable-name-face)
2038 (add-text-properties start end
2039 '(help-echo "mouse-2: edit value"
2040 mouse-face highlight))))
2041 (forward-line 1))))))
2043 (defun gdb-edit-register-value (&optional event)
2044 (interactive (list last-input-event))
2046 (if event (posn-set-point (event-end event)))
2048 (let* ((register (current-word))
2049 (value (read-string (format "New value (%s): " register))))
2051 (list (concat gdb-server-prefix "set $" register "=" value "\n")
2054 (defvar gdb-registers-mode-map
2055 (let ((map (make-sparse-keymap)))
2056 (suppress-keymap map)
2057 (define-key map "\r" 'gdb-edit-register-value)
2058 (define-key map [mouse-2] 'gdb-edit-register-value)
2059 (define-key map " " 'gdb-all-registers)
2060 (define-key map "q" 'kill-this-buffer)
2063 (defun gdb-registers-mode ()
2064 "Major mode for gdb registers.
2066 \\{gdb-registers-mode-map}"
2067 (kill-all-local-variables)
2068 (setq major-mode 'gdb-registers-mode)
2069 (setq mode-name "Registers")
2070 (setq buffer-read-only t)
2071 (use-local-map gdb-registers-mode-map)
2072 (run-mode-hooks 'gdb-registers-mode-hook)
2073 (if (string-equal gdb-version "pre-6.4")
2075 (if gdb-all-registers (setq mode-name "Registers:All"))
2076 'gdb-invalidate-registers)
2077 'gdb-invalidate-registers-1))
2079 (defun gdb-registers-buffer-name ()
2080 (with-current-buffer gud-comint-buffer
2081 (concat "*registers of " (gdb-get-target-string) "*")))
2083 (defun gdb-display-registers-buffer ()
2084 "Display integer register contents."
2087 (gdb-get-buffer-create 'gdb-registers-buffer)))
2089 (defun gdb-frame-registers-buffer ()
2090 "Display integer register contents in a new frame."
2092 (let ((special-display-regexps (append special-display-regexps '(".*")))
2093 (special-display-frame-alist gdb-frame-parameters))
2094 (display-buffer (gdb-get-buffer-create 'gdb-registers-buffer))))
2096 (defun gdb-all-registers ()
2097 "Toggle the display of floating-point registers (pre GDB 6.4 only)."
2099 (when (string-equal gdb-version "pre-6.4")
2100 (if gdb-all-registers
2102 (setq gdb-all-registers nil)
2103 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2104 (setq mode-name "Registers")))
2105 (setq gdb-all-registers t)
2106 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2107 (setq mode-name "Registers:All")))
2108 (message (format "Display of floating-point registers %sabled"
2109 (if gdb-all-registers "en" "dis")))
2110 (gdb-invalidate-registers)))
2115 (defcustom gdb-memory-repeat-count 32
2116 "Number of data items in memory window."
2121 (defcustom gdb-memory-format "x"
2122 "Display format of data items in memory window."
2123 :type '(choice (const :tag "Hexadecimal" "x")
2124 (const :tag "Signed decimal" "d")
2125 (const :tag "Unsigned decimal" "u")
2126 (const :tag "Octal" "o")
2127 (const :tag "Binary" "t"))
2131 (defcustom gdb-memory-unit "w"
2132 "Unit size of data items in memory window."
2133 :type '(choice (const :tag "Byte" "b")
2134 (const :tag "Halfword" "h")
2135 (const :tag "Word" "w")
2136 (const :tag "Giant word" "g"))
2140 (gdb-set-buffer-rules 'gdb-memory-buffer
2141 'gdb-memory-buffer-name
2144 (def-gdb-auto-updated-buffer gdb-memory-buffer
2145 gdb-invalidate-memory
2146 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
2147 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
2148 gdb-read-memory-handler
2149 gdb-read-memory-custom)
2151 (defun gdb-read-memory-custom ()
2153 (goto-char (point-min))
2154 (if (looking-at "0x[[:xdigit:]]+")
2155 (setq gdb-memory-address (match-string 0)))))
2157 (defvar gdb-memory-mode-map
2158 (let ((map (make-sparse-keymap)))
2159 (suppress-keymap map)
2160 (define-key map "q" 'kill-this-buffer)
2163 (defun gdb-memory-set-address (event)
2164 "Set the start memory address."
2166 (save-selected-window
2167 (select-window (posn-window (event-start event)))
2168 (let ((arg (read-from-minibuffer "Memory address: ")))
2169 (setq gdb-memory-address arg))
2170 (gdb-invalidate-memory)))
2172 (defun gdb-memory-set-repeat-count (event)
2173 "Set the number of data items in memory window."
2175 (save-selected-window
2176 (select-window (posn-window (event-start event)))
2177 (let* ((arg (read-from-minibuffer "Repeat count: "))
2178 (count (string-to-number arg)))
2180 (error "Positive numbers only")
2181 (customize-set-variable 'gdb-memory-repeat-count count)
2182 (gdb-invalidate-memory)))))
2184 (defun gdb-memory-format-binary ()
2185 "Set the display format to binary."
2187 (customize-set-variable 'gdb-memory-format "t")
2188 (gdb-invalidate-memory))
2190 (defun gdb-memory-format-octal ()
2191 "Set the display format to octal."
2193 (customize-set-variable 'gdb-memory-format "o")
2194 (gdb-invalidate-memory))
2196 (defun gdb-memory-format-unsigned ()
2197 "Set the display format to unsigned decimal."
2199 (customize-set-variable 'gdb-memory-format "u")
2200 (gdb-invalidate-memory))
2202 (defun gdb-memory-format-signed ()
2203 "Set the display format to decimal."
2205 (customize-set-variable 'gdb-memory-format "d")
2206 (gdb-invalidate-memory))
2208 (defun gdb-memory-format-hexadecimal ()
2209 "Set the display format to hexadecimal."
2211 (customize-set-variable 'gdb-memory-format "x")
2212 (gdb-invalidate-memory))
2214 (defvar gdb-memory-format-map
2215 (let ((map (make-sparse-keymap)))
2216 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2218 "Keymap to select format in the header line.")
2220 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2221 "Menu of display formats in the header line.")
2223 (define-key gdb-memory-format-menu [binary]
2224 '(menu-item "Binary" gdb-memory-format-binary
2225 :button (:radio . (equal gdb-memory-format "t"))))
2226 (define-key gdb-memory-format-menu [octal]
2227 '(menu-item "Octal" gdb-memory-format-octal
2228 :button (:radio . (equal gdb-memory-format "o"))))
2229 (define-key gdb-memory-format-menu [unsigned]
2230 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2231 :button (:radio . (equal gdb-memory-format "u"))))
2232 (define-key gdb-memory-format-menu [signed]
2233 '(menu-item "Signed Decimal" gdb-memory-format-signed
2234 :button (:radio . (equal gdb-memory-format "d"))))
2235 (define-key gdb-memory-format-menu [hexadecimal]
2236 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2237 :button (:radio . (equal gdb-memory-format "x"))))
2239 (defun gdb-memory-format-menu (event)
2241 (x-popup-menu event gdb-memory-format-menu))
2243 (defun gdb-memory-format-menu-1 (event)
2245 (save-selected-window
2246 (select-window (posn-window (event-start event)))
2247 (let* ((selection (gdb-memory-format-menu event))
2248 (binding (and selection (lookup-key gdb-memory-format-menu
2249 (vector (car selection))))))
2250 (if binding (call-interactively binding)))))
2252 (defun gdb-memory-unit-giant ()
2253 "Set the unit size to giant words (eight bytes)."
2255 (customize-set-variable 'gdb-memory-unit "g")
2256 (gdb-invalidate-memory))
2258 (defun gdb-memory-unit-word ()
2259 "Set the unit size to words (four bytes)."
2261 (customize-set-variable 'gdb-memory-unit "w")
2262 (gdb-invalidate-memory))
2264 (defun gdb-memory-unit-halfword ()
2265 "Set the unit size to halfwords (two bytes)."
2267 (customize-set-variable 'gdb-memory-unit "h")
2268 (gdb-invalidate-memory))
2270 (defun gdb-memory-unit-byte ()
2271 "Set the unit size to bytes."
2273 (customize-set-variable 'gdb-memory-unit "b")
2274 (gdb-invalidate-memory))
2276 (defvar gdb-memory-unit-map
2277 (let ((map (make-sparse-keymap)))
2278 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2280 "Keymap to select units in the header line.")
2282 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2283 "Menu of units in the header line.")
2285 (define-key gdb-memory-unit-menu [giantwords]
2286 '(menu-item "Giant words" gdb-memory-unit-giant
2287 :button (:radio . (equal gdb-memory-unit "g"))))
2288 (define-key gdb-memory-unit-menu [words]
2289 '(menu-item "Words" gdb-memory-unit-word
2290 :button (:radio . (equal gdb-memory-unit "w"))))
2291 (define-key gdb-memory-unit-menu [halfwords]
2292 '(menu-item "Halfwords" gdb-memory-unit-halfword
2293 :button (:radio . (equal gdb-memory-unit "h"))))
2294 (define-key gdb-memory-unit-menu [bytes]
2295 '(menu-item "Bytes" gdb-memory-unit-byte
2296 :button (:radio . (equal gdb-memory-unit "b"))))
2298 (defun gdb-memory-unit-menu (event)
2300 (x-popup-menu event gdb-memory-unit-menu))
2302 (defun gdb-memory-unit-menu-1 (event)
2304 (save-selected-window
2305 (select-window (posn-window (event-start event)))
2306 (let* ((selection (gdb-memory-unit-menu event))
2307 (binding (and selection (lookup-key gdb-memory-unit-menu
2308 (vector (car selection))))))
2309 (if binding (call-interactively binding)))))
2311 ;;from make-mode-line-mouse-map
2312 (defun gdb-make-header-line-mouse-map (mouse function) "\
2313 Return a keymap with single entry for mouse key MOUSE on the header line.
2314 MOUSE is defined to run function FUNCTION with no args in the buffer
2315 corresponding to the mode line clicked."
2316 (let ((map (make-sparse-keymap)))
2317 (define-key map (vector 'header-line mouse) function)
2318 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2321 (defvar gdb-memory-font-lock-keywords
2322 '(;; <__function.name+n>
2323 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2325 "Font lock keywords used in `gdb-memory-mode'.")
2327 (defun gdb-memory-mode ()
2328 "Major mode for examining memory.
2330 \\{gdb-memory-mode-map}"
2331 (kill-all-local-variables)
2332 (setq major-mode 'gdb-memory-mode)
2333 (setq mode-name "Memory")
2334 (setq buffer-read-only t)
2335 (use-local-map gdb-memory-mode-map)
2336 (setq header-line-format
2342 'face font-lock-warning-face
2343 'help-echo "mouse-1: Decrement address"
2344 'mouse-face 'mode-line-highlight
2346 (gdb-make-header-line-mouse-map
2348 #'(lambda () (interactive)
2349 (let ((gdb-memory-address
2350 ;; Let GDB do the arithmetic.
2352 gdb-memory-address " - "
2354 (* gdb-memory-repeat-count
2355 (cond ((string= gdb-memory-unit "b") 1)
2356 ((string= gdb-memory-unit "h") 2)
2357 ((string= gdb-memory-unit "w") 4)
2358 ((string= gdb-memory-unit "g") 8)))))))
2359 (gdb-invalidate-memory)))))
2362 'face font-lock-warning-face
2363 'help-echo "mouse-1: Increment address"
2364 'mouse-face 'mode-line-highlight
2365 'local-map (gdb-make-header-line-mouse-map
2367 #'(lambda () (interactive)
2368 (let ((gdb-memory-address nil))
2369 (gdb-invalidate-memory)))))
2371 (propertize gdb-memory-address
2372 'face font-lock-warning-face
2373 'help-echo "mouse-1: Set memory address"
2374 'mouse-face 'mode-line-highlight
2375 'local-map (gdb-make-header-line-mouse-map
2377 #'gdb-memory-set-address))
2379 (propertize (number-to-string gdb-memory-repeat-count)
2380 'face font-lock-warning-face
2381 'help-echo "mouse-1: Set repeat count"
2382 'mouse-face 'mode-line-highlight
2383 'local-map (gdb-make-header-line-mouse-map
2385 #'gdb-memory-set-repeat-count))
2387 (propertize gdb-memory-format
2388 'face font-lock-warning-face
2389 'help-echo "mouse-3: Select display format"
2390 'mouse-face 'mode-line-highlight
2391 'local-map gdb-memory-format-map)
2393 (propertize gdb-memory-unit
2394 'face font-lock-warning-face
2395 'help-echo "mouse-3: Select unit size"
2396 'mouse-face 'mode-line-highlight
2397 'local-map gdb-memory-unit-map))))
2398 (set (make-local-variable 'font-lock-defaults)
2399 '(gdb-memory-font-lock-keywords))
2400 (run-mode-hooks 'gdb-memory-mode-hook)
2401 'gdb-invalidate-memory)
2403 (defun gdb-memory-buffer-name ()
2404 (with-current-buffer gud-comint-buffer
2405 (concat "*memory of " (gdb-get-target-string) "*")))
2407 (defun gdb-display-memory-buffer ()
2408 "Display memory contents."
2411 (gdb-get-buffer-create 'gdb-memory-buffer)))
2413 (defun gdb-frame-memory-buffer ()
2414 "Display memory contents in a new frame."
2416 (let ((special-display-regexps (append special-display-regexps '(".*")))
2417 (special-display-frame-alist gdb-frame-parameters))
2418 (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
2423 (gdb-set-buffer-rules 'gdb-locals-buffer
2424 'gdb-locals-buffer-name
2427 (def-gdb-auto-update-trigger gdb-invalidate-locals
2428 (gdb-get-buffer 'gdb-locals-buffer)
2429 "server info locals\n"
2430 gdb-info-locals-handler)
2432 (defvar gdb-locals-watch-map
2433 (let ((map (make-sparse-keymap)))
2434 (define-key map "\r" '(lambda () (interactive)
2437 (define-key map [mouse-2] '(lambda (event) (interactive "e")
2438 (mouse-set-point event)
2442 "Keymap to create watch expression of a complex data type local variable.")
2444 (defconst gdb-struct-string
2445 (concat (propertize "[struct/union]"
2446 'mouse-face 'highlight
2447 'help-echo "mouse-2: create watch expression"
2448 'local-map gdb-locals-watch-map) "\n"))
2450 (defconst gdb-array-string
2451 (concat " " (propertize "[array]"
2452 'mouse-face 'highlight
2453 'help-echo "mouse-2: create watch expression"
2454 'local-map gdb-locals-watch-map) "\n"))
2456 ;; Abbreviate for arrays and structures.
2457 ;; These can be expanded using gud-display.
2458 (defun gdb-info-locals-handler ()
2459 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2460 gdb-pending-triggers))
2461 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2462 (with-current-buffer buf
2463 (goto-char (point-min))
2464 (while (re-search-forward "^[ }].*\n" nil t)
2465 (replace-match "" nil nil))
2466 (goto-char (point-min))
2467 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2468 (replace-match gdb-struct-string nil nil))
2469 (goto-char (point-min))
2470 (while (re-search-forward "\\s-*{.*\n" nil t)
2471 (replace-match gdb-array-string nil nil))))
2472 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2474 (with-current-buffer buf
2475 (let* ((window (get-buffer-window buf 0))
2476 (start (window-start window))
2477 (p (window-point window))
2478 (buffer-read-only nil))
2480 (insert-buffer-substring (gdb-get-buffer-create
2481 'gdb-partial-output-buffer))
2482 (set-window-start window start)
2483 (set-window-point window p))
2485 (run-hooks 'gdb-info-locals-hook))
2487 (defvar gdb-locals-mode-map
2488 (let ((map (make-sparse-keymap)))
2489 (suppress-keymap map)
2490 (define-key map "q" 'kill-this-buffer)
2493 (defun gdb-locals-mode ()
2494 "Major mode for gdb locals.
2496 \\{gdb-locals-mode-map}"
2497 (kill-all-local-variables)
2498 (setq major-mode 'gdb-locals-mode)
2499 (setq mode-name (concat "Locals:" gdb-selected-frame))
2500 (setq buffer-read-only t)
2501 (use-local-map gdb-locals-mode-map)
2502 (set (make-local-variable 'font-lock-defaults)
2503 '(gdb-locals-font-lock-keywords))
2504 (run-mode-hooks 'gdb-locals-mode-hook)
2505 (if (and (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2506 (string-equal gdb-version "pre-6.4"))
2507 'gdb-invalidate-locals
2508 'gdb-invalidate-locals-1))
2510 (defun gdb-locals-buffer-name ()
2511 (with-current-buffer gud-comint-buffer
2512 (concat "*locals of " (gdb-get-target-string) "*")))
2514 (defun gdb-display-locals-buffer ()
2515 "Display local variables of current stack and their values."
2518 (gdb-get-buffer-create 'gdb-locals-buffer)))
2520 (defun gdb-frame-locals-buffer ()
2521 "Display local variables of current stack and their values in a new frame."
2523 (let ((special-display-regexps (append special-display-regexps '(".*")))
2524 (special-display-frame-alist gdb-frame-parameters))
2525 (display-buffer (gdb-get-buffer-create 'gdb-locals-buffer))))
2528 ;;;; Window management
2529 (defun gdb-display-buffer (buf &optional size)
2530 (let ((answer (get-buffer-window buf 0))
2533 (display-buffer buf nil 0) ;Raise the frame if necessary.
2534 ;; The buffer is not yet displayed.
2535 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2536 (let ((window (get-lru-window)))
2538 (not (eq window (get-buffer-window gud-comint-buffer))))
2540 (set-window-buffer window buf)
2541 (setq answer window))
2542 (setq must-split t)))
2544 (let* ((largest (get-largest-window))
2545 (cur-size (window-height largest))
2546 (new-size (and size (< size cur-size) (- cur-size size))))
2547 (setq answer (split-window largest new-size))
2548 (set-window-buffer answer buf)
2549 (set-window-dedicated-p answer t)))
2553 ;;; Shared keymap initialization:
2555 (let ((menu (make-sparse-keymap "GDB-Windows")))
2556 (define-key gud-menu-map [displays]
2557 `(menu-item "GDB-Windows" ,menu
2558 :visible (memq gud-minor-mode '(gdbmi gdba))))
2559 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2560 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2561 (define-key menu [inferior]
2562 '(menu-item "Inferior IO" gdb-display-separate-io-buffer
2563 :enable gdb-use-separate-io-buffer))
2564 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2565 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2566 (define-key menu [disassembly]
2567 '("Disassembly" . gdb-display-assembler-buffer))
2568 (define-key menu [breakpoints]
2569 '("Breakpoints" . gdb-display-breakpoints-buffer))
2570 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2571 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)))
2573 (let ((menu (make-sparse-keymap "GDB-Frames")))
2574 (define-key gud-menu-map [frames]
2575 `(menu-item "GDB-Frames" ,menu
2576 :visible (memq gud-minor-mode '(gdbmi gdba))))
2577 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2578 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2579 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2580 (define-key menu [inferior]
2581 '(menu-item "Inferior IO" gdb-frame-separate-io-buffer
2582 :enable gdb-use-separate-io-buffer))
2583 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2584 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2585 (define-key menu [breakpoints]
2586 '("Breakpoints" . gdb-frame-breakpoints-buffer))
2587 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2588 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)))
2590 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2591 (define-key gud-menu-map [ui]
2592 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2593 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2594 (define-key menu [gdb-use-separate-io]
2595 '(menu-item "Separate inferior IO" gdb-use-separate-io-buffer
2596 :visible (eq gud-minor-mode 'gdba)
2597 :help "Toggle separate IO for inferior."
2598 :button (:toggle . gdb-use-separate-io-buffer)))
2599 (define-key menu [gdb-many-windows]
2600 '(menu-item "Display Other Windows" gdb-many-windows
2601 :help "Toggle display of locals, stack and breakpoint information"
2602 :button (:toggle . gdb-many-windows)))
2603 (define-key menu [gdb-restore-windows]
2604 '(menu-item "Restore Window Layout" gdb-restore-windows
2605 :help "Restore standard layout for debug session.")))
2607 (defun gdb-frame-gdb-buffer ()
2608 "Display GUD buffer in a new frame."
2610 (let ((special-display-regexps (append special-display-regexps '(".*")))
2611 (special-display-frame-alist gdb-frame-parameters)
2612 (same-window-regexps nil))
2613 (display-buffer gud-comint-buffer)))
2615 (defun gdb-display-gdb-buffer ()
2616 "Display GUD buffer."
2618 (let ((same-window-regexps nil))
2619 (pop-to-buffer gud-comint-buffer)))
2621 (defun gdb-set-window-buffer (name)
2622 (set-window-buffer (selected-window) (get-buffer name))
2623 (set-window-dedicated-p (selected-window) t))
2625 (defun gdb-setup-windows ()
2626 "Layout the window pattern for `gdb-many-windows'."
2627 (gdb-display-locals-buffer)
2628 (gdb-display-stack-buffer)
2629 (delete-other-windows)
2630 (gdb-display-breakpoints-buffer)
2631 (delete-other-windows)
2633 (pop-to-buffer gud-comint-buffer)
2634 (split-window nil ( / ( * (window-height) 3) 4))
2635 (split-window nil ( / (window-height) 3))
2636 (split-window-horizontally)
2638 (gdb-set-window-buffer (gdb-locals-buffer-name))
2641 (if gud-last-last-frame
2642 (gud-find-file (car gud-last-last-frame))
2643 (gud-find-file gdb-main-file)))
2644 (when gdb-use-separate-io-buffer
2645 (split-window-horizontally)
2647 (gdb-set-window-buffer
2648 (gdb-get-buffer-create 'gdb-inferior-io)))
2650 (gdb-set-window-buffer (gdb-stack-buffer-name))
2651 (split-window-horizontally)
2653 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2656 (defcustom gdb-many-windows nil
2657 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2658 In this case it starts with two windows: one displaying the GUD
2659 buffer and the other with the source file with the main routine
2660 of the inferior. Non-nil means display the layout shown for
2666 (defun gdb-many-windows (arg)
2667 "Toggle the number of windows in the basic arrangement.
2668 With arg, display additional buffers iff arg is positive."
2670 (setq gdb-many-windows
2672 (not gdb-many-windows)
2673 (> (prefix-numeric-value arg) 0)))
2674 (message (format "Display of other windows %sabled"
2675 (if gdb-many-windows "en" "dis")))
2676 (if (and gud-comint-buffer
2677 (buffer-name gud-comint-buffer))
2679 (gdb-restore-windows)
2682 (defun gdb-restore-windows ()
2683 "Restore the basic arrangement of windows used by gdba.
2684 This arrangement depends on the value of `gdb-many-windows'."
2686 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2687 (delete-other-windows)
2688 (if gdb-many-windows
2690 (when (or gud-last-last-frame gdb-show-main)
2694 (if gud-last-last-frame
2695 (gud-find-file (car gud-last-last-frame))
2696 (gud-find-file gdb-main-file)))
2700 "Exit a debugging session cleanly.
2701 Kills the gdb buffers, and resets variables and the source buffers."
2702 (dolist (buffer (buffer-list))
2703 (unless (eq buffer gud-comint-buffer)
2704 (with-current-buffer buffer
2705 (if (memq gud-minor-mode '(gdbmi gdba))
2706 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2708 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2709 (setq gud-minor-mode nil)
2710 (kill-local-variable 'tool-bar-map)
2711 (kill-local-variable 'gdb-define-alist))))))
2712 (when (markerp gdb-overlay-arrow-position)
2713 (move-marker gdb-overlay-arrow-position nil)
2714 (setq gdb-overlay-arrow-position nil))
2715 (setq overlay-arrow-variable-list
2716 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2717 (if (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
2719 (setq gud-running nil)
2720 (setq gdb-active-process nil)
2721 (setq gdb-var-list nil)
2722 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2724 (defun gdb-source-info ()
2725 "Find the source file where the program starts and displays it with related
2727 (goto-char (point-min))
2728 (if (and (search-forward "Located in " nil t)
2729 (looking-at "\\S-+"))
2730 (setq gdb-main-file (match-string 0)))
2731 (goto-char (point-min))
2732 (if (search-forward "Includes preprocessor macro info." nil t)
2733 (setq gdb-macro-info t))
2734 (if gdb-many-windows
2736 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
2738 (let ((pop-up-windows t))
2739 (display-buffer (gud-find-file gdb-main-file))))))
2741 (defun gdb-get-location (bptno line flag)
2742 "Find the directory containing the relevant source file.
2743 Put in buffer and place breakpoint icon."
2744 (goto-char (point-min))
2745 (catch 'file-not-found
2746 (if (search-forward "Located in " nil t)
2747 (when (looking-at "\\S-+")
2748 (delete (cons bptno "File not found") gdb-location-alist)
2749 (push (cons bptno (match-string 0)) gdb-location-alist))
2751 (unless (assoc bptno gdb-location-alist)
2752 (push (cons bptno "File not found") gdb-location-alist)
2753 (message-box "Cannot find source file for breakpoint location.\n\
2754 Add directory to search path for source files using the GDB command, dir."))
2755 (throw 'file-not-found nil))
2756 (with-current-buffer
2757 (find-file-noselect (match-string 0))
2758 (save-current-buffer
2759 (set (make-local-variable 'gud-minor-mode) 'gdba)
2760 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2761 ;; only want one breakpoint icon at each location
2763 (goto-line (string-to-number line))
2764 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2766 (add-hook 'find-file-hook 'gdb-find-file-hook)
2768 (defun gdb-find-file-hook ()
2769 "Set up buffer for debugging if file is part of the source code
2770 of the current session."
2771 (if (and (buffer-name gud-comint-buffer)
2772 ;; in case gud or gdb-ui is just loaded
2774 (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2776 (if (member buffer-file-name gdb-source-file-list)
2777 (with-current-buffer (find-buffer-visiting buffer-file-name)
2778 (set (make-local-variable 'gud-minor-mode)
2779 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
2780 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)))))
2783 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2784 "Put string PUTSTRING in front of POS in the current buffer.
2785 PUTSTRING is displayed by putting an overlay into the current buffer with a
2786 `before-string' string that has a `display' property whose value is
2788 (let ((string (make-string 1 ?x))
2789 (buffer (current-buffer)))
2790 (setq putstring (copy-sequence putstring))
2791 (let ((overlay (make-overlay pos pos buffer))
2793 (list (list 'margin 'left-margin) putstring))))
2794 (put-text-property 0 1 'display prop string)
2796 (add-text-properties 0 1 sprops string))
2797 (overlay-put overlay 'put-break t)
2798 (overlay-put overlay 'before-string string))))
2800 ;;from remove-images
2801 (defun gdb-remove-strings (start end &optional buffer)
2802 "Remove strings between START and END in BUFFER.
2803 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2804 BUFFER nil or omitted means use the current buffer."
2806 (setq buffer (current-buffer)))
2807 (dolist (overlay (overlays-in start end))
2808 (when (overlay-get overlay 'put-break)
2809 (delete-overlay overlay))))
2811 (defun gdb-put-breakpoint-icon (enabled bptno)
2812 (let ((start (- (line-beginning-position) 1))
2813 (end (+ (line-end-position) 1))
2814 (putstring (if enabled "B" "b"))
2815 (source-window (get-buffer-window (current-buffer) 0)))
2816 (add-text-properties
2817 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2820 (add-text-properties
2821 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2822 (add-text-properties
2823 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2824 (gdb-remove-breakpoint-icons start end)
2825 (if (display-images-p)
2826 (if (>= (or left-fringe-width
2827 (if source-window (car (window-fringes source-window)))
2828 gdb-buffer-fringe-width) 8)
2831 `(left-fringe breakpoint
2834 'breakpoint-disabled))
2836 'gdb-enabled enabled)
2837 (when (< left-margin-width 2)
2838 (save-current-buffer
2839 (setq left-margin-width 2)
2843 left-margin-width right-margin-width))))
2846 (or breakpoint-enabled-icon
2847 (setq breakpoint-enabled-icon
2848 (find-image `((:type xpm :data
2849 ,breakpoint-xpm-data
2850 :ascent 100 :pointer hand)
2852 ,breakpoint-enabled-pbm-data
2853 :ascent 100 :pointer hand)))))
2854 (or breakpoint-disabled-icon
2855 (setq breakpoint-disabled-icon
2856 (find-image `((:type xpm :data
2857 ,breakpoint-xpm-data
2858 :conversion disabled
2859 :ascent 100 :pointer hand)
2861 ,breakpoint-disabled-pbm-data
2862 :ascent 100 :pointer hand))))))
2866 (when (< left-margin-width 2)
2867 (save-current-buffer
2868 (setq left-margin-width 2)
2869 (let ((window (get-buffer-window (current-buffer) 0)))
2872 window left-margin-width right-margin-width)))))
2874 (propertize putstring
2875 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2878 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2879 (gdb-remove-strings start end)
2880 (if (display-images-p)
2881 (remove-images start end))
2883 (setq left-margin-width 0)
2884 (let ((window (get-buffer-window (current-buffer) 0)))
2887 window left-margin-width right-margin-width)))))
2891 ;; Assembler buffer.
2893 (gdb-set-buffer-rules 'gdb-assembler-buffer
2894 'gdb-assembler-buffer-name
2895 'gdb-assembler-mode)
2897 (def-gdb-auto-update-handler gdb-assembler-handler
2898 gdb-invalidate-assembler
2899 gdb-assembler-buffer
2900 gdb-assembler-custom)
2902 (defun gdb-assembler-custom ()
2903 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2904 (pos 1) (address) (flag) (bptno))
2905 (with-current-buffer buffer
2907 (if (not (equal gdb-frame-address "main"))
2909 (goto-char (point-min))
2910 (if (and gdb-frame-address
2911 (search-forward gdb-frame-address nil t))
2915 (or gdb-overlay-arrow-position
2916 (setq gdb-overlay-arrow-position (make-marker)))
2917 (set-marker gdb-overlay-arrow-position
2918 (point) (current-buffer))))))
2919 ;; remove all breakpoint-icons in assembler buffer before updating.
2920 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2921 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2922 (goto-char (point-min))
2923 (while (< (point) (- (point-max) 1))
2925 (if (looking-at "[^\t].*?breakpoint")
2928 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2929 (setq bptno (match-string 1))
2930 (setq flag (char-after (match-beginning 2)))
2931 (setq address (match-string 3))
2932 (with-current-buffer buffer
2934 (goto-char (point-min))
2935 (if (search-forward address nil t)
2936 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2937 (if (not (equal gdb-frame-address "main"))
2938 (with-current-buffer buffer
2939 (set-window-point (get-buffer-window buffer 0) pos)))))
2941 (defvar gdb-assembler-mode-map
2942 (let ((map (make-sparse-keymap)))
2943 (suppress-keymap map)
2944 (define-key map "q" 'kill-this-buffer)
2947 (defvar gdb-assembler-font-lock-keywords
2948 '(;; <__function.name+n>
2949 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2950 (1 font-lock-function-name-face))
2951 ;; 0xNNNNNNNN <__function.name+n>: opcode
2952 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2953 (4 font-lock-keyword-face))
2954 ;; %register(at least i386)
2955 ("%\\sw+" . font-lock-variable-name-face)
2956 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2957 (1 font-lock-comment-face)
2958 (2 font-lock-function-name-face))
2959 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2960 "Font lock keywords used in `gdb-assembler-mode'.")
2962 (defun gdb-assembler-mode ()
2963 "Major mode for viewing code assembler.
2965 \\{gdb-assembler-mode-map}"
2966 (kill-all-local-variables)
2967 (setq major-mode 'gdb-assembler-mode)
2968 (setq mode-name (concat "Machine:" gdb-selected-frame))
2969 (setq gdb-overlay-arrow-position nil)
2970 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2971 (setq fringes-outside-margins t)
2972 (setq buffer-read-only t)
2973 (use-local-map gdb-assembler-mode-map)
2974 (gdb-invalidate-assembler)
2975 (set (make-local-variable 'font-lock-defaults)
2976 '(gdb-assembler-font-lock-keywords))
2977 (run-mode-hooks 'gdb-assembler-mode-hook)
2978 'gdb-invalidate-assembler)
2980 (defun gdb-assembler-buffer-name ()
2981 (with-current-buffer gud-comint-buffer
2982 (concat "*disassembly of " (gdb-get-target-string) "*")))
2984 (defun gdb-display-assembler-buffer ()
2985 "Display disassembly view."
2987 (setq gdb-previous-frame nil)
2989 (gdb-get-buffer-create 'gdb-assembler-buffer)))
2991 (defun gdb-frame-assembler-buffer ()
2992 "Display disassembly view in a new frame."
2994 (setq gdb-previous-frame nil)
2995 (let ((special-display-regexps (append special-display-regexps '(".*")))
2996 (special-display-frame-alist gdb-frame-parameters))
2997 (display-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))))
2999 ;; modified because if gdb-frame-address has changed value a new command
3000 ;; must be enqueued to update the buffer with the new output
3001 (defun gdb-invalidate-assembler (&optional ignored)
3002 (if (gdb-get-buffer 'gdb-assembler-buffer)
3004 (unless (and gdb-selected-frame
3005 (string-equal gdb-selected-frame gdb-previous-frame))
3006 (if (or (not (member 'gdb-invalidate-assembler
3007 gdb-pending-triggers))
3008 (not (string-equal gdb-frame-address
3009 gdb-previous-frame-address)))
3011 ;; take previous disassemble command, if any, off the queue
3012 (with-current-buffer gud-comint-buffer
3013 (let ((queue gdb-input-queue))
3014 (dolist (item queue)
3015 (if (equal (cdr item) '(gdb-assembler-handler))
3016 (setq gdb-input-queue
3017 (delete item gdb-input-queue))))))
3020 (concat gdb-server-prefix "disassemble "
3021 (if (member gdb-frame-address '(nil "main")) nil "0x")
3022 gdb-frame-address "\n")
3023 'gdb-assembler-handler))
3024 (push 'gdb-invalidate-assembler gdb-pending-triggers)
3025 (setq gdb-previous-frame-address gdb-frame-address)
3026 (setq gdb-previous-frame gdb-selected-frame)))))))
3028 (defun gdb-get-selected-frame ()
3029 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
3032 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
3033 (push 'gdb-get-selected-frame
3034 gdb-pending-triggers))))
3036 (defun gdb-frame-handler ()
3037 (setq gdb-pending-triggers
3038 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3039 (goto-char (point-min))
3040 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
3041 (setq gdb-frame-number (match-string 1)))
3042 (goto-char (point-min))
3043 (if (re-search-forward
3044 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
3046 (setq gdb-selected-frame (match-string 2))
3047 (if (gdb-get-buffer 'gdb-locals-buffer)
3048 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3049 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3050 (if (gdb-get-buffer 'gdb-assembler-buffer)
3051 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3052 (setq mode-name (concat "Machine:" gdb-selected-frame))))
3053 (setq gdb-frame-address (match-string 1))))
3054 (goto-char (point-min))
3055 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
3056 (setq gdb-current-language (match-string 1)))
3057 (gdb-invalidate-assembler))
3060 ;; Code specific to GDB 6.4
3061 (defconst gdb-source-file-regexp-1 "fullname=\"\\(.*?\\)\"")
3063 (defun gdb-set-gud-minor-mode-existing-buffers-1 ()
3064 "Create list of source files for current GDB session.
3065 If buffers already exist for any of these files, gud-minor-mode
3067 (goto-char (point-min))
3068 (while (re-search-forward gdb-source-file-regexp-1 nil t)
3069 (push (match-string 1) gdb-source-file-list))
3070 (dolist (buffer (buffer-list))
3071 (with-current-buffer buffer
3072 (when (member buffer-file-name gdb-source-file-list)
3073 (set (make-local-variable 'gud-minor-mode)
3074 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
3075 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
3076 (when gud-tooltip-mode
3077 (make-local-variable 'gdb-define-alist)
3078 (gdb-create-define-alist)
3079 (add-hook 'after-save-hook 'gdb-create-define-alist nil t))))))
3081 ; Uses "-var-list-children --all-values". Needs GDB 6.1 onwards.
3082 (defun gdb-var-list-children-1 (varnum)
3085 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3086 (concat "server interpreter mi \"-var-list-children --all-values "
3088 (concat "-var-list-children --all-values " varnum "\n"))
3089 `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
3091 (defconst gdb-var-list-children-regexp-1
3092 "name=\"\\(.+?\\)\",exp=\"\\(.+?\\)\",numchild=\"\\(.+?\\)\",\
3093 value=\\(\".*?\"\\),type=\"\\(.+?\\)\"}")
3095 (defun gdb-var-list-children-handler-1 (varnum)
3096 (goto-char (point-min))
3097 (let ((var-list nil))
3098 (catch 'child-already-watched
3099 (dolist (var gdb-var-list)
3100 (if (string-equal varnum (cadr var))
3103 (while (re-search-forward gdb-var-list-children-regexp-1 nil t)
3104 (let ((varchild (list (match-string 2)
3108 (read (match-string 4))
3110 (dolist (var1 gdb-var-list)
3111 (if (string-equal (cadr var1) (cadr varchild))
3112 (throw 'child-already-watched nil)))
3113 (push varchild var-list))))
3114 (push var var-list)))
3115 (setq gdb-var-list (nreverse var-list)))))
3117 ; Uses "-var-update --all-values". Needs GDB 6.4 onwards.
3118 (defun gdb-var-update-1 ()
3119 (if (not (member 'gdb-var-update gdb-pending-triggers))
3123 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3124 "server interpreter mi \"-var-update --all-values *\"\n"
3125 "-var-update --all-values *\n")
3126 'gdb-var-update-handler-1))
3127 (push 'gdb-var-update gdb-pending-triggers))))
3129 (defconst gdb-var-update-regexp-1
3130 "name=\"\\(.*?\\)\",\\(?:value=\\(\".*?\"\\),\\)?in_scope=\"\\(.*?\\)\"")
3132 (defun gdb-var-update-handler-1 ()
3133 (dolist (var gdb-var-list)
3134 (setcar (nthcdr 5 var) nil))
3135 (goto-char (point-min))
3136 (while (re-search-forward gdb-var-update-regexp-1 nil t)
3137 (let ((varnum (match-string 1)))
3139 (dolist (var gdb-var-list)
3140 (when (string-equal varnum (cadr var))
3141 (if (string-equal (match-string 3) "false")
3142 (setcar (nthcdr 5 var) 'out-of-scope)
3143 (setcar (nthcdr 5 var) 'changed)
3144 (setcar (nthcdr 4 var)
3145 (read (match-string 2))))
3146 (throw 'var-found nil))))))
3147 (setq gdb-pending-triggers
3148 (delq 'gdb-var-update gdb-pending-triggers))
3149 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
3150 ;; dummy command to update speedbar at right time
3151 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-refresh))
3152 ;; keep gdb-pending-triggers non-nil till end
3153 (push 'gdb-speedbar-refresh gdb-pending-triggers)))
3155 ;; Registers buffer.
3157 (gdb-set-buffer-rules 'gdb-registers-buffer
3158 'gdb-registers-buffer-name
3159 'gdb-registers-mode)
3161 (def-gdb-auto-update-trigger gdb-invalidate-registers-1
3162 (gdb-get-buffer 'gdb-registers-buffer)
3163 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3164 "server interpreter mi \"-data-list-register-values x\"\n"
3165 "-data-list-register-values x\n")
3166 gdb-data-list-register-values-handler)
3168 (defconst gdb-data-list-register-values-regexp
3169 "number=\"\\(.*?\\)\",value=\"\\(.*?\\)\"")
3171 (defun gdb-data-list-register-values-handler ()
3172 (setq gdb-pending-triggers (delq 'gdb-invalidate-registers-1
3173 gdb-pending-triggers))
3174 (goto-char (point-min))
3175 (if (re-search-forward gdb-error-regexp nil t)
3176 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3177 (let ((buffer-read-only nil))
3179 (insert (match-string 1))
3180 (goto-char (point-min))))
3181 (let ((register-list (reverse gdb-register-names))
3182 (register nil) (register-string nil) (register-values nil))
3183 (goto-char (point-min))
3184 (while (re-search-forward gdb-data-list-register-values-regexp nil t)
3185 (setq register (pop register-list))
3186 (setq register-string (concat register "\t" (match-string 2) "\n"))
3187 (if (member (match-string 1) gdb-changed-registers)
3188 (put-text-property 0 (length register-string)
3189 'face 'font-lock-warning-face
3191 (setq register-values
3192 (concat register-values register-string)))
3193 (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
3194 (with-current-buffer buf
3195 (let* ((window (get-buffer-window buf 0))
3196 (start (window-start window))
3197 (p (window-point window))
3198 (buffer-read-only nil))
3200 (insert register-values)
3201 (set-window-start window start)
3202 (set-window-point window p))))))
3203 (gdb-data-list-register-values-custom))
3205 (defun gdb-data-list-register-values-custom ()
3206 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3208 (let ((buffer-read-only nil)
3210 (goto-char (point-min))
3211 (while (< (point) (point-max))
3212 (setq start (line-beginning-position))
3213 (setq end (line-end-position))
3214 (when (looking-at "^[^\t]+")
3215 (unless (string-equal (match-string 0) "No registers.")
3216 (put-text-property start (match-end 0)
3217 'face font-lock-variable-name-face)
3218 (add-text-properties start end
3219 '(help-echo "mouse-2: edit value"
3220 mouse-face highlight))))
3221 (forward-line 1))))))
3223 ;; Needs GDB 6.4 onwards (used to fail with no stack).
3224 (defun gdb-get-changed-registers ()
3225 (if (and (gdb-get-buffer 'gdb-registers-buffer)
3226 (not (member 'gdb-get-changed-registers gdb-pending-triggers)))
3230 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3231 "server interpreter mi -data-list-changed-registers\n"
3232 "-data-list-changed-registers\n")
3233 'gdb-get-changed-registers-handler))
3234 (push 'gdb-get-changed-registers gdb-pending-triggers))))
3236 (defconst gdb-data-list-register-names-regexp "\"\\(.*?\\)\"")
3238 (defun gdb-get-changed-registers-handler ()
3239 (setq gdb-pending-triggers
3240 (delq 'gdb-get-changed-registers gdb-pending-triggers))
3241 (setq gdb-changed-registers nil)
3242 (goto-char (point-min))
3243 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3244 (push (match-string 1) gdb-changed-registers)))
3249 ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards.
3250 (gdb-set-buffer-rules 'gdb-locals-buffer
3251 'gdb-locals-buffer-name
3254 (def-gdb-auto-update-trigger gdb-invalidate-locals-1
3255 (gdb-get-buffer 'gdb-locals-buffer)
3256 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3257 "server interpreter mi -\"stack-list-locals --simple-values\"\n"
3258 "-stack-list-locals --simple-values\n")
3259 gdb-stack-list-locals-handler)
3261 (defconst gdb-stack-list-locals-regexp
3262 "name=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
3264 (defvar gdb-locals-watch-map-1
3265 (let ((map (make-sparse-keymap)))
3266 (define-key map [mouse-2] 'gud-watch)
3268 "Keymap to create watch expression of a complex data type local variable.")
3270 ;; Dont display values of arrays or structures.
3271 ;; These can be expanded using gud-watch.
3272 (defun gdb-stack-list-locals-handler ()
3273 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals-1
3274 gdb-pending-triggers))
3275 (let (local locals-list)
3276 (goto-char (point-min))
3277 (while (re-search-forward gdb-stack-list-locals-regexp nil t)
3278 (let ((local (list (match-string 1)
3281 (if (looking-at ",value=\\(\".*\"\\)}")
3282 (setcar (nthcdr 2 local) (read (match-string 1))))
3283 (push local locals-list)))
3284 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
3285 (and buf (with-current-buffer buf
3286 (let* ((window (get-buffer-window buf 0))
3287 (start (window-start window))
3288 (p (window-point window))
3289 (buffer-read-only nil))
3291 (dolist (local locals-list)
3292 (setq name (car local))
3293 (if (or (not (nth 2 local))
3294 (string-match "\\*$" (nth 1 local)))
3295 (add-text-properties 0 (length name)
3296 `(mouse-face highlight
3297 help-echo "mouse-2: create watch expression"
3298 local-map ,gdb-locals-watch-map-1)
3301 (concat name "\t" (nth 1 local)
3302 "\t" (nth 2 local) "\n")))
3303 (set-window-start window start)
3304 (set-window-point window p)))))))
3306 (defun gdb-get-register-names ()
3307 "Create a list of register names."
3308 (goto-char (point-min))
3309 (setq gdb-register-names nil)
3310 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3311 (push (match-string 1) gdb-register-names)))
3315 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
3316 ;;; gdb-ui.el ends here