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.
82 (defvar gdb-buffer-fringe-width)
85 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
86 (defvar gdb-previous-frame-address nil)
87 (defvar gdb-memory-address "main")
88 (defvar gdb-previous-frame nil)
89 (defvar gdb-selected-frame nil)
90 (defvar gdb-frame-number nil)
91 (defvar gdb-current-language nil)
92 (defvar gdb-var-list nil "List of variables in watch window.")
93 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
94 (defvar gdb-main-file nil "Source file from which program execution begins.")
95 (defvar gdb-buffer-type nil)
96 (defvar gdb-overlay-arrow-position nil)
97 (defvar gdb-server-prefix nil)
98 (defvar gdb-flush-pending-output nil)
99 (defvar gdb-location-alist nil
100 "Alist of breakpoint numbers and full filenames.")
101 (defvar gdb-find-file-unhook nil)
102 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
103 and #define directives otherwise.")
104 (defvar gdb-error "Non-nil when GDB is reporting an error.")
105 (defvar gdb-macro-info nil
106 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
107 (defvar gdb-fringe-width nil)
109 (defvar gdb-buffer-type nil
110 "One of the symbols bound in `gdb-buffer-rules'.")
112 (defvar gdb-input-queue ()
113 "A list of gdb command objects.")
115 (defvar gdb-prompting nil
116 "True when gdb is idle with no pending input.")
118 (defvar gdb-output-sink 'user
119 "The disposition of the output of the current gdb command.
120 Possible values are these symbols:
122 `user' -- gdb output should be copied to the GUD buffer
125 `inferior' -- gdb output should be copied to the inferior-io buffer.
127 `pre-emacs' -- output should be ignored util the post-prompt
128 annotation is received. Then the output-sink
130 `emacs' -- output should be collected in the partial-output-buffer
131 for subsequent processing by a command. This is the
132 disposition of output generated by commands that
133 gdb mode sends to gdb on its own behalf.
134 `post-emacs' -- ignore output until the prompt annotation is
135 received, then go to USER disposition.
137 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
138 \(`user' and `emacs').")
140 (defvar gdb-current-item nil
141 "The most recent command item sent to gdb.")
143 (defvar gdb-pending-triggers '()
144 "A list of trigger functions that have run later than their output
147 ;; end of gdb variables
150 (defun gdba (command-line)
151 "Run gdb on program FILE in buffer *gud-FILE*.
152 The directory containing FILE becomes the initial working directory
153 and source-file directory for your debugger.
155 If `gdb-many-windows' is nil (the default value) then gdb just
156 pops up the GUD buffer unless `gdb-show-main' is t. In this case
157 it starts with two windows: one displaying the GUD buffer and the
158 other with the source file with the main routine of the inferior.
160 If `gdb-many-windows' is t, regardless of the value of
161 `gdb-show-main', the layout below will appear unless
162 `gdb-use-inferior-io-buffer' is nil when the source buffer
163 occupies the full width of the frame. Keybindings are given in
166 Watch expressions appear in the speedbar/slowbar.
168 The following commands help control operation :
170 `gdb-many-windows' - Toggle the number of windows gdb uses.
171 `gdb-restore-windows' - To restore the window layout.
173 See Info node `(emacs)GDB Graphical Interface' for a more
174 detailed description of this mode.
177 ---------------------------------------------------------------------
179 ---------------------------------------------------------------------
180 GUD buffer (I/O of GDB) | Locals buffer
184 ---------------------------------------------------------------------
185 Source buffer | Input/Output (of inferior) buffer
193 ---------------------------------------------------------------------
194 Stack buffer | Breakpoints buffer
195 RET gdb-frames-select | SPC gdb-toggle-breakpoint
196 | RET gdb-goto-breakpoint
197 | d gdb-delete-breakpoint
198 ---------------------------------------------------------------------"
200 (interactive (list (gud-query-cmdline 'gdba)))
202 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
206 (defvar gdb-debug-log nil)
209 (defcustom gdb-enable-debug-log nil
210 "Non-nil means record the process input and output in `gdb-debug-log'."
215 (defcustom gdb-use-inferior-io-buffer nil
216 "Non-nil means display output from the inferior in a separate buffer."
221 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
222 "Shell command for generating a list of defined macros in a source file.
223 This list is used to display the #define directive associated
224 with an identifier as a tooltip. It works in a debug session with
225 GDB, when gud-tooltip-mode is t.
227 Set `gdb-cpp-define-alist-flags' for any include paths or
233 (defcustom gdb-cpp-define-alist-flags ""
234 "Preprocessor flags for `gdb-cpp-define-alist-program'."
239 (defcustom gdb-show-main nil
240 "Non-nil means display source file containing the main routine at startup.
241 Also display the main routine in the disassembly buffer if present."
246 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
248 (defun gdb-create-define-alist ()
249 "Create an alist of #define directives for GUD tooltips."
250 (let* ((file (buffer-file-name))
252 (with-output-to-string
253 (with-current-buffer standard-output
254 (call-process shell-file-name
255 (if (file-exists-p file) file nil)
256 (list t nil) nil "-c"
257 (concat gdb-cpp-define-alist-program " "
258 gdb-cpp-define-alist-flags)))))
259 (define-list (split-string output "\n" t))
261 (setq gdb-define-alist nil)
262 (dolist (define define-list)
263 (setq name (nth 1 (split-string define "[( ]")))
264 (push (cons name define) gdb-define-alist))))
266 (defun gdb-tooltip-print ()
268 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
269 (let ((string (buffer-string)))
270 ;; remove newline for gud-tooltip-echo-area
271 (substring string 0 (- (length string) 1))))
272 (or gud-tooltip-echo-area tooltip-use-echo-area)))
274 ;; If expr is a macro for a function don't print because of possible dangerous
275 ;; side-effects. Also printing a function within a tooltip generates an
276 ;; unexpected starting annotation (phase error).
277 (defun gdb-tooltip-print-1 (expr)
278 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
279 (goto-char (point-min))
280 (if (search-forward "expands to: " nil t)
281 (unless (looking-at "\\S+.*(.*).*")
283 (list (concat gdb-server-prefix "print " expr "\n")
284 'gdb-tooltip-print))))))
286 (defun gdb-set-gud-minor-mode (buffer)
287 "Set `gud-minor-mode' from find-file if appropriate."
288 (goto-char (point-min))
289 (unless (search-forward "No source file named " nil t)
292 (list (concat gdb-server-prefix "info source\n")
293 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
294 (error (setq gdb-find-file-unhook t)))))
296 (defun gdb-set-gud-minor-mode-1 (buffer)
297 (goto-char (point-min))
298 (when (and (search-forward "Located in " nil t)
300 (string-equal (buffer-file-name buffer)
302 (with-current-buffer buffer
303 (set (make-local-variable 'gud-minor-mode) 'gdba)
304 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
305 (when gud-tooltip-mode
306 (make-local-variable 'gdb-define-alist)
307 (gdb-create-define-alist)
308 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
310 (defun gdb-set-gud-minor-mode-existing-buffers ()
311 (dolist (buffer (buffer-list))
312 (let ((file (buffer-file-name buffer)))
316 (list (concat gdb-server-prefix "list "
317 (file-name-nondirectory file) ":1\n")
318 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
321 (setq gdb-debug-log nil)
322 (set (make-local-variable 'gud-minor-mode) 'gdba)
323 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
325 (gud-def gud-break (if (not (string-match "Machine" mode-name))
326 (gud-call "break %f:%l" arg)
330 (gud-call "break *%a" arg)))
331 "\C-b" "Set breakpoint at current line or address.")
333 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
334 (gud-call "clear %f:%l" arg)
338 (gud-call "clear *%a" arg)))
339 "\C-d" "Remove breakpoint at current line or address.")
341 (gud-def gud-until (if (not (string-match "Machine" mode-name))
342 (gud-call "until %f:%l" arg)
346 (gud-call "until *%a" arg)))
347 "\C-u" "Continue to current line or address.")
349 (define-key gud-minor-mode-map [left-margin mouse-1]
350 'gdb-mouse-set-clear-breakpoint)
351 (define-key gud-minor-mode-map [left-fringe mouse-1]
352 'gdb-mouse-set-clear-breakpoint)
353 (define-key gud-minor-mode-map [left-margin mouse-3]
354 'gdb-mouse-toggle-breakpoint)
355 ; Currently only works in margin.
356 ; (define-key gud-minor-mode-map [left-fringe mouse-3]
357 ; 'gdb-mouse-toggle-breakpoint)
359 (setq comint-input-sender 'gdb-send)
362 (setq gdb-frame-address (if gdb-show-main "main" nil))
363 (setq gdb-previous-frame-address nil
364 gdb-memory-address "main"
365 gdb-previous-frame nil
366 gdb-selected-frame nil
367 gdb-current-language nil
375 gdb-pending-triggers nil
376 gdb-output-sink 'user
377 gdb-server-prefix "server "
378 gdb-flush-pending-output nil
379 gdb-location-alist nil
380 gdb-find-file-unhook nil
383 gdb-buffer-fringe-width (car (window-fringes)))
385 (setq gdb-buffer-type 'gdba)
387 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
389 (if (eq window-system 'w32)
390 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
391 (gdb-enqueue-input (list "set height 0\n" 'ignore))
392 (gdb-enqueue-input (list "set width 0\n" 'ignore))
393 ;; find source file and compilation directory here
394 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
395 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
396 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
398 (gdb-set-gud-minor-mode-existing-buffers)
399 (run-hooks 'gdba-mode-hook))
401 (defcustom gdb-use-colon-colon-notation nil
402 "If non-nil use FUN::VAR format to display variables in the speedbar."
408 "Watch expression at point."
411 (let ((expr (tooltip-identifier-from-point (point))))
412 (if (and (string-equal gdb-current-language "c")
413 gdb-use-colon-colon-notation gdb-selected-frame)
414 (setq expr (concat gdb-selected-frame "::" expr)))
415 (catch 'already-watched
416 (dolist (var gdb-var-list)
417 (if (string-equal expr (car var)) (throw 'already-watched nil)))
418 (set-text-properties 0 (length expr) nil expr)
421 (if (eq gud-minor-mode 'gdba)
422 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
423 (concat"-var-create - * " expr "\n"))
424 `(lambda () (gdb-var-create-handler ,expr))))))
425 (select-window (get-buffer-window gud-comint-buffer 0)))
427 (defconst gdb-var-create-regexp
428 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
430 (defun gdb-var-create-handler (expr)
431 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
432 (goto-char (point-min))
433 (if (re-search-forward gdb-var-create-regexp nil t)
434 (let ((var (list expr
439 (push var gdb-var-list)
441 (if (equal (nth 2 var) "0")
444 (if (with-current-buffer
445 gud-comint-buffer (eq gud-minor-mode 'gdba))
446 (concat "server interpreter mi \"-var-evaluate-expression "
448 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
449 `(lambda () (gdb-var-evaluate-expression-handler
451 (setq gdb-var-changed t)))
452 (if (re-search-forward "Undefined command" nil t)
453 (message-box "Watching expressions requires gdb 6.0 onwards")
454 (message "No symbol \"%s\" in current context." expr)))))
456 (defun gdb-var-evaluate-expression-handler (varnum changed)
457 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
458 (goto-char (point-min))
459 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t)
462 (dolist (var gdb-var-list)
463 (if (string-equal varnum (cadr var))
465 (if changed (setcar (nthcdr 5 var) t))
466 (setcar (nthcdr 4 var) (match-string 1))
467 (setcar (nthcdr num gdb-var-list) var)
468 (throw 'var-found nil)))
469 (setq num (+ num 1))))))
470 (setq gdb-var-changed t))
472 (defun gdb-var-list-children (varnum)
474 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
475 `(lambda () (gdb-var-list-children-handler ,varnum)))))
477 (defconst gdb-var-list-children-regexp
478 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
480 (defun gdb-var-list-children-handler (varnum)
481 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
482 (goto-char (point-min))
483 (let ((var-list nil))
484 (catch 'child-already-watched
485 (dolist (var gdb-var-list)
486 (if (string-equal varnum (cadr var))
489 (while (re-search-forward gdb-var-list-children-regexp nil t)
490 (let ((varchild (list (match-string 2)
494 (if (looking-at ",type=\"\\(.*?\\)\"")
495 (setcar (nthcdr 3 varchild) (match-string 1)))
496 (dolist (var1 gdb-var-list)
497 (if (string-equal (cadr var1) (cadr varchild))
498 (throw 'child-already-watched nil)))
499 (push varchild var-list)
500 (if (equal (nth 2 varchild) "0")
504 "server interpreter mi \"-var-evaluate-expression "
505 (nth 1 varchild) "\"\n")
506 `(lambda () (gdb-var-evaluate-expression-handler
507 ,(nth 1 varchild) nil))))))))
508 (push var var-list)))
509 (setq gdb-var-list (nreverse var-list))))))
511 (defun gdb-var-update ()
512 (when (not (member 'gdb-var-update gdb-pending-triggers))
514 (list "server interpreter mi \"-var-update *\"\n"
515 'gdb-var-update-handler))
516 (push 'gdb-var-update gdb-pending-triggers)))
518 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
520 (defun gdb-var-update-handler ()
521 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
522 (goto-char (point-min))
523 (while (re-search-forward gdb-var-update-regexp nil t)
524 (let ((varnum (match-string 1)))
527 (concat "server interpreter mi \"-var-evaluate-expression "
529 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
530 (setq gdb-pending-triggers
531 (delq 'gdb-var-update gdb-pending-triggers))
532 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
533 ;; Dummy command to update speedbar at right time.
534 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
535 ;; Keep gdb-pending-triggers non-nil till end.
536 (push 'gdb-speedbar-timer gdb-pending-triggers)))
538 (defun gdb-speedbar-timer-fn ()
539 (setq gdb-pending-triggers
540 (delq 'gdb-speedbar-timer gdb-pending-triggers))
541 (with-current-buffer gud-comint-buffer
542 (speedbar-timer-fn)))
544 (defun gdb-var-delete ()
545 "Delete watch expression at point from the speedbar."
547 (if (with-current-buffer
548 gud-comint-buffer (memq gud-minor-mode '(gdbmi gdba)))
549 (let ((text (speedbar-line-text)))
550 (string-match "\\(\\S-+\\)" text)
551 (let* ((expr (match-string 1 text))
552 (var (assoc expr gdb-var-list))
554 (unless (string-match "\\." varnum)
557 (if (with-current-buffer gud-comint-buffer
558 (eq gud-minor-mode 'gdba))
559 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
560 (concat "-var-delete " varnum "\n"))
562 (setq gdb-var-list (delq var gdb-var-list))
563 (dolist (varchild gdb-var-list)
564 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
565 (setq gdb-var-list (delq varchild gdb-var-list))))
566 (setq gdb-var-changed t))))))
568 (defun gdb-edit-value (text token indent)
569 "Assign a value to a variable displayed in the speedbar."
570 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
571 (varnum (cadr var)) (value))
572 (setq value (read-string "New value: "))
575 (if (with-current-buffer gud-comint-buffer
576 (eq gud-minor-mode 'gdba))
577 (concat "server interpreter mi \"-var-assign "
578 varnum " " value "\"\n")
579 (concat "-var-assign " varnum " " value "\n"))
582 (defcustom gdb-show-changed-values t
583 "If non-nil highlight values that have recently changed in the speedbar.
584 The highlighting is done with `font-lock-warning-face'."
589 (defun gdb-speedbar-expand-node (text token indent)
590 "Expand the node the user clicked on.
591 TEXT is the text of the button we clicked on, a + or - item.
592 TOKEN is data related to this node.
593 INDENT is the current indentation depth."
594 (cond ((string-match "+" text) ;expand this node
595 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
596 (gdb-var-list-children token)
599 (gdbmi-var-list-children token))))
600 ((string-match "-" text) ;contract this node
601 (dolist (var gdb-var-list)
602 (if (string-match (concat token "\\.") (nth 1 var))
603 (setq gdb-var-list (delq var gdb-var-list))))
604 (setq gdb-var-changed t))))
606 (defun gdb-get-target-string ()
607 (with-current-buffer gud-comint-buffer
614 ;; Each buffer has a TYPE -- a symbol that identifies the function
615 ;; of that particular buffer.
617 ;; The usual gdb interaction buffer is given the type `gdba' and
618 ;; is constructed specially.
620 ;; Others are constructed by gdb-get-create-buffer and
621 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
623 (defvar gdb-buffer-rules-assoc '())
625 (defun gdb-get-buffer (key)
626 "Return the gdb buffer tagged with type KEY.
627 The key should be one of the cars in `gdb-buffer-rules-assoc'."
629 (gdb-look-for-tagged-buffer key (buffer-list))))
631 (defun gdb-get-create-buffer (key)
632 "Create a new gdb buffer of the type specified by KEY.
633 The key should be one of the cars in `gdb-buffer-rules-assoc'."
634 (or (gdb-get-buffer key)
635 (let* ((rules (assoc key gdb-buffer-rules-assoc))
636 (name (funcall (gdb-rules-name-maker rules)))
637 (new (get-buffer-create name)))
638 (with-current-buffer new
640 (if (cdr (cdr rules))
641 (setq trigger (funcall (car (cdr (cdr rules))))))
642 (set (make-local-variable 'gdb-buffer-type) key)
643 (set (make-local-variable 'gud-minor-mode)
644 (with-current-buffer gud-comint-buffer gud-minor-mode))
645 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
646 (if trigger (funcall trigger)))
649 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
651 (defun gdb-look-for-tagged-buffer (key bufs)
653 (while (and (not retval) bufs)
654 (set-buffer (car bufs))
655 (if (eq gdb-buffer-type key)
656 (setq retval (car bufs)))
657 (setq bufs (cdr bufs)))
661 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
662 ;; at least one and possible more functions. The functions have these
663 ;; roles in defining a buffer type:
665 ;; NAME - Return a name for this buffer type.
667 ;; The remaining function(s) are optional:
669 ;; MODE - called in a new buffer with no arguments, should establish
670 ;; the proper mode for the buffer.
673 (defun gdb-set-buffer-rules (buffer-type &rest rules)
674 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
676 (setcdr binding rules)
677 (push (cons buffer-type rules)
678 gdb-buffer-rules-assoc))))
680 ;; GUD buffers are an exception to the rules
681 (gdb-set-buffer-rules 'gdba 'error)
684 ;; Partial-output buffer : This accumulates output from a command executed on
685 ;; behalf of emacs (rather than the user).
687 (gdb-set-buffer-rules 'gdb-partial-output-buffer
688 'gdb-partial-output-name)
690 (defun gdb-partial-output-name ()
691 (concat "*partial-output-"
692 (gdb-get-target-string)
696 (gdb-set-buffer-rules 'gdb-inferior-io
697 'gdb-inferior-io-name
698 'gdb-inferior-io-mode)
700 (defun gdb-inferior-io-name ()
701 (concat "*input/output of "
702 (gdb-get-target-string)
705 (defun gdb-display-inferior-io-buffer ()
706 "Display IO of inferior in a separate window."
708 (if gdb-use-inferior-io-buffer
710 (gdb-get-create-buffer 'gdb-inferior-io))))
712 (defconst gdb-frame-parameters
713 '((height . 14) (width . 80)
715 (tool-bar-lines . nil)
716 (menu-bar-lines . nil)
719 (defun gdb-frame-inferior-io-buffer ()
720 "Display IO of inferior in a new frame."
722 (if gdb-use-inferior-io-buffer
723 (let ((special-display-regexps (append special-display-regexps '(".*")))
724 (special-display-frame-alist gdb-frame-parameters))
725 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
727 (defvar gdb-inferior-io-mode-map
728 (let ((map (make-sparse-keymap)))
729 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
730 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
731 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
732 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
733 (define-key map "\C-d" 'gdb-inferior-io-eof)
736 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
737 "Major mode for gdb inferior-io."
738 :syntax-table nil :abbrev-table nil
739 ;; We want to use comint because it has various nifty and familiar
740 ;; features. We don't need a process, but comint wants one, so create
742 (make-comint-in-buffer
743 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
744 (current-buffer) "hexl")
745 (setq comint-input-sender 'gdb-inferior-io-sender))
747 (defun gdb-inferior-io-sender (proc string)
748 ;; PROC is the pseudo-process created to satisfy comint.
749 (with-current-buffer (process-buffer proc)
750 (setq proc (get-buffer-process gud-comint-buffer))
751 (process-send-string proc string)
752 (process-send-string proc "\n")))
754 (defun gdb-inferior-io-interrupt ()
755 "Interrupt the program being debugged."
758 (get-buffer-process gud-comint-buffer) comint-ptyp))
760 (defun gdb-inferior-io-quit ()
761 "Send quit signal to the program being debugged."
764 (get-buffer-process gud-comint-buffer) comint-ptyp))
766 (defun gdb-inferior-io-stop ()
767 "Stop the program being debugged."
770 (get-buffer-process gud-comint-buffer) comint-ptyp))
772 (defun gdb-inferior-io-eof ()
773 "Send end-of-file to the program being debugged."
776 (get-buffer-process gud-comint-buffer)))
780 ;; gdb communications
783 ;; INPUT: things sent to gdb
785 ;; The queues are lists. Each element is either a string (indicating user or
786 ;; user-like input) or a list of the form:
788 ;; (INPUT-STRING HANDLER-FN)
790 ;; The handler function will be called from the partial-output buffer when the
791 ;; command completes. This is the way to write commands which invoke gdb
792 ;; commands autonomously.
794 ;; These lists are consumed tail first.
797 (defun gdb-send (proc string)
798 "A comint send filter for gdb.
799 This filter may simply queue input for a later time."
800 (with-current-buffer gud-comint-buffer
801 (remove-text-properties (point-min) (point-max) '(face)))
802 (let ((item (concat string "\n")))
805 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
806 (process-send-string proc item))
807 (gdb-enqueue-input item))))
809 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
810 ;; is a query, or other non-top-level prompt.
812 (defun gdb-enqueue-input (item)
816 (setq gdb-prompting nil))
817 (push item gdb-input-queue)))
819 (defun gdb-dequeue-input ()
820 (let ((queue gdb-input-queue))
822 (let ((last (car (last queue))))
823 (unless (nbutlast queue) (setq gdb-input-queue '()))
826 (defun gdb-send-item (item)
827 (setq gdb-flush-pending-output nil)
828 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
829 (setq gdb-current-item item)
830 (with-current-buffer gud-comint-buffer
831 (if (eq gud-minor-mode 'gdba)
834 (setq gdb-output-sink 'user)
835 (process-send-string (get-buffer-process gud-comint-buffer) item))
837 (gdb-clear-partial-output)
838 (setq gdb-output-sink 'pre-emacs)
839 (process-send-string (get-buffer-process gud-comint-buffer)
841 ;; case: eq gud-minor-mode 'gdbmi
842 (gdb-clear-partial-output)
843 (setq gdb-output-sink 'emacs)
844 (process-send-string (get-buffer-process gud-comint-buffer)
848 ;; output -- things gdb prints to emacs
850 ;; GDB output is a stream interrupted by annotations.
851 ;; Annotations can be recognized by their beginning
852 ;; with \C-j\C-z\C-z<tag><opt>\C-j
854 ;; The tag is a string obeying symbol syntax.
856 ;; The optional part `<opt>' can be either the empty string
857 ;; or a space followed by more data relating to the annotation.
858 ;; For example, the SOURCE annotation is followed by a filename,
859 ;; line number and various useless goo. This data must not include
863 (defcustom gud-gdba-command-name "gdb -annotate=3"
864 "Default command to execute an executable under the GDB-UI debugger."
869 (defvar gdb-annotation-rules
870 '(("pre-prompt" gdb-pre-prompt)
871 ("prompt" gdb-prompt)
872 ("commands" gdb-subprompt)
873 ("overload-choice" gdb-subprompt)
874 ("query" gdb-subprompt)
875 ;; Need this prompt for GDB 6.1
876 ("nquery" gdb-subprompt)
877 ("prompt-for-continue" gdb-subprompt)
878 ("post-prompt" gdb-post-prompt)
879 ("source" gdb-source)
880 ("starting" gdb-starting)
881 ("exited" gdb-exited)
882 ("signalled" gdb-exited)
883 ("signal" gdb-stopping)
884 ("breakpoint" gdb-stopping)
885 ("watchpoint" gdb-stopping)
886 ("frame-begin" gdb-frame-begin)
887 ("stopped" gdb-stopped)
888 ("error-begin" gdb-error)
890 ) "An assoc mapping annotation tags to functions which process them.")
893 (setq gdb-flush-pending-output t)
894 (setq gud-running nil)
895 (setq gdb-output-sink 'user)
896 (setq gdb-input-queue nil)
897 (setq gdb-pending-triggers nil)
898 (setq gdb-prompting t))
900 (defconst gdb-source-spec-regexp
901 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
903 ;; Do not use this except as an annotation handler.
904 (defun gdb-source (args)
905 (string-match gdb-source-spec-regexp args)
906 ;; Extract the frame position from the marker.
909 (match-string 1 args)
910 (string-to-number (match-string 2 args))))
911 (setq gdb-frame-address (match-string 3 args))
912 ;; cover for auto-display output which comes *before*
913 ;; stopped annotation
914 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
916 (defun gdb-pre-prompt (ignored)
917 "An annotation handler for `pre-prompt'.
918 This terminates the collection of output from a previous command if that
919 happens to be in effect."
920 (let ((sink gdb-output-sink))
924 (setq gdb-output-sink 'post-emacs))
927 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
929 (defun gdb-prompt (ignored)
930 "An annotation handler for `prompt'.
931 This sends the next command (if any) to gdb."
932 (when gdb-first-prompt (gdb-ann3))
933 (let ((sink gdb-output-sink))
936 ((eq sink 'post-emacs)
937 (setq gdb-output-sink 'user)
939 (car (cdr gdb-current-item))))
940 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
944 (error "Phase error in gdb-prompt (got %s)" sink))))
945 (let ((input (gdb-dequeue-input)))
947 (gdb-send-item input)
949 (setq gdb-prompting t)
950 (gud-display-frame)))))
952 (defun gdb-subprompt (ignored)
953 "An annotation handler for non-top-level prompts."
954 (setq gdb-prompting t))
956 (defun gdb-starting (ignored)
957 "An annotation handler for `starting'.
958 This says that I/O for the subprocess is now the program being debugged,
960 (setq gdb-active-process t)
961 (let ((sink gdb-output-sink))
966 (if gdb-use-inferior-io-buffer
967 (setq gdb-output-sink 'inferior))))
970 (error "Unexpected `starting' annotation")))))
972 (defun gdb-stopping (ignored)
973 "An annotation handler for `breakpoint' and other annotations.
974 They say that I/O for the subprocess is now GDB, not the program
976 (if gdb-use-inferior-io-buffer
977 (let ((sink gdb-output-sink))
980 (setq gdb-output-sink 'user))
983 (error "Unexpected stopping annotation"))))))
985 (defun gdb-exited (ignored)
986 "An annotation handler for `exited' and `signalled'.
987 They say that I/O for the subprocess is now GDB, not the program
988 being debugged and that the program is no longer running. This
989 function is used to change the focus of GUD tooltips to #define
991 (setq gdb-active-process nil)
992 (gdb-stopping ignored))
994 (defun gdb-frame-begin (ignored)
995 (let ((sink gdb-output-sink))
998 (setq gdb-output-sink 'user))
1000 ((eq sink 'emacs) t)
1003 (error "Unexpected frame-begin annotation (%S)" sink)))))
1005 (defun gdb-stopped (ignored)
1006 "An annotation handler for `stopped'.
1007 It is just like `gdb-stopping', except that if we already set the output
1008 sink to `user' in `gdb-stopping', that is fine."
1009 (setq gud-running nil)
1010 (let ((sink gdb-output-sink))
1012 ((eq sink 'inferior)
1013 (setq gdb-output-sink 'user))
1017 (error "Unexpected stopped annotation")))))
1019 (defun gdb-error (ignored)
1020 (setq gdb-error (not gdb-error)))
1022 (defun gdb-post-prompt (ignored)
1023 "An annotation handler for `post-prompt'.
1024 This begins the collection of output from the current command if that
1025 happens to be appropriate."
1026 (unless gdb-pending-triggers
1027 (gdb-get-selected-frame)
1028 (gdb-invalidate-frames)
1029 (gdb-invalidate-breakpoints)
1030 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1031 ;; so gdb-frame-address is updated.
1032 ;; (gdb-invalidate-assembler)
1033 (gdb-invalidate-registers)
1034 (gdb-invalidate-memory)
1035 (gdb-invalidate-locals)
1036 (gdb-invalidate-threads)
1037 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1038 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1039 ;; Only needed/used with speedbar/watch expressions.
1040 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1041 (setq gdb-var-changed t) ; force update
1042 (dolist (var gdb-var-list)
1043 (setcar (nthcdr 5 var) nil))
1045 (let ((sink gdb-output-sink))
1048 ((eq sink 'pre-emacs)
1049 (setq gdb-output-sink 'emacs))
1052 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1054 (defun gud-gdba-marker-filter (string)
1055 "A gud marker filter for gdb. Handle a burst of output from GDB."
1056 (if gdb-flush-pending-output
1058 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1059 ;; Recall the left over gud-marker-acc from last time.
1060 (setq gud-marker-acc (concat gud-marker-acc string))
1061 ;; Start accumulating output for the GUD buffer.
1064 ;; Process all the complete markers in this chunk.
1065 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1066 (let ((annotation (match-string 1 gud-marker-acc)))
1068 ;; Stuff prior to the match is just ordinary output.
1069 ;; It is either concatenated to OUTPUT or directed
1074 (substring gud-marker-acc 0 (match-beginning 0))))
1076 ;; Take that stuff off the gud-marker-acc.
1077 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1079 ;; Parse the tag from the annotation, and maybe its arguments.
1080 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1081 (let* ((annotation-type (match-string 1 annotation))
1082 (annotation-arguments (match-string 2 annotation))
1083 (annotation-rule (assoc annotation-type
1084 gdb-annotation-rules)))
1085 ;; Call the handler for this annotation.
1087 (funcall (car (cdr annotation-rule))
1088 annotation-arguments)
1089 ;; Else the annotation is not recognized. Ignore it silently,
1090 ;; so that GDB can add new annotations without causing
1094 ;; Does the remaining text end in a partial line?
1095 ;; If it does, then keep part of the gud-marker-acc until we get more.
1096 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1099 ;; Everything before the potential marker start can be output.
1101 (gdb-concat-output output
1102 (substring gud-marker-acc 0
1103 (match-beginning 0))))
1105 ;; Everything after, we save, to combine with later input.
1106 (setq gud-marker-acc (substring gud-marker-acc
1107 (match-beginning 0))))
1109 ;; In case we know the gud-marker-acc contains no partial annotations:
1111 (setq output (gdb-concat-output output gud-marker-acc))
1112 (setq gud-marker-acc "")))
1115 (defun gdb-concat-output (so-far new)
1117 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1118 (let ((sink gdb-output-sink))
1120 ((eq sink 'user) (concat so-far new))
1121 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1123 (gdb-append-to-partial-output new)
1125 ((eq sink 'inferior)
1126 (gdb-append-to-inferior-io new)
1130 (error "Bogon output sink %S" sink)))))
1132 (defun gdb-append-to-partial-output (string)
1133 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1134 (goto-char (point-max))
1137 (defun gdb-clear-partial-output ()
1138 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1141 (defun gdb-append-to-inferior-io (string)
1142 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1143 (goto-char (point-max))
1144 (insert-before-markers string))
1145 (if (not (string-equal string ""))
1146 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1148 (defun gdb-clear-inferior-io ()
1149 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1153 ;; One trick is to have a command who's output is always available in a buffer
1154 ;; of it's own, and is always up to date. We build several buffers of this
1157 ;; There are two aspects to this: gdb has to tell us when the output for that
1158 ;; command might have changed, and we have to be able to run the command
1159 ;; behind the user's back.
1161 ;; The output phasing associated with the variable gdb-output-sink
1162 ;; help us to run commands behind the user's back.
1164 ;; Below is the code for specificly managing buffers of output from one
1168 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1169 ;; It adds an input for the command we are tracking. It should be the
1170 ;; annotation rule binding of whatever gdb sends to tell us this command
1171 ;; might have changed it's output.
1173 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1174 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1175 ;; input in the input queue (see comment about ``gdb communications'' above).
1177 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1179 `(defun ,name (&optional ignored)
1180 (if (and (,demand-predicate)
1182 gdb-pending-triggers)))
1185 (list ,gdb-command ',output-handler))
1186 (push ',name gdb-pending-triggers)))))
1188 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1190 (setq gdb-pending-triggers
1192 gdb-pending-triggers))
1193 (let ((buf (gdb-get-buffer ',buf-key)))
1195 (with-current-buffer buf
1196 (let ((p (window-point (get-buffer-window buf 0)))
1197 (buffer-read-only nil))
1199 (insert-buffer-substring (gdb-get-create-buffer
1200 'gdb-partial-output-buffer))
1201 (set-window-point (get-buffer-window buf 0) p)))))
1202 ;; put customisation here
1205 (defmacro def-gdb-auto-updated-buffer (buffer-key
1206 trigger-name gdb-command
1207 output-handler-name custom-defun)
1209 (def-gdb-auto-update-trigger ,trigger-name
1210 ;; The demand predicate:
1211 (lambda () (gdb-get-buffer ',buffer-key))
1213 ,output-handler-name)
1214 (def-gdb-auto-update-handler ,output-handler-name
1215 ,trigger-name ,buffer-key ,custom-defun)))
1219 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1221 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1222 'gdb-breakpoints-buffer-name
1223 'gdb-breakpoints-mode)
1225 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1226 ;; This defines the auto update rule for buffers of type
1227 ;; `gdb-breakpoints-buffer'.
1229 ;; It defines a function to serve as the annotation handler that
1230 ;; handles the `foo-invalidated' message. That function is called:
1231 gdb-invalidate-breakpoints
1233 ;; To update the buffer, this command is sent to gdb.
1234 "server info breakpoints\n"
1236 ;; This also defines a function to be the handler for the output
1237 ;; from the command above. That function will copy the output into
1238 ;; the appropriately typed buffer. That function will be called:
1239 gdb-info-breakpoints-handler
1240 ;; buffer specific functions
1241 gdb-info-breakpoints-custom)
1243 (defconst breakpoint-xpm-data
1245 static char *magick[] = {
1246 /* columns rows colors chars-per-pixel */
1262 "XPM data used for breakpoint icon.")
1264 (defconst breakpoint-enabled-pbm-data
1267 0 0 0 0 1 1 1 1 0 0 0 0
1268 0 0 0 1 1 1 1 1 1 0 0 0
1269 0 0 1 1 1 1 1 1 1 1 0 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 1 1 1 1 1 1 1 1 1 1 0
1274 0 0 1 1 1 1 1 1 1 1 0 0
1275 0 0 0 1 1 1 1 1 1 0 0 0
1276 0 0 0 0 1 1 1 1 0 0 0 0"
1277 "PBM data used for enabled breakpoint icon.")
1279 (defconst breakpoint-disabled-pbm-data
1291 0 0 0 1 0 1 0 1 0 0"
1292 "PBM data used for disabled breakpoint icon.")
1294 (defvar breakpoint-enabled-icon nil
1295 "Icon for enabled breakpoint in display margin.")
1297 (defvar breakpoint-disabled-icon nil
1298 "Icon for disabled breakpoint in display margin.")
1300 ;; Bitmap for breakpoint in fringe
1301 (and (display-images-p)
1302 (define-fringe-bitmap 'breakpoint
1303 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1305 (defface breakpoint-enabled
1309 "Face for enabled breakpoint icon in fringe."
1311 ;; Compatibility alias for old name.
1312 (put 'breakpoint-enabled-bitmap-face 'face-alias 'breakpoint-enabled)
1314 (defface breakpoint-disabled
1315 ;; We use different values of grey for different background types,
1316 ;; so that on low-color displays it will end up as something visible
1317 ;; if it has to be approximated.
1318 '((((background dark)) :foreground "grey60")
1319 (((background light)) :foreground "grey40"))
1320 "Face for disabled breakpoint icon in fringe."
1323 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1324 (defun gdb-info-breakpoints-custom ()
1325 (let ((flag) (bptno))
1326 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1327 (dolist (buffer (buffer-list))
1328 (with-current-buffer buffer
1329 (if (and (eq gud-minor-mode 'gdba)
1330 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1331 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1332 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1334 (goto-char (point-min))
1335 (while (< (point) (- (point-max) 1))
1337 (if (looking-at "[^\t].*?breakpoint")
1339 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1340 (setq bptno (match-string 1))
1341 (setq flag (char-after (match-beginning 2)))
1343 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1345 (let ((buffer-read-only nil))
1346 (add-text-properties (match-beginning 1) (match-end 1)
1347 '(face font-lock-function-name-face)))
1348 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1349 (let ((line (match-string 2)) (buffer-read-only nil)
1350 (file (match-string 1)))
1351 (add-text-properties (line-beginning-position)
1353 '(mouse-face highlight
1354 help-echo "mouse-2, RET: visit breakpoint"))
1355 (unless (file-exists-p file)
1356 (setq file (cdr (assoc bptno gdb-location-alist))))
1358 (not (string-equal file "File not found")))
1359 (with-current-buffer
1360 (find-file-noselect file 'nowarn)
1361 (set (make-local-variable 'gud-minor-mode)
1363 (set (make-local-variable 'tool-bar-map)
1365 ;; Only want one breakpoint icon at each
1368 (goto-line (string-to-number line))
1369 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1373 (match-string-no-properties 1) ":1\n")
1376 (list "info source\n"
1377 `(lambda () (gdb-get-location
1378 ,bptno ,line ,flag))))))))))
1380 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1382 (defun gdb-mouse-set-clear-breakpoint (event)
1383 "Set/clear breakpoint in left fringe/margin with mouse click."
1385 (mouse-minibuffer-check event)
1386 (let ((posn (event-end event)))
1387 (if (numberp (posn-point posn))
1388 (with-selected-window (posn-window posn)
1390 (goto-char (posn-point posn))
1391 (if (or (posn-object posn)
1392 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1395 (gud-break nil)))))))
1397 (defun gdb-mouse-toggle-breakpoint (event)
1398 "Enable/disable breakpoint in left fringe/margin with mouse click."
1400 (mouse-minibuffer-check event)
1401 (let ((posn (event-end event)))
1402 (if (numberp (posn-point posn))
1403 (with-selected-window (posn-window posn)
1405 (goto-char (posn-point posn))
1406 (if (posn-object posn)
1409 (let ((bptno (get-text-property
1410 0 'gdb-bptno (car (posn-string posn)))))
1412 (if (get-text-property
1413 0 'gdb-enabled (car (posn-string posn)))
1416 bptno "\n")) 'ignore))))))))
1418 (defun gdb-breakpoints-buffer-name ()
1419 (with-current-buffer gud-comint-buffer
1420 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1422 (defun gdb-display-breakpoints-buffer ()
1423 "Display status of user-settable breakpoints."
1426 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1428 (defun gdb-frame-breakpoints-buffer ()
1429 "Display status of user-settable breakpoints in a new frame."
1431 (let ((special-display-regexps (append special-display-regexps '(".*")))
1432 (special-display-frame-alist gdb-frame-parameters))
1433 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1435 (defvar gdb-breakpoints-mode-map
1436 (let ((map (make-sparse-keymap))
1437 (menu (make-sparse-keymap "Breakpoints")))
1438 (define-key menu [quit] '("Quit" . kill-this-buffer))
1439 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1440 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1441 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1442 (suppress-keymap map)
1443 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1444 (define-key map " " 'gdb-toggle-breakpoint)
1445 (define-key map "d" 'gdb-delete-breakpoint)
1446 (define-key map "q" 'kill-this-buffer)
1447 (define-key map "\r" 'gdb-goto-breakpoint)
1448 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1449 (define-key map [follow-link] 'mouse-face)
1452 (defun gdb-breakpoints-mode ()
1453 "Major mode for gdb breakpoints.
1455 \\{gdb-breakpoints-mode-map}"
1456 (kill-all-local-variables)
1457 (setq major-mode 'gdb-breakpoints-mode)
1458 (setq mode-name "Breakpoints")
1459 (use-local-map gdb-breakpoints-mode-map)
1460 (setq buffer-read-only t)
1461 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1462 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1463 'gdb-invalidate-breakpoints
1464 'gdbmi-invalidate-breakpoints))
1466 (defun gdb-toggle-breakpoint ()
1467 "Enable/disable breakpoint at current line."
1470 (beginning-of-line 1)
1471 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1472 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1474 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1477 (concat gdb-server-prefix
1478 (if (eq ?y (char-after (match-beginning 2)))
1481 (match-string 1) "\n") 'ignore))
1482 (error "Not recognized as break/watchpoint line"))))
1484 (defun gdb-delete-breakpoint ()
1485 "Delete the breakpoint at current line."
1487 (beginning-of-line 1)
1488 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1489 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1491 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1494 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1495 (error "Not recognized as break/watchpoint line")))
1497 (defun gdb-goto-breakpoint (&optional event)
1498 "Display the breakpoint location specified at current line."
1499 (interactive (list last-input-event))
1500 (if event (mouse-set-point event))
1502 (beginning-of-line 1)
1503 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1504 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1506 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1507 \\(\\S-+\\):\\([0-9]+\\)"))
1508 (let ((bptno (match-string 1))
1509 (file (match-string 2))
1510 (line (match-string 3)))
1511 (save-selected-window
1512 (let* ((buf (find-file-noselect
1513 (if (file-exists-p file) file
1514 (cdr (assoc bptno gdb-location-alist)))))
1515 (window (display-buffer buf)))
1516 (with-current-buffer buf
1517 (goto-line (string-to-number line))
1518 (set-window-point window (point))))))
1519 (error "Not recognized as break/watchpoint line"))))
1522 ;; Frames buffer. This displays a perpetually correct bactracktrace
1523 ;; (from the command `where').
1525 ;; Alas, if your stack is deep, it is costly.
1527 (gdb-set-buffer-rules 'gdb-stack-buffer
1528 'gdb-stack-buffer-name
1531 (def-gdb-auto-updated-buffer gdb-stack-buffer
1532 gdb-invalidate-frames
1534 gdb-info-frames-handler
1535 gdb-info-frames-custom)
1537 (defun gdb-info-frames-custom ()
1538 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1540 (let ((buffer-read-only nil)
1542 (goto-char (point-min))
1543 (while (< (point) (point-max))
1544 (setq bl (line-beginning-position)
1545 el (line-end-position))
1546 (add-text-properties bl el
1547 '(mouse-face highlight
1548 help-echo "mouse-2, RET: Select frame"))
1550 (when (looking-at "^#\\([0-9]+\\)")
1551 (when (string-equal (match-string 1) gdb-frame-number)
1552 (put-text-property bl (+ bl 4)
1553 'face '(:inverse-video t)))
1554 (when (re-search-forward
1556 (if (string-equal (match-string 1) "0") "" " in ")
1557 "\\([^ ]+\\) (") el t)
1558 (put-text-property (match-beginning 1) (match-end 1)
1559 'face font-lock-function-name-face)
1560 (setq bl (match-end 0))
1561 (while (re-search-forward "<\\([^>]+\\)>" el t)
1562 (put-text-property (match-beginning 1) (match-end 1)
1563 'face font-lock-function-name-face))
1565 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1566 (put-text-property (match-beginning 1) (match-end 1)
1567 'face font-lock-variable-name-face))))
1568 (forward-line 1))))))
1570 (defun gdb-stack-buffer-name ()
1571 (with-current-buffer gud-comint-buffer
1572 (concat "*stack frames of " (gdb-get-target-string) "*")))
1574 (defun gdb-display-stack-buffer ()
1575 "Display backtrace of current stack."
1578 (gdb-get-create-buffer 'gdb-stack-buffer)))
1580 (defun gdb-frame-stack-buffer ()
1581 "Display backtrace of current stack in a new frame."
1583 (let ((special-display-regexps (append special-display-regexps '(".*")))
1584 (special-display-frame-alist gdb-frame-parameters))
1585 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1587 (defvar gdb-frames-mode-map
1588 (let ((map (make-sparse-keymap)))
1589 (suppress-keymap map)
1590 (define-key map "q" 'kill-this-buffer)
1591 (define-key map "\r" 'gdb-frames-select)
1592 (define-key map [mouse-2] 'gdb-frames-select)
1593 (define-key map [follow-link] 'mouse-face)
1596 (defun gdb-frames-mode ()
1597 "Major mode for gdb frames.
1599 \\{gdb-frames-mode-map}"
1600 (kill-all-local-variables)
1601 (setq major-mode 'gdb-frames-mode)
1602 (setq mode-name "Frames")
1603 (setq buffer-read-only t)
1604 (use-local-map gdb-frames-mode-map)
1606 (run-mode-hooks 'gdb-frames-mode-hook)
1607 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1608 'gdb-invalidate-frames
1609 'gdbmi-invalidate-frames))
1611 (defun gdb-get-frame-number ()
1614 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1615 (n (or (and pos (match-string-no-properties 1)) "0")))
1618 (defun gdb-frames-select (&optional event)
1619 "Select the frame and display the relevant source."
1620 (interactive (list last-input-event))
1621 (if event (mouse-set-point event))
1623 (list (concat gdb-server-prefix "frame "
1624 (gdb-get-frame-number) "\n") 'ignore))
1625 (gud-display-frame))
1628 ;; Threads buffer. This displays a selectable thread list.
1630 (gdb-set-buffer-rules 'gdb-threads-buffer
1631 'gdb-threads-buffer-name
1634 (def-gdb-auto-updated-buffer gdb-threads-buffer
1635 gdb-invalidate-threads
1636 (concat gdb-server-prefix "info threads\n")
1637 gdb-info-threads-handler
1638 gdb-info-threads-custom)
1640 (defun gdb-info-threads-custom ()
1641 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1642 (let ((buffer-read-only nil))
1643 (goto-char (point-min))
1644 (while (< (point) (point-max))
1645 (add-text-properties (line-beginning-position) (line-end-position)
1646 '(mouse-face highlight
1647 help-echo "mouse-2, RET: select thread"))
1648 (forward-line 1)))))
1650 (defun gdb-threads-buffer-name ()
1651 (with-current-buffer gud-comint-buffer
1652 (concat "*threads of " (gdb-get-target-string) "*")))
1654 (defun gdb-display-threads-buffer ()
1655 "Display IDs of currently known threads."
1658 (gdb-get-create-buffer 'gdb-threads-buffer)))
1660 (defun gdb-frame-threads-buffer ()
1661 "Display IDs of currently known threads in a new frame."
1663 (let ((special-display-regexps (append special-display-regexps '(".*")))
1664 (special-display-frame-alist gdb-frame-parameters))
1665 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1667 (defvar gdb-threads-mode-map
1668 (let ((map (make-sparse-keymap)))
1669 (suppress-keymap map)
1670 (define-key map "q" 'kill-this-buffer)
1671 (define-key map "\r" 'gdb-threads-select)
1672 (define-key map [mouse-2] 'gdb-threads-select)
1675 (defvar gdb-threads-font-lock-keywords
1677 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1678 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1679 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1681 "Font lock keywords used in `gdb-threads-mode'.")
1683 (defun gdb-threads-mode ()
1684 "Major mode for gdb frames.
1686 \\{gdb-threads-mode-map}"
1687 (kill-all-local-variables)
1688 (setq major-mode 'gdb-threads-mode)
1689 (setq mode-name "Threads")
1690 (setq buffer-read-only t)
1691 (use-local-map gdb-threads-mode-map)
1692 (set (make-local-variable 'font-lock-defaults)
1693 '(gdb-threads-font-lock-keywords))
1694 (run-mode-hooks 'gdb-threads-mode-hook)
1695 'gdb-invalidate-threads)
1697 (defun gdb-get-thread-number ()
1699 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1700 (match-string-no-properties 1)))
1702 (defun gdb-threads-select (&optional event)
1703 "Select the thread and display the relevant source."
1704 (interactive (list last-input-event))
1705 (if event (mouse-set-point event))
1707 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1708 (gud-display-frame))
1711 ;; Registers buffer.
1713 (defcustom gdb-all-registers nil
1714 "Non-nil means include floating-point registers."
1719 (gdb-set-buffer-rules 'gdb-registers-buffer
1720 'gdb-registers-buffer-name
1721 'gdb-registers-mode)
1723 (def-gdb-auto-updated-buffer gdb-registers-buffer
1724 gdb-invalidate-registers
1726 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1727 gdb-info-registers-handler
1728 gdb-info-registers-custom)
1730 (defun gdb-info-registers-custom ())
1732 (defvar gdb-registers-mode-map
1733 (let ((map (make-sparse-keymap)))
1734 (suppress-keymap map)
1735 (define-key map " " 'toggle-gdb-all-registers)
1736 (define-key map "q" 'kill-this-buffer)
1739 (defvar gdb-registers-font-lock-keywords
1741 ("^[^ ]+" . font-lock-variable-name-face)
1743 "Font lock keywords used in `gdb-registers-mode'.")
1745 (defun gdb-registers-mode ()
1746 "Major mode for gdb registers.
1748 \\{gdb-registers-mode-map}"
1749 (kill-all-local-variables)
1750 (setq major-mode 'gdb-registers-mode)
1751 (setq mode-name "Registers:")
1752 (setq buffer-read-only t)
1753 (use-local-map gdb-registers-mode-map)
1754 (set (make-local-variable 'font-lock-defaults)
1755 '(gdb-registers-font-lock-keywords))
1756 (run-mode-hooks 'gdb-registers-mode-hook)
1757 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1758 'gdb-invalidate-registers
1759 'gdbmi-invalidate-registers))
1761 (defun gdb-registers-buffer-name ()
1762 (with-current-buffer gud-comint-buffer
1763 (concat "*registers of " (gdb-get-target-string) "*")))
1765 (defun gdb-display-registers-buffer ()
1766 "Display integer register contents."
1769 (gdb-get-create-buffer 'gdb-registers-buffer)))
1771 (defun gdb-frame-registers-buffer ()
1772 "Display integer register contents in a new frame."
1774 (let ((special-display-regexps (append special-display-regexps '(".*")))
1775 (special-display-frame-alist gdb-frame-parameters))
1776 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1778 (defun toggle-gdb-all-registers ()
1779 "Toggle the display of floating-point registers."
1781 (if gdb-all-registers
1783 (setq gdb-all-registers nil)
1784 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1785 (setq mode-name "Registers:")))
1786 (setq gdb-all-registers t)
1787 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1788 (setq mode-name "Registers:All")))
1789 (gdb-invalidate-registers))
1794 (defcustom gdb-memory-repeat-count 32
1795 "Number of data items in memory window."
1800 (defcustom gdb-memory-format "x"
1801 "Display format of data items in memory window."
1802 :type '(choice (const :tag "Hexadecimal" "x")
1803 (const :tag "Signed decimal" "d")
1804 (const :tag "Unsigned decimal" "u")
1805 (const :tag "Octal" "o")
1806 (const :tag "Binary" "t"))
1810 (defcustom gdb-memory-unit "w"
1811 "Unit size of data items in memory window."
1812 :type '(choice (const :tag "Byte" "b")
1813 (const :tag "Halfword" "h")
1814 (const :tag "Word" "w")
1815 (const :tag "Giant word" "g"))
1819 (gdb-set-buffer-rules 'gdb-memory-buffer
1820 'gdb-memory-buffer-name
1823 (def-gdb-auto-updated-buffer gdb-memory-buffer
1824 gdb-invalidate-memory
1825 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1826 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1827 gdb-read-memory-handler
1828 gdb-read-memory-custom)
1830 (defun gdb-read-memory-custom ()
1832 (goto-char (point-min))
1833 (if (looking-at "0x[[:xdigit:]]+")
1834 (setq gdb-memory-address (match-string 0)))))
1836 (defvar gdb-memory-mode-map
1837 (let ((map (make-sparse-keymap)))
1838 (suppress-keymap map)
1839 (define-key map "q" 'kill-this-buffer)
1842 (defun gdb-memory-set-address (event)
1843 "Set the start memory address."
1845 (save-selected-window
1846 (select-window (posn-window (event-start event)))
1847 (let ((arg (read-from-minibuffer "Memory address: ")))
1848 (setq gdb-memory-address arg))
1849 (gdb-invalidate-memory)))
1851 (defun gdb-memory-set-repeat-count (event)
1852 "Set the number of data items in memory window."
1854 (save-selected-window
1855 (select-window (posn-window (event-start event)))
1856 (let* ((arg (read-from-minibuffer "Repeat count: "))
1857 (count (string-to-number arg)))
1859 (error "Positive numbers only")
1860 (customize-set-variable 'gdb-memory-repeat-count count)
1861 (gdb-invalidate-memory)))))
1863 (defun gdb-memory-format-binary ()
1864 "Set the display format to binary."
1866 (customize-set-variable 'gdb-memory-format "t")
1867 (gdb-invalidate-memory))
1869 (defun gdb-memory-format-octal ()
1870 "Set the display format to octal."
1872 (customize-set-variable 'gdb-memory-format "o")
1873 (gdb-invalidate-memory))
1875 (defun gdb-memory-format-unsigned ()
1876 "Set the display format to unsigned decimal."
1878 (customize-set-variable 'gdb-memory-format "u")
1879 (gdb-invalidate-memory))
1881 (defun gdb-memory-format-signed ()
1882 "Set the display format to decimal."
1884 (customize-set-variable 'gdb-memory-format "d")
1885 (gdb-invalidate-memory))
1887 (defun gdb-memory-format-hexadecimal ()
1888 "Set the display format to hexadecimal."
1890 (customize-set-variable 'gdb-memory-format "x")
1891 (gdb-invalidate-memory))
1893 (defvar gdb-memory-format-keymap
1894 (let ((map (make-sparse-keymap)))
1895 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1897 "Keymap to select format in the header line.")
1899 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1900 "Menu of display formats in the header line.")
1902 (define-key gdb-memory-format-menu [binary]
1903 '(menu-item "Binary" gdb-memory-format-binary
1904 :button (:radio . (equal gdb-memory-format "t"))))
1905 (define-key gdb-memory-format-menu [octal]
1906 '(menu-item "Octal" gdb-memory-format-octal
1907 :button (:radio . (equal gdb-memory-format "o"))))
1908 (define-key gdb-memory-format-menu [unsigned]
1909 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
1910 :button (:radio . (equal gdb-memory-format "u"))))
1911 (define-key gdb-memory-format-menu [signed]
1912 '(menu-item "Signed Decimal" gdb-memory-format-signed
1913 :button (:radio . (equal gdb-memory-format "d"))))
1914 (define-key gdb-memory-format-menu [hexadecimal]
1915 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
1916 :button (:radio . (equal gdb-memory-format "x"))))
1918 (defun gdb-memory-format-menu (event)
1920 (x-popup-menu event gdb-memory-format-menu))
1922 (defun gdb-memory-format-menu-1 (event)
1924 (save-selected-window
1925 (select-window (posn-window (event-start event)))
1926 (let* ((selection (gdb-memory-format-menu event))
1927 (binding (and selection (lookup-key gdb-memory-format-menu
1928 (vector (car selection))))))
1929 (if binding (call-interactively binding)))))
1931 (defun gdb-memory-unit-giant ()
1932 "Set the unit size to giant words (eight bytes)."
1934 (customize-set-variable 'gdb-memory-unit "g")
1935 (gdb-invalidate-memory))
1937 (defun gdb-memory-unit-word ()
1938 "Set the unit size to words (four bytes)."
1940 (customize-set-variable 'gdb-memory-unit "w")
1941 (gdb-invalidate-memory))
1943 (defun gdb-memory-unit-halfword ()
1944 "Set the unit size to halfwords (two bytes)."
1946 (customize-set-variable 'gdb-memory-unit "h")
1947 (gdb-invalidate-memory))
1949 (defun gdb-memory-unit-byte ()
1950 "Set the unit size to bytes."
1952 (customize-set-variable 'gdb-memory-unit "b")
1953 (gdb-invalidate-memory))
1955 (defvar gdb-memory-unit-keymap
1956 (let ((map (make-sparse-keymap)))
1957 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
1959 "Keymap to select units in the header line.")
1961 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
1962 "Menu of units in the header line.")
1964 (define-key gdb-memory-unit-menu [giantwords]
1965 '(menu-item "Giant words" gdb-memory-unit-giant
1966 :button (:radio . (equal gdb-memory-unit "g"))))
1967 (define-key gdb-memory-unit-menu [words]
1968 '(menu-item "Words" gdb-memory-unit-word
1969 :button (:radio . (equal gdb-memory-unit "w"))))
1970 (define-key gdb-memory-unit-menu [halfwords]
1971 '(menu-item "Halfwords" gdb-memory-unit-halfword
1972 :button (:radio . (equal gdb-memory-unit "h"))))
1973 (define-key gdb-memory-unit-menu [bytes]
1974 '(menu-item "Bytes" gdb-memory-unit-byte
1975 :button (:radio . (equal gdb-memory-unit "b"))))
1977 (defun gdb-memory-unit-menu (event)
1979 (x-popup-menu event gdb-memory-unit-menu))
1981 (defun gdb-memory-unit-menu-1 (event)
1983 (save-selected-window
1984 (select-window (posn-window (event-start event)))
1985 (let* ((selection (gdb-memory-unit-menu event))
1986 (binding (and selection (lookup-key gdb-memory-unit-menu
1987 (vector (car selection))))))
1988 (if binding (call-interactively binding)))))
1990 ;;from make-mode-line-mouse-map
1991 (defun gdb-make-header-line-mouse-map (mouse function) "\
1992 Return a keymap with single entry for mouse key MOUSE on the header line.
1993 MOUSE is defined to run function FUNCTION with no args in the buffer
1994 corresponding to the mode line clicked."
1995 (let ((map (make-sparse-keymap)))
1996 (define-key map (vector 'header-line mouse) function)
1997 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2000 (defvar gdb-memory-font-lock-keywords
2001 '(;; <__function.name+n>
2002 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2004 "Font lock keywords used in `gdb-memory-mode'.")
2006 (defun gdb-memory-mode ()
2007 "Major mode for examining memory.
2009 \\{gdb-memory-mode-map}"
2010 (kill-all-local-variables)
2011 (setq major-mode 'gdb-memory-mode)
2012 (setq mode-name "Memory")
2013 (setq buffer-read-only t)
2014 (use-local-map gdb-memory-mode-map)
2015 (setq header-line-format
2021 'face font-lock-warning-face
2022 'help-echo "mouse-1: Decrement address"
2023 'mouse-face 'mode-line-highlight
2025 (gdb-make-header-line-mouse-map
2027 #'(lambda () (interactive)
2028 (let ((gdb-memory-address
2029 ;; Let GDB do the arithmetic.
2031 gdb-memory-address " - "
2033 (* gdb-memory-repeat-count
2034 (cond ((string= gdb-memory-unit "b") 1)
2035 ((string= gdb-memory-unit "h") 2)
2036 ((string= gdb-memory-unit "w") 4)
2037 ((string= gdb-memory-unit "g") 8)))))))
2038 (gdb-invalidate-memory)))))
2041 'face font-lock-warning-face
2042 'help-echo "mouse-1: Increment address"
2043 'mouse-face 'mode-line-highlight
2044 'local-map (gdb-make-header-line-mouse-map
2046 #'(lambda () (interactive)
2047 (let ((gdb-memory-address nil))
2048 (gdb-invalidate-memory)))))
2050 (propertize gdb-memory-address
2051 'face font-lock-warning-face
2052 'help-echo "mouse-1: Set memory address"
2053 'mouse-face 'mode-line-highlight
2054 'local-map (gdb-make-header-line-mouse-map
2056 #'gdb-memory-set-address))
2058 (propertize (number-to-string gdb-memory-repeat-count)
2059 'face font-lock-warning-face
2060 'help-echo "mouse-1: Set repeat count"
2061 'mouse-face 'mode-line-highlight
2062 'local-map (gdb-make-header-line-mouse-map
2064 #'gdb-memory-set-repeat-count))
2066 (propertize gdb-memory-format
2067 'face font-lock-warning-face
2068 'help-echo "mouse-3: Select display format"
2069 'mouse-face 'mode-line-highlight
2070 'local-map gdb-memory-format-keymap)
2072 (propertize gdb-memory-unit
2073 'face font-lock-warning-face
2074 'help-echo "mouse-3: Select unit size"
2075 'mouse-face 'mode-line-highlight
2076 'local-map gdb-memory-unit-keymap))))
2077 (set (make-local-variable 'font-lock-defaults)
2078 '(gdb-memory-font-lock-keywords))
2079 (run-mode-hooks 'gdb-memory-mode-hook)
2080 'gdb-invalidate-memory)
2082 (defun gdb-memory-buffer-name ()
2083 (with-current-buffer gud-comint-buffer
2084 (concat "*memory of " (gdb-get-target-string) "*")))
2086 (defun gdb-display-memory-buffer ()
2087 "Display memory contents."
2090 (gdb-get-create-buffer 'gdb-memory-buffer)))
2092 (defun gdb-frame-memory-buffer ()
2093 "Display memory contents in a new frame."
2095 (let ((special-display-regexps (append special-display-regexps '(".*")))
2096 (special-display-frame-alist gdb-frame-parameters))
2097 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2102 (gdb-set-buffer-rules 'gdb-locals-buffer
2103 'gdb-locals-buffer-name
2106 (def-gdb-auto-updated-buffer gdb-locals-buffer
2107 gdb-invalidate-locals
2108 "server info locals\n"
2109 gdb-info-locals-handler
2110 gdb-info-locals-custom)
2112 ;; Abbreviate for arrays and structures.
2113 ;; These can be expanded using gud-display.
2114 (defun gdb-info-locals-handler nil
2115 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2116 gdb-pending-triggers))
2117 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2118 (with-current-buffer buf
2119 (goto-char (point-min))
2120 (while (re-search-forward "^[ }].*\n" nil t)
2121 (replace-match "" nil nil))
2122 (goto-char (point-min))
2123 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2124 (replace-match "(structure);\n" nil nil))
2125 (goto-char (point-min))
2126 (while (re-search-forward "\\s-*{.*\n" nil t)
2127 (replace-match " (array);\n" nil nil))))
2128 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2129 (and buf (with-current-buffer buf
2130 (let ((p (window-point (get-buffer-window buf 0)))
2131 (buffer-read-only nil))
2133 (insert-buffer-substring (gdb-get-create-buffer
2134 'gdb-partial-output-buffer))
2135 (set-window-point (get-buffer-window buf 0) p)))))
2136 (run-hooks 'gdb-info-locals-hook))
2138 (defun gdb-info-locals-custom ()
2141 (defvar gdb-locals-mode-map
2142 (let ((map (make-sparse-keymap)))
2143 (suppress-keymap map)
2144 (define-key map "q" 'kill-this-buffer)
2147 (defvar gdb-local-font-lock-keywords
2149 ;; var = (struct struct_tag) value
2150 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2151 (1 font-lock-variable-name-face)
2152 (3 font-lock-keyword-face)
2153 (4 font-lock-type-face))
2154 ;; var = (type) value
2155 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2156 (1 font-lock-variable-name-face)
2157 (3 font-lock-type-face))
2159 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2160 (1 font-lock-variable-name-face))
2162 "Font lock keywords used in `gdb-local-mode'.")
2164 (defun gdb-locals-mode ()
2165 "Major mode for gdb locals.
2167 \\{gdb-locals-mode-map}"
2168 (kill-all-local-variables)
2169 (setq major-mode 'gdb-locals-mode)
2170 (setq mode-name (concat "Locals:" gdb-selected-frame))
2171 (setq buffer-read-only t)
2172 (use-local-map gdb-locals-mode-map)
2173 (set (make-local-variable 'font-lock-defaults)
2174 '(gdb-local-font-lock-keywords))
2175 (run-mode-hooks 'gdb-locals-mode-hook)
2176 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
2177 'gdb-invalidate-locals
2178 'gdbmi-invalidate-locals))
2180 (defun gdb-locals-buffer-name ()
2181 (with-current-buffer gud-comint-buffer
2182 (concat "*locals of " (gdb-get-target-string) "*")))
2184 (defun gdb-display-locals-buffer ()
2185 "Display local variables of current stack and their values."
2188 (gdb-get-create-buffer 'gdb-locals-buffer)))
2190 (defun gdb-frame-locals-buffer ()
2191 "Display local variables of current stack and their values in a new frame."
2193 (let ((special-display-regexps (append special-display-regexps '(".*")))
2194 (special-display-frame-alist gdb-frame-parameters))
2195 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2198 ;;;; Window management
2199 (defun gdb-display-buffer (buf &optional size)
2200 (let ((answer (get-buffer-window buf 0))
2203 (display-buffer buf nil 0) ;Raise the frame if necessary.
2204 ;; The buffer is not yet displayed.
2205 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2206 (let ((window (get-lru-window)))
2208 (not (eq window (get-buffer-window gud-comint-buffer))))
2210 (set-window-buffer window buf)
2211 (setq answer window))
2212 (setq must-split t)))
2214 (let* ((largest (get-largest-window))
2215 (cur-size (window-height largest))
2216 (new-size (and size (< size cur-size) (- cur-size size))))
2217 (setq answer (split-window largest new-size))
2218 (set-window-buffer answer buf)
2219 (set-window-dedicated-p answer t)))
2223 ;;; Shared keymap initialization:
2225 (let ((menu (make-sparse-keymap "GDB-Windows")))
2226 (define-key gud-menu-map [displays]
2227 `(menu-item "GDB-Windows" ,menu
2228 :visible (memq gud-minor-mode '(gdbmi gdba))))
2229 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2230 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2231 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2232 (define-key menu [disassembly]
2233 '("Disassembly" . gdb-display-assembler-buffer))
2234 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2235 (define-key menu [inferior]
2236 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2237 :enable gdb-use-inferior-io-buffer))
2238 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2239 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2240 (define-key menu [breakpoints]
2241 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2243 (let ((menu (make-sparse-keymap "GDB-Frames")))
2244 (define-key gud-menu-map [frames]
2245 `(menu-item "GDB-Frames" ,menu
2246 :visible (memq gud-minor-mode '(gdbmi gdba))))
2247 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2248 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2249 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2250 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2251 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2252 (define-key menu [inferior]
2253 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2254 :enable gdb-use-inferior-io-buffer))
2255 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2256 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2257 (define-key menu [breakpoints]
2258 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2260 (let ((menu (make-sparse-keymap "GDB-UI")))
2261 (define-key gud-menu-map [ui]
2262 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2263 (define-key menu [gdb-use-inferior-io]
2264 ;; See defadvice below.
2265 (menu-bar-make-toggle toggle-gdb-use-inferior-io-buffer
2266 gdb-use-inferior-io-buffer
2267 "Separate inferior IO" "Use separate IO %s"
2268 "Toggle separate IO for inferior."))
2269 (define-key menu [gdb-many-windows]
2270 '(menu-item "Display Other Windows" gdb-many-windows
2271 :help "Toggle display of locals, stack and breakpoint information"
2272 :button (:toggle . gdb-many-windows)))
2273 (define-key menu [gdb-restore-windows]
2274 '(menu-item "Restore Window Layout" gdb-restore-windows
2275 :help "Restore standard layout for debug session.")))
2277 ;; This function is defined above through a macro.
2278 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
2279 (unless gdb-use-inferior-io-buffer
2280 (kill-buffer (gdb-inferior-io-name))))
2282 (defun gdb-frame-gdb-buffer ()
2283 "Display GUD buffer in a new frame."
2285 (select-frame (make-frame gdb-frame-parameters))
2286 (switch-to-buffer (gdb-get-create-buffer 'gdba))
2287 (set-window-dedicated-p (selected-window) t))
2289 (defun gdb-display-gdb-buffer ()
2290 "Display GUD buffer."
2293 (gdb-get-create-buffer 'gdba)))
2295 (defun gdb-set-window-buffer (name)
2296 (set-window-buffer (selected-window) (get-buffer name))
2297 (set-window-dedicated-p (selected-window) t))
2299 (defun gdb-setup-windows ()
2300 "Layout the window pattern for `gdb-many-windows'."
2301 (gdb-display-locals-buffer)
2302 (gdb-display-stack-buffer)
2303 (delete-other-windows)
2304 (gdb-display-breakpoints-buffer)
2305 (delete-other-windows)
2307 (pop-to-buffer gud-comint-buffer)
2308 (split-window nil ( / ( * (window-height) 3) 4))
2309 (split-window nil ( / (window-height) 3))
2310 (split-window-horizontally)
2312 (gdb-set-window-buffer (gdb-locals-buffer-name))
2315 (if gud-last-last-frame
2316 (gud-find-file (car gud-last-last-frame))
2317 (gud-find-file gdb-main-file)))
2318 (when gdb-use-inferior-io-buffer
2319 (split-window-horizontally)
2321 (gdb-set-window-buffer
2322 (gdb-get-create-buffer 'gdb-inferior-io)))
2324 (gdb-set-window-buffer (gdb-stack-buffer-name))
2325 (split-window-horizontally)
2327 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2330 (defcustom gdb-many-windows nil
2331 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2332 In this case it starts with two windows: one displaying the GUD
2333 buffer and the other with the source file with the main routine
2334 of the inferior. Non-nil means display the layout shown for
2340 (defun gdb-many-windows (arg)
2341 "Toggle the number of windows in the basic arrangement."
2343 (setq gdb-many-windows
2345 (not gdb-many-windows)
2346 (> (prefix-numeric-value arg) 0)))
2348 (gdb-restore-windows)
2351 (defun gdb-restore-windows ()
2352 "Restore the basic arrangement of windows used by gdba.
2353 This arrangement depends on the value of `gdb-many-windows'."
2355 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2356 (delete-other-windows)
2357 (if gdb-many-windows
2362 (if gud-last-last-frame
2363 (gud-find-file (car gud-last-last-frame))
2364 (gud-find-file gdb-main-file)))
2368 "Exit a debugging session cleanly.
2369 Kills the gdb buffers and resets the source buffers."
2370 (dolist (buffer (buffer-list))
2371 (unless (eq buffer gud-comint-buffer)
2372 (with-current-buffer buffer
2373 (if (memq gud-minor-mode '(gdbmi gdba))
2374 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2376 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2377 (setq gud-minor-mode nil)
2378 (kill-local-variable 'tool-bar-map)
2379 (kill-local-variable 'gdb-define-alist))))))
2380 (when (markerp gdb-overlay-arrow-position)
2381 (move-marker gdb-overlay-arrow-position nil)
2382 (setq gdb-overlay-arrow-position nil))
2383 (setq overlay-arrow-variable-list
2384 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2385 (setq gud-running nil)
2386 (setq gdb-active-process nil)
2387 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2389 (defun gdb-source-info ()
2390 "Find the source file where the program starts and displays it with related
2392 (goto-char (point-min))
2393 (if (and (search-forward "Located in " nil t)
2394 (looking-at "\\S-+"))
2395 (setq gdb-main-file (match-string 0)))
2396 (goto-char (point-min))
2397 (if (search-forward "Includes preprocessor macro info." nil t)
2398 (setq gdb-macro-info t))
2399 (if gdb-many-windows
2401 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2403 (let ((pop-up-windows t))
2404 (display-buffer (gud-find-file gdb-main-file))))))
2406 (defun gdb-get-location (bptno line flag)
2407 "Find the directory containing the relevant source file.
2408 Put in buffer and place breakpoint icon."
2409 (goto-char (point-min))
2410 (catch 'file-not-found
2411 (if (search-forward "Located in " nil t)
2412 (when (looking-at "\\S-+")
2413 (delete (cons bptno "File not found") gdb-location-alist)
2414 (push (cons bptno (match-string 0)) gdb-location-alist))
2416 (unless (assoc bptno gdb-location-alist)
2417 (push (cons bptno "File not found") gdb-location-alist)
2418 (message-box "Cannot find source file for breakpoint location.\n\
2419 Add directory to search path for source files using the GDB command, dir."))
2420 (throw 'file-not-found nil))
2421 (with-current-buffer
2422 (find-file-noselect (match-string 0))
2423 (save-current-buffer
2424 (set (make-local-variable 'gud-minor-mode) 'gdba)
2425 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2426 ;; only want one breakpoint icon at each location
2428 (goto-line (string-to-number line))
2429 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2431 (add-hook 'find-file-hook 'gdb-find-file-hook)
2433 (defun gdb-find-file-hook ()
2434 "Set up buffer for debugging if file is part of the source code
2435 of the current session."
2436 (if (and (not gdb-find-file-unhook)
2437 ;; in case gud or gdb-ui is just loaded
2439 (buffer-name gud-comint-buffer)
2440 (with-current-buffer gud-comint-buffer
2441 (eq gud-minor-mode 'gdba)))
2444 (list (concat gdb-server-prefix "list "
2445 (file-name-nondirectory buffer-file-name)
2447 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2448 (error (setq gdb-find-file-unhook t)))))
2451 (defun gdb-put-string (putstring pos &optional dprop)
2452 "Put string PUTSTRING in front of POS in the current buffer.
2453 PUTSTRING is displayed by putting an overlay into the current buffer with a
2454 `before-string' string that has a `display' property whose value is
2456 (let ((string (make-string 1 ?x))
2457 (buffer (current-buffer)))
2458 (setq putstring (copy-sequence putstring))
2459 (let ((overlay (make-overlay pos pos buffer))
2461 (list (list 'margin 'left-margin) putstring))))
2462 (put-text-property 0 (length string) 'display prop string)
2463 (overlay-put overlay 'put-break t)
2464 (overlay-put overlay 'before-string string))))
2466 ;;from remove-images
2467 (defun gdb-remove-strings (start end &optional buffer)
2468 "Remove strings between START and END in BUFFER.
2469 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2470 BUFFER nil or omitted means use the current buffer."
2472 (setq buffer (current-buffer)))
2473 (dolist (overlay (overlays-in start end))
2474 (when (overlay-get overlay 'put-break)
2475 (delete-overlay overlay))))
2477 (defun gdb-put-breakpoint-icon (enabled bptno)
2478 (let ((start (- (line-beginning-position) 1))
2479 (end (+ (line-end-position) 1))
2480 (putstring (if enabled "B" "b"))
2481 (source-window (get-buffer-window (current-buffer) 0)))
2482 (add-text-properties
2483 0 1 '(help-echo "mouse-1: set/clear bkpt, mouse-3: enable/disable bkpt")
2485 (if enabled (add-text-properties
2486 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2487 (add-text-properties
2488 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2489 (gdb-remove-breakpoint-icons start end)
2490 (if (display-images-p)
2491 (if (>= (or left-fringe-width
2492 (if source-window (car (window-fringes source-window)))
2493 gdb-buffer-fringe-width) 8)
2496 `(left-fringe breakpoint
2499 'breakpoint-disabled)))
2500 (when (< left-margin-width 2)
2501 (save-current-buffer
2502 (setq left-margin-width 2)
2506 left-margin-width right-margin-width))))
2509 (or breakpoint-enabled-icon
2510 (setq breakpoint-enabled-icon
2511 (find-image `((:type xpm :data
2512 ,breakpoint-xpm-data
2513 :ascent 100 :pointer hand)
2515 ,breakpoint-enabled-pbm-data
2516 :ascent 100 :pointer hand)))))
2517 (or breakpoint-disabled-icon
2518 (setq breakpoint-disabled-icon
2519 (find-image `((:type xpm :data
2520 ,breakpoint-xpm-data
2521 :conversion disabled
2524 ,breakpoint-disabled-pbm-data
2529 (when (< left-margin-width 2)
2530 (save-current-buffer
2531 (setq left-margin-width 2)
2532 (if (get-buffer-window (current-buffer) 0)
2534 (get-buffer-window (current-buffer) 0)
2535 left-margin-width right-margin-width))))
2537 (propertize putstring
2538 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2541 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2542 (gdb-remove-strings start end)
2543 (if (display-images-p)
2544 (remove-images start end))
2546 (setq left-margin-width 0)
2547 (if (get-buffer-window (current-buffer) 0)
2549 (get-buffer-window (current-buffer) 0)
2550 left-margin-width right-margin-width))))
2554 ;; Assembler buffer.
2556 (gdb-set-buffer-rules 'gdb-assembler-buffer
2557 'gdb-assembler-buffer-name
2558 'gdb-assembler-mode)
2560 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2561 gdb-invalidate-assembler
2562 (concat gdb-server-prefix "disassemble "
2563 (if (member gdb-frame-address '(nil "main")) nil "0x")
2564 gdb-frame-address "\n")
2565 gdb-assembler-handler
2566 gdb-assembler-custom)
2568 (defun gdb-assembler-custom ()
2569 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2570 (pos 1) (address) (flag) (bptno))
2571 (with-current-buffer buffer
2573 (if (not (equal gdb-frame-address "main"))
2575 (goto-char (point-min))
2576 (if (and gdb-frame-address
2577 (re-search-forward gdb-frame-address nil t))
2581 (or gdb-overlay-arrow-position
2582 (setq gdb-overlay-arrow-position (make-marker)))
2583 (set-marker gdb-overlay-arrow-position
2584 (point) (current-buffer))))))
2585 ;; remove all breakpoint-icons in assembler buffer before updating.
2586 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2587 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2588 (goto-char (point-min))
2589 (while (< (point) (- (point-max) 1))
2591 (if (looking-at "[^\t].*?breakpoint")
2594 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2595 (setq bptno (match-string 1))
2596 (setq flag (char-after (match-beginning 2)))
2597 (setq address (match-string 3))
2598 (with-current-buffer buffer
2600 (goto-char (point-min))
2601 (if (re-search-forward address nil t)
2602 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2603 (if (not (equal gdb-frame-address "main"))
2604 (set-window-point (get-buffer-window buffer 0) pos))))
2606 (defvar gdb-assembler-mode-map
2607 (let ((map (make-sparse-keymap)))
2608 (suppress-keymap map)
2609 (define-key map "q" 'kill-this-buffer)
2612 (defvar gdb-assembler-font-lock-keywords
2613 '(;; <__function.name+n>
2614 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2615 (1 font-lock-function-name-face))
2616 ;; 0xNNNNNNNN <__function.name+n>: opcode
2617 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2618 (4 font-lock-keyword-face))
2619 ;; %register(at least i386)
2620 ("%\\sw+" . font-lock-variable-name-face)
2621 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2622 (1 font-lock-comment-face)
2623 (2 font-lock-function-name-face))
2624 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2625 "Font lock keywords used in `gdb-assembler-mode'.")
2627 (defun gdb-assembler-mode ()
2628 "Major mode for viewing code assembler.
2630 \\{gdb-assembler-mode-map}"
2631 (kill-all-local-variables)
2632 (setq major-mode 'gdb-assembler-mode)
2633 (setq mode-name (concat "Machine:" gdb-selected-frame))
2634 (setq gdb-overlay-arrow-position nil)
2635 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2636 (setq fringes-outside-margins t)
2637 (setq buffer-read-only t)
2638 (use-local-map gdb-assembler-mode-map)
2639 (gdb-invalidate-assembler)
2640 (set (make-local-variable 'font-lock-defaults)
2641 '(gdb-assembler-font-lock-keywords))
2642 (run-mode-hooks 'gdb-assembler-mode-hook)
2643 'gdb-invalidate-assembler)
2645 (defun gdb-assembler-buffer-name ()
2646 (with-current-buffer gud-comint-buffer
2647 (concat "*Disassembly of " (gdb-get-target-string) "*")))
2649 (defun gdb-display-assembler-buffer ()
2650 "Display disassembly view."
2652 (setq gdb-previous-frame nil)
2654 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2656 (defun gdb-frame-assembler-buffer ()
2657 "Display disassembly view in a new frame."
2659 (setq gdb-previous-frame nil)
2660 (let ((special-display-regexps (append special-display-regexps '(".*")))
2661 (special-display-frame-alist gdb-frame-parameters))
2662 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2664 ;; modified because if gdb-frame-address has changed value a new command
2665 ;; must be enqueued to update the buffer with the new output
2666 (defun gdb-invalidate-assembler (&optional ignored)
2667 (if (gdb-get-buffer 'gdb-assembler-buffer)
2669 (unless (and gdb-selected-frame
2670 (string-equal gdb-selected-frame gdb-previous-frame))
2671 (if (or (not (member 'gdb-invalidate-assembler
2672 gdb-pending-triggers))
2673 (not (string-equal gdb-frame-address
2674 gdb-previous-frame-address)))
2676 ;; take previous disassemble command, if any, off the queue
2677 (with-current-buffer gud-comint-buffer
2678 (let ((queue gdb-input-queue))
2679 (dolist (item queue)
2680 (if (equal (cdr item) '(gdb-assembler-handler))
2681 (setq gdb-input-queue
2682 (delete item gdb-input-queue))))))
2685 (concat gdb-server-prefix "disassemble "
2686 (if (member gdb-frame-address '(nil "main")) nil "0x")
2687 gdb-frame-address "\n")
2688 'gdb-assembler-handler))
2689 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2690 (setq gdb-previous-frame-address gdb-frame-address)
2691 (setq gdb-previous-frame gdb-selected-frame)))))))
2693 (defun gdb-get-selected-frame ()
2694 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2697 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2698 (push 'gdb-get-selected-frame
2699 gdb-pending-triggers))))
2701 (defun gdb-frame-handler ()
2702 (setq gdb-pending-triggers
2703 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2704 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2705 (goto-char (point-min))
2706 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2707 (setq gdb-frame-number (match-string 1)))
2708 (goto-char (point-min))
2709 (if (re-search-forward
2710 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2712 (setq gdb-selected-frame (match-string 2))
2713 (if (gdb-get-buffer 'gdb-locals-buffer)
2714 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2715 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2716 (if (gdb-get-buffer 'gdb-assembler-buffer)
2717 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2718 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2719 (setq gdb-frame-address (match-string 1))))
2720 (goto-char (point-min))
2721 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2722 (setq gdb-current-language (match-string 1))))
2723 (gdb-invalidate-assembler))
2727 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2728 ;;; gdb-ui.el ends here