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 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode acts as a graphical user interface to GDB. You can interact with
29 ;; GDB through the GUD buffer in the usual way, but there are also further
30 ;; buffers which control the execution and describe the state of your program.
31 ;; It separates the input/output of your program from that of GDB, if
32 ;; required, and watches expressions in the speedbar. It also uses features of
33 ;; Emacs 21 such as the fringe/display margin for breakpoints, and the toolbar
34 ;; (see the GDB Graphical Interface section in the Emacs info manual).
36 ;; By default, M-x gdb will start the debugger. However, if you have customised
37 ;; gud-gdb-command-name, then start it with M-x gdba.
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, then see the
43 ;; Annotations 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
47 ;; it. Some GDB/MI commands are used in this file through the CLI command
48 ;; 'interpreter mi <mi-command>'. A file called gdb-mi.el is included with
49 ;; GDB (6.2 onwards) that uses GDB/MI as the primary interface to GDB. It is
50 ;; still under development and is part of a process to migrate Emacs from
51 ;; annotations to GDB/MI.
55 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
56 ;; explicitly in your program if you want timely display of I/O in Emacs.
57 ;; Alternatively you can make the output stream unbuffered, for example, by
61 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
64 ;; and compiling with -DUNBUFFERED while debugging.
69 ;; 1) Use MI command -data-read-memory for memory window.
70 ;; 2) Highlight changed register values (use MI commands
71 ;; -data-list-register-values and -data-list-changed-registers instead
72 ;; of 'info registers'.
73 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
74 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
75 ;; 5) After release of 22.1 use '-var-list-children --all-values'
76 ;; and '-stack-list-locals 2' which need GDB 6.1 onwards.
84 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
85 (defvar gdb-previous-frame-address nil)
86 (defvar gdb-memory-address "main")
87 (defvar gdb-previous-frame nil)
88 (defvar gdb-selected-frame nil)
89 (defvar gdb-frame-number nil)
90 (defvar gdb-current-language nil)
91 (defvar gdb-var-list nil "List of variables in watch window.")
92 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
93 (defvar gdb-main-file nil "Source file from which program execution begins.")
94 (defvar gdb-buffer-type nil)
95 (defvar gdb-overlay-arrow-position nil)
96 (defvar gdb-server-prefix nil)
97 (defvar gdb-flush-pending-output nil)
98 (defvar gdb-location-alist nil
99 "Alist of breakpoint numbers and full filenames.")
100 (defvar gdb-find-file-unhook nil)
101 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
102 and #define directives otherwise.")
103 (defvar gdb-error "Non-nil when GDB is reporting an error.")
104 (defvar gdb-macro-info nil
105 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
106 (defvar gdb-fringe-width nil)
108 (defvar gdb-buffer-type nil
109 "One of the symbols bound in `gdb-buffer-rules'.")
111 (defvar gdb-input-queue ()
112 "A list of gdb command objects.")
114 (defvar gdb-prompting nil
115 "True when gdb is idle with no pending input.")
117 (defvar gdb-output-sink 'user
118 "The disposition of the output of the current gdb command.
119 Possible values are these symbols:
121 `user' -- gdb output should be copied to the GUD buffer
124 `inferior' -- gdb output should be copied to the inferior-io buffer.
126 `pre-emacs' -- output should be ignored util the post-prompt
127 annotation is received. Then the output-sink
129 `emacs' -- output should be collected in the partial-output-buffer
130 for subsequent processing by a command. This is the
131 disposition of output generated by commands that
132 gdb mode sends to gdb on its own behalf.
133 `post-emacs' -- ignore output until the prompt annotation is
134 received, then go to USER disposition.
136 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
137 \(`user' and `emacs').")
139 (defvar gdb-current-item nil
140 "The most recent command item sent to gdb.")
142 (defvar gdb-pending-triggers '()
143 "A list of trigger functions that have run later than their output
146 ;; end of gdb variables
149 (defun gdba (command-line)
150 "Run gdb on program FILE in buffer *gud-FILE*.
151 The directory containing FILE becomes the initial working directory
152 and source-file directory for your debugger.
154 If `gdb-many-windows' is nil (the default value) then gdb just
155 pops up the GUD buffer unless `gdb-show-main' is t. In this case
156 it starts with two windows: one displaying the GUD buffer and the
157 other with the source file with the main routine of the inferior.
159 If `gdb-many-windows' is t, regardless of the value of
160 `gdb-show-main', the layout below will appear unless
161 `gdb-use-inferior-io-buffer' is nil when the source buffer
162 occupies the full width of the frame. Keybindings are given in
165 Watch expressions appear in the speedbar/slowbar.
167 The following commands help control operation :
169 `gdb-many-windows' - Toggle the number of windows gdb uses.
170 `gdb-restore-windows' - To restore the window layout.
172 See Info node `(emacs)GDB Graphical Interface' for a more
173 detailed description of this mode.
176 ---------------------------------------------------------------------
178 ---------------------------------------------------------------------
179 GUD buffer (I/O of GDB) | Locals buffer
183 ---------------------------------------------------------------------
184 Source buffer | Input/Output (of inferior) buffer
192 ---------------------------------------------------------------------
193 Stack buffer | Breakpoints buffer
194 RET gdb-frames-select | SPC gdb-toggle-breakpoint
195 | RET gdb-goto-breakpoint
196 | d gdb-delete-breakpoint
197 ---------------------------------------------------------------------"
199 (interactive (list (gud-query-cmdline 'gdba)))
201 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
205 (defvar gdb-debug-log nil)
208 (defcustom gdb-enable-debug-log nil
209 "Non-nil means record the process input and output in `gdb-debug-log'."
214 (defcustom gdb-use-inferior-io-buffer nil
215 "Non-nil means display output from the inferior in a separate buffer."
220 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
221 "Shell command for generating a list of defined macros in a source file.
222 This list is used to display the #define directive associated
223 with an identifier as a tooltip. It works in a debug session with
224 GDB, when gud-tooltip-mode is t.
226 Set `gdb-cpp-define-alist-flags' for any include paths or
232 (defcustom gdb-cpp-define-alist-flags ""
233 "Preprocessor flags for `gdb-cpp-define-alist-program'."
238 (defcustom gdb-show-main nil
239 "Non-nil means display source file containing the main routine at startup.
240 Also display the main routine in the disassembly buffer if present."
245 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
247 (defun gdb-create-define-alist ()
248 "Create an alist of #define directives for GUD tooltips."
249 (let* ((file (buffer-file-name))
251 (with-output-to-string
252 (with-current-buffer standard-output
253 (call-process shell-file-name
254 (if (file-exists-p file) file nil)
255 (list t nil) nil "-c"
256 (concat gdb-cpp-define-alist-program " "
257 gdb-cpp-define-alist-flags)))))
258 (define-list (split-string output "\n" t))
260 (setq gdb-define-alist nil)
261 (dolist (define define-list)
262 (setq name (nth 1 (split-string define "[( ]")))
263 (push (cons name define) gdb-define-alist))))
265 (defun gdb-tooltip-print ()
267 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
268 (let ((string (buffer-string)))
269 ;; remove newline for gud-tooltip-echo-area
270 (substring string 0 (- (length string) 1))))
271 (or gud-tooltip-echo-area tooltip-use-echo-area)))
273 ;; If expr is a macro for a function don't print because of possible dangerous
274 ;; side-effects. Also printing a function within a tooltip generates an
275 ;; unexpected starting annotation (phase error).
276 (defun gdb-tooltip-print-1 (expr)
277 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
278 (goto-char (point-min))
279 (if (search-forward "expands to: " nil t)
280 (unless (looking-at "\\S+.*(.*).*")
282 (list (concat gdb-server-prefix "print " expr "\n")
283 'gdb-tooltip-print))))))
285 (defun gdb-set-gud-minor-mode (buffer)
286 "Set `gud-minor-mode' from find-file if appropriate."
287 (goto-char (point-min))
288 (unless (search-forward "No source file named " nil t)
291 (list (concat gdb-server-prefix "info source\n")
292 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
293 (error (setq gdb-find-file-unhook t)))))
295 (defun gdb-set-gud-minor-mode-1 (buffer)
296 (goto-char (point-min))
297 (when (and (search-forward "Located in " nil t)
299 (string-equal (buffer-file-name buffer)
301 (with-current-buffer buffer
302 (set (make-local-variable 'gud-minor-mode) 'gdba)
303 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
304 (when gud-tooltip-mode
305 (make-local-variable 'gdb-define-alist)
306 (gdb-create-define-alist)
307 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
309 (defun gdb-set-gud-minor-mode-existing-buffers ()
310 (dolist (buffer (buffer-list))
311 (let ((file (buffer-file-name buffer)))
315 (list (concat gdb-server-prefix "list "
316 (file-name-nondirectory file) ":1\n")
317 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
320 (setq gdb-debug-log nil)
321 (set (make-local-variable 'gud-minor-mode) 'gdba)
322 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
324 (gud-def gud-break (if (not (string-match "Machine" mode-name))
325 (gud-call "break %f:%l" arg)
329 (gud-call "break *%a" arg)))
330 "\C-b" "Set breakpoint at current line or address.")
332 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
333 (gud-call "clear %f:%l" arg)
337 (gud-call "clear *%a" arg)))
338 "\C-d" "Remove breakpoint at current line or address.")
340 (gud-def gud-until (if (not (string-match "Machine" mode-name))
341 (gud-call "until %f:%l" arg)
345 (gud-call "until *%a" arg)))
346 "\C-u" "Continue to current line or address.")
348 (define-key gud-minor-mode-map [left-margin mouse-1]
349 'gdb-mouse-set-clear-breakpoint)
350 (define-key gud-minor-mode-map [left-fringe mouse-1]
351 'gdb-mouse-set-clear-breakpoint)
352 (define-key gud-minor-mode-map [left-margin mouse-3]
353 'gdb-mouse-toggle-breakpoint)
354 ; Currently only works in margin.
355 ; (define-key gud-minor-mode-map [left-fringe mouse-3]
356 ; 'gdb-mouse-toggle-breakpoint)
358 (setq comint-input-sender 'gdb-send)
361 (setq gdb-frame-address (if gdb-show-main "main" nil))
362 (setq gdb-previous-frame-address nil
363 gdb-memory-address "main"
364 gdb-previous-frame nil
365 gdb-selected-frame nil
366 gdb-current-language nil
374 gdb-pending-triggers nil
375 gdb-output-sink 'user
376 gdb-server-prefix "server "
377 gdb-flush-pending-output nil
378 gdb-location-alist nil
379 gdb-find-file-unhook nil
382 gdb-buffer-fringe-width (car (window-fringes)))
384 (setq gdb-buffer-type 'gdba)
386 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
388 (if (eq window-system 'w32)
389 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
390 (gdb-enqueue-input (list "set height 0\n" 'ignore))
391 (gdb-enqueue-input (list "set width 0\n" 'ignore))
392 ;; find source file and compilation directory here
393 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
394 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
395 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
397 (gdb-set-gud-minor-mode-existing-buffers)
398 (run-hooks 'gdba-mode-hook))
400 (defcustom gdb-use-colon-colon-notation nil
401 "If non-nil use FUN::VAR format to display variables in the speedbar."
407 "Watch expression at point."
410 (let ((expr (tooltip-identifier-from-point (point))))
411 (if (and (string-equal gdb-current-language "c")
412 gdb-use-colon-colon-notation gdb-selected-frame)
413 (setq expr (concat gdb-selected-frame "::" expr)))
414 (catch 'already-watched
415 (dolist (var gdb-var-list)
416 (if (string-equal expr (car var)) (throw 'already-watched nil)))
417 (set-text-properties 0 (length expr) nil expr)
420 (if (eq gud-minor-mode 'gdba)
421 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
422 (concat"-var-create - * " expr "\n"))
423 `(lambda () (gdb-var-create-handler ,expr))))))
424 (select-window (get-buffer-window gud-comint-buffer 0)))
426 (defconst gdb-var-create-regexp
427 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
429 (defun gdb-var-create-handler (expr)
430 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
431 (goto-char (point-min))
432 (if (re-search-forward gdb-var-create-regexp nil t)
433 (let ((var (list expr
438 (push var gdb-var-list)
440 (if (equal (nth 2 var) "0")
443 (if (with-current-buffer
444 gud-comint-buffer (eq gud-minor-mode 'gdba))
445 (concat "server interpreter mi \"-var-evaluate-expression "
447 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
448 `(lambda () (gdb-var-evaluate-expression-handler
450 (setq gdb-var-changed t)))
451 (if (re-search-forward "Undefined command" nil t)
452 (message-box "Watching expressions requires gdb 6.0 onwards")
453 (message "No symbol \"%s\" in current context." expr)))))
455 (defun gdb-var-evaluate-expression-handler (varnum changed)
456 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
457 (goto-char (point-min))
458 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t)
461 (dolist (var gdb-var-list)
462 (if (string-equal varnum (cadr var))
464 (if changed (setcar (nthcdr 5 var) t))
465 (setcar (nthcdr 4 var) (match-string 1))
466 (setcar (nthcdr num gdb-var-list) var)
467 (throw 'var-found nil)))
468 (setq num (+ num 1))))))
469 (setq gdb-var-changed t))
471 (defun gdb-var-list-children (varnum)
473 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
474 `(lambda () (gdb-var-list-children-handler ,varnum)))))
476 (defconst gdb-var-list-children-regexp
477 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
479 (defun gdb-var-list-children-handler (varnum)
480 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
481 (goto-char (point-min))
482 (let ((var-list nil))
483 (catch 'child-already-watched
484 (dolist (var gdb-var-list)
485 (if (string-equal varnum (cadr var))
488 (while (re-search-forward gdb-var-list-children-regexp nil t)
489 (let ((varchild (list (match-string 2)
493 (if (looking-at ",type=\"\\(.*?\\)\"")
494 (setcar (nthcdr 3 varchild) (match-string 1)))
495 (dolist (var1 gdb-var-list)
496 (if (string-equal (cadr var1) (cadr varchild))
497 (throw 'child-already-watched nil)))
498 (push varchild var-list)
499 (if (equal (nth 2 varchild) "0")
503 "server interpreter mi \"-var-evaluate-expression "
504 (nth 1 varchild) "\"\n")
505 `(lambda () (gdb-var-evaluate-expression-handler
506 ,(nth 1 varchild) nil))))))))
507 (push var var-list)))
508 (setq gdb-var-list (nreverse var-list))))))
510 (defun gdb-var-update ()
511 (when (not (member 'gdb-var-update gdb-pending-triggers))
513 (list "server interpreter mi \"-var-update *\"\n"
514 'gdb-var-update-handler))
515 (push 'gdb-var-update gdb-pending-triggers)))
517 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
519 (defun gdb-var-update-handler ()
520 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
521 (goto-char (point-min))
522 (while (re-search-forward gdb-var-update-regexp nil t)
523 (let ((varnum (match-string 1)))
526 (concat "server interpreter mi \"-var-evaluate-expression "
528 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
529 (setq gdb-pending-triggers
530 (delq 'gdb-var-update gdb-pending-triggers))
531 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
532 ;; Dummy command to update speedbar at right time.
533 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
534 ;; Keep gdb-pending-triggers non-nil till end.
535 (push 'gdb-speedbar-timer gdb-pending-triggers)))
537 (defun gdb-speedbar-timer-fn ()
538 (setq gdb-pending-triggers
539 (delq 'gdb-speedbar-timer gdb-pending-triggers))
540 (with-current-buffer gud-comint-buffer
541 (speedbar-timer-fn)))
543 (defun gdb-var-delete ()
544 "Delete watch expression at point from the speedbar."
546 (if (with-current-buffer
547 gud-comint-buffer (memq gud-minor-mode '(gdbmi gdba)))
548 (let ((text (speedbar-line-text)))
549 (string-match "\\(\\S-+\\)" text)
550 (let* ((expr (match-string 1 text))
551 (var (assoc expr gdb-var-list))
553 (unless (string-match "\\." varnum)
556 (if (with-current-buffer gud-comint-buffer
557 (eq gud-minor-mode 'gdba))
558 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
559 (concat "-var-delete " varnum "\n"))
561 (setq gdb-var-list (delq var gdb-var-list))
562 (dolist (varchild gdb-var-list)
563 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
564 (setq gdb-var-list (delq varchild gdb-var-list))))
565 (setq gdb-var-changed t))))))
567 (defun gdb-edit-value (text token indent)
568 "Assign a value to a variable displayed in the speedbar."
569 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
570 (varnum (cadr var)) (value))
571 (setq value (read-string "New value: "))
574 (if (with-current-buffer gud-comint-buffer
575 (eq gud-minor-mode 'gdba))
576 (concat "server interpreter mi \"-var-assign "
577 varnum " " value "\"\n")
578 (concat "-var-assign " varnum " " value "\n"))
581 (defcustom gdb-show-changed-values t
582 "If non-nil highlight values that have recently changed in the speedbar.
583 The highlighting is done with `font-lock-warning-face'."
588 (defun gdb-speedbar-expand-node (text token indent)
589 "Expand the node the user clicked on.
590 TEXT is the text of the button we clicked on, a + or - item.
591 TOKEN is data related to this node.
592 INDENT is the current indentation depth."
593 (cond ((string-match "+" text) ;expand this node
594 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
595 (gdb-var-list-children token)
598 (gdbmi-var-list-children token))))
599 ((string-match "-" text) ;contract this node
600 (dolist (var gdb-var-list)
601 (if (string-match (concat token "\\.") (nth 1 var))
602 (setq gdb-var-list (delq var gdb-var-list))))
603 (setq gdb-var-changed t))))
605 (defun gdb-get-target-string ()
606 (with-current-buffer gud-comint-buffer
613 ;; Each buffer has a TYPE -- a symbol that identifies the function
614 ;; of that particular buffer.
616 ;; The usual gdb interaction buffer is given the type `gdba' and
617 ;; is constructed specially.
619 ;; Others are constructed by gdb-get-create-buffer and
620 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
622 (defvar gdb-buffer-rules-assoc '())
624 (defun gdb-get-buffer (key)
625 "Return the gdb buffer tagged with type KEY.
626 The key should be one of the cars in `gdb-buffer-rules-assoc'."
628 (gdb-look-for-tagged-buffer key (buffer-list))))
630 (defun gdb-get-create-buffer (key)
631 "Create a new gdb buffer of the type specified by KEY.
632 The key should be one of the cars in `gdb-buffer-rules-assoc'."
633 (or (gdb-get-buffer key)
634 (let* ((rules (assoc key gdb-buffer-rules-assoc))
635 (name (funcall (gdb-rules-name-maker rules)))
636 (new (get-buffer-create name)))
637 (with-current-buffer new
639 (if (cdr (cdr rules))
640 (setq trigger (funcall (car (cdr (cdr rules))))))
641 (set (make-local-variable 'gdb-buffer-type) key)
642 (set (make-local-variable 'gud-minor-mode)
643 (with-current-buffer gud-comint-buffer gud-minor-mode))
644 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
645 (if trigger (funcall trigger)))
648 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
650 (defun gdb-look-for-tagged-buffer (key bufs)
652 (while (and (not retval) bufs)
653 (set-buffer (car bufs))
654 (if (eq gdb-buffer-type key)
655 (setq retval (car bufs)))
656 (setq bufs (cdr bufs)))
660 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
661 ;; at least one and possible more functions. The functions have these
662 ;; roles in defining a buffer type:
664 ;; NAME - Return a name for this buffer type.
666 ;; The remaining function(s) are optional:
668 ;; MODE - called in a new buffer with no arguments, should establish
669 ;; the proper mode for the buffer.
672 (defun gdb-set-buffer-rules (buffer-type &rest rules)
673 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
675 (setcdr binding rules)
676 (push (cons buffer-type rules)
677 gdb-buffer-rules-assoc))))
679 ;; GUD buffers are an exception to the rules
680 (gdb-set-buffer-rules 'gdba 'error)
683 ;; Partial-output buffer : This accumulates output from a command executed on
684 ;; behalf of emacs (rather than the user).
686 (gdb-set-buffer-rules 'gdb-partial-output-buffer
687 'gdb-partial-output-name)
689 (defun gdb-partial-output-name ()
690 (concat "*partial-output-"
691 (gdb-get-target-string)
695 (gdb-set-buffer-rules 'gdb-inferior-io
696 'gdb-inferior-io-name
697 'gdb-inferior-io-mode)
699 (defun gdb-inferior-io-name ()
700 (concat "*input/output of "
701 (gdb-get-target-string)
704 (defun gdb-display-inferior-io-buffer ()
705 "Display IO of inferior in a separate window."
707 (if gdb-use-inferior-io-buffer
709 (gdb-get-create-buffer 'gdb-inferior-io))))
711 (defconst gdb-frame-parameters
712 '((height . 14) (width . 80)
714 (tool-bar-lines . nil)
715 (menu-bar-lines . nil)
718 (defun gdb-frame-inferior-io-buffer ()
719 "Display IO of inferior in a new frame."
721 (if gdb-use-inferior-io-buffer
722 (let ((special-display-regexps (append special-display-regexps '(".*")))
723 (special-display-frame-alist gdb-frame-parameters))
724 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
726 (defvar gdb-inferior-io-mode-map
727 (let ((map (make-sparse-keymap)))
728 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
729 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
730 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
731 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
732 (define-key map "\C-d" 'gdb-inferior-io-eof)
735 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
736 "Major mode for gdb inferior-io."
737 :syntax-table nil :abbrev-table nil
738 ;; We want to use comint because it has various nifty and familiar
739 ;; features. We don't need a process, but comint wants one, so create
741 (make-comint-in-buffer
742 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
743 (current-buffer) "hexl")
744 (setq comint-input-sender 'gdb-inferior-io-sender))
746 (defun gdb-inferior-io-sender (proc string)
747 ;; PROC is the pseudo-process created to satisfy comint.
748 (with-current-buffer (process-buffer proc)
749 (setq proc (get-buffer-process gud-comint-buffer))
750 (process-send-string proc string)
751 (process-send-string proc "\n")))
753 (defun gdb-inferior-io-interrupt ()
754 "Interrupt the program being debugged."
757 (get-buffer-process gud-comint-buffer) comint-ptyp))
759 (defun gdb-inferior-io-quit ()
760 "Send quit signal to the program being debugged."
763 (get-buffer-process gud-comint-buffer) comint-ptyp))
765 (defun gdb-inferior-io-stop ()
766 "Stop the program being debugged."
769 (get-buffer-process gud-comint-buffer) comint-ptyp))
771 (defun gdb-inferior-io-eof ()
772 "Send end-of-file to the program being debugged."
775 (get-buffer-process gud-comint-buffer)))
779 ;; gdb communications
782 ;; INPUT: things sent to gdb
784 ;; The queues are lists. Each element is either a string (indicating user or
785 ;; user-like input) or a list of the form:
787 ;; (INPUT-STRING HANDLER-FN)
789 ;; The handler function will be called from the partial-output buffer when the
790 ;; command completes. This is the way to write commands which invoke gdb
791 ;; commands autonomously.
793 ;; These lists are consumed tail first.
796 (defun gdb-send (proc string)
797 "A comint send filter for gdb.
798 This filter may simply queue input for a later time."
799 (with-current-buffer gud-comint-buffer
800 (remove-text-properties (point-min) (point-max) '(face)))
801 (let ((item (concat string "\n")))
804 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
805 (process-send-string proc item))
806 (gdb-enqueue-input item))))
808 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
809 ;; is a query, or other non-top-level prompt.
811 (defun gdb-enqueue-input (item)
815 (setq gdb-prompting nil))
816 (push item gdb-input-queue)))
818 (defun gdb-dequeue-input ()
819 (let ((queue gdb-input-queue))
821 (let ((last (car (last queue))))
822 (unless (nbutlast queue) (setq gdb-input-queue '()))
825 (defun gdb-send-item (item)
826 (setq gdb-flush-pending-output nil)
827 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
828 (setq gdb-current-item item)
829 (with-current-buffer gud-comint-buffer
830 (if (eq gud-minor-mode 'gdba)
833 (setq gdb-output-sink 'user)
834 (process-send-string (get-buffer-process gud-comint-buffer) item))
836 (gdb-clear-partial-output)
837 (setq gdb-output-sink 'pre-emacs)
838 (process-send-string (get-buffer-process gud-comint-buffer)
840 ;; case: eq gud-minor-mode 'gdbmi
841 (gdb-clear-partial-output)
842 (setq gdb-output-sink 'emacs)
843 (process-send-string (get-buffer-process gud-comint-buffer)
847 ;; output -- things gdb prints to emacs
849 ;; GDB output is a stream interrupted by annotations.
850 ;; Annotations can be recognized by their beginning
851 ;; with \C-j\C-z\C-z<tag><opt>\C-j
853 ;; The tag is a string obeying symbol syntax.
855 ;; The optional part `<opt>' can be either the empty string
856 ;; or a space followed by more data relating to the annotation.
857 ;; For example, the SOURCE annotation is followed by a filename,
858 ;; line number and various useless goo. This data must not include
862 (defcustom gud-gdba-command-name "gdb -annotate=3"
863 "Default command to execute an executable under the GDB-UI debugger."
868 (defvar gdb-annotation-rules
869 '(("pre-prompt" gdb-pre-prompt)
870 ("prompt" gdb-prompt)
871 ("commands" gdb-subprompt)
872 ("overload-choice" gdb-subprompt)
873 ("query" gdb-subprompt)
874 ;; Need this prompt for GDB 6.1
875 ("nquery" gdb-subprompt)
876 ("prompt-for-continue" gdb-subprompt)
877 ("post-prompt" gdb-post-prompt)
878 ("source" gdb-source)
879 ("starting" gdb-starting)
880 ("exited" gdb-exited)
881 ("signalled" gdb-exited)
882 ("signal" gdb-stopping)
883 ("breakpoint" gdb-stopping)
884 ("watchpoint" gdb-stopping)
885 ("frame-begin" gdb-frame-begin)
886 ("stopped" gdb-stopped)
887 ("error-begin" gdb-error)
889 ) "An assoc mapping annotation tags to functions which process them.")
892 (setq gdb-flush-pending-output t)
893 (setq gud-running nil)
894 (setq gdb-output-sink 'user)
895 (setq gdb-input-queue nil)
896 (setq gdb-pending-triggers nil)
897 (setq gdb-prompting t))
899 (defconst gdb-source-spec-regexp
900 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
902 ;; Do not use this except as an annotation handler.
903 (defun gdb-source (args)
904 (string-match gdb-source-spec-regexp args)
905 ;; Extract the frame position from the marker.
908 (match-string 1 args)
909 (string-to-number (match-string 2 args))))
910 (setq gdb-frame-address (match-string 3 args))
911 ;; cover for auto-display output which comes *before*
912 ;; stopped annotation
913 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
915 (defun gdb-pre-prompt (ignored)
916 "An annotation handler for `pre-prompt'.
917 This terminates the collection of output from a previous command if that
918 happens to be in effect."
919 (let ((sink gdb-output-sink))
923 (setq gdb-output-sink 'post-emacs))
926 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
928 (defun gdb-prompt (ignored)
929 "An annotation handler for `prompt'.
930 This sends the next command (if any) to gdb."
931 (when gdb-first-prompt (gdb-ann3))
932 (let ((sink gdb-output-sink))
935 ((eq sink 'post-emacs)
936 (setq gdb-output-sink 'user)
938 (car (cdr gdb-current-item))))
939 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
943 (error "Phase error in gdb-prompt (got %s)" sink))))
944 (let ((input (gdb-dequeue-input)))
946 (gdb-send-item input)
948 (setq gdb-prompting t)
949 (gud-display-frame)))))
951 (defun gdb-subprompt (ignored)
952 "An annotation handler for non-top-level prompts."
953 (setq gdb-prompting t))
955 (defun gdb-starting (ignored)
956 "An annotation handler for `starting'.
957 This says that I/O for the subprocess is now the program being debugged,
959 (setq gdb-active-process t)
960 (let ((sink gdb-output-sink))
965 (if gdb-use-inferior-io-buffer
966 (setq gdb-output-sink 'inferior))))
969 (error "Unexpected `starting' annotation")))))
971 (defun gdb-stopping (ignored)
972 "An annotation handler for `breakpoint' and other annotations.
973 They say that I/O for the subprocess is now GDB, not the program
975 (if gdb-use-inferior-io-buffer
976 (let ((sink gdb-output-sink))
979 (setq gdb-output-sink 'user))
982 (error "Unexpected stopping annotation"))))))
984 (defun gdb-exited (ignored)
985 "An annotation handler for `exited' and `signalled'.
986 They say that I/O for the subprocess is now GDB, not the program
987 being debugged and that the program is no longer running. This
988 function is used to change the focus of GUD tooltips to #define
990 (setq gdb-active-process nil)
991 (gdb-stopping ignored))
993 (defun gdb-frame-begin (ignored)
994 (let ((sink gdb-output-sink))
997 (setq gdb-output-sink 'user))
1002 (error "Unexpected frame-begin annotation (%S)" sink)))))
1004 (defun gdb-stopped (ignored)
1005 "An annotation handler for `stopped'.
1006 It is just like `gdb-stopping', except that if we already set the output
1007 sink to `user' in `gdb-stopping', that is fine."
1008 (setq gud-running nil)
1009 (let ((sink gdb-output-sink))
1011 ((eq sink 'inferior)
1012 (setq gdb-output-sink 'user))
1016 (error "Unexpected stopped annotation")))))
1018 (defun gdb-error (ignored)
1019 (setq gdb-error (not gdb-error)))
1021 (defun gdb-post-prompt (ignored)
1022 "An annotation handler for `post-prompt'.
1023 This begins the collection of output from the current command if that
1024 happens to be appropriate."
1025 (unless gdb-pending-triggers
1026 (gdb-get-selected-frame)
1027 (gdb-invalidate-frames)
1028 (gdb-invalidate-breakpoints)
1029 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1030 ;; so gdb-frame-address is updated.
1031 ;; (gdb-invalidate-assembler)
1032 (gdb-invalidate-registers)
1033 (gdb-invalidate-memory)
1034 (gdb-invalidate-locals)
1035 (gdb-invalidate-threads)
1036 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1037 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1038 ;; Only needed/used with speedbar/watch expressions.
1039 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1040 (setq gdb-var-changed t) ; force update
1041 (dolist (var gdb-var-list)
1042 (setcar (nthcdr 5 var) nil))
1044 (let ((sink gdb-output-sink))
1047 ((eq sink 'pre-emacs)
1048 (setq gdb-output-sink 'emacs))
1051 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1053 (defun gud-gdba-marker-filter (string)
1054 "A gud marker filter for gdb. Handle a burst of output from GDB."
1055 (if gdb-flush-pending-output
1057 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1058 ;; Recall the left over gud-marker-acc from last time.
1059 (setq gud-marker-acc (concat gud-marker-acc string))
1060 ;; Start accumulating output for the GUD buffer.
1063 ;; Process all the complete markers in this chunk.
1064 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1065 (let ((annotation (match-string 1 gud-marker-acc)))
1067 ;; Stuff prior to the match is just ordinary output.
1068 ;; It is either concatenated to OUTPUT or directed
1073 (substring gud-marker-acc 0 (match-beginning 0))))
1075 ;; Take that stuff off the gud-marker-acc.
1076 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1078 ;; Parse the tag from the annotation, and maybe its arguments.
1079 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1080 (let* ((annotation-type (match-string 1 annotation))
1081 (annotation-arguments (match-string 2 annotation))
1082 (annotation-rule (assoc annotation-type
1083 gdb-annotation-rules)))
1084 ;; Call the handler for this annotation.
1086 (funcall (car (cdr annotation-rule))
1087 annotation-arguments)
1088 ;; Else the annotation is not recognized. Ignore it silently,
1089 ;; so that GDB can add new annotations without causing
1093 ;; Does the remaining text end in a partial line?
1094 ;; If it does, then keep part of the gud-marker-acc until we get more.
1095 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1098 ;; Everything before the potential marker start can be output.
1100 (gdb-concat-output output
1101 (substring gud-marker-acc 0
1102 (match-beginning 0))))
1104 ;; Everything after, we save, to combine with later input.
1105 (setq gud-marker-acc (substring gud-marker-acc
1106 (match-beginning 0))))
1108 ;; In case we know the gud-marker-acc contains no partial annotations:
1110 (setq output (gdb-concat-output output gud-marker-acc))
1111 (setq gud-marker-acc "")))
1114 (defun gdb-concat-output (so-far new)
1116 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1117 (let ((sink gdb-output-sink))
1119 ((eq sink 'user) (concat so-far new))
1120 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1122 (gdb-append-to-partial-output new)
1124 ((eq sink 'inferior)
1125 (gdb-append-to-inferior-io new)
1129 (error "Bogon output sink %S" sink)))))
1131 (defun gdb-append-to-partial-output (string)
1132 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1133 (goto-char (point-max))
1136 (defun gdb-clear-partial-output ()
1137 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1140 (defun gdb-append-to-inferior-io (string)
1141 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1142 (goto-char (point-max))
1143 (insert-before-markers string))
1144 (if (not (string-equal string ""))
1145 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1147 (defun gdb-clear-inferior-io ()
1148 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1152 ;; One trick is to have a command who's output is always available in a buffer
1153 ;; of it's own, and is always up to date. We build several buffers of this
1156 ;; There are two aspects to this: gdb has to tell us when the output for that
1157 ;; command might have changed, and we have to be able to run the command
1158 ;; behind the user's back.
1160 ;; The output phasing associated with the variable gdb-output-sink
1161 ;; help us to run commands behind the user's back.
1163 ;; Below is the code for specificly managing buffers of output from one
1167 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1168 ;; It adds an input for the command we are tracking. It should be the
1169 ;; annotation rule binding of whatever gdb sends to tell us this command
1170 ;; might have changed it's output.
1172 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1173 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1174 ;; input in the input queue (see comment about ``gdb communications'' above).
1176 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1178 `(defun ,name (&optional ignored)
1179 (if (and (,demand-predicate)
1181 gdb-pending-triggers)))
1184 (list ,gdb-command ',output-handler))
1185 (push ',name gdb-pending-triggers)))))
1187 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1189 (setq gdb-pending-triggers
1191 gdb-pending-triggers))
1192 (let ((buf (gdb-get-buffer ',buf-key)))
1194 (with-current-buffer buf
1195 (let ((p (window-point (get-buffer-window buf 0)))
1196 (buffer-read-only nil))
1198 (insert-buffer-substring (gdb-get-create-buffer
1199 'gdb-partial-output-buffer))
1200 (set-window-point (get-buffer-window buf 0) p)))))
1201 ;; put customisation here
1204 (defmacro def-gdb-auto-updated-buffer (buffer-key
1205 trigger-name gdb-command
1206 output-handler-name custom-defun)
1208 (def-gdb-auto-update-trigger ,trigger-name
1209 ;; The demand predicate:
1210 (lambda () (gdb-get-buffer ',buffer-key))
1212 ,output-handler-name)
1213 (def-gdb-auto-update-handler ,output-handler-name
1214 ,trigger-name ,buffer-key ,custom-defun)))
1218 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1220 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1221 'gdb-breakpoints-buffer-name
1222 'gdb-breakpoints-mode)
1224 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1225 ;; This defines the auto update rule for buffers of type
1226 ;; `gdb-breakpoints-buffer'.
1228 ;; It defines a function to serve as the annotation handler that
1229 ;; handles the `foo-invalidated' message. That function is called:
1230 gdb-invalidate-breakpoints
1232 ;; To update the buffer, this command is sent to gdb.
1233 "server info breakpoints\n"
1235 ;; This also defines a function to be the handler for the output
1236 ;; from the command above. That function will copy the output into
1237 ;; the appropriately typed buffer. That function will be called:
1238 gdb-info-breakpoints-handler
1239 ;; buffer specific functions
1240 gdb-info-breakpoints-custom)
1242 (defconst breakpoint-xpm-data
1244 static char *magick[] = {
1245 /* columns rows colors chars-per-pixel */
1261 "XPM data used for breakpoint icon.")
1263 (defconst breakpoint-enabled-pbm-data
1266 0 0 0 0 1 1 1 1 0 0 0 0
1267 0 0 0 1 1 1 1 1 1 0 0 0
1268 0 0 1 1 1 1 1 1 1 1 0 0
1269 0 1 1 1 1 1 1 1 1 1 1 0
1270 0 1 1 1 1 1 1 1 1 1 1 0
1271 0 1 1 1 1 1 1 1 1 1 1 0
1272 0 1 1 1 1 1 1 1 1 1 1 0
1273 0 0 1 1 1 1 1 1 1 1 0 0
1274 0 0 0 1 1 1 1 1 1 0 0 0
1275 0 0 0 0 1 1 1 1 0 0 0 0"
1276 "PBM data used for enabled breakpoint icon.")
1278 (defconst breakpoint-disabled-pbm-data
1290 0 0 0 1 0 1 0 1 0 0"
1291 "PBM data used for disabled breakpoint icon.")
1293 (defvar breakpoint-enabled-icon nil
1294 "Icon for enabled breakpoint in display margin.")
1296 (defvar breakpoint-disabled-icon nil
1297 "Icon for disabled breakpoint in display margin.")
1299 ;; Bitmap for breakpoint in fringe
1300 (and (display-images-p)
1301 (define-fringe-bitmap 'breakpoint
1302 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1304 (defface breakpoint-enabled
1308 "Face for enabled breakpoint icon in fringe."
1310 ;; Compatibility alias for old name.
1311 (put 'breakpoint-enabled-bitmap-face 'face-alias 'breakpoint-enabled)
1313 (defface breakpoint-disabled
1314 ;; We use different values of grey for different background types,
1315 ;; so that on low-color displays it will end up as something visible
1316 ;; if it has to be approximated.
1317 '((((background dark)) :foreground "grey60")
1318 (((background light)) :foreground "grey40"))
1319 "Face for disabled breakpoint icon in fringe."
1322 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1323 (defun gdb-info-breakpoints-custom ()
1324 (let ((flag) (bptno))
1325 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1326 (dolist (buffer (buffer-list))
1327 (with-current-buffer buffer
1328 (if (and (eq gud-minor-mode 'gdba)
1329 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1330 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1331 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1333 (goto-char (point-min))
1334 (while (< (point) (- (point-max) 1))
1336 (if (looking-at "[^\t].*?breakpoint")
1338 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1339 (setq bptno (match-string 1))
1340 (setq flag (char-after (match-beginning 2)))
1342 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1344 (let ((buffer-read-only nil))
1345 (add-text-properties (match-beginning 1) (match-end 1)
1346 '(face font-lock-function-name-face)))
1347 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1348 (let ((line (match-string 2)) (buffer-read-only nil)
1349 (file (match-string 1)))
1350 (add-text-properties (line-beginning-position)
1352 '(mouse-face highlight
1353 help-echo "mouse-2, RET: visit breakpoint"))
1354 (unless (file-exists-p file)
1355 (setq file (cdr (assoc bptno gdb-location-alist))))
1357 (not (string-equal file "File not found")))
1358 (with-current-buffer
1359 (find-file-noselect file 'nowarn)
1360 (set (make-local-variable 'gud-minor-mode)
1362 (set (make-local-variable 'tool-bar-map)
1364 ;; Only want one breakpoint icon at each
1367 (goto-line (string-to-number line))
1368 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1372 (match-string-no-properties 1) ":1\n")
1375 (list "info source\n"
1376 `(lambda () (gdb-get-location
1377 ,bptno ,line ,flag))))))))))
1379 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1381 (defun gdb-mouse-set-clear-breakpoint (event)
1382 "Set/clear breakpoint in left fringe/margin with mouse click."
1384 (mouse-minibuffer-check event)
1385 (let ((posn (event-end event)))
1386 (if (numberp (posn-point posn))
1387 (with-selected-window (posn-window posn)
1389 (goto-char (posn-point posn))
1390 (if (or (posn-object posn)
1391 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1394 (gud-break nil)))))))
1396 (defun gdb-mouse-toggle-breakpoint (event)
1397 "Enable/disable breakpoint in left fringe/margin with mouse click."
1399 (mouse-minibuffer-check event)
1400 (let ((posn (event-end event)))
1401 (if (numberp (posn-point posn))
1402 (with-selected-window (posn-window posn)
1404 (goto-char (posn-point posn))
1405 (if (posn-object posn)
1408 (let ((bptno (get-text-property
1409 0 'gdb-bptno (car (posn-string posn)))))
1411 (if (get-text-property
1412 0 'gdb-enabled (car (posn-string posn)))
1415 bptno "\n")) 'ignore))))))))
1417 (defun gdb-breakpoints-buffer-name ()
1418 (with-current-buffer gud-comint-buffer
1419 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1421 (defun gdb-display-breakpoints-buffer ()
1422 "Display status of user-settable breakpoints."
1425 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1427 (defun gdb-frame-breakpoints-buffer ()
1428 "Display status of user-settable breakpoints in a new frame."
1430 (let ((special-display-regexps (append special-display-regexps '(".*")))
1431 (special-display-frame-alist gdb-frame-parameters))
1432 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1434 (defvar gdb-breakpoints-mode-map
1435 (let ((map (make-sparse-keymap))
1436 (menu (make-sparse-keymap "Breakpoints")))
1437 (define-key menu [quit] '("Quit" . kill-this-buffer))
1438 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1439 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1440 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1441 (suppress-keymap map)
1442 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1443 (define-key map " " 'gdb-toggle-breakpoint)
1444 (define-key map "d" 'gdb-delete-breakpoint)
1445 (define-key map "q" 'kill-this-buffer)
1446 (define-key map "\r" 'gdb-goto-breakpoint)
1447 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1448 (define-key map [follow-link] 'mouse-face)
1451 (defun gdb-breakpoints-mode ()
1452 "Major mode for gdb breakpoints.
1454 \\{gdb-breakpoints-mode-map}"
1455 (kill-all-local-variables)
1456 (setq major-mode 'gdb-breakpoints-mode)
1457 (setq mode-name "Breakpoints")
1458 (use-local-map gdb-breakpoints-mode-map)
1459 (setq buffer-read-only t)
1460 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1461 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1462 'gdb-invalidate-breakpoints
1463 'gdbmi-invalidate-breakpoints))
1465 (defun gdb-toggle-breakpoint ()
1466 "Enable/disable breakpoint at current line."
1469 (beginning-of-line 1)
1470 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1471 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1473 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1476 (concat gdb-server-prefix
1477 (if (eq ?y (char-after (match-beginning 2)))
1480 (match-string 1) "\n") 'ignore))
1481 (error "Not recognized as break/watchpoint line"))))
1483 (defun gdb-delete-breakpoint ()
1484 "Delete the breakpoint at current line."
1486 (beginning-of-line 1)
1487 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1488 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1490 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1493 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1494 (error "Not recognized as break/watchpoint line")))
1496 (defun gdb-goto-breakpoint (&optional event)
1497 "Display the breakpoint location specified at current line."
1498 (interactive (list last-input-event))
1499 (if event (mouse-set-point event))
1501 (beginning-of-line 1)
1502 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1503 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1505 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1506 \\(\\S-+\\):\\([0-9]+\\)"))
1507 (let ((bptno (match-string 1))
1508 (file (match-string 2))
1509 (line (match-string 3)))
1510 (save-selected-window
1511 (let* ((buf (find-file-noselect
1512 (if (file-exists-p file) file
1513 (cdr (assoc bptno gdb-location-alist)))))
1514 (window (display-buffer buf)))
1515 (with-current-buffer buf
1516 (goto-line (string-to-number line))
1517 (set-window-point window (point))))))
1518 (error "Not recognized as break/watchpoint line"))))
1521 ;; Frames buffer. This displays a perpetually correct bactracktrace
1522 ;; (from the command `where').
1524 ;; Alas, if your stack is deep, it is costly.
1526 (gdb-set-buffer-rules 'gdb-stack-buffer
1527 'gdb-stack-buffer-name
1530 (def-gdb-auto-updated-buffer gdb-stack-buffer
1531 gdb-invalidate-frames
1533 gdb-info-frames-handler
1534 gdb-info-frames-custom)
1536 (defun gdb-info-frames-custom ()
1537 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1539 (let ((buffer-read-only nil)
1541 (goto-char (point-min))
1542 (while (< (point) (point-max))
1543 (setq bl (line-beginning-position)
1544 el (line-end-position))
1545 (add-text-properties bl el
1546 '(mouse-face highlight
1547 help-echo "mouse-2, RET: Select frame"))
1549 (when (looking-at "^#\\([0-9]+\\)")
1550 (if (equal (match-string 1) gdb-frame-number)
1551 (put-text-property bl el 'face '(:inverse-video t))
1552 (when (re-search-forward " in \\([^ ]+\\) (" el t)
1553 (put-text-property (match-beginning 1) (match-end 1)
1554 'face font-lock-function-name-face)
1555 (setq bl (match-end 0))
1556 (while (re-search-forward "<\\([^>]+\\)>" el t)
1557 (put-text-property (match-beginning 1) (match-end 1)
1558 'face font-lock-function-name-face))
1560 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1561 (put-text-property (match-beginning 1) (match-end 1)
1562 'face font-lock-variable-name-face))
1564 (forward-line 1))))))
1566 (defun gdb-stack-buffer-name ()
1567 (with-current-buffer gud-comint-buffer
1568 (concat "*stack frames of " (gdb-get-target-string) "*")))
1570 (defun gdb-display-stack-buffer ()
1571 "Display backtrace of current stack."
1574 (gdb-get-create-buffer 'gdb-stack-buffer)))
1576 (defun gdb-frame-stack-buffer ()
1577 "Display backtrace of current stack in a new frame."
1579 (let ((special-display-regexps (append special-display-regexps '(".*")))
1580 (special-display-frame-alist gdb-frame-parameters))
1581 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1583 (defvar gdb-frames-mode-map
1584 (let ((map (make-sparse-keymap)))
1585 (suppress-keymap map)
1586 (define-key map "q" 'kill-this-buffer)
1587 (define-key map "\r" 'gdb-frames-select)
1588 (define-key map [mouse-2] 'gdb-frames-select)
1589 (define-key map [follow-link] 'mouse-face)
1592 (defun gdb-frames-mode ()
1593 "Major mode for gdb frames.
1595 \\{gdb-frames-mode-map}"
1596 (kill-all-local-variables)
1597 (setq major-mode 'gdb-frames-mode)
1598 (setq mode-name "Frames")
1599 (setq buffer-read-only t)
1600 (use-local-map gdb-frames-mode-map)
1602 (run-mode-hooks 'gdb-frames-mode-hook)
1603 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1604 'gdb-invalidate-frames
1605 'gdbmi-invalidate-frames))
1607 (defun gdb-get-frame-number ()
1609 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1610 (n (or (and pos (match-string-no-properties 1)) "0")))
1613 (defun gdb-frames-select (&optional event)
1614 "Select the frame and display the relevant source."
1615 (interactive (list last-input-event))
1616 (if event (mouse-set-point event))
1618 (list (concat gdb-server-prefix "frame "
1619 (gdb-get-frame-number) "\n") 'ignore))
1620 (gud-display-frame))
1623 ;; Threads buffer. This displays a selectable thread list.
1625 (gdb-set-buffer-rules 'gdb-threads-buffer
1626 'gdb-threads-buffer-name
1629 (def-gdb-auto-updated-buffer gdb-threads-buffer
1630 gdb-invalidate-threads
1631 (concat gdb-server-prefix "info threads\n")
1632 gdb-info-threads-handler
1633 gdb-info-threads-custom)
1635 (defun gdb-info-threads-custom ()
1636 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1637 (let ((buffer-read-only nil))
1638 (goto-char (point-min))
1639 (while (< (point) (point-max))
1640 (add-text-properties (line-beginning-position) (line-end-position)
1641 '(mouse-face highlight
1642 help-echo "mouse-2, RET: select thread"))
1643 (forward-line 1)))))
1645 (defun gdb-threads-buffer-name ()
1646 (with-current-buffer gud-comint-buffer
1647 (concat "*threads of " (gdb-get-target-string) "*")))
1649 (defun gdb-display-threads-buffer ()
1650 "Display IDs of currently known threads."
1653 (gdb-get-create-buffer 'gdb-threads-buffer)))
1655 (defun gdb-frame-threads-buffer ()
1656 "Display IDs of currently known threads in a new frame."
1658 (let ((special-display-regexps (append special-display-regexps '(".*")))
1659 (special-display-frame-alist gdb-frame-parameters))
1660 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1662 (defvar gdb-threads-mode-map
1663 (let ((map (make-sparse-keymap)))
1664 (suppress-keymap map)
1665 (define-key map "q" 'kill-this-buffer)
1666 (define-key map "\r" 'gdb-threads-select)
1667 (define-key map [mouse-2] 'gdb-threads-select)
1670 (defvar gdb-threads-font-lock-keywords
1672 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1673 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1674 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1676 "Font lock keywords used in `gdb-threads-mode'.")
1678 (defun gdb-threads-mode ()
1679 "Major mode for gdb frames.
1681 \\{gdb-threads-mode-map}"
1682 (kill-all-local-variables)
1683 (setq major-mode 'gdb-threads-mode)
1684 (setq mode-name "Threads")
1685 (setq buffer-read-only t)
1686 (use-local-map gdb-threads-mode-map)
1687 (set (make-local-variable 'font-lock-defaults)
1688 '(gdb-threads-font-lock-keywords))
1689 (run-mode-hooks 'gdb-threads-mode-hook)
1690 'gdb-invalidate-threads)
1692 (defun gdb-get-thread-number ()
1694 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1695 (match-string-no-properties 1)))
1697 (defun gdb-threads-select (&optional event)
1698 "Select the thread and display the relevant source."
1699 (interactive (list last-input-event))
1700 (if event (mouse-set-point event))
1702 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1703 (gud-display-frame))
1706 ;; Registers buffer.
1708 (defcustom gdb-all-registers nil
1709 "Non-nil means include floating-point registers."
1714 (gdb-set-buffer-rules 'gdb-registers-buffer
1715 'gdb-registers-buffer-name
1716 'gdb-registers-mode)
1718 (def-gdb-auto-updated-buffer gdb-registers-buffer
1719 gdb-invalidate-registers
1721 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1722 gdb-info-registers-handler
1723 gdb-info-registers-custom)
1725 (defun gdb-info-registers-custom ())
1727 (defvar gdb-registers-mode-map
1728 (let ((map (make-sparse-keymap)))
1729 (suppress-keymap map)
1730 (define-key map " " 'toggle-gdb-all-registers)
1731 (define-key map "q" 'kill-this-buffer)
1734 (defvar gdb-registers-font-lock-keywords
1736 ("^[^ ]+" . font-lock-variable-name-face)
1738 "Font lock keywords used in `gdb-registers-mode'.")
1740 (defun gdb-registers-mode ()
1741 "Major mode for gdb registers.
1743 \\{gdb-registers-mode-map}"
1744 (kill-all-local-variables)
1745 (setq major-mode 'gdb-registers-mode)
1746 (setq mode-name "Registers:")
1747 (setq buffer-read-only t)
1748 (use-local-map gdb-registers-mode-map)
1749 (set (make-local-variable 'font-lock-defaults)
1750 '(gdb-registers-font-lock-keywords))
1751 (run-mode-hooks 'gdb-registers-mode-hook)
1752 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1753 'gdb-invalidate-registers
1754 'gdbmi-invalidate-registers))
1756 (defun gdb-registers-buffer-name ()
1757 (with-current-buffer gud-comint-buffer
1758 (concat "*registers of " (gdb-get-target-string) "*")))
1760 (defun gdb-display-registers-buffer ()
1761 "Display integer register contents."
1764 (gdb-get-create-buffer 'gdb-registers-buffer)))
1766 (defun gdb-frame-registers-buffer ()
1767 "Display integer register contents in a new frame."
1769 (let ((special-display-regexps (append special-display-regexps '(".*")))
1770 (special-display-frame-alist gdb-frame-parameters))
1771 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1773 (defun toggle-gdb-all-registers ()
1774 "Toggle the display of floating-point registers."
1776 (if gdb-all-registers
1778 (setq gdb-all-registers nil)
1779 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1780 (setq mode-name "Registers:")))
1781 (setq gdb-all-registers t)
1782 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1783 (setq mode-name "Registers:All")))
1784 (gdb-invalidate-registers))
1789 (defcustom gdb-memory-repeat-count 32
1790 "Number of data items in memory window."
1795 (defcustom gdb-memory-format "x"
1796 "Display format of data items in memory window."
1797 :type '(choice (const :tag "Hexadecimal" "x")
1798 (const :tag "Signed decimal" "d")
1799 (const :tag "Unsigned decimal" "u")
1800 (const :tag "Octal" "o")
1801 (const :tag "Binary" "t"))
1805 (defcustom gdb-memory-unit "w"
1806 "Unit size of data items in memory window."
1807 :type '(choice (const :tag "Byte" "b")
1808 (const :tag "Halfword" "h")
1809 (const :tag "Word" "w")
1810 (const :tag "Giant word" "g"))
1814 (gdb-set-buffer-rules 'gdb-memory-buffer
1815 'gdb-memory-buffer-name
1818 (def-gdb-auto-updated-buffer gdb-memory-buffer
1819 gdb-invalidate-memory
1820 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1821 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1822 gdb-read-memory-handler
1823 gdb-read-memory-custom)
1825 (defun gdb-read-memory-custom ()
1827 (goto-char (point-min))
1828 (if (looking-at "0x[[:xdigit:]]+")
1829 (setq gdb-memory-address (match-string 0)))))
1831 (defvar gdb-memory-mode-map
1832 (let ((map (make-sparse-keymap)))
1833 (suppress-keymap map)
1834 (define-key map "q" 'kill-this-buffer)
1837 (defun gdb-memory-set-address (event)
1838 "Set the start memory address."
1840 (save-selected-window
1841 (select-window (posn-window (event-start event)))
1842 (let ((arg (read-from-minibuffer "Memory address: ")))
1843 (setq gdb-memory-address arg))
1844 (gdb-invalidate-memory)))
1846 (defun gdb-memory-set-repeat-count (event)
1847 "Set the number of data items in memory window."
1849 (save-selected-window
1850 (select-window (posn-window (event-start event)))
1851 (let* ((arg (read-from-minibuffer "Repeat count: "))
1852 (count (string-to-number arg)))
1854 (error "Positive numbers only")
1855 (customize-set-variable 'gdb-memory-repeat-count count)
1856 (gdb-invalidate-memory)))))
1858 (defun gdb-memory-format-binary ()
1859 "Set the display format to binary."
1861 (customize-set-variable 'gdb-memory-format "t")
1862 (gdb-invalidate-memory))
1864 (defun gdb-memory-format-octal ()
1865 "Set the display format to octal."
1867 (customize-set-variable 'gdb-memory-format "o")
1868 (gdb-invalidate-memory))
1870 (defun gdb-memory-format-unsigned ()
1871 "Set the display format to unsigned decimal."
1873 (customize-set-variable 'gdb-memory-format "u")
1874 (gdb-invalidate-memory))
1876 (defun gdb-memory-format-signed ()
1877 "Set the display format to decimal."
1879 (customize-set-variable 'gdb-memory-format "d")
1880 (gdb-invalidate-memory))
1882 (defun gdb-memory-format-hexadecimal ()
1883 "Set the display format to hexadecimal."
1885 (customize-set-variable 'gdb-memory-format "x")
1886 (gdb-invalidate-memory))
1888 (defvar gdb-memory-format-keymap
1889 (let ((map (make-sparse-keymap)))
1890 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1892 "Keymap to select format in the header line.")
1894 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1895 "Menu of display formats in the header line.")
1897 (define-key gdb-memory-format-menu [binary]
1898 '(menu-item "Binary" gdb-memory-format-binary
1899 :button (:radio . (equal gdb-memory-format "t"))))
1900 (define-key gdb-memory-format-menu [octal]
1901 '(menu-item "Octal" gdb-memory-format-octal
1902 :button (:radio . (equal gdb-memory-format "o"))))
1903 (define-key gdb-memory-format-menu [unsigned]
1904 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
1905 :button (:radio . (equal gdb-memory-format "u"))))
1906 (define-key gdb-memory-format-menu [signed]
1907 '(menu-item "Signed Decimal" gdb-memory-format-signed
1908 :button (:radio . (equal gdb-memory-format "d"))))
1909 (define-key gdb-memory-format-menu [hexadecimal]
1910 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
1911 :button (:radio . (equal gdb-memory-format "x"))))
1913 (defun gdb-memory-format-menu (event)
1915 (x-popup-menu event gdb-memory-format-menu))
1917 (defun gdb-memory-format-menu-1 (event)
1919 (save-selected-window
1920 (select-window (posn-window (event-start event)))
1921 (let* ((selection (gdb-memory-format-menu event))
1922 (binding (and selection (lookup-key gdb-memory-format-menu
1923 (vector (car selection))))))
1924 (if binding (call-interactively binding)))))
1926 (defun gdb-memory-unit-giant ()
1927 "Set the unit size to giant words (eight bytes)."
1929 (customize-set-variable 'gdb-memory-unit "g")
1930 (gdb-invalidate-memory))
1932 (defun gdb-memory-unit-word ()
1933 "Set the unit size to words (four bytes)."
1935 (customize-set-variable 'gdb-memory-unit "w")
1936 (gdb-invalidate-memory))
1938 (defun gdb-memory-unit-halfword ()
1939 "Set the unit size to halfwords (two bytes)."
1941 (customize-set-variable 'gdb-memory-unit "h")
1942 (gdb-invalidate-memory))
1944 (defun gdb-memory-unit-byte ()
1945 "Set the unit size to bytes."
1947 (customize-set-variable 'gdb-memory-unit "b")
1948 (gdb-invalidate-memory))
1950 (defvar gdb-memory-unit-keymap
1951 (let ((map (make-sparse-keymap)))
1952 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
1954 "Keymap to select units in the header line.")
1956 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
1957 "Menu of units in the header line.")
1959 (define-key gdb-memory-unit-menu [giantwords]
1960 '(menu-item "Giant words" gdb-memory-unit-giant
1961 :button (:radio . (equal gdb-memory-unit "g"))))
1962 (define-key gdb-memory-unit-menu [words]
1963 '(menu-item "Words" gdb-memory-unit-word
1964 :button (:radio . (equal gdb-memory-unit "w"))))
1965 (define-key gdb-memory-unit-menu [halfwords]
1966 '(menu-item "Halfwords" gdb-memory-unit-halfword
1967 :button (:radio . (equal gdb-memory-unit "h"))))
1968 (define-key gdb-memory-unit-menu [bytes]
1969 '(menu-item "Bytes" gdb-memory-unit-byte
1970 :button (:radio . (equal gdb-memory-unit "b"))))
1972 (defun gdb-memory-unit-menu (event)
1974 (x-popup-menu event gdb-memory-unit-menu))
1976 (defun gdb-memory-unit-menu-1 (event)
1978 (save-selected-window
1979 (select-window (posn-window (event-start event)))
1980 (let* ((selection (gdb-memory-unit-menu event))
1981 (binding (and selection (lookup-key gdb-memory-unit-menu
1982 (vector (car selection))))))
1983 (if binding (call-interactively binding)))))
1985 ;;from make-mode-line-mouse-map
1986 (defun gdb-make-header-line-mouse-map (mouse function) "\
1987 Return a keymap with single entry for mouse key MOUSE on the header line.
1988 MOUSE is defined to run function FUNCTION with no args in the buffer
1989 corresponding to the mode line clicked."
1990 (let ((map (make-sparse-keymap)))
1991 (define-key map (vector 'header-line mouse) function)
1992 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
1995 (defvar gdb-memory-font-lock-keywords
1996 '(;; <__function.name+n>
1997 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
1999 "Font lock keywords used in `gdb-memory-mode'.")
2001 (defun gdb-memory-mode ()
2002 "Major mode for examining memory.
2004 \\{gdb-memory-mode-map}"
2005 (kill-all-local-variables)
2006 (setq major-mode 'gdb-memory-mode)
2007 (setq mode-name "Memory")
2008 (setq buffer-read-only t)
2009 (use-local-map gdb-memory-mode-map)
2010 (setq header-line-format
2016 'face font-lock-warning-face
2017 'help-echo "mouse-1: Decrement address"
2018 'mouse-face 'mode-line-highlight
2020 (gdb-make-header-line-mouse-map
2022 #'(lambda () (interactive)
2023 (let ((gdb-memory-address
2024 ;; Let GDB do the arithmetic.
2026 gdb-memory-address " - "
2028 (* gdb-memory-repeat-count
2029 (cond ((string= gdb-memory-unit "b") 1)
2030 ((string= gdb-memory-unit "h") 2)
2031 ((string= gdb-memory-unit "w") 4)
2032 ((string= gdb-memory-unit "g") 8)))))))
2033 (gdb-invalidate-memory)))))
2036 'face font-lock-warning-face
2037 'help-echo "mouse-1: Increment address"
2038 'mouse-face 'mode-line-highlight
2039 'local-map (gdb-make-header-line-mouse-map
2041 #'(lambda () (interactive)
2042 (let ((gdb-memory-address nil))
2043 (gdb-invalidate-memory)))))
2045 (propertize gdb-memory-address
2046 'face font-lock-warning-face
2047 'help-echo "mouse-1: Set memory address"
2048 'mouse-face 'mode-line-highlight
2049 'local-map (gdb-make-header-line-mouse-map
2051 #'gdb-memory-set-address))
2053 (propertize (number-to-string gdb-memory-repeat-count)
2054 'face font-lock-warning-face
2055 'help-echo "mouse-1: Set repeat count"
2056 'mouse-face 'mode-line-highlight
2057 'local-map (gdb-make-header-line-mouse-map
2059 #'gdb-memory-set-repeat-count))
2061 (propertize gdb-memory-format
2062 'face font-lock-warning-face
2063 'help-echo "mouse-3: Select display format"
2064 'mouse-face 'mode-line-highlight
2065 'local-map gdb-memory-format-keymap)
2067 (propertize gdb-memory-unit
2068 'face font-lock-warning-face
2069 'help-echo "mouse-3: Select unit size"
2070 'mouse-face 'mode-line-highlight
2071 'local-map gdb-memory-unit-keymap))))
2072 (set (make-local-variable 'font-lock-defaults)
2073 '(gdb-memory-font-lock-keywords))
2074 (run-mode-hooks 'gdb-memory-mode-hook)
2075 'gdb-invalidate-memory)
2077 (defun gdb-memory-buffer-name ()
2078 (with-current-buffer gud-comint-buffer
2079 (concat "*memory of " (gdb-get-target-string) "*")))
2081 (defun gdb-display-memory-buffer ()
2082 "Display memory contents."
2085 (gdb-get-create-buffer 'gdb-memory-buffer)))
2087 (defun gdb-frame-memory-buffer ()
2088 "Display memory contents in a new frame."
2090 (let ((special-display-regexps (append special-display-regexps '(".*")))
2091 (special-display-frame-alist gdb-frame-parameters))
2092 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2097 (gdb-set-buffer-rules 'gdb-locals-buffer
2098 'gdb-locals-buffer-name
2101 (def-gdb-auto-updated-buffer gdb-locals-buffer
2102 gdb-invalidate-locals
2103 "server info locals\n"
2104 gdb-info-locals-handler
2105 gdb-info-locals-custom)
2107 ;; Abbreviate for arrays and structures.
2108 ;; These can be expanded using gud-display.
2109 (defun gdb-info-locals-handler nil
2110 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2111 gdb-pending-triggers))
2112 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2113 (with-current-buffer buf
2114 (goto-char (point-min))
2115 (while (re-search-forward "^[ }].*\n" nil t)
2116 (replace-match "" nil nil))
2117 (goto-char (point-min))
2118 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2119 (replace-match "(structure);\n" nil nil))
2120 (goto-char (point-min))
2121 (while (re-search-forward "\\s-*{.*\n" nil t)
2122 (replace-match " (array);\n" nil nil))))
2123 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2124 (and buf (with-current-buffer buf
2125 (let ((p (window-point (get-buffer-window buf 0)))
2126 (buffer-read-only nil))
2128 (insert-buffer-substring (gdb-get-create-buffer
2129 'gdb-partial-output-buffer))
2130 (set-window-point (get-buffer-window buf 0) p)))))
2131 (run-hooks 'gdb-info-locals-hook))
2133 (defun gdb-info-locals-custom ()
2136 (defvar gdb-locals-mode-map
2137 (let ((map (make-sparse-keymap)))
2138 (suppress-keymap map)
2139 (define-key map "q" 'kill-this-buffer)
2142 (defvar gdb-local-font-lock-keywords
2144 ;; var = (struct struct_tag) value
2145 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2146 (1 font-lock-variable-name-face)
2147 (3 font-lock-keyword-face)
2148 (4 font-lock-type-face))
2149 ;; var = (type) value
2150 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2151 (1 font-lock-variable-name-face)
2152 (3 font-lock-type-face))
2154 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2155 (1 font-lock-variable-name-face))
2157 "Font lock keywords used in `gdb-local-mode'.")
2159 (defun gdb-locals-mode ()
2160 "Major mode for gdb locals.
2162 \\{gdb-locals-mode-map}"
2163 (kill-all-local-variables)
2164 (setq major-mode 'gdb-locals-mode)
2165 (setq mode-name (concat "Locals:" gdb-selected-frame))
2166 (setq buffer-read-only t)
2167 (use-local-map gdb-locals-mode-map)
2168 (set (make-local-variable 'font-lock-defaults)
2169 '(gdb-local-font-lock-keywords))
2170 (run-mode-hooks 'gdb-locals-mode-hook)
2171 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
2172 'gdb-invalidate-locals
2173 'gdbmi-invalidate-locals))
2175 (defun gdb-locals-buffer-name ()
2176 (with-current-buffer gud-comint-buffer
2177 (concat "*locals of " (gdb-get-target-string) "*")))
2179 (defun gdb-display-locals-buffer ()
2180 "Display local variables of current stack and their values."
2183 (gdb-get-create-buffer 'gdb-locals-buffer)))
2185 (defun gdb-frame-locals-buffer ()
2186 "Display local variables of current stack and their values in a new frame."
2188 (let ((special-display-regexps (append special-display-regexps '(".*")))
2189 (special-display-frame-alist gdb-frame-parameters))
2190 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2193 ;;;; Window management
2194 (defun gdb-display-buffer (buf &optional size)
2195 (let ((answer (get-buffer-window buf 0))
2198 (display-buffer buf nil 0) ;Raise the frame if necessary.
2199 ;; The buffer is not yet displayed.
2200 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2201 (let ((window (get-lru-window)))
2203 (not (eq window (get-buffer-window gud-comint-buffer))))
2205 (set-window-buffer window buf)
2206 (setq answer window))
2207 (setq must-split t)))
2209 (let* ((largest (get-largest-window))
2210 (cur-size (window-height largest))
2211 (new-size (and size (< size cur-size) (- cur-size size))))
2212 (setq answer (split-window largest new-size))
2213 (set-window-buffer answer buf)
2214 (set-window-dedicated-p answer t)))
2218 ;;; Shared keymap initialization:
2220 (let ((menu (make-sparse-keymap "GDB-Windows")))
2221 (define-key gud-menu-map [displays]
2222 `(menu-item "GDB-Windows" ,menu
2223 :visible (memq gud-minor-mode '(gdbmi gdba))))
2224 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2225 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2226 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2227 (define-key menu [disassembly]
2228 '("Disassembly" . gdb-display-assembler-buffer))
2229 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2230 (define-key menu [inferior]
2231 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2232 :enable gdb-use-inferior-io-buffer))
2233 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2234 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2235 (define-key menu [breakpoints]
2236 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2238 (let ((menu (make-sparse-keymap "GDB-Frames")))
2239 (define-key gud-menu-map [frames]
2240 `(menu-item "GDB-Frames" ,menu
2241 :visible (memq gud-minor-mode '(gdbmi gdba))))
2242 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2243 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2244 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2245 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2246 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2247 (define-key menu [inferior]
2248 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2249 :enable gdb-use-inferior-io-buffer))
2250 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2251 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2252 (define-key menu [breakpoints]
2253 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2255 (let ((menu (make-sparse-keymap "GDB-UI")))
2256 (define-key gud-menu-map [ui]
2257 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2258 (define-key menu [gdb-use-inferior-io]
2259 ;; See defadvice below.
2260 (menu-bar-make-toggle toggle-gdb-use-inferior-io-buffer
2261 gdb-use-inferior-io-buffer
2262 "Separate inferior IO" "Use separate IO %s"
2263 "Toggle separate IO for inferior."))
2264 (define-key menu [gdb-many-windows]
2265 '(menu-item "Display Other Windows" gdb-many-windows
2266 :help "Toggle display of locals, stack and breakpoint information"
2267 :button (:toggle . gdb-many-windows)))
2268 (define-key menu [gdb-restore-windows]
2269 '(menu-item "Restore Window Layout" gdb-restore-windows
2270 :help "Restore standard layout for debug session.")))
2272 ;; This function is defined above through a macro.
2273 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
2274 (unless gdb-use-inferior-io-buffer
2275 (kill-buffer (gdb-inferior-io-name))))
2277 (defun gdb-frame-gdb-buffer ()
2278 "Display GUD buffer in a new frame."
2280 (select-frame (make-frame gdb-frame-parameters))
2281 (switch-to-buffer (gdb-get-create-buffer 'gdba))
2282 (set-window-dedicated-p (selected-window) t))
2284 (defun gdb-display-gdb-buffer ()
2285 "Display GUD buffer."
2288 (gdb-get-create-buffer 'gdba)))
2290 (defun gdb-set-window-buffer (name)
2291 (set-window-buffer (selected-window) (get-buffer name))
2292 (set-window-dedicated-p (selected-window) t))
2294 (defun gdb-setup-windows ()
2295 "Layout the window pattern for `gdb-many-windows'."
2296 (gdb-display-locals-buffer)
2297 (gdb-display-stack-buffer)
2298 (delete-other-windows)
2299 (gdb-display-breakpoints-buffer)
2300 (delete-other-windows)
2302 (pop-to-buffer gud-comint-buffer)
2303 (split-window nil ( / ( * (window-height) 3) 4))
2304 (split-window nil ( / (window-height) 3))
2305 (split-window-horizontally)
2307 (gdb-set-window-buffer (gdb-locals-buffer-name))
2310 (if gud-last-last-frame
2311 (gud-find-file (car gud-last-last-frame))
2312 (gud-find-file gdb-main-file)))
2313 (when gdb-use-inferior-io-buffer
2314 (split-window-horizontally)
2316 (gdb-set-window-buffer
2317 (gdb-get-create-buffer 'gdb-inferior-io)))
2319 (gdb-set-window-buffer (gdb-stack-buffer-name))
2320 (split-window-horizontally)
2322 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2325 (defcustom gdb-many-windows nil
2326 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2327 In this case it starts with two windows: one displaying the GUD
2328 buffer and the other with the source file with the main routine
2329 of the inferior. Non-nil means display the layout shown for
2335 (defun gdb-many-windows (arg)
2336 "Toggle the number of windows in the basic arrangement."
2338 (setq gdb-many-windows
2340 (not gdb-many-windows)
2341 (> (prefix-numeric-value arg) 0)))
2343 (gdb-restore-windows)
2346 (defun gdb-restore-windows ()
2347 "Restore the basic arrangement of windows used by gdba.
2348 This arrangement depends on the value of `gdb-many-windows'."
2350 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2351 (delete-other-windows)
2352 (if gdb-many-windows
2357 (if gud-last-last-frame
2358 (gud-find-file (car gud-last-last-frame))
2359 (gud-find-file gdb-main-file)))
2363 "Exit a debugging session cleanly.
2364 Kills the gdb buffers and resets the source buffers."
2365 (dolist (buffer (buffer-list))
2366 (unless (eq buffer gud-comint-buffer)
2367 (with-current-buffer buffer
2368 (if (memq gud-minor-mode '(gdbmi gdba))
2369 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2371 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2372 (setq gud-minor-mode nil)
2373 (kill-local-variable 'tool-bar-map)
2374 (kill-local-variable 'gdb-define-alist))))))
2375 (when (markerp gdb-overlay-arrow-position)
2376 (move-marker gdb-overlay-arrow-position nil)
2377 (setq gdb-overlay-arrow-position nil))
2378 (setq overlay-arrow-variable-list
2379 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2380 (setq gud-running nil)
2381 (setq gdb-active-process nil)
2382 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2384 (defun gdb-source-info ()
2385 "Find the source file where the program starts and displays it with related
2387 (goto-char (point-min))
2388 (if (and (search-forward "Located in " nil t)
2389 (looking-at "\\S-+"))
2390 (setq gdb-main-file (match-string 0)))
2391 (goto-char (point-min))
2392 (if (search-forward "Includes preprocessor macro info." nil t)
2393 (setq gdb-macro-info t))
2394 (if gdb-many-windows
2396 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2398 (let ((pop-up-windows t))
2399 (display-buffer (gud-find-file gdb-main-file))))))
2401 (defun gdb-get-location (bptno line flag)
2402 "Find the directory containing the relevant source file.
2403 Put in buffer and place breakpoint icon."
2404 (goto-char (point-min))
2405 (catch 'file-not-found
2406 (if (search-forward "Located in " nil t)
2407 (when (looking-at "\\S-+")
2408 (delete (cons bptno "File not found") gdb-location-alist)
2409 (push (cons bptno (match-string 0)) gdb-location-alist))
2411 (unless (assoc bptno gdb-location-alist)
2412 (push (cons bptno "File not found") gdb-location-alist)
2413 (message-box "Cannot find source file for breakpoint location.\n\
2414 Add directory to search path for source files using the GDB command, dir."))
2415 (throw 'file-not-found nil))
2416 (with-current-buffer
2417 (find-file-noselect (match-string 0))
2418 (save-current-buffer
2419 (set (make-local-variable 'gud-minor-mode) 'gdba)
2420 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2421 ;; only want one breakpoint icon at each location
2423 (goto-line (string-to-number line))
2424 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2426 (add-hook 'find-file-hook 'gdb-find-file-hook)
2428 (defun gdb-find-file-hook ()
2429 "Set up buffer for debugging if file is part of the source code
2430 of the current session."
2431 (if (and (not gdb-find-file-unhook)
2432 ;; in case gud or gdb-ui is just loaded
2434 (buffer-name gud-comint-buffer)
2435 (with-current-buffer gud-comint-buffer
2436 (eq gud-minor-mode 'gdba)))
2439 (list (concat gdb-server-prefix "list "
2440 (file-name-nondirectory buffer-file-name)
2442 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2443 (error (setq gdb-find-file-unhook t)))))
2446 (defun gdb-put-string (putstring pos &optional dprop)
2447 "Put string PUTSTRING in front of POS in the current buffer.
2448 PUTSTRING is displayed by putting an overlay into the current buffer with a
2449 `before-string' string that has a `display' property whose value is
2451 (let ((string (make-string 1 ?x))
2452 (buffer (current-buffer)))
2453 (setq putstring (copy-sequence putstring))
2454 (let ((overlay (make-overlay pos pos buffer))
2456 (list (list 'margin 'left-margin) putstring))))
2457 (put-text-property 0 (length string) 'display prop string)
2458 (overlay-put overlay 'put-break t)
2459 (overlay-put overlay 'before-string string))))
2461 ;;from remove-images
2462 (defun gdb-remove-strings (start end &optional buffer)
2463 "Remove strings between START and END in BUFFER.
2464 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2465 BUFFER nil or omitted means use the current buffer."
2467 (setq buffer (current-buffer)))
2468 (dolist (overlay (overlays-in start end))
2469 (when (overlay-get overlay 'put-break)
2470 (delete-overlay overlay))))
2472 (defun gdb-put-breakpoint-icon (enabled bptno)
2473 (let ((start (- (line-beginning-position) 1))
2474 (end (+ (line-end-position) 1))
2475 (putstring (if enabled "B" "b"))
2476 (source-window (get-buffer-window (current-buffer) 0)))
2477 (add-text-properties
2478 0 1 '(help-echo "mouse-1: set/clear bkpt, mouse-3: enable/disable bkpt")
2480 (if enabled (add-text-properties
2481 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2482 (add-text-properties
2483 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2484 (gdb-remove-breakpoint-icons start end)
2485 (if (display-images-p)
2486 (if (>= (or left-fringe-width
2487 (if source-window (car (window-fringes source-window)))
2488 gdb-buffer-fringe-width) 8)
2491 `(left-fringe breakpoint
2494 'breakpoint-disabled)))
2495 (when (< left-margin-width 2)
2496 (save-current-buffer
2497 (setq left-margin-width 2)
2501 left-margin-width right-margin-width))))
2504 (or breakpoint-enabled-icon
2505 (setq breakpoint-enabled-icon
2506 (find-image `((:type xpm :data
2507 ,breakpoint-xpm-data
2508 :ascent 100 :pointer hand)
2510 ,breakpoint-enabled-pbm-data
2511 :ascent 100 :pointer hand)))))
2512 (or breakpoint-disabled-icon
2513 (setq breakpoint-disabled-icon
2514 (find-image `((:type xpm :data
2515 ,breakpoint-xpm-data
2516 :conversion disabled
2519 ,breakpoint-disabled-pbm-data
2524 (when (< left-margin-width 2)
2525 (save-current-buffer
2526 (setq left-margin-width 2)
2527 (if (get-buffer-window (current-buffer) 0)
2529 (get-buffer-window (current-buffer) 0)
2530 left-margin-width right-margin-width))))
2532 (propertize putstring
2533 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2536 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2537 (gdb-remove-strings start end)
2538 (if (display-images-p)
2539 (remove-images start end))
2541 (setq left-margin-width 0)
2542 (if (get-buffer-window (current-buffer) 0)
2544 (get-buffer-window (current-buffer) 0)
2545 left-margin-width right-margin-width))))
2549 ;; Assembler buffer.
2551 (gdb-set-buffer-rules 'gdb-assembler-buffer
2552 'gdb-assembler-buffer-name
2553 'gdb-assembler-mode)
2555 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2556 gdb-invalidate-assembler
2557 (concat gdb-server-prefix "disassemble "
2558 (if (member gdb-frame-address '(nil "main")) nil "0x")
2559 gdb-frame-address "\n")
2560 gdb-assembler-handler
2561 gdb-assembler-custom)
2563 (defun gdb-assembler-custom ()
2564 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2565 (pos 1) (address) (flag) (bptno))
2566 (with-current-buffer buffer
2568 (if (not (equal gdb-frame-address "main"))
2570 (goto-char (point-min))
2571 (if (and gdb-frame-address
2572 (re-search-forward gdb-frame-address nil t))
2576 (or gdb-overlay-arrow-position
2577 (setq gdb-overlay-arrow-position (make-marker)))
2578 (set-marker gdb-overlay-arrow-position
2579 (point) (current-buffer))))))
2580 ;; remove all breakpoint-icons in assembler buffer before updating.
2581 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2582 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2583 (goto-char (point-min))
2584 (while (< (point) (- (point-max) 1))
2586 (if (looking-at "[^\t].*?breakpoint")
2589 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2590 (setq bptno (match-string 1))
2591 (setq flag (char-after (match-beginning 2)))
2592 (setq address (match-string 3))
2593 (with-current-buffer buffer
2595 (goto-char (point-min))
2596 (if (re-search-forward address nil t)
2597 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2598 (if (not (equal gdb-frame-address "main"))
2599 (set-window-point (get-buffer-window buffer 0) pos))))
2601 (defvar gdb-assembler-mode-map
2602 (let ((map (make-sparse-keymap)))
2603 (suppress-keymap map)
2604 (define-key map "q" 'kill-this-buffer)
2607 (defvar gdb-assembler-font-lock-keywords
2608 '(;; <__function.name+n>
2609 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2610 (1 font-lock-function-name-face))
2611 ;; 0xNNNNNNNN <__function.name+n>: opcode
2612 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2613 (4 font-lock-keyword-face))
2614 ;; %register(at least i386)
2615 ("%\\sw+" . font-lock-variable-name-face)
2616 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2617 (1 font-lock-comment-face)
2618 (2 font-lock-function-name-face))
2619 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2620 "Font lock keywords used in `gdb-assembler-mode'.")
2622 (defun gdb-assembler-mode ()
2623 "Major mode for viewing code assembler.
2625 \\{gdb-assembler-mode-map}"
2626 (kill-all-local-variables)
2627 (setq major-mode 'gdb-assembler-mode)
2628 (setq mode-name (concat "Machine:" gdb-selected-frame))
2629 (setq gdb-overlay-arrow-position nil)
2630 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2631 (setq fringes-outside-margins t)
2632 (setq buffer-read-only t)
2633 (use-local-map gdb-assembler-mode-map)
2634 (gdb-invalidate-assembler)
2635 (set (make-local-variable 'font-lock-defaults)
2636 '(gdb-assembler-font-lock-keywords))
2637 (run-mode-hooks 'gdb-assembler-mode-hook)
2638 'gdb-invalidate-assembler)
2640 (defun gdb-assembler-buffer-name ()
2641 (with-current-buffer gud-comint-buffer
2642 (concat "*Disassembly of " (gdb-get-target-string) "*")))
2644 (defun gdb-display-assembler-buffer ()
2645 "Display disassembly view."
2647 (setq gdb-previous-frame nil)
2649 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2651 (defun gdb-frame-assembler-buffer ()
2652 "Display disassembly view in a new frame."
2654 (setq gdb-previous-frame nil)
2655 (let ((special-display-regexps (append special-display-regexps '(".*")))
2656 (special-display-frame-alist gdb-frame-parameters))
2657 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2659 ;; modified because if gdb-frame-address has changed value a new command
2660 ;; must be enqueued to update the buffer with the new output
2661 (defun gdb-invalidate-assembler (&optional ignored)
2662 (if (gdb-get-buffer 'gdb-assembler-buffer)
2664 (unless (and gdb-selected-frame
2665 (string-equal gdb-selected-frame gdb-previous-frame))
2666 (if (or (not (member 'gdb-invalidate-assembler
2667 gdb-pending-triggers))
2668 (not (string-equal gdb-frame-address
2669 gdb-previous-frame-address)))
2671 ;; take previous disassemble command, if any, off the queue
2672 (with-current-buffer gud-comint-buffer
2673 (let ((queue gdb-input-queue))
2674 (dolist (item queue)
2675 (if (equal (cdr item) '(gdb-assembler-handler))
2676 (setq gdb-input-queue
2677 (delete item gdb-input-queue))))))
2680 (concat gdb-server-prefix "disassemble "
2681 (if (member gdb-frame-address '(nil "main")) nil "0x")
2682 gdb-frame-address "\n")
2683 'gdb-assembler-handler))
2684 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2685 (setq gdb-previous-frame-address gdb-frame-address)
2686 (setq gdb-previous-frame gdb-selected-frame)))))))
2688 (defun gdb-get-selected-frame ()
2689 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2692 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2693 (push 'gdb-get-selected-frame
2694 gdb-pending-triggers))))
2696 (defun gdb-frame-handler ()
2697 (setq gdb-pending-triggers
2698 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2699 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2700 (goto-char (point-min))
2701 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2702 (setq gdb-frame-number (match-string 1)))
2703 (goto-char (point-min))
2704 (if (re-search-forward
2705 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2707 (setq gdb-selected-frame (match-string 2))
2708 (if (gdb-get-buffer 'gdb-locals-buffer)
2709 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2710 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2711 (if (gdb-get-buffer 'gdb-assembler-buffer)
2712 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2713 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2714 (setq gdb-frame-address (match-string 1))))
2715 (goto-char (point-min))
2716 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2717 (setq gdb-current-language (match-string 1))))
2718 (gdb-invalidate-assembler))
2722 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2723 ;;; gdb-ui.el ends here