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-pc-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
199 '(;; var = (struct struct_tag) value
200 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
201 (1 font-lock-variable-name-face
)
202 (3 font-lock-keyword-face
)
203 (4 font-lock-type-face
))
204 ;; var = (type) value
205 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
206 (1 font-lock-variable-name-face
)
207 (3 font-lock-type-face
))
209 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
210 (1 font-lock-variable-name-face
)))
211 "Font lock keywords used in `gdb-local-mode'.")
213 (defvar gdb-locals-font-lock-keywords-2
214 '(;; var = type value
215 ( "\\(^\\(\\sw\\|[_.]\\)+\\)\t+\\(\\(\\sw\\|[_.]\\)+\\)"
216 (1 font-lock-variable-name-face
)
217 (3 font-lock-type-face
)))
218 "Font lock keywords used in `gdb-local-mode'.")
220 ;; Variables for GDB 6.4+
221 (defvar gdb-register-names nil
"List of register names.")
222 (defvar gdb-changed-registers nil
223 "List of changed register numbers (strings).")
226 (defun gdb (command-line)
227 "Run gdb on program FILE in buffer *gud-FILE*.
228 The directory containing FILE becomes the initial working
229 directory and source-file directory for your debugger.
231 If `gdb-many-windows' is nil (the default value) then gdb just
232 pops up the GUD buffer unless `gdb-show-main' is t. In this case
233 it starts with two windows: one displaying the GUD buffer and the
234 other with the source file with the main routine of the inferior.
236 If `gdb-many-windows' is t, regardless of the value of
237 `gdb-show-main', the layout below will appear unless
238 `gdb-use-separate-io-buffer' is nil when the source buffer
239 occupies the full width of the frame. Keybindings are shown in
242 Watch expressions appear in the speedbar/slowbar.
244 The following commands help control operation :
246 `gdb-many-windows' - Toggle the number of windows gdb uses.
247 `gdb-restore-windows' - To restore the window layout.
249 See Info node `(emacs)GDB Graphical Interface' for a more
250 detailed description of this mode.
252 +----------------------------------------------------------------------+
254 +-----------------------------------+----------------------------------+
255 | GUD buffer (I/O of GDB) | Locals buffer |
256 |-----------------------------------+----------------------------------+
258 | Source buffer | I/O buffer for debugged program |
260 |-----------------------------------+----------------------------------+
261 | Stack buffer | Breakpoints/threads buffer |
262 +-----------------------------------+----------------------------------+
264 To run GDB in text command mode, replace the GDB \"--annotate=3\"
265 option with \"--fullname\" either in the minibuffer for the
266 current Emacs session, or the custom variable
267 `gud-gdb-command-name' for all future sessions. You need to use
268 text command mode to debug multiple programs within one Emacs
270 (interactive (list (gud-query-cmdline 'gdb
)))
272 (when (and gud-comint-buffer
273 (buffer-name gud-comint-buffer
)
274 (get-buffer-process gud-comint-buffer
)
275 (with-current-buffer gud-comint-buffer
(eq gud-minor-mode
'gdba
)))
276 (gdb-restore-windows)
278 "Multiple debugging requires restarting in text command mode"))
280 (gud-common-init command-line nil
'gud-gdba-marker-filter
)
281 (set (make-local-variable 'gud-minor-mode
) 'gdba
)
282 (setq comint-input-sender
'gdb-send
)
284 (gud-def gud-break
"break %f:%l" "\C-b" "Set breakpoint at current line.")
285 (gud-def gud-tbreak
"tbreak %f:%l" "\C-t"
286 "Set temporary breakpoint at current line.")
287 (gud-def gud-remove
"clear %f:%l" "\C-d" "Remove breakpoint at current line.")
288 (gud-def gud-step
"step %p" "\C-s" "Step one source line with display.")
289 (gud-def gud-stepi
"stepi %p" "\C-i" "Step one instruction with display.")
290 (gud-def gud-next
"next %p" "\C-n" "Step one line (skip functions).")
291 (gud-def gud-nexti
"nexti %p" nil
"Step one instruction (skip functions).")
292 (gud-def gud-cont
"cont" "\C-r" "Continue with display.")
293 (gud-def gud-finish
"finish" "\C-f" "Finish executing current function.")
295 (progn (gud-call "tbreak %f:%l") (gud-call "jump %f:%l"))
296 "\C-j" "Set execution address to current line.")
298 (gud-def gud-up
"up %p" "<" "Up N stack frames (numeric arg).")
299 (gud-def gud-down
"down %p" ">" "Down N stack frames (numeric arg).")
300 (gud-def gud-print
"print %e" "\C-p" "Evaluate C expression at point.")
301 (gud-def gud-pstar
"print* %e" nil
302 "Evaluate C dereferenced pointer expression at point.")
304 ;; For debugging Emacs only.
305 (gud-def gud-pv
"pv1 %e" "\C-v" "Print the value of the lisp variable.")
307 (gud-def gud-until
"until %l" "\C-u" "Continue to current line.")
308 (gud-def gud-run
"run" nil
"Run the program.")
310 (local-set-key "\C-i" 'gud-gdb-complete-command
)
311 (setq comint-prompt-regexp
"^(.*gdb[+]?) *")
312 (setq paragraph-start comint-prompt-regexp
)
313 (setq gdb-output-sink
'user
)
314 (setq gdb-first-prompt t
)
315 (setq gud-running nil
)
317 (setq gdb-stack-update nil
)
318 (setq gdb-flush-pending-output nil
)
319 (setq gdb-early-user-input nil
)
320 (setq gud-filter-pending-text nil
)
321 (gdb-thread-identification)
322 (run-hooks 'gdb-mode-hook
))
324 ;; Keep as an alias for compatibility with Emacs 22.1.
326 (defalias 'gdba
'gdb
)
329 "Gdb Graphical Mode options specifically for running Gdb in Emacs."
333 (defcustom gdb-debug-log-max
128
334 "Maximum size of `gdb-debug-log'. If nil, size is unlimited."
336 :type
'(choice (integer :tag
"Number of elements")
337 (const :tag
"Unlimited" nil
))
340 (defvar gdb-debug-log nil
341 "List of commands sent to and replies received from GDB.
342 Most recent commands are listed first. This list stores only the last
343 `gdb-debug-log-max' values. This variable is used to debug GDB-UI.")
346 (defcustom gdb-enable-debug nil
347 "Non-nil means record the process input and output in `gdb-debug-log'."
352 (defcustom gdb-cpp-define-alist-program
"gcc -E -dM -"
353 "Shell command for generating a list of defined macros in a source file.
354 This list is used to display the #define directive associated
355 with an identifier as a tooltip. It works in a debug session with
356 GDB, when `gud-tooltip-mode' is t.
358 Set `gdb-cpp-define-alist-flags' for any include paths or
364 (defcustom gdb-cpp-define-alist-flags
""
365 "Preprocessor flags for `gdb-cpp-define-alist-program'."
370 (defcustom gdb-show-main nil
371 "Non-nil means display source file containing the main routine at startup.
372 Also display the main routine in the disassembly buffer if present."
377 (defcustom gdb-many-windows nil
378 "If nil, just pop up the GUD buffer unless `gdb-show-main' is t.
379 In this case start with two windows: one displaying the GUD
380 buffer and the other with the source file with the main routine
381 of the debugged program. Non-nil means display the layout shown
387 (defcustom gdb-use-separate-io-buffer nil
388 "Non-nil means display output from the debugged program in a separate buffer."
393 (defun gdb-force-mode-line-update (status)
394 (let ((buffer gud-comint-buffer
))
395 (if (and buffer
(buffer-name buffer
))
396 (with-current-buffer buffer
397 (setq mode-line-process
399 (process-status (get-buffer-process buffer
)) status
))
400 ;; Force mode line redisplay soon.
401 (force-mode-line-update)))))
403 (defun gdb-many-windows (arg)
404 "Toggle the number of windows in the basic arrangement.
405 With prefix argument ARG, display additional buffers if ARG is positive,
406 otherwise use a single window."
408 (setq gdb-many-windows
410 (not gdb-many-windows
)
411 (> (prefix-numeric-value arg
) 0)))
412 (message (format "Display of other windows %sabled"
413 (if gdb-many-windows
"en" "dis")))
414 (if (and gud-comint-buffer
415 (buffer-name gud-comint-buffer
))
417 (gdb-restore-windows)
420 (defun gdb-use-separate-io-buffer (arg)
421 "Toggle separate IO for debugged program.
422 With prefix argument ARG, use separate IO if ARG is positive,
425 (setq gdb-use-separate-io-buffer
427 (not gdb-use-separate-io-buffer
)
428 (> (prefix-numeric-value arg
) 0)))
429 (message (format "Separate IO %sabled"
430 (if gdb-use-separate-io-buffer
"en" "dis")))
431 (if (and gud-comint-buffer
432 (buffer-name gud-comint-buffer
))
434 (if gdb-use-separate-io-buffer
435 (if gdb-many-windows
(gdb-restore-windows))
436 (kill-buffer (gdb-inferior-io-name)))
439 (defvar gdb-define-alist nil
"Alist of #define directives for GUD tooltips.")
441 (defun gdb-create-define-alist ()
442 "Create an alist of #define directives for GUD tooltips."
443 (let* ((file (buffer-file-name))
445 (with-output-to-string
446 (with-current-buffer standard-output
447 (and file
(file-exists-p file
)
448 (call-process shell-file-name file
449 (list t nil
) nil
"-c"
450 (concat gdb-cpp-define-alist-program
" "
451 gdb-cpp-define-alist-flags
))))))
452 (define-list (split-string output
"\n" t
)) (name))
453 (setq gdb-define-alist nil
)
454 (dolist (define define-list
)
455 (setq name
(nth 1 (split-string define
"[( ]")))
456 (push (cons name define
) gdb-define-alist
))))
458 (defun gdb-tooltip-print (expr)
460 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer
)
461 (goto-char (point-min))
463 (if (search-forward "=" nil t
)
464 (concat expr
(buffer-substring (- (point) 2) (point-max)))
466 ;; remove newline for gud-tooltip-echo-area
467 (substring string
0 (- (length string
) 1))))
468 (or gud-tooltip-echo-area tooltip-use-echo-area
)))
470 ;; If expr is a macro for a function don't print because of possible dangerous
471 ;; side-effects. Also printing a function within a tooltip generates an
472 ;; unexpected starting annotation (phase error).
473 (defun gdb-tooltip-print-1 (expr)
474 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer
)
475 (goto-char (point-min))
476 (if (search-forward "expands to: " nil t
)
477 (unless (looking-at "\\S-+.*(.*).*")
479 (list (concat gdb-server-prefix
"print " expr
"\n")
480 `(lambda () (gdb-tooltip-print ,expr
))))))))
482 (defconst gdb-source-file-regexp
"\\(.+?\\), \\|\\([^, \n].*$\\)")
484 (defun gdb-init-buffer ()
485 (set (make-local-variable 'gud-minor-mode
)
486 (buffer-local-value 'gud-minor-mode gud-comint-buffer
))
487 (set (make-local-variable 'tool-bar-map
) gud-tool-bar-map
)
488 (when gud-tooltip-mode
489 (make-local-variable 'gdb-define-alist
)
490 (gdb-create-define-alist)
491 (add-hook 'after-save-hook
'gdb-create-define-alist nil t
)))
493 (defun gdb-set-gud-minor-mode-existing-buffers ()
494 "Create list of source files for current GDB session."
495 (goto-char (point-min))
496 (when (search-forward "read in on demand:" nil t
)
497 (while (re-search-forward gdb-source-file-regexp nil t
)
498 (push (file-name-nondirectory (or (match-string 1) (match-string 2)))
499 gdb-source-file-list
))
500 (dolist (buffer (buffer-list))
501 (with-current-buffer buffer
502 (when (and buffer-file-name
503 (member (file-name-nondirectory buffer-file-name
)
504 gdb-source-file-list
))
505 (gdb-init-buffer)))))
506 (gdb-force-mode-line-update
507 (propertize "ready" 'face font-lock-variable-name-face
)))
509 (defun gdb-find-watch-expression ()
510 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list
))
511 (varnum (car var
)) expr array
)
512 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varnum
)
513 (let ((var1 (assoc (match-string 1 varnum
) gdb-var-list
)) var2 varnumlet
514 (component-list (split-string (match-string 2 varnum
) "\\." t
)))
515 (setq expr
(nth 1 var1
))
516 (setq varnumlet
(car var1
))
517 (dolist (component component-list
)
518 (setq var2
(assoc varnumlet gdb-var-list
))
519 (setq expr
(concat expr
520 (if (string-match ".*\\[[0-9]+\\]$" (nth 3 var2
))
521 (concat "[" component
"]")
522 (concat "." component
))))
523 (setq varnumlet
(concat varnumlet
"." component
)))
527 (gud-def gud-break
(if (not (string-match "Machine" mode-name
))
528 (gud-call "break %f:%l" arg
)
532 (gud-call "break *%a" arg
)))
533 "\C-b" "Set breakpoint at current line or address.")
535 (gud-def gud-remove
(if (not (string-match "Machine" mode-name
))
536 (gud-call "clear %f:%l" arg
)
540 (gud-call "clear *%a" arg
)))
541 "\C-d" "Remove breakpoint at current line or address.")
543 (gud-def gud-until
(if (not (string-match "Machine" mode-name
))
544 (gud-call "until %f:%l" arg
)
548 (gud-call "until *%a" arg
)))
549 "\C-u" "Continue to current line or address.")
551 (gud-def gud-go
(gud-call (if gdb-active-process
"continue" "run") arg
)
552 nil
"Start or continue execution.")
554 ;; For debugging Emacs only.
558 "pp1 " (if (eq (buffer-local-value
559 'major-mode
(window-buffer)) 'speedbar-mode
)
560 (gdb-find-watch-expression) "%e")) arg
)
561 nil
"Print the Emacs s-expression.")
563 (define-key gud-minor-mode-map
[left-margin mouse-1
]
564 'gdb-mouse-set-clear-breakpoint
)
565 (define-key gud-minor-mode-map
[left-fringe mouse-1
]
566 'gdb-mouse-set-clear-breakpoint
)
567 (define-key gud-minor-mode-map
[left-margin C-mouse-1
]
568 'gdb-mouse-toggle-breakpoint-margin
)
569 (define-key gud-minor-mode-map
[left-fringe C-mouse-1
]
570 'gdb-mouse-toggle-breakpoint-fringe
)
572 (define-key gud-minor-mode-map
[left-margin drag-mouse-1
]
574 (define-key gud-minor-mode-map
[left-fringe drag-mouse-1
]
576 (define-key gud-minor-mode-map
[left-margin mouse-3
]
578 (define-key gud-minor-mode-map
[left-fringe mouse-3
]
581 (define-key gud-minor-mode-map
[left-margin C-drag-mouse-1
]
583 (define-key gud-minor-mode-map
[left-fringe C-drag-mouse-1
]
585 (define-key gud-minor-mode-map
[left-fringe C-mouse-3
]
587 (define-key gud-minor-mode-map
[left-margin C-mouse-3
]
591 (setq gdb-pc-address
(if gdb-show-main
"main" nil
))
592 (setq gdb-previous-frame-pc-address nil
593 gdb-memory-address
"main"
594 gdb-previous-frame nil
595 gdb-selected-frame nil
596 gdb-current-language nil
600 gdb-first-post-prompt t
604 gdb-pending-triggers nil
605 gdb-output-sink
'user
606 gdb-server-prefix
"server "
607 gdb-location-alist nil
608 gdb-source-file-list nil
611 gdb-buffer-fringe-width
(car (window-fringes))
614 gdb-source-window nil
615 gdb-inferior-status nil
617 gdb-look-up-stack nil
621 gdb-thread-indicator nil
)
623 (setq gdb-buffer-type
'gdba
)
625 (if gdb-use-separate-io-buffer
(gdb-clear-inferior-io))
627 ;; Hack to see test for GDB 6.4+ (-stack-info-frame was implemented in 6.4)
628 (gdb-enqueue-input (list "server interpreter mi -stack-info-frame\n"
632 (if (eq window-system
'w32
)
633 (gdb-enqueue-input (list "set new-console off\n" 'ignore
)))
634 (gdb-enqueue-input (list "set height 0\n" 'ignore
))
635 (gdb-enqueue-input (list "set width 0\n" 'ignore
))
637 (if (string-equal gdb-version
"pre-6.4")
639 (gdb-enqueue-input (list (concat gdb-server-prefix
"info sources\n")
640 'gdb-set-gud-minor-mode-existing-buffers
))
641 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-1
))
643 (list "server interpreter mi -data-list-register-names\n"
644 'gdb-get-register-names
))
645 ; Needs GDB 6.2 onwards.
647 (list "server interpreter mi \"-file-list-exec-source-files\"\n"
648 'gdb-set-gud-minor-mode-existing-buffers-1
))
649 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-2
))
651 ;; Find source file and compilation directory here.
652 ;; Works for C, C++, Fortran and Ada but not Java (GDB 6.4)
653 (gdb-enqueue-input (list "server list\n" 'ignore
))
654 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info
))
656 (run-hooks 'gdb-mode-hook
))
658 (defun gdb-get-version ()
659 (goto-char (point-min))
660 (if (re-search-forward "Undefined\\( mi\\)* command:" nil t
)
661 (setq gdb-version
"pre-6.4")
662 (setq gdb-version
"6.4+"))
665 (defmacro gdb-if-arrow
(arrow-position &rest body
)
667 (let ((buffer (marker-buffer ,arrow-position
)) (line))
668 (if (equal buffer
(window-buffer (posn-window end
)))
669 (with-current-buffer buffer
670 (when (or (equal start end
)
671 (equal (posn-point start
)
672 (marker-position ,arrow-position
)))
675 (defun gdb-mouse-until (event)
676 "Continue running until a source line past the current line.
677 The destination source line can be selected either by clicking
678 with mouse-3 on the fringe/margin or dragging the arrow
679 with mouse-1 (default bindings)."
681 (let ((start (event-start event
))
682 (end (event-end event
)))
683 (gdb-if-arrow gud-overlay-arrow-position
684 (setq line
(line-number-at-pos (posn-point end
)))
685 (gud-call (concat "until " (number-to-string line
))))
686 (gdb-if-arrow gdb-overlay-arrow-position
688 (goto-line (line-number-at-pos (posn-point end
)))
690 (gud-call (concat "until *%a"))))))
692 (defun gdb-mouse-jump (event)
693 "Set execution address/line.
694 The destination source line can be selected either by clicking with C-mouse-3
695 on the fringe/margin or dragging the arrow with C-mouse-1 (default bindings).
696 Unlike `gdb-mouse-until' the destination address can be before the current
697 line, and no execution takes place."
699 (let ((start (event-start event
))
700 (end (event-end event
)))
701 (gdb-if-arrow gud-overlay-arrow-position
702 (setq line
(line-number-at-pos (posn-point end
)))
704 (gud-call (concat "tbreak " (number-to-string line
)))
705 (gud-call (concat "jump " (number-to-string line
)))))
706 (gdb-if-arrow gdb-overlay-arrow-position
708 (goto-line (line-number-at-pos (posn-point end
)))
711 (gud-call (concat "tbreak *%a"))
712 (gud-call (concat "jump *%a")))))))
714 (defcustom gdb-speedbar-auto-raise nil
715 "If non-nil raise speedbar every time display of watch expressions is\
721 (defun gdb-speedbar-auto-raise (arg)
722 "Toggle automatic raising of the speedbar for watch expressions.
723 With prefix argument ARG, automatically raise speedbar if ARG is
724 positive, otherwise don't automatically raise it."
726 (setq gdb-speedbar-auto-raise
728 (not gdb-speedbar-auto-raise
)
729 (> (prefix-numeric-value arg
) 0)))
730 (message (format "Auto raising %sabled"
731 (if gdb-speedbar-auto-raise
"en" "dis"))))
733 (defcustom gdb-use-colon-colon-notation nil
734 "If non-nil use FUN::VAR format to display variables in the speedbar."
739 (define-key gud-minor-mode-map
"\C-c\C-w" 'gud-watch
)
740 (define-key global-map
(concat gud-key-prefix
"\C-w") 'gud-watch
)
742 (defun gud-watch (&optional arg event
)
743 "Watch expression at point.
744 With arg, enter name of variable to be watched in the minibuffer."
745 (interactive (list current-prefix-arg last-input-event
))
746 (let ((minor-mode (buffer-local-value 'gud-minor-mode gud-comint-buffer
)))
747 (if (memq minor-mode
'(gdbmi gdba
))
749 (if event
(posn-set-point (event-end event
)))
751 (save-selected-window
754 (completing-read "Name of variable: "
755 'gud-gdb-complete-command
)
756 (if (and transient-mark-mode mark-active
)
757 (buffer-substring (region-beginning) (region-end))
758 (concat (if (eq major-mode
'gdb-registers-mode
) "$")
759 (tooltip-identifier-from-point (point)))))))
761 (set-text-properties 0 (length expr
) nil expr
)
764 (if (eq minor-mode
'gdba
)
766 "server interpreter mi \"-var-create - * " expr
"\"\n")
767 (concat"-var-create - * " expr
"\n"))
768 `(lambda () (gdb-var-create-handler ,expr
)))))))
769 (message "gud-watch is a no-op in this mode."))))
771 (defconst gdb-var-create-regexp
772 "name=\"\\(.*?\\)\",.*numchild=\"\\(.*?\\)\",\\(?:.*value=\\(\".*\"\\),\\)?.*type=\"\\(.*?\\)\"")
774 (defun gdb-var-create-handler (expr)
775 (goto-char (point-min))
776 (if (re-search-forward gdb-var-create-regexp nil t
)
779 (if (and (string-equal gdb-current-language
"c")
780 gdb-use-colon-colon-notation gdb-selected-frame
)
781 (setq expr
(concat gdb-selected-frame
"::" expr
))
785 (if (match-string 3) (read (match-string 3)))
786 nil gdb-frame-address
)))
787 (push var gdb-var-list
)
788 (unless (string-equal
789 speedbar-initial-expansion-list-name
"GUD")
790 (speedbar-change-initial-expansion-list "GUD"))
794 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer
)
796 (concat "server interpreter mi \"0-var-evaluate-expression "
798 (concat "0-var-evaluate-expression " (car var
) "\n"))
799 `(lambda () (gdb-var-evaluate-expression-handler
801 (if (search-forward "Undefined command" nil t
)
802 (message-box "Watching expressions requires GDB 6.0 onwards")
803 (message-box "No symbol \"%s\" in current context." expr
))))
805 (defun gdb-speedbar-update ()
806 (when (and (boundp 'speedbar-frame
) (frame-live-p speedbar-frame
)
807 (not (member 'gdb-speedbar-timer gdb-pending-triggers
)))
808 ;; Dummy command to update speedbar even when idle.
809 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn
))
810 ;; Keep gdb-pending-triggers non-nil till end.
811 (push 'gdb-speedbar-timer gdb-pending-triggers
)))
813 (defun gdb-speedbar-timer-fn ()
814 (setq gdb-pending-triggers
815 (delq 'gdb-speedbar-timer gdb-pending-triggers
))
818 (defun gdb-var-evaluate-expression-handler (varnum changed
)
819 (goto-char (point-min))
820 (re-search-forward "\\(.+\\)\\^done,value=\\(\".*\"\\)" nil t
)
821 (setq gdb-pending-triggers
822 (delq (string-to-number (match-string 1)) gdb-pending-triggers
))
823 (let ((var (assoc varnum gdb-var-list
)))
825 (if changed
(setcar (nthcdr 5 var
) 'changed
))
826 (setcar (nthcdr 4 var
) (read (match-string 2)))))
827 (gdb-speedbar-update))
829 (defun gdb-var-list-children (varnum)
831 (list (concat "server interpreter mi \"-var-list-children " varnum
"\"\n")
832 `(lambda () (gdb-var-list-children-handler ,varnum
)))))
834 (defconst gdb-var-list-children-regexp
835 "child={.*?name=\"\\(.*?\\)\",.*?exp=\"\\(.*?\\)\",.*?\
836 numchild=\"\\(.*?\\)\"\\(}\\|,.*?\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
838 (defun gdb-var-list-children-handler (varnum)
839 (goto-char (point-min))
840 (let ((var-list nil
))
841 (catch 'child-already-watched
842 (dolist (var gdb-var-list
)
843 (if (string-equal varnum
(car var
))
846 (while (re-search-forward gdb-var-list-children-regexp nil t
)
847 (let ((varchild (list (match-string 1)
852 (if (assoc (car varchild
) gdb-var-list
)
853 (throw 'child-already-watched nil
))
854 (push varchild var-list
)
858 "server interpreter mi \"0-var-evaluate-expression "
859 (car varchild
) "\"\n")
860 `(lambda () (gdb-var-evaluate-expression-handler
861 ,(car varchild
) nil
)))))))
862 (push var var-list
)))
863 (setq gdb-var-list
(nreverse var-list
)))))
865 (defun gdb-var-update ()
866 (when (not (member 'gdb-var-update gdb-pending-triggers
))
868 (list "server interpreter mi \"-var-update *\"\n"
869 'gdb-var-update-handler
))
870 (push 'gdb-var-update gdb-pending-triggers
)))
872 (defconst gdb-var-update-regexp
873 "{.*?name=\"\\(.*?\\)\",.*?in_scope=\"\\(.*?\\)\",.*?\
874 type_changed=\".*?\".*?}")
876 (defun gdb-var-update-handler ()
877 (dolist (var gdb-var-list
)
878 (setcar (nthcdr 5 var
) nil
))
879 (goto-char (point-min))
881 (while (re-search-forward gdb-var-update-regexp nil t
)
882 (let ((varnum (match-string 1)))
883 (if (string-equal (match-string 2) "false")
884 (let ((var (assoc varnum gdb-var-list
)))
885 (if var
(setcar (nthcdr 5 var
) 'out-of-scope
)))
887 (push n gdb-pending-triggers
)
890 (concat "server interpreter mi \"" (number-to-string n
)
891 "-var-evaluate-expression " varnum
"\"\n")
892 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t
))))))))
893 (setq gdb-pending-triggers
894 (delq 'gdb-var-update gdb-pending-triggers
)))
896 (defun gdb-var-set-format (format)
897 "Set the output format for a variable displayed in the speedbar."
898 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list
))
902 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer
) 'gdba
)
903 (concat "server interpreter mi \"-var-set-format "
904 varnum
" " format
"\"\n")
905 (concat "-var-set-format " varnum
" " format
"\n"))
906 `(lambda () (gdb-var-set-format-handler ,varnum
))))))
908 (defconst gdb-var-set-format-regexp
909 "format=\"\\(.*?\\)\",.*value=\"\\(.*?\\)\"")
911 (defun gdb-var-set-format-handler (varnum)
912 (goto-char (point-min))
913 (if (re-search-forward gdb-var-set-format-regexp nil t
)
914 (let ((var (assoc varnum gdb-var-list
)))
915 (setcar (nthcdr 4 var
) (match-string 2))
916 (gdb-var-update-1))))
918 (defun gdb-var-delete-1 (varnum)
921 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer
) 'gdba
)
922 (concat "server interpreter mi \"-var-delete " varnum
"\"\n")
923 (concat "-var-delete " varnum
"\n"))
925 (setq gdb-var-list
(delq var gdb-var-list
))
926 (dolist (varchild gdb-var-list
)
927 (if (string-match (concat (car var
) "\\.") (car varchild
))
928 (setq gdb-var-list
(delq varchild gdb-var-list
)))))
930 (defun gdb-var-delete ()
931 "Delete watch expression at point from the speedbar."
933 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer
)
935 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list
))
937 (if (string-match "\\." (car var
))
938 (message-box "Can only delete a root expression")
939 (gdb-var-delete-1 varnum
)))))
941 (defun gdb-var-delete-children (varnum)
942 "Delete children of variable object at point from the speedbar."
945 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer
) 'gdba
)
946 (concat "server interpreter mi \"-var-delete -c " varnum
"\"\n")
947 (concat "-var-delete -c " varnum
"\n")) 'ignore
)))
949 (defun gdb-edit-value (text token indent
)
950 "Assign a value to a variable displayed in the speedbar."
951 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list
))
952 (varnum (car var
)) (value))
953 (setq value
(read-string "New value: "))
956 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer
) 'gdba
)
957 (concat "server interpreter mi \"-var-assign "
958 varnum
" " value
"\"\n")
959 (concat "-var-assign " varnum
" " value
"\n"))
960 `(lambda () (gdb-edit-value-handler ,value
))))))
962 (defun gdb-edit-value-handler (value)
963 (goto-char (point-min))
964 (if (re-search-forward gdb-error-regexp nil t
)
965 (message-box "Invalid number or expression (%s)" value
)))
967 (defcustom gdb-show-changed-values t
968 "If non-nil change the face of out of scope variables and changed values.
969 Out of scope variables are suppressed with `shadow' face.
970 Changed values are highlighted with the face `font-lock-warning-face'."
975 (defcustom gdb-max-children
40
976 "Maximum number of children before expansion requires confirmation."
981 (defcustom gdb-delete-out-of-scope t
982 "If non-nil delete watch expressions automatically when they go out of scope."
987 (defun gdb-speedbar-expand-node (text token indent
)
988 "Expand the node the user clicked on.
989 TEXT is the text of the button we clicked on, a + or - item.
990 TOKEN is data related to this node.
991 INDENT is the current indentation depth."
992 (if (and gud-comint-buffer
(buffer-name gud-comint-buffer
))
994 (cond ((string-match "+" text
) ;expand this node
995 (let* ((var (assoc token gdb-var-list
))
996 (expr (nth 1 var
)) (children (nth 2 var
)))
997 (if (or (<= (string-to-number children
) gdb-max-children
)
1000 "%s has %s children. Continue? " expr children
)))
1001 (if (and (eq (buffer-local-value
1002 'gud-minor-mode gud-comint-buffer
) 'gdba
)
1003 (string-equal gdb-version
"pre-6.4"))
1004 (gdb-var-list-children token
)
1005 (gdb-var-list-children-1 token
)))))
1006 ((string-match "-" text
) ;contract this node
1007 (dolist (var gdb-var-list
)
1008 (if (string-match (concat token
"\\.") (car var
))
1009 (setq gdb-var-list
(delq var gdb-var-list
))))
1010 (gdb-var-delete-children token
)
1011 (speedbar-change-expand-button-char ?
+)
1012 (speedbar-delete-subblock indent
))
1013 (t (error "Ooops... not sure what to do")))
1014 (speedbar-center-buffer-smartly))
1015 (message-box "GUD session has been killed")))
1017 (defun gdb-get-target-string ()
1018 (with-current-buffer gud-comint-buffer
1025 ;; Each buffer has a TYPE -- a symbol that identifies the function
1026 ;; of that particular buffer.
1028 ;; The usual gdb interaction buffer is given the type `gdba' and
1029 ;; is constructed specially.
1031 ;; Others are constructed by gdb-get-buffer-create and
1032 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
1034 (defvar gdb-buffer-rules-assoc
'())
1036 (defun gdb-get-buffer (key)
1037 "Return the gdb buffer tagged with type KEY.
1038 The key should be one of the cars in `gdb-buffer-rules-assoc'."
1040 (gdb-look-for-tagged-buffer key
(buffer-list))))
1042 (defun gdb-get-buffer-create (key)
1043 "Create a new gdb buffer of the type specified by KEY.
1044 The key should be one of the cars in `gdb-buffer-rules-assoc'."
1045 (or (gdb-get-buffer key
)
1046 (let* ((rules (assoc key gdb-buffer-rules-assoc
))
1047 (name (funcall (gdb-rules-name-maker rules
)))
1048 (new (get-buffer-create name
)))
1049 (with-current-buffer new
1051 (if (cdr (cdr rules
))
1052 (setq trigger
(funcall (car (cdr (cdr rules
))))))
1053 (setq gdb-buffer-type key
)
1054 (set (make-local-variable 'gud-minor-mode
)
1055 (buffer-local-value 'gud-minor-mode gud-comint-buffer
))
1056 (set (make-local-variable 'tool-bar-map
) gud-tool-bar-map
)
1057 (if trigger
(funcall trigger
)))
1060 (defun gdb-rules-name-maker (rules) (car (cdr rules
)))
1062 (defun gdb-look-for-tagged-buffer (key bufs
)
1064 (while (and (not retval
) bufs
)
1065 (set-buffer (car bufs
))
1066 (if (eq gdb-buffer-type key
)
1067 (setq retval
(car bufs
)))
1068 (setq bufs
(cdr bufs
)))
1072 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
1073 ;; at least one and possible more functions. The functions have these
1074 ;; roles in defining a buffer type:
1076 ;; NAME - Return a name for this buffer type.
1078 ;; The remaining function(s) are optional:
1080 ;; MODE - called in a new buffer with no arguments, should establish
1081 ;; the proper mode for the buffer.
1084 (defun gdb-set-buffer-rules (buffer-type &rest rules
)
1085 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc
)))
1087 (setcdr binding rules
)
1088 (push (cons buffer-type rules
)
1089 gdb-buffer-rules-assoc
))))
1091 ;; GUD buffers are an exception to the rules
1092 (gdb-set-buffer-rules 'gdba
'error
)
1094 ;; Partial-output buffer : This accumulates output from a command executed on
1095 ;; behalf of emacs (rather than the user).
1097 (gdb-set-buffer-rules 'gdb-partial-output-buffer
1098 'gdb-partial-output-name
)
1100 (defun gdb-partial-output-name ()
1101 (concat " *partial-output-"
1102 (gdb-get-target-string)
1106 (gdb-set-buffer-rules 'gdb-inferior-io
1107 'gdb-inferior-io-name
1108 'gdb-inferior-io-mode
)
1110 (defun gdb-inferior-io-name ()
1111 (concat "*input/output of "
1112 (gdb-get-target-string)
1115 (defun gdb-display-separate-io-buffer ()
1116 "Display IO of debugged program in a separate window."
1118 (if gdb-use-separate-io-buffer
1120 (gdb-get-buffer-create 'gdb-inferior-io
) t
)))
1122 (defconst gdb-frame-parameters
1123 '((height .
14) (width .
80)
1125 (tool-bar-lines . nil
)
1126 (menu-bar-lines . nil
)
1127 (minibuffer . nil
)))
1129 (defun gdb-frame-separate-io-buffer ()
1130 "Display IO of debugged program in a new frame."
1132 (if gdb-use-separate-io-buffer
1133 (let ((special-display-regexps (append special-display-regexps
'(".*")))
1134 (special-display-frame-alist gdb-frame-parameters
))
1135 (display-buffer (gdb-get-buffer-create 'gdb-inferior-io
)))))
1137 (defvar gdb-inferior-io-mode-map
1138 (let ((map (make-sparse-keymap)))
1139 (define-key map
"\C-c\C-c" 'gdb-separate-io-interrupt
)
1140 (define-key map
"\C-c\C-z" 'gdb-separate-io-stop
)
1141 (define-key map
"\C-c\C-\\" 'gdb-separate-io-quit
)
1142 (define-key map
"\C-c\C-d" 'gdb-separate-io-eof
)
1143 (define-key map
"\C-d" 'gdb-separate-io-eof
)
1146 (define-derived-mode gdb-inferior-io-mode comint-mode
"Inferior I/O"
1147 "Major mode for gdb inferior-io."
1148 :syntax-table nil
:abbrev-table nil
1149 ;; We want to use comint because it has various nifty and familiar
1150 ;; features. We don't need a process, but comint wants one, so create
1152 (make-comint-in-buffer
1153 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
1154 (current-buffer) "hexl")
1155 (setq comint-input-sender
'gdb-inferior-io-sender
))
1157 (defun gdb-inferior-io-sender (proc string
)
1158 ;; PROC is the pseudo-process created to satisfy comint.
1159 (with-current-buffer (process-buffer proc
)
1160 (setq proc
(get-buffer-process gud-comint-buffer
))
1161 (process-send-string proc string
)
1162 (process-send-string proc
"\n")))
1164 (defun gdb-separate-io-interrupt ()
1165 "Interrupt the program being debugged."
1168 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
1170 (defun gdb-separate-io-quit ()
1171 "Send quit signal to the program being debugged."
1174 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
1176 (defun gdb-separate-io-stop ()
1177 "Stop the program being debugged."
1180 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
1182 (defun gdb-separate-io-eof ()
1183 "Send end-of-file to the program being debugged."
1186 (get-buffer-process gud-comint-buffer
)))
1189 ;; gdb communications
1192 ;; INPUT: things sent to gdb
1194 ;; The queues are lists. Each element is either a string (indicating user or
1195 ;; user-like input) or a list of the form:
1197 ;; (INPUT-STRING HANDLER-FN)
1199 ;; The handler function will be called from the partial-output buffer when the
1200 ;; command completes. This is the way to write commands which invoke gdb
1201 ;; commands autonomously.
1203 ;; These lists are consumed tail first.
1206 (defun gdb-send (proc string
)
1207 "A comint send filter for gdb.
1208 This filter may simply queue input for a later time."
1211 (with-current-buffer gud-comint-buffer
1212 (let ((inhibit-read-only t
))
1213 (remove-text-properties (point-min) (point-max) '(face))))
1216 (let ((item (concat string
"\n")))
1217 (if gdb-enable-debug
(push (cons 'send item
) gdb-debug-log
))
1218 (process-send-string proc item
)))
1219 (if (string-match "\\\\\\'" string
)
1220 (setq gdb-continuation
(concat gdb-continuation string
"\n"))
1222 gdb-continuation string
1223 (if (not comint-input-sender-no-newline
) "\n"))))
1224 (gdb-enqueue-input item
)
1225 (setq gdb-continuation nil
)))))
1226 (push (concat string
"\n") gdb-early-user-input
)))
1228 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
1229 ;; is a query, or other non-top-level prompt.
1231 (defun gdb-enqueue-input (item)
1232 (if (not gud-running
)
1235 (gdb-send-item item
)
1236 (setq gdb-prompting nil
))
1237 (push item gdb-input-queue
))))
1239 (defun gdb-dequeue-input ()
1240 (let ((queue gdb-input-queue
))
1242 (let ((last (car (last queue
))))
1243 (unless (nbutlast queue
) (setq gdb-input-queue
'()))
1245 ;; This should be nil here anyway but set it just to make sure.
1246 (setq gdb-pending-triggers nil
))))
1248 (defun gdb-send-item (item)
1249 (setq gdb-flush-pending-output nil
)
1250 (if gdb-enable-debug
(push (cons 'send-item item
) gdb-debug-log
))
1251 (setq gdb-current-item item
)
1252 (let ((process (get-buffer-process gud-comint-buffer
)))
1253 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer
) 'gdba
)
1256 (setq gdb-output-sink
'user
)
1257 (process-send-string process item
))
1259 (gdb-clear-partial-output)
1260 (setq gdb-output-sink
'pre-emacs
)
1261 (process-send-string process
1263 ;; case: eq gud-minor-mode 'gdbmi
1264 (gdb-clear-partial-output)
1265 (setq gdb-output-sink
'emacs
)
1266 (process-send-string process
(car item
)))))
1269 ;; output -- things gdb prints to emacs
1271 ;; GDB output is a stream interrupted by annotations.
1272 ;; Annotations can be recognized by their beginning
1273 ;; with \C-j\C-z\C-z<tag><opt>\C-j
1275 ;; The tag is a string obeying symbol syntax.
1277 ;; The optional part `<opt>' can be either the empty string
1278 ;; or a space followed by more data relating to the annotation.
1279 ;; For example, the SOURCE annotation is followed by a filename,
1280 ;; line number and various useless goo. This data must not include
1284 (defcustom gud-gdb-command-name
"gdb --annotate=3"
1285 "Default command to execute an executable under the GDB debugger.
1286 The option \"--annotate=3\" must be included in this value if you
1287 want the GDB Graphical Interface."
1292 (defvar gdb-annotation-rules
1293 '(("pre-prompt" gdb-pre-prompt
)
1294 ("prompt" gdb-prompt
)
1295 ("commands" gdb-subprompt
)
1296 ("overload-choice" gdb-subprompt
)
1297 ("query" gdb-subprompt
)
1298 ;; Need this prompt for GDB 6.1
1299 ("nquery" gdb-subprompt
)
1300 ("prompt-for-continue" gdb-subprompt
)
1301 ("post-prompt" gdb-post-prompt
)
1302 ("source" gdb-source
)
1303 ("starting" gdb-starting
)
1304 ("exited" gdb-exited
)
1305 ("signalled" gdb-signalled
)
1306 ("signal" gdb-signal
)
1307 ("breakpoint" gdb-stopping
)
1308 ("watchpoint" gdb-stopping
)
1309 ("frame-begin" gdb-frame-begin
)
1310 ("stopped" gdb-stopped
)
1311 ("error-begin" gdb-error
)
1313 ("new-thread" (lambda (ignored) (gdb-get-buffer-create 'gdb-threads-buffer
))))
1314 "An assoc mapping annotation tags to functions which process them.")
1317 (setq gdb-flush-pending-output t
)
1318 (setq gud-running nil
)
1319 (gdb-force-mode-line-update
1320 (propertize "stopped" 'face font-lock-warning-face
))
1321 (setq gdb-output-sink
'user
)
1322 (setq gdb-input-queue nil
)
1323 (setq gdb-pending-triggers nil
)
1324 (setq gdb-prompting t
))
1326 (defconst gdb-source-spec-regexp
1327 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
1329 ;; Do not use this except as an annotation handler.
1330 (defun gdb-source (args)
1331 (string-match gdb-source-spec-regexp args
)
1332 ;; Extract the frame position from the marker.
1333 (setq gud-last-frame
1335 (match-string 1 args
)
1336 (string-to-number (match-string 2 args
))))
1337 (setq gdb-pc-address
(match-string 3 args
))
1338 ;; cover for auto-display output which comes *before*
1339 ;; stopped annotation
1340 (if (eq gdb-output-sink
'inferior
) (setq gdb-output-sink
'user
)))
1342 (defun gdb-pre-prompt (ignored)
1343 "An annotation handler for `pre-prompt'.
1344 This terminates the collection of output from a previous command if that
1345 happens to be in effect."
1346 (setq gdb-error nil
)
1347 (let ((sink gdb-output-sink
))
1351 (setq gdb-output-sink
'post-emacs
))
1354 (error "Phase error in gdb-pre-prompt (got %s)" sink
)))))
1356 (defun gdb-prompt (ignored)
1357 "An annotation handler for `prompt'.
1358 This sends the next command (if any) to gdb."
1359 (when gdb-first-prompt
1360 (gdb-force-mode-line-update
1361 (propertize "initializing..." 'face font-lock-variable-name-face
))
1363 (setq gdb-first-prompt nil
))
1364 (let ((sink gdb-output-sink
))
1367 ((eq sink
'post-emacs
)
1368 (setq gdb-output-sink
'user
)
1370 (car (cdr gdb-current-item
))))
1371 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer
)
1372 (funcall handler
))))
1375 (error "Phase error in gdb-prompt (got %s)" sink
))))
1376 (let ((input (gdb-dequeue-input)))
1378 (gdb-send-item input
)
1380 (setq gdb-prompting t
)
1382 (setq gdb-early-user-input
(nreverse gdb-early-user-input
))
1383 (while gdb-early-user-input
1384 (gdb-enqueue-input (car gdb-early-user-input
))
1385 (setq gdb-early-user-input
(cdr gdb-early-user-input
)))))))
1387 (defun gdb-subprompt (ignored)
1388 "An annotation handler for non-top-level prompts."
1389 (setq gdb-prompting t
))
1391 (defun gdb-starting (ignored)
1392 "An annotation handler for `starting'.
1393 This says that I/O for the subprocess is now the program being debugged,
1395 (setq gdb-active-process t
)
1396 (setq gdb-printing t
)
1397 (let ((sink gdb-output-sink
))
1401 (setq gud-running t
)
1402 (setq gdb-stack-update t
)
1403 ;; Temporarily set gud-running to nil to force "info stack" onto queue.
1404 (let ((gud-running nil
))
1405 (gdb-invalidate-frames))
1406 (setq gdb-inferior-status
"running")
1407 (setq gdb-signalled nil
)
1408 (gdb-force-mode-line-update
1409 (propertize gdb-inferior-status
'face font-lock-type-face
))
1410 (gdb-remove-text-properties)
1411 (setq gud-old-arrow gud-overlay-arrow-position
)
1412 (setq gud-overlay-arrow-position nil
)
1413 (setq gdb-overlay-arrow-position nil
)
1414 (setq gdb-stack-position nil
)
1415 (if gdb-use-separate-io-buffer
1416 (setq gdb-output-sink
'inferior
))))
1419 (error "Unexpected `starting' annotation")))))
1421 (defun gdb-signal (ignored)
1422 (setq gdb-inferior-status
"signal")
1423 (gdb-force-mode-line-update
1424 (propertize gdb-inferior-status
'face font-lock-warning-face
))
1425 (gdb-stopping ignored
))
1427 (defun gdb-stopping (ignored)
1428 "An annotation handler for `breakpoint' and other annotations.
1429 They say that I/O for the subprocess is now GDB, not the program
1431 (if gdb-use-separate-io-buffer
1432 (let ((sink gdb-output-sink
))
1434 ((eq sink
'inferior
)
1435 (setq gdb-output-sink
'user
))
1438 (error "Unexpected stopping annotation"))))))
1440 (defun gdb-exited (ignored)
1441 "An annotation handler for `exited' and `signalled'.
1442 They say that I/O for the subprocess is now GDB, not the program
1443 being debugged and that the program is no longer running. This
1444 function is used to change the focus of GUD tooltips to #define
1446 (setq gdb-active-process nil
)
1447 (setq gud-overlay-arrow-position nil
)
1448 (setq gdb-overlay-arrow-position nil
)
1449 (setq gdb-stack-position nil
)
1450 (setq gud-old-arrow nil
)
1451 (setq gdb-inferior-status
"exited")
1452 (gdb-force-mode-line-update
1453 (propertize gdb-inferior-status
'face font-lock-warning-face
))
1454 (gdb-stopping ignored
))
1456 (defun gdb-signalled (ignored)
1457 (setq gdb-signalled t
))
1459 (defun gdb-frame-begin (ignored)
1460 (setq gdb-frame-begin t
)
1461 (setq gdb-printing nil
)
1462 (let ((sink gdb-output-sink
))
1464 ((eq sink
'inferior
)
1465 (setq gdb-output-sink
'user
))
1467 ((eq sink
'emacs
) t
)
1470 (error "Unexpected frame-begin annotation (%S)" sink
)))))
1472 (defcustom gdb-same-frame focus-follows-mouse
1473 "Non-nil means pop up GUD buffer in same frame."
1478 (defcustom gdb-find-source-frame nil
1479 "Non-nil means try to find a source frame further up stack e.g after signal."
1484 (defun gdb-find-source-frame (arg)
1485 "Toggle looking for a source frame further up call stack.
1486 The code associated with current (innermost) frame may not have
1487 been compiled with debug information, e.g., C library routine.
1488 With prefix argument ARG, look for a source frame further up
1489 stack to display in the source buffer if ARG is positive,
1490 otherwise don't look further up."
1492 (setq gdb-find-source-frame
1494 (not gdb-find-source-frame
)
1495 (> (prefix-numeric-value arg
) 0)))
1496 (message (format "Looking for source frame %sabled"
1497 (if gdb-find-source-frame
"en" "dis"))))
1499 (defun gdb-stopped (ignored)
1500 "An annotation handler for `stopped'.
1501 It is just like `gdb-stopping', except that if we already set the output
1502 sink to `user' in `gdb-stopping', that is fine."
1503 (setq gud-running nil
)
1504 (unless (or gud-overlay-arrow-position gud-last-frame
)
1505 (if (and gdb-frame-begin gdb-printing
)
1506 (setq gud-overlay-arrow-position gud-old-arrow
)
1507 ;;Pop up GUD buffer to display current frame when it doesn't have source
1508 ;;information i.e if not compiled with -g as with libc routines generally.
1510 (gdb-display-gdb-buffer)
1511 (gdb-frame-gdb-buffer))
1512 (if gdb-find-source-frame
1513 ;;Try to find source further up stack e.g after signal.
1514 (setq gdb-look-up-stack
1515 (if (gdb-get-buffer 'gdb-stack-buffer
)
1518 (gdb-get-buffer-create 'gdb-stack-buffer
)
1519 (gdb-invalidate-frames)
1521 (unless (member gdb-inferior-status
'("exited" "signal"))
1522 (setq gdb-active-process t
) ;Just for attaching case.
1523 (setq gdb-inferior-status
"stopped")
1524 (gdb-force-mode-line-update
1525 (propertize gdb-inferior-status
'face font-lock-warning-face
)))
1526 (let ((sink gdb-output-sink
))
1528 ((eq sink
'inferior
)
1529 (setq gdb-output-sink
'user
))
1533 (error "Unexpected stopped annotation"))))
1534 (if gdb-signalled
(gdb-exited ignored
)))
1536 (defun gdb-error (ignored)
1537 (setq gdb-error
(not gdb-error
)))
1539 (defun gdb-post-prompt (ignored)
1540 "An annotation handler for `post-prompt'.
1541 This begins the collection of output from the current command if that
1542 happens to be appropriate."
1543 ;; Don't add to queue if there outstanding items or gdb-version is not known
1545 (unless (or gdb-pending-triggers gdb-first-post-prompt
)
1546 (gdb-get-selected-frame)
1547 (gdb-invalidate-frames)
1548 ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
1549 (gdb-get-buffer-create 'gdb-breakpoints-buffer
)
1550 (gdb-invalidate-breakpoints)
1551 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1552 ;; so gdb-pc-address is updated.
1553 ;; (gdb-invalidate-assembler)
1555 (if (string-equal gdb-version
"pre-6.4")
1556 (gdb-invalidate-registers)
1557 (gdb-get-changed-registers)
1558 (gdb-invalidate-registers-1))
1560 (gdb-invalidate-memory)
1561 (if (string-equal gdb-version
"pre-6.4")
1562 (gdb-invalidate-locals)
1563 (gdb-invalidate-locals-1))
1565 (gdb-invalidate-threads)
1566 (unless (eq system-type
'darwin
) ;Breaks on Darwin's GDB-5.3.
1567 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1568 ;; Only needed/used with speedbar/watch expressions.
1569 (when (and (boundp 'speedbar-frame
) (frame-live-p speedbar-frame
))
1570 (if (string-equal gdb-version
"pre-6.4")
1572 (gdb-var-update-1)))))
1573 (setq gdb-first-post-prompt nil
)
1574 (let ((sink gdb-output-sink
))
1577 ((eq sink
'pre-emacs
)
1578 (setq gdb-output-sink
'emacs
))
1581 (error "Phase error in gdb-post-prompt (got %s)" sink
)))))
1583 (defconst gdb-buffer-list
1584 '(gdb-stack-buffer gdb-locals-buffer gdb-registers-buffer gdb-threads-buffer
))
1586 (defun gdb-remove-text-properties ()
1587 (dolist (buffertype gdb-buffer-list
)
1588 (let ((buffer (gdb-get-buffer buffertype
)))
1590 (with-current-buffer buffer
1591 (let ((inhibit-read-only t
))
1592 (remove-text-properties
1593 (point-min) (point-max) '(mouse-face nil help-echo nil
))))))))
1595 ;; GUD displays the selected GDB frame. This might might not be the current
1596 ;; GDB frame (after up, down etc). If no GDB frame is visible but the last
1597 ;; visited breakpoint is, use that window.
1598 (defun gdb-display-source-buffer (buffer)
1599 (let* ((last-window (if gud-last-last-frame
1601 (gud-find-file (car gud-last-last-frame
)))))
1602 (source-window (or last-window
1603 (if (and gdb-source-window
1604 (window-live-p gdb-source-window
))
1605 gdb-source-window
))))
1607 (setq gdb-source-window source-window
)
1608 (set-window-buffer source-window buffer
))
1611 ;; Derived from gud-gdb-marker-regexp
1612 (defvar gdb-fullname-regexp
1613 (concat "\\(.:?[^" ":" "\n]*\\)" ":" "\\([0-9]*\\)" ":" ".*"))
1615 (defun gud-gdba-marker-filter (string)
1616 "A gud marker filter for gdb. Handle a burst of output from GDB."
1617 (if gdb-flush-pending-output
1619 (when gdb-enable-debug
1620 (push (cons 'recv string
) gdb-debug-log
)
1621 (if (and gdb-debug-log-max
1622 (> (length gdb-debug-log
) gdb-debug-log-max
))
1623 (setcdr (nthcdr (1- gdb-debug-log-max
) gdb-debug-log
) nil
)))
1624 ;; Recall the left over gud-marker-acc from last time.
1625 (setq gud-marker-acc
(concat gud-marker-acc string
))
1626 ;; Start accumulating output for the GUD buffer.
1629 ;; Process all the complete markers in this chunk.
1630 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc
)
1631 (let ((annotation (match-string 1 gud-marker-acc
))
1632 (before (substring gud-marker-acc
0 (match-beginning 0)))
1633 (after (substring gud-marker-acc
(match-end 0))))
1635 ;; Parse the tag from the annotation, and maybe its arguments.
1636 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation
)
1637 (let* ((annotation-type (match-string 1 annotation
))
1638 (annotation-arguments (match-string 2 annotation
))
1639 (annotation-rule (assoc annotation-type
1640 gdb-annotation-rules
))
1641 (fullname (string-match gdb-fullname-regexp annotation-type
)))
1643 ;; Stuff prior to the match is just ordinary output.
1644 ;; It is either concatenated to OUTPUT or directed
1647 (gdb-concat-output output
1648 (concat before
(if fullname
"\n"))))
1650 ;; Take that stuff off the gud-marker-acc.
1651 (setq gud-marker-acc after
)
1653 ;; Call the handler for this annotation.
1655 (funcall (car (cdr annotation-rule
))
1656 annotation-arguments
)
1658 ;; Switch to gud-gdb-marker-filter if appropriate.
1661 ;; Extract the frame position from the marker.
1662 (setq gud-last-frame
(cons (match-string 1 annotation
)
1664 (match-string 2 annotation
))))
1666 (set (make-local-variable 'gud-minor-mode
) 'gdb
)
1667 (set (make-local-variable 'gud-marker-filter
)
1668 'gud-gdb-marker-filter
)))
1670 ;; Else the annotation is not recognized. Ignore it silently,
1671 ;; so that GDB can add new annotations without causing
1675 ;; Does the remaining text end in a partial line?
1676 ;; If it does, then keep part of the gud-marker-acc until we get more.
1677 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1680 ;; Everything before the potential marker start can be output.
1682 (gdb-concat-output output
1683 (substring gud-marker-acc
0
1684 (match-beginning 0))))
1686 ;; Everything after, we save, to combine with later input.
1687 (setq gud-marker-acc
(substring gud-marker-acc
1688 (match-beginning 0))))
1690 ;; In case we know the gud-marker-acc contains no partial annotations:
1692 (setq output
(gdb-concat-output output gud-marker-acc
))
1693 (setq gud-marker-acc
"")))
1696 (defun gdb-concat-output (so-far new
)
1698 (put-text-property 0 (length new
) 'face font-lock-warning-face new
))
1699 (let ((sink gdb-output-sink
))
1701 ((eq sink
'user
) (concat so-far new
))
1702 ((or (eq sink
'pre-emacs
) (eq sink
'post-emacs
)) so-far
)
1704 (gdb-append-to-partial-output new
)
1706 ((eq sink
'inferior
)
1707 (gdb-append-to-inferior-io new
)
1711 (error "Bogon output sink %S" sink
)))))
1713 (defun gdb-append-to-partial-output (string)
1714 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer
)
1715 (goto-char (point-max))
1718 (defun gdb-clear-partial-output ()
1719 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer
)
1722 (defun gdb-append-to-inferior-io (string)
1723 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io
)
1724 (goto-char (point-max))
1725 (insert-before-markers string
))
1726 (if (not (string-equal string
""))
1727 (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io
) t
)))
1729 (defun gdb-clear-inferior-io ()
1730 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io
)
1734 ;; One trick is to have a command who's output is always available in a buffer
1735 ;; of it's own, and is always up to date. We build several buffers of this
1738 ;; There are two aspects to this: gdb has to tell us when the output for that
1739 ;; command might have changed, and we have to be able to run the command
1740 ;; behind the user's back.
1742 ;; The output phasing associated with the variable gdb-output-sink
1743 ;; help us to run commands behind the user's back.
1745 ;; Below is the code for specificly managing buffers of output from one
1749 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1750 ;; It adds an input for the command we are tracking. It should be the
1751 ;; annotation rule binding of whatever gdb sends to tell us this command
1752 ;; might have changed it's output.
1754 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1755 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1756 ;; input in the input queue (see comment about ``gdb communications'' above).
1758 (defmacro def-gdb-auto-update-trigger
(name demand-predicate gdb-command
1760 `(defun ,name
(&optional ignored
)
1761 (if (and ,demand-predicate
1763 gdb-pending-triggers
)))
1766 (list ,gdb-command
',output-handler
))
1767 (push ',name gdb-pending-triggers
)))))
1769 (defmacro def-gdb-auto-update-handler
(name trigger buf-key custom-defun
)
1771 (setq gdb-pending-triggers
1773 gdb-pending-triggers
))
1774 (let ((buf (gdb-get-buffer ',buf-key
)))
1776 (with-current-buffer buf
1777 (let* ((window (get-buffer-window buf
0))
1778 (start (window-start window
))
1779 (p (window-point window
))
1780 (buffer-read-only nil
))
1782 (insert-buffer-substring (gdb-get-buffer-create
1783 'gdb-partial-output-buffer
))
1784 (set-window-start window start
)
1785 (set-window-point window p
)))))
1786 ;; put customisation here
1789 (defmacro def-gdb-auto-updated-buffer
(buffer-key
1790 trigger-name gdb-command
1791 output-handler-name custom-defun
)
1793 (def-gdb-auto-update-trigger ,trigger-name
1794 ;; The demand predicate:
1795 (gdb-get-buffer ',buffer-key
)
1797 ,output-handler-name
)
1798 (def-gdb-auto-update-handler ,output-handler-name
1799 ,trigger-name
,buffer-key
,custom-defun
)))
1803 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1805 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1806 'gdb-breakpoints-buffer-name
1807 'gdb-breakpoints-mode
)
1809 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1810 ;; This defines the auto update rule for buffers of type
1811 ;; `gdb-breakpoints-buffer'.
1813 ;; It defines a function to serve as the annotation handler that
1814 ;; handles the `foo-invalidated' message. That function is called:
1815 gdb-invalidate-breakpoints
1817 ;; To update the buffer, this command is sent to gdb.
1818 "server info breakpoints\n"
1820 ;; This also defines a function to be the handler for the output
1821 ;; from the command above. That function will copy the output into
1822 ;; the appropriately typed buffer. That function will be called:
1823 gdb-info-breakpoints-handler
1824 ;; buffer specific functions
1825 gdb-info-breakpoints-custom
)
1827 (defconst breakpoint-xpm-data
1829 static char *magick[] = {
1830 /* columns rows colors chars-per-pixel */
1846 "XPM data used for breakpoint icon.")
1848 (defconst breakpoint-enabled-pbm-data
1851 0 0 0 0 1 1 1 1 0 0 0 0
1852 0 0 0 1 1 1 1 1 1 0 0 0
1853 0 0 1 1 1 1 1 1 1 1 0 0
1854 0 1 1 1 1 1 1 1 1 1 1 0
1855 0 1 1 1 1 1 1 1 1 1 1 0
1856 0 1 1 1 1 1 1 1 1 1 1 0
1857 0 1 1 1 1 1 1 1 1 1 1 0
1858 0 0 1 1 1 1 1 1 1 1 0 0
1859 0 0 0 1 1 1 1 1 1 0 0 0
1860 0 0 0 0 1 1 1 1 0 0 0 0"
1861 "PBM data used for enabled breakpoint icon.")
1863 (defconst breakpoint-disabled-pbm-data
1875 0 0 0 1 0 1 0 1 0 0"
1876 "PBM data used for disabled breakpoint icon.")
1878 (defvar breakpoint-enabled-icon nil
1879 "Icon for enabled breakpoint in display margin.")
1881 (defvar breakpoint-disabled-icon nil
1882 "Icon for disabled breakpoint in display margin.")
1884 (and (display-images-p)
1885 ;; Bitmap for breakpoint in fringe
1886 (define-fringe-bitmap 'breakpoint
1887 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c")
1888 ;; Bitmap for gud-overlay-arrow in fringe
1889 (define-fringe-bitmap 'hollow-right-triangle
1890 "\xe0\x90\x88\x84\x84\x88\x90\xe0"))
1892 (defface breakpoint-enabled
1896 "Face for enabled breakpoint icon in fringe."
1899 (defface breakpoint-disabled
1900 '((((class color
) (min-colors 88)) :foreground
"grey70")
1901 ;; Ensure that on low-color displays that we end up something visible.
1902 (((class color
) (min-colors 8) (background light
))
1903 :foreground
"black")
1904 (((class color
) (min-colors 8) (background dark
))
1905 :foreground
"white")
1906 (((type tty
) (class mono
))
1908 (t :background
"gray"))
1909 "Face for disabled breakpoint icon in fringe."
1912 (defconst gdb-breakpoint-regexp
1913 "\\(?:\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\|\\([0-9]+\\.[0-9]+\\)\\)\\s-+\\(.\\)\\s-+")
1915 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1916 (defun gdb-info-breakpoints-custom ()
1917 (let ((flag) (bptno))
1918 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1919 (dolist (buffer (buffer-list))
1920 (with-current-buffer buffer
1921 (if (and (memq gud-minor-mode
'(gdba gdbmi
))
1922 (not (string-match "\\` ?\\*.+\\*\\'" (buffer-name))))
1923 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1924 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer
)
1926 (let ((buffer-read-only nil
))
1927 (goto-char (point-min))
1928 (while (< (point) (- (point-max) 1))
1930 (if (looking-at gdb-breakpoint-regexp
)
1932 (setq bptno
(or (match-string 1) (match-string 2)))
1933 (setq flag
(char-after (match-beginning 3)))
1934 (if (match-string 1)
1935 (setq gdb-parent-bptno-enabled
(eq flag ?y
)))
1936 (add-text-properties
1937 (match-beginning 3) (match-end 3)
1939 '(face font-lock-warning-face
)
1940 '(face font-lock-type-face
)))
1942 (el (line-end-position)))
1943 (if (re-search-forward " in \\(.*\\) at\\s-+" el t
)
1945 (add-text-properties
1946 (match-beginning 1) (match-end 1)
1947 '(face font-lock-function-name-face
))
1948 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1949 (let ((line (match-string 2))
1950 (file (match-string 1)))
1951 (add-text-properties bl el
1952 '(mouse-face highlight
1953 help-echo
"mouse-2, RET: visit breakpoint"))
1954 (unless (file-exists-p file
)
1955 (setq file
(cdr (assoc bptno gdb-location-alist
))))
1957 (not (string-equal file
"File not found")))
1958 (with-current-buffer
1959 (find-file-noselect file
'nowarn
)
1961 ;; Only want one breakpoint icon at each
1964 (goto-line (string-to-number line
))
1965 (gdb-put-breakpoint-icon (eq flag ?y
) bptno
)))
1968 (concat gdb-server-prefix
"list "
1969 (match-string-no-properties 1) ":1\n")
1972 (list (concat gdb-server-prefix
"info source\n")
1973 `(lambda () (gdb-get-location
1974 ,bptno
,line
,flag
)))))))
1975 (if (re-search-forward
1976 "<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
1978 (add-text-properties
1979 (match-beginning 1) (match-end 1)
1980 '(face font-lock-function-name-face
))
1982 (re-search-backward "\\s-\\(\\S-*\\)"
1984 (add-text-properties
1985 (match-beginning 1) (match-end 1)
1986 '(face font-lock-variable-name-face
)))))))
1988 (if (gdb-get-buffer 'gdb-assembler-buffer
) (gdb-assembler-custom))
1990 ;; Breakpoints buffer is always present. Hack to just update
1991 ;; current frame if there's been no execution.
1992 (if gdb-stack-update
1993 (setq gdb-stack-update nil
)
1994 (if (gdb-get-buffer 'gdb-stack-buffer
) (gdb-info-stack-custom))))
1996 (declare-function gud-remove
"gdb-ui" t t
) ; gud-def
1997 (declare-function gud-break
"gdb-ui" t t
) ; gud-def
1999 (defun gdb-mouse-set-clear-breakpoint (event)
2000 "Set/clear breakpoint in left fringe/margin at mouse click.
2001 If not in a source or disassembly buffer just set point."
2003 (mouse-minibuffer-check event
)
2004 (let ((posn (event-end event
)))
2005 (with-selected-window (posn-window posn
)
2006 (if (or (buffer-file-name) (eq major-mode
'gdb-assembler-mode
))
2007 (if (numberp (posn-point posn
))
2009 (goto-char (posn-point posn
))
2010 (if (or (posn-object posn
)
2011 (eq (car (fringe-bitmaps-at-pos (posn-point posn
)))
2015 (posn-set-point posn
))))
2017 (defun gdb-mouse-toggle-breakpoint-margin (event)
2018 "Enable/disable breakpoint in left margin with mouse click."
2020 (mouse-minibuffer-check event
)
2021 (let ((posn (event-end event
)))
2022 (if (numberp (posn-point posn
))
2023 (with-selected-window (posn-window posn
)
2025 (goto-char (posn-point posn
))
2026 (if (posn-object posn
)
2027 (let* ((bptno (get-text-property
2028 0 'gdb-bptno
(car (posn-string posn
)))))
2029 (string-match "\\([0-9+]\\)*" bptno
)
2032 (concat gdb-server-prefix
2033 (if (get-text-property
2034 0 'gdb-enabled
(car (posn-string posn
)))
2037 (match-string 1 bptno
) "\n")
2040 (defun gdb-mouse-toggle-breakpoint-fringe (event)
2041 "Enable/disable breakpoint in left fringe with mouse click."
2043 (mouse-minibuffer-check event
)
2044 (let* ((posn (event-end event
))
2045 (pos (posn-point posn
))
2048 (with-selected-window (posn-window posn
)
2050 (set-buffer (window-buffer (selected-window)))
2052 (dolist (overlay (overlays-in pos pos
))
2053 (when (overlay-get overlay
'put-break
)
2054 (setq obj
(overlay-get overlay
'before-string
))))
2056 (let* ((bptno (get-text-property 0 'gdb-bptno obj
)))
2057 (string-match "\\([0-9+]\\)*" bptno
)
2060 (concat gdb-server-prefix
2061 (if (get-text-property 0 'gdb-enabled obj
)
2064 (match-string 1 bptno
) "\n")
2067 (defun gdb-breakpoints-buffer-name ()
2068 (with-current-buffer gud-comint-buffer
2069 (concat "*breakpoints of " (gdb-get-target-string) "*")))
2071 (defun gdb-display-breakpoints-buffer ()
2072 "Display status of user-settable breakpoints."
2075 (gdb-get-buffer-create 'gdb-breakpoints-buffer
) t
))
2077 (defun gdb-frame-breakpoints-buffer ()
2078 "Display status of user-settable breakpoints in a new frame."
2080 (let ((special-display-regexps (append special-display-regexps
'(".*")))
2081 (special-display-frame-alist gdb-frame-parameters
))
2082 (display-buffer (gdb-get-buffer-create 'gdb-breakpoints-buffer
))))
2084 (defvar gdb-breakpoints-mode-map
2085 (let ((map (make-sparse-keymap))
2086 (menu (make-sparse-keymap "Breakpoints")))
2087 (define-key menu
[quit] '("Quit" . gdb-delete-frame-or-window))
2088 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
2089 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
2090 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
2091 (suppress-keymap map)
2092 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
2093 (define-key map " " 'gdb-toggle-breakpoint)
2094 (define-key map "D" 'gdb-delete-breakpoint)
2095 ;; Don't bind "q" to kill-this-buffer as we need it for breakpoint icons.
2096 (define-key map "q" 'gdb-delete-frame-or-window)
2097 (define-key map "\r" 'gdb-goto-breakpoint)
2098 (define-key map [mouse-2] 'gdb-goto-breakpoint)
2099 (define-key map [follow-link] 'mouse-face)
2102 (defun gdb-delete-frame-or-window ()
2103 "Delete frame if there is only one window. Otherwise delete the window."
2105 (if (one-window-p) (delete-frame)
2108 ;;from make-mode-line-mouse-map
2109 (defun gdb-make-header-line-mouse-map (mouse function) "\
2110 Return a keymap with single entry for mouse key MOUSE on the header line.
2111 MOUSE is defined to run function FUNCTION with no args in the buffer
2112 corresponding to the mode line clicked."
2113 (let ((map (make-sparse-keymap)))
2114 (define-key map (vector 'header-line mouse) function)
2115 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2118 (defvar gdb-breakpoints-header
2119 `(,(propertize "Breakpoints"
2120 'help-echo "mouse-1: select"
2121 'mouse-face 'mode-line-highlight
2124 (gdb-make-header-line-mouse-map
2126 (lambda (event) (interactive "e")
2127 (save-selected-window
2128 (select-window (posn-window (event-start event)))
2129 (set-window-dedicated-p (selected-window) nil)
2131 (gdb-get-buffer-create 'gdb-breakpoints-buffer))
2132 (set-window-dedicated-p (selected-window) t)))))
2134 ,(propertize "Threads"
2135 'help-echo "mouse-1: select"
2136 'mouse-face 'mode-line-highlight
2139 (gdb-make-header-line-mouse-map
2141 (lambda (event) (interactive "e")
2142 (save-selected-window
2143 (select-window (posn-window (event-start event)))
2144 (set-window-dedicated-p (selected-window) nil)
2146 (gdb-get-buffer-create 'gdb-threads-buffer))
2147 (set-window-dedicated-p (selected-window) t)))))))
2149 (defun gdb-breakpoints-mode ()
2150 "Major mode for gdb breakpoints.
2152 \\{gdb-breakpoints-mode-map}"
2153 (kill-all-local-variables)
2154 (setq major-mode 'gdb-breakpoints-mode)
2155 (setq mode-name "Breakpoints")
2156 (use-local-map gdb-breakpoints-mode-map)
2157 (setq buffer-read-only t)
2158 (setq header-line-format gdb-breakpoints-header)
2159 (run-mode-hooks 'gdb-breakpoints-mode-hook)
2160 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2161 'gdb-invalidate-breakpoints
2162 'gdbmi-invalidate-breakpoints))
2164 (defun gdb-toggle-breakpoint ()
2165 "Enable/disable breakpoint at current line."
2168 (beginning-of-line 1)
2169 (if (looking-at gdb-breakpoint-regexp)
2172 (concat gdb-server-prefix
2173 (if (eq ?y (char-after (match-beginning 3)))
2176 (or (match-string 1) (match-string 2)) "\n") 'ignore))
2177 (error "Not recognized as break/watchpoint line"))))
2179 (defun gdb-delete-breakpoint ()
2180 "Delete the breakpoint at current line."
2183 (beginning-of-line 1)
2184 (if (looking-at gdb-breakpoint-regexp)
2185 (if (match-string 1)
2188 (concat gdb-server-prefix "delete " (match-string 1) "\n")
2190 (message-box "This breakpoint cannot be deleted on its own."))
2191 (error "Not recognized as break/watchpoint line"))))
2193 (defun gdb-goto-breakpoint (&optional event)
2194 "Display the breakpoint location specified at current line."
2195 (interactive (list last-input-event))
2196 (if event (posn-set-point (event-end event)))
2198 (beginning-of-line 1)
2199 (if (looking-at "\\([0-9]+\\.?[0-9]*\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
2200 (let ((bptno (match-string 1))
2201 (file (match-string 2))
2202 (line (match-string 3)))
2203 (save-selected-window
2204 (let* ((buffer (find-file-noselect
2205 (if (file-exists-p file) file
2206 (cdr (assoc bptno gdb-location-alist)))))
2207 (window (or (gdb-display-source-buffer buffer)
2208 (display-buffer buffer))))
2209 (setq gdb-source-window window)
2210 (with-current-buffer buffer
2211 (goto-line (string-to-number line))
2212 (set-window-point window (point))))))
2213 (error "No location specified."))))
2216 ;; Frames buffer. This displays a perpetually correct bactracktrace
2217 ;; (from the command `where').
2219 ;; Alas, if your stack is deep, it is costly.
2221 (defcustom gdb-max-frames 40
2222 "Maximum number of frames displayed in call stack."
2227 (gdb-set-buffer-rules 'gdb-stack-buffer
2228 'gdb-stack-buffer-name
2231 (def-gdb-auto-updated-buffer gdb-stack-buffer
2232 gdb-invalidate-frames
2233 (concat "server info stack " (number-to-string gdb-max-frames) "\n")
2234 gdb-info-stack-handler
2235 gdb-info-stack-custom)
2237 ;; This may be more important for embedded targets where unwinding the
2238 ;; stack may take a long time.
2239 (defadvice gdb-invalidate-frames (around gdb-invalidate-frames-advice
2240 (&optional ignored) activate compile)
2241 "Only queue \"info stack\" if execution has occurred."
2242 (if gdb-stack-update ad-do-it))
2244 (defun gdb-info-stack-custom ()
2245 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
2248 (unless (eq gdb-look-up-stack 'delete)
2249 (let ((buffer-read-only nil)
2251 (goto-char (point-min))
2252 (while (< (point) (point-max))
2253 (setq bl (line-beginning-position)
2254 el (line-end-position))
2255 (when (looking-at "#")
2256 (add-text-properties bl el
2257 '(mouse-face highlight
2258 help-echo "mouse-2, RET: Select frame")))
2260 (when (looking-at "^#\\([0-9]+\\)")
2261 (when (string-equal (match-string 1) gdb-frame-number)
2262 (if (> (car (window-fringes)) 0)
2264 (or gdb-stack-position
2265 (setq gdb-stack-position (make-marker)))
2266 (set-marker gdb-stack-position (point))
2267 (setq move-to gdb-stack-position))
2268 (put-text-property bl (+ bl 4)
2269 'face '(:inverse-video t))
2271 (when (re-search-forward "\\([^ ]+\\) (" el t)
2272 (put-text-property (match-beginning 1) (match-end 1)
2273 'face font-lock-function-name-face)
2274 (setq bl (match-end 0))
2275 (while (re-search-forward "<\\([^>]+\\)>" el t)
2276 (put-text-property (match-beginning 1) (match-end 1)
2277 'face font-lock-function-name-face))
2279 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
2280 (put-text-property (match-beginning 1) (match-end 1)
2281 'face font-lock-variable-name-face))))
2284 (when (looking-at "(More stack frames follow...)")
2285 (add-text-properties (match-beginning 0) (match-end 0)
2286 '(mouse-face highlight
2289 "mouse-2, RET: customize gdb-max-frames to see more frames")))))
2290 (when gdb-look-up-stack
2291 (goto-char (point-min))
2292 (when (re-search-forward "\\(\\S-+?\\):\\([0-9]+\\)" nil t)
2293 (let ((start (line-beginning-position))
2294 (file (match-string 1))
2295 (line (match-string 2)))
2296 (re-search-backward "^#*\\([0-9]+\\)" start t)
2298 (list (concat gdb-server-prefix "frame "
2299 (match-string 1) "\n") 'gdb-set-hollow))
2301 (list (concat gdb-server-prefix "frame 0\n") 'ignore))))))
2303 (let ((window (get-buffer-window (current-buffer) 0)))
2305 (with-selected-window window
2307 (unless (pos-visible-in-window-p)
2308 (recenter '(center)))))))))
2309 (if (eq gdb-look-up-stack 'delete)
2310 (kill-buffer (gdb-get-buffer 'gdb-stack-buffer)))
2311 (setq gdb-look-up-stack nil))
2313 (defun gdb-set-hollow ()
2314 (if gud-last-last-frame
2315 (with-current-buffer (gud-find-file (car gud-last-last-frame))
2316 (setq fringe-indicator-alist
2317 '((overlay-arrow . hollow-right-triangle))))))
2319 (defun gdb-stack-buffer-name ()
2320 (with-current-buffer gud-comint-buffer
2321 (concat "*stack frames of " (gdb-get-target-string) "*")))
2323 (defun gdb-display-stack-buffer ()
2324 "Display backtrace of current stack."
2327 (gdb-get-buffer-create 'gdb-stack-buffer) t))
2329 (defun gdb-frame-stack-buffer ()
2330 "Display backtrace of current stack in a new frame."
2332 (let ((special-display-regexps (append special-display-regexps '(".*")))
2333 (special-display-frame-alist gdb-frame-parameters))
2334 (display-buffer (gdb-get-buffer-create 'gdb-stack-buffer))))
2336 (defvar gdb-frames-mode-map
2337 (let ((map (make-sparse-keymap)))
2338 (suppress-keymap map)
2339 (define-key map "q" 'kill-this-buffer)
2340 (define-key map "\r" 'gdb-frames-select)
2341 (define-key map "F" 'gdb-frames-force-update)
2342 (define-key map [mouse-2] 'gdb-frames-select)
2343 (define-key map [follow-link] 'mouse-face)
2346 (declare-function gdbmi-invalidate-frames "ext:gdb-mi" nil t)
2348 (defun gdb-frames-force-update ()
2349 "Force update of call stack.
2350 Use when the displayed call stack gets out of sync with the
2351 actual one, e.g after using the Gdb command \"return\" or setting
2352 $pc directly from the GUD buffer. This command isn't normally needed."
2354 (setq gdb-stack-update t)
2355 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2356 (gdb-invalidate-frames)
2357 (gdbmi-invalidate-frames)))
2359 (defun gdb-frames-mode ()
2360 "Major mode for gdb call stack.
2362 \\{gdb-frames-mode-map}"
2363 (kill-all-local-variables)
2364 (setq major-mode 'gdb-frames-mode)
2365 (setq mode-name "Frames")
2366 (setq gdb-stack-position nil)
2367 (add-to-list 'overlay-arrow-variable-list 'gdb-stack-position)
2368 (setq truncate-lines t) ;; Make it easier to see overlay arrow.
2369 (setq buffer-read-only t)
2370 (gdb-thread-identification)
2371 (use-local-map gdb-frames-mode-map)
2372 (run-mode-hooks 'gdb-frames-mode-hook)
2373 (setq gdb-stack-update t)
2374 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2375 'gdb-invalidate-frames
2376 'gdbmi-invalidate-frames))
2378 (defun gdb-get-frame-number ()
2381 (let* ((start (line-beginning-position))
2382 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
2383 (n (or (and pos (match-string 1)) "0")))
2386 (defun gdb-frames-select (&optional event)
2387 "Select the frame and display the relevant source."
2388 (interactive (list last-input-event))
2389 (if event (posn-set-point (event-end event)))
2390 (if (get-text-property (point) 'gdb-max-frames)
2392 (message-box "After setting gdb-max-frames, you need to enter\n\
2393 another GDB command e.g pwd, to see new frames")
2394 (customize-variable-other-window 'gdb-max-frames))
2396 (list (concat gdb-server-prefix "frame "
2397 (gdb-get-frame-number) "\n") 'ignore))))
2400 ;; Threads buffer. This displays a selectable thread list.
2402 (gdb-set-buffer-rules 'gdb-threads-buffer
2403 'gdb-threads-buffer-name
2406 (def-gdb-auto-updated-buffer gdb-threads-buffer
2407 gdb-invalidate-threads
2408 (concat gdb-server-prefix "info threads\n")
2409 gdb-info-threads-handler
2410 gdb-info-threads-custom)
2412 (defun gdb-info-threads-custom ()
2413 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
2414 (let ((buffer-read-only nil))
2416 (goto-char (point-min))
2417 (if (re-search-forward "\\* \\([0-9]+\\)" nil t)
2418 (setq gdb-thread-indicator
2419 (propertize (concat " [" (match-string 1) "]")
2420 ; FIXME: this help-echo doesn't work
2421 'help-echo "thread id")))
2422 (goto-char (point-min))
2423 (while (< (point) (point-max))
2424 (unless (looking-at "No ")
2425 (add-text-properties (line-beginning-position) (line-end-position)
2426 '(mouse-face highlight
2427 help-echo "mouse-2, RET: select thread")))
2428 (forward-line 1))))))
2430 (defun gdb-threads-buffer-name ()
2431 (with-current-buffer gud-comint-buffer
2432 (concat "*threads of " (gdb-get-target-string) "*")))
2434 (defun gdb-display-threads-buffer ()
2435 "Display IDs of currently known threads."
2438 (gdb-get-buffer-create 'gdb-threads-buffer) t))
2440 (defun gdb-frame-threads-buffer ()
2441 "Display IDs of currently known threads in a new frame."
2443 (let ((special-display-regexps (append special-display-regexps '(".*")))
2444 (special-display-frame-alist gdb-frame-parameters))
2445 (display-buffer (gdb-get-buffer-create 'gdb-threads-buffer))))
2447 (defvar gdb-threads-mode-map
2448 (let ((map (make-sparse-keymap)))
2449 (suppress-keymap map)
2450 (define-key map "q" 'kill-this-buffer)
2451 (define-key map "\r" 'gdb-threads-select)
2452 (define-key map [mouse-2] 'gdb-threads-select)
2453 (define-key map [follow-link] 'mouse-face)
2456 (defvar gdb-threads-font-lock-keywords
2457 '((") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
2458 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
2459 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face)))
2460 "Font lock keywords used in `gdb-threads-mode'.")
2462 (defun gdb-threads-mode ()
2463 "Major mode for gdb threads.
2465 \\{gdb-threads-mode-map}"
2466 (kill-all-local-variables)
2467 (setq major-mode 'gdb-threads-mode)
2468 (setq mode-name "Threads")
2469 (setq buffer-read-only t)
2470 (setq header-line-format gdb-breakpoints-header)
2471 (use-local-map gdb-threads-mode-map)
2472 (set (make-local-variable 'font-lock-defaults)
2473 '(gdb-threads-font-lock-keywords))
2474 (run-mode-hooks 'gdb-threads-mode-hook)
2475 ;; Force "info threads" onto queue.
2476 (lambda () (let ((gud-running nil)) (gdb-invalidate-threads))))
2478 (defun gdb-get-thread-number ()
2480 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
2481 (match-string-no-properties 1)))
2483 (defun gdb-threads-select (&optional event)
2484 "Select the thread and display the relevant source."
2485 (interactive (list last-input-event))
2486 (if event (posn-set-point (event-end event)))
2488 (list (concat gdb-server-prefix "thread "
2489 (gdb-get-thread-number) "\n") 'ignore))
2490 (gud-display-frame))
2492 (defun gdb-thread-identification ()
2493 (setq mode-line-buffer-identification
2494 (list (car mode-line-buffer-identification)
2495 '(gdb-thread-indicator gdb-thread-indicator))))
2497 ;; Registers buffer.
2499 (defcustom gdb-all-registers nil
2500 "Non-nil means include floating-point registers."
2505 (gdb-set-buffer-rules 'gdb-registers-buffer
2506 'gdb-registers-buffer-name
2507 'gdb-registers-mode)
2509 (def-gdb-auto-updated-buffer gdb-registers-buffer
2510 gdb-invalidate-registers
2512 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
2513 gdb-info-registers-handler
2514 gdb-info-registers-custom)
2516 (defun gdb-info-registers-custom ()
2517 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2519 (let ((buffer-read-only nil)
2521 (goto-char (point-min))
2522 (while (< (point) (point-max))
2523 (setq start (line-beginning-position))
2524 (setq end (line-end-position))
2525 (when (looking-at "^[^ ]+")
2526 (unless (string-equal (match-string 0) "The")
2527 (put-text-property start (match-end 0)
2528 'face font-lock-variable-name-face)
2529 (add-text-properties start end
2530 '(help-echo "mouse-2: edit value"
2531 mouse-face highlight))))
2532 (forward-line 1))))))
2534 (defun gdb-edit-register-value (&optional event)
2535 (interactive (list last-input-event))
2537 (if event (posn-set-point (event-end event)))
2539 (let* ((register (current-word))
2540 (value (read-string (format "New value (%s): " register))))
2542 (list (concat gdb-server-prefix "set $" register "=" value "\n")
2545 (defvar gdb-registers-mode-map
2546 (let ((map (make-sparse-keymap)))
2547 (suppress-keymap map)
2548 (define-key map "\r" 'gdb-edit-register-value)
2549 (define-key map [mouse-2] 'gdb-edit-register-value)
2550 (define-key map " " 'gdb-all-registers)
2551 (define-key map "q" 'kill-this-buffer)
2554 (defvar gdb-locals-header
2555 `(,(propertize "Locals"
2556 'help-echo "mouse-1: select"
2557 'mouse-face 'mode-line-highlight
2560 (gdb-make-header-line-mouse-map
2562 (lambda (event) (interactive "e")
2563 (save-selected-window
2564 (select-window (posn-window (event-start event)))
2565 (set-window-dedicated-p (selected-window) nil)
2567 (gdb-get-buffer-create 'gdb-locals-buffer))
2568 (set-window-dedicated-p (selected-window) t)))))
2570 ,(propertize "Registers"
2571 'help-echo "mouse-1: select"
2572 'mouse-face 'mode-line-highlight
2575 (gdb-make-header-line-mouse-map
2577 (lambda (event) (interactive "e")
2578 (save-selected-window
2579 (select-window (posn-window (event-start event)))
2580 (set-window-dedicated-p (selected-window) nil)
2582 (gdb-get-buffer-create 'gdb-registers-buffer))
2583 (set-window-dedicated-p (selected-window) t)))))))
2585 (defun gdb-registers-mode ()
2586 "Major mode for gdb registers.
2588 \\{gdb-registers-mode-map}"
2589 (kill-all-local-variables)
2590 (setq major-mode 'gdb-registers-mode)
2591 (setq mode-name "Registers")
2592 (setq header-line-format gdb-locals-header)
2593 (setq buffer-read-only t)
2594 (gdb-thread-identification)
2595 (use-local-map gdb-registers-mode-map)
2596 (run-mode-hooks 'gdb-registers-mode-hook)
2597 (if (string-equal gdb-version "pre-6.4")
2599 (if gdb-all-registers (setq mode-name "Registers:All"))
2600 'gdb-invalidate-registers)
2601 'gdb-invalidate-registers-1))
2603 (defun gdb-registers-buffer-name ()
2604 (with-current-buffer gud-comint-buffer
2605 (concat "*registers of " (gdb-get-target-string) "*")))
2607 (defun gdb-display-registers-buffer ()
2608 "Display integer register contents."
2611 (gdb-get-buffer-create 'gdb-registers-buffer) t))
2613 (defun gdb-frame-registers-buffer ()
2614 "Display integer register contents in a new frame."
2616 (let ((special-display-regexps (append special-display-regexps '(".*")))
2617 (special-display-frame-alist gdb-frame-parameters))
2618 (display-buffer (gdb-get-buffer-create 'gdb-registers-buffer))))
2620 (defun gdb-all-registers ()
2621 "Toggle the display of floating-point registers (pre GDB 6.4 only)."
2623 (when (string-equal gdb-version "pre-6.4")
2624 (if gdb-all-registers
2626 (setq gdb-all-registers nil)
2627 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2628 (setq mode-name "Registers")))
2629 (setq gdb-all-registers t)
2630 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2631 (setq mode-name "Registers:All")))
2632 (message (format "Display of floating-point registers %sabled"
2633 (if gdb-all-registers "en" "dis")))
2634 (gdb-invalidate-registers)))
2639 (defcustom gdb-memory-repeat-count 32
2640 "Number of data items in memory window."
2645 (defcustom gdb-memory-format "x"
2646 "Display format of data items in memory window."
2647 :type '(choice (const :tag "Hexadecimal" "x")
2648 (const :tag "Signed decimal" "d")
2649 (const :tag "Unsigned decimal" "u")
2650 (const :tag "Octal" "o")
2651 (const :tag "Binary" "t"))
2655 (defcustom gdb-memory-unit "w"
2656 "Unit size of data items in memory window."
2657 :type '(choice (const :tag "Byte" "b")
2658 (const :tag "Halfword" "h")
2659 (const :tag "Word" "w")
2660 (const :tag "Giant word" "g"))
2664 (gdb-set-buffer-rules 'gdb-memory-buffer
2665 'gdb-memory-buffer-name
2668 (def-gdb-auto-updated-buffer gdb-memory-buffer
2669 gdb-invalidate-memory
2670 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
2671 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
2672 gdb-read-memory-handler
2673 gdb-read-memory-custom)
2675 (defun gdb-read-memory-custom ()
2677 (goto-char (point-min))
2678 (if (looking-at "0x[[:xdigit:]]+")
2679 (setq gdb-memory-address (match-string 0)))))
2681 (defvar gdb-memory-mode-map
2682 (let ((map (make-sparse-keymap)))
2683 (suppress-keymap map)
2684 (define-key map "q" 'kill-this-buffer)
2687 (defun gdb-memory-set-address (event)
2688 "Set the start memory address."
2690 (save-selected-window
2691 (select-window (posn-window (event-start event)))
2692 (let ((arg (read-from-minibuffer "Memory address: ")))
2693 (setq gdb-memory-address arg))
2694 (gdb-invalidate-memory)))
2696 (defun gdb-memory-set-repeat-count (event)
2697 "Set the number of data items in memory window."
2699 (save-selected-window
2700 (select-window (posn-window (event-start event)))
2701 (let* ((arg (read-from-minibuffer "Repeat count: "))
2702 (count (string-to-number arg)))
2704 (error "Positive numbers only")
2705 (customize-set-variable 'gdb-memory-repeat-count count)
2706 (gdb-invalidate-memory)))))
2708 (defun gdb-memory-format-binary ()
2709 "Set the display format to binary."
2711 (customize-set-variable 'gdb-memory-format "t")
2712 (gdb-invalidate-memory))
2714 (defun gdb-memory-format-octal ()
2715 "Set the display format to octal."
2717 (customize-set-variable 'gdb-memory-format "o")
2718 (gdb-invalidate-memory))
2720 (defun gdb-memory-format-unsigned ()
2721 "Set the display format to unsigned decimal."
2723 (customize-set-variable 'gdb-memory-format "u")
2724 (gdb-invalidate-memory))
2726 (defun gdb-memory-format-signed ()
2727 "Set the display format to decimal."
2729 (customize-set-variable 'gdb-memory-format "d")
2730 (gdb-invalidate-memory))
2732 (defun gdb-memory-format-hexadecimal ()
2733 "Set the display format to hexadecimal."
2735 (customize-set-variable 'gdb-memory-format "x")
2736 (gdb-invalidate-memory))
2738 (defvar gdb-memory-format-map
2739 (let ((map (make-sparse-keymap)))
2740 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2742 "Keymap to select format in the header line.")
2744 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2745 "Menu of display formats in the header line.")
2747 (define-key gdb-memory-format-menu [binary]
2748 '(menu-item "Binary" gdb-memory-format-binary
2749 :button (:radio . (equal gdb-memory-format "t"))))
2750 (define-key gdb-memory-format-menu [octal]
2751 '(menu-item "Octal" gdb-memory-format-octal
2752 :button (:radio . (equal gdb-memory-format "o"))))
2753 (define-key gdb-memory-format-menu [unsigned]
2754 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2755 :button (:radio . (equal gdb-memory-format "u"))))
2756 (define-key gdb-memory-format-menu [signed]
2757 '(menu-item "Signed Decimal" gdb-memory-format-signed
2758 :button (:radio . (equal gdb-memory-format "d"))))
2759 (define-key gdb-memory-format-menu [hexadecimal]
2760 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2761 :button (:radio . (equal gdb-memory-format "x"))))
2763 (defun gdb-memory-format-menu (event)
2765 (x-popup-menu event gdb-memory-format-menu))
2767 (defun gdb-memory-format-menu-1 (event)
2769 (save-selected-window
2770 (select-window (posn-window (event-start event)))
2771 (let* ((selection (gdb-memory-format-menu event))
2772 (binding (and selection (lookup-key gdb-memory-format-menu
2773 (vector (car selection))))))
2774 (if binding (call-interactively binding)))))
2776 (defun gdb-memory-unit-giant ()
2777 "Set the unit size to giant words (eight bytes)."
2779 (customize-set-variable 'gdb-memory-unit "g")
2780 (gdb-invalidate-memory))
2782 (defun gdb-memory-unit-word ()
2783 "Set the unit size to words (four bytes)."
2785 (customize-set-variable 'gdb-memory-unit "w")
2786 (gdb-invalidate-memory))
2788 (defun gdb-memory-unit-halfword ()
2789 "Set the unit size to halfwords (two bytes)."
2791 (customize-set-variable 'gdb-memory-unit "h")
2792 (gdb-invalidate-memory))
2794 (defun gdb-memory-unit-byte ()
2795 "Set the unit size to bytes."
2797 (customize-set-variable 'gdb-memory-unit "b")
2798 (gdb-invalidate-memory))
2800 (defvar gdb-memory-unit-map
2801 (let ((map (make-sparse-keymap)))
2802 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2804 "Keymap to select units in the header line.")
2806 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2807 "Menu of units in the header line.")
2809 (define-key gdb-memory-unit-menu [giantwords]
2810 '(menu-item "Giant words" gdb-memory-unit-giant
2811 :button (:radio . (equal gdb-memory-unit "g"))))
2812 (define-key gdb-memory-unit-menu [words]
2813 '(menu-item "Words" gdb-memory-unit-word
2814 :button (:radio . (equal gdb-memory-unit "w"))))
2815 (define-key gdb-memory-unit-menu [halfwords]
2816 '(menu-item "Halfwords" gdb-memory-unit-halfword
2817 :button (:radio . (equal gdb-memory-unit "h"))))
2818 (define-key gdb-memory-unit-menu [bytes]
2819 '(menu-item "Bytes" gdb-memory-unit-byte
2820 :button (:radio . (equal gdb-memory-unit "b"))))
2822 (defun gdb-memory-unit-menu (event)
2824 (x-popup-menu event gdb-memory-unit-menu))
2826 (defun gdb-memory-unit-menu-1 (event)
2828 (save-selected-window
2829 (select-window (posn-window (event-start event)))
2830 (let* ((selection (gdb-memory-unit-menu event))
2831 (binding (and selection (lookup-key gdb-memory-unit-menu
2832 (vector (car selection))))))
2833 (if binding (call-interactively binding)))))
2835 (defvar gdb-memory-font-lock-keywords
2836 '(;; <__function.name+n>
2837 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2839 "Font lock keywords used in `gdb-memory-mode'.")
2841 (defun gdb-memory-mode ()
2842 "Major mode for examining memory.
2844 \\{gdb-memory-mode-map}"
2845 (kill-all-local-variables)
2846 (setq major-mode 'gdb-memory-mode)
2847 (setq mode-name "Memory")
2848 (setq buffer-read-only t)
2849 (use-local-map gdb-memory-mode-map)
2850 (setq header-line-format
2856 'face font-lock-warning-face
2857 'help-echo "mouse-1: decrement address"
2858 'mouse-face 'mode-line-highlight
2860 (gdb-make-header-line-mouse-map
2862 (lambda () (interactive)
2863 (let ((gdb-memory-address
2864 ;; Let GDB do the arithmetic.
2866 gdb-memory-address " - "
2868 (* gdb-memory-repeat-count
2869 (cond ((string= gdb-memory-unit "b") 1)
2870 ((string= gdb-memory-unit "h") 2)
2871 ((string= gdb-memory-unit "w") 4)
2872 ((string= gdb-memory-unit "g") 8)))))))
2873 (gdb-invalidate-memory)))))
2876 'face font-lock-warning-face
2877 'help-echo "mouse-1: increment address"
2878 'mouse-face 'mode-line-highlight
2879 'local-map (gdb-make-header-line-mouse-map
2881 (lambda () (interactive)
2882 (let ((gdb-memory-address nil))
2883 (gdb-invalidate-memory)))))
2885 (propertize gdb-memory-address
2886 'face font-lock-warning-face
2887 'help-echo "mouse-1: set memory address"
2888 'mouse-face 'mode-line-highlight
2889 'local-map (gdb-make-header-line-mouse-map
2891 #'gdb-memory-set-address))
2893 (propertize (number-to-string gdb-memory-repeat-count)
2894 'face font-lock-warning-face
2895 'help-echo "mouse-1: set repeat count"
2896 'mouse-face 'mode-line-highlight
2897 'local-map (gdb-make-header-line-mouse-map
2899 #'gdb-memory-set-repeat-count))
2901 (propertize gdb-memory-format
2902 'face font-lock-warning-face
2903 'help-echo "mouse-3: select display format"
2904 'mouse-face 'mode-line-highlight
2905 'local-map gdb-memory-format-map)
2907 (propertize gdb-memory-unit
2908 'face font-lock-warning-face
2909 'help-echo "mouse-3: select unit size"
2910 'mouse-face 'mode-line-highlight
2911 'local-map gdb-memory-unit-map))))
2912 (set (make-local-variable 'font-lock-defaults)
2913 '(gdb-memory-font-lock-keywords))
2914 (run-mode-hooks 'gdb-memory-mode-hook)
2915 'gdb-invalidate-memory)
2917 (defun gdb-memory-buffer-name ()
2918 (with-current-buffer gud-comint-buffer
2919 (concat "*memory of " (gdb-get-target-string) "*")))
2921 (defun gdb-display-memory-buffer ()
2922 "Display memory contents."
2925 (gdb-get-buffer-create 'gdb-memory-buffer) t))
2927 (defun gdb-frame-memory-buffer ()
2928 "Display memory contents in a new frame."
2930 (let* ((special-display-regexps (append special-display-regexps '(".*")))
2931 (special-display-frame-alist
2932 (cons '(left-fringe . 0)
2933 (cons '(right-fringe . 0)
2934 (cons '(width . 83) gdb-frame-parameters)))))
2935 (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
2940 (gdb-set-buffer-rules 'gdb-locals-buffer
2941 'gdb-locals-buffer-name
2944 (def-gdb-auto-update-trigger gdb-invalidate-locals
2945 (gdb-get-buffer 'gdb-locals-buffer)
2946 "server info locals\n"
2947 gdb-info-locals-handler)
2949 (defvar gdb-locals-watch-map
2950 (let ((map (make-sparse-keymap)))
2951 (suppress-keymap map)
2952 (define-key map "\r" (lambda () (interactive)
2955 (define-key map [mouse-2] (lambda (event) (interactive "e")
2956 (mouse-set-point event)
2960 "Keymap to create watch expression of a complex data type local variable.")
2962 (defconst gdb-struct-string
2963 (concat (propertize "[struct/union]"
2964 'mouse-face 'highlight
2965 'help-echo "mouse-2: create watch expression"
2966 'local-map gdb-locals-watch-map) "\n"))
2968 (defconst gdb-array-string
2969 (concat " " (propertize "[array]"
2970 'mouse-face 'highlight
2971 'help-echo "mouse-2: create watch expression"
2972 'local-map gdb-locals-watch-map) "\n"))
2974 ;; Abbreviate for arrays and structures.
2975 ;; These can be expanded using gud-display.
2976 (defun gdb-info-locals-handler ()
2977 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2978 gdb-pending-triggers))
2979 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2980 (with-current-buffer buf
2981 (goto-char (point-min))
2982 (while (re-search-forward "^[ }].*\n" nil t)
2983 (replace-match "" nil nil))
2984 (goto-char (point-min))
2985 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2986 (replace-match gdb-struct-string nil nil))
2987 (goto-char (point-min))
2988 (while (re-search-forward "\\s-*{.*\n" nil t)
2989 (replace-match gdb-array-string nil nil))))
2990 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2992 (with-current-buffer buf
2993 (let* ((window (get-buffer-window buf 0))
2994 (start (window-start window))
2995 (p (window-point window))
2996 (buffer-read-only nil))
2998 (insert-buffer-substring (gdb-get-buffer-create
2999 'gdb-partial-output-buffer))
3000 (set-window-start window start)
3001 (set-window-point window p))
3003 (run-hooks 'gdb-info-locals-hook))
3005 (defvar gdb-locals-mode-map
3006 (let ((map (make-sparse-keymap)))
3007 (suppress-keymap map)
3008 (define-key map "q" 'kill-this-buffer)
3011 (defun gdb-locals-mode ()
3012 "Major mode for gdb locals.
3014 \\{gdb-locals-mode-map}"
3015 (kill-all-local-variables)
3016 (setq major-mode 'gdb-locals-mode)
3017 (setq mode-name (concat "Locals:" gdb-selected-frame))
3018 (use-local-map gdb-locals-mode-map)
3019 (setq buffer-read-only t)
3020 (setq header-line-format gdb-locals-header)
3021 (gdb-thread-identification)
3022 (set (make-local-variable 'font-lock-defaults)
3023 '(gdb-locals-font-lock-keywords))
3024 (run-mode-hooks 'gdb-locals-mode-hook)
3025 (if (and (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3026 (string-equal gdb-version "pre-6.4"))
3027 'gdb-invalidate-locals
3028 'gdb-invalidate-locals-1))
3030 (defun gdb-locals-buffer-name ()
3031 (with-current-buffer gud-comint-buffer
3032 (concat "*locals of " (gdb-get-target-string) "*")))
3034 (defun gdb-display-locals-buffer ()
3035 "Display local variables of current stack and their values."
3038 (gdb-get-buffer-create 'gdb-locals-buffer) t))
3040 (defun gdb-frame-locals-buffer ()
3041 "Display local variables of current stack and their values in a new frame."
3043 (let ((special-display-regexps (append special-display-regexps '(".*")))
3044 (special-display-frame-alist gdb-frame-parameters))
3045 (display-buffer (gdb-get-buffer-create 'gdb-locals-buffer))))
3048 ;;;; Window management
3049 (defun gdb-display-buffer (buf dedicated &optional size)
3050 (let ((answer (get-buffer-window buf 0))
3053 (display-buffer buf nil 0) ;Deiconify the frame if necessary.
3054 ;; The buffer is not yet displayed.
3055 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
3056 (let ((window (get-lru-window)))
3058 (not (memq window `(,(get-buffer-window gud-comint-buffer)
3059 ,gdb-source-window))))
3061 (set-window-buffer window buf)
3062 (setq answer window))
3063 (setq must-split t)))
3065 (let* ((largest (get-largest-window))
3066 (cur-size (window-height largest))
3067 (new-size (and size (< size cur-size) (- cur-size size))))
3068 (setq answer (split-window largest new-size))
3069 (set-window-buffer answer buf)
3070 (set-window-dedicated-p answer dedicated)))
3074 ;;; Shared keymap initialization:
3076 (let ((menu (make-sparse-keymap "GDB-Windows")))
3077 (define-key gud-menu-map [displays]
3078 `(menu-item "GDB-Windows" ,menu
3079 :help "Open a GDB-UI buffer in a new window."
3080 :visible (memq gud-minor-mode '(gdbmi gdba))))
3081 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
3082 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
3083 (define-key menu [inferior]
3084 '(menu-item "Separate IO" gdb-display-separate-io-buffer
3085 :enable gdb-use-separate-io-buffer))
3086 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
3087 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
3088 (define-key menu [disassembly]
3089 '("Disassembly" . gdb-display-assembler-buffer))
3090 (define-key menu [breakpoints]
3091 '("Breakpoints" . gdb-display-breakpoints-buffer))
3092 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
3093 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)))
3095 (let ((menu (make-sparse-keymap "GDB-Frames")))
3096 (define-key gud-menu-map [frames]
3097 `(menu-item "GDB-Frames" ,menu
3098 :help "Open a GDB-UI buffer in a new frame."
3099 :visible (memq gud-minor-mode '(gdbmi gdba))))
3100 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
3101 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
3102 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
3103 (define-key menu [inferior]
3104 '(menu-item "Separate IO" gdb-frame-separate-io-buffer
3105 :enable gdb-use-separate-io-buffer))
3106 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
3107 (define-key menu [disassembly] '("Disassembly" . gdb-frame-assembler-buffer))
3108 (define-key menu [breakpoints]
3109 '("Breakpoints" . gdb-frame-breakpoints-buffer))
3110 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
3111 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)))
3113 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
3114 (define-key gud-menu-map [ui]
3115 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
3116 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
3117 (define-key menu [gdb-customize]
3118 '(menu-item "Customize" (lambda () (interactive) (customize-group 'gdb))
3119 :help "Customize Gdb Graphical Mode options."))
3120 (define-key menu [gdb-find-source-frame]
3121 '(menu-item "Look For Source Frame" gdb-find-source-frame
3122 :visible (eq gud-minor-mode 'gdba)
3123 :help "Toggle looking for source frame further up call stack."
3124 :button (:toggle . gdb-find-source-frame)))
3125 (define-key menu [gdb-use-separate-io]
3126 '(menu-item "Separate IO" gdb-use-separate-io-buffer
3127 :visible (eq gud-minor-mode 'gdba)
3128 :help "Toggle separate IO for debugged program."
3129 :button (:toggle . gdb-use-separate-io-buffer)))
3130 (define-key menu [gdb-many-windows]
3131 '(menu-item "Display Other Windows" gdb-many-windows
3132 :help "Toggle display of locals, stack and breakpoint information"
3133 :button (:toggle . gdb-many-windows)))
3134 (define-key menu [gdb-restore-windows]
3135 '(menu-item "Restore Window Layout" gdb-restore-windows
3136 :help "Restore standard layout for debug session.")))
3138 (defun gdb-frame-gdb-buffer ()
3139 "Display GUD buffer in a new frame."
3141 (let ((special-display-regexps (append special-display-regexps '(".*")))
3142 (special-display-frame-alist
3143 (remove '(menu-bar-lines) (remove '(tool-bar-lines)
3144 gdb-frame-parameters)))
3145 (same-window-regexps nil))
3146 (display-buffer gud-comint-buffer)))
3148 (defun gdb-display-gdb-buffer ()
3149 "Display GUD buffer."
3151 (let ((same-window-regexps nil))
3152 (pop-to-buffer gud-comint-buffer)))
3154 (defun gdb-set-window-buffer (name)
3155 (set-window-buffer (selected-window) (get-buffer name))
3156 (set-window-dedicated-p (selected-window) t))
3158 (defun gdb-setup-windows ()
3159 "Layout the window pattern for `gdb-many-windows'."
3160 (gdb-display-locals-buffer)
3161 (gdb-display-stack-buffer)
3162 (delete-other-windows)
3163 (gdb-display-breakpoints-buffer)
3164 (delete-other-windows)
3166 (pop-to-buffer gud-comint-buffer)
3167 (split-window nil ( / ( * (window-height) 3) 4))
3168 (split-window nil ( / (window-height) 3))
3169 (split-window-horizontally)
3171 (gdb-set-window-buffer (gdb-locals-buffer-name))
3174 (if gud-last-last-frame
3175 (gud-find-file (car gud-last-last-frame))
3177 (gud-find-file gdb-main-file)
3178 ;; Put buffer list in window if we
3179 ;; can't find a source file.
3180 (list-buffers-noselect))))
3181 (setq gdb-source-window (selected-window))
3182 (when gdb-use-separate-io-buffer
3183 (split-window-horizontally)
3185 (gdb-set-window-buffer
3186 (gdb-get-buffer-create 'gdb-inferior-io)))
3188 (gdb-set-window-buffer (gdb-stack-buffer-name))
3189 (split-window-horizontally)
3191 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
3194 (defun gdb-restore-windows ()
3195 "Restore the basic arrangement of windows used by gdba.
3196 This arrangement depends on the value of `gdb-many-windows'."
3198 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
3199 (delete-other-windows)
3200 (if gdb-many-windows
3202 (when (or gud-last-last-frame gdb-show-main)
3206 (if gud-last-last-frame
3207 (gud-find-file (car gud-last-last-frame))
3208 (gud-find-file gdb-main-file)))
3209 (setq gdb-source-window (selected-window))
3213 "Exit a debugging session cleanly.
3214 Kills the gdb buffers, and resets variables and the source buffers."
3215 (dolist (buffer (buffer-list))
3216 (unless (eq buffer gud-comint-buffer)
3217 (with-current-buffer buffer
3218 (if (memq gud-minor-mode '(gdbmi gdba))
3219 (if (string-match "\\` ?\\*.+\\*\\'" (buffer-name))
3221 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
3222 (setq gud-minor-mode nil)
3223 (kill-local-variable 'tool-bar-map)
3224 (kill-local-variable 'gdb-define-alist))))))
3225 (setq gdb-overlay-arrow-position nil)
3226 (setq overlay-arrow-variable-list
3227 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
3228 (setq fringe-indicator-alist '((overlay-arrow . right-triangle)))
3229 (setq gdb-stack-position nil)
3230 (setq overlay-arrow-variable-list
3231 (delq 'gdb-stack-position overlay-arrow-variable-list))
3232 (if (boundp 'speedbar-frame) (speedbar-timer-fn))
3233 (setq gud-running nil)
3234 (setq gdb-active-process nil)
3235 (setq gdb-var-list nil)
3236 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
3238 (defun gdb-source-info ()
3239 "Find the source file where the program starts and displays it with related
3241 (goto-char (point-min))
3242 (if (and (search-forward "Located in " nil t)
3243 (looking-at "\\S-+"))
3244 (setq gdb-main-file (match-string 0)))
3245 (goto-char (point-min))
3246 (if (search-forward "Includes preprocessor macro info." nil t)
3247 (setq gdb-macro-info t))
3248 (if gdb-many-windows
3250 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
3252 (let ((pop-up-windows t))
3253 (display-buffer (gud-find-file gdb-main-file)))))
3256 (defun gdb-get-location (bptno line flag)
3257 "Find the directory containing the relevant source file.
3258 Put in buffer and place breakpoint icon."
3259 (goto-char (point-min))
3260 (catch 'file-not-found
3261 (if (search-forward "Located in " nil t)
3262 (when (looking-at "\\S-+")
3263 (delete (cons bptno "File not found") gdb-location-alist)
3264 (push (cons bptno (match-string 0)) gdb-location-alist))
3266 (unless (assoc bptno gdb-location-alist)
3267 (push (cons bptno "File not found") gdb-location-alist)
3268 (message-box "Cannot find source file for breakpoint location.\n\
3269 Add directory to search path for source files using the GDB command, dir."))
3270 (throw 'file-not-found nil))
3271 (with-current-buffer
3272 (find-file-noselect (match-string 0))
3274 ;; only want one breakpoint icon at each location
3276 (goto-line (string-to-number line))
3277 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
3279 (add-hook 'find-file-hook 'gdb-find-file-hook)
3281 (defun gdb-find-file-hook ()
3282 "Set up buffer for debugging if file is part of the source code
3283 of the current session."
3284 (if (and (buffer-name gud-comint-buffer)
3285 ;; in case gud or gdb-ui is just loaded
3287 (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
3289 ;;Pre GDB 6.3 "info sources" doesn't give absolute file name.
3290 (if (member (if (string-equal gdb-version "pre-6.4")
3291 (file-name-nondirectory buffer-file-name)
3293 gdb-source-file-list)
3294 (with-current-buffer (find-buffer-visiting buffer-file-name)
3295 (gdb-init-buffer)))))
3298 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
3299 "Put string PUTSTRING in front of POS in the current buffer.
3300 PUTSTRING is displayed by putting an overlay into the current buffer with a
3301 `before-string' string that has a `display' property whose value is
3303 (let ((string (make-string 1 ?x))
3304 (buffer (current-buffer)))
3305 (setq putstring (copy-sequence putstring))
3306 (let ((overlay (make-overlay pos pos buffer))
3308 (list (list 'margin 'left-margin) putstring))))
3309 (put-text-property 0 1 'display prop string)
3311 (add-text-properties 0 1 sprops string))
3312 (overlay-put overlay 'put-break t)
3313 (overlay-put overlay 'before-string string))))
3315 ;;from remove-images
3316 (defun gdb-remove-strings (start end &optional buffer)
3317 "Remove strings between START and END in BUFFER.
3318 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
3319 BUFFER nil or omitted means use the current buffer."
3321 (setq buffer (current-buffer)))
3322 (dolist (overlay (overlays-in start end))
3323 (when (overlay-get overlay 'put-break)
3324 (delete-overlay overlay))))
3326 (defun gdb-put-breakpoint-icon (enabled bptno)
3327 (if (string-match "[0-9+]+\\." bptno)
3328 (setq enabled gdb-parent-bptno-enabled))
3329 (let ((start (- (line-beginning-position) 1))
3330 (end (+ (line-end-position) 1))
3331 (putstring (if enabled "B" "b"))
3332 (source-window (get-buffer-window (current-buffer) 0)))
3333 (add-text-properties
3334 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
3337 (add-text-properties
3338 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
3339 (add-text-properties
3340 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
3341 (gdb-remove-breakpoint-icons start end)
3342 (if (display-images-p)
3343 (if (>= (or left-fringe-width
3344 (if source-window (car (window-fringes source-window)))
3345 gdb-buffer-fringe-width) 8)
3348 `(left-fringe breakpoint
3351 'breakpoint-disabled))
3353 'gdb-enabled enabled)
3354 (when (< left-margin-width 2)
3355 (save-current-buffer
3356 (setq left-margin-width 2)
3360 left-margin-width right-margin-width))))
3363 (or breakpoint-enabled-icon
3364 (setq breakpoint-enabled-icon
3365 (find-image `((:type xpm :data
3366 ,breakpoint-xpm-data
3367 :ascent 100 :pointer hand)
3369 ,breakpoint-enabled-pbm-data
3370 :ascent 100 :pointer hand)))))
3371 (or breakpoint-disabled-icon
3372 (setq breakpoint-disabled-icon
3373 (find-image `((:type xpm :data
3374 ,breakpoint-xpm-data
3375 :conversion disabled
3376 :ascent 100 :pointer hand)
3378 ,breakpoint-disabled-pbm-data
3379 :ascent 100 :pointer hand))))))
3383 (when (< left-margin-width 2)
3384 (save-current-buffer
3385 (setq left-margin-width 2)
3386 (let ((window (get-buffer-window (current-buffer) 0)))
3389 window left-margin-width right-margin-width)))))
3391 (propertize putstring
3392 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
3395 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
3396 (gdb-remove-strings start end)
3397 (if (display-images-p)
3398 (remove-images start end))
3400 (setq left-margin-width 0)
3401 (let ((window (get-buffer-window (current-buffer) 0)))
3404 window left-margin-width right-margin-width)))))
3408 ;; Assembler buffer.
3410 (gdb-set-buffer-rules 'gdb-assembler-buffer
3411 'gdb-assembler-buffer-name
3412 'gdb-assembler-mode)
3414 ;; We can't use def-gdb-auto-update-handler because we don't want to use
3415 ;; window-start but keep the overlay arrow/current line visible.
3416 (defun gdb-assembler-handler ()
3417 (setq gdb-pending-triggers
3418 (delq 'gdb-invalidate-assembler
3419 gdb-pending-triggers))
3420 (let ((buf (gdb-get-buffer 'gdb-assembler-buffer)))
3422 (with-current-buffer buf
3423 (let* ((window (get-buffer-window buf 0))
3424 (p (window-point window))
3425 (buffer-read-only nil))
3427 (insert-buffer-substring (gdb-get-buffer-create
3428 'gdb-partial-output-buffer))
3429 (set-window-point window p)))))
3430 ;; put customisation here
3431 (gdb-assembler-custom))
3433 (defun gdb-assembler-custom ()
3434 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
3435 (pos 1) (address) (flag) (bptno))
3436 (with-current-buffer buffer
3438 (if (not (equal gdb-pc-address "main"))
3440 (goto-char (point-min))
3441 (if (and gdb-pc-address
3442 (search-forward gdb-pc-address nil t))
3446 (setq fringe-indicator-alist
3447 (if (string-equal gdb-frame-number "0")
3449 '((overlay-arrow . hollow-right-triangle))))
3450 (or gdb-overlay-arrow-position
3451 (setq gdb-overlay-arrow-position (make-marker)))
3452 (set-marker gdb-overlay-arrow-position (point))))))
3453 ;; remove all breakpoint-icons in assembler buffer before updating.
3454 (gdb-remove-breakpoint-icons (point-min) (point-max))))
3455 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
3456 (goto-char (point-min))
3457 (while (< (point) (- (point-max) 1))
3460 "\\([0-9]+\\.?[0-9]*\\).*?\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
3461 (setq bptno (match-string 1))
3462 (setq flag (char-after (match-beginning 2)))
3463 (setq address (match-string 3))
3464 (with-current-buffer buffer
3466 (goto-char (point-min))
3467 (if (search-forward address nil t)
3468 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))))
3469 (if (not (equal gdb-pc-address "main"))
3470 (with-current-buffer buffer
3471 (set-window-point (get-buffer-window buffer 0) pos)))))
3473 (defvar gdb-assembler-mode-map
3474 (let ((map (make-sparse-keymap)))
3475 (suppress-keymap map)
3476 (define-key map "q" 'kill-this-buffer)
3479 (defvar gdb-assembler-font-lock-keywords
3480 '(;; <__function.name+n>
3481 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
3482 (1 font-lock-function-name-face))
3483 ;; 0xNNNNNNNN <__function.name+n>: opcode
3484 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
3485 (4 font-lock-keyword-face))
3486 ;; %register(at least i386)
3487 ("%\\sw+" . font-lock-variable-name-face)
3488 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
3489 (1 font-lock-comment-face)
3490 (2 font-lock-function-name-face))
3491 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
3492 "Font lock keywords used in `gdb-assembler-mode'.")
3494 (defun gdb-assembler-mode ()
3495 "Major mode for viewing code assembler.
3497 \\{gdb-assembler-mode-map}"
3498 (kill-all-local-variables)
3499 (setq major-mode 'gdb-assembler-mode)
3500 (setq mode-name (concat "Machine:" gdb-selected-frame))
3501 (setq gdb-overlay-arrow-position nil)
3502 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
3503 (setq fringes-outside-margins t)
3504 (setq buffer-read-only t)
3505 (gdb-thread-identification)
3506 (use-local-map gdb-assembler-mode-map)
3507 (gdb-invalidate-assembler)
3508 (set (make-local-variable 'font-lock-defaults)
3509 '(gdb-assembler-font-lock-keywords))
3510 (run-mode-hooks 'gdb-assembler-mode-hook)
3511 'gdb-invalidate-assembler)
3513 (defun gdb-assembler-buffer-name ()
3514 (with-current-buffer gud-comint-buffer
3515 (concat "*disassembly of " (gdb-get-target-string) "*")))
3517 (defun gdb-display-assembler-buffer ()
3518 "Display disassembly view."
3520 (setq gdb-previous-frame nil)
3522 (gdb-get-buffer-create 'gdb-assembler-buffer) t))
3524 (defun gdb-frame-assembler-buffer ()
3525 "Display disassembly view in a new frame."
3527 (setq gdb-previous-frame nil)
3528 (let ((special-display-regexps (append special-display-regexps '(".*")))
3529 (special-display-frame-alist gdb-frame-parameters))
3530 (display-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))))
3532 ;; modified because if gdb-pc-address has changed value a new command
3533 ;; must be enqueued to update the buffer with the new output
3534 (defun gdb-invalidate-assembler (&optional ignored)
3535 (if (gdb-get-buffer 'gdb-assembler-buffer)
3537 (unless (and gdb-selected-frame
3538 (string-equal gdb-selected-frame gdb-previous-frame))
3539 (if (or (not (member 'gdb-invalidate-assembler
3540 gdb-pending-triggers))
3541 (not (string-equal gdb-pc-address
3542 gdb-previous-frame-pc-address)))
3544 ;; take previous disassemble command, if any, off the queue
3545 (with-current-buffer gud-comint-buffer
3546 (let ((queue gdb-input-queue))
3547 (dolist (item queue)
3548 (if (equal (cdr item) '(gdb-assembler-handler))
3549 (setq gdb-input-queue
3550 (delete item gdb-input-queue))))))
3553 (concat gdb-server-prefix "disassemble "
3554 (if (member gdb-pc-address '(nil "main")) nil "0x")
3555 gdb-pc-address "\n")
3556 'gdb-assembler-handler))
3557 (push 'gdb-invalidate-assembler gdb-pending-triggers)
3558 (setq gdb-previous-frame-pc-address gdb-pc-address)
3559 (setq gdb-previous-frame gdb-selected-frame)))))))
3561 (defun gdb-get-selected-frame ()
3562 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
3564 (if (string-equal gdb-version "pre-6.4")
3566 (list (concat gdb-server-prefix "info frame\n")
3567 'gdb-frame-handler))
3569 (list "server interpreter mi -stack-info-frame\n"
3570 'gdb-frame-handler-1)))
3571 (push 'gdb-get-selected-frame gdb-pending-triggers))))
3573 (defun gdb-frame-handler ()
3574 (setq gdb-pending-triggers
3575 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3576 (goto-char (point-min))
3577 (when (re-search-forward
3578 "Stack level \\([0-9]+\\), frame at \\(0x[[:xdigit:]]+\\)" nil t)
3579 (setq gdb-frame-number (match-string 1))
3580 (setq gdb-frame-address (match-string 2)))
3581 (goto-char (point-min))
3582 (when (re-search-forward ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(.*?\\)\
3583 \\(?: (\\(\\S-+?\\):[0-9]+?)\\)*; "
3585 (setq gdb-selected-frame (match-string 2))
3586 (if (gdb-get-buffer 'gdb-locals-buffer)
3587 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3588 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3589 (if (gdb-get-buffer 'gdb-assembler-buffer)
3590 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3591 (setq mode-name (concat "Machine:" gdb-selected-frame))))
3592 (setq gdb-pc-address (match-string 1))
3593 (if (and (match-string 3) gud-overlay-arrow-position)
3594 (let ((buffer (marker-buffer gud-overlay-arrow-position))
3595 (position (marker-position gud-overlay-arrow-position)))
3597 (string-equal (file-name-nondirectory
3598 (buffer-file-name buffer))
3599 (file-name-nondirectory (match-string 3))))
3600 (with-current-buffer buffer
3601 (setq fringe-indicator-alist
3602 (if (string-equal gdb-frame-number "0")
3604 '((overlay-arrow . hollow-right-triangle))))
3605 (set-marker gud-overlay-arrow-position position))))))
3606 (goto-char (point-min))
3607 (if (re-search-forward " source language \\(\\S-+\\)\." nil t)
3608 (setq gdb-current-language (match-string 1)))
3609 (gdb-invalidate-assembler))
3612 ;; Code specific to GDB 6.4
3613 (defconst gdb-source-file-regexp-1 "fullname=\"\\(.*?\\)\"")
3615 (defun gdb-set-gud-minor-mode-existing-buffers-1 ()
3616 "Create list of source files for current GDB session.
3617 If buffers already exist for any of these files, `gud-minor-mode'
3619 (goto-char (point-min))
3620 (while (re-search-forward gdb-source-file-regexp-1 nil t)
3621 (push (match-string 1) gdb-source-file-list))
3622 (dolist (buffer (buffer-list))
3623 (with-current-buffer buffer
3624 (when (member buffer-file-name gdb-source-file-list)
3625 (gdb-init-buffer))))
3626 (gdb-force-mode-line-update
3627 (propertize "ready" 'face font-lock-variable-name-face)))
3629 ;; Used for -stack-info-frame but could be used for -stack-list-frames too.
3630 (defconst gdb-stack-list-frames-regexp
3631 ".*?level=\"\\(.*?\\)\",.*?addr=\"\\(.*?\\)\",.*?func=\"\\(.*?\\)\",\
3632 \\(?:.*?file=\".*?\",.*?fullname=\"\\(.*?\\)\",.*?line=\"\\(.*?\\)\".*?}\\|\
3633 from=\"\\(.*?\\)\"\\)")
3635 (defun gdb-frame-handler-1 ()
3636 (setq gdb-pending-triggers
3637 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3638 (goto-char (point-min))
3639 (when (re-search-forward gdb-stack-list-frames-regexp nil t)
3640 (setq gdb-frame-number (match-string 1))
3641 (setq gdb-pc-address (match-string 2))
3642 (setq gdb-selected-frame (match-string 3))
3643 (if (gdb-get-buffer 'gdb-locals-buffer)
3644 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3645 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3646 (if (gdb-get-buffer 'gdb-assembler-buffer)
3647 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3648 (setq mode-name (concat "Machine:" gdb-selected-frame)))))
3649 (gdb-invalidate-assembler))
3651 ; Uses "-var-list-children --all-values". Needs GDB 6.4 onwards.
3652 (defun gdb-var-list-children-1 (varnum)
3655 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3656 (concat "server interpreter mi \"-var-list-children --all-values \\\""
3658 (concat "-var-list-children --all-values \"" varnum "\"\n"))
3659 `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
3661 (defconst gdb-var-list-children-regexp-1
3662 "child={.*?name=\"\\(.+?\\)\",.*?exp=\"\\(.+?\\)\",.*?\
3663 numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\)\
3664 \\(}\\|,.*?\\(type=\"\\(.+?\\)\"\\)?.*?}\\)")
3666 (defun gdb-var-list-children-handler-1 (varnum)
3667 (goto-char (point-min))
3668 (let ((var-list nil))
3669 (catch 'child-already-watched
3670 (dolist (var gdb-var-list)
3671 (if (string-equal varnum (car var))
3674 (while (re-search-forward gdb-var-list-children-regexp-1 nil t)
3675 (let ((varchild (list (match-string 1)
3679 (read (match-string 4))
3681 (if (assoc (car varchild) gdb-var-list)
3682 (throw 'child-already-watched nil))
3683 (push varchild var-list))))
3684 (push var var-list)))
3685 (setq gdb-var-list (nreverse var-list))))
3686 (gdb-speedbar-update))
3688 ; Uses "-var-update --all-values". Needs GDB 6.4 onwards.
3689 (defun gdb-var-update-1 ()
3690 (if (not (member 'gdb-var-update gdb-pending-triggers))
3694 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3695 "server interpreter mi \"-var-update --all-values *\"\n"
3696 "-var-update --all-values *\n")
3697 'gdb-var-update-handler-1))
3698 (push 'gdb-var-update gdb-pending-triggers))))
3700 (defconst gdb-var-update-regexp-1
3701 "{.*?name=\"\\(.*?\\)\",.*?\\(?:value=\\(\".*?\"\\),\\)?.*?\
3702 in_scope=\"\\(.*?\\)\".*?}")
3704 (defun gdb-var-update-handler-1 ()
3705 (dolist (var gdb-var-list)
3706 (setcar (nthcdr 5 var) nil))
3707 (goto-char (point-min))
3708 (while (re-search-forward gdb-var-update-regexp-1 nil t)
3709 (let* ((varnum (match-string 1))
3710 (var (assoc varnum gdb-var-list)))
3712 (let ((match (match-string 3)))
3713 (cond ((string-equal match "false")
3714 (if gdb-delete-out-of-scope
3715 (gdb-var-delete-1 varnum)
3716 (setcar (nthcdr 5 var) 'out-of-scope)))
3717 ((string-equal match "true")
3718 (setcar (nthcdr 5 var) 'changed)
3719 (setcar (nthcdr 4 var)
3720 (read (match-string 2))))
3721 ((string-equal match "invalid")
3722 (gdb-var-delete-1 varnum)))))))
3723 (setq gdb-pending-triggers
3724 (delq 'gdb-var-update gdb-pending-triggers))
3725 (gdb-speedbar-update))
3727 ;; Registers buffer.
3729 (gdb-set-buffer-rules 'gdb-registers-buffer
3730 'gdb-registers-buffer-name
3731 'gdb-registers-mode)
3733 (def-gdb-auto-update-trigger gdb-invalidate-registers-1
3734 (gdb-get-buffer 'gdb-registers-buffer)
3735 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3736 "server interpreter mi \"-data-list-register-values x\"\n"
3737 "-data-list-register-values x\n")
3738 gdb-data-list-register-values-handler)
3740 (defconst gdb-data-list-register-values-regexp
3741 "{.*?number=\"\\(.*?\\)\",.*?value=\"\\(.*?\\)\".*?}")
3743 (defun gdb-data-list-register-values-handler ()
3744 (setq gdb-pending-triggers (delq 'gdb-invalidate-registers-1
3745 gdb-pending-triggers))
3746 (goto-char (point-min))
3747 (if (re-search-forward gdb-error-regexp nil t)
3748 (let ((err (match-string 1)))
3749 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3750 (let ((buffer-read-only nil))
3752 (put-text-property 0 (length err) 'face font-lock-warning-face err)
3754 (goto-char (point-min)))))
3755 (let ((register-list (reverse gdb-register-names))
3756 (register nil) (register-string nil) (register-values nil))
3757 (goto-char (point-min))
3758 (while (re-search-forward gdb-data-list-register-values-regexp nil t)
3759 (setq register (pop register-list))
3760 (setq register-string (concat register "\t" (match-string 2) "\n"))
3761 (if (member (match-string 1) gdb-changed-registers)
3762 (put-text-property 0 (length register-string)
3763 'face 'font-lock-warning-face
3765 (setq register-values
3766 (concat register-values register-string)))
3767 (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
3768 (with-current-buffer buf
3769 (let* ((window (get-buffer-window buf 0))
3770 (start (window-start window))
3771 (p (window-point window))
3772 (buffer-read-only nil))
3774 (insert register-values)
3775 (set-window-start window start)
3776 (set-window-point window p))))))
3777 (gdb-data-list-register-values-custom))
3779 (defun gdb-data-list-register-values-custom ()
3780 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3782 (let ((buffer-read-only nil)
3784 (goto-char (point-min))
3785 (while (< (point) (point-max))
3786 (setq start (line-beginning-position))
3787 (setq end (line-end-position))
3788 (when (looking-at "^[^\t]+")
3789 (unless (string-equal (match-string 0) "No registers.")
3790 (put-text-property start (match-end 0)
3791 'face font-lock-variable-name-face)
3792 (add-text-properties start end
3793 '(help-echo "mouse-2: edit value"
3794 mouse-face highlight))))
3795 (forward-line 1))))))
3797 ;; Needs GDB 6.4 onwards (used to fail with no stack).
3798 (defun gdb-get-changed-registers ()
3799 (if (and (gdb-get-buffer 'gdb-registers-buffer)
3800 (not (member 'gdb-get-changed-registers gdb-pending-triggers)))
3804 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3805 "server interpreter mi -data-list-changed-registers\n"
3806 "-data-list-changed-registers\n")
3807 'gdb-get-changed-registers-handler))
3808 (push 'gdb-get-changed-registers gdb-pending-triggers))))
3810 (defconst gdb-data-list-register-names-regexp "\"\\(.*?\\)\"")
3812 (defun gdb-get-changed-registers-handler ()
3813 (setq gdb-pending-triggers
3814 (delq 'gdb-get-changed-registers gdb-pending-triggers))
3815 (setq gdb-changed-registers nil)
3816 (goto-char (point-min))
3817 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3818 (push (match-string 1) gdb-changed-registers)))
3823 ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards.
3824 (gdb-set-buffer-rules 'gdb-locals-buffer
3825 'gdb-locals-buffer-name
3828 (def-gdb-auto-update-trigger gdb-invalidate-locals-1
3829 (gdb-get-buffer 'gdb-locals-buffer)
3830 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3831 "server interpreter mi -\"stack-list-locals --simple-values\"\n"
3832 "-stack-list-locals --simple-values\n")
3833 gdb-stack-list-locals-handler)
3835 (defconst gdb-stack-list-locals-regexp
3836 "{.*?name=\"\\(.*?\\)\",.*?type=\"\\(.*?\\)\"")
3838 (defvar gdb-locals-watch-map-1
3839 (let ((map (make-sparse-keymap)))
3840 (suppress-keymap map)
3841 (define-key map "\r" 'gud-watch)
3842 (define-key map [mouse-2] 'gud-watch)
3844 "Keymap to create watch expression of a complex data type local variable.")
3846 (defvar gdb-edit-locals-map-1
3847 (let ((map (make-sparse-keymap)))
3848 (suppress-keymap map)
3849 (define-key map "\r" 'gdb-edit-locals-value)
3850 (define-key map [mouse-2] 'gdb-edit-locals-value)
3852 "Keymap to edit value of a simple data type local variable.")
3854 (defun gdb-edit-locals-value (&optional event)
3855 "Assign a value to a variable displayed in the locals buffer."
3856 (interactive (list last-input-event))
3858 (if event (posn-set-point (event-end event)))
3860 (let* ((var (current-word))
3861 (value (read-string (format "New value (%s): " var))))
3863 (list (concat gdb-server-prefix"set variable " var " = " value "\n")
3866 ;; Dont display values of arrays or structures.
3867 ;; These can be expanded using gud-watch.
3868 (defun gdb-stack-list-locals-handler ()
3869 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals-1
3870 gdb-pending-triggers))
3871 (goto-char (point-min))
3872 (if (re-search-forward gdb-error-regexp nil t)
3873 (let ((err (match-string 1)))
3874 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3875 (let ((buffer-read-only nil))
3878 (goto-char (point-min)))))
3879 (let (local locals-list)
3880 (goto-char (point-min))
3881 (while (re-search-forward gdb-stack-list-locals-regexp nil t)
3882 (let ((local (list (match-string 1)
3885 (if (looking-at ",value=\\(\".*\"\\).*?}")
3886 (setcar (nthcdr 2 local) (read (match-string 1))))
3887 (push local locals-list)))
3888 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
3889 (and buf (with-current-buffer buf
3890 (let* ((window (get-buffer-window buf 0))
3891 (start (window-start window))
3892 (p (window-point window))
3893 (buffer-read-only nil) (name) (value))
3895 (dolist (local locals-list)
3896 (setq name (car local))
3897 (setq value (nth 2 local))
3899 (string-match "^\\0x" value))
3900 (add-text-properties 0 (length name)
3901 `(mouse-face highlight
3902 help-echo "mouse-2: create watch expression"
3903 local-map ,gdb-locals-watch-map-1)
3905 (add-text-properties 0 (length value)
3906 `(mouse-face highlight
3907 help-echo "mouse-2: edit value"
3908 local-map ,gdb-edit-locals-map-1)
3911 (concat name "\t" (nth 1 local)
3913 (set-window-start window start)
3914 (set-window-point window p))))))))
3916 (defun gdb-get-register-names ()
3917 "Create a list of register names."
3918 (goto-char (point-min))
3919 (setq gdb-register-names nil)
3920 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3921 (push (match-string 1) gdb-register-names)))
3925 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
3926 ;;; gdb-ui.el ends here