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
75 ;; 2) Cannot handle multiple debug sessions.
77 ;;; Problems with watch expressions:
79 ;; 1) They go out of scope when the inferior is re-run.
80 ;; 2) -var-update reports that an out of scope variable has changed:
81 ;; changelist=[{name="var1",in_scope="false"}], but the value can't be accessed.
82 ;; (-var-list-children, in contrast allows you to create variable objects of
83 ;; the children when they are out of scope and get their values).
84 ;; 3) VARNUM increments even when vaiable 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-timer-fn))
754 ;; Keep gdb-pending-triggers non-nil till end.
755 (push 'gdb-speedbar-timer gdb-pending-triggers)))
757 (defun gdb-speedbar-timer-fn ()
758 (setq gdb-pending-triggers
759 (delq 'gdb-speedbar-timer gdb-pending-triggers))
760 (with-current-buffer gud-comint-buffer
761 (speedbar-timer-fn)))
763 (defun gdb-var-delete ()
764 "Delete watch expression at point from the speedbar."
766 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
768 (let ((text (speedbar-line-text)))
769 (string-match "\\(\\S-+\\)" text)
770 (let* ((expr (match-string 1 text))
771 (var (assoc expr gdb-var-list))
773 (unless (string-match "\\." varnum)
776 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
778 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
779 (concat "-var-delete " varnum "\n"))
781 (setq gdb-var-list (delq var gdb-var-list))
782 (dolist (varchild gdb-var-list)
783 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
784 (setq gdb-var-list (delq varchild gdb-var-list)))))))))
786 (defun gdb-edit-value (text token indent)
787 "Assign a value to a variable displayed in the speedbar."
788 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
789 (varnum (cadr var)) (value))
790 (setq value (read-string "New value: "))
793 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
794 (concat "server interpreter mi \"-var-assign "
795 varnum " " value "\"\n")
796 (concat "-var-assign " varnum " " value "\n"))
799 (defcustom gdb-show-changed-values t
800 "If non-nil change the face of out of scope variables and changed values.
801 Out of scope variables are suppressed with `shadow' face.
802 Changed values are highlighted with the face `font-lock-warning-face'."
807 (defun gdb-speedbar-expand-node (text token indent)
808 "Expand the node the user clicked on.
809 TEXT is the text of the button we clicked on, a + or - item.
810 TOKEN is data related to this node.
811 INDENT is the current indentation depth."
812 (cond ((string-match "+" text) ;expand this node
814 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
815 (string-equal gdb-version "pre-6.4"))
816 (gdb-var-list-children token)
817 (gdb-var-list-children-1 token)))
818 ((string-match "-" text) ;contract this node
819 (dolist (var gdb-var-list)
820 (if (string-match (concat token "\\.") (nth 1 var))
821 (setq gdb-var-list (delq var gdb-var-list))))
822 (setq gdb-force-update t)
823 (with-current-buffer gud-comint-buffer
824 (speedbar-timer-fn)))))
826 (defun gdb-get-target-string ()
827 (with-current-buffer gud-comint-buffer
834 ;; Each buffer has a TYPE -- a symbol that identifies the function
835 ;; of that particular buffer.
837 ;; The usual gdb interaction buffer is given the type `gdba' and
838 ;; is constructed specially.
840 ;; Others are constructed by gdb-get-buffer-create and
841 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
843 (defvar gdb-buffer-rules-assoc '())
845 (defun gdb-get-buffer (key)
846 "Return the gdb buffer tagged with type KEY.
847 The key should be one of the cars in `gdb-buffer-rules-assoc'."
849 (gdb-look-for-tagged-buffer key (buffer-list))))
851 (defun gdb-get-buffer-create (key)
852 "Create a new gdb buffer of the type specified by KEY.
853 The key should be one of the cars in `gdb-buffer-rules-assoc'."
854 (or (gdb-get-buffer key)
855 (let* ((rules (assoc key gdb-buffer-rules-assoc))
856 (name (funcall (gdb-rules-name-maker rules)))
857 (new (get-buffer-create name)))
858 (with-current-buffer new
860 (if (cdr (cdr rules))
861 (setq trigger (funcall (car (cdr (cdr rules))))))
862 (setq gdb-buffer-type key)
863 (set (make-local-variable 'gud-minor-mode)
864 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
865 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
866 (if trigger (funcall trigger)))
869 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
871 (defun gdb-look-for-tagged-buffer (key bufs)
873 (while (and (not retval) bufs)
874 (set-buffer (car bufs))
875 (if (eq gdb-buffer-type key)
876 (setq retval (car bufs)))
877 (setq bufs (cdr bufs)))
881 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
882 ;; at least one and possible more functions. The functions have these
883 ;; roles in defining a buffer type:
885 ;; NAME - Return a name for this buffer type.
887 ;; The remaining function(s) are optional:
889 ;; MODE - called in a new buffer with no arguments, should establish
890 ;; the proper mode for the buffer.
893 (defun gdb-set-buffer-rules (buffer-type &rest rules)
894 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
896 (setcdr binding rules)
897 (push (cons buffer-type rules)
898 gdb-buffer-rules-assoc))))
900 ;; GUD buffers are an exception to the rules
901 (gdb-set-buffer-rules 'gdba 'error)
903 ;; Partial-output buffer : This accumulates output from a command executed on
904 ;; behalf of emacs (rather than the user).
906 (gdb-set-buffer-rules 'gdb-partial-output-buffer
907 'gdb-partial-output-name)
909 (defun gdb-partial-output-name ()
910 (concat "*partial-output-"
911 (gdb-get-target-string)
915 (gdb-set-buffer-rules 'gdb-inferior-io
916 'gdb-inferior-io-name
917 'gdb-inferior-io-mode)
919 (defun gdb-inferior-io-name ()
920 (concat "*input/output of "
921 (gdb-get-target-string)
924 (defun gdb-display-separate-io-buffer ()
925 "Display IO of debugged program in a separate window."
927 (if gdb-use-separate-io-buffer
929 (gdb-get-buffer-create 'gdb-inferior-io))))
931 (defconst gdb-frame-parameters
932 '((height . 14) (width . 80)
934 (tool-bar-lines . nil)
935 (menu-bar-lines . nil)
938 (defun gdb-frame-separate-io-buffer ()
939 "Display IO of inferior in a new frame."
941 (if gdb-use-separate-io-buffer
942 (let ((special-display-regexps (append special-display-regexps '(".*")))
943 (special-display-frame-alist gdb-frame-parameters))
944 (display-buffer (gdb-get-buffer-create 'gdb-inferior-io)))))
946 (defvar gdb-inferior-io-mode-map
947 (let ((map (make-sparse-keymap)))
948 (define-key map "\C-c\C-c" 'gdb-separate-io-interrupt)
949 (define-key map "\C-c\C-z" 'gdb-separate-io-stop)
950 (define-key map "\C-c\C-\\" 'gdb-separate-io-quit)
951 (define-key map "\C-c\C-d" 'gdb-separate-io-eof)
952 (define-key map "\C-d" 'gdb-separate-io-eof)
955 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
956 "Major mode for gdb inferior-io."
957 :syntax-table nil :abbrev-table nil
958 ;; We want to use comint because it has various nifty and familiar
959 ;; features. We don't need a process, but comint wants one, so create
961 (make-comint-in-buffer
962 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
963 (current-buffer) "hexl")
964 (setq comint-input-sender 'gdb-inferior-io-sender))
966 (defun gdb-inferior-io-sender (proc string)
967 ;; PROC is the pseudo-process created to satisfy comint.
968 (with-current-buffer (process-buffer proc)
969 (setq proc (get-buffer-process gud-comint-buffer))
970 (process-send-string proc string)
971 (process-send-string proc "\n")))
973 (defun gdb-separate-io-interrupt ()
974 "Interrupt the program being debugged."
977 (get-buffer-process gud-comint-buffer) comint-ptyp))
979 (defun gdb-separate-io-quit ()
980 "Send quit signal to the program being debugged."
983 (get-buffer-process gud-comint-buffer) comint-ptyp))
985 (defun gdb-separate-io-stop ()
986 "Stop the program being debugged."
989 (get-buffer-process gud-comint-buffer) comint-ptyp))
991 (defun gdb-separate-io-eof ()
992 "Send end-of-file to the program being debugged."
995 (get-buffer-process gud-comint-buffer)))
998 ;; gdb communications
1001 ;; INPUT: things sent to gdb
1003 ;; The queues are lists. Each element is either a string (indicating user or
1004 ;; user-like input) or a list of the form:
1006 ;; (INPUT-STRING HANDLER-FN)
1008 ;; The handler function will be called from the partial-output buffer when the
1009 ;; command completes. This is the way to write commands which invoke gdb
1010 ;; commands autonomously.
1012 ;; These lists are consumed tail first.
1015 (defun gdb-send (proc string)
1016 "A comint send filter for gdb.
1017 This filter may simply queue input for a later time."
1018 (with-current-buffer gud-comint-buffer
1019 (let ((inhibit-read-only t))
1020 (remove-text-properties (point-min) (point-max) '(face))))
1021 (let ((item (concat string "\n")))
1024 (if gdb-enable-debug (push (cons 'send item) gdb-debug-ring))
1025 (process-send-string proc item))
1026 (gdb-enqueue-input item))))
1028 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
1029 ;; is a query, or other non-top-level prompt.
1031 (defun gdb-enqueue-input (item)
1034 (gdb-send-item item)
1035 (setq gdb-prompting nil))
1036 (push item gdb-input-queue)))
1038 (defun gdb-dequeue-input ()
1039 (let ((queue gdb-input-queue))
1041 (let ((last (car (last queue))))
1042 (unless (nbutlast queue) (setq gdb-input-queue '()))
1045 (defun gdb-send-item (item)
1046 (setq gdb-flush-pending-output nil)
1047 (if gdb-enable-debug (push (cons 'send-item item) gdb-debug-ring))
1048 (setq gdb-current-item item)
1049 (let ((process (get-buffer-process gud-comint-buffer)))
1050 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1053 (setq gdb-output-sink 'user)
1054 (process-send-string process item))
1056 (gdb-clear-partial-output)
1057 (setq gdb-output-sink 'pre-emacs)
1058 (process-send-string process
1060 ;; case: eq gud-minor-mode 'gdbmi
1061 (gdb-clear-partial-output)
1062 (setq gdb-output-sink 'emacs)
1063 (process-send-string process (car item)))))
1066 ;; output -- things gdb prints to emacs
1068 ;; GDB output is a stream interrupted by annotations.
1069 ;; Annotations can be recognized by their beginning
1070 ;; with \C-j\C-z\C-z<tag><opt>\C-j
1072 ;; The tag is a string obeying symbol syntax.
1074 ;; The optional part `<opt>' can be either the empty string
1075 ;; or a space followed by more data relating to the annotation.
1076 ;; For example, the SOURCE annotation is followed by a filename,
1077 ;; line number and various useless goo. This data must not include
1081 (defcustom gud-gdba-command-name "gdb -annotate=3"
1082 "Default command to execute an executable under the GDB-UI debugger."
1087 (defvar gdb-annotation-rules
1088 '(("pre-prompt" gdb-pre-prompt)
1089 ("prompt" gdb-prompt)
1090 ("commands" gdb-subprompt)
1091 ("overload-choice" gdb-subprompt)
1092 ("query" gdb-subprompt)
1093 ;; Need this prompt for GDB 6.1
1094 ("nquery" gdb-subprompt)
1095 ("prompt-for-continue" gdb-subprompt)
1096 ("post-prompt" gdb-post-prompt)
1097 ("source" gdb-source)
1098 ("starting" gdb-starting)
1099 ("exited" gdb-exited)
1100 ("signalled" gdb-signalled)
1101 ("signal" gdb-stopping)
1102 ("breakpoint" gdb-stopping)
1103 ("watchpoint" gdb-stopping)
1104 ("frame-begin" gdb-frame-begin)
1105 ("stopped" gdb-stopped)
1106 ("error-begin" gdb-error)
1108 ) "An assoc mapping annotation tags to functions which process them.")
1111 (setq gdb-flush-pending-output t)
1112 (setq gud-running nil)
1113 (setq gdb-output-sink 'user)
1114 (setq gdb-input-queue nil)
1115 (setq gdb-pending-triggers nil)
1116 (setq gdb-prompting t))
1118 (defconst gdb-source-spec-regexp
1119 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
1121 ;; Do not use this except as an annotation handler.
1122 (defun gdb-source (args)
1123 (string-match gdb-source-spec-regexp args)
1124 ;; Extract the frame position from the marker.
1125 (setq gud-last-frame
1127 (match-string 1 args)
1128 (string-to-number (match-string 2 args))))
1129 (setq gdb-frame-address (match-string 3 args))
1130 ;; cover for auto-display output which comes *before*
1131 ;; stopped annotation
1132 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1134 (defun gdb-pre-prompt (ignored)
1135 "An annotation handler for `pre-prompt'.
1136 This terminates the collection of output from a previous command if that
1137 happens to be in effect."
1138 (setq gdb-error nil)
1139 (let ((sink gdb-output-sink))
1143 (setq gdb-output-sink 'post-emacs))
1146 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1148 (defun gdb-prompt (ignored)
1149 "An annotation handler for `prompt'.
1150 This sends the next command (if any) to gdb."
1151 (when gdb-first-prompt
1153 (setq gdb-first-prompt nil))
1154 (let ((sink gdb-output-sink))
1157 ((eq sink 'post-emacs)
1158 (setq gdb-output-sink 'user)
1160 (car (cdr gdb-current-item))))
1161 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1162 (funcall handler))))
1165 (error "Phase error in gdb-prompt (got %s)" sink))))
1166 (let ((input (gdb-dequeue-input)))
1168 (gdb-send-item input)
1170 (setq gdb-prompting t)
1171 (gud-display-frame)))))
1173 (defun gdb-subprompt (ignored)
1174 "An annotation handler for non-top-level prompts."
1175 (setq gdb-prompting t))
1177 (defun gdb-starting (ignored)
1178 "An annotation handler for `starting'.
1179 This says that I/O for the subprocess is now the program being debugged,
1181 (setq gdb-active-process t)
1182 (let ((sink gdb-output-sink))
1186 (setq gud-running t)
1187 (if gdb-use-separate-io-buffer
1188 (setq gdb-output-sink 'inferior))))
1191 (error "Unexpected `starting' annotation")))))
1193 (defun gdb-stopping (ignored)
1194 "An annotation handler for `breakpoint' and other annotations.
1195 They say that I/O for the subprocess is now GDB, not the program
1197 (if gdb-use-separate-io-buffer
1198 (let ((sink gdb-output-sink))
1200 ((eq sink 'inferior)
1201 (setq gdb-output-sink 'user))
1204 (error "Unexpected stopping annotation"))))))
1206 (defun gdb-exited (ignored)
1207 "An annotation handler for `exited' and `signalled'.
1208 They say that I/O for the subprocess is now GDB, not the program
1209 being debugged and that the program is no longer running. This
1210 function is used to change the focus of GUD tooltips to #define
1212 (setq gdb-active-process nil)
1213 (setq gud-overlay-arrow-position nil)
1214 (setq gdb-overlay-arrow-position nil)
1215 (gdb-stopping ignored))
1217 (defun gdb-signalled (ignored)
1218 (setq gdb-signalled t))
1220 (defun gdb-frame-begin (ignored)
1221 (let ((sink gdb-output-sink))
1223 ((eq sink 'inferior)
1224 (setq gdb-output-sink 'user))
1226 ((eq sink 'emacs) t)
1229 (error "Unexpected frame-begin annotation (%S)" sink)))))
1231 (defun gdb-stopped (ignored)
1232 "An annotation handler for `stopped'.
1233 It is just like `gdb-stopping', except that if we already set the output
1234 sink to `user' in `gdb-stopping', that is fine."
1235 (setq gud-running nil)
1236 (let ((sink gdb-output-sink))
1238 ((eq sink 'inferior)
1239 (setq gdb-output-sink 'user))
1243 (error "Unexpected stopped annotation"))))
1244 (if gdb-signalled (gdb-exited ignored)))
1246 (defun gdb-error (ignored)
1247 (setq gdb-error (not gdb-error)))
1249 (defun gdb-post-prompt (ignored)
1250 "An annotation handler for `post-prompt'.
1251 This begins the collection of output from the current command if that
1252 happens to be appropriate."
1253 ;; Don't add to queue if there outstanding items or GDB is not known yet.
1254 (unless (or gdb-pending-triggers gdb-first-post-prompt)
1255 (gdb-get-selected-frame)
1256 (gdb-invalidate-frames)
1257 ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
1258 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
1259 (gdb-invalidate-breakpoints)
1260 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1261 ;; so gdb-frame-address is updated.
1262 ;; (gdb-invalidate-assembler)
1264 (if (string-equal gdb-version "pre-6.4")
1265 (gdb-invalidate-registers)
1266 (gdb-get-changed-registers)
1267 (gdb-invalidate-registers-1))
1269 (gdb-invalidate-memory)
1270 (if (string-equal gdb-version "pre-6.4")
1271 (gdb-invalidate-locals)
1272 (gdb-invalidate-locals-1))
1274 (gdb-invalidate-threads)
1275 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1276 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1277 ;; Only needed/used with speedbar/watch expressions.
1278 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1279 (setq gdb-force-update t)
1280 (if (string-equal gdb-version "pre-6.4")
1282 (gdb-var-update-1)))))
1283 (setq gdb-first-post-prompt nil)
1284 (let ((sink gdb-output-sink))
1287 ((eq sink 'pre-emacs)
1288 (setq gdb-output-sink 'emacs))
1291 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1293 ;; GUD displays the selected GDB frame. This might might not be the current
1294 ;; GDB frame (after up, down etc). If no GDB frame is visible but the last
1295 ;; visited breakpoint is, use that window.
1296 (defun gdb-display-source-buffer (buffer)
1297 (let* ((last-window (if gud-last-last-frame
1299 (gud-find-file (car gud-last-last-frame)))))
1300 (source-window (or last-window
1301 (if (and gdb-source-window
1302 (window-live-p gdb-source-window))
1303 gdb-source-window))))
1305 (setq gdb-source-window source-window)
1306 (set-window-buffer source-window buffer))
1309 (defun gud-gdba-marker-filter (string)
1310 "A gud marker filter for gdb. Handle a burst of output from GDB."
1311 (if gdb-flush-pending-output
1313 (when gdb-enable-debug
1314 (push (cons 'recv string) gdb-debug-ring)
1315 (if (> (length gdb-debug-ring) gdb-debug-ring-max)
1316 (setcdr (nthcdr (1- gdb-debug-ring-max) gdb-debug-ring) nil)))
1317 ;; Recall the left over gud-marker-acc from last time.
1318 (setq gud-marker-acc (concat gud-marker-acc string))
1319 ;; Start accumulating output for the GUD buffer.
1322 ;; Process all the complete markers in this chunk.
1323 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1324 (let ((annotation (match-string 1 gud-marker-acc)))
1326 ;; Stuff prior to the match is just ordinary output.
1327 ;; It is either concatenated to OUTPUT or directed
1332 (substring gud-marker-acc 0 (match-beginning 0))))
1334 ;; Take that stuff off the gud-marker-acc.
1335 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1337 ;; Parse the tag from the annotation, and maybe its arguments.
1338 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1339 (let* ((annotation-type (match-string 1 annotation))
1340 (annotation-arguments (match-string 2 annotation))
1341 (annotation-rule (assoc annotation-type
1342 gdb-annotation-rules)))
1343 ;; Call the handler for this annotation.
1345 (funcall (car (cdr annotation-rule))
1346 annotation-arguments)
1347 ;; Else the annotation is not recognized. Ignore it silently,
1348 ;; so that GDB can add new annotations without causing
1352 ;; Does the remaining text end in a partial line?
1353 ;; If it does, then keep part of the gud-marker-acc until we get more.
1354 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1357 ;; Everything before the potential marker start can be output.
1359 (gdb-concat-output output
1360 (substring gud-marker-acc 0
1361 (match-beginning 0))))
1363 ;; Everything after, we save, to combine with later input.
1364 (setq gud-marker-acc (substring gud-marker-acc
1365 (match-beginning 0))))
1367 ;; In case we know the gud-marker-acc contains no partial annotations:
1369 (setq output (gdb-concat-output output gud-marker-acc))
1370 (setq gud-marker-acc "")))
1373 (defun gdb-concat-output (so-far new)
1375 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1376 (let ((sink gdb-output-sink))
1378 ((eq sink 'user) (concat so-far new))
1379 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1381 (gdb-append-to-partial-output new)
1383 ((eq sink 'inferior)
1384 (gdb-append-to-inferior-io new)
1388 (error "Bogon output sink %S" sink)))))
1390 (defun gdb-append-to-partial-output (string)
1391 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1392 (goto-char (point-max))
1395 (defun gdb-clear-partial-output ()
1396 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1399 (defun gdb-append-to-inferior-io (string)
1400 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1401 (goto-char (point-max))
1402 (insert-before-markers string))
1403 (if (not (string-equal string ""))
1404 (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io))))
1406 (defun gdb-clear-inferior-io ()
1407 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1411 ;; One trick is to have a command who's output is always available in a buffer
1412 ;; of it's own, and is always up to date. We build several buffers of this
1415 ;; There are two aspects to this: gdb has to tell us when the output for that
1416 ;; command might have changed, and we have to be able to run the command
1417 ;; behind the user's back.
1419 ;; The output phasing associated with the variable gdb-output-sink
1420 ;; help us to run commands behind the user's back.
1422 ;; Below is the code for specificly managing buffers of output from one
1426 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1427 ;; It adds an input for the command we are tracking. It should be the
1428 ;; annotation rule binding of whatever gdb sends to tell us this command
1429 ;; might have changed it's output.
1431 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1432 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1433 ;; input in the input queue (see comment about ``gdb communications'' above).
1435 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1437 `(defun ,name (&optional ignored)
1438 (if (and ,demand-predicate
1440 gdb-pending-triggers)))
1443 (list ,gdb-command ',output-handler))
1444 (push ',name gdb-pending-triggers)))))
1446 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1448 (setq gdb-pending-triggers
1450 gdb-pending-triggers))
1451 (let ((buf (gdb-get-buffer ',buf-key)))
1453 (with-current-buffer buf
1454 (let* ((window (get-buffer-window buf 0))
1455 (start (window-start window))
1456 (p (window-point window))
1457 (buffer-read-only nil))
1459 (insert-buffer-substring (gdb-get-buffer-create
1460 'gdb-partial-output-buffer))
1461 (set-window-start window start)
1462 (set-window-point window p)))))
1463 ;; put customisation here
1466 (defmacro def-gdb-auto-updated-buffer (buffer-key
1467 trigger-name gdb-command
1468 output-handler-name custom-defun)
1470 (def-gdb-auto-update-trigger ,trigger-name
1471 ;; The demand predicate:
1472 (gdb-get-buffer ',buffer-key)
1474 ,output-handler-name)
1475 (def-gdb-auto-update-handler ,output-handler-name
1476 ,trigger-name ,buffer-key ,custom-defun)))
1480 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1482 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1483 'gdb-breakpoints-buffer-name
1484 'gdb-breakpoints-mode)
1486 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1487 ;; This defines the auto update rule for buffers of type
1488 ;; `gdb-breakpoints-buffer'.
1490 ;; It defines a function to serve as the annotation handler that
1491 ;; handles the `foo-invalidated' message. That function is called:
1492 gdb-invalidate-breakpoints
1494 ;; To update the buffer, this command is sent to gdb.
1495 "server info breakpoints\n"
1497 ;; This also defines a function to be the handler for the output
1498 ;; from the command above. That function will copy the output into
1499 ;; the appropriately typed buffer. That function will be called:
1500 gdb-info-breakpoints-handler
1501 ;; buffer specific functions
1502 gdb-info-breakpoints-custom)
1504 (defconst breakpoint-xpm-data
1506 static char *magick[] = {
1507 /* columns rows colors chars-per-pixel */
1523 "XPM data used for breakpoint icon.")
1525 (defconst breakpoint-enabled-pbm-data
1528 0 0 0 0 1 1 1 1 0 0 0 0
1529 0 0 0 1 1 1 1 1 1 0 0 0
1530 0 0 1 1 1 1 1 1 1 1 0 0
1531 0 1 1 1 1 1 1 1 1 1 1 0
1532 0 1 1 1 1 1 1 1 1 1 1 0
1533 0 1 1 1 1 1 1 1 1 1 1 0
1534 0 1 1 1 1 1 1 1 1 1 1 0
1535 0 0 1 1 1 1 1 1 1 1 0 0
1536 0 0 0 1 1 1 1 1 1 0 0 0
1537 0 0 0 0 1 1 1 1 0 0 0 0"
1538 "PBM data used for enabled breakpoint icon.")
1540 (defconst breakpoint-disabled-pbm-data
1552 0 0 0 1 0 1 0 1 0 0"
1553 "PBM data used for disabled breakpoint icon.")
1555 (defvar breakpoint-enabled-icon nil
1556 "Icon for enabled breakpoint in display margin.")
1558 (defvar breakpoint-disabled-icon nil
1559 "Icon for disabled breakpoint in display margin.")
1561 ;; Bitmap for breakpoint in fringe
1562 (and (display-images-p)
1563 (define-fringe-bitmap 'breakpoint
1564 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1566 (defface breakpoint-enabled
1570 "Face for enabled breakpoint icon in fringe."
1573 (defface breakpoint-disabled
1574 ;; We use different values of grey for different background types,
1575 ;; so that on low-color displays it will end up as something visible
1576 ;; if it has to be approximated.
1577 '((((background dark)) :foreground "grey60")
1578 (((background light)) :foreground "grey40"))
1579 "Face for disabled breakpoint icon in fringe."
1582 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1583 (defun gdb-info-breakpoints-custom ()
1584 (let ((flag) (bptno))
1585 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1586 (dolist (buffer (buffer-list))
1587 (with-current-buffer buffer
1588 (if (and (memq gud-minor-mode '(gdba gdbmi))
1589 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1590 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1591 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1593 (goto-char (point-min))
1594 (while (< (point) (- (point-max) 1))
1596 (if (looking-at "[^\t].*?breakpoint")
1598 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1599 (setq bptno (match-string 1))
1600 (setq flag (char-after (match-beginning 2)))
1602 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1604 (let ((buffer-read-only nil))
1605 (add-text-properties (match-beginning 1) (match-end 1)
1606 '(face font-lock-function-name-face)))
1607 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1608 (let ((line (match-string 2)) (buffer-read-only nil)
1609 (file (match-string 1)))
1610 (add-text-properties (line-beginning-position)
1612 '(mouse-face highlight
1613 help-echo "mouse-2, RET: visit breakpoint"))
1614 (unless (file-exists-p file)
1615 (setq file (cdr (assoc bptno gdb-location-alist))))
1617 (not (string-equal file "File not found")))
1618 (with-current-buffer
1619 (find-file-noselect file 'nowarn)
1620 (set (make-local-variable 'gud-minor-mode)
1622 (set (make-local-variable 'tool-bar-map)
1624 ;; Only want one breakpoint icon at each
1627 (goto-line (string-to-number line))
1628 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1631 (concat gdb-server-prefix "list "
1632 (match-string-no-properties 1) ":1\n")
1635 (list (concat gdb-server-prefix "info source\n")
1636 `(lambda () (gdb-get-location
1637 ,bptno ,line ,flag))))))))))
1639 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1641 (defun gdb-mouse-set-clear-breakpoint (event)
1642 "Set/clear breakpoint in left fringe/margin with mouse click."
1644 (mouse-minibuffer-check event)
1645 (let ((posn (event-end event)))
1646 (if (numberp (posn-point posn))
1647 (with-selected-window (posn-window posn)
1649 (goto-char (posn-point posn))
1650 (if (or (posn-object posn)
1651 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1654 (gud-break nil)))))))
1656 (defun gdb-mouse-toggle-breakpoint-margin (event)
1657 "Enable/disable breakpoint in left margin with mouse click."
1659 (mouse-minibuffer-check event)
1660 (let ((posn (event-end event)))
1661 (if (numberp (posn-point posn))
1662 (with-selected-window (posn-window posn)
1664 (goto-char (posn-point posn))
1665 (if (posn-object posn)
1668 (let ((bptno (get-text-property
1669 0 'gdb-bptno (car (posn-string posn)))))
1670 (concat gdb-server-prefix
1671 (if (get-text-property
1672 0 'gdb-enabled (car (posn-string posn)))
1678 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1679 "Enable/disable breakpoint in left fringe with mouse click."
1681 (mouse-minibuffer-check event)
1682 (let* ((posn (event-end event))
1683 (pos (posn-point posn))
1686 (with-selected-window (posn-window posn)
1688 (set-buffer (window-buffer (selected-window)))
1690 (dolist (overlay (overlays-in pos pos))
1691 (when (overlay-get overlay 'put-break)
1692 (setq obj (overlay-get overlay 'before-string))))
1696 (concat gdb-server-prefix
1697 (if (get-text-property 0 'gdb-enabled obj)
1700 (get-text-property 0 'gdb-bptno obj) "\n")
1703 (defun gdb-breakpoints-buffer-name ()
1704 (with-current-buffer gud-comint-buffer
1705 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1707 (defun gdb-display-breakpoints-buffer ()
1708 "Display status of user-settable breakpoints."
1711 (gdb-get-buffer-create 'gdb-breakpoints-buffer)))
1713 (defun gdb-frame-breakpoints-buffer ()
1714 "Display status of user-settable breakpoints in a new frame."
1716 (let ((special-display-regexps (append special-display-regexps '(".*")))
1717 (special-display-frame-alist gdb-frame-parameters))
1718 (display-buffer (gdb-get-buffer-create 'gdb-breakpoints-buffer))))
1720 (defvar gdb-breakpoints-mode-map
1721 (let ((map (make-sparse-keymap))
1722 (menu (make-sparse-keymap "Breakpoints")))
1723 (define-key menu [quit] '("Quit" . gdb-delete-frame-or-window))
1724 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1725 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1726 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1727 (suppress-keymap map)
1728 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1729 (define-key map " " 'gdb-toggle-breakpoint)
1730 (define-key map "D" 'gdb-delete-breakpoint)
1731 ;; Don't bind "q" to kill-this-buffer as we need it for breakpoint icons.
1732 (define-key map "q" 'gdb-delete-frame-or-window)
1733 (define-key map "\r" 'gdb-goto-breakpoint)
1734 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1735 (define-key map [follow-link] 'mouse-face)
1738 (defun gdb-delete-frame-or-window ()
1739 "Delete frame if there is only one window. Otherwise delete the window."
1741 (if (one-window-p) (delete-frame)
1744 (defun gdb-breakpoints-mode ()
1745 "Major mode for gdb breakpoints.
1747 \\{gdb-breakpoints-mode-map}"
1748 (kill-all-local-variables)
1749 (setq major-mode 'gdb-breakpoints-mode)
1750 (setq mode-name "Breakpoints")
1751 (use-local-map gdb-breakpoints-mode-map)
1752 (setq buffer-read-only t)
1753 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1754 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1755 'gdb-invalidate-breakpoints
1756 'gdbmi-invalidate-breakpoints))
1758 (defconst gdb-breakpoint-regexp
1759 "\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1761 (defun gdb-toggle-breakpoint ()
1762 "Enable/disable breakpoint at current line."
1765 (beginning-of-line 1)
1766 (if (looking-at gdb-breakpoint-regexp)
1769 (concat gdb-server-prefix
1770 (if (eq ?y (char-after (match-beginning 2)))
1773 (match-string 1) "\n") 'ignore))
1774 (error "Not recognized as break/watchpoint line"))))
1776 (defun gdb-delete-breakpoint ()
1777 "Delete the breakpoint at current line."
1779 (beginning-of-line 1)
1780 (if (looking-at gdb-breakpoint-regexp)
1783 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1784 (error "Not recognized as break/watchpoint line")))
1786 (defun gdb-goto-breakpoint (&optional event)
1787 "Display the breakpoint location specified at current line."
1788 (interactive (list last-input-event))
1789 (if event (posn-set-point (event-end event)))
1791 (beginning-of-line 1)
1792 (if (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1793 (let ((bptno (match-string 1))
1794 (file (match-string 2))
1795 (line (match-string 3)))
1796 (save-selected-window
1797 (let* ((buffer (find-file-noselect
1798 (if (file-exists-p file) file
1799 (cdr (assoc bptno gdb-location-alist)))))
1800 (window (unless (gdb-display-source-buffer buffer)
1801 (display-buffer buffer))))
1802 (setq gdb-source-window window)
1803 (with-current-buffer buffer
1804 (goto-line (string-to-number line))
1805 (set-window-point window (point))))))
1806 (error "No location specified."))))
1809 ;; Frames buffer. This displays a perpetually correct bactracktrace
1810 ;; (from the command `where').
1812 ;; Alas, if your stack is deep, it is costly.
1814 (gdb-set-buffer-rules 'gdb-stack-buffer
1815 'gdb-stack-buffer-name
1818 (def-gdb-auto-updated-buffer gdb-stack-buffer
1819 gdb-invalidate-frames
1821 gdb-info-frames-handler
1822 gdb-info-frames-custom)
1824 (defun gdb-info-frames-custom ()
1825 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1827 (let ((buffer-read-only nil)
1829 (goto-char (point-min))
1830 (while (< (point) (point-max))
1831 (setq bl (line-beginning-position)
1832 el (line-end-position))
1833 (when (looking-at "#")
1834 (add-text-properties bl el
1835 '(mouse-face highlight
1836 help-echo "mouse-2, RET: Select frame")))
1838 (when (looking-at "^#\\([0-9]+\\)")
1839 (when (string-equal (match-string 1) gdb-frame-number)
1840 (put-text-property bl (+ bl 4)
1841 'face '(:inverse-video t)))
1842 (when (re-search-forward
1844 (if (string-equal (match-string 1) "0") "" " in ")
1845 "\\([^ ]+\\) (") el t)
1846 (put-text-property (match-beginning 1) (match-end 1)
1847 'face font-lock-function-name-face)
1848 (setq bl (match-end 0))
1849 (while (re-search-forward "<\\([^>]+\\)>" el t)
1850 (put-text-property (match-beginning 1) (match-end 1)
1851 'face font-lock-function-name-face))
1853 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1854 (put-text-property (match-beginning 1) (match-end 1)
1855 'face font-lock-variable-name-face))))
1856 (forward-line 1))))))
1858 (defun gdb-stack-buffer-name ()
1859 (with-current-buffer gud-comint-buffer
1860 (concat "*stack frames of " (gdb-get-target-string) "*")))
1862 (defun gdb-display-stack-buffer ()
1863 "Display backtrace of current stack."
1866 (gdb-get-buffer-create 'gdb-stack-buffer)))
1868 (defun gdb-frame-stack-buffer ()
1869 "Display backtrace of current stack in a new frame."
1871 (let ((special-display-regexps (append special-display-regexps '(".*")))
1872 (special-display-frame-alist gdb-frame-parameters))
1873 (display-buffer (gdb-get-buffer-create 'gdb-stack-buffer))))
1875 (defvar gdb-frames-mode-map
1876 (let ((map (make-sparse-keymap)))
1877 (suppress-keymap map)
1878 (define-key map "q" 'kill-this-buffer)
1879 (define-key map "\r" 'gdb-frames-select)
1880 (define-key map [mouse-2] 'gdb-frames-select)
1881 (define-key map [follow-link] 'mouse-face)
1884 (defun gdb-frames-mode ()
1885 "Major mode for gdb frames.
1887 \\{gdb-frames-mode-map}"
1888 (kill-all-local-variables)
1889 (setq major-mode 'gdb-frames-mode)
1890 (setq mode-name "Frames")
1891 (setq buffer-read-only t)
1892 (use-local-map gdb-frames-mode-map)
1893 (run-mode-hooks 'gdb-frames-mode-hook)
1894 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1895 'gdb-invalidate-frames
1896 'gdbmi-invalidate-frames))
1898 (defun gdb-get-frame-number ()
1901 (let* ((start (line-beginning-position))
1902 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
1903 (n (or (and pos (match-string-no-properties 1)) "0")))
1906 (defun gdb-frames-select (&optional event)
1907 "Select the frame and display the relevant source."
1908 (interactive (list last-input-event))
1909 (if event (posn-set-point (event-end event)))
1911 (list (concat gdb-server-prefix "frame "
1912 (gdb-get-frame-number) "\n") 'ignore))
1913 (gud-display-frame))
1916 ;; Threads buffer. This displays a selectable thread list.
1918 (gdb-set-buffer-rules 'gdb-threads-buffer
1919 'gdb-threads-buffer-name
1922 (def-gdb-auto-updated-buffer gdb-threads-buffer
1923 gdb-invalidate-threads
1924 (concat gdb-server-prefix "info threads\n")
1925 gdb-info-threads-handler
1926 gdb-info-threads-custom)
1928 (defun gdb-info-threads-custom ()
1929 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1930 (let ((buffer-read-only nil))
1931 (goto-char (point-min))
1932 (while (< (point) (point-max))
1933 (unless (looking-at "No ")
1934 (add-text-properties (line-beginning-position) (line-end-position)
1935 '(mouse-face highlight
1936 help-echo "mouse-2, RET: select thread")))
1937 (forward-line 1)))))
1939 (defun gdb-threads-buffer-name ()
1940 (with-current-buffer gud-comint-buffer
1941 (concat "*threads of " (gdb-get-target-string) "*")))
1943 (defun gdb-display-threads-buffer ()
1944 "Display IDs of currently known threads."
1947 (gdb-get-buffer-create 'gdb-threads-buffer)))
1949 (defun gdb-frame-threads-buffer ()
1950 "Display IDs of currently known threads in a new frame."
1952 (let ((special-display-regexps (append special-display-regexps '(".*")))
1953 (special-display-frame-alist gdb-frame-parameters))
1954 (display-buffer (gdb-get-buffer-create 'gdb-threads-buffer))))
1956 (defvar gdb-threads-mode-map
1957 (let ((map (make-sparse-keymap)))
1958 (suppress-keymap map)
1959 (define-key map "q" 'kill-this-buffer)
1960 (define-key map "\r" 'gdb-threads-select)
1961 (define-key map [mouse-2] 'gdb-threads-select)
1962 (define-key map [follow-link] 'mouse-face)
1965 (defvar gdb-threads-font-lock-keywords
1967 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1968 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1969 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1971 "Font lock keywords used in `gdb-threads-mode'.")
1973 (defun gdb-threads-mode ()
1974 "Major mode for gdb frames.
1976 \\{gdb-threads-mode-map}"
1977 (kill-all-local-variables)
1978 (setq major-mode 'gdb-threads-mode)
1979 (setq mode-name "Threads")
1980 (setq buffer-read-only t)
1981 (use-local-map gdb-threads-mode-map)
1982 (set (make-local-variable 'font-lock-defaults)
1983 '(gdb-threads-font-lock-keywords))
1984 (run-mode-hooks 'gdb-threads-mode-hook)
1985 'gdb-invalidate-threads)
1987 (defun gdb-get-thread-number ()
1989 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1990 (match-string-no-properties 1)))
1992 (defun gdb-threads-select (&optional event)
1993 "Select the thread and display the relevant source."
1994 (interactive (list last-input-event))
1995 (if event (posn-set-point (event-end event)))
1997 (list (concat gdb-server-prefix "thread "
1998 (gdb-get-thread-number) "\n") 'ignore))
1999 (gud-display-frame))
2002 ;; Registers buffer.
2004 (defcustom gdb-all-registers nil
2005 "Non-nil means include floating-point registers."
2010 (gdb-set-buffer-rules 'gdb-registers-buffer
2011 'gdb-registers-buffer-name
2012 'gdb-registers-mode)
2014 (def-gdb-auto-updated-buffer gdb-registers-buffer
2015 gdb-invalidate-registers
2017 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
2018 gdb-info-registers-handler
2019 gdb-info-registers-custom)
2021 (defun gdb-info-registers-custom ()
2022 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2024 (let ((buffer-read-only nil)
2026 (goto-char (point-min))
2027 (while (< (point) (point-max))
2028 (setq start (line-beginning-position))
2029 (setq end (line-end-position))
2030 (when (looking-at "^[^ ]+")
2031 (unless (string-equal (match-string 0) "The")
2032 (put-text-property start (match-end 0)
2033 'face font-lock-variable-name-face)
2034 (add-text-properties start end
2035 '(help-echo "mouse-2: edit value"
2036 mouse-face highlight))))
2037 (forward-line 1))))))
2039 (defun gdb-edit-register-value (&optional event)
2040 (interactive (list last-input-event))
2042 (if event (posn-set-point (event-end event)))
2044 (let* ((register (current-word))
2045 (value (read-string (format "New value (%s): " register))))
2047 (list (concat gdb-server-prefix "set $" register "=" value "\n")
2050 (defvar gdb-registers-mode-map
2051 (let ((map (make-sparse-keymap)))
2052 (suppress-keymap map)
2053 (define-key map "\r" 'gdb-edit-register-value)
2054 (define-key map [mouse-2] 'gdb-edit-register-value)
2055 (define-key map " " 'gdb-all-registers)
2056 (define-key map "q" 'kill-this-buffer)
2059 (defun gdb-registers-mode ()
2060 "Major mode for gdb registers.
2062 \\{gdb-registers-mode-map}"
2063 (kill-all-local-variables)
2064 (setq major-mode 'gdb-registers-mode)
2065 (setq mode-name "Registers")
2066 (setq buffer-read-only t)
2067 (use-local-map gdb-registers-mode-map)
2068 (run-mode-hooks 'gdb-registers-mode-hook)
2069 (if (string-equal gdb-version "pre-6.4")
2071 (if gdb-all-registers (setq mode-name "Registers:All"))
2072 'gdb-invalidate-registers)
2073 'gdb-invalidate-registers-1))
2075 (defun gdb-registers-buffer-name ()
2076 (with-current-buffer gud-comint-buffer
2077 (concat "*registers of " (gdb-get-target-string) "*")))
2079 (defun gdb-display-registers-buffer ()
2080 "Display integer register contents."
2083 (gdb-get-buffer-create 'gdb-registers-buffer)))
2085 (defun gdb-frame-registers-buffer ()
2086 "Display integer register contents in a new frame."
2088 (let ((special-display-regexps (append special-display-regexps '(".*")))
2089 (special-display-frame-alist gdb-frame-parameters))
2090 (display-buffer (gdb-get-buffer-create 'gdb-registers-buffer))))
2092 (defun gdb-all-registers ()
2093 "Toggle the display of floating-point registers (pre GDB 6.4 only)."
2095 (when (string-equal gdb-version "pre-6.4")
2096 (if gdb-all-registers
2098 (setq gdb-all-registers nil)
2099 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2100 (setq mode-name "Registers")))
2101 (setq gdb-all-registers t)
2102 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2103 (setq mode-name "Registers:All")))
2104 (message (format "Display of floating-point registers %sabled"
2105 (if gdb-all-registers "en" "dis")))
2106 (gdb-invalidate-registers)))
2111 (defcustom gdb-memory-repeat-count 32
2112 "Number of data items in memory window."
2117 (defcustom gdb-memory-format "x"
2118 "Display format of data items in memory window."
2119 :type '(choice (const :tag "Hexadecimal" "x")
2120 (const :tag "Signed decimal" "d")
2121 (const :tag "Unsigned decimal" "u")
2122 (const :tag "Octal" "o")
2123 (const :tag "Binary" "t"))
2127 (defcustom gdb-memory-unit "w"
2128 "Unit size of data items in memory window."
2129 :type '(choice (const :tag "Byte" "b")
2130 (const :tag "Halfword" "h")
2131 (const :tag "Word" "w")
2132 (const :tag "Giant word" "g"))
2136 (gdb-set-buffer-rules 'gdb-memory-buffer
2137 'gdb-memory-buffer-name
2140 (def-gdb-auto-updated-buffer gdb-memory-buffer
2141 gdb-invalidate-memory
2142 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
2143 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
2144 gdb-read-memory-handler
2145 gdb-read-memory-custom)
2147 (defun gdb-read-memory-custom ()
2149 (goto-char (point-min))
2150 (if (looking-at "0x[[:xdigit:]]+")
2151 (setq gdb-memory-address (match-string 0)))))
2153 (defvar gdb-memory-mode-map
2154 (let ((map (make-sparse-keymap)))
2155 (suppress-keymap map)
2156 (define-key map "q" 'kill-this-buffer)
2159 (defun gdb-memory-set-address (event)
2160 "Set the start memory address."
2162 (save-selected-window
2163 (select-window (posn-window (event-start event)))
2164 (let ((arg (read-from-minibuffer "Memory address: ")))
2165 (setq gdb-memory-address arg))
2166 (gdb-invalidate-memory)))
2168 (defun gdb-memory-set-repeat-count (event)
2169 "Set the number of data items in memory window."
2171 (save-selected-window
2172 (select-window (posn-window (event-start event)))
2173 (let* ((arg (read-from-minibuffer "Repeat count: "))
2174 (count (string-to-number arg)))
2176 (error "Positive numbers only")
2177 (customize-set-variable 'gdb-memory-repeat-count count)
2178 (gdb-invalidate-memory)))))
2180 (defun gdb-memory-format-binary ()
2181 "Set the display format to binary."
2183 (customize-set-variable 'gdb-memory-format "t")
2184 (gdb-invalidate-memory))
2186 (defun gdb-memory-format-octal ()
2187 "Set the display format to octal."
2189 (customize-set-variable 'gdb-memory-format "o")
2190 (gdb-invalidate-memory))
2192 (defun gdb-memory-format-unsigned ()
2193 "Set the display format to unsigned decimal."
2195 (customize-set-variable 'gdb-memory-format "u")
2196 (gdb-invalidate-memory))
2198 (defun gdb-memory-format-signed ()
2199 "Set the display format to decimal."
2201 (customize-set-variable 'gdb-memory-format "d")
2202 (gdb-invalidate-memory))
2204 (defun gdb-memory-format-hexadecimal ()
2205 "Set the display format to hexadecimal."
2207 (customize-set-variable 'gdb-memory-format "x")
2208 (gdb-invalidate-memory))
2210 (defvar gdb-memory-format-map
2211 (let ((map (make-sparse-keymap)))
2212 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2214 "Keymap to select format in the header line.")
2216 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2217 "Menu of display formats in the header line.")
2219 (define-key gdb-memory-format-menu [binary]
2220 '(menu-item "Binary" gdb-memory-format-binary
2221 :button (:radio . (equal gdb-memory-format "t"))))
2222 (define-key gdb-memory-format-menu [octal]
2223 '(menu-item "Octal" gdb-memory-format-octal
2224 :button (:radio . (equal gdb-memory-format "o"))))
2225 (define-key gdb-memory-format-menu [unsigned]
2226 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2227 :button (:radio . (equal gdb-memory-format "u"))))
2228 (define-key gdb-memory-format-menu [signed]
2229 '(menu-item "Signed Decimal" gdb-memory-format-signed
2230 :button (:radio . (equal gdb-memory-format "d"))))
2231 (define-key gdb-memory-format-menu [hexadecimal]
2232 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2233 :button (:radio . (equal gdb-memory-format "x"))))
2235 (defun gdb-memory-format-menu (event)
2237 (x-popup-menu event gdb-memory-format-menu))
2239 (defun gdb-memory-format-menu-1 (event)
2241 (save-selected-window
2242 (select-window (posn-window (event-start event)))
2243 (let* ((selection (gdb-memory-format-menu event))
2244 (binding (and selection (lookup-key gdb-memory-format-menu
2245 (vector (car selection))))))
2246 (if binding (call-interactively binding)))))
2248 (defun gdb-memory-unit-giant ()
2249 "Set the unit size to giant words (eight bytes)."
2251 (customize-set-variable 'gdb-memory-unit "g")
2252 (gdb-invalidate-memory))
2254 (defun gdb-memory-unit-word ()
2255 "Set the unit size to words (four bytes)."
2257 (customize-set-variable 'gdb-memory-unit "w")
2258 (gdb-invalidate-memory))
2260 (defun gdb-memory-unit-halfword ()
2261 "Set the unit size to halfwords (two bytes)."
2263 (customize-set-variable 'gdb-memory-unit "h")
2264 (gdb-invalidate-memory))
2266 (defun gdb-memory-unit-byte ()
2267 "Set the unit size to bytes."
2269 (customize-set-variable 'gdb-memory-unit "b")
2270 (gdb-invalidate-memory))
2272 (defvar gdb-memory-unit-map
2273 (let ((map (make-sparse-keymap)))
2274 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2276 "Keymap to select units in the header line.")
2278 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2279 "Menu of units in the header line.")
2281 (define-key gdb-memory-unit-menu [giantwords]
2282 '(menu-item "Giant words" gdb-memory-unit-giant
2283 :button (:radio . (equal gdb-memory-unit "g"))))
2284 (define-key gdb-memory-unit-menu [words]
2285 '(menu-item "Words" gdb-memory-unit-word
2286 :button (:radio . (equal gdb-memory-unit "w"))))
2287 (define-key gdb-memory-unit-menu [halfwords]
2288 '(menu-item "Halfwords" gdb-memory-unit-halfword
2289 :button (:radio . (equal gdb-memory-unit "h"))))
2290 (define-key gdb-memory-unit-menu [bytes]
2291 '(menu-item "Bytes" gdb-memory-unit-byte
2292 :button (:radio . (equal gdb-memory-unit "b"))))
2294 (defun gdb-memory-unit-menu (event)
2296 (x-popup-menu event gdb-memory-unit-menu))
2298 (defun gdb-memory-unit-menu-1 (event)
2300 (save-selected-window
2301 (select-window (posn-window (event-start event)))
2302 (let* ((selection (gdb-memory-unit-menu event))
2303 (binding (and selection (lookup-key gdb-memory-unit-menu
2304 (vector (car selection))))))
2305 (if binding (call-interactively binding)))))
2307 ;;from make-mode-line-mouse-map
2308 (defun gdb-make-header-line-mouse-map (mouse function) "\
2309 Return a keymap with single entry for mouse key MOUSE on the header line.
2310 MOUSE is defined to run function FUNCTION with no args in the buffer
2311 corresponding to the mode line clicked."
2312 (let ((map (make-sparse-keymap)))
2313 (define-key map (vector 'header-line mouse) function)
2314 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2317 (defvar gdb-memory-font-lock-keywords
2318 '(;; <__function.name+n>
2319 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2321 "Font lock keywords used in `gdb-memory-mode'.")
2323 (defun gdb-memory-mode ()
2324 "Major mode for examining memory.
2326 \\{gdb-memory-mode-map}"
2327 (kill-all-local-variables)
2328 (setq major-mode 'gdb-memory-mode)
2329 (setq mode-name "Memory")
2330 (setq buffer-read-only t)
2331 (use-local-map gdb-memory-mode-map)
2332 (setq header-line-format
2338 'face font-lock-warning-face
2339 'help-echo "mouse-1: Decrement address"
2340 'mouse-face 'mode-line-highlight
2342 (gdb-make-header-line-mouse-map
2344 #'(lambda () (interactive)
2345 (let ((gdb-memory-address
2346 ;; Let GDB do the arithmetic.
2348 gdb-memory-address " - "
2350 (* gdb-memory-repeat-count
2351 (cond ((string= gdb-memory-unit "b") 1)
2352 ((string= gdb-memory-unit "h") 2)
2353 ((string= gdb-memory-unit "w") 4)
2354 ((string= gdb-memory-unit "g") 8)))))))
2355 (gdb-invalidate-memory)))))
2358 'face font-lock-warning-face
2359 'help-echo "mouse-1: Increment address"
2360 'mouse-face 'mode-line-highlight
2361 'local-map (gdb-make-header-line-mouse-map
2363 #'(lambda () (interactive)
2364 (let ((gdb-memory-address nil))
2365 (gdb-invalidate-memory)))))
2367 (propertize gdb-memory-address
2368 'face font-lock-warning-face
2369 'help-echo "mouse-1: Set memory address"
2370 'mouse-face 'mode-line-highlight
2371 'local-map (gdb-make-header-line-mouse-map
2373 #'gdb-memory-set-address))
2375 (propertize (number-to-string gdb-memory-repeat-count)
2376 'face font-lock-warning-face
2377 'help-echo "mouse-1: Set repeat count"
2378 'mouse-face 'mode-line-highlight
2379 'local-map (gdb-make-header-line-mouse-map
2381 #'gdb-memory-set-repeat-count))
2383 (propertize gdb-memory-format
2384 'face font-lock-warning-face
2385 'help-echo "mouse-3: Select display format"
2386 'mouse-face 'mode-line-highlight
2387 'local-map gdb-memory-format-map)
2389 (propertize gdb-memory-unit
2390 'face font-lock-warning-face
2391 'help-echo "mouse-3: Select unit size"
2392 'mouse-face 'mode-line-highlight
2393 'local-map gdb-memory-unit-map))))
2394 (set (make-local-variable 'font-lock-defaults)
2395 '(gdb-memory-font-lock-keywords))
2396 (run-mode-hooks 'gdb-memory-mode-hook)
2397 'gdb-invalidate-memory)
2399 (defun gdb-memory-buffer-name ()
2400 (with-current-buffer gud-comint-buffer
2401 (concat "*memory of " (gdb-get-target-string) "*")))
2403 (defun gdb-display-memory-buffer ()
2404 "Display memory contents."
2407 (gdb-get-buffer-create 'gdb-memory-buffer)))
2409 (defun gdb-frame-memory-buffer ()
2410 "Display memory contents in a new frame."
2412 (let ((special-display-regexps (append special-display-regexps '(".*")))
2413 (special-display-frame-alist gdb-frame-parameters))
2414 (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
2419 (gdb-set-buffer-rules 'gdb-locals-buffer
2420 'gdb-locals-buffer-name
2423 (def-gdb-auto-update-trigger gdb-invalidate-locals
2424 (gdb-get-buffer 'gdb-locals-buffer)
2425 "server info locals\n"
2426 gdb-info-locals-handler)
2428 (defvar gdb-locals-watch-map
2429 (let ((map (make-sparse-keymap)))
2430 (define-key map "\r" '(lambda () (interactive)
2433 (define-key map [mouse-2] '(lambda (event) (interactive "e")
2434 (mouse-set-point event)
2438 "Keymap to create watch expression of a complex data type local variable.")
2440 (defconst gdb-struct-string
2441 (concat (propertize "[struct/union]"
2442 'mouse-face 'highlight
2443 'help-echo "mouse-2: create watch expression"
2444 'local-map gdb-locals-watch-map) "\n"))
2446 (defconst gdb-array-string
2447 (concat " " (propertize "[array]"
2448 'mouse-face 'highlight
2449 'help-echo "mouse-2: create watch expression"
2450 'local-map gdb-locals-watch-map) "\n"))
2452 ;; Abbreviate for arrays and structures.
2453 ;; These can be expanded using gud-display.
2454 (defun gdb-info-locals-handler ()
2455 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2456 gdb-pending-triggers))
2457 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2458 (with-current-buffer buf
2459 (goto-char (point-min))
2460 (while (re-search-forward "^[ }].*\n" nil t)
2461 (replace-match "" nil nil))
2462 (goto-char (point-min))
2463 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2464 (replace-match gdb-struct-string nil nil))
2465 (goto-char (point-min))
2466 (while (re-search-forward "\\s-*{.*\n" nil t)
2467 (replace-match gdb-array-string nil nil))))
2468 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2470 (with-current-buffer buf
2471 (let* ((window (get-buffer-window buf 0))
2472 (start (window-start window))
2473 (p (window-point window))
2474 (buffer-read-only nil))
2476 (insert-buffer-substring (gdb-get-buffer-create
2477 'gdb-partial-output-buffer))
2478 (set-window-start window start)
2479 (set-window-point window p))
2481 (run-hooks 'gdb-info-locals-hook))
2483 (defvar gdb-locals-mode-map
2484 (let ((map (make-sparse-keymap)))
2485 (suppress-keymap map)
2486 (define-key map "q" 'kill-this-buffer)
2489 (defun gdb-locals-mode ()
2490 "Major mode for gdb locals.
2492 \\{gdb-locals-mode-map}"
2493 (kill-all-local-variables)
2494 (setq major-mode 'gdb-locals-mode)
2495 (setq mode-name (concat "Locals:" gdb-selected-frame))
2496 (setq buffer-read-only t)
2497 (use-local-map gdb-locals-mode-map)
2498 (set (make-local-variable 'font-lock-defaults)
2499 '(gdb-locals-font-lock-keywords))
2500 (run-mode-hooks 'gdb-locals-mode-hook)
2501 (if (and (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2502 (string-equal gdb-version "pre-6.4"))
2503 'gdb-invalidate-locals
2504 'gdb-invalidate-locals-1))
2506 (defun gdb-locals-buffer-name ()
2507 (with-current-buffer gud-comint-buffer
2508 (concat "*locals of " (gdb-get-target-string) "*")))
2510 (defun gdb-display-locals-buffer ()
2511 "Display local variables of current stack and their values."
2514 (gdb-get-buffer-create 'gdb-locals-buffer)))
2516 (defun gdb-frame-locals-buffer ()
2517 "Display local variables of current stack and their values in a new frame."
2519 (let ((special-display-regexps (append special-display-regexps '(".*")))
2520 (special-display-frame-alist gdb-frame-parameters))
2521 (display-buffer (gdb-get-buffer-create 'gdb-locals-buffer))))
2524 ;;;; Window management
2525 (defun gdb-display-buffer (buf &optional size)
2526 (let ((answer (get-buffer-window buf 0))
2529 (display-buffer buf nil 0) ;Raise the frame if necessary.
2530 ;; The buffer is not yet displayed.
2531 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2532 (let ((window (get-lru-window)))
2534 (not (eq window (get-buffer-window gud-comint-buffer))))
2536 (set-window-buffer window buf)
2537 (setq answer window))
2538 (setq must-split t)))
2540 (let* ((largest (get-largest-window))
2541 (cur-size (window-height largest))
2542 (new-size (and size (< size cur-size) (- cur-size size))))
2543 (setq answer (split-window largest new-size))
2544 (set-window-buffer answer buf)
2545 (set-window-dedicated-p answer t)))
2549 ;;; Shared keymap initialization:
2551 (let ((menu (make-sparse-keymap "GDB-Windows")))
2552 (define-key gud-menu-map [displays]
2553 `(menu-item "GDB-Windows" ,menu
2554 :visible (memq gud-minor-mode '(gdbmi gdba))))
2555 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2556 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2557 (define-key menu [inferior]
2558 '(menu-item "Inferior IO" gdb-display-separate-io-buffer
2559 :enable gdb-use-separate-io-buffer))
2560 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2561 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2562 (define-key menu [disassembly]
2563 '("Disassembly" . gdb-display-assembler-buffer))
2564 (define-key menu [breakpoints]
2565 '("Breakpoints" . gdb-display-breakpoints-buffer))
2566 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2567 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)))
2569 (let ((menu (make-sparse-keymap "GDB-Frames")))
2570 (define-key gud-menu-map [frames]
2571 `(menu-item "GDB-Frames" ,menu
2572 :visible (memq gud-minor-mode '(gdbmi gdba))))
2573 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2574 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2575 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2576 (define-key menu [inferior]
2577 '(menu-item "Inferior IO" gdb-frame-separate-io-buffer
2578 :enable gdb-use-separate-io-buffer))
2579 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2580 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2581 (define-key menu [breakpoints]
2582 '("Breakpoints" . gdb-frame-breakpoints-buffer))
2583 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2584 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)))
2586 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2587 (define-key gud-menu-map [ui]
2588 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2589 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2590 (define-key menu [gdb-use-separate-io]
2591 '(menu-item "Separate inferior IO" gdb-use-separate-io-buffer
2592 :visible (eq gud-minor-mode 'gdba)
2593 :help "Toggle separate IO for inferior."
2594 :button (:toggle . gdb-use-separate-io-buffer)))
2595 (define-key menu [gdb-many-windows]
2596 '(menu-item "Display Other Windows" gdb-many-windows
2597 :help "Toggle display of locals, stack and breakpoint information"
2598 :button (:toggle . gdb-many-windows)))
2599 (define-key menu [gdb-restore-windows]
2600 '(menu-item "Restore Window Layout" gdb-restore-windows
2601 :help "Restore standard layout for debug session.")))
2603 (defun gdb-frame-gdb-buffer ()
2604 "Display GUD buffer in a new frame."
2606 (let ((special-display-regexps (append special-display-regexps '(".*")))
2607 (special-display-frame-alist gdb-frame-parameters)
2608 (same-window-regexps nil))
2609 (display-buffer gud-comint-buffer)))
2611 (defun gdb-display-gdb-buffer ()
2612 "Display GUD buffer."
2614 (let ((same-window-regexps nil))
2615 (pop-to-buffer gud-comint-buffer)))
2617 (defun gdb-set-window-buffer (name)
2618 (set-window-buffer (selected-window) (get-buffer name))
2619 (set-window-dedicated-p (selected-window) t))
2621 (defun gdb-setup-windows ()
2622 "Layout the window pattern for `gdb-many-windows'."
2623 (gdb-display-locals-buffer)
2624 (gdb-display-stack-buffer)
2625 (delete-other-windows)
2626 (gdb-display-breakpoints-buffer)
2627 (delete-other-windows)
2629 (pop-to-buffer gud-comint-buffer)
2630 (split-window nil ( / ( * (window-height) 3) 4))
2631 (split-window nil ( / (window-height) 3))
2632 (split-window-horizontally)
2634 (gdb-set-window-buffer (gdb-locals-buffer-name))
2637 (if gud-last-last-frame
2638 (gud-find-file (car gud-last-last-frame))
2639 (gud-find-file gdb-main-file)))
2640 (when gdb-use-separate-io-buffer
2641 (split-window-horizontally)
2643 (gdb-set-window-buffer
2644 (gdb-get-buffer-create 'gdb-inferior-io)))
2646 (gdb-set-window-buffer (gdb-stack-buffer-name))
2647 (split-window-horizontally)
2649 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2652 (defcustom gdb-many-windows nil
2653 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2654 In this case it starts with two windows: one displaying the GUD
2655 buffer and the other with the source file with the main routine
2656 of the inferior. Non-nil means display the layout shown for
2662 (defun gdb-many-windows (arg)
2663 "Toggle the number of windows in the basic arrangement.
2664 With arg, display additional buffers iff arg is positive."
2666 (setq gdb-many-windows
2668 (not gdb-many-windows)
2669 (> (prefix-numeric-value arg) 0)))
2670 (message (format "Display of other windows %sabled"
2671 (if gdb-many-windows "en" "dis")))
2672 (if (and gud-comint-buffer
2673 (buffer-name gud-comint-buffer))
2675 (gdb-restore-windows)
2678 (defun gdb-restore-windows ()
2679 "Restore the basic arrangement of windows used by gdba.
2680 This arrangement depends on the value of `gdb-many-windows'."
2682 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2683 (delete-other-windows)
2684 (if gdb-many-windows
2686 (when (or gud-last-last-frame gdb-show-main)
2690 (if gud-last-last-frame
2691 (gud-find-file (car gud-last-last-frame))
2692 (gud-find-file gdb-main-file)))
2696 "Exit a debugging session cleanly.
2697 Kills the gdb buffers and resets the source buffers."
2698 (dolist (buffer (buffer-list))
2699 (unless (eq buffer gud-comint-buffer)
2700 (with-current-buffer buffer
2701 (if (memq gud-minor-mode '(gdbmi gdba))
2702 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2704 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2705 (setq gud-minor-mode nil)
2706 (kill-local-variable 'tool-bar-map)
2707 (kill-local-variable 'gdb-define-alist))))))
2708 (when (markerp gdb-overlay-arrow-position)
2709 (move-marker gdb-overlay-arrow-position nil)
2710 (setq gdb-overlay-arrow-position nil))
2711 (setq overlay-arrow-variable-list
2712 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2713 (if (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
2715 (setq gud-running nil)
2716 (setq gdb-active-process nil)
2717 (setq gdb-var-list nil)
2718 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2720 (defun gdb-source-info ()
2721 "Find the source file where the program starts and displays it with related
2723 (goto-char (point-min))
2724 (if (and (search-forward "Located in " nil t)
2725 (looking-at "\\S-+"))
2726 (setq gdb-main-file (match-string 0)))
2727 (goto-char (point-min))
2728 (if (search-forward "Includes preprocessor macro info." nil t)
2729 (setq gdb-macro-info t))
2730 (if gdb-many-windows
2732 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
2734 (let ((pop-up-windows t))
2735 (display-buffer (gud-find-file gdb-main-file))))))
2737 (defun gdb-get-location (bptno line flag)
2738 "Find the directory containing the relevant source file.
2739 Put in buffer and place breakpoint icon."
2740 (goto-char (point-min))
2741 (catch 'file-not-found
2742 (if (search-forward "Located in " nil t)
2743 (when (looking-at "\\S-+")
2744 (delete (cons bptno "File not found") gdb-location-alist)
2745 (push (cons bptno (match-string 0)) gdb-location-alist))
2747 (unless (assoc bptno gdb-location-alist)
2748 (push (cons bptno "File not found") gdb-location-alist)
2749 (message-box "Cannot find source file for breakpoint location.\n\
2750 Add directory to search path for source files using the GDB command, dir."))
2751 (throw 'file-not-found nil))
2752 (with-current-buffer
2753 (find-file-noselect (match-string 0))
2754 (save-current-buffer
2755 (set (make-local-variable 'gud-minor-mode) 'gdba)
2756 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2757 ;; only want one breakpoint icon at each location
2759 (goto-line (string-to-number line))
2760 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2762 (add-hook 'find-file-hook 'gdb-find-file-hook)
2764 (defun gdb-find-file-hook ()
2765 "Set up buffer for debugging if file is part of the source code
2766 of the current session."
2767 (if (and (buffer-name gud-comint-buffer)
2768 ;; in case gud or gdb-ui is just loaded
2770 (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2772 (if (member buffer-file-name gdb-source-file-list)
2773 (with-current-buffer (find-buffer-visiting buffer-file-name)
2774 (set (make-local-variable 'gud-minor-mode)
2775 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
2776 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)))))
2779 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2780 "Put string PUTSTRING in front of POS in the current buffer.
2781 PUTSTRING is displayed by putting an overlay into the current buffer with a
2782 `before-string' string that has a `display' property whose value is
2784 (let ((string (make-string 1 ?x))
2785 (buffer (current-buffer)))
2786 (setq putstring (copy-sequence putstring))
2787 (let ((overlay (make-overlay pos pos buffer))
2789 (list (list 'margin 'left-margin) putstring))))
2790 (put-text-property 0 1 'display prop string)
2792 (add-text-properties 0 1 sprops string))
2793 (overlay-put overlay 'put-break t)
2794 (overlay-put overlay 'before-string string))))
2796 ;;from remove-images
2797 (defun gdb-remove-strings (start end &optional buffer)
2798 "Remove strings between START and END in BUFFER.
2799 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2800 BUFFER nil or omitted means use the current buffer."
2802 (setq buffer (current-buffer)))
2803 (dolist (overlay (overlays-in start end))
2804 (when (overlay-get overlay 'put-break)
2805 (delete-overlay overlay))))
2807 (defun gdb-put-breakpoint-icon (enabled bptno)
2808 (let ((start (- (line-beginning-position) 1))
2809 (end (+ (line-end-position) 1))
2810 (putstring (if enabled "B" "b"))
2811 (source-window (get-buffer-window (current-buffer) 0)))
2812 (add-text-properties
2813 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2816 (add-text-properties
2817 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2818 (add-text-properties
2819 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2820 (gdb-remove-breakpoint-icons start end)
2821 (if (display-images-p)
2822 (if (>= (or left-fringe-width
2823 (if source-window (car (window-fringes source-window)))
2824 gdb-buffer-fringe-width) 8)
2827 `(left-fringe breakpoint
2830 'breakpoint-disabled))
2832 'gdb-enabled enabled)
2833 (when (< left-margin-width 2)
2834 (save-current-buffer
2835 (setq left-margin-width 2)
2839 left-margin-width right-margin-width))))
2842 (or breakpoint-enabled-icon
2843 (setq breakpoint-enabled-icon
2844 (find-image `((:type xpm :data
2845 ,breakpoint-xpm-data
2846 :ascent 100 :pointer hand)
2848 ,breakpoint-enabled-pbm-data
2849 :ascent 100 :pointer hand)))))
2850 (or breakpoint-disabled-icon
2851 (setq breakpoint-disabled-icon
2852 (find-image `((:type xpm :data
2853 ,breakpoint-xpm-data
2854 :conversion disabled
2855 :ascent 100 :pointer hand)
2857 ,breakpoint-disabled-pbm-data
2858 :ascent 100 :pointer hand))))))
2862 (when (< left-margin-width 2)
2863 (save-current-buffer
2864 (setq left-margin-width 2)
2865 (let ((window (get-buffer-window (current-buffer) 0)))
2868 window left-margin-width right-margin-width)))))
2870 (propertize putstring
2871 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2874 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2875 (gdb-remove-strings start end)
2876 (if (display-images-p)
2877 (remove-images start end))
2879 (setq left-margin-width 0)
2880 (let ((window (get-buffer-window (current-buffer) 0)))
2883 window left-margin-width right-margin-width)))))
2887 ;; Assembler buffer.
2889 (gdb-set-buffer-rules 'gdb-assembler-buffer
2890 'gdb-assembler-buffer-name
2891 'gdb-assembler-mode)
2893 (def-gdb-auto-update-handler gdb-assembler-handler
2894 gdb-invalidate-assembler
2895 gdb-assembler-buffer
2896 gdb-assembler-custom)
2898 (defun gdb-assembler-custom ()
2899 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2900 (pos 1) (address) (flag) (bptno))
2901 (with-current-buffer buffer
2903 (if (not (equal gdb-frame-address "main"))
2905 (goto-char (point-min))
2906 (if (and gdb-frame-address
2907 (search-forward gdb-frame-address nil t))
2911 (or gdb-overlay-arrow-position
2912 (setq gdb-overlay-arrow-position (make-marker)))
2913 (set-marker gdb-overlay-arrow-position
2914 (point) (current-buffer))))))
2915 ;; remove all breakpoint-icons in assembler buffer before updating.
2916 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2917 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2918 (goto-char (point-min))
2919 (while (< (point) (- (point-max) 1))
2921 (if (looking-at "[^\t].*?breakpoint")
2924 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2925 (setq bptno (match-string 1))
2926 (setq flag (char-after (match-beginning 2)))
2927 (setq address (match-string 3))
2928 (with-current-buffer buffer
2930 (goto-char (point-min))
2931 (if (search-forward address nil t)
2932 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2933 (if (not (equal gdb-frame-address "main"))
2934 (with-current-buffer buffer
2935 (set-window-point (get-buffer-window buffer 0) pos)))))
2937 (defvar gdb-assembler-mode-map
2938 (let ((map (make-sparse-keymap)))
2939 (suppress-keymap map)
2940 (define-key map "q" 'kill-this-buffer)
2943 (defvar gdb-assembler-font-lock-keywords
2944 '(;; <__function.name+n>
2945 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2946 (1 font-lock-function-name-face))
2947 ;; 0xNNNNNNNN <__function.name+n>: opcode
2948 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2949 (4 font-lock-keyword-face))
2950 ;; %register(at least i386)
2951 ("%\\sw+" . font-lock-variable-name-face)
2952 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2953 (1 font-lock-comment-face)
2954 (2 font-lock-function-name-face))
2955 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2956 "Font lock keywords used in `gdb-assembler-mode'.")
2958 (defun gdb-assembler-mode ()
2959 "Major mode for viewing code assembler.
2961 \\{gdb-assembler-mode-map}"
2962 (kill-all-local-variables)
2963 (setq major-mode 'gdb-assembler-mode)
2964 (setq mode-name (concat "Machine:" gdb-selected-frame))
2965 (setq gdb-overlay-arrow-position nil)
2966 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2967 (setq fringes-outside-margins t)
2968 (setq buffer-read-only t)
2969 (use-local-map gdb-assembler-mode-map)
2970 (gdb-invalidate-assembler)
2971 (set (make-local-variable 'font-lock-defaults)
2972 '(gdb-assembler-font-lock-keywords))
2973 (run-mode-hooks 'gdb-assembler-mode-hook)
2974 'gdb-invalidate-assembler)
2976 (defun gdb-assembler-buffer-name ()
2977 (with-current-buffer gud-comint-buffer
2978 (concat "*disassembly of " (gdb-get-target-string) "*")))
2980 (defun gdb-display-assembler-buffer ()
2981 "Display disassembly view."
2983 (setq gdb-previous-frame nil)
2985 (gdb-get-buffer-create 'gdb-assembler-buffer)))
2987 (defun gdb-frame-assembler-buffer ()
2988 "Display disassembly view in a new frame."
2990 (setq gdb-previous-frame nil)
2991 (let ((special-display-regexps (append special-display-regexps '(".*")))
2992 (special-display-frame-alist gdb-frame-parameters))
2993 (display-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))))
2995 ;; modified because if gdb-frame-address has changed value a new command
2996 ;; must be enqueued to update the buffer with the new output
2997 (defun gdb-invalidate-assembler (&optional ignored)
2998 (if (gdb-get-buffer 'gdb-assembler-buffer)
3000 (unless (and gdb-selected-frame
3001 (string-equal gdb-selected-frame gdb-previous-frame))
3002 (if (or (not (member 'gdb-invalidate-assembler
3003 gdb-pending-triggers))
3004 (not (string-equal gdb-frame-address
3005 gdb-previous-frame-address)))
3007 ;; take previous disassemble command, if any, off the queue
3008 (with-current-buffer gud-comint-buffer
3009 (let ((queue gdb-input-queue))
3010 (dolist (item queue)
3011 (if (equal (cdr item) '(gdb-assembler-handler))
3012 (setq gdb-input-queue
3013 (delete item gdb-input-queue))))))
3016 (concat gdb-server-prefix "disassemble "
3017 (if (member gdb-frame-address '(nil "main")) nil "0x")
3018 gdb-frame-address "\n")
3019 'gdb-assembler-handler))
3020 (push 'gdb-invalidate-assembler gdb-pending-triggers)
3021 (setq gdb-previous-frame-address gdb-frame-address)
3022 (setq gdb-previous-frame gdb-selected-frame)))))))
3024 (defun gdb-get-selected-frame ()
3025 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
3028 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
3029 (push 'gdb-get-selected-frame
3030 gdb-pending-triggers))))
3032 (defun gdb-frame-handler ()
3033 (setq gdb-pending-triggers
3034 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3035 (goto-char (point-min))
3036 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
3037 (setq gdb-frame-number (match-string 1)))
3038 (goto-char (point-min))
3039 (if (re-search-forward
3040 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
3042 (setq gdb-selected-frame (match-string 2))
3043 (if (gdb-get-buffer 'gdb-locals-buffer)
3044 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3045 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3046 (if (gdb-get-buffer 'gdb-assembler-buffer)
3047 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3048 (setq mode-name (concat "Machine:" gdb-selected-frame))))
3049 (setq gdb-frame-address (match-string 1))))
3050 (goto-char (point-min))
3051 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
3052 (setq gdb-current-language (match-string 1)))
3053 (gdb-invalidate-assembler))
3056 ;; Code specific to GDB 6.4
3057 (defconst gdb-source-file-regexp-1 "fullname=\"\\(.*?\\)\"")
3059 (defun gdb-set-gud-minor-mode-existing-buffers-1 ()
3060 "Create list of source files for current GDB session.
3061 If buffers already exist for any of these files, gud-minor-mode
3063 (goto-char (point-min))
3064 (while (re-search-forward gdb-source-file-regexp-1 nil t)
3065 (push (match-string 1) gdb-source-file-list))
3066 (dolist (buffer (buffer-list))
3067 (with-current-buffer buffer
3068 (when (member buffer-file-name gdb-source-file-list)
3069 (set (make-local-variable 'gud-minor-mode)
3070 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
3071 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
3072 (when gud-tooltip-mode
3073 (make-local-variable 'gdb-define-alist)
3074 (gdb-create-define-alist)
3075 (add-hook 'after-save-hook 'gdb-create-define-alist nil t))))))
3077 ; Uses "-var-list-children --all-values". Needs GDB 6.1 onwards.
3078 (defun gdb-var-list-children-1 (varnum)
3081 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3082 (concat "server interpreter mi \"-var-list-children --all-values "
3084 (concat "-var-list-children --all-values " varnum "\n"))
3085 `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
3087 (defconst gdb-var-list-children-regexp-1
3088 "name=\"\\(.+?\\)\",exp=\"\\(.+?\\)\",numchild=\"\\(.+?\\)\",\
3089 value=\\(\".*?\"\\),type=\"\\(.+?\\)\"}")
3091 (defun gdb-var-list-children-handler-1 (varnum)
3092 (goto-char (point-min))
3093 (let ((var-list nil))
3094 (catch 'child-already-watched
3095 (dolist (var gdb-var-list)
3096 (if (string-equal varnum (cadr var))
3099 (while (re-search-forward gdb-var-list-children-regexp-1 nil t)
3100 (let ((varchild (list (match-string 2)
3104 (read (match-string 4))
3106 (dolist (var1 gdb-var-list)
3107 (if (string-equal (cadr var1) (cadr varchild))
3108 (throw 'child-already-watched nil)))
3109 (push varchild var-list))))
3110 (push var var-list)))
3111 (setq gdb-var-list (nreverse var-list)))))
3113 ; Uses "-var-update --all-values". Needs GDB 6.4 onwards.
3114 (defun gdb-var-update-1 ()
3115 (if (not (member 'gdb-var-update gdb-pending-triggers))
3119 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3120 "server interpreter mi \"-var-update --all-values *\"\n"
3121 "-var-update --all-values *\n")
3122 'gdb-var-update-handler-1))
3123 (push 'gdb-var-update gdb-pending-triggers))))
3125 (defconst gdb-var-update-regexp-1
3126 "name=\"\\(.*?\\)\",\\(?:value=\\(\".*?\"\\),\\)?in_scope=\"\\(.*?\\)\"")
3128 (defun gdb-var-update-handler-1 ()
3129 (dolist (var gdb-var-list)
3130 (setcar (nthcdr 5 var) nil))
3131 (goto-char (point-min))
3132 (while (re-search-forward gdb-var-update-regexp-1 nil t)
3133 (let ((varnum (match-string 1)))
3135 (dolist (var gdb-var-list)
3136 (when (string-equal varnum (cadr var))
3137 (if (string-equal (match-string 3) "false")
3138 (setcar (nthcdr 5 var) 'out-of-scope)
3139 (setcar (nthcdr 5 var) 'changed)
3140 (setcar (nthcdr 4 var)
3141 (read (match-string 2))))
3142 (throw 'var-found nil))))))
3143 (setq gdb-pending-triggers
3144 (delq 'gdb-var-update gdb-pending-triggers))
3145 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
3146 ;; dummy command to update speedbar at right time
3147 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
3148 ;; keep gdb-pending-triggers non-nil till end
3149 (push 'gdb-speedbar-timer gdb-pending-triggers)))
3151 ;; Registers buffer.
3153 (gdb-set-buffer-rules 'gdb-registers-buffer
3154 'gdb-registers-buffer-name
3155 'gdb-registers-mode)
3157 (def-gdb-auto-update-trigger gdb-invalidate-registers-1
3158 (gdb-get-buffer 'gdb-registers-buffer)
3159 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3160 "server interpreter mi \"-data-list-register-values x\"\n"
3161 "-data-list-register-values x\n")
3162 gdb-data-list-register-values-handler)
3164 (defconst gdb-data-list-register-values-regexp
3165 "number=\"\\(.*?\\)\",value=\"\\(.*?\\)\"")
3167 (defun gdb-data-list-register-values-handler ()
3168 (setq gdb-pending-triggers (delq 'gdb-invalidate-registers-1
3169 gdb-pending-triggers))
3170 (goto-char (point-min))
3171 (if (re-search-forward gdb-error-regexp nil t)
3172 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3173 (let ((buffer-read-only nil))
3175 (insert (match-string 1))
3176 (goto-char (point-min))))
3177 (let ((register-list (reverse gdb-register-names))
3178 (register nil) (register-string nil) (register-values nil))
3179 (goto-char (point-min))
3180 (while (re-search-forward gdb-data-list-register-values-regexp nil t)
3181 (setq register (pop register-list))
3182 (setq register-string (concat register "\t" (match-string 2) "\n"))
3183 (if (member (match-string 1) gdb-changed-registers)
3184 (put-text-property 0 (length register-string)
3185 'face 'font-lock-warning-face
3187 (setq register-values
3188 (concat register-values register-string)))
3189 (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
3190 (with-current-buffer buf
3191 (let* ((window (get-buffer-window buf 0))
3192 (start (window-start window))
3193 (p (window-point window))
3194 (buffer-read-only nil))
3196 (insert register-values)
3197 (set-window-start window start)
3198 (set-window-point window p))))))
3199 (gdb-data-list-register-values-custom))
3201 (defun gdb-data-list-register-values-custom ()
3202 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3204 (let ((buffer-read-only nil)
3206 (goto-char (point-min))
3207 (while (< (point) (point-max))
3208 (setq start (line-beginning-position))
3209 (setq end (line-end-position))
3210 (when (looking-at "^[^\t]+")
3211 (unless (string-equal (match-string 0) "No registers.")
3212 (put-text-property start (match-end 0)
3213 'face font-lock-variable-name-face)
3214 (add-text-properties start end
3215 '(help-echo "mouse-2: edit value"
3216 mouse-face highlight))))
3217 (forward-line 1))))))
3219 ;; Needs GDB 6.4 onwards (used to fail with no stack).
3220 (defun gdb-get-changed-registers ()
3221 (if (and (gdb-get-buffer 'gdb-registers-buffer)
3222 (not (member 'gdb-get-changed-registers gdb-pending-triggers)))
3226 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3227 "server interpreter mi -data-list-changed-registers\n"
3228 "-data-list-changed-registers\n")
3229 'gdb-get-changed-registers-handler))
3230 (push 'gdb-get-changed-registers gdb-pending-triggers))))
3232 (defconst gdb-data-list-register-names-regexp "\"\\(.*?\\)\"")
3234 (defun gdb-get-changed-registers-handler ()
3235 (setq gdb-pending-triggers
3236 (delq 'gdb-get-changed-registers gdb-pending-triggers))
3237 (setq gdb-changed-registers nil)
3238 (goto-char (point-min))
3239 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3240 (push (match-string 1) gdb-changed-registers)))
3245 ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards.
3246 (gdb-set-buffer-rules 'gdb-locals-buffer
3247 'gdb-locals-buffer-name
3250 (def-gdb-auto-update-trigger gdb-invalidate-locals-1
3251 (gdb-get-buffer 'gdb-locals-buffer)
3252 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3253 "server interpreter mi -\"stack-list-locals --simple-values\"\n"
3254 "-stack-list-locals --simple-values\n")
3255 gdb-stack-list-locals-handler)
3257 (defconst gdb-stack-list-locals-regexp
3258 "name=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
3260 (defvar gdb-locals-watch-map-1
3261 (let ((map (make-sparse-keymap)))
3262 (define-key map [mouse-2] 'gud-watch)
3264 "Keymap to create watch expression of a complex data type local variable.")
3266 ;; Dont display values of arrays or structures.
3267 ;; These can be expanded using gud-watch.
3268 (defun gdb-stack-list-locals-handler ()
3269 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals-1
3270 gdb-pending-triggers))
3271 (let (local locals-list)
3272 (goto-char (point-min))
3273 (while (re-search-forward gdb-stack-list-locals-regexp nil t)
3274 (let ((local (list (match-string 1)
3277 (if (looking-at ",value=\\(\".*\"\\)}")
3278 (setcar (nthcdr 2 local) (read (match-string 1))))
3279 (push local locals-list)))
3280 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
3281 (and buf (with-current-buffer buf
3282 (let* ((window (get-buffer-window buf 0))
3283 (start (window-start window))
3284 (p (window-point window))
3285 (buffer-read-only nil))
3287 (dolist (local locals-list)
3288 (setq name (car local))
3289 (if (or (not (nth 2 local))
3290 (string-match "\\*$" (nth 1 local)))
3291 (add-text-properties 0 (length name)
3292 `(mouse-face highlight
3293 help-echo "mouse-2: create watch expression"
3294 local-map ,gdb-locals-watch-map-1)
3297 (concat name "\t" (nth 1 local)
3298 "\t" (nth 2 local) "\n")))
3299 (set-window-start window start)
3300 (set-window-point window p)))))))
3302 (defun gdb-get-register-names ()
3303 "Create a list of register names."
3304 (goto-char (point-min))
3305 (setq gdb-register-names nil)
3306 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3307 (push (match-string 1) gdb-register-names)))
3311 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
3312 ;;; gdb-ui.el ends here