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, 2007, 2008
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 3, 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.
39 ;; This file has evolved from gdba.el that was included with GDB 5.0 and
40 ;; written by Tom Lord and Jim Kingdon. It uses GDB's annotation interface.
41 ;; You don't need to know about annotations to use this mode as a debugger,
42 ;; but if you are interested developing the mode itself, see the Annotations
43 ;; section in the GDB info manual.
45 ;; GDB developers plan to make the annotation interface obsolete. A new
46 ;; interface called GDB/MI (machine interface) has been designed to replace it.
47 ;; Some GDB/MI commands are used in this file through the CLI command
48 ;; 'interpreter mi <mi-command>'. To help with the process of fully migrating
49 ;; Emacs from annotations to GDB/MI, there is an experimental package called
50 ;; gdb-mi in the Emacs Lisp Package Archive ("http://tromey.com/elpa/"). It
51 ;; comprises of modified gud.el and a file called gdb-mi.el which replaces
52 ;; gdb-ui.el. When installed, this overrides the current files and invoking
53 ;; M-x gdb will use GDB/MI directly (starts with "gdb -i=mi"). When deleted
54 ;; ('d' followed by 'x' in Package Menu mode), the files are deleted and old
55 ;; functionality restored. This provides a convenient way to review the
56 ;; current status/contribute to its improvement. For someone who just wants to
57 ;; use GDB, however, the current mode in Emacs 22 is a much better option.
58 ;; There is also a file, also called gdb-mi.el, a version of which is included
59 ;; the GDB distribution. This will probably only work with versions
60 ;; distributed with GDB 6.5 or later. Unlike the version in ELPA it works on
61 ;; top of gdb-ui.el and you can only start it with M-x gdbmi.
63 ;; This mode SHOULD WORK WITH GDB 5.0 or later but you will NEED AT LEAST
64 ;; GDB 6.0 to use watch expressions. It works best with GDB 6.4 or later
65 ;; where watch expressions will update more quickly.
67 ;;; Windows Platforms:
69 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
70 ;; explicitly in your program if you want timely display of I/O in Emacs.
71 ;; Alternatively you can make the output stream unbuffered, for example, by
75 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
78 ;; and compiling with -DUNBUFFERED while debugging.
80 ;; If you are using Cygwin GDB and find that the source is not being displayed
81 ;; in Emacs when you step through it, possible solutions are to:
83 ;; 1) Use Cygwin X Windows and Cygwin Emacs.
84 ;; (Since 22.1 Emacs builds under Cygwin.)
85 ;; 2) Use MinGW GDB instead.
86 ;; 3) Use cygwin-mount.el
90 ;; 1) Cannot handle multiple debug sessions.
91 ;; 2) If you wish to call procedures from your program in GDB
92 ;; e.g "call myproc ()", "p mysquare (5)" then use level 2 annotations
93 ;; "gdb --annotate=2 myprog" to keep source buffer/selected frame fixed.
94 ;; 3) After detaching from a process, clicking on the "GO" icon on toolbar
95 ;; (gud-go) sends "continue" to GDB (should be "run").
99 ;; 1) Use MI command -data-read-memory for memory window.
100 ;; 2) Use tree-widget.el instead of the speedbar for watch-expressions?
101 ;; 3) Mark breakpoint locations on scroll-bar of source buffer?
107 (defvar tool-bar-map)
108 (defvar speedbar-initial-expansion-list-name)
110 (defvar gdb-pc-address nil "Initialization for Assembler buffer.
111 Set to \"main\" at start if `gdb-show-main' is t.")
112 (defvar gdb-frame-address nil "Identity of frame for watch expression.")
113 (defvar gdb-previous-frame-address nil)
114 (defvar gdb-memory-address "main")
115 (defvar gdb-previous-frame nil)
116 (defvar gdb-selected-frame nil)
117 (defvar gdb-frame-number nil)
118 (defvar gdb-current-language nil)
119 (defvar gdb-var-list nil
120 "List of variables in watch window.
121 Each element has the form (VARNUM EXPRESSION NUMCHILD TYPE VALUE STATUS FP)
122 where STATUS is nil (`unchanged'), `changed' or `out-of-scope', FP the frame
123 address for root variables.")
124 (defvar gdb-main-file nil "Source file from which program execution begins.")
125 (defvar gud-old-arrow nil)
126 (defvar gdb-thread-indicator nil)
127 (defvar gdb-overlay-arrow-position nil)
128 (defvar gdb-stack-position nil)
129 (defvar gdb-server-prefix nil)
130 (defvar gdb-flush-pending-output nil)
131 (defvar gdb-location-alist nil
132 "Alist of breakpoint numbers and full filenames. Only used for files that
134 (defvar gdb-active-process nil
135 "GUD tooltips display variable values when t, and macro definitions otherwise.")
136 (defvar gdb-error "Non-nil when GDB is reporting an error.")
137 (defvar gdb-macro-info nil
138 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
139 (defvar gdb-buffer-fringe-width nil)
140 (defvar gdb-signalled nil)
141 (defvar gdb-source-window nil)
142 (defvar gdb-inferior-status nil)
143 (defvar gdb-continuation nil)
144 (defvar gdb-look-up-stack nil)
145 (defvar gdb-frame-begin nil
146 "Non-nil when GDB generates frame-begin annotation.")
147 (defvar gdb-printing t)
148 (defvar gdb-parent-bptno-enabled nil)
149 (defvar gdb-ready nil)
150 (defvar gdb-stack-update nil)
151 (defvar gdb-early-user-input nil)
153 (defvar gdb-buffer-type nil
154 "One of the symbols bound in `gdb-buffer-rules'.")
155 (make-variable-buffer-local 'gdb-buffer-type)
157 (defvar gdb-input-queue ()
158 "A list of gdb command objects.")
160 (defvar gdb-prompting nil
161 "True when gdb is idle with no pending input.")
163 (defvar gdb-output-sink nil
164 "The disposition of the output of the current gdb command.
165 Possible values are these symbols:
167 `user' -- gdb output should be copied to the GUD buffer
170 `inferior' -- gdb output should be copied to the inferior-io buffer.
172 `pre-emacs' -- output should be ignored util the post-prompt
173 annotation is received. Then the output-sink
175 `emacs' -- output should be collected in the partial-output-buffer
176 for subsequent processing by a command. This is the
177 disposition of output generated by commands that
178 gdb mode sends to gdb on its own behalf.
179 `post-emacs' -- ignore output until the prompt annotation is
180 received, then go to USER disposition.
182 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
183 \(`user' and `emacs').")
185 (defvar gdb-current-item nil
186 "The most recent command item sent to gdb.")
188 (defvar gdb-pending-triggers '()
189 "A list of trigger functions that have run later than their output handlers.")
191 (defvar gdb-first-post-prompt nil)
192 (defvar gdb-version nil)
193 (defvar gdb-locals-font-lock-keywords nil)
194 (defvar gdb-source-file-list nil
195 "List of source files for the current executable.")
196 (defconst gdb-error-regexp "\\^error,msg=\"\\(.+\\)\"")
198 (defvar gdb-locals-font-lock-keywords-1
200 ;; var = (struct struct_tag) value
201 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
202 (1 font-lock-variable-name-face)
203 (3 font-lock-keyword-face)
204 (4 font-lock-type-face))
205 ;; var = (type) value
206 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
207 (1 font-lock-variable-name-face)
208 (3 font-lock-type-face))
210 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
211 (1 font-lock-variable-name-face))
213 "Font lock keywords used in `gdb-local-mode'.")
215 (defvar gdb-locals-font-lock-keywords-2
218 ( "\\(^\\(\\sw\\|[_.]\\)+\\)\t+\\(\\(\\sw\\|[_.]\\)+\\)"
219 (1 font-lock-variable-name-face)
220 (3 font-lock-type-face))
222 "Font lock keywords used in `gdb-local-mode'.")
224 ;; Variables for GDB 6.4+
225 (defvar gdb-register-names nil "List of register names.")
226 (defvar gdb-changed-registers nil
227 "List of changed register numbers (strings).")
230 (defun gdb (command-line)
231 "Run gdb on program FILE in buffer *gud-FILE*.
232 The directory containing FILE becomes the initial working
233 directory and source-file directory for your debugger.
235 If `gdb-many-windows' is nil (the default value) then gdb just
236 pops up the GUD buffer unless `gdb-show-main' is t. In this case
237 it starts with two windows: one displaying the GUD buffer and the
238 other with the source file with the main routine of the inferior.
240 If `gdb-many-windows' is t, regardless of the value of
241 `gdb-show-main', the layout below will appear unless
242 `gdb-use-separate-io-buffer' is nil when the source buffer
243 occupies the full width of the frame. Keybindings are shown in
246 Watch expressions appear in the speedbar/slowbar.
248 The following commands help control operation :
250 `gdb-many-windows' - Toggle the number of windows gdb uses.
251 `gdb-restore-windows' - To restore the window layout.
253 See Info node `(emacs)GDB Graphical Interface' for a more
254 detailed description of this mode.
257 +----------------------------------------------------------------------+
259 +-----------------------------------+----------------------------------+
260 | GUD buffer (I/O of GDB) | Locals buffer |
264 +-----------------------------------+----------------------------------+
265 | Source buffer | I/O buffer (of debugged program) |
273 +-----------------------------------+----------------------------------+
274 | Stack buffer | Breakpoints buffer |
275 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
276 | | RET gdb-goto-breakpoint |
277 | | D gdb-delete-breakpoint |
278 +-----------------------------------+----------------------------------+
280 To run GDB in text command mode, replace the GDB \"--annotate=3\"
281 option with \"--fullname\" either in the minibuffer for the
282 current Emacs session, or the custom variable
283 `gud-gdb-command-name' for all future sessions. You need to use
284 text command mode to debug multiple programs within one Emacs
286 (interactive (list (gud-query-cmdline 'gdb)))
288 (when (and gud-comint-buffer
289 (buffer-name gud-comint-buffer)
290 (get-buffer-process gud-comint-buffer)
291 (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)))
292 (gdb-restore-windows)
294 "Multiple debugging requires restarting in text command mode"))
296 (gud-common-init command-line nil 'gud-gdba-marker-filter)
297 (set (make-local-variable 'gud-minor-mode) 'gdba)
298 (setq comint-input-sender 'gdb-send)
300 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
301 (gud-def gud-tbreak "tbreak %f:%l" "\C-t"
302 "Set temporary breakpoint at current line.")
303 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line.")
304 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.")
305 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
306 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
307 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).")
308 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
309 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
311 (progn (gud-call "tbreak %f:%l") (gud-call "jump %f:%l"))
312 "\C-j" "Set execution address to current line.")
314 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
315 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
316 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
317 (gud-def gud-pstar "print* %e" nil
318 "Evaluate C dereferenced pointer expression at point.")
320 ;; For debugging Emacs only.
321 (gud-def gud-pv "pv1 %e" "\C-v" "Print the value of the lisp variable.")
323 (gud-def gud-until "until %l" "\C-u" "Continue to current line.")
324 (gud-def gud-run "run" nil "Run the program.")
326 (local-set-key "\C-i" 'gud-gdb-complete-command)
327 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
328 (setq paragraph-start comint-prompt-regexp)
329 (setq gdb-output-sink 'user)
330 (setq gdb-first-prompt t)
331 (setq gud-running nil)
333 (setq gdb-stack-update nil)
334 (setq gdb-flush-pending-output nil)
335 (setq gdb-early-user-input nil)
336 (setq gud-filter-pending-text nil)
337 (run-hooks 'gdb-mode-hook))
339 ;; Keep as an alias for compatibility with Emacs 22.1.
341 (defalias 'gdba 'gdb)
344 "Gdb Graphical Mode options specifically for running Gdb in Emacs."
348 (defcustom gdb-debug-log-max 128
349 "Maximum size of `gdb-debug-log'. If nil, size is unlimited."
351 :type '(choice (integer :tag "Number of elements")
352 (const :tag "Unlimited" nil))
355 (defvar gdb-debug-log nil
356 "List of commands sent to and replies received from GDB.
357 Most recent commands are listed first. This list stores only the last
358 `gdb-debug-log-max' values. This variable is used to debug GDB-UI.")
361 (defcustom gdb-enable-debug nil
362 "Non-nil means record the process input and output in `gdb-debug-log'."
367 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
368 "Shell command for generating a list of defined macros in a source file.
369 This list is used to display the #define directive associated
370 with an identifier as a tooltip. It works in a debug session with
371 GDB, when `gud-tooltip-mode' is t.
373 Set `gdb-cpp-define-alist-flags' for any include paths or
379 (defcustom gdb-cpp-define-alist-flags ""
380 "Preprocessor flags for `gdb-cpp-define-alist-program'."
385 (defcustom gdb-show-main nil
386 "Non-nil means display source file containing the main routine at startup.
387 Also display the main routine in the disassembly buffer if present."
392 (defcustom gdb-many-windows nil
393 "If nil, just pop up the GUD buffer unless `gdb-show-main' is t.
394 In this case start with two windows: one displaying the GUD
395 buffer and the other with the source file with the main routine
396 of the debugged program. Non-nil means display the layout shown
402 (defcustom gdb-use-separate-io-buffer nil
403 "Non-nil means display output from the debugged program in a separate buffer."
408 (defun gdb-force-mode-line-update (status)
409 (let ((buffer gud-comint-buffer))
410 (if (and buffer (buffer-name buffer))
411 (with-current-buffer buffer
412 (setq mode-line-process
414 (process-status (get-buffer-process buffer)) status))
415 ;; Force mode line redisplay soon.
416 (force-mode-line-update)))))
418 (defun gdb-many-windows (arg)
419 "Toggle the number of windows in the basic arrangement.
420 With prefix argument ARG, display additional buffers if ARG is positive,
421 otherwise use a single window."
423 (setq gdb-many-windows
425 (not gdb-many-windows)
426 (> (prefix-numeric-value arg) 0)))
427 (message (format "Display of other windows %sabled"
428 (if gdb-many-windows "en" "dis")))
429 (if (and gud-comint-buffer
430 (buffer-name gud-comint-buffer))
432 (gdb-restore-windows)
435 (defun gdb-use-separate-io-buffer (arg)
436 "Toggle separate IO for debugged program.
437 With prefix argument ARG, use separate IO if ARG is positive,
440 (setq gdb-use-separate-io-buffer
442 (not gdb-use-separate-io-buffer)
443 (> (prefix-numeric-value arg) 0)))
444 (message (format "Separate IO %sabled"
445 (if gdb-use-separate-io-buffer "en" "dis")))
446 (if (and gud-comint-buffer
447 (buffer-name gud-comint-buffer))
449 (if gdb-use-separate-io-buffer
450 (if gdb-many-windows (gdb-restore-windows))
451 (kill-buffer (gdb-inferior-io-name)))
454 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
456 (defun gdb-create-define-alist ()
457 "Create an alist of #define directives for GUD tooltips."
458 (let* ((file (buffer-file-name))
460 (with-output-to-string
461 (with-current-buffer standard-output
462 (and file (file-exists-p file)
463 (call-process shell-file-name file
464 (list t nil) nil "-c"
465 (concat gdb-cpp-define-alist-program " "
466 gdb-cpp-define-alist-flags))))))
467 (define-list (split-string output "\n" t)) (name))
468 (setq gdb-define-alist nil)
469 (dolist (define define-list)
470 (setq name (nth 1 (split-string define "[( ]")))
471 (push (cons name define) gdb-define-alist))))
473 (defun gdb-tooltip-print (expr)
475 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
476 (goto-char (point-min))
478 (if (search-forward "=" nil t)
479 (concat expr (buffer-substring (- (point) 2) (point-max)))
481 ;; remove newline for gud-tooltip-echo-area
482 (substring string 0 (- (length string) 1))))
483 (or gud-tooltip-echo-area tooltip-use-echo-area)))
485 ;; If expr is a macro for a function don't print because of possible dangerous
486 ;; side-effects. Also printing a function within a tooltip generates an
487 ;; unexpected starting annotation (phase error).
488 (defun gdb-tooltip-print-1 (expr)
489 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
490 (goto-char (point-min))
491 (if (search-forward "expands to: " nil t)
492 (unless (looking-at "\\S-+.*(.*).*")
494 (list (concat gdb-server-prefix "print " expr "\n")
495 `(lambda () (gdb-tooltip-print ,expr))))))))
497 (defconst gdb-source-file-regexp "\\(.+?\\), \\|\\([^, \n].*$\\)")
499 (defun gdb-set-gud-minor-mode-existing-buffers ()
500 "Create list of source files for current GDB session."
501 (goto-char (point-min))
502 (when (search-forward "read in on demand:" nil t)
503 (while (re-search-forward gdb-source-file-regexp nil t)
504 (push (file-name-nondirectory (or (match-string 1) (match-string 2)))
505 gdb-source-file-list))
506 (dolist (buffer (buffer-list))
507 (with-current-buffer buffer
508 (when (and buffer-file-name
509 (member (file-name-nondirectory buffer-file-name)
510 gdb-source-file-list))
511 (set (make-local-variable 'gud-minor-mode) 'gdba)
512 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
513 (when gud-tooltip-mode
514 (make-local-variable 'gdb-define-alist)
515 (gdb-create-define-alist)
516 (add-hook 'after-save-hook 'gdb-create-define-alist nil t))))))
517 (gdb-force-mode-line-update
518 (propertize "ready" 'face font-lock-variable-name-face)))
520 (defun gdb-find-watch-expression ()
521 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
522 (varnum (car var)) expr array)
523 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varnum)
524 (let ((var1 (assoc (match-string 1 varnum) gdb-var-list)) var2 varnumlet
525 (component-list (split-string (match-string 2 varnum) "\\." t)))
526 (setq expr (nth 1 var1))
527 (setq varnumlet (car var1))
528 (dolist (component component-list)
529 (setq var2 (assoc varnumlet gdb-var-list))
530 (setq expr (concat expr
531 (if (string-match ".*\\[[0-9]+\\]$" (nth 3 var2))
532 (concat "[" component "]")
533 (concat "." component))))
534 (setq varnumlet (concat varnumlet "." component)))
538 (gud-def gud-break (if (not (string-match "Machine" mode-name))
539 (gud-call "break %f:%l" arg)
543 (gud-call "break *%a" arg)))
544 "\C-b" "Set breakpoint at current line or address.")
546 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
547 (gud-call "clear %f:%l" arg)
551 (gud-call "clear *%a" arg)))
552 "\C-d" "Remove breakpoint at current line or address.")
554 (gud-def gud-until (if (not (string-match "Machine" mode-name))
555 (gud-call "until %f:%l" arg)
559 (gud-call "until *%a" arg)))
560 "\C-u" "Continue to current line or address.")
562 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
563 nil "Start or continue execution.")
565 ;; For debugging Emacs only.
569 "pp1 " (if (eq (buffer-local-value
570 'major-mode (window-buffer)) 'speedbar-mode)
571 (gdb-find-watch-expression) "%e")) arg)
572 nil "Print the Emacs s-expression.")
574 (define-key gud-minor-mode-map [left-margin mouse-1]
575 'gdb-mouse-set-clear-breakpoint)
576 (define-key gud-minor-mode-map [left-fringe mouse-1]
577 'gdb-mouse-set-clear-breakpoint)
578 (define-key gud-minor-mode-map [left-margin C-mouse-1]
579 'gdb-mouse-toggle-breakpoint-margin)
580 (define-key gud-minor-mode-map [left-fringe C-mouse-1]
581 'gdb-mouse-toggle-breakpoint-fringe)
583 (define-key gud-minor-mode-map [left-margin drag-mouse-1]
585 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
587 (define-key gud-minor-mode-map [left-margin mouse-3]
589 (define-key gud-minor-mode-map [left-fringe mouse-3]
592 (define-key gud-minor-mode-map [left-margin C-drag-mouse-1]
594 (define-key gud-minor-mode-map [left-fringe C-drag-mouse-1]
596 (define-key gud-minor-mode-map [left-fringe C-mouse-3]
598 (define-key gud-minor-mode-map [left-margin C-mouse-3]
602 (setq gdb-pc-address (if gdb-show-main "main" nil))
603 (setq gdb-previous-frame-address nil
604 gdb-memory-address "main"
605 gdb-previous-frame nil
606 gdb-selected-frame nil
607 gdb-current-language nil
611 gdb-first-post-prompt t
615 gdb-pending-triggers nil
616 gdb-output-sink 'user
617 gdb-server-prefix "server "
618 gdb-location-alist nil
619 gdb-source-file-list nil
622 gdb-buffer-fringe-width (car (window-fringes))
625 gdb-source-window nil
626 gdb-inferior-status nil
628 gdb-look-up-stack nil
632 gdb-thread-indicator nil)
634 (setq gdb-buffer-type 'gdba)
636 (if gdb-use-separate-io-buffer (gdb-clear-inferior-io))
638 ;; Hack to see test for GDB 6.4+ (-stack-info-frame was implemented in 6.4)
639 (gdb-enqueue-input (list "server interpreter mi -stack-info-frame\n"
643 (if (eq window-system 'w32)
644 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
645 (gdb-enqueue-input (list "set height 0\n" 'ignore))
646 (gdb-enqueue-input (list "set width 0\n" 'ignore))
648 (if (string-equal gdb-version "pre-6.4")
650 (gdb-enqueue-input (list (concat gdb-server-prefix "info sources\n")
651 'gdb-set-gud-minor-mode-existing-buffers))
652 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-1))
654 (list "server interpreter mi -data-list-register-names\n"
655 'gdb-get-register-names))
656 ; Needs GDB 6.2 onwards.
658 (list "server interpreter mi \"-file-list-exec-source-files\"\n"
659 'gdb-set-gud-minor-mode-existing-buffers-1))
660 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-2))
662 ;; Find source file and compilation directory here.
663 ;; Works for C, C++, Fortran and Ada but not Java (GDB 6.4)
664 (gdb-enqueue-input (list "server list\n" 'ignore))
665 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
667 (run-hooks 'gdb-mode-hook))
669 (defun gdb-get-version ()
670 (goto-char (point-min))
671 (if (re-search-forward "Undefined\\( mi\\)* command:" nil t)
672 (setq gdb-version "pre-6.4")
673 (setq gdb-version "6.4+"))
676 (defmacro gdb-if-arrow (arrow-position &rest body)
678 (let ((buffer (marker-buffer ,arrow-position)) (line))
679 (if (equal buffer (window-buffer (posn-window end)))
680 (with-current-buffer buffer
681 (when (or (equal start end)
682 (equal (posn-point start)
683 (marker-position ,arrow-position)))
686 (defun gdb-mouse-until (event)
687 "Continue running until a source line past the current line.
688 The destination source line can be selected either by clicking
689 with mouse-3 on the fringe/margin or dragging the arrow
690 with mouse-1 (default bindings)."
692 (let ((start (event-start event))
693 (end (event-end event)))
694 (gdb-if-arrow gud-overlay-arrow-position
695 (setq line (line-number-at-pos (posn-point end)))
696 (gud-call (concat "until " (number-to-string line))))
697 (gdb-if-arrow gdb-overlay-arrow-position
699 (goto-line (line-number-at-pos (posn-point end)))
701 (gud-call (concat "until *%a"))))))
703 (defun gdb-mouse-jump (event)
704 "Set execution address/line.
705 The destination source line can be selected either by clicking with C-mouse-3
706 on the fringe/margin or dragging the arrow with C-mouse-1 (default bindings).
707 Unlike `gdb-mouse-until' the destination address can be before the current
708 line, and no execution takes place."
710 (let ((start (event-start event))
711 (end (event-end event)))
712 (gdb-if-arrow gud-overlay-arrow-position
713 (setq line (line-number-at-pos (posn-point end)))
715 (gud-call (concat "tbreak " (number-to-string line)))
716 (gud-call (concat "jump " (number-to-string line)))))
717 (gdb-if-arrow gdb-overlay-arrow-position
719 (goto-line (line-number-at-pos (posn-point end)))
722 (gud-call (concat "tbreak *%a"))
723 (gud-call (concat "jump *%a")))))))
725 (defcustom gdb-speedbar-auto-raise nil
726 "If non-nil raise speedbar every time display of watch expressions is\
732 (defun gdb-speedbar-auto-raise (arg)
733 "Toggle automatic raising of the speedbar for watch expressions.
734 With prefix argument ARG, automatically raise speedbar if ARG is
735 positive, otherwise don't automatically raise it."
737 (setq gdb-speedbar-auto-raise
739 (not gdb-speedbar-auto-raise)
740 (> (prefix-numeric-value arg) 0)))
741 (message (format "Auto raising %sabled"
742 (if gdb-speedbar-auto-raise "en" "dis"))))
744 (defcustom gdb-use-colon-colon-notation nil
745 "If non-nil use FUN::VAR format to display variables in the speedbar."
750 (define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch)
751 (define-key global-map (concat gud-key-prefix "\C-w") 'gud-watch)
753 (defun gud-watch (&optional arg event)
754 "Watch expression at point.
755 With arg, enter name of variable to be watched in the minibuffer."
756 (interactive (list current-prefix-arg last-input-event))
757 (let ((minor-mode (buffer-local-value 'gud-minor-mode gud-comint-buffer)))
758 (if (memq minor-mode '(gdbmi gdba))
760 (if event (posn-set-point (event-end event)))
762 (save-selected-window
765 (completing-read "Name of variable: "
766 'gud-gdb-complete-command)
767 (if (and transient-mark-mode mark-active)
768 (buffer-substring (region-beginning) (region-end))
769 (tooltip-identifier-from-point (point))))))
771 (set-text-properties 0 (length expr) nil expr)
774 (if (eq minor-mode 'gdba)
776 "server interpreter mi \"-var-create - * " expr "\"\n")
777 (concat"-var-create - * " expr "\n"))
778 `(lambda () (gdb-var-create-handler ,expr)))))))
779 (message "gud-watch is a no-op in this mode."))))
781 (defconst gdb-var-create-regexp
782 "name=\"\\(.*?\\)\",.*numchild=\"\\(.*?\\)\",\\(?:.*value=\\(\".*\"\\),\\)?.*type=\"\\(.*?\\)\"")
784 (defun gdb-var-create-handler (expr)
785 (goto-char (point-min))
786 (if (re-search-forward gdb-var-create-regexp nil t)
789 (if (and (string-equal gdb-current-language "c")
790 gdb-use-colon-colon-notation gdb-selected-frame)
791 (setq expr (concat gdb-selected-frame "::" expr))
795 (if (match-string 3) (read (match-string 3)))
796 nil gdb-frame-address)))
797 (push var gdb-var-list)
798 (unless (string-equal
799 speedbar-initial-expansion-list-name "GUD")
800 (speedbar-change-initial-expansion-list "GUD"))
804 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
806 (concat "server interpreter mi \"0-var-evaluate-expression "
808 (concat "0-var-evaluate-expression " (car var) "\n"))
809 `(lambda () (gdb-var-evaluate-expression-handler
811 (if (search-forward "Undefined command" nil t)
812 (message-box "Watching expressions requires GDB 6.0 onwards")
813 (message-box "No symbol \"%s\" in current context." expr))))
815 (defun gdb-speedbar-update ()
816 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame)
817 (not (member 'gdb-speedbar-timer gdb-pending-triggers)))
818 ;; Dummy command to update speedbar even when idle.
819 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
820 ;; Keep gdb-pending-triggers non-nil till end.
821 (push 'gdb-speedbar-timer gdb-pending-triggers)))
823 (defun gdb-speedbar-timer-fn ()
824 (setq gdb-pending-triggers
825 (delq 'gdb-speedbar-timer gdb-pending-triggers))
828 (defun gdb-var-evaluate-expression-handler (varnum changed)
829 (goto-char (point-min))
830 (re-search-forward "\\(.+\\)\\^done,value=\\(\".*\"\\)" nil t)
831 (setq gdb-pending-triggers
832 (delq (string-to-number (match-string 1)) gdb-pending-triggers))
833 (let ((var (assoc varnum gdb-var-list)))
835 (if changed (setcar (nthcdr 5 var) 'changed))
836 (setcar (nthcdr 4 var) (read (match-string 2)))))
837 (gdb-speedbar-update))
839 (defun gdb-var-list-children (varnum)
841 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
842 `(lambda () (gdb-var-list-children-handler ,varnum)))))
844 (defconst gdb-var-list-children-regexp
845 "child={.*?name=\"\\(.*?\\)\",.*?exp=\"\\(.*?\\)\",.*?\
846 numchild=\"\\(.*?\\)\"\\(}\\|,.*?\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
848 (defun gdb-var-list-children-handler (varnum)
849 (goto-char (point-min))
850 (let ((var-list nil))
851 (catch 'child-already-watched
852 (dolist (var gdb-var-list)
853 (if (string-equal varnum (car var))
856 (while (re-search-forward gdb-var-list-children-regexp nil t)
857 (let ((varchild (list (match-string 1)
862 (if (assoc (car varchild) gdb-var-list)
863 (throw 'child-already-watched nil))
864 (push varchild var-list)
868 "server interpreter mi \"0-var-evaluate-expression "
869 (car varchild) "\"\n")
870 `(lambda () (gdb-var-evaluate-expression-handler
871 ,(car varchild) nil)))))))
872 (push var var-list)))
873 (setq gdb-var-list (nreverse var-list)))))
875 (defun gdb-var-update ()
876 (when (not (member 'gdb-var-update gdb-pending-triggers))
878 (list "server interpreter mi \"-var-update *\"\n"
879 'gdb-var-update-handler))
880 (push 'gdb-var-update gdb-pending-triggers)))
882 (defconst gdb-var-update-regexp
883 "{.*?name=\"\\(.*?\\)\",.*?in_scope=\"\\(.*?\\)\",.*?\
884 type_changed=\".*?\".*?}")
886 (defun gdb-var-update-handler ()
887 (dolist (var gdb-var-list)
888 (setcar (nthcdr 5 var) nil))
889 (goto-char (point-min))
891 (while (re-search-forward gdb-var-update-regexp nil t)
892 (let ((varnum (match-string 1)))
893 (if (string-equal (match-string 2) "false")
894 (let ((var (assoc varnum gdb-var-list)))
895 (if var (setcar (nthcdr 5 var) 'out-of-scope)))
897 (push n gdb-pending-triggers)
900 (concat "server interpreter mi \"" (number-to-string n)
901 "-var-evaluate-expression " varnum "\"\n")
902 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t))))))))
903 (setq gdb-pending-triggers
904 (delq 'gdb-var-update gdb-pending-triggers)))
906 (defun gdb-var-set-format (format)
907 "Set the output format for a variable displayed in the speedbar."
908 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
912 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
913 (concat "server interpreter mi \"-var-set-format "
914 varnum " " format "\"\n")
915 (concat "-var-set-format " varnum " " format "\n"))
916 `(lambda () (gdb-var-set-format-handler ,varnum))))))
918 (defconst gdb-var-set-format-regexp
919 "format=\"\\(.*?\\)\",.*value=\"\\(.*?\\)\"")
921 (defun gdb-var-set-format-handler (varnum)
922 (goto-char (point-min))
923 (if (re-search-forward gdb-var-set-format-regexp nil t)
924 (let ((var (assoc varnum gdb-var-list)))
925 (setcar (nthcdr 4 var) (match-string 2))
926 (gdb-var-update-1))))
928 (defun gdb-var-delete-1 (varnum)
931 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
932 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
933 (concat "-var-delete " varnum "\n"))
935 (setq gdb-var-list (delq var gdb-var-list))
936 (dolist (varchild gdb-var-list)
937 (if (string-match (concat (car var) "\\.") (car varchild))
938 (setq gdb-var-list (delq varchild gdb-var-list)))))
940 (defun gdb-var-delete ()
941 "Delete watch expression at point from the speedbar."
943 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
945 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
947 (if (string-match "\\." (car var))
948 (message-box "Can only delete a root expression")
949 (gdb-var-delete-1 varnum)))))
951 (defun gdb-var-delete-children (varnum)
952 "Delete children of variable object at point from the speedbar."
955 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
956 (concat "server interpreter mi \"-var-delete -c " varnum "\"\n")
957 (concat "-var-delete -c " varnum "\n")) 'ignore)))
959 (defun gdb-edit-value (text token indent)
960 "Assign a value to a variable displayed in the speedbar."
961 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
962 (varnum (car var)) (value))
963 (setq value (read-string "New value: "))
966 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
967 (concat "server interpreter mi \"-var-assign "
968 varnum " " value "\"\n")
969 (concat "-var-assign " varnum " " value "\n"))
970 `(lambda () (gdb-edit-value-handler ,value))))))
972 (defun gdb-edit-value-handler (value)
973 (goto-char (point-min))
974 (if (re-search-forward gdb-error-regexp nil t)
975 (message-box "Invalid number or expression (%s)" value)))
977 (defcustom gdb-show-changed-values t
978 "If non-nil change the face of out of scope variables and changed values.
979 Out of scope variables are suppressed with `shadow' face.
980 Changed values are highlighted with the face `font-lock-warning-face'."
985 (defcustom gdb-max-children 40
986 "Maximum number of children before expansion requires confirmation."
991 (defcustom gdb-delete-out-of-scope t
992 "If non-nil delete watch expressions automatically when they go out of scope."
997 (defun gdb-speedbar-expand-node (text token indent)
998 "Expand the node the user clicked on.
999 TEXT is the text of the button we clicked on, a + or - item.
1000 TOKEN is data related to this node.
1001 INDENT is the current indentation depth."
1002 (if (and gud-comint-buffer (buffer-name gud-comint-buffer))
1004 (cond ((string-match "+" text) ;expand this node
1005 (let* ((var (assoc token gdb-var-list))
1006 (expr (nth 1 var)) (children (nth 2 var)))
1007 (if (or (<= (string-to-number children) gdb-max-children)
1010 "%s has %s children. Continue? " expr children)))
1011 (if (and (eq (buffer-local-value
1012 'gud-minor-mode gud-comint-buffer) 'gdba)
1013 (string-equal gdb-version "pre-6.4"))
1014 (gdb-var-list-children token)
1015 (gdb-var-list-children-1 token)))))
1016 ((string-match "-" text) ;contract this node
1017 (dolist (var gdb-var-list)
1018 (if (string-match (concat token "\\.") (car var))
1019 (setq gdb-var-list (delq var gdb-var-list))))
1020 (gdb-var-delete-children token)
1021 (speedbar-change-expand-button-char ?+)
1022 (speedbar-delete-subblock indent))
1023 (t (error "Ooops... not sure what to do")))
1024 (speedbar-center-buffer-smartly))
1025 (message-box "GUD session has been killed")))
1027 (defun gdb-get-target-string ()
1028 (with-current-buffer gud-comint-buffer
1035 ;; Each buffer has a TYPE -- a symbol that identifies the function
1036 ;; of that particular buffer.
1038 ;; The usual gdb interaction buffer is given the type `gdba' and
1039 ;; is constructed specially.
1041 ;; Others are constructed by gdb-get-buffer-create and
1042 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
1044 (defvar gdb-buffer-rules-assoc '())
1046 (defun gdb-get-buffer (key)
1047 "Return the gdb buffer tagged with type KEY.
1048 The key should be one of the cars in `gdb-buffer-rules-assoc'."
1050 (gdb-look-for-tagged-buffer key (buffer-list))))
1052 (defun gdb-get-buffer-create (key)
1053 "Create a new gdb buffer of the type specified by KEY.
1054 The key should be one of the cars in `gdb-buffer-rules-assoc'."
1055 (or (gdb-get-buffer key)
1056 (let* ((rules (assoc key gdb-buffer-rules-assoc))
1057 (name (funcall (gdb-rules-name-maker rules)))
1058 (new (get-buffer-create name)))
1059 (with-current-buffer new
1061 (if (cdr (cdr rules))
1062 (setq trigger (funcall (car (cdr (cdr rules))))))
1063 (setq gdb-buffer-type key)
1064 (set (make-local-variable 'gud-minor-mode)
1065 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
1066 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
1067 (if trigger (funcall trigger)))
1070 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
1072 (defun gdb-look-for-tagged-buffer (key bufs)
1074 (while (and (not retval) bufs)
1075 (set-buffer (car bufs))
1076 (if (eq gdb-buffer-type key)
1077 (setq retval (car bufs)))
1078 (setq bufs (cdr bufs)))
1082 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
1083 ;; at least one and possible more functions. The functions have these
1084 ;; roles in defining a buffer type:
1086 ;; NAME - Return a name for this buffer type.
1088 ;; The remaining function(s) are optional:
1090 ;; MODE - called in a new buffer with no arguments, should establish
1091 ;; the proper mode for the buffer.
1094 (defun gdb-set-buffer-rules (buffer-type &rest rules)
1095 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
1097 (setcdr binding rules)
1098 (push (cons buffer-type rules)
1099 gdb-buffer-rules-assoc))))
1101 ;; GUD buffers are an exception to the rules
1102 (gdb-set-buffer-rules 'gdba 'error)
1104 ;; Partial-output buffer : This accumulates output from a command executed on
1105 ;; behalf of emacs (rather than the user).
1107 (gdb-set-buffer-rules 'gdb-partial-output-buffer
1108 'gdb-partial-output-name)
1110 (defun gdb-partial-output-name ()
1111 (concat " *partial-output-"
1112 (gdb-get-target-string)
1116 (gdb-set-buffer-rules 'gdb-inferior-io
1117 'gdb-inferior-io-name
1118 'gdb-inferior-io-mode)
1120 (defun gdb-inferior-io-name ()
1121 (concat "*input/output of "
1122 (gdb-get-target-string)
1125 (defun gdb-display-separate-io-buffer ()
1126 "Display IO of debugged program in a separate window."
1128 (if gdb-use-separate-io-buffer
1130 (gdb-get-buffer-create 'gdb-inferior-io) t)))
1132 (defconst gdb-frame-parameters
1133 '((height . 14) (width . 80)
1135 (tool-bar-lines . nil)
1136 (menu-bar-lines . nil)
1137 (minibuffer . nil)))
1139 (defun gdb-frame-separate-io-buffer ()
1140 "Display IO of debugged program in a new frame."
1142 (if gdb-use-separate-io-buffer
1143 (let ((special-display-regexps (append special-display-regexps '(".*")))
1144 (special-display-frame-alist gdb-frame-parameters))
1145 (display-buffer (gdb-get-buffer-create 'gdb-inferior-io)))))
1147 (defvar gdb-inferior-io-mode-map
1148 (let ((map (make-sparse-keymap)))
1149 (define-key map "\C-c\C-c" 'gdb-separate-io-interrupt)
1150 (define-key map "\C-c\C-z" 'gdb-separate-io-stop)
1151 (define-key map "\C-c\C-\\" 'gdb-separate-io-quit)
1152 (define-key map "\C-c\C-d" 'gdb-separate-io-eof)
1153 (define-key map "\C-d" 'gdb-separate-io-eof)
1156 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
1157 "Major mode for gdb inferior-io."
1158 :syntax-table nil :abbrev-table nil
1159 ;; We want to use comint because it has various nifty and familiar
1160 ;; features. We don't need a process, but comint wants one, so create
1162 (make-comint-in-buffer
1163 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
1164 (current-buffer) "hexl")
1165 (setq comint-input-sender 'gdb-inferior-io-sender))
1167 (defun gdb-inferior-io-sender (proc string)
1168 ;; PROC is the pseudo-process created to satisfy comint.
1169 (with-current-buffer (process-buffer proc)
1170 (setq proc (get-buffer-process gud-comint-buffer))
1171 (process-send-string proc string)
1172 (process-send-string proc "\n")))
1174 (defun gdb-separate-io-interrupt ()
1175 "Interrupt the program being debugged."
1178 (get-buffer-process gud-comint-buffer) comint-ptyp))
1180 (defun gdb-separate-io-quit ()
1181 "Send quit signal to the program being debugged."
1184 (get-buffer-process gud-comint-buffer) comint-ptyp))
1186 (defun gdb-separate-io-stop ()
1187 "Stop the program being debugged."
1190 (get-buffer-process gud-comint-buffer) comint-ptyp))
1192 (defun gdb-separate-io-eof ()
1193 "Send end-of-file to the program being debugged."
1196 (get-buffer-process gud-comint-buffer)))
1199 ;; gdb communications
1202 ;; INPUT: things sent to gdb
1204 ;; The queues are lists. Each element is either a string (indicating user or
1205 ;; user-like input) or a list of the form:
1207 ;; (INPUT-STRING HANDLER-FN)
1209 ;; The handler function will be called from the partial-output buffer when the
1210 ;; command completes. This is the way to write commands which invoke gdb
1211 ;; commands autonomously.
1213 ;; These lists are consumed tail first.
1216 (defun gdb-send (proc string)
1217 "A comint send filter for gdb.
1218 This filter may simply queue input for a later time."
1221 (with-current-buffer gud-comint-buffer
1222 (let ((inhibit-read-only t))
1223 (remove-text-properties (point-min) (point-max) '(face))))
1226 (let ((item (concat string "\n")))
1227 (if gdb-enable-debug (push (cons 'send item) gdb-debug-log))
1228 (process-send-string proc item)))
1229 (if (string-match "\\\\\\'" string)
1230 (setq gdb-continuation (concat gdb-continuation string "\n"))
1232 gdb-continuation string
1233 (if (not comint-input-sender-no-newline) "\n"))))
1234 (gdb-enqueue-input item)
1235 (setq gdb-continuation nil)))))
1236 (push (concat string "\n") gdb-early-user-input)))
1238 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
1239 ;; is a query, or other non-top-level prompt.
1241 (defun gdb-enqueue-input (item)
1242 (if (not gud-running)
1245 (gdb-send-item item)
1246 (setq gdb-prompting nil))
1247 (push item gdb-input-queue))))
1249 (defun gdb-dequeue-input ()
1250 (let ((queue gdb-input-queue))
1252 (let ((last (car (last queue))))
1253 (unless (nbutlast queue) (setq gdb-input-queue '()))
1255 ;; This should be nil here anyway but set it just to make sure.
1256 (setq gdb-pending-triggers nil))))
1258 (defun gdb-send-item (item)
1259 (setq gdb-flush-pending-output nil)
1260 (if gdb-enable-debug (push (cons 'send-item item) gdb-debug-log))
1261 (setq gdb-current-item item)
1262 (let ((process (get-buffer-process gud-comint-buffer)))
1263 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1266 (setq gdb-output-sink 'user)
1267 (process-send-string process item))
1269 (gdb-clear-partial-output)
1270 (setq gdb-output-sink 'pre-emacs)
1271 (process-send-string process
1273 ;; case: eq gud-minor-mode 'gdbmi
1274 (gdb-clear-partial-output)
1275 (setq gdb-output-sink 'emacs)
1276 (process-send-string process (car item)))))
1279 ;; output -- things gdb prints to emacs
1281 ;; GDB output is a stream interrupted by annotations.
1282 ;; Annotations can be recognized by their beginning
1283 ;; with \C-j\C-z\C-z<tag><opt>\C-j
1285 ;; The tag is a string obeying symbol syntax.
1287 ;; The optional part `<opt>' can be either the empty string
1288 ;; or a space followed by more data relating to the annotation.
1289 ;; For example, the SOURCE annotation is followed by a filename,
1290 ;; line number and various useless goo. This data must not include
1294 (defcustom gud-gdb-command-name "gdb --annotate=3"
1295 "Default command to execute an executable under the GDB debugger.
1296 The option \"--annotate=3\" must be included in this value if you
1297 want the GDB Graphical Interface."
1302 (defvar gdb-annotation-rules
1303 '(("pre-prompt" gdb-pre-prompt)
1304 ("prompt" gdb-prompt)
1305 ("commands" gdb-subprompt)
1306 ("overload-choice" gdb-subprompt)
1307 ("query" gdb-subprompt)
1308 ;; Need this prompt for GDB 6.1
1309 ("nquery" gdb-subprompt)
1310 ("prompt-for-continue" gdb-subprompt)
1311 ("post-prompt" gdb-post-prompt)
1312 ("source" gdb-source)
1313 ("starting" gdb-starting)
1314 ("exited" gdb-exited)
1315 ("signalled" gdb-signalled)
1316 ("signal" gdb-signal)
1317 ("breakpoint" gdb-stopping)
1318 ("watchpoint" gdb-stopping)
1319 ("frame-begin" gdb-frame-begin)
1320 ("stopped" gdb-stopped)
1321 ("error-begin" gdb-error)
1323 ("new-thread" (lambda (ignored) (gdb-get-buffer-create 'gdb-threads-buffer))))
1324 "An assoc mapping annotation tags to functions which process them.")
1327 (setq gdb-flush-pending-output t)
1328 (setq gud-running nil)
1329 (gdb-force-mode-line-update
1330 (propertize "stopped" 'face font-lock-warning-face))
1331 (setq gdb-output-sink 'user)
1332 (setq gdb-input-queue nil)
1333 (setq gdb-pending-triggers nil)
1334 (setq gdb-prompting t))
1336 (defconst gdb-source-spec-regexp
1337 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
1339 ;; Do not use this except as an annotation handler.
1340 (defun gdb-source (args)
1341 (string-match gdb-source-spec-regexp args)
1342 ;; Extract the frame position from the marker.
1343 (setq gud-last-frame
1345 (match-string 1 args)
1346 (string-to-number (match-string 2 args))))
1347 (setq gdb-pc-address (match-string 3 args))
1348 ;; cover for auto-display output which comes *before*
1349 ;; stopped annotation
1350 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1352 (defun gdb-pre-prompt (ignored)
1353 "An annotation handler for `pre-prompt'.
1354 This terminates the collection of output from a previous command if that
1355 happens to be in effect."
1356 (setq gdb-error nil)
1357 (let ((sink gdb-output-sink))
1361 (setq gdb-output-sink 'post-emacs))
1364 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1366 (defun gdb-prompt (ignored)
1367 "An annotation handler for `prompt'.
1368 This sends the next command (if any) to gdb."
1369 (when gdb-first-prompt
1370 (gdb-force-mode-line-update
1371 (propertize "initializing..." 'face font-lock-variable-name-face))
1373 (setq gdb-first-prompt nil))
1374 (let ((sink gdb-output-sink))
1377 ((eq sink 'post-emacs)
1378 (setq gdb-output-sink 'user)
1380 (car (cdr gdb-current-item))))
1381 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1382 (funcall handler))))
1385 (error "Phase error in gdb-prompt (got %s)" sink))))
1386 (let ((input (gdb-dequeue-input)))
1388 (gdb-send-item input)
1390 (setq gdb-prompting t)
1392 (setq gdb-early-user-input (nreverse gdb-early-user-input))
1393 (while gdb-early-user-input
1394 (gdb-enqueue-input (car gdb-early-user-input))
1395 (setq gdb-early-user-input (cdr gdb-early-user-input)))))))
1397 (defun gdb-subprompt (ignored)
1398 "An annotation handler for non-top-level prompts."
1399 (setq gdb-prompting t))
1401 (defun gdb-starting (ignored)
1402 "An annotation handler for `starting'.
1403 This says that I/O for the subprocess is now the program being debugged,
1405 (setq gdb-active-process t)
1406 (setq gdb-printing t)
1407 (let ((sink gdb-output-sink))
1411 (setq gud-running t)
1412 (setq gdb-stack-update t)
1413 ;; Temporarily set gud-running to nil to force "info stack" onto queue.
1414 (let ((gud-running nil))
1415 (gdb-invalidate-frames))
1416 (setq gdb-inferior-status "running")
1417 (setq gdb-signalled nil)
1418 (gdb-force-mode-line-update
1419 (propertize gdb-inferior-status 'face font-lock-type-face))
1420 (gdb-remove-text-properties)
1421 (setq gud-old-arrow gud-overlay-arrow-position)
1422 (setq gud-overlay-arrow-position nil)
1423 (setq gdb-overlay-arrow-position nil)
1424 (setq gdb-stack-position nil)
1425 (if gdb-use-separate-io-buffer
1426 (setq gdb-output-sink 'inferior))))
1429 (error "Unexpected `starting' annotation")))))
1431 (defun gdb-signal (ignored)
1432 (setq gdb-inferior-status "signal")
1433 (gdb-force-mode-line-update
1434 (propertize gdb-inferior-status 'face font-lock-warning-face))
1435 (gdb-stopping ignored))
1437 (defun gdb-stopping (ignored)
1438 "An annotation handler for `breakpoint' and other annotations.
1439 They say that I/O for the subprocess is now GDB, not the program
1441 (if gdb-use-separate-io-buffer
1442 (let ((sink gdb-output-sink))
1444 ((eq sink 'inferior)
1445 (setq gdb-output-sink 'user))
1448 (error "Unexpected stopping annotation"))))))
1450 (defun gdb-exited (ignored)
1451 "An annotation handler for `exited' and `signalled'.
1452 They say that I/O for the subprocess is now GDB, not the program
1453 being debugged and that the program is no longer running. This
1454 function is used to change the focus of GUD tooltips to #define
1456 (setq gdb-active-process nil)
1457 (setq gud-overlay-arrow-position nil)
1458 (setq gdb-overlay-arrow-position nil)
1459 (setq gdb-stack-position nil)
1460 (setq gud-old-arrow nil)
1461 (setq gdb-inferior-status "exited")
1462 (gdb-force-mode-line-update
1463 (propertize gdb-inferior-status 'face font-lock-warning-face))
1464 (gdb-stopping ignored))
1466 (defun gdb-signalled (ignored)
1467 (setq gdb-signalled t))
1469 (defun gdb-frame-begin (ignored)
1470 (setq gdb-frame-begin t)
1471 (setq gdb-printing nil)
1472 (let ((sink gdb-output-sink))
1474 ((eq sink 'inferior)
1475 (setq gdb-output-sink 'user))
1477 ((eq sink 'emacs) t)
1480 (error "Unexpected frame-begin annotation (%S)" sink)))))
1482 (defcustom gdb-same-frame focus-follows-mouse
1483 "Non-nil means pop up GUD buffer in same frame."
1488 (defcustom gdb-find-source-frame nil
1489 "Non-nil means try to find a source frame further up stack e.g after signal."
1494 (defun gdb-find-source-frame (arg)
1495 "Toggle looking for a source frame further up call stack.
1496 The code associated with current (innermost) frame may not have
1497 been compiled with debug information, e.g., C library routine.
1498 With prefix argument ARG, look for a source frame further up
1499 stack to display in the source buffer if ARG is positive,
1500 otherwise don't look further up."
1502 (setq gdb-find-source-frame
1504 (not gdb-find-source-frame)
1505 (> (prefix-numeric-value arg) 0)))
1506 (message (format "Looking for source frame %sabled"
1507 (if gdb-find-source-frame "en" "dis"))))
1509 (defun gdb-stopped (ignored)
1510 "An annotation handler for `stopped'.
1511 It is just like `gdb-stopping', except that if we already set the output
1512 sink to `user' in `gdb-stopping', that is fine."
1513 (setq gud-running nil)
1514 (unless (or gud-overlay-arrow-position gud-last-frame)
1515 (if (and gdb-frame-begin gdb-printing)
1516 (setq gud-overlay-arrow-position gud-old-arrow)
1517 ;;Pop up GUD buffer to display current frame when it doesn't have source
1518 ;;information i.e if not compiled with -g as with libc routines generally.
1520 (gdb-display-gdb-buffer)
1521 (gdb-frame-gdb-buffer))
1522 (if gdb-find-source-frame
1523 ;;Try to find source further up stack e.g after signal.
1524 (setq gdb-look-up-stack
1525 (if (gdb-get-buffer 'gdb-stack-buffer)
1528 (gdb-get-buffer-create 'gdb-stack-buffer)
1529 (gdb-invalidate-frames)
1531 (unless (member gdb-inferior-status '("exited" "signal"))
1532 (setq gdb-active-process t) ;Just for attaching case.
1533 (setq gdb-inferior-status "stopped")
1534 (gdb-force-mode-line-update
1535 (propertize gdb-inferior-status 'face font-lock-warning-face)))
1536 (let ((sink gdb-output-sink))
1538 ((eq sink 'inferior)
1539 (setq gdb-output-sink 'user))
1543 (error "Unexpected stopped annotation"))))
1544 (if gdb-signalled (gdb-exited ignored)))
1546 (defun gdb-error (ignored)
1547 (setq gdb-error (not gdb-error)))
1549 (defun gdb-post-prompt (ignored)
1550 "An annotation handler for `post-prompt'.
1551 This begins the collection of output from the current command if that
1552 happens to be appropriate."
1553 ;; Don't add to queue if there outstanding items or gdb-version is not known
1555 (unless (or gdb-pending-triggers gdb-first-post-prompt)
1556 (gdb-get-selected-frame)
1557 (gdb-invalidate-frames)
1558 ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
1559 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
1560 (gdb-invalidate-breakpoints)
1561 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1562 ;; so gdb-pc-address is updated.
1563 ;; (gdb-invalidate-assembler)
1565 (if (string-equal gdb-version "pre-6.4")
1566 (gdb-invalidate-registers)
1567 (gdb-get-changed-registers)
1568 (gdb-invalidate-registers-1))
1570 (gdb-invalidate-memory)
1571 (if (string-equal gdb-version "pre-6.4")
1572 (gdb-invalidate-locals)
1573 (gdb-invalidate-locals-1))
1575 (gdb-invalidate-threads)
1576 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1577 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1578 ;; Only needed/used with speedbar/watch expressions.
1579 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1580 (if (string-equal gdb-version "pre-6.4")
1582 (gdb-var-update-1)))))
1583 (setq gdb-first-post-prompt nil)
1584 (let ((sink gdb-output-sink))
1587 ((eq sink 'pre-emacs)
1588 (setq gdb-output-sink 'emacs))
1591 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1593 (defconst gdb-buffer-list
1594 '(gdb-stack-buffer gdb-locals-buffer gdb-registers-buffer gdb-threads-buffer))
1596 (defun gdb-remove-text-properties ()
1597 (dolist (buffertype gdb-buffer-list)
1598 (let ((buffer (gdb-get-buffer buffertype)))
1600 (with-current-buffer buffer
1601 (let ((inhibit-read-only t))
1602 (remove-text-properties
1603 (point-min) (point-max) '(mouse-face nil help-echo nil))))))))
1605 ;; GUD displays the selected GDB frame. This might might not be the current
1606 ;; GDB frame (after up, down etc). If no GDB frame is visible but the last
1607 ;; visited breakpoint is, use that window.
1608 (defun gdb-display-source-buffer (buffer)
1609 (let* ((last-window (if gud-last-last-frame
1611 (gud-find-file (car gud-last-last-frame)))))
1612 (source-window (or last-window
1613 (if (and gdb-source-window
1614 (window-live-p gdb-source-window))
1615 gdb-source-window))))
1617 (setq gdb-source-window source-window)
1618 (set-window-buffer source-window buffer))
1621 ;; Derived from gud-gdb-marker-regexp
1622 (defvar gdb-fullname-regexp
1623 (concat "\\(.:?[^" ":" "\n]*\\)" ":" "\\([0-9]*\\)" ":" ".*"))
1625 (defun gud-gdba-marker-filter (string)
1626 "A gud marker filter for gdb. Handle a burst of output from GDB."
1627 (if gdb-flush-pending-output
1629 (when gdb-enable-debug
1630 (push (cons 'recv string) gdb-debug-log)
1631 (if (and gdb-debug-log-max
1632 (> (length gdb-debug-log) gdb-debug-log-max))
1633 (setcdr (nthcdr (1- gdb-debug-log-max) gdb-debug-log) nil)))
1634 ;; Recall the left over gud-marker-acc from last time.
1635 (setq gud-marker-acc (concat gud-marker-acc string))
1636 ;; Start accumulating output for the GUD buffer.
1639 ;; Process all the complete markers in this chunk.
1640 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1641 (let ((annotation (match-string 1 gud-marker-acc))
1642 (before (substring gud-marker-acc 0 (match-beginning 0)))
1643 (after (substring gud-marker-acc (match-end 0))))
1645 ;; Parse the tag from the annotation, and maybe its arguments.
1646 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1647 (let* ((annotation-type (match-string 1 annotation))
1648 (annotation-arguments (match-string 2 annotation))
1649 (annotation-rule (assoc annotation-type
1650 gdb-annotation-rules))
1651 (fullname (string-match gdb-fullname-regexp annotation-type)))
1653 ;; Stuff prior to the match is just ordinary output.
1654 ;; It is either concatenated to OUTPUT or directed
1657 (gdb-concat-output output
1658 (concat before (if fullname "\n"))))
1660 ;; Take that stuff off the gud-marker-acc.
1661 (setq gud-marker-acc after)
1663 ;; Call the handler for this annotation.
1665 (funcall (car (cdr annotation-rule))
1666 annotation-arguments)
1668 ;; Switch to gud-gdb-marker-filter if appropriate.
1671 ;; Extract the frame position from the marker.
1672 (setq gud-last-frame (cons (match-string 1 annotation)
1674 (match-string 2 annotation))))
1676 (set (make-local-variable 'gud-minor-mode) 'gdb)
1677 (set (make-local-variable 'gud-marker-filter)
1678 'gud-gdb-marker-filter)))
1680 ;; Else the annotation is not recognized. Ignore it silently,
1681 ;; so that GDB can add new annotations without causing
1685 ;; Does the remaining text end in a partial line?
1686 ;; If it does, then keep part of the gud-marker-acc until we get more.
1687 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1690 ;; Everything before the potential marker start can be output.
1692 (gdb-concat-output output
1693 (substring gud-marker-acc 0
1694 (match-beginning 0))))
1696 ;; Everything after, we save, to combine with later input.
1697 (setq gud-marker-acc (substring gud-marker-acc
1698 (match-beginning 0))))
1700 ;; In case we know the gud-marker-acc contains no partial annotations:
1702 (setq output (gdb-concat-output output gud-marker-acc))
1703 (setq gud-marker-acc "")))
1706 (defun gdb-concat-output (so-far new)
1708 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1709 (let ((sink gdb-output-sink))
1711 ((eq sink 'user) (concat so-far new))
1712 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1714 (gdb-append-to-partial-output new)
1716 ((eq sink 'inferior)
1717 (gdb-append-to-inferior-io new)
1721 (error "Bogon output sink %S" sink)))))
1723 (defun gdb-append-to-partial-output (string)
1724 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1725 (goto-char (point-max))
1728 (defun gdb-clear-partial-output ()
1729 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1732 (defun gdb-append-to-inferior-io (string)
1733 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1734 (goto-char (point-max))
1735 (insert-before-markers string))
1736 (if (not (string-equal string ""))
1737 (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io) t)))
1739 (defun gdb-clear-inferior-io ()
1740 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1744 ;; One trick is to have a command who's output is always available in a buffer
1745 ;; of it's own, and is always up to date. We build several buffers of this
1748 ;; There are two aspects to this: gdb has to tell us when the output for that
1749 ;; command might have changed, and we have to be able to run the command
1750 ;; behind the user's back.
1752 ;; The output phasing associated with the variable gdb-output-sink
1753 ;; help us to run commands behind the user's back.
1755 ;; Below is the code for specificly managing buffers of output from one
1759 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1760 ;; It adds an input for the command we are tracking. It should be the
1761 ;; annotation rule binding of whatever gdb sends to tell us this command
1762 ;; might have changed it's output.
1764 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1765 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1766 ;; input in the input queue (see comment about ``gdb communications'' above).
1768 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1770 `(defun ,name (&optional ignored)
1771 (if (and ,demand-predicate
1773 gdb-pending-triggers)))
1776 (list ,gdb-command ',output-handler))
1777 (push ',name gdb-pending-triggers)))))
1779 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1781 (setq gdb-pending-triggers
1783 gdb-pending-triggers))
1784 (let ((buf (gdb-get-buffer ',buf-key)))
1786 (with-current-buffer buf
1787 (let* ((window (get-buffer-window buf 0))
1788 (start (window-start window))
1789 (p (window-point window))
1790 (buffer-read-only nil))
1792 (insert-buffer-substring (gdb-get-buffer-create
1793 'gdb-partial-output-buffer))
1794 (set-window-start window start)
1795 (set-window-point window p)))))
1796 ;; put customisation here
1799 (defmacro def-gdb-auto-updated-buffer (buffer-key
1800 trigger-name gdb-command
1801 output-handler-name custom-defun)
1803 (def-gdb-auto-update-trigger ,trigger-name
1804 ;; The demand predicate:
1805 (gdb-get-buffer ',buffer-key)
1807 ,output-handler-name)
1808 (def-gdb-auto-update-handler ,output-handler-name
1809 ,trigger-name ,buffer-key ,custom-defun)))
1813 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1815 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1816 'gdb-breakpoints-buffer-name
1817 'gdb-breakpoints-mode)
1819 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1820 ;; This defines the auto update rule for buffers of type
1821 ;; `gdb-breakpoints-buffer'.
1823 ;; It defines a function to serve as the annotation handler that
1824 ;; handles the `foo-invalidated' message. That function is called:
1825 gdb-invalidate-breakpoints
1827 ;; To update the buffer, this command is sent to gdb.
1828 "server info breakpoints\n"
1830 ;; This also defines a function to be the handler for the output
1831 ;; from the command above. That function will copy the output into
1832 ;; the appropriately typed buffer. That function will be called:
1833 gdb-info-breakpoints-handler
1834 ;; buffer specific functions
1835 gdb-info-breakpoints-custom)
1837 (defconst breakpoint-xpm-data
1839 static char *magick[] = {
1840 /* columns rows colors chars-per-pixel */
1856 "XPM data used for breakpoint icon.")
1858 (defconst breakpoint-enabled-pbm-data
1861 0 0 0 0 1 1 1 1 0 0 0 0
1862 0 0 0 1 1 1 1 1 1 0 0 0
1863 0 0 1 1 1 1 1 1 1 1 0 0
1864 0 1 1 1 1 1 1 1 1 1 1 0
1865 0 1 1 1 1 1 1 1 1 1 1 0
1866 0 1 1 1 1 1 1 1 1 1 1 0
1867 0 1 1 1 1 1 1 1 1 1 1 0
1868 0 0 1 1 1 1 1 1 1 1 0 0
1869 0 0 0 1 1 1 1 1 1 0 0 0
1870 0 0 0 0 1 1 1 1 0 0 0 0"
1871 "PBM data used for enabled breakpoint icon.")
1873 (defconst breakpoint-disabled-pbm-data
1885 0 0 0 1 0 1 0 1 0 0"
1886 "PBM data used for disabled breakpoint icon.")
1888 (defvar breakpoint-enabled-icon nil
1889 "Icon for enabled breakpoint in display margin.")
1891 (defvar breakpoint-disabled-icon nil
1892 "Icon for disabled breakpoint in display margin.")
1894 (and (display-images-p)
1895 ;; Bitmap for breakpoint in fringe
1896 (define-fringe-bitmap 'breakpoint
1897 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c")
1898 ;; Bitmap for gud-overlay-arrow in fringe
1899 (define-fringe-bitmap 'hollow-right-triangle
1900 "\xe0\x90\x88\x84\x84\x88\x90\xe0"))
1902 (defface breakpoint-enabled
1906 "Face for enabled breakpoint icon in fringe."
1909 (defface breakpoint-disabled
1910 '((((class color) (min-colors 88)) :foreground "grey70")
1911 ;; Ensure that on low-color displays that we end up something visible.
1912 (((class color) (min-colors 8) (background light))
1913 :foreground "black")
1914 (((class color) (min-colors 8) (background dark))
1915 :foreground "white")
1916 (((type tty) (class mono))
1918 (t :background "gray"))
1919 "Face for disabled breakpoint icon in fringe."
1922 (defconst gdb-breakpoint-regexp
1923 "\\(?:\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\|\\([0-9]+\\.[0-9]+\\)\\)\\s-+\\(.\\)\\s-+")
1925 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1926 (defun gdb-info-breakpoints-custom ()
1927 (let ((flag) (bptno))
1928 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1929 (dolist (buffer (buffer-list))
1930 (with-current-buffer buffer
1931 (if (and (memq gud-minor-mode '(gdba gdbmi))
1932 (not (string-match "\\` ?\\*.+\\*\\'" (buffer-name))))
1933 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1934 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1936 (let ((buffer-read-only nil))
1937 (goto-char (point-min))
1938 (while (< (point) (- (point-max) 1))
1940 (if (looking-at gdb-breakpoint-regexp)
1942 (setq bptno (or (match-string 1) (match-string 2)))
1943 (setq flag (char-after (match-beginning 3)))
1944 (if (match-string 1)
1945 (setq gdb-parent-bptno-enabled (eq flag ?y)))
1946 (add-text-properties
1947 (match-beginning 3) (match-end 3)
1949 '(face font-lock-warning-face)
1950 '(face font-lock-type-face)))
1952 (el (line-end-position)))
1953 (if (re-search-forward " in \\(.*\\) at\\s-+" el t)
1955 (add-text-properties
1956 (match-beginning 1) (match-end 1)
1957 '(face font-lock-function-name-face))
1958 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1959 (let ((line (match-string 2))
1960 (file (match-string 1)))
1961 (add-text-properties bl el
1962 '(mouse-face highlight
1963 help-echo "mouse-2, RET: visit breakpoint"))
1964 (unless (file-exists-p file)
1965 (setq file (cdr (assoc bptno gdb-location-alist))))
1967 (not (string-equal file "File not found")))
1968 (with-current-buffer
1969 (find-file-noselect file 'nowarn)
1970 (set (make-local-variable 'gud-minor-mode)
1972 (set (make-local-variable 'tool-bar-map)
1974 ;; Only want one breakpoint icon at each
1977 (goto-line (string-to-number line))
1978 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1981 (concat gdb-server-prefix "list "
1982 (match-string-no-properties 1) ":1\n")
1985 (list (concat gdb-server-prefix "info source\n")
1986 `(lambda () (gdb-get-location
1987 ,bptno ,line ,flag)))))))
1988 (if (re-search-forward
1989 "<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
1991 (add-text-properties
1992 (match-beginning 1) (match-end 1)
1993 '(face font-lock-function-name-face))
1995 (re-search-backward "\\s-\\(\\S-*\\)"
1997 (add-text-properties
1998 (match-beginning 1) (match-end 1)
1999 '(face font-lock-variable-name-face)))))))
2001 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom))
2003 ;; Breakpoints buffer is always present. Hack to just update
2004 ;; current frame if there's been no execution.
2005 (if gdb-stack-update
2006 (setq gdb-stack-update nil)
2007 (if (gdb-get-buffer 'gdb-stack-buffer) (gdb-info-stack-custom))))
2009 (declare-function gud-remove "gdb-ui" t t) ; gud-def
2010 (declare-function gud-break "gdb-ui" t t) ; gud-def
2012 (defun gdb-mouse-set-clear-breakpoint (event)
2013 "Set/clear breakpoint in left fringe/margin at mouse click.
2014 If not in a source or disassembly buffer just set point."
2016 (mouse-minibuffer-check event)
2017 (let ((posn (event-end event)))
2018 (if (or (buffer-file-name) (eq major-mode 'gdb-assembler-mode))
2019 (if (numberp (posn-point posn))
2020 (with-selected-window (posn-window posn)
2022 (goto-char (posn-point posn))
2023 (if (or (posn-object posn)
2024 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
2028 (posn-set-point posn))))
2030 (defun gdb-mouse-toggle-breakpoint-margin (event)
2031 "Enable/disable breakpoint in left margin with mouse click."
2033 (mouse-minibuffer-check event)
2034 (let ((posn (event-end event)))
2035 (if (numberp (posn-point posn))
2036 (with-selected-window (posn-window posn)
2038 (goto-char (posn-point posn))
2039 (if (posn-object posn)
2040 (let* ((bptno (get-text-property
2041 0 'gdb-bptno (car (posn-string posn)))))
2042 (string-match "\\([0-9+]\\)*" bptno)
2045 (concat gdb-server-prefix
2046 (if (get-text-property
2047 0 'gdb-enabled (car (posn-string posn)))
2050 (match-string 1 bptno) "\n")
2053 (defun gdb-mouse-toggle-breakpoint-fringe (event)
2054 "Enable/disable breakpoint in left fringe with mouse click."
2056 (mouse-minibuffer-check event)
2057 (let* ((posn (event-end event))
2058 (pos (posn-point posn))
2061 (with-selected-window (posn-window posn)
2063 (set-buffer (window-buffer (selected-window)))
2065 (dolist (overlay (overlays-in pos pos))
2066 (when (overlay-get overlay 'put-break)
2067 (setq obj (overlay-get overlay 'before-string))))
2069 (let* ((bptno (get-text-property 0 'gdb-bptno obj)))
2070 (string-match "\\([0-9+]\\)*" bptno)
2073 (concat gdb-server-prefix
2074 (if (get-text-property 0 'gdb-enabled obj)
2077 (match-string 1 bptno) "\n")
2080 (defun gdb-breakpoints-buffer-name ()
2081 (with-current-buffer gud-comint-buffer
2082 (concat "*breakpoints of " (gdb-get-target-string) "*")))
2084 (defun gdb-display-breakpoints-buffer ()
2085 "Display status of user-settable breakpoints."
2088 (gdb-get-buffer-create 'gdb-breakpoints-buffer) t))
2090 (defun gdb-frame-breakpoints-buffer ()
2091 "Display status of user-settable breakpoints in a new frame."
2093 (let ((special-display-regexps (append special-display-regexps '(".*")))
2094 (special-display-frame-alist gdb-frame-parameters))
2095 (display-buffer (gdb-get-buffer-create 'gdb-breakpoints-buffer))))
2097 (defvar gdb-breakpoints-mode-map
2098 (let ((map (make-sparse-keymap))
2099 (menu (make-sparse-keymap "Breakpoints")))
2100 (define-key menu [quit] '("Quit" . gdb-delete-frame-or-window))
2101 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
2102 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
2103 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
2104 (suppress-keymap map)
2105 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
2106 (define-key map " " 'gdb-toggle-breakpoint)
2107 (define-key map "D" 'gdb-delete-breakpoint)
2108 ;; Don't bind "q" to kill-this-buffer as we need it for breakpoint icons.
2109 (define-key map "q" 'gdb-delete-frame-or-window)
2110 (define-key map "\r" 'gdb-goto-breakpoint)
2111 (define-key map [mouse-2] 'gdb-goto-breakpoint)
2112 (define-key map [follow-link] 'mouse-face)
2115 (defun gdb-delete-frame-or-window ()
2116 "Delete frame if there is only one window. Otherwise delete the window."
2118 (if (one-window-p) (delete-frame)
2121 (defun gdb-breakpoints-mode ()
2122 "Major mode for gdb breakpoints.
2124 \\{gdb-breakpoints-mode-map}"
2125 (kill-all-local-variables)
2126 (setq major-mode 'gdb-breakpoints-mode)
2127 (setq mode-name "Breakpoints")
2128 (use-local-map gdb-breakpoints-mode-map)
2129 (setq buffer-read-only t)
2130 (run-mode-hooks 'gdb-breakpoints-mode-hook)
2131 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2132 'gdb-invalidate-breakpoints
2133 'gdbmi-invalidate-breakpoints))
2135 (defun gdb-toggle-breakpoint ()
2136 "Enable/disable breakpoint at current line."
2139 (beginning-of-line 1)
2140 (if (looking-at gdb-breakpoint-regexp)
2143 (concat gdb-server-prefix
2144 (if (eq ?y (char-after (match-beginning 3)))
2147 (or (match-string 1) (match-string 2)) "\n") 'ignore))
2148 (error "Not recognized as break/watchpoint line"))))
2150 (defun gdb-delete-breakpoint ()
2151 "Delete the breakpoint at current line."
2154 (beginning-of-line 1)
2155 (if (looking-at gdb-breakpoint-regexp)
2156 (if (match-string 1)
2159 (concat gdb-server-prefix "delete " (match-string 1) "\n")
2161 (message-box "This breakpoint cannot be deleted on its own."))
2162 (error "Not recognized as break/watchpoint line"))))
2164 (defun gdb-goto-breakpoint (&optional event)
2165 "Display the breakpoint location specified at current line."
2166 (interactive (list last-input-event))
2167 (if event (posn-set-point (event-end event)))
2169 (beginning-of-line 1)
2170 (if (looking-at "\\([0-9]+\\.?[0-9]*\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
2171 (let ((bptno (match-string 1))
2172 (file (match-string 2))
2173 (line (match-string 3)))
2174 (save-selected-window
2175 (let* ((buffer (find-file-noselect
2176 (if (file-exists-p file) file
2177 (cdr (assoc bptno gdb-location-alist)))))
2178 (window (or (gdb-display-source-buffer buffer)
2179 (display-buffer buffer))))
2180 (setq gdb-source-window window)
2181 (with-current-buffer buffer
2182 (goto-line (string-to-number line))
2183 (set-window-point window (point))))))
2184 (error "No location specified."))))
2187 ;; Frames buffer. This displays a perpetually correct bactracktrace
2188 ;; (from the command `where').
2190 ;; Alas, if your stack is deep, it is costly.
2192 (defcustom gdb-max-frames 40
2193 "Maximum number of frames displayed in call stack."
2198 (gdb-set-buffer-rules 'gdb-stack-buffer
2199 'gdb-stack-buffer-name
2202 (def-gdb-auto-updated-buffer gdb-stack-buffer
2203 gdb-invalidate-frames
2204 (concat "server info stack " (number-to-string gdb-max-frames) "\n")
2205 gdb-info-stack-handler
2206 gdb-info-stack-custom)
2208 ;; This may be more important for embedded targets where unwinding the
2209 ;; stack may take a long time.
2210 (defadvice gdb-invalidate-frames (around gdb-invalidate-frames-advice
2211 (&optional ignored) activate compile)
2212 "Only queue \"info stack\" if execution has occurred."
2213 (if gdb-stack-update ad-do-it))
2215 (defun gdb-info-stack-custom ()
2216 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
2219 (unless (eq gdb-look-up-stack 'delete)
2220 (let ((buffer-read-only nil)
2222 (goto-char (point-min))
2223 (while (< (point) (point-max))
2224 (setq bl (line-beginning-position)
2225 el (line-end-position))
2226 (when (looking-at "#")
2227 (add-text-properties bl el
2228 '(mouse-face highlight
2229 help-echo "mouse-2, RET: Select frame")))
2231 (when (looking-at "^#\\([0-9]+\\)")
2232 (when (string-equal (match-string 1) gdb-frame-number)
2233 (if (> (car (window-fringes)) 0)
2235 (or gdb-stack-position
2236 (setq gdb-stack-position (make-marker)))
2237 (set-marker gdb-stack-position (point))
2238 (setq move-to gdb-stack-position))
2239 (put-text-property bl (+ bl 4)
2240 'face '(:inverse-video t))
2242 (when (re-search-forward "\\([^ ]+\\) (" el t)
2243 (put-text-property (match-beginning 1) (match-end 1)
2244 'face font-lock-function-name-face)
2245 (setq bl (match-end 0))
2246 (while (re-search-forward "<\\([^>]+\\)>" el t)
2247 (put-text-property (match-beginning 1) (match-end 1)
2248 'face font-lock-function-name-face))
2250 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
2251 (put-text-property (match-beginning 1) (match-end 1)
2252 'face font-lock-variable-name-face))))
2255 (when (looking-at "(More stack frames follow...)")
2256 (add-text-properties (match-beginning 0) (match-end 0)
2257 '(mouse-face highlight
2260 "mouse-2, RET: customize gdb-max-frames to see more frames")))))
2261 (when gdb-look-up-stack
2262 (goto-char (point-min))
2263 (when (re-search-forward "\\(\\S-+?\\):\\([0-9]+\\)" nil t)
2264 (let ((start (line-beginning-position))
2265 (file (match-string 1))
2266 (line (match-string 2)))
2267 (re-search-backward "^#*\\([0-9]+\\)" start t)
2269 (list (concat gdb-server-prefix "frame "
2270 (match-string 1) "\n") 'gdb-set-hollow))
2272 (list (concat gdb-server-prefix "frame 0\n") 'ignore))))))
2274 (let ((window (get-buffer-window (current-buffer) 0)))
2276 (with-selected-window window
2278 (unless (pos-visible-in-window-p)
2279 (recenter '(center)))))))))
2280 (if (eq gdb-look-up-stack 'delete)
2281 (kill-buffer (gdb-get-buffer 'gdb-stack-buffer)))
2282 (setq gdb-look-up-stack nil))
2284 (defun gdb-set-hollow ()
2285 (if gud-last-last-frame
2286 (with-current-buffer (gud-find-file (car gud-last-last-frame))
2287 (setq fringe-indicator-alist
2288 '((overlay-arrow . hollow-right-triangle))))))
2290 (defun gdb-stack-buffer-name ()
2291 (with-current-buffer gud-comint-buffer
2292 (concat "*stack frames of " (gdb-get-target-string) "*")))
2294 (defun gdb-display-stack-buffer ()
2295 "Display backtrace of current stack."
2298 (gdb-get-buffer-create 'gdb-stack-buffer) t))
2300 (defun gdb-frame-stack-buffer ()
2301 "Display backtrace of current stack in a new frame."
2303 (let ((special-display-regexps (append special-display-regexps '(".*")))
2304 (special-display-frame-alist gdb-frame-parameters))
2305 (display-buffer (gdb-get-buffer-create 'gdb-stack-buffer))))
2307 (defvar gdb-frames-mode-map
2308 (let ((map (make-sparse-keymap)))
2309 (suppress-keymap map)
2310 (define-key map "q" 'kill-this-buffer)
2311 (define-key map "\r" 'gdb-frames-select)
2312 (define-key map "F" 'gdb-frames-force-update)
2313 (define-key map [mouse-2] 'gdb-frames-select)
2314 (define-key map [follow-link] 'mouse-face)
2317 (defun gdb-frames-force-update ()
2318 "Force update of call stack.
2319 Use when the displayed call stack gets out of sync with the
2320 actual one, e.g after using the Gdb command \"return\" or setting
2321 $pc directly from the GUD buffer. This command isn't normally needed."
2323 (setq gdb-stack-update t)
2324 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2325 (gdb-invalidate-frames)
2326 (gdbmi-invalidate-frames)))
2328 (defun gdb-frames-mode ()
2329 "Major mode for gdb call stack.
2331 \\{gdb-frames-mode-map}"
2332 (kill-all-local-variables)
2333 (setq major-mode 'gdb-frames-mode)
2334 (setq mode-name "Frames")
2335 (setq gdb-stack-position nil)
2336 (add-to-list 'overlay-arrow-variable-list 'gdb-stack-position)
2337 (setq truncate-lines t) ;; Make it easier to see overlay arrow.
2338 (setq buffer-read-only t)
2339 (gdb-thread-identification)
2340 (use-local-map gdb-frames-mode-map)
2341 (run-mode-hooks 'gdb-frames-mode-hook)
2342 (setq gdb-stack-update t)
2343 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2344 'gdb-invalidate-frames
2345 'gdbmi-invalidate-frames))
2347 (defun gdb-get-frame-number ()
2350 (let* ((start (line-beginning-position))
2351 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
2352 (n (or (and pos (match-string 1)) "0")))
2355 (defun gdb-frames-select (&optional event)
2356 "Select the frame and display the relevant source."
2357 (interactive (list last-input-event))
2358 (if event (posn-set-point (event-end event)))
2359 (if (get-text-property (point) 'gdb-max-frames)
2361 (message-box "After setting gdb-max-frames, you need to enter\n\
2362 another GDB command e.g pwd, to see new frames")
2363 (customize-variable-other-window 'gdb-max-frames))
2365 (list (concat gdb-server-prefix "frame "
2366 (gdb-get-frame-number) "\n") 'ignore))))
2369 ;; Threads buffer. This displays a selectable thread list.
2371 (gdb-set-buffer-rules 'gdb-threads-buffer
2372 'gdb-threads-buffer-name
2375 (def-gdb-auto-updated-buffer gdb-threads-buffer
2376 gdb-invalidate-threads
2377 (concat gdb-server-prefix "info threads\n")
2378 gdb-info-threads-handler
2379 gdb-info-threads-custom)
2381 (defun gdb-info-threads-custom ()
2382 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
2383 (let ((buffer-read-only nil))
2385 (goto-char (point-min))
2386 (if (re-search-forward "\\* \\([0-9]+\\)" nil t)
2387 (setq gdb-thread-indicator
2388 (propertize (concat " [" (match-string 1) "]")
2389 ; FIXME: this help-echo doesn't work
2390 'help-echo "thread id")))
2391 (goto-char (point-min))
2392 (while (< (point) (point-max))
2393 (unless (looking-at "No ")
2394 (add-text-properties (line-beginning-position) (line-end-position)
2395 '(mouse-face highlight
2396 help-echo "mouse-2, RET: select thread")))
2397 (forward-line 1))))))
2399 (defun gdb-threads-buffer-name ()
2400 (with-current-buffer gud-comint-buffer
2401 (concat "*threads of " (gdb-get-target-string) "*")))
2403 (defun gdb-display-threads-buffer ()
2404 "Display IDs of currently known threads."
2407 (gdb-get-buffer-create 'gdb-threads-buffer) t))
2409 (defun gdb-frame-threads-buffer ()
2410 "Display IDs of currently known threads 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-threads-buffer))))
2416 (defvar gdb-threads-mode-map
2417 (let ((map (make-sparse-keymap)))
2418 (suppress-keymap map)
2419 (define-key map "q" 'kill-this-buffer)
2420 (define-key map "\r" 'gdb-threads-select)
2421 (define-key map [mouse-2] 'gdb-threads-select)
2422 (define-key map [follow-link] 'mouse-face)
2425 (defvar gdb-threads-font-lock-keywords
2426 '((") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
2427 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
2428 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face)))
2429 "Font lock keywords used in `gdb-threads-mode'.")
2431 (defun gdb-threads-mode ()
2432 "Major mode for gdb threads.
2434 \\{gdb-threads-mode-map}"
2435 (kill-all-local-variables)
2436 (setq major-mode 'gdb-threads-mode)
2437 (setq mode-name "Threads")
2438 (setq buffer-read-only t)
2439 (use-local-map gdb-threads-mode-map)
2440 (set (make-local-variable 'font-lock-defaults)
2441 '(gdb-threads-font-lock-keywords))
2442 (run-mode-hooks 'gdb-threads-mode-hook)
2443 ;; Force "info threads" onto queue.
2444 (lambda () (let ((gud-running nil)) (gdb-invalidate-threads))))
2446 (defun gdb-get-thread-number ()
2448 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
2449 (match-string-no-properties 1)))
2451 (defun gdb-threads-select (&optional event)
2452 "Select the thread and display the relevant source."
2453 (interactive (list last-input-event))
2454 (if event (posn-set-point (event-end event)))
2456 (list (concat gdb-server-prefix "thread "
2457 (gdb-get-thread-number) "\n") 'ignore))
2458 (gud-display-frame))
2460 (defun gdb-thread-identification ()
2461 (setq mode-line-buffer-identification
2462 (list (car mode-line-buffer-identification)
2463 '(gdb-thread-indicator gdb-thread-indicator))))
2465 ;; Registers buffer.
2467 (defcustom gdb-all-registers nil
2468 "Non-nil means include floating-point registers."
2473 (gdb-set-buffer-rules 'gdb-registers-buffer
2474 'gdb-registers-buffer-name
2475 'gdb-registers-mode)
2477 (def-gdb-auto-updated-buffer gdb-registers-buffer
2478 gdb-invalidate-registers
2480 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
2481 gdb-info-registers-handler
2482 gdb-info-registers-custom)
2484 (defun gdb-info-registers-custom ()
2485 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2487 (let ((buffer-read-only nil)
2489 (goto-char (point-min))
2490 (while (< (point) (point-max))
2491 (setq start (line-beginning-position))
2492 (setq end (line-end-position))
2493 (when (looking-at "^[^ ]+")
2494 (unless (string-equal (match-string 0) "The")
2495 (put-text-property start (match-end 0)
2496 'face font-lock-variable-name-face)
2497 (add-text-properties start end
2498 '(help-echo "mouse-2: edit value"
2499 mouse-face highlight))))
2500 (forward-line 1))))))
2502 (defun gdb-edit-register-value (&optional event)
2503 (interactive (list last-input-event))
2505 (if event (posn-set-point (event-end event)))
2507 (let* ((register (current-word))
2508 (value (read-string (format "New value (%s): " register))))
2510 (list (concat gdb-server-prefix "set $" register "=" value "\n")
2513 (defvar gdb-registers-mode-map
2514 (let ((map (make-sparse-keymap)))
2515 (suppress-keymap map)
2516 (define-key map "\r" 'gdb-edit-register-value)
2517 (define-key map [mouse-2] 'gdb-edit-register-value)
2518 (define-key map " " 'gdb-all-registers)
2519 (define-key map "q" 'kill-this-buffer)
2522 (defun gdb-registers-mode ()
2523 "Major mode for gdb registers.
2525 \\{gdb-registers-mode-map}"
2526 (kill-all-local-variables)
2527 (setq major-mode 'gdb-registers-mode)
2528 (setq mode-name "Registers")
2529 (setq buffer-read-only t)
2530 (gdb-thread-identification)
2531 (use-local-map gdb-registers-mode-map)
2532 (run-mode-hooks 'gdb-registers-mode-hook)
2533 (if (string-equal gdb-version "pre-6.4")
2535 (if gdb-all-registers (setq mode-name "Registers:All"))
2536 'gdb-invalidate-registers)
2537 'gdb-invalidate-registers-1))
2539 (defun gdb-registers-buffer-name ()
2540 (with-current-buffer gud-comint-buffer
2541 (concat "*registers of " (gdb-get-target-string) "*")))
2543 (defun gdb-display-registers-buffer ()
2544 "Display integer register contents."
2547 (gdb-get-buffer-create 'gdb-registers-buffer) t))
2549 (defun gdb-frame-registers-buffer ()
2550 "Display integer register contents in a new frame."
2552 (let ((special-display-regexps (append special-display-regexps '(".*")))
2553 (special-display-frame-alist gdb-frame-parameters))
2554 (display-buffer (gdb-get-buffer-create 'gdb-registers-buffer))))
2556 (defun gdb-all-registers ()
2557 "Toggle the display of floating-point registers (pre GDB 6.4 only)."
2559 (when (string-equal gdb-version "pre-6.4")
2560 (if gdb-all-registers
2562 (setq gdb-all-registers nil)
2563 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2564 (setq mode-name "Registers")))
2565 (setq gdb-all-registers t)
2566 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2567 (setq mode-name "Registers:All")))
2568 (message (format "Display of floating-point registers %sabled"
2569 (if gdb-all-registers "en" "dis")))
2570 (gdb-invalidate-registers)))
2575 (defcustom gdb-memory-repeat-count 32
2576 "Number of data items in memory window."
2581 (defcustom gdb-memory-format "x"
2582 "Display format of data items in memory window."
2583 :type '(choice (const :tag "Hexadecimal" "x")
2584 (const :tag "Signed decimal" "d")
2585 (const :tag "Unsigned decimal" "u")
2586 (const :tag "Octal" "o")
2587 (const :tag "Binary" "t"))
2591 (defcustom gdb-memory-unit "w"
2592 "Unit size of data items in memory window."
2593 :type '(choice (const :tag "Byte" "b")
2594 (const :tag "Halfword" "h")
2595 (const :tag "Word" "w")
2596 (const :tag "Giant word" "g"))
2600 (gdb-set-buffer-rules 'gdb-memory-buffer
2601 'gdb-memory-buffer-name
2604 (def-gdb-auto-updated-buffer gdb-memory-buffer
2605 gdb-invalidate-memory
2606 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
2607 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
2608 gdb-read-memory-handler
2609 gdb-read-memory-custom)
2611 (defun gdb-read-memory-custom ()
2613 (goto-char (point-min))
2614 (if (looking-at "0x[[:xdigit:]]+")
2615 (setq gdb-memory-address (match-string 0)))))
2617 (defvar gdb-memory-mode-map
2618 (let ((map (make-sparse-keymap)))
2619 (suppress-keymap map)
2620 (define-key map "q" 'kill-this-buffer)
2623 (defun gdb-memory-set-address (event)
2624 "Set the start memory address."
2626 (save-selected-window
2627 (select-window (posn-window (event-start event)))
2628 (let ((arg (read-from-minibuffer "Memory address: ")))
2629 (setq gdb-memory-address arg))
2630 (gdb-invalidate-memory)))
2632 (defun gdb-memory-set-repeat-count (event)
2633 "Set the number of data items in memory window."
2635 (save-selected-window
2636 (select-window (posn-window (event-start event)))
2637 (let* ((arg (read-from-minibuffer "Repeat count: "))
2638 (count (string-to-number arg)))
2640 (error "Positive numbers only")
2641 (customize-set-variable 'gdb-memory-repeat-count count)
2642 (gdb-invalidate-memory)))))
2644 (defun gdb-memory-format-binary ()
2645 "Set the display format to binary."
2647 (customize-set-variable 'gdb-memory-format "t")
2648 (gdb-invalidate-memory))
2650 (defun gdb-memory-format-octal ()
2651 "Set the display format to octal."
2653 (customize-set-variable 'gdb-memory-format "o")
2654 (gdb-invalidate-memory))
2656 (defun gdb-memory-format-unsigned ()
2657 "Set the display format to unsigned decimal."
2659 (customize-set-variable 'gdb-memory-format "u")
2660 (gdb-invalidate-memory))
2662 (defun gdb-memory-format-signed ()
2663 "Set the display format to decimal."
2665 (customize-set-variable 'gdb-memory-format "d")
2666 (gdb-invalidate-memory))
2668 (defun gdb-memory-format-hexadecimal ()
2669 "Set the display format to hexadecimal."
2671 (customize-set-variable 'gdb-memory-format "x")
2672 (gdb-invalidate-memory))
2674 (defvar gdb-memory-format-map
2675 (let ((map (make-sparse-keymap)))
2676 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2678 "Keymap to select format in the header line.")
2680 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2681 "Menu of display formats in the header line.")
2683 (define-key gdb-memory-format-menu [binary]
2684 '(menu-item "Binary" gdb-memory-format-binary
2685 :button (:radio . (equal gdb-memory-format "t"))))
2686 (define-key gdb-memory-format-menu [octal]
2687 '(menu-item "Octal" gdb-memory-format-octal
2688 :button (:radio . (equal gdb-memory-format "o"))))
2689 (define-key gdb-memory-format-menu [unsigned]
2690 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2691 :button (:radio . (equal gdb-memory-format "u"))))
2692 (define-key gdb-memory-format-menu [signed]
2693 '(menu-item "Signed Decimal" gdb-memory-format-signed
2694 :button (:radio . (equal gdb-memory-format "d"))))
2695 (define-key gdb-memory-format-menu [hexadecimal]
2696 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2697 :button (:radio . (equal gdb-memory-format "x"))))
2699 (defun gdb-memory-format-menu (event)
2701 (x-popup-menu event gdb-memory-format-menu))
2703 (defun gdb-memory-format-menu-1 (event)
2705 (save-selected-window
2706 (select-window (posn-window (event-start event)))
2707 (let* ((selection (gdb-memory-format-menu event))
2708 (binding (and selection (lookup-key gdb-memory-format-menu
2709 (vector (car selection))))))
2710 (if binding (call-interactively binding)))))
2712 (defun gdb-memory-unit-giant ()
2713 "Set the unit size to giant words (eight bytes)."
2715 (customize-set-variable 'gdb-memory-unit "g")
2716 (gdb-invalidate-memory))
2718 (defun gdb-memory-unit-word ()
2719 "Set the unit size to words (four bytes)."
2721 (customize-set-variable 'gdb-memory-unit "w")
2722 (gdb-invalidate-memory))
2724 (defun gdb-memory-unit-halfword ()
2725 "Set the unit size to halfwords (two bytes)."
2727 (customize-set-variable 'gdb-memory-unit "h")
2728 (gdb-invalidate-memory))
2730 (defun gdb-memory-unit-byte ()
2731 "Set the unit size to bytes."
2733 (customize-set-variable 'gdb-memory-unit "b")
2734 (gdb-invalidate-memory))
2736 (defvar gdb-memory-unit-map
2737 (let ((map (make-sparse-keymap)))
2738 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2740 "Keymap to select units in the header line.")
2742 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2743 "Menu of units in the header line.")
2745 (define-key gdb-memory-unit-menu [giantwords]
2746 '(menu-item "Giant words" gdb-memory-unit-giant
2747 :button (:radio . (equal gdb-memory-unit "g"))))
2748 (define-key gdb-memory-unit-menu [words]
2749 '(menu-item "Words" gdb-memory-unit-word
2750 :button (:radio . (equal gdb-memory-unit "w"))))
2751 (define-key gdb-memory-unit-menu [halfwords]
2752 '(menu-item "Halfwords" gdb-memory-unit-halfword
2753 :button (:radio . (equal gdb-memory-unit "h"))))
2754 (define-key gdb-memory-unit-menu [bytes]
2755 '(menu-item "Bytes" gdb-memory-unit-byte
2756 :button (:radio . (equal gdb-memory-unit "b"))))
2758 (defun gdb-memory-unit-menu (event)
2760 (x-popup-menu event gdb-memory-unit-menu))
2762 (defun gdb-memory-unit-menu-1 (event)
2764 (save-selected-window
2765 (select-window (posn-window (event-start event)))
2766 (let* ((selection (gdb-memory-unit-menu event))
2767 (binding (and selection (lookup-key gdb-memory-unit-menu
2768 (vector (car selection))))))
2769 (if binding (call-interactively binding)))))
2771 ;;from make-mode-line-mouse-map
2772 (defun gdb-make-header-line-mouse-map (mouse function) "\
2773 Return a keymap with single entry for mouse key MOUSE on the header line.
2774 MOUSE is defined to run function FUNCTION with no args in the buffer
2775 corresponding to the mode line clicked."
2776 (let ((map (make-sparse-keymap)))
2777 (define-key map (vector 'header-line mouse) function)
2778 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2781 (defvar gdb-memory-font-lock-keywords
2782 '(;; <__function.name+n>
2783 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2785 "Font lock keywords used in `gdb-memory-mode'.")
2787 (defun gdb-memory-mode ()
2788 "Major mode for examining memory.
2790 \\{gdb-memory-mode-map}"
2791 (kill-all-local-variables)
2792 (setq major-mode 'gdb-memory-mode)
2793 (setq mode-name "Memory")
2794 (setq buffer-read-only t)
2795 (use-local-map gdb-memory-mode-map)
2796 (setq header-line-format
2802 'face font-lock-warning-face
2803 'help-echo "mouse-1: decrement address"
2804 'mouse-face 'mode-line-highlight
2806 (gdb-make-header-line-mouse-map
2808 (lambda () (interactive)
2809 (let ((gdb-memory-address
2810 ;; Let GDB do the arithmetic.
2812 gdb-memory-address " - "
2814 (* gdb-memory-repeat-count
2815 (cond ((string= gdb-memory-unit "b") 1)
2816 ((string= gdb-memory-unit "h") 2)
2817 ((string= gdb-memory-unit "w") 4)
2818 ((string= gdb-memory-unit "g") 8)))))))
2819 (gdb-invalidate-memory)))))
2822 'face font-lock-warning-face
2823 'help-echo "mouse-1: increment address"
2824 'mouse-face 'mode-line-highlight
2825 'local-map (gdb-make-header-line-mouse-map
2827 (lambda () (interactive)
2828 (let ((gdb-memory-address nil))
2829 (gdb-invalidate-memory)))))
2831 (propertize gdb-memory-address
2832 'face font-lock-warning-face
2833 'help-echo "mouse-1: set memory address"
2834 'mouse-face 'mode-line-highlight
2835 'local-map (gdb-make-header-line-mouse-map
2837 #'gdb-memory-set-address))
2839 (propertize (number-to-string gdb-memory-repeat-count)
2840 'face font-lock-warning-face
2841 'help-echo "mouse-1: set repeat count"
2842 'mouse-face 'mode-line-highlight
2843 'local-map (gdb-make-header-line-mouse-map
2845 #'gdb-memory-set-repeat-count))
2847 (propertize gdb-memory-format
2848 'face font-lock-warning-face
2849 'help-echo "mouse-3: select display format"
2850 'mouse-face 'mode-line-highlight
2851 'local-map gdb-memory-format-map)
2853 (propertize gdb-memory-unit
2854 'face font-lock-warning-face
2855 'help-echo "mouse-3: select unit size"
2856 'mouse-face 'mode-line-highlight
2857 'local-map gdb-memory-unit-map))))
2858 (set (make-local-variable 'font-lock-defaults)
2859 '(gdb-memory-font-lock-keywords))
2860 (run-mode-hooks 'gdb-memory-mode-hook)
2861 'gdb-invalidate-memory)
2863 (defun gdb-memory-buffer-name ()
2864 (with-current-buffer gud-comint-buffer
2865 (concat "*memory of " (gdb-get-target-string) "*")))
2867 (defun gdb-display-memory-buffer ()
2868 "Display memory contents."
2871 (gdb-get-buffer-create 'gdb-memory-buffer) t))
2873 (defun gdb-frame-memory-buffer ()
2874 "Display memory contents in a new frame."
2876 (let* ((special-display-regexps (append special-display-regexps '(".*")))
2877 (special-display-frame-alist
2878 (cons '(left-fringe . 0)
2879 (cons '(right-fringe . 0)
2880 (cons '(width . 83) gdb-frame-parameters)))))
2881 (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
2886 (gdb-set-buffer-rules 'gdb-locals-buffer
2887 'gdb-locals-buffer-name
2890 (def-gdb-auto-update-trigger gdb-invalidate-locals
2891 (gdb-get-buffer 'gdb-locals-buffer)
2892 "server info locals\n"
2893 gdb-info-locals-handler)
2895 (defvar gdb-locals-watch-map
2896 (let ((map (make-sparse-keymap)))
2897 (suppress-keymap map)
2898 (define-key map "\r" (lambda () (interactive)
2901 (define-key map [mouse-2] (lambda (event) (interactive "e")
2902 (mouse-set-point event)
2906 "Keymap to create watch expression of a complex data type local variable.")
2908 (defconst gdb-struct-string
2909 (concat (propertize "[struct/union]"
2910 'mouse-face 'highlight
2911 'help-echo "mouse-2: create watch expression"
2912 'local-map gdb-locals-watch-map) "\n"))
2914 (defconst gdb-array-string
2915 (concat " " (propertize "[array]"
2916 'mouse-face 'highlight
2917 'help-echo "mouse-2: create watch expression"
2918 'local-map gdb-locals-watch-map) "\n"))
2920 ;; Abbreviate for arrays and structures.
2921 ;; These can be expanded using gud-display.
2922 (defun gdb-info-locals-handler ()
2923 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2924 gdb-pending-triggers))
2925 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2926 (with-current-buffer buf
2927 (goto-char (point-min))
2928 (while (re-search-forward "^[ }].*\n" nil t)
2929 (replace-match "" nil nil))
2930 (goto-char (point-min))
2931 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2932 (replace-match gdb-struct-string nil nil))
2933 (goto-char (point-min))
2934 (while (re-search-forward "\\s-*{.*\n" nil t)
2935 (replace-match gdb-array-string nil nil))))
2936 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2938 (with-current-buffer buf
2939 (let* ((window (get-buffer-window buf 0))
2940 (start (window-start window))
2941 (p (window-point window))
2942 (buffer-read-only nil))
2944 (insert-buffer-substring (gdb-get-buffer-create
2945 'gdb-partial-output-buffer))
2946 (set-window-start window start)
2947 (set-window-point window p))
2949 (run-hooks 'gdb-info-locals-hook))
2951 (defvar gdb-locals-mode-map
2952 (let ((map (make-sparse-keymap)))
2953 (suppress-keymap map)
2954 (define-key map "q" 'kill-this-buffer)
2957 (defun gdb-locals-mode ()
2958 "Major mode for gdb locals.
2960 \\{gdb-locals-mode-map}"
2961 (kill-all-local-variables)
2962 (setq major-mode 'gdb-locals-mode)
2963 (setq mode-name (concat "Locals:" gdb-selected-frame))
2964 (setq buffer-read-only t)
2965 (gdb-thread-identification)
2966 (use-local-map gdb-locals-mode-map)
2967 (set (make-local-variable 'font-lock-defaults)
2968 '(gdb-locals-font-lock-keywords))
2969 (run-mode-hooks 'gdb-locals-mode-hook)
2970 (if (and (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2971 (string-equal gdb-version "pre-6.4"))
2972 'gdb-invalidate-locals
2973 'gdb-invalidate-locals-1))
2975 (defun gdb-locals-buffer-name ()
2976 (with-current-buffer gud-comint-buffer
2977 (concat "*locals of " (gdb-get-target-string) "*")))
2979 (defun gdb-display-locals-buffer ()
2980 "Display local variables of current stack and their values."
2983 (gdb-get-buffer-create 'gdb-locals-buffer) t))
2985 (defun gdb-frame-locals-buffer ()
2986 "Display local variables of current stack and their values in a new frame."
2988 (let ((special-display-regexps (append special-display-regexps '(".*")))
2989 (special-display-frame-alist gdb-frame-parameters))
2990 (display-buffer (gdb-get-buffer-create 'gdb-locals-buffer))))
2993 ;;;; Window management
2994 (defun gdb-display-buffer (buf dedicated &optional size)
2995 (let ((answer (get-buffer-window buf 0))
2998 (display-buffer buf nil 0) ;Deiconify the frame if necessary.
2999 ;; The buffer is not yet displayed.
3000 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
3001 (let ((window (get-lru-window)))
3003 (not (memq window `(,(get-buffer-window gud-comint-buffer)
3004 ,gdb-source-window))))
3006 (set-window-buffer window buf)
3007 (setq answer window))
3008 (setq must-split t)))
3010 (let* ((largest (get-largest-window))
3011 (cur-size (window-height largest))
3012 (new-size (and size (< size cur-size) (- cur-size size))))
3013 (setq answer (split-window largest new-size))
3014 (set-window-buffer answer buf)
3015 (set-window-dedicated-p answer dedicated)))
3019 ;;; Shared keymap initialization:
3021 (let ((menu (make-sparse-keymap "GDB-Windows")))
3022 (define-key gud-menu-map [displays]
3023 `(menu-item "GDB-Windows" ,menu
3024 :help "Open a GDB-UI buffer in a new window."
3025 :visible (memq gud-minor-mode '(gdbmi gdba))))
3026 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
3027 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
3028 (define-key menu [inferior]
3029 '(menu-item "Separate IO" gdb-display-separate-io-buffer
3030 :enable gdb-use-separate-io-buffer))
3031 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
3032 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
3033 (define-key menu [disassembly]
3034 '("Disassembly" . gdb-display-assembler-buffer))
3035 (define-key menu [breakpoints]
3036 '("Breakpoints" . gdb-display-breakpoints-buffer))
3037 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
3038 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)))
3040 (let ((menu (make-sparse-keymap "GDB-Frames")))
3041 (define-key gud-menu-map [frames]
3042 `(menu-item "GDB-Frames" ,menu
3043 :help "Open a GDB-UI buffer in a new frame."
3044 :visible (memq gud-minor-mode '(gdbmi gdba))))
3045 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
3046 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
3047 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
3048 (define-key menu [inferior]
3049 '(menu-item "Separate IO" gdb-frame-separate-io-buffer
3050 :enable gdb-use-separate-io-buffer))
3051 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
3052 (define-key menu [disassembly] '("Disassembly" . gdb-frame-assembler-buffer))
3053 (define-key menu [breakpoints]
3054 '("Breakpoints" . gdb-frame-breakpoints-buffer))
3055 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
3056 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)))
3058 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
3059 (define-key gud-menu-map [ui]
3060 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
3061 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
3062 (define-key menu [gdb-customize]
3063 '(menu-item "Customize" (lambda () (interactive) (customize-group 'gdb))
3064 :help "Customize Gdb Graphical Mode options."))
3065 (define-key menu [gdb-find-source-frame]
3066 '(menu-item "Look For Source Frame" gdb-find-source-frame
3067 :visible (eq gud-minor-mode 'gdba)
3068 :help "Toggle looking for source frame further up call stack."
3069 :button (:toggle . gdb-find-source-frame)))
3070 (define-key menu [gdb-use-separate-io]
3071 '(menu-item "Separate IO" gdb-use-separate-io-buffer
3072 :visible (eq gud-minor-mode 'gdba)
3073 :help "Toggle separate IO for debugged program."
3074 :button (:toggle . gdb-use-separate-io-buffer)))
3075 (define-key menu [gdb-many-windows]
3076 '(menu-item "Display Other Windows" gdb-many-windows
3077 :help "Toggle display of locals, stack and breakpoint information"
3078 :button (:toggle . gdb-many-windows)))
3079 (define-key menu [gdb-restore-windows]
3080 '(menu-item "Restore Window Layout" gdb-restore-windows
3081 :help "Restore standard layout for debug session.")))
3083 (defun gdb-frame-gdb-buffer ()
3084 "Display GUD buffer in a new frame."
3086 (let ((special-display-regexps (append special-display-regexps '(".*")))
3087 (special-display-frame-alist
3088 (remove '(menu-bar-lines) (remove '(tool-bar-lines)
3089 gdb-frame-parameters)))
3090 (same-window-regexps nil))
3091 (display-buffer gud-comint-buffer)))
3093 (defun gdb-display-gdb-buffer ()
3094 "Display GUD buffer."
3096 (let ((same-window-regexps nil))
3097 (pop-to-buffer gud-comint-buffer)))
3099 (defun gdb-set-window-buffer (name)
3100 (set-window-buffer (selected-window) (get-buffer name))
3101 (set-window-dedicated-p (selected-window) t))
3103 (defun gdb-setup-windows ()
3104 "Layout the window pattern for `gdb-many-windows'."
3105 (gdb-display-locals-buffer)
3106 (gdb-display-stack-buffer)
3107 (delete-other-windows)
3108 (gdb-display-breakpoints-buffer)
3109 (delete-other-windows)
3111 (pop-to-buffer gud-comint-buffer)
3112 (split-window nil ( / ( * (window-height) 3) 4))
3113 (split-window nil ( / (window-height) 3))
3114 (split-window-horizontally)
3116 (gdb-set-window-buffer (gdb-locals-buffer-name))
3119 (if gud-last-last-frame
3120 (gud-find-file (car gud-last-last-frame))
3122 (gud-find-file gdb-main-file)
3123 ;; Put buffer list in window if we
3124 ;; can't find a source file.
3125 (list-buffers-noselect))))
3126 (setq gdb-source-window (selected-window))
3127 (when gdb-use-separate-io-buffer
3128 (split-window-horizontally)
3130 (gdb-set-window-buffer
3131 (gdb-get-buffer-create 'gdb-inferior-io)))
3133 (gdb-set-window-buffer (gdb-stack-buffer-name))
3134 (split-window-horizontally)
3136 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
3139 (defun gdb-restore-windows ()
3140 "Restore the basic arrangement of windows used by gdba.
3141 This arrangement depends on the value of `gdb-many-windows'."
3143 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
3144 (delete-other-windows)
3145 (if gdb-many-windows
3147 (when (or gud-last-last-frame gdb-show-main)
3151 (if gud-last-last-frame
3152 (gud-find-file (car gud-last-last-frame))
3153 (gud-find-file gdb-main-file)))
3154 (setq gdb-source-window (selected-window))
3158 "Exit a debugging session cleanly.
3159 Kills the gdb buffers, and resets variables and the source buffers."
3160 (dolist (buffer (buffer-list))
3161 (unless (eq buffer gud-comint-buffer)
3162 (with-current-buffer buffer
3163 (if (memq gud-minor-mode '(gdbmi gdba))
3164 (if (string-match "\\` ?\\*.+\\*\\'" (buffer-name))
3166 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
3167 (setq gud-minor-mode nil)
3168 (kill-local-variable 'tool-bar-map)
3169 (kill-local-variable 'gdb-define-alist))))))
3170 (setq gdb-overlay-arrow-position nil)
3171 (setq overlay-arrow-variable-list
3172 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
3173 (setq fringe-indicator-alist '((overlay-arrow . right-triangle)))
3174 (setq gdb-stack-position nil)
3175 (setq overlay-arrow-variable-list
3176 (delq 'gdb-stack-position overlay-arrow-variable-list))
3177 (if (boundp 'speedbar-frame) (speedbar-timer-fn))
3178 (setq gud-running nil)
3179 (setq gdb-active-process nil)
3180 (setq gdb-var-list nil)
3181 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
3183 (defun gdb-source-info ()
3184 "Find the source file where the program starts and displays it with related
3186 (goto-char (point-min))
3187 (if (and (search-forward "Located in " nil t)
3188 (looking-at "\\S-+"))
3189 (setq gdb-main-file (match-string 0)))
3190 (goto-char (point-min))
3191 (if (search-forward "Includes preprocessor macro info." nil t)
3192 (setq gdb-macro-info t))
3193 (if gdb-many-windows
3195 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
3197 (let ((pop-up-windows t))
3198 (display-buffer (gud-find-file gdb-main-file)))))
3201 (defun gdb-get-location (bptno line flag)
3202 "Find the directory containing the relevant source file.
3203 Put in buffer and place breakpoint icon."
3204 (goto-char (point-min))
3205 (catch 'file-not-found
3206 (if (search-forward "Located in " nil t)
3207 (when (looking-at "\\S-+")
3208 (delete (cons bptno "File not found") gdb-location-alist)
3209 (push (cons bptno (match-string 0)) gdb-location-alist))
3211 (unless (assoc bptno gdb-location-alist)
3212 (push (cons bptno "File not found") gdb-location-alist)
3213 (message-box "Cannot find source file for breakpoint location.\n\
3214 Add directory to search path for source files using the GDB command, dir."))
3215 (throw 'file-not-found nil))
3216 (with-current-buffer
3217 (find-file-noselect (match-string 0))
3218 (save-current-buffer
3219 (set (make-local-variable 'gud-minor-mode) 'gdba)
3220 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
3221 ;; only want one breakpoint icon at each location
3223 (goto-line (string-to-number line))
3224 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
3226 (add-hook 'find-file-hook 'gdb-find-file-hook)
3228 (defun gdb-find-file-hook ()
3229 "Set up buffer for debugging if file is part of the source code
3230 of the current session."
3231 (if (and (buffer-name gud-comint-buffer)
3232 ;; in case gud or gdb-ui is just loaded
3234 (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
3236 ;;Pre GDB 6.3 "info sources" doesn't give absolute file name.
3237 (if (member (if (string-equal gdb-version "pre-6.4")
3238 (file-name-nondirectory buffer-file-name)
3240 gdb-source-file-list)
3241 (with-current-buffer (find-buffer-visiting buffer-file-name)
3242 (set (make-local-variable 'gud-minor-mode)
3243 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
3244 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)))))
3247 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
3248 "Put string PUTSTRING in front of POS in the current buffer.
3249 PUTSTRING is displayed by putting an overlay into the current buffer with a
3250 `before-string' string that has a `display' property whose value is
3252 (let ((string (make-string 1 ?x))
3253 (buffer (current-buffer)))
3254 (setq putstring (copy-sequence putstring))
3255 (let ((overlay (make-overlay pos pos buffer))
3257 (list (list 'margin 'left-margin) putstring))))
3258 (put-text-property 0 1 'display prop string)
3260 (add-text-properties 0 1 sprops string))
3261 (overlay-put overlay 'put-break t)
3262 (overlay-put overlay 'before-string string))))
3264 ;;from remove-images
3265 (defun gdb-remove-strings (start end &optional buffer)
3266 "Remove strings between START and END in BUFFER.
3267 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
3268 BUFFER nil or omitted means use the current buffer."
3270 (setq buffer (current-buffer)))
3271 (dolist (overlay (overlays-in start end))
3272 (when (overlay-get overlay 'put-break)
3273 (delete-overlay overlay))))
3275 (defun gdb-put-breakpoint-icon (enabled bptno)
3276 (if (string-match "[0-9+]+\\." bptno)
3277 (setq enabled gdb-parent-bptno-enabled))
3278 (let ((start (- (line-beginning-position) 1))
3279 (end (+ (line-end-position) 1))
3280 (putstring (if enabled "B" "b"))
3281 (source-window (get-buffer-window (current-buffer) 0)))
3282 (add-text-properties
3283 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
3286 (add-text-properties
3287 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
3288 (add-text-properties
3289 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
3290 (gdb-remove-breakpoint-icons start end)
3291 (if (display-images-p)
3292 (if (>= (or left-fringe-width
3293 (if source-window (car (window-fringes source-window)))
3294 gdb-buffer-fringe-width) 8)
3297 `(left-fringe breakpoint
3300 'breakpoint-disabled))
3302 'gdb-enabled enabled)
3303 (when (< left-margin-width 2)
3304 (save-current-buffer
3305 (setq left-margin-width 2)
3309 left-margin-width right-margin-width))))
3312 (or breakpoint-enabled-icon
3313 (setq breakpoint-enabled-icon
3314 (find-image `((:type xpm :data
3315 ,breakpoint-xpm-data
3316 :ascent 100 :pointer hand)
3318 ,breakpoint-enabled-pbm-data
3319 :ascent 100 :pointer hand)))))
3320 (or breakpoint-disabled-icon
3321 (setq breakpoint-disabled-icon
3322 (find-image `((:type xpm :data
3323 ,breakpoint-xpm-data
3324 :conversion disabled
3325 :ascent 100 :pointer hand)
3327 ,breakpoint-disabled-pbm-data
3328 :ascent 100 :pointer hand))))))
3332 (when (< left-margin-width 2)
3333 (save-current-buffer
3334 (setq left-margin-width 2)
3335 (let ((window (get-buffer-window (current-buffer) 0)))
3338 window left-margin-width right-margin-width)))))
3340 (propertize putstring
3341 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
3344 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
3345 (gdb-remove-strings start end)
3346 (if (display-images-p)
3347 (remove-images start end))
3349 (setq left-margin-width 0)
3350 (let ((window (get-buffer-window (current-buffer) 0)))
3353 window left-margin-width right-margin-width)))))
3357 ;; Assembler buffer.
3359 (gdb-set-buffer-rules 'gdb-assembler-buffer
3360 'gdb-assembler-buffer-name
3361 'gdb-assembler-mode)
3363 ;; We can't use def-gdb-auto-update-handler because we don't want to use
3364 ;; window-start but keep the overlay arrow/current line visible.
3365 (defun gdb-assembler-handler ()
3366 (setq gdb-pending-triggers
3367 (delq 'gdb-invalidate-assembler
3368 gdb-pending-triggers))
3369 (let ((buf (gdb-get-buffer 'gdb-assembler-buffer)))
3371 (with-current-buffer buf
3372 (let* ((window (get-buffer-window buf 0))
3373 (p (window-point window))
3374 (buffer-read-only nil))
3376 (insert-buffer-substring (gdb-get-buffer-create
3377 'gdb-partial-output-buffer))
3378 (set-window-point window p)))))
3379 ;; put customisation here
3380 (gdb-assembler-custom))
3382 (defun gdb-assembler-custom ()
3383 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
3384 (pos 1) (address) (flag) (bptno))
3385 (with-current-buffer buffer
3387 (if (not (equal gdb-pc-address "main"))
3389 (goto-char (point-min))
3390 (if (and gdb-pc-address
3391 (search-forward gdb-pc-address nil t))
3395 (setq fringe-indicator-alist
3396 (if (string-equal gdb-frame-number "0")
3398 '((overlay-arrow . hollow-right-triangle))))
3399 (or gdb-overlay-arrow-position
3400 (setq gdb-overlay-arrow-position (make-marker)))
3401 (set-marker gdb-overlay-arrow-position (point))))))
3402 ;; remove all breakpoint-icons in assembler buffer before updating.
3403 (gdb-remove-breakpoint-icons (point-min) (point-max))))
3404 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
3405 (goto-char (point-min))
3406 (while (< (point) (- (point-max) 1))
3409 "\\([0-9]+\\.?[0-9]*\\).*?\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
3410 (setq bptno (match-string 1))
3411 (setq flag (char-after (match-beginning 2)))
3412 (setq address (match-string 3))
3413 (with-current-buffer buffer
3415 (goto-char (point-min))
3416 (if (search-forward address nil t)
3417 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))))
3418 (if (not (equal gdb-pc-address "main"))
3419 (with-current-buffer buffer
3420 (set-window-point (get-buffer-window buffer 0) pos)))))
3422 (defvar gdb-assembler-mode-map
3423 (let ((map (make-sparse-keymap)))
3424 (suppress-keymap map)
3425 (define-key map "q" 'kill-this-buffer)
3428 (defvar gdb-assembler-font-lock-keywords
3429 '(;; <__function.name+n>
3430 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
3431 (1 font-lock-function-name-face))
3432 ;; 0xNNNNNNNN <__function.name+n>: opcode
3433 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
3434 (4 font-lock-keyword-face))
3435 ;; %register(at least i386)
3436 ("%\\sw+" . font-lock-variable-name-face)
3437 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
3438 (1 font-lock-comment-face)
3439 (2 font-lock-function-name-face))
3440 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
3441 "Font lock keywords used in `gdb-assembler-mode'.")
3443 (defun gdb-assembler-mode ()
3444 "Major mode for viewing code assembler.
3446 \\{gdb-assembler-mode-map}"
3447 (kill-all-local-variables)
3448 (setq major-mode 'gdb-assembler-mode)
3449 (setq mode-name (concat "Machine:" gdb-selected-frame))
3450 (setq gdb-overlay-arrow-position nil)
3451 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
3452 (setq fringes-outside-margins t)
3453 (setq buffer-read-only t)
3454 (gdb-thread-identification)
3455 (use-local-map gdb-assembler-mode-map)
3456 (gdb-invalidate-assembler)
3457 (set (make-local-variable 'font-lock-defaults)
3458 '(gdb-assembler-font-lock-keywords))
3459 (run-mode-hooks 'gdb-assembler-mode-hook)
3460 'gdb-invalidate-assembler)
3462 (defun gdb-assembler-buffer-name ()
3463 (with-current-buffer gud-comint-buffer
3464 (concat "*disassembly of " (gdb-get-target-string) "*")))
3466 (defun gdb-display-assembler-buffer ()
3467 "Display disassembly view."
3469 (setq gdb-previous-frame nil)
3471 (gdb-get-buffer-create 'gdb-assembler-buffer) t))
3473 (defun gdb-frame-assembler-buffer ()
3474 "Display disassembly view in a new frame."
3476 (setq gdb-previous-frame nil)
3477 (let ((special-display-regexps (append special-display-regexps '(".*")))
3478 (special-display-frame-alist gdb-frame-parameters))
3479 (display-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))))
3481 ;; modified because if gdb-pc-address has changed value a new command
3482 ;; must be enqueued to update the buffer with the new output
3483 (defun gdb-invalidate-assembler (&optional ignored)
3484 (if (gdb-get-buffer 'gdb-assembler-buffer)
3486 (unless (and gdb-selected-frame
3487 (string-equal gdb-selected-frame gdb-previous-frame))
3488 (if (or (not (member 'gdb-invalidate-assembler
3489 gdb-pending-triggers))
3490 (not (string-equal gdb-pc-address
3491 gdb-previous-frame-address)))
3493 ;; take previous disassemble command, if any, off the queue
3494 (with-current-buffer gud-comint-buffer
3495 (let ((queue gdb-input-queue))
3496 (dolist (item queue)
3497 (if (equal (cdr item) '(gdb-assembler-handler))
3498 (setq gdb-input-queue
3499 (delete item gdb-input-queue))))))
3502 (concat gdb-server-prefix "disassemble "
3503 (if (member gdb-pc-address '(nil "main")) nil "0x")
3504 gdb-pc-address "\n")
3505 'gdb-assembler-handler))
3506 (push 'gdb-invalidate-assembler gdb-pending-triggers)
3507 (setq gdb-previous-frame-address gdb-pc-address)
3508 (setq gdb-previous-frame gdb-selected-frame)))))))
3510 (defun gdb-get-selected-frame ()
3511 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
3514 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
3515 (push 'gdb-get-selected-frame
3516 gdb-pending-triggers))))
3518 (defun gdb-frame-handler ()
3519 (setq gdb-pending-triggers
3520 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3521 (goto-char (point-min))
3522 (when (re-search-forward
3523 "Stack level \\([0-9]+\\), frame at \\(0x[[:xdigit:]]+\\)" nil t)
3524 (setq gdb-frame-number (match-string 1))
3525 (setq gdb-frame-address (match-string 2)))
3526 (goto-char (point-min))
3527 (when (re-search-forward ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(.*?\\)\
3528 \\(?: (\\(\\S-+?\\):[0-9]+?)\\)*; "
3530 (setq gdb-selected-frame (match-string 2))
3531 (if (gdb-get-buffer 'gdb-locals-buffer)
3532 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3533 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3534 (if (gdb-get-buffer 'gdb-assembler-buffer)
3535 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3536 (setq mode-name (concat "Machine:" gdb-selected-frame))))
3537 (setq gdb-pc-address (match-string 1))
3538 (if (and (match-string 3) gud-overlay-arrow-position)
3539 (let ((buffer (marker-buffer gud-overlay-arrow-position))
3540 (position (marker-position gud-overlay-arrow-position)))
3542 (string-equal (file-name-nondirectory
3543 (buffer-file-name buffer))
3544 (file-name-nondirectory (match-string 3))))
3545 (with-current-buffer buffer
3546 (setq fringe-indicator-alist
3547 (if (string-equal gdb-frame-number "0")
3549 '((overlay-arrow . hollow-right-triangle))))
3550 (set-marker gud-overlay-arrow-position position))))))
3551 (goto-char (point-min))
3552 (if (re-search-forward " source language \\(\\S-+\\)\." nil t)
3553 (setq gdb-current-language (match-string 1)))
3554 (gdb-invalidate-assembler))
3557 ;; Code specific to GDB 6.4
3558 (defconst gdb-source-file-regexp-1 "fullname=\"\\(.*?\\)\"")
3560 (defun gdb-set-gud-minor-mode-existing-buffers-1 ()
3561 "Create list of source files for current GDB session.
3562 If buffers already exist for any of these files, `gud-minor-mode'
3564 (goto-char (point-min))
3565 (while (re-search-forward gdb-source-file-regexp-1 nil t)
3566 (push (match-string 1) gdb-source-file-list))
3567 (dolist (buffer (buffer-list))
3568 (with-current-buffer buffer
3569 (when (member buffer-file-name gdb-source-file-list)
3570 (set (make-local-variable 'gud-minor-mode)
3571 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
3572 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
3573 (when gud-tooltip-mode
3574 (make-local-variable 'gdb-define-alist)
3575 (gdb-create-define-alist)
3576 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
3577 (gdb-force-mode-line-update
3578 (propertize "ready" 'face font-lock-variable-name-face)))
3580 ; Uses "-var-list-children --all-values". Needs GDB 6.4 onwards.
3581 (defun gdb-var-list-children-1 (varnum)
3584 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3585 (concat "server interpreter mi \"-var-list-children --all-values \\\""
3587 (concat "-var-list-children --all-values \"" varnum "\"\n"))
3588 `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
3590 (defconst gdb-var-list-children-regexp-1
3591 "child={.*?name=\"\\(.+?\\)\",.*?exp=\"\\(.+?\\)\",.*?\
3592 numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\)\
3593 \\(}\\|,.*?\\(type=\"\\(.+?\\)\"\\)?.*?}\\)")
3595 (defun gdb-var-list-children-handler-1 (varnum)
3596 (goto-char (point-min))
3597 (let ((var-list nil))
3598 (catch 'child-already-watched
3599 (dolist (var gdb-var-list)
3600 (if (string-equal varnum (car var))
3603 (while (re-search-forward gdb-var-list-children-regexp-1 nil t)
3604 (let ((varchild (list (match-string 1)
3608 (read (match-string 4))
3610 (if (assoc (car varchild) gdb-var-list)
3611 (throw 'child-already-watched nil))
3612 (push varchild var-list))))
3613 (push var var-list)))
3614 (setq gdb-var-list (nreverse var-list))))
3615 (gdb-speedbar-update))
3617 ; Uses "-var-update --all-values". Needs GDB 6.4 onwards.
3618 (defun gdb-var-update-1 ()
3619 (if (not (member 'gdb-var-update gdb-pending-triggers))
3623 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3624 "server interpreter mi \"-var-update --all-values *\"\n"
3625 "-var-update --all-values *\n")
3626 'gdb-var-update-handler-1))
3627 (push 'gdb-var-update gdb-pending-triggers))))
3629 (defconst gdb-var-update-regexp-1
3630 "{.*?name=\"\\(.*?\\)\",.*?\\(?:value=\\(\".*?\"\\),\\)?.*?\
3631 in_scope=\"\\(.*?\\)\".*?}")
3633 (defun gdb-var-update-handler-1 ()
3634 (dolist (var gdb-var-list)
3635 (setcar (nthcdr 5 var) nil))
3636 (goto-char (point-min))
3637 (while (re-search-forward gdb-var-update-regexp-1 nil t)
3638 (let* ((varnum (match-string 1))
3639 (var (assoc varnum gdb-var-list)))
3641 (let ((match (match-string 3)))
3642 (cond ((string-equal match "false")
3643 (if gdb-delete-out-of-scope
3644 (gdb-var-delete-1 varnum)
3645 (setcar (nthcdr 5 var) 'out-of-scope)))
3646 ((string-equal match "true")
3647 (setcar (nthcdr 5 var) 'changed)
3648 (setcar (nthcdr 4 var)
3649 (read (match-string 2))))
3650 ((string-equal match "invalid")
3651 (gdb-var-delete-1 varnum)))))))
3652 (setq gdb-pending-triggers
3653 (delq 'gdb-var-update gdb-pending-triggers))
3654 (gdb-speedbar-update))
3656 ;; Registers buffer.
3658 (gdb-set-buffer-rules 'gdb-registers-buffer
3659 'gdb-registers-buffer-name
3660 'gdb-registers-mode)
3662 (def-gdb-auto-update-trigger gdb-invalidate-registers-1
3663 (gdb-get-buffer 'gdb-registers-buffer)
3664 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3665 "server interpreter mi \"-data-list-register-values x\"\n"
3666 "-data-list-register-values x\n")
3667 gdb-data-list-register-values-handler)
3669 (defconst gdb-data-list-register-values-regexp
3670 "{.*?number=\"\\(.*?\\)\",.*?value=\"\\(.*?\\)\".*?}")
3672 (defun gdb-data-list-register-values-handler ()
3673 (setq gdb-pending-triggers (delq 'gdb-invalidate-registers-1
3674 gdb-pending-triggers))
3675 (goto-char (point-min))
3676 (if (re-search-forward gdb-error-regexp nil t)
3677 (let ((err (match-string 1)))
3678 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3679 (let ((buffer-read-only nil))
3681 (put-text-property 0 (length err) 'face font-lock-warning-face err)
3683 (goto-char (point-min)))))
3684 (let ((register-list (reverse gdb-register-names))
3685 (register nil) (register-string nil) (register-values nil))
3686 (goto-char (point-min))
3687 (while (re-search-forward gdb-data-list-register-values-regexp nil t)
3688 (setq register (pop register-list))
3689 (setq register-string (concat register "\t" (match-string 2) "\n"))
3690 (if (member (match-string 1) gdb-changed-registers)
3691 (put-text-property 0 (length register-string)
3692 'face 'font-lock-warning-face
3694 (setq register-values
3695 (concat register-values register-string)))
3696 (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
3697 (with-current-buffer buf
3698 (let* ((window (get-buffer-window buf 0))
3699 (start (window-start window))
3700 (p (window-point window))
3701 (buffer-read-only nil))
3703 (insert register-values)
3704 (set-window-start window start)
3705 (set-window-point window p))))))
3706 (gdb-data-list-register-values-custom))
3708 (defun gdb-data-list-register-values-custom ()
3709 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3711 (let ((buffer-read-only nil)
3713 (goto-char (point-min))
3714 (while (< (point) (point-max))
3715 (setq start (line-beginning-position))
3716 (setq end (line-end-position))
3717 (when (looking-at "^[^\t]+")
3718 (unless (string-equal (match-string 0) "No registers.")
3719 (put-text-property start (match-end 0)
3720 'face font-lock-variable-name-face)
3721 (add-text-properties start end
3722 '(help-echo "mouse-2: edit value"
3723 mouse-face highlight))))
3724 (forward-line 1))))))
3726 ;; Needs GDB 6.4 onwards (used to fail with no stack).
3727 (defun gdb-get-changed-registers ()
3728 (if (and (gdb-get-buffer 'gdb-registers-buffer)
3729 (not (member 'gdb-get-changed-registers gdb-pending-triggers)))
3733 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3734 "server interpreter mi -data-list-changed-registers\n"
3735 "-data-list-changed-registers\n")
3736 'gdb-get-changed-registers-handler))
3737 (push 'gdb-get-changed-registers gdb-pending-triggers))))
3739 (defconst gdb-data-list-register-names-regexp "\"\\(.*?\\)\"")
3741 (defun gdb-get-changed-registers-handler ()
3742 (setq gdb-pending-triggers
3743 (delq 'gdb-get-changed-registers gdb-pending-triggers))
3744 (setq gdb-changed-registers nil)
3745 (goto-char (point-min))
3746 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3747 (push (match-string 1) gdb-changed-registers)))
3752 ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards.
3753 (gdb-set-buffer-rules 'gdb-locals-buffer
3754 'gdb-locals-buffer-name
3757 (def-gdb-auto-update-trigger gdb-invalidate-locals-1
3758 (gdb-get-buffer 'gdb-locals-buffer)
3759 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3760 "server interpreter mi -\"stack-list-locals --simple-values\"\n"
3761 "-stack-list-locals --simple-values\n")
3762 gdb-stack-list-locals-handler)
3764 (defconst gdb-stack-list-locals-regexp
3765 "{.*?name=\"\\(.*?\\)\",.*?type=\"\\(.*?\\)\"")
3767 (defvar gdb-locals-watch-map-1
3768 (let ((map (make-sparse-keymap)))
3769 (suppress-keymap map)
3770 (define-key map "\r" 'gud-watch)
3771 (define-key map [mouse-2] 'gud-watch)
3773 "Keymap to create watch expression of a complex data type local variable.")
3775 (defvar gdb-edit-locals-map-1
3776 (let ((map (make-sparse-keymap)))
3777 (suppress-keymap map)
3778 (define-key map "\r" 'gdb-edit-locals-value)
3779 (define-key map [mouse-2] 'gdb-edit-locals-value)
3781 "Keymap to edit value of a simple data type local variable.")
3783 (defun gdb-edit-locals-value (&optional event)
3784 "Assign a value to a variable displayed in the locals buffer."
3785 (interactive (list last-input-event))
3787 (if event (posn-set-point (event-end event)))
3789 (let* ((var (current-word))
3790 (value (read-string (format "New value (%s): " var))))
3792 (list (concat gdb-server-prefix"set variable " var " = " value "\n")
3795 ;; Dont display values of arrays or structures.
3796 ;; These can be expanded using gud-watch.
3797 (defun gdb-stack-list-locals-handler ()
3798 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals-1
3799 gdb-pending-triggers))
3800 (goto-char (point-min))
3801 (if (re-search-forward gdb-error-regexp nil t)
3802 (let ((err (match-string 1)))
3803 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3804 (let ((buffer-read-only nil))
3807 (goto-char (point-min)))))
3808 (let (local locals-list)
3809 (goto-char (point-min))
3810 (while (re-search-forward gdb-stack-list-locals-regexp nil t)
3811 (let ((local (list (match-string 1)
3814 (if (looking-at ",value=\\(\".*\"\\).*?}")
3815 (setcar (nthcdr 2 local) (read (match-string 1))))
3816 (push local locals-list)))
3817 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
3818 (and buf (with-current-buffer buf
3819 (let* ((window (get-buffer-window buf 0))
3820 (start (window-start window))
3821 (p (window-point window))
3822 (buffer-read-only nil) (name) (value))
3824 (dolist (local locals-list)
3825 (setq name (car local))
3826 (setq value (nth 2 local))
3828 (string-match "^\\0x" value))
3829 (add-text-properties 0 (length name)
3830 `(mouse-face highlight
3831 help-echo "mouse-2: create watch expression"
3832 local-map ,gdb-locals-watch-map-1)
3834 (add-text-properties 0 (length value)
3835 `(mouse-face highlight
3836 help-echo "mouse-2: edit value"
3837 local-map ,gdb-edit-locals-map-1)
3840 (concat name "\t" (nth 1 local)
3842 (set-window-start window start)
3843 (set-window-point window p))))))))
3845 (defun gdb-get-register-names ()
3846 "Create a list of register names."
3847 (goto-char (point-min))
3848 (setq gdb-register-names nil)
3849 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3850 (push (match-string 1) gdb-register-names)))
3854 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
3855 ;;; gdb-ui.el ends here