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.")
107 (defvar gdb-buffer-type nil
108 "One of the symbols bound in `gdb-buffer-rules'.")
110 (defvar gdb-input-queue ()
111 "A list of gdb command objects.")
113 (defvar gdb-prompting nil
114 "True when gdb is idle with no pending input.")
116 (defvar gdb-output-sink 'user
117 "The disposition of the output of the current gdb command.
118 Possible values are these symbols:
120 `user' -- gdb output should be copied to the GUD buffer
123 `inferior' -- gdb output should be copied to the inferior-io buffer.
125 `pre-emacs' -- output should be ignored util the post-prompt
126 annotation is received. Then the output-sink
128 `emacs' -- output should be collected in the partial-output-buffer
129 for subsequent processing by a command. This is the
130 disposition of output generated by commands that
131 gdb mode sends to gdb on its own behalf.
132 `post-emacs' -- ignore output until the prompt annotation is
133 received, then go to USER disposition.
135 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
136 \(`user' and `emacs').")
138 (defvar gdb-current-item nil
139 "The most recent command item sent to gdb.")
141 (defvar gdb-pending-triggers '()
142 "A list of trigger functions that have run later than their output
145 ;; end of gdb variables
148 (defun gdba (command-line)
149 "Run gdb on program FILE in buffer *gud-FILE*.
150 The directory containing FILE becomes the initial working directory
151 and source-file directory for your debugger.
153 If `gdb-many-windows' is nil (the default value) then gdb just
154 pops up the GUD buffer unless `gdb-show-main' is t. In this case
155 it starts with two windows: one displaying the GUD buffer and the
156 other with the source file with the main routine of the inferior.
158 If `gdb-many-windows' is t, regardless of the value of
159 `gdb-show-main', the layout below will appear unless
160 `gdb-use-inferior-io-buffer' is nil when the source buffer
161 occupies the full width of the frame. Keybindings are given in
164 Watch expressions appear in the speedbar/slowbar.
166 The following commands help control operation :
168 `gdb-many-windows' - Toggle the number of windows gdb uses.
169 `gdb-restore-windows' - To restore the window layout.
171 See Info node `(emacs)GDB Graphical Interface' for a more
172 detailed description of this mode.
175 ---------------------------------------------------------------------
177 ---------------------------------------------------------------------
178 GUD buffer (I/O of GDB) | Locals buffer
182 ---------------------------------------------------------------------
183 Source buffer | Input/Output (of inferior) buffer
191 ---------------------------------------------------------------------
192 Stack buffer | Breakpoints buffer
193 RET gdb-frames-select | SPC gdb-toggle-breakpoint
194 | RET gdb-goto-breakpoint
195 | d gdb-delete-breakpoint
196 ---------------------------------------------------------------------"
198 (interactive (list (gud-query-cmdline 'gdba)))
200 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
204 (defvar gdb-debug-log nil)
207 (defcustom gdb-enable-debug-log nil
208 "Non-nil means record the process input and output in `gdb-debug-log'."
213 (defcustom gdb-use-inferior-io-buffer nil
214 "Non-nil means display output from the inferior in a separate buffer."
219 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
220 "Shell command for generating a list of defined macros in a source file.
221 This list is used to display the #define directive associated
222 with an identifier as a tooltip. It works in a debug session with
223 GDB, when gud-tooltip-mode is t.
225 Set `gdb-cpp-define-alist-flags' for any include paths or
231 (defcustom gdb-cpp-define-alist-flags ""
232 "Preprocessor flags for `gdb-cpp-define-alist-program'."
237 (defcustom gdb-show-main nil
238 "Non-nil means display source file containing the main routine at startup.
239 Also display the main routine in the disassembly buffer if present."
244 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
246 (defun gdb-create-define-alist ()
247 "Create an alist of #define directives for GUD tooltips."
248 (let* ((file (buffer-file-name))
250 (with-output-to-string
251 (with-current-buffer standard-output
252 (call-process shell-file-name
253 (if (file-exists-p file) file nil)
254 (list t nil) nil "-c"
255 (concat gdb-cpp-define-alist-program " "
256 gdb-cpp-define-alist-flags)))))
257 (define-list (split-string output "\n" t))
259 (setq gdb-define-alist nil)
260 (dolist (define define-list)
261 (setq name (nth 1 (split-string define "[( ]")))
262 (push (cons name define) gdb-define-alist))))
264 (defun gdb-tooltip-print ()
266 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
267 (let ((string (buffer-string)))
268 ;; remove newline for gud-tooltip-echo-area
269 (substring string 0 (- (length string) 1))))
270 (or gud-tooltip-echo-area tooltip-use-echo-area)))
272 ;; If expr is a macro for a function don't print because of possible dangerous
273 ;; side-effects. Also printing a function within a tooltip generates an
274 ;; unexpected starting annotation (phase error).
275 (defun gdb-tooltip-print-1 (expr)
276 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
277 (goto-char (point-min))
278 (if (search-forward "expands to: " nil t)
279 (unless (looking-at "\\S+.*(.*).*")
281 (list (concat gdb-server-prefix "print " expr "\n")
282 'gdb-tooltip-print))))))
284 (defun gdb-set-gud-minor-mode (buffer)
285 "Set `gud-minor-mode' from find-file if appropriate."
286 (goto-char (point-min))
287 (unless (search-forward "No source file named " nil t)
290 (list (concat gdb-server-prefix "info source\n")
291 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
292 (error (setq gdb-find-file-unhook t)))))
294 (defun gdb-set-gud-minor-mode-1 (buffer)
295 (goto-char (point-min))
296 (when (and (search-forward "Located in " nil t)
298 (string-equal (buffer-file-name buffer)
300 (with-current-buffer buffer
301 (set (make-local-variable 'gud-minor-mode) 'gdba)
302 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
303 (when gud-tooltip-mode
304 (make-local-variable 'gdb-define-alist)
305 (gdb-create-define-alist)
306 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
308 (defun gdb-set-gud-minor-mode-existing-buffers ()
309 (dolist (buffer (buffer-list))
310 (let ((file (buffer-file-name buffer)))
314 (list (concat gdb-server-prefix "list "
315 (file-name-nondirectory file) ":1\n")
316 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
319 (setq gdb-debug-log nil)
320 (set (make-local-variable 'gud-minor-mode) 'gdba)
321 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
323 (gud-def gud-break (if (not (string-match "Machine" mode-name))
324 (gud-call "break %f:%l" arg)
328 (gud-call "break *%a" arg)))
329 "\C-b" "Set breakpoint at current line or address.")
331 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
332 (gud-call "clear %f:%l" arg)
336 (gud-call "clear *%a" arg)))
337 "\C-d" "Remove breakpoint at current line or address.")
339 (gud-def gud-until (if (not (string-match "Machine" mode-name))
340 (gud-call "until %f:%l" arg)
344 (gud-call "until *%a" arg)))
345 "\C-u" "Continue to current line or address.")
347 (define-key gud-minor-mode-map [left-margin mouse-1]
348 'gdb-mouse-set-clear-breakpoint)
349 (define-key gud-minor-mode-map [left-fringe mouse-1]
350 'gdb-mouse-set-clear-breakpoint)
351 (define-key gud-minor-mode-map [left-margin mouse-3]
352 'gdb-mouse-toggle-breakpoint)
353 ; Currently only works in margin.
354 ; (define-key gud-minor-mode-map [left-fringe mouse-3]
355 ; 'gdb-mouse-toggle-breakpoint)
357 (setq comint-input-sender 'gdb-send)
360 (setq gdb-frame-address (if gdb-show-main "main" nil))
361 (setq gdb-previous-frame-address nil
362 gdb-memory-address "main"
363 gdb-previous-frame nil
364 gdb-selected-frame nil
365 gdb-current-language nil
373 gdb-pending-triggers nil
374 gdb-output-sink 'user
375 gdb-server-prefix "server "
376 gdb-flush-pending-output nil
377 gdb-location-alist nil
378 gdb-find-file-unhook nil
382 (setq gdb-buffer-type 'gdba)
384 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
386 (if (eq window-system 'w32)
387 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
388 (gdb-enqueue-input (list "set height 0\n" 'ignore))
389 (gdb-enqueue-input (list "set width 0\n" 'ignore))
390 ;; find source file and compilation directory here
391 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
392 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
393 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
395 (gdb-set-gud-minor-mode-existing-buffers)
396 (run-hooks 'gdba-mode-hook))
398 (defcustom gdb-use-colon-colon-notation nil
399 "If non-nil use FUN::VAR format to display variables in the speedbar."
405 "Watch expression at point."
408 (let ((expr (tooltip-identifier-from-point (point))))
409 (if (and (string-equal gdb-current-language "c")
410 gdb-use-colon-colon-notation gdb-selected-frame)
411 (setq expr (concat gdb-selected-frame "::" expr)))
412 (catch 'already-watched
413 (dolist (var gdb-var-list)
414 (if (string-equal expr (car var)) (throw 'already-watched nil)))
415 (set-text-properties 0 (length expr) nil expr)
418 (if (eq gud-minor-mode 'gdba)
419 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
420 (concat"-var-create - * " expr "\n"))
421 `(lambda () (gdb-var-create-handler ,expr))))))
422 (select-window (get-buffer-window gud-comint-buffer 0)))
424 (defconst gdb-var-create-regexp
425 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
427 (defun gdb-var-create-handler (expr)
428 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
429 (goto-char (point-min))
430 (if (re-search-forward gdb-var-create-regexp nil t)
431 (let ((var (list expr
436 (push var gdb-var-list)
438 (if (equal (nth 2 var) "0")
441 (if (with-current-buffer
442 gud-comint-buffer (eq gud-minor-mode 'gdba))
443 (concat "server interpreter mi \"-var-evaluate-expression "
445 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
446 `(lambda () (gdb-var-evaluate-expression-handler
448 (setq gdb-var-changed t)))
449 (if (re-search-forward "Undefined command" nil t)
450 (message-box "Watching expressions requires gdb 6.0 onwards")
451 (message "No symbol \"%s\" in current context." expr)))))
453 (defun gdb-var-evaluate-expression-handler (varnum changed)
454 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
455 (goto-char (point-min))
456 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t)
459 (dolist (var gdb-var-list)
460 (if (string-equal varnum (cadr var))
462 (if changed (setcar (nthcdr 5 var) t))
463 (setcar (nthcdr 4 var) (match-string 1))
464 (setcar (nthcdr num gdb-var-list) var)
465 (throw 'var-found nil)))
466 (setq num (+ num 1))))))
467 (setq gdb-var-changed t))
469 (defun gdb-var-list-children (varnum)
471 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
472 `(lambda () (gdb-var-list-children-handler ,varnum)))))
474 (defconst gdb-var-list-children-regexp
475 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
477 (defun gdb-var-list-children-handler (varnum)
478 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
479 (goto-char (point-min))
480 (let ((var-list nil))
481 (catch 'child-already-watched
482 (dolist (var gdb-var-list)
483 (if (string-equal varnum (cadr var))
486 (while (re-search-forward gdb-var-list-children-regexp nil t)
487 (let ((varchild (list (match-string 2)
491 (if (looking-at ",type=\"\\(.*?\\)\"")
492 (setcar (nthcdr 3 varchild) (match-string 1)))
493 (dolist (var1 gdb-var-list)
494 (if (string-equal (cadr var1) (cadr varchild))
495 (throw 'child-already-watched nil)))
496 (push varchild var-list)
497 (if (equal (nth 2 varchild) "0")
501 "server interpreter mi \"-var-evaluate-expression "
502 (nth 1 varchild) "\"\n")
503 `(lambda () (gdb-var-evaluate-expression-handler
504 ,(nth 1 varchild) nil))))))))
505 (push var var-list)))
506 (setq gdb-var-list (nreverse var-list))))))
508 (defun gdb-var-update ()
509 (when (not (member 'gdb-var-update gdb-pending-triggers))
511 (list "server interpreter mi \"-var-update *\"\n"
512 'gdb-var-update-handler))
513 (push 'gdb-var-update gdb-pending-triggers)))
515 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
517 (defun gdb-var-update-handler ()
518 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
519 (goto-char (point-min))
520 (while (re-search-forward gdb-var-update-regexp nil t)
521 (let ((varnum (match-string 1)))
524 (concat "server interpreter mi \"-var-evaluate-expression "
526 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
527 (setq gdb-pending-triggers
528 (delq 'gdb-var-update gdb-pending-triggers))
529 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
530 ;; Dummy command to update speedbar at right time.
531 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
532 ;; Keep gdb-pending-triggers non-nil till end.
533 (push 'gdb-speedbar-timer gdb-pending-triggers)))
535 (defun gdb-speedbar-timer-fn ()
536 (setq gdb-pending-triggers
537 (delq 'gdb-speedbar-timer gdb-pending-triggers))
538 (with-current-buffer gud-comint-buffer
539 (speedbar-timer-fn)))
541 (defun gdb-var-delete ()
542 "Delete watch expression at point from the speedbar."
544 (if (with-current-buffer
545 gud-comint-buffer (memq gud-minor-mode '(gdbmi gdba)))
546 (let ((text (speedbar-line-text)))
547 (string-match "\\(\\S-+\\)" text)
548 (let* ((expr (match-string 1 text))
549 (var (assoc expr gdb-var-list))
551 (unless (string-match "\\." varnum)
554 (if (with-current-buffer gud-comint-buffer
555 (eq gud-minor-mode 'gdba))
556 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
557 (concat "-var-delete " varnum "\n"))
559 (setq gdb-var-list (delq var gdb-var-list))
560 (dolist (varchild gdb-var-list)
561 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
562 (setq gdb-var-list (delq varchild gdb-var-list))))
563 (setq gdb-var-changed t))))))
565 (defun gdb-edit-value (text token indent)
566 "Assign a value to a variable displayed in the speedbar."
567 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
568 (varnum (cadr var)) (value))
569 (setq value (read-string "New value: "))
572 (if (with-current-buffer gud-comint-buffer
573 (eq gud-minor-mode 'gdba))
574 (concat "server interpreter mi \"-var-assign "
575 varnum " " value "\"\n")
576 (concat "-var-assign " varnum " " value "\n"))
579 (defcustom gdb-show-changed-values t
580 "If non-nil highlight values that have recently changed in the speedbar.
581 The highlighting is done with `font-lock-warning-face'."
586 (defun gdb-speedbar-expand-node (text token indent)
587 "Expand the node the user clicked on.
588 TEXT is the text of the button we clicked on, a + or - item.
589 TOKEN is data related to this node.
590 INDENT is the current indentation depth."
591 (cond ((string-match "+" text) ;expand this node
592 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
593 (gdb-var-list-children token)
596 (gdbmi-var-list-children token))))
597 ((string-match "-" text) ;contract this node
598 (dolist (var gdb-var-list)
599 (if (string-match (concat token "\\.") (nth 1 var))
600 (setq gdb-var-list (delq var gdb-var-list))))
601 (setq gdb-var-changed t))))
603 (defun gdb-get-target-string ()
604 (with-current-buffer gud-comint-buffer
611 ;; Each buffer has a TYPE -- a symbol that identifies the function
612 ;; of that particular buffer.
614 ;; The usual gdb interaction buffer is given the type `gdba' and
615 ;; is constructed specially.
617 ;; Others are constructed by gdb-get-create-buffer and
618 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
620 (defvar gdb-buffer-rules-assoc '())
622 (defun gdb-get-buffer (key)
623 "Return the gdb buffer tagged with type KEY.
624 The key should be one of the cars in `gdb-buffer-rules-assoc'."
626 (gdb-look-for-tagged-buffer key (buffer-list))))
628 (defun gdb-get-create-buffer (key)
629 "Create a new gdb buffer of the type specified by KEY.
630 The key should be one of the cars in `gdb-buffer-rules-assoc'."
631 (or (gdb-get-buffer key)
632 (let* ((rules (assoc key gdb-buffer-rules-assoc))
633 (name (funcall (gdb-rules-name-maker rules)))
634 (new (get-buffer-create name)))
635 (with-current-buffer new
637 (if (cdr (cdr rules))
638 (setq trigger (funcall (car (cdr (cdr rules))))))
639 (set (make-local-variable 'gdb-buffer-type) key)
640 (set (make-local-variable 'gud-minor-mode)
641 (with-current-buffer gud-comint-buffer gud-minor-mode))
642 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
643 (if trigger (funcall trigger)))
646 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
648 (defun gdb-look-for-tagged-buffer (key bufs)
650 (while (and (not retval) bufs)
651 (set-buffer (car bufs))
652 (if (eq gdb-buffer-type key)
653 (setq retval (car bufs)))
654 (setq bufs (cdr bufs)))
658 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
659 ;; at least one and possible more functions. The functions have these
660 ;; roles in defining a buffer type:
662 ;; NAME - Return a name for this buffer type.
664 ;; The remaining function(s) are optional:
666 ;; MODE - called in a new buffer with no arguments, should establish
667 ;; the proper mode for the buffer.
670 (defun gdb-set-buffer-rules (buffer-type &rest rules)
671 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
673 (setcdr binding rules)
674 (push (cons buffer-type rules)
675 gdb-buffer-rules-assoc))))
677 ;; GUD buffers are an exception to the rules
678 (gdb-set-buffer-rules 'gdba 'error)
681 ;; Partial-output buffer : This accumulates output from a command executed on
682 ;; behalf of emacs (rather than the user).
684 (gdb-set-buffer-rules 'gdb-partial-output-buffer
685 'gdb-partial-output-name)
687 (defun gdb-partial-output-name ()
688 (concat "*partial-output-"
689 (gdb-get-target-string)
693 (gdb-set-buffer-rules 'gdb-inferior-io
694 'gdb-inferior-io-name
695 'gdb-inferior-io-mode)
697 (defun gdb-inferior-io-name ()
698 (concat "*input/output of "
699 (gdb-get-target-string)
702 (defun gdb-display-inferior-io-buffer ()
703 "Display IO of inferior in a separate window."
705 (if gdb-use-inferior-io-buffer
707 (gdb-get-create-buffer 'gdb-inferior-io))))
709 (defconst gdb-frame-parameters
710 '((height . 14) (width . 80)
712 (tool-bar-lines . nil)
713 (menu-bar-lines . nil)
716 (defun gdb-frame-inferior-io-buffer ()
717 "Display IO of inferior in a new frame."
719 (if gdb-use-inferior-io-buffer
720 (let ((special-display-regexps (append special-display-regexps '(".*")))
721 (special-display-frame-alist gdb-frame-parameters))
722 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
724 (defvar gdb-inferior-io-mode-map
725 (let ((map (make-sparse-keymap)))
726 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
727 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
728 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
729 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
730 (define-key map "\C-d" 'gdb-inferior-io-eof)
733 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
734 "Major mode for gdb inferior-io."
735 :syntax-table nil :abbrev-table nil
736 ;; We want to use comint because it has various nifty and familiar
737 ;; features. We don't need a process, but comint wants one, so create
739 (make-comint-in-buffer
740 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
741 (current-buffer) "hexl")
742 (setq comint-input-sender 'gdb-inferior-io-sender))
744 (defun gdb-inferior-io-sender (proc string)
745 ;; PROC is the pseudo-process created to satisfy comint.
746 (with-current-buffer (process-buffer proc)
747 (setq proc (get-buffer-process gud-comint-buffer))
748 (process-send-string proc string)
749 (process-send-string proc "\n")))
751 (defun gdb-inferior-io-interrupt ()
752 "Interrupt the program being debugged."
755 (get-buffer-process gud-comint-buffer) comint-ptyp))
757 (defun gdb-inferior-io-quit ()
758 "Send quit signal to the program being debugged."
761 (get-buffer-process gud-comint-buffer) comint-ptyp))
763 (defun gdb-inferior-io-stop ()
764 "Stop the program being debugged."
767 (get-buffer-process gud-comint-buffer) comint-ptyp))
769 (defun gdb-inferior-io-eof ()
770 "Send end-of-file to the program being debugged."
773 (get-buffer-process gud-comint-buffer)))
777 ;; gdb communications
780 ;; INPUT: things sent to gdb
782 ;; The queues are lists. Each element is either a string (indicating user or
783 ;; user-like input) or a list of the form:
785 ;; (INPUT-STRING HANDLER-FN)
787 ;; The handler function will be called from the partial-output buffer when the
788 ;; command completes. This is the way to write commands which invoke gdb
789 ;; commands autonomously.
791 ;; These lists are consumed tail first.
794 (defun gdb-send (proc string)
795 "A comint send filter for gdb.
796 This filter may simply queue input for a later time."
797 (with-current-buffer gud-comint-buffer
798 (remove-text-properties (point-min) (point-max) '(face)))
799 (let ((item (concat string "\n")))
802 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
803 (process-send-string proc item))
804 (gdb-enqueue-input item))))
806 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
807 ;; is a query, or other non-top-level prompt.
809 (defun gdb-enqueue-input (item)
813 (setq gdb-prompting nil))
814 (push item gdb-input-queue)))
816 (defun gdb-dequeue-input ()
817 (let ((queue gdb-input-queue))
819 (let ((last (car (last queue))))
820 (unless (nbutlast queue) (setq gdb-input-queue '()))
823 (defun gdb-send-item (item)
824 (setq gdb-flush-pending-output nil)
825 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
826 (setq gdb-current-item item)
827 (with-current-buffer gud-comint-buffer
828 (if (eq gud-minor-mode 'gdba)
831 (setq gdb-output-sink 'user)
832 (process-send-string (get-buffer-process gud-comint-buffer) item))
834 (gdb-clear-partial-output)
835 (setq gdb-output-sink 'pre-emacs)
836 (process-send-string (get-buffer-process gud-comint-buffer)
838 ;; case: eq gud-minor-mode 'gdbmi
839 (gdb-clear-partial-output)
840 (setq gdb-output-sink 'emacs)
841 (process-send-string (get-buffer-process gud-comint-buffer)
845 ;; output -- things gdb prints to emacs
847 ;; GDB output is a stream interrupted by annotations.
848 ;; Annotations can be recognized by their beginning
849 ;; with \C-j\C-z\C-z<tag><opt>\C-j
851 ;; The tag is a string obeying symbol syntax.
853 ;; The optional part `<opt>' can be either the empty string
854 ;; or a space followed by more data relating to the annotation.
855 ;; For example, the SOURCE annotation is followed by a filename,
856 ;; line number and various useless goo. This data must not include
860 (defcustom gud-gdba-command-name "gdb -annotate=3"
861 "Default command to execute an executable under the GDB-UI debugger."
866 (defvar gdb-annotation-rules
867 '(("pre-prompt" gdb-pre-prompt)
868 ("prompt" gdb-prompt)
869 ("commands" gdb-subprompt)
870 ("overload-choice" gdb-subprompt)
871 ("query" gdb-subprompt)
872 ;; Need this prompt for GDB 6.1
873 ("nquery" gdb-subprompt)
874 ("prompt-for-continue" gdb-subprompt)
875 ("post-prompt" gdb-post-prompt)
876 ("source" gdb-source)
877 ("starting" gdb-starting)
878 ("exited" gdb-exited)
879 ("signalled" gdb-exited)
880 ("signal" gdb-stopping)
881 ("breakpoint" gdb-stopping)
882 ("watchpoint" gdb-stopping)
883 ("frame-begin" gdb-frame-begin)
884 ("stopped" gdb-stopped)
885 ("error-begin" gdb-error)
887 ) "An assoc mapping annotation tags to functions which process them.")
890 (setq gdb-flush-pending-output t)
891 (setq gud-running nil)
892 (setq gdb-output-sink 'user)
893 (setq gdb-input-queue nil)
894 (setq gdb-pending-triggers nil)
895 (setq gdb-prompting t))
897 (defconst gdb-source-spec-regexp
898 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
900 ;; Do not use this except as an annotation handler.
901 (defun gdb-source (args)
902 (string-match gdb-source-spec-regexp args)
903 ;; Extract the frame position from the marker.
906 (match-string 1 args)
907 (string-to-number (match-string 2 args))))
908 (setq gdb-frame-address (match-string 3 args))
909 ;; cover for auto-display output which comes *before*
910 ;; stopped annotation
911 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
913 (defun gdb-pre-prompt (ignored)
914 "An annotation handler for `pre-prompt'.
915 This terminates the collection of output from a previous command if that
916 happens to be in effect."
917 (let ((sink gdb-output-sink))
921 (setq gdb-output-sink 'post-emacs))
924 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
926 (defun gdb-prompt (ignored)
927 "An annotation handler for `prompt'.
928 This sends the next command (if any) to gdb."
929 (when gdb-first-prompt (gdb-ann3))
930 (let ((sink gdb-output-sink))
933 ((eq sink 'post-emacs)
934 (setq gdb-output-sink 'user)
936 (car (cdr gdb-current-item))))
937 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
941 (error "Phase error in gdb-prompt (got %s)" sink))))
942 (let ((input (gdb-dequeue-input)))
944 (gdb-send-item input)
946 (setq gdb-prompting t)
947 (gud-display-frame)))))
949 (defun gdb-subprompt (ignored)
950 "An annotation handler for non-top-level prompts."
951 (setq gdb-prompting t))
953 (defun gdb-starting (ignored)
954 "An annotation handler for `starting'.
955 This says that I/O for the subprocess is now the program being debugged,
957 (setq gdb-active-process t)
958 (let ((sink gdb-output-sink))
963 (if gdb-use-inferior-io-buffer
964 (setq gdb-output-sink 'inferior))))
967 (error "Unexpected `starting' annotation")))))
969 (defun gdb-stopping (ignored)
970 "An annotation handler for `breakpoint' and other annotations.
971 They say that I/O for the subprocess is now GDB, not the program
973 (if gdb-use-inferior-io-buffer
974 (let ((sink gdb-output-sink))
977 (setq gdb-output-sink 'user))
980 (error "Unexpected stopping annotation"))))))
982 (defun gdb-exited (ignored)
983 "An annotation handler for `exited' and `signalled'.
984 They say that I/O for the subprocess is now GDB, not the program
985 being debugged and that the program is no longer running. This
986 function is used to change the focus of GUD tooltips to #define
988 (setq gdb-active-process nil)
989 (gdb-stopping ignored))
991 (defun gdb-frame-begin (ignored)
992 (let ((sink gdb-output-sink))
995 (setq gdb-output-sink 'user))
1000 (error "Unexpected frame-begin annotation (%S)" sink)))))
1002 (defun gdb-stopped (ignored)
1003 "An annotation handler for `stopped'.
1004 It is just like `gdb-stopping', except that if we already set the output
1005 sink to `user' in `gdb-stopping', that is fine."
1006 (setq gud-running nil)
1007 (let ((sink gdb-output-sink))
1009 ((eq sink 'inferior)
1010 (setq gdb-output-sink 'user))
1014 (error "Unexpected stopped annotation")))))
1016 (defun gdb-error (ignored)
1017 (setq gdb-error (not gdb-error)))
1019 (defun gdb-post-prompt (ignored)
1020 "An annotation handler for `post-prompt'.
1021 This begins the collection of output from the current command if that
1022 happens to be appropriate."
1023 (unless gdb-pending-triggers
1024 (gdb-get-selected-frame)
1025 (gdb-invalidate-frames)
1026 (gdb-invalidate-breakpoints)
1027 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1028 ;; so gdb-frame-address is updated.
1029 ;; (gdb-invalidate-assembler)
1030 (gdb-invalidate-registers)
1031 (gdb-invalidate-memory)
1032 (gdb-invalidate-locals)
1033 (gdb-invalidate-threads)
1034 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1035 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1036 ;; Only needed/used with speedbar/watch expressions.
1037 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1038 (setq gdb-var-changed t) ; force update
1039 (dolist (var gdb-var-list)
1040 (setcar (nthcdr 5 var) nil))
1042 (let ((sink gdb-output-sink))
1045 ((eq sink 'pre-emacs)
1046 (setq gdb-output-sink 'emacs))
1049 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1051 (defun gud-gdba-marker-filter (string)
1052 "A gud marker filter for gdb. Handle a burst of output from GDB."
1053 (if gdb-flush-pending-output
1055 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1056 ;; Recall the left over gud-marker-acc from last time.
1057 (setq gud-marker-acc (concat gud-marker-acc string))
1058 ;; Start accumulating output for the GUD buffer.
1061 ;; Process all the complete markers in this chunk.
1062 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1063 (let ((annotation (match-string 1 gud-marker-acc)))
1065 ;; Stuff prior to the match is just ordinary output.
1066 ;; It is either concatenated to OUTPUT or directed
1071 (substring gud-marker-acc 0 (match-beginning 0))))
1073 ;; Take that stuff off the gud-marker-acc.
1074 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1076 ;; Parse the tag from the annotation, and maybe its arguments.
1077 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1078 (let* ((annotation-type (match-string 1 annotation))
1079 (annotation-arguments (match-string 2 annotation))
1080 (annotation-rule (assoc annotation-type
1081 gdb-annotation-rules)))
1082 ;; Call the handler for this annotation.
1084 (funcall (car (cdr annotation-rule))
1085 annotation-arguments)
1086 ;; Else the annotation is not recognized. Ignore it silently,
1087 ;; so that GDB can add new annotations without causing
1091 ;; Does the remaining text end in a partial line?
1092 ;; If it does, then keep part of the gud-marker-acc until we get more.
1093 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1096 ;; Everything before the potential marker start can be output.
1098 (gdb-concat-output output
1099 (substring gud-marker-acc 0
1100 (match-beginning 0))))
1102 ;; Everything after, we save, to combine with later input.
1103 (setq gud-marker-acc (substring gud-marker-acc
1104 (match-beginning 0))))
1106 ;; In case we know the gud-marker-acc contains no partial annotations:
1108 (setq output (gdb-concat-output output gud-marker-acc))
1109 (setq gud-marker-acc "")))
1112 (defun gdb-concat-output (so-far new)
1114 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1115 (let ((sink gdb-output-sink))
1117 ((eq sink 'user) (concat so-far new))
1118 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1120 (gdb-append-to-partial-output new)
1122 ((eq sink 'inferior)
1123 (gdb-append-to-inferior-io new)
1127 (error "Bogon output sink %S" sink)))))
1129 (defun gdb-append-to-partial-output (string)
1130 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1131 (goto-char (point-max))
1134 (defun gdb-clear-partial-output ()
1135 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1138 (defun gdb-append-to-inferior-io (string)
1139 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1140 (goto-char (point-max))
1141 (insert-before-markers string))
1142 (if (not (string-equal string ""))
1143 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1145 (defun gdb-clear-inferior-io ()
1146 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1150 ;; One trick is to have a command who's output is always available in a buffer
1151 ;; of it's own, and is always up to date. We build several buffers of this
1154 ;; There are two aspects to this: gdb has to tell us when the output for that
1155 ;; command might have changed, and we have to be able to run the command
1156 ;; behind the user's back.
1158 ;; The output phasing associated with the variable gdb-output-sink
1159 ;; help us to run commands behind the user's back.
1161 ;; Below is the code for specificly managing buffers of output from one
1165 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1166 ;; It adds an input for the command we are tracking. It should be the
1167 ;; annotation rule binding of whatever gdb sends to tell us this command
1168 ;; might have changed it's output.
1170 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1171 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1172 ;; input in the input queue (see comment about ``gdb communications'' above).
1174 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1176 `(defun ,name (&optional ignored)
1177 (if (and (,demand-predicate)
1179 gdb-pending-triggers)))
1182 (list ,gdb-command ',output-handler))
1183 (push ',name gdb-pending-triggers)))))
1185 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1187 (setq gdb-pending-triggers
1189 gdb-pending-triggers))
1190 (let ((buf (gdb-get-buffer ',buf-key)))
1192 (with-current-buffer buf
1193 (let ((p (window-point (get-buffer-window buf 0)))
1194 (buffer-read-only nil))
1196 (insert-buffer-substring (gdb-get-create-buffer
1197 'gdb-partial-output-buffer))
1198 (set-window-point (get-buffer-window buf 0) p)))))
1199 ;; put customisation here
1202 (defmacro def-gdb-auto-updated-buffer (buffer-key
1203 trigger-name gdb-command
1204 output-handler-name custom-defun)
1206 (def-gdb-auto-update-trigger ,trigger-name
1207 ;; The demand predicate:
1208 (lambda () (gdb-get-buffer ',buffer-key))
1210 ,output-handler-name)
1211 (def-gdb-auto-update-handler ,output-handler-name
1212 ,trigger-name ,buffer-key ,custom-defun)))
1216 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1218 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1219 'gdb-breakpoints-buffer-name
1220 'gdb-breakpoints-mode)
1222 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1223 ;; This defines the auto update rule for buffers of type
1224 ;; `gdb-breakpoints-buffer'.
1226 ;; It defines a function to serve as the annotation handler that
1227 ;; handles the `foo-invalidated' message. That function is called:
1228 gdb-invalidate-breakpoints
1230 ;; To update the buffer, this command is sent to gdb.
1231 "server info breakpoints\n"
1233 ;; This also defines a function to be the handler for the output
1234 ;; from the command above. That function will copy the output into
1235 ;; the appropriately typed buffer. That function will be called:
1236 gdb-info-breakpoints-handler
1237 ;; buffer specific functions
1238 gdb-info-breakpoints-custom)
1240 (defconst breakpoint-xpm-data
1242 static char *magick[] = {
1243 /* columns rows colors chars-per-pixel */
1259 "XPM data used for breakpoint icon.")
1261 (defconst breakpoint-enabled-pbm-data
1264 0 0 0 0 1 1 1 1 0 0 0 0
1265 0 0 0 1 1 1 1 1 1 0 0 0
1266 0 0 1 1 1 1 1 1 1 1 0 0
1267 0 1 1 1 1 1 1 1 1 1 1 0
1268 0 1 1 1 1 1 1 1 1 1 1 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 0 1 1 1 1 1 1 1 1 0 0
1272 0 0 0 1 1 1 1 1 1 0 0 0
1273 0 0 0 0 1 1 1 1 0 0 0 0"
1274 "PBM data used for enabled breakpoint icon.")
1276 (defconst breakpoint-disabled-pbm-data
1288 0 0 0 1 0 1 0 1 0 0"
1289 "PBM data used for disabled breakpoint icon.")
1291 (defvar breakpoint-enabled-icon nil
1292 "Icon for enabled breakpoint in display margin.")
1294 (defvar breakpoint-disabled-icon nil
1295 "Icon for disabled breakpoint in display margin.")
1297 ;; Bitmap for breakpoint in fringe
1298 (and (display-images-p)
1299 (define-fringe-bitmap 'breakpoint
1300 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1302 (defface breakpoint-enabled
1306 "Face for enabled breakpoint icon in fringe."
1308 ;; Compatibility alias for old name.
1309 (put 'breakpoint-enabled-bitmap-face 'face-alias 'breakpoint-enabled)
1311 (defface breakpoint-disabled
1312 ;; We use different values of grey for different background types,
1313 ;; so that on low-color displays it will end up as something visible
1314 ;; if it has to be approximated.
1315 '((((background dark)) :foreground "grey60")
1316 (((background light)) :foreground "grey40"))
1317 "Face for disabled breakpoint icon in fringe."
1320 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1321 (defun gdb-info-breakpoints-custom ()
1322 (let ((flag) (bptno))
1323 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1324 (dolist (buffer (buffer-list))
1325 (with-current-buffer buffer
1326 (if (and (eq gud-minor-mode 'gdba)
1327 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1328 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1329 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1331 (goto-char (point-min))
1332 (while (< (point) (- (point-max) 1))
1334 (if (looking-at "[^\t].*?breakpoint")
1336 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1337 (setq bptno (match-string 1))
1338 (setq flag (char-after (match-beginning 2)))
1340 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1342 (let ((buffer-read-only nil))
1343 (add-text-properties (match-beginning 1) (match-end 1)
1344 '(face font-lock-function-name-face)))
1345 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1346 (let ((line (match-string 2)) (buffer-read-only nil)
1347 (file (match-string 1)))
1348 (add-text-properties (line-beginning-position)
1350 '(mouse-face highlight
1351 help-echo "mouse-2, RET: visit breakpoint"))
1352 (unless (file-exists-p file)
1353 (setq file (cdr (assoc bptno gdb-location-alist))))
1355 (not (string-equal file "File not found")))
1356 (with-current-buffer
1357 (find-file-noselect file 'nowarn)
1358 (set (make-local-variable 'gud-minor-mode)
1360 (set (make-local-variable 'tool-bar-map)
1362 ;; Only want one breakpoint icon at each
1365 (goto-line (string-to-number line))
1366 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1370 (match-string-no-properties 1) ":1\n")
1373 (list "info source\n"
1374 `(lambda () (gdb-get-location
1375 ,bptno ,line ,flag))))))))))
1377 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1379 (defun gdb-mouse-set-clear-breakpoint (event)
1380 "Set/clear breakpoint in left fringe/margin with mouse click."
1382 (mouse-minibuffer-check event)
1383 (let ((posn (event-end event)))
1384 (if (numberp (posn-point posn))
1385 (with-selected-window (posn-window posn)
1387 (goto-char (posn-point posn))
1388 (if (or (posn-object posn)
1389 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1392 (gud-break nil)))))))
1394 (defun gdb-mouse-toggle-breakpoint (event)
1395 "Enable/disable breakpoint in left fringe/margin with mouse click."
1397 (mouse-minibuffer-check event)
1398 (let ((posn (event-end event)))
1399 (if (numberp (posn-point posn))
1400 (with-selected-window (posn-window posn)
1402 (goto-char (posn-point posn))
1403 (if (posn-object posn)
1406 (let ((bptno (get-text-property
1407 0 'gdb-bptno (car (posn-string posn)))))
1409 (if (get-text-property
1410 0 'gdb-enabled (car (posn-string posn)))
1413 bptno "\n")) 'ignore))))))))
1415 (defun gdb-breakpoints-buffer-name ()
1416 (with-current-buffer gud-comint-buffer
1417 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1419 (defun gdb-display-breakpoints-buffer ()
1420 "Display status of user-settable breakpoints."
1423 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1425 (defun gdb-frame-breakpoints-buffer ()
1426 "Display status of user-settable breakpoints in a new frame."
1428 (let ((special-display-regexps (append special-display-regexps '(".*")))
1429 (special-display-frame-alist gdb-frame-parameters))
1430 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1432 (defvar gdb-breakpoints-mode-map
1433 (let ((map (make-sparse-keymap))
1434 (menu (make-sparse-keymap "Breakpoints")))
1435 (define-key menu [quit] '("Quit" . kill-this-buffer))
1436 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1437 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1438 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1439 (suppress-keymap map)
1440 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1441 (define-key map " " 'gdb-toggle-breakpoint)
1442 (define-key map "d" 'gdb-delete-breakpoint)
1443 (define-key map "q" 'kill-this-buffer)
1444 (define-key map "\r" 'gdb-goto-breakpoint)
1445 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1446 (define-key map [follow-link] 'mouse-face)
1449 (defun gdb-breakpoints-mode ()
1450 "Major mode for gdb breakpoints.
1452 \\{gdb-breakpoints-mode-map}"
1453 (kill-all-local-variables)
1454 (setq major-mode 'gdb-breakpoints-mode)
1455 (setq mode-name "Breakpoints")
1456 (use-local-map gdb-breakpoints-mode-map)
1457 (setq buffer-read-only t)
1458 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1459 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1460 'gdb-invalidate-breakpoints
1461 'gdbmi-invalidate-breakpoints))
1463 (defun gdb-toggle-breakpoint ()
1464 "Enable/disable breakpoint at current line."
1467 (beginning-of-line 1)
1468 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1469 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1471 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1474 (concat gdb-server-prefix
1475 (if (eq ?y (char-after (match-beginning 2)))
1478 (match-string 1) "\n") 'ignore))
1479 (error "Not recognized as break/watchpoint line"))))
1481 (defun gdb-delete-breakpoint ()
1482 "Delete the breakpoint at current line."
1484 (beginning-of-line 1)
1485 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1486 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1488 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1491 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1492 (error "Not recognized as break/watchpoint line")))
1494 (defun gdb-goto-breakpoint (&optional event)
1495 "Display the breakpoint location specified at current line."
1496 (interactive (list last-input-event))
1497 (if event (mouse-set-point event))
1499 (beginning-of-line 1)
1500 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1501 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1503 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1504 \\(\\S-+\\):\\([0-9]+\\)"))
1505 (let ((bptno (match-string 1))
1506 (file (match-string 2))
1507 (line (match-string 3)))
1508 (save-selected-window
1509 (let* ((buf (find-file-noselect
1510 (if (file-exists-p file) file
1511 (cdr (assoc bptno gdb-location-alist)))))
1512 (window (display-buffer buf)))
1513 (with-current-buffer buf
1514 (goto-line (string-to-number line))
1515 (set-window-point window (point))))))
1516 (error "Not recognized as break/watchpoint line"))))
1519 ;; Frames buffer. This displays a perpetually correct bactracktrace
1520 ;; (from the command `where').
1522 ;; Alas, if your stack is deep, it is costly.
1524 (gdb-set-buffer-rules 'gdb-stack-buffer
1525 'gdb-stack-buffer-name
1528 (def-gdb-auto-updated-buffer gdb-stack-buffer
1529 gdb-invalidate-frames
1531 gdb-info-frames-handler
1532 gdb-info-frames-custom)
1534 (defun gdb-info-frames-custom ()
1535 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1537 (let ((buffer-read-only nil)
1539 (goto-char (point-min))
1540 (while (< (point) (point-max))
1541 (setq bl (line-beginning-position)
1542 el (line-end-position))
1543 (add-text-properties bl el
1544 '(mouse-face highlight
1545 help-echo "mouse-2, RET: Select frame"))
1547 (when (looking-at "^#\\([0-9]+\\)")
1548 (if (equal (match-string 1) gdb-frame-number)
1549 (put-text-property bl el 'face '(:inverse-video t))
1550 (when (re-search-forward " in \\([^ ]+\\) (" el t)
1551 (put-text-property (match-beginning 1) (match-end 1)
1552 'face font-lock-function-name-face)
1553 (setq bl (match-end 0))
1554 (while (re-search-forward "<\\([^>]+\\)>" el t)
1555 (put-text-property (match-beginning 1) (match-end 1)
1556 'face font-lock-function-name-face))
1558 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1559 (put-text-property (match-beginning 1) (match-end 1)
1560 'face font-lock-variable-name-face))
1562 (forward-line 1))))))
1564 (defun gdb-stack-buffer-name ()
1565 (with-current-buffer gud-comint-buffer
1566 (concat "*stack frames of " (gdb-get-target-string) "*")))
1568 (defun gdb-display-stack-buffer ()
1569 "Display backtrace of current stack."
1572 (gdb-get-create-buffer 'gdb-stack-buffer)))
1574 (defun gdb-frame-stack-buffer ()
1575 "Display backtrace of current stack in a new frame."
1577 (let ((special-display-regexps (append special-display-regexps '(".*")))
1578 (special-display-frame-alist gdb-frame-parameters))
1579 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1581 (defvar gdb-frames-mode-map
1582 (let ((map (make-sparse-keymap)))
1583 (suppress-keymap map)
1584 (define-key map "q" 'kill-this-buffer)
1585 (define-key map "\r" 'gdb-frames-select)
1586 (define-key map [mouse-2] 'gdb-frames-select)
1587 (define-key map [follow-link] 'mouse-face)
1590 (defun gdb-frames-mode ()
1591 "Major mode for gdb frames.
1593 \\{gdb-frames-mode-map}"
1594 (kill-all-local-variables)
1595 (setq major-mode 'gdb-frames-mode)
1596 (setq mode-name "Frames")
1597 (setq buffer-read-only t)
1598 (use-local-map gdb-frames-mode-map)
1600 (run-mode-hooks 'gdb-frames-mode-hook)
1601 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1602 'gdb-invalidate-frames
1603 'gdbmi-invalidate-frames))
1605 (defun gdb-get-frame-number ()
1607 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1608 (n (or (and pos (match-string-no-properties 1)) "0")))
1611 (defun gdb-frames-select (&optional event)
1612 "Select the frame and display the relevant source."
1613 (interactive (list last-input-event))
1614 (if event (mouse-set-point event))
1616 (list (concat gdb-server-prefix "frame "
1617 (gdb-get-frame-number) "\n") 'ignore))
1618 (gud-display-frame))
1621 ;; Threads buffer. This displays a selectable thread list.
1623 (gdb-set-buffer-rules 'gdb-threads-buffer
1624 'gdb-threads-buffer-name
1627 (def-gdb-auto-updated-buffer gdb-threads-buffer
1628 gdb-invalidate-threads
1629 (concat gdb-server-prefix "info threads\n")
1630 gdb-info-threads-handler
1631 gdb-info-threads-custom)
1633 (defun gdb-info-threads-custom ()
1634 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1635 (let ((buffer-read-only nil))
1636 (goto-char (point-min))
1637 (while (< (point) (point-max))
1638 (add-text-properties (line-beginning-position) (line-end-position)
1639 '(mouse-face highlight
1640 help-echo "mouse-2, RET: select thread"))
1641 (forward-line 1)))))
1643 (defun gdb-threads-buffer-name ()
1644 (with-current-buffer gud-comint-buffer
1645 (concat "*threads of " (gdb-get-target-string) "*")))
1647 (defun gdb-display-threads-buffer ()
1648 "Display IDs of currently known threads."
1651 (gdb-get-create-buffer 'gdb-threads-buffer)))
1653 (defun gdb-frame-threads-buffer ()
1654 "Display IDs of currently known threads in a new frame."
1656 (let ((special-display-regexps (append special-display-regexps '(".*")))
1657 (special-display-frame-alist gdb-frame-parameters))
1658 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1660 (defvar gdb-threads-mode-map
1661 (let ((map (make-sparse-keymap)))
1662 (suppress-keymap map)
1663 (define-key map "q" 'kill-this-buffer)
1664 (define-key map "\r" 'gdb-threads-select)
1665 (define-key map [mouse-2] 'gdb-threads-select)
1668 (defvar gdb-threads-font-lock-keywords
1670 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1671 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1672 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1674 "Font lock keywords used in `gdb-threads-mode'.")
1676 (defun gdb-threads-mode ()
1677 "Major mode for gdb frames.
1679 \\{gdb-threads-mode-map}"
1680 (kill-all-local-variables)
1681 (setq major-mode 'gdb-threads-mode)
1682 (setq mode-name "Threads")
1683 (setq buffer-read-only t)
1684 (use-local-map gdb-threads-mode-map)
1685 (set (make-local-variable 'font-lock-defaults)
1686 '(gdb-threads-font-lock-keywords))
1687 (run-mode-hooks 'gdb-threads-mode-hook)
1688 'gdb-invalidate-threads)
1690 (defun gdb-get-thread-number ()
1692 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1693 (match-string-no-properties 1)))
1695 (defun gdb-threads-select (&optional event)
1696 "Select the thread and display the relevant source."
1697 (interactive (list last-input-event))
1698 (if event (mouse-set-point event))
1700 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1701 (gud-display-frame))
1704 ;; Registers buffer.
1706 (defcustom gdb-all-registers nil
1707 "Non-nil means include floating-point registers."
1712 (gdb-set-buffer-rules 'gdb-registers-buffer
1713 'gdb-registers-buffer-name
1714 'gdb-registers-mode)
1716 (def-gdb-auto-updated-buffer gdb-registers-buffer
1717 gdb-invalidate-registers
1719 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1720 gdb-info-registers-handler
1721 gdb-info-registers-custom)
1723 (defun gdb-info-registers-custom ())
1725 (defvar gdb-registers-mode-map
1726 (let ((map (make-sparse-keymap)))
1727 (suppress-keymap map)
1728 (define-key map " " 'toggle-gdb-all-registers)
1729 (define-key map "q" 'kill-this-buffer)
1732 (defvar gdb-registers-font-lock-keywords
1734 ("^[^ ]+" . font-lock-variable-name-face)
1736 "Font lock keywords used in `gdb-registers-mode'.")
1738 (defun gdb-registers-mode ()
1739 "Major mode for gdb registers.
1741 \\{gdb-registers-mode-map}"
1742 (kill-all-local-variables)
1743 (setq major-mode 'gdb-registers-mode)
1744 (setq mode-name "Registers:")
1745 (setq buffer-read-only t)
1746 (use-local-map gdb-registers-mode-map)
1747 (set (make-local-variable 'font-lock-defaults)
1748 '(gdb-registers-font-lock-keywords))
1749 (run-mode-hooks 'gdb-registers-mode-hook)
1750 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1751 'gdb-invalidate-registers
1752 'gdbmi-invalidate-registers))
1754 (defun gdb-registers-buffer-name ()
1755 (with-current-buffer gud-comint-buffer
1756 (concat "*registers of " (gdb-get-target-string) "*")))
1758 (defun gdb-display-registers-buffer ()
1759 "Display integer register contents."
1762 (gdb-get-create-buffer 'gdb-registers-buffer)))
1764 (defun gdb-frame-registers-buffer ()
1765 "Display integer register contents in a new frame."
1767 (let ((special-display-regexps (append special-display-regexps '(".*")))
1768 (special-display-frame-alist gdb-frame-parameters))
1769 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1771 (defun toggle-gdb-all-registers ()
1772 "Toggle the display of floating-point registers."
1774 (if gdb-all-registers
1776 (setq gdb-all-registers nil)
1777 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1778 (setq mode-name "Registers:")))
1779 (setq gdb-all-registers t)
1780 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1781 (setq mode-name "Registers:All")))
1782 (gdb-invalidate-registers))
1787 (defcustom gdb-memory-repeat-count 32
1788 "Number of data items in memory window."
1793 (defcustom gdb-memory-format "x"
1794 "Display format of data items in memory window."
1795 :type '(choice (const :tag "Hexadecimal" "x")
1796 (const :tag "Signed decimal" "d")
1797 (const :tag "Unsigned decimal" "u")
1798 (const :tag "Octal" "o")
1799 (const :tag "Binary" "t"))
1803 (defcustom gdb-memory-unit "w"
1804 "Unit size of data items in memory window."
1805 :type '(choice (const :tag "Byte" "b")
1806 (const :tag "Halfword" "h")
1807 (const :tag "Word" "w")
1808 (const :tag "Giant word" "g"))
1812 (gdb-set-buffer-rules 'gdb-memory-buffer
1813 'gdb-memory-buffer-name
1816 (def-gdb-auto-updated-buffer gdb-memory-buffer
1817 gdb-invalidate-memory
1818 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1819 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1820 gdb-read-memory-handler
1821 gdb-read-memory-custom)
1823 (defun gdb-read-memory-custom ()
1825 (goto-char (point-min))
1826 (if (looking-at "0x[[:xdigit:]]+")
1827 (setq gdb-memory-address (match-string 0)))))
1829 (defvar gdb-memory-mode-map
1830 (let ((map (make-sparse-keymap)))
1831 (suppress-keymap map)
1832 (define-key map "q" 'kill-this-buffer)
1835 (defun gdb-memory-set-address (event)
1836 "Set the start memory address."
1838 (save-selected-window
1839 (select-window (posn-window (event-start event)))
1840 (let ((arg (read-from-minibuffer "Memory address: ")))
1841 (setq gdb-memory-address arg))
1842 (gdb-invalidate-memory)))
1844 (defun gdb-memory-set-repeat-count (event)
1845 "Set the number of data items in memory window."
1847 (save-selected-window
1848 (select-window (posn-window (event-start event)))
1849 (let* ((arg (read-from-minibuffer "Repeat count: "))
1850 (count (string-to-number arg)))
1852 (error "Positive numbers only")
1853 (customize-set-variable 'gdb-memory-repeat-count count)
1854 (gdb-invalidate-memory)))))
1856 (defun gdb-memory-format-binary ()
1857 "Set the display format to binary."
1859 (customize-set-variable 'gdb-memory-format "t")
1860 (gdb-invalidate-memory))
1862 (defun gdb-memory-format-octal ()
1863 "Set the display format to octal."
1865 (customize-set-variable 'gdb-memory-format "o")
1866 (gdb-invalidate-memory))
1868 (defun gdb-memory-format-unsigned ()
1869 "Set the display format to unsigned decimal."
1871 (customize-set-variable 'gdb-memory-format "u")
1872 (gdb-invalidate-memory))
1874 (defun gdb-memory-format-signed ()
1875 "Set the display format to decimal."
1877 (customize-set-variable 'gdb-memory-format "d")
1878 (gdb-invalidate-memory))
1880 (defun gdb-memory-format-hexadecimal ()
1881 "Set the display format to hexadecimal."
1883 (customize-set-variable 'gdb-memory-format "x")
1884 (gdb-invalidate-memory))
1886 (defvar gdb-memory-format-keymap
1887 (let ((map (make-sparse-keymap)))
1888 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1890 "Keymap to select format in the header line.")
1892 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1893 "Menu of display formats in the header line.")
1895 (define-key gdb-memory-format-menu [binary]
1896 '(menu-item "Binary" gdb-memory-format-binary
1897 :button (:radio . (equal gdb-memory-format "t"))))
1898 (define-key gdb-memory-format-menu [octal]
1899 '(menu-item "Octal" gdb-memory-format-octal
1900 :button (:radio . (equal gdb-memory-format "o"))))
1901 (define-key gdb-memory-format-menu [unsigned]
1902 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
1903 :button (:radio . (equal gdb-memory-format "u"))))
1904 (define-key gdb-memory-format-menu [signed]
1905 '(menu-item "Signed Decimal" gdb-memory-format-signed
1906 :button (:radio . (equal gdb-memory-format "d"))))
1907 (define-key gdb-memory-format-menu [hexadecimal]
1908 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
1909 :button (:radio . (equal gdb-memory-format "x"))))
1911 (defun gdb-memory-format-menu (event)
1913 (x-popup-menu event gdb-memory-format-menu))
1915 (defun gdb-memory-format-menu-1 (event)
1917 (save-selected-window
1918 (select-window (posn-window (event-start event)))
1919 (let* ((selection (gdb-memory-format-menu event))
1920 (binding (and selection (lookup-key gdb-memory-format-menu
1921 (vector (car selection))))))
1922 (if binding (call-interactively binding)))))
1924 (defun gdb-memory-unit-giant ()
1925 "Set the unit size to giant words (eight bytes)."
1927 (customize-set-variable 'gdb-memory-unit "g")
1928 (gdb-invalidate-memory))
1930 (defun gdb-memory-unit-word ()
1931 "Set the unit size to words (four bytes)."
1933 (customize-set-variable 'gdb-memory-unit "w")
1934 (gdb-invalidate-memory))
1936 (defun gdb-memory-unit-halfword ()
1937 "Set the unit size to halfwords (two bytes)."
1939 (customize-set-variable 'gdb-memory-unit "h")
1940 (gdb-invalidate-memory))
1942 (defun gdb-memory-unit-byte ()
1943 "Set the unit size to bytes."
1945 (customize-set-variable 'gdb-memory-unit "b")
1946 (gdb-invalidate-memory))
1948 (defvar gdb-memory-unit-keymap
1949 (let ((map (make-sparse-keymap)))
1950 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
1952 "Keymap to select units in the header line.")
1954 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
1955 "Menu of units in the header line.")
1957 (define-key gdb-memory-unit-menu [giantwords]
1958 '(menu-item "Giant words" gdb-memory-unit-giant
1959 :button (:radio . (equal gdb-memory-unit "g"))))
1960 (define-key gdb-memory-unit-menu [words]
1961 '(menu-item "Words" gdb-memory-unit-word
1962 :button (:radio . (equal gdb-memory-unit "w"))))
1963 (define-key gdb-memory-unit-menu [halfwords]
1964 '(menu-item "Halfwords" gdb-memory-unit-halfword
1965 :button (:radio . (equal gdb-memory-unit "h"))))
1966 (define-key gdb-memory-unit-menu [bytes]
1967 '(menu-item "Bytes" gdb-memory-unit-byte
1968 :button (:radio . (equal gdb-memory-unit "b"))))
1970 (defun gdb-memory-unit-menu (event)
1972 (x-popup-menu event gdb-memory-unit-menu))
1974 (defun gdb-memory-unit-menu-1 (event)
1976 (save-selected-window
1977 (select-window (posn-window (event-start event)))
1978 (let* ((selection (gdb-memory-unit-menu event))
1979 (binding (and selection (lookup-key gdb-memory-unit-menu
1980 (vector (car selection))))))
1981 (if binding (call-interactively binding)))))
1983 ;;from make-mode-line-mouse-map
1984 (defun gdb-make-header-line-mouse-map (mouse function) "\
1985 Return a keymap with single entry for mouse key MOUSE on the header line.
1986 MOUSE is defined to run function FUNCTION with no args in the buffer
1987 corresponding to the mode line clicked."
1988 (let ((map (make-sparse-keymap)))
1989 (define-key map (vector 'header-line mouse) function)
1990 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
1993 (defvar gdb-memory-font-lock-keywords
1994 '(;; <__function.name+n>
1995 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
1997 "Font lock keywords used in `gdb-memory-mode'.")
1999 (defun gdb-memory-mode ()
2000 "Major mode for examining memory.
2002 \\{gdb-memory-mode-map}"
2003 (kill-all-local-variables)
2004 (setq major-mode 'gdb-memory-mode)
2005 (setq mode-name "Memory")
2006 (setq buffer-read-only t)
2007 (use-local-map gdb-memory-mode-map)
2008 (setq header-line-format
2014 'face font-lock-warning-face
2015 'help-echo "mouse-1: Decrement address"
2016 'mouse-face 'mode-line-highlight
2018 (gdb-make-header-line-mouse-map
2020 #'(lambda () (interactive)
2021 (let ((gdb-memory-address
2022 ;; Let GDB do the arithmetic.
2024 gdb-memory-address " - "
2026 (* gdb-memory-repeat-count
2027 (cond ((string= gdb-memory-unit "b") 1)
2028 ((string= gdb-memory-unit "h") 2)
2029 ((string= gdb-memory-unit "w") 4)
2030 ((string= gdb-memory-unit "g") 8)))))))
2031 (gdb-invalidate-memory)))))
2034 'face font-lock-warning-face
2035 'help-echo "mouse-1: Increment address"
2036 'mouse-face 'mode-line-highlight
2037 'local-map (gdb-make-header-line-mouse-map
2039 #'(lambda () (interactive)
2040 (let ((gdb-memory-address nil))
2041 (gdb-invalidate-memory)))))
2043 (propertize gdb-memory-address
2044 'face font-lock-warning-face
2045 'help-echo "mouse-1: Set memory address"
2046 'mouse-face 'mode-line-highlight
2047 'local-map (gdb-make-header-line-mouse-map
2049 #'gdb-memory-set-address))
2051 (propertize (number-to-string gdb-memory-repeat-count)
2052 'face font-lock-warning-face
2053 'help-echo "mouse-1: Set repeat count"
2054 'mouse-face 'mode-line-highlight
2055 'local-map (gdb-make-header-line-mouse-map
2057 #'gdb-memory-set-repeat-count))
2059 (propertize gdb-memory-format
2060 'face font-lock-warning-face
2061 'help-echo "mouse-3: Select display format"
2062 'mouse-face 'mode-line-highlight
2063 'local-map gdb-memory-format-keymap)
2065 (propertize gdb-memory-unit
2066 'face font-lock-warning-face
2067 'help-echo "mouse-3: Select unit size"
2068 'mouse-face 'mode-line-highlight
2069 'local-map gdb-memory-unit-keymap))))
2070 (set (make-local-variable 'font-lock-defaults)
2071 '(gdb-memory-font-lock-keywords))
2072 (run-mode-hooks 'gdb-memory-mode-hook)
2073 'gdb-invalidate-memory)
2075 (defun gdb-memory-buffer-name ()
2076 (with-current-buffer gud-comint-buffer
2077 (concat "*memory of " (gdb-get-target-string) "*")))
2079 (defun gdb-display-memory-buffer ()
2080 "Display memory contents."
2083 (gdb-get-create-buffer 'gdb-memory-buffer)))
2085 (defun gdb-frame-memory-buffer ()
2086 "Display memory contents in a new frame."
2088 (let ((special-display-regexps (append special-display-regexps '(".*")))
2089 (special-display-frame-alist gdb-frame-parameters))
2090 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2095 (gdb-set-buffer-rules 'gdb-locals-buffer
2096 'gdb-locals-buffer-name
2099 (def-gdb-auto-updated-buffer gdb-locals-buffer
2100 gdb-invalidate-locals
2101 "server info locals\n"
2102 gdb-info-locals-handler
2103 gdb-info-locals-custom)
2105 ;; Abbreviate for arrays and structures.
2106 ;; These can be expanded using gud-display.
2107 (defun gdb-info-locals-handler nil
2108 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2109 gdb-pending-triggers))
2110 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2111 (with-current-buffer buf
2112 (goto-char (point-min))
2113 (while (re-search-forward "^[ }].*\n" nil t)
2114 (replace-match "" nil nil))
2115 (goto-char (point-min))
2116 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2117 (replace-match "(structure);\n" nil nil))
2118 (goto-char (point-min))
2119 (while (re-search-forward "\\s-*{.*\n" nil t)
2120 (replace-match " (array);\n" nil nil))))
2121 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2122 (and buf (with-current-buffer buf
2123 (let ((p (window-point (get-buffer-window buf 0)))
2124 (buffer-read-only nil))
2126 (insert-buffer-substring (gdb-get-create-buffer
2127 'gdb-partial-output-buffer))
2128 (set-window-point (get-buffer-window buf 0) p)))))
2129 (run-hooks 'gdb-info-locals-hook))
2131 (defun gdb-info-locals-custom ()
2134 (defvar gdb-locals-mode-map
2135 (let ((map (make-sparse-keymap)))
2136 (suppress-keymap map)
2137 (define-key map "q" 'kill-this-buffer)
2140 (defvar gdb-local-font-lock-keywords
2142 ;; var = (struct struct_tag) value
2143 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2144 (1 font-lock-variable-name-face)
2145 (3 font-lock-keyword-face)
2146 (4 font-lock-type-face))
2147 ;; var = (type) value
2148 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2149 (1 font-lock-variable-name-face)
2150 (3 font-lock-type-face))
2152 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2153 (1 font-lock-variable-name-face))
2155 "Font lock keywords used in `gdb-local-mode'.")
2157 (defun gdb-locals-mode ()
2158 "Major mode for gdb locals.
2160 \\{gdb-locals-mode-map}"
2161 (kill-all-local-variables)
2162 (setq major-mode 'gdb-locals-mode)
2163 (setq mode-name (concat "Locals:" gdb-selected-frame))
2164 (setq buffer-read-only t)
2165 (use-local-map gdb-locals-mode-map)
2166 (set (make-local-variable 'font-lock-defaults)
2167 '(gdb-local-font-lock-keywords))
2168 (run-mode-hooks 'gdb-locals-mode-hook)
2169 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
2170 'gdb-invalidate-locals
2171 'gdbmi-invalidate-locals))
2173 (defun gdb-locals-buffer-name ()
2174 (with-current-buffer gud-comint-buffer
2175 (concat "*locals of " (gdb-get-target-string) "*")))
2177 (defun gdb-display-locals-buffer ()
2178 "Display local variables of current stack and their values."
2181 (gdb-get-create-buffer 'gdb-locals-buffer)))
2183 (defun gdb-frame-locals-buffer ()
2184 "Display local variables of current stack and their values in a new frame."
2186 (let ((special-display-regexps (append special-display-regexps '(".*")))
2187 (special-display-frame-alist gdb-frame-parameters))
2188 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2191 ;;;; Window management
2192 (defun gdb-display-buffer (buf &optional size)
2193 (let ((answer (get-buffer-window buf 0))
2196 (display-buffer buf nil 0) ;Raise the frame if necessary.
2197 ;; The buffer is not yet displayed.
2198 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2199 (let ((window (get-lru-window)))
2201 (not (eq window (get-buffer-window gud-comint-buffer))))
2203 (set-window-buffer window buf)
2204 (setq answer window))
2205 (setq must-split t)))
2207 (let* ((largest (get-largest-window))
2208 (cur-size (window-height largest))
2209 (new-size (and size (< size cur-size) (- cur-size size))))
2210 (setq answer (split-window largest new-size))
2211 (set-window-buffer answer buf)
2212 (set-window-dedicated-p answer t)))
2216 ;;; Shared keymap initialization:
2218 (let ((menu (make-sparse-keymap "GDB-Windows")))
2219 (define-key gud-menu-map [displays]
2220 `(menu-item "GDB-Windows" ,menu
2221 :visible (memq gud-minor-mode '(gdbmi gdba))))
2222 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2223 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2224 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2225 (define-key menu [disassembly]
2226 '("Disassembly" . gdb-display-assembler-buffer))
2227 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2228 (define-key menu [inferior]
2229 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2230 :enable gdb-use-inferior-io-buffer))
2231 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2232 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2233 (define-key menu [breakpoints]
2234 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2236 (let ((menu (make-sparse-keymap "GDB-Frames")))
2237 (define-key gud-menu-map [frames]
2238 `(menu-item "GDB-Frames" ,menu
2239 :visible (memq gud-minor-mode '(gdbmi gdba))))
2240 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2241 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2242 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2243 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2244 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2245 (define-key menu [inferior]
2246 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2247 :enable gdb-use-inferior-io-buffer))
2248 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2249 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2250 (define-key menu [breakpoints]
2251 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2253 (let ((menu (make-sparse-keymap "GDB-UI")))
2254 (define-key gud-menu-map [ui]
2255 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2256 (define-key menu [gdb-use-inferior-io]
2257 ;; See defadvice below.
2258 (menu-bar-make-toggle toggle-gdb-use-inferior-io-buffer
2259 gdb-use-inferior-io-buffer
2260 "Separate inferior IO" "Use separate IO %s"
2261 "Toggle separate IO for inferior."))
2262 (define-key menu [gdb-many-windows]
2263 '(menu-item "Display Other Windows" gdb-many-windows
2264 :help "Toggle display of locals, stack and breakpoint information"
2265 :button (:toggle . gdb-many-windows)))
2266 (define-key menu [gdb-restore-windows]
2267 '(menu-item "Restore Window Layout" gdb-restore-windows
2268 :help "Restore standard layout for debug session.")))
2270 ;; This function is defined above through a macro.
2271 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
2272 (unless gdb-use-inferior-io-buffer
2273 (kill-buffer (gdb-inferior-io-name))))
2275 (defun gdb-frame-gdb-buffer ()
2276 "Display GUD buffer in a new frame."
2278 (select-frame (make-frame gdb-frame-parameters))
2279 (switch-to-buffer (gdb-get-create-buffer 'gdba))
2280 (set-window-dedicated-p (selected-window) t))
2282 (defun gdb-display-gdb-buffer ()
2283 "Display GUD buffer."
2286 (gdb-get-create-buffer 'gdba)))
2288 (defun gdb-set-window-buffer (name)
2289 (set-window-buffer (selected-window) (get-buffer name))
2290 (set-window-dedicated-p (selected-window) t))
2292 (defun gdb-setup-windows ()
2293 "Layout the window pattern for `gdb-many-windows'."
2294 (gdb-display-locals-buffer)
2295 (gdb-display-stack-buffer)
2296 (delete-other-windows)
2297 (gdb-display-breakpoints-buffer)
2298 (delete-other-windows)
2300 (pop-to-buffer gud-comint-buffer)
2301 (split-window nil ( / ( * (window-height) 3) 4))
2302 (split-window nil ( / (window-height) 3))
2303 (split-window-horizontally)
2305 (gdb-set-window-buffer (gdb-locals-buffer-name))
2308 (if gud-last-last-frame
2309 (gud-find-file (car gud-last-last-frame))
2310 (gud-find-file gdb-main-file)))
2311 (when gdb-use-inferior-io-buffer
2312 (split-window-horizontally)
2314 (gdb-set-window-buffer
2315 (gdb-get-create-buffer 'gdb-inferior-io)))
2317 (gdb-set-window-buffer (gdb-stack-buffer-name))
2318 (split-window-horizontally)
2320 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2323 (defcustom gdb-many-windows nil
2324 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2325 In this case it starts with two windows: one displaying the GUD
2326 buffer and the other with the source file with the main routine
2327 of the inferior. Non-nil means display the layout shown for
2333 (defun gdb-many-windows (arg)
2334 "Toggle the number of windows in the basic arrangement."
2336 (setq gdb-many-windows
2338 (not gdb-many-windows)
2339 (> (prefix-numeric-value arg) 0)))
2341 (gdb-restore-windows)
2344 (defun gdb-restore-windows ()
2345 "Restore the basic arrangement of windows used by gdba.
2346 This arrangement depends on the value of `gdb-many-windows'."
2348 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2349 (delete-other-windows)
2350 (if gdb-many-windows
2355 (if gud-last-last-frame
2356 (gud-find-file (car gud-last-last-frame))
2357 (gud-find-file gdb-main-file)))
2361 "Exit a debugging session cleanly.
2362 Kills the gdb buffers and resets the source buffers."
2363 (dolist (buffer (buffer-list))
2364 (unless (eq buffer gud-comint-buffer)
2365 (with-current-buffer buffer
2366 (if (memq gud-minor-mode '(gdbmi gdba))
2367 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2369 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2370 (setq gud-minor-mode nil)
2371 (kill-local-variable 'tool-bar-map)
2372 (kill-local-variable 'gdb-define-alist))))))
2373 (when (markerp gdb-overlay-arrow-position)
2374 (move-marker gdb-overlay-arrow-position nil)
2375 (setq gdb-overlay-arrow-position nil))
2376 (setq overlay-arrow-variable-list
2377 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2378 (setq gud-running nil)
2379 (setq gdb-active-process nil)
2380 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2382 (defun gdb-source-info ()
2383 "Find the source file where the program starts and displays it with related
2385 (goto-char (point-min))
2386 (if (and (search-forward "Located in " nil t)
2387 (looking-at "\\S-+"))
2388 (setq gdb-main-file (match-string 0)))
2389 (goto-char (point-min))
2390 (if (search-forward "Includes preprocessor macro info." nil t)
2391 (setq gdb-macro-info t))
2392 (if gdb-many-windows
2394 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2396 (let ((pop-up-windows t))
2397 (display-buffer (gud-find-file gdb-main-file))))))
2399 (defun gdb-get-location (bptno line flag)
2400 "Find the directory containing the relevant source file.
2401 Put in buffer and place breakpoint icon."
2402 (goto-char (point-min))
2403 (catch 'file-not-found
2404 (if (search-forward "Located in " nil t)
2405 (when (looking-at "\\S-+")
2406 (delete (cons bptno "File not found") gdb-location-alist)
2407 (push (cons bptno (match-string 0)) gdb-location-alist))
2409 (unless (assoc bptno gdb-location-alist)
2410 (push (cons bptno "File not found") gdb-location-alist)
2411 (message-box "Cannot find source file for breakpoint location.\n\
2412 Add directory to search path for source files using the GDB command, dir."))
2413 (throw 'file-not-found nil))
2414 (with-current-buffer
2415 (find-file-noselect (match-string 0))
2416 (save-current-buffer
2417 (set (make-local-variable 'gud-minor-mode) 'gdba)
2418 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2419 ;; only want one breakpoint icon at each location
2421 (goto-line (string-to-number line))
2422 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2424 (add-hook 'find-file-hook 'gdb-find-file-hook)
2426 (defun gdb-find-file-hook ()
2427 "Set up buffer for debugging if file is part of the source code
2428 of the current session."
2429 (if (and (not gdb-find-file-unhook)
2430 ;; in case gud or gdb-ui is just loaded
2432 (buffer-name gud-comint-buffer)
2433 (with-current-buffer gud-comint-buffer
2434 (eq gud-minor-mode 'gdba)))
2437 (list (concat gdb-server-prefix "list "
2438 (file-name-nondirectory buffer-file-name)
2440 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2441 (error (setq gdb-find-file-unhook t)))))
2444 (defun gdb-put-string (putstring pos &optional dprop)
2445 "Put string PUTSTRING in front of POS in the current buffer.
2446 PUTSTRING is displayed by putting an overlay into the current buffer with a
2447 `before-string' string that has a `display' property whose value is
2449 (let ((string (make-string 1 ?x))
2450 (buffer (current-buffer)))
2451 (setq putstring (copy-sequence putstring))
2452 (let ((overlay (make-overlay pos pos buffer))
2454 (list (list 'margin 'left-margin) putstring))))
2455 (put-text-property 0 (length string) 'display prop string)
2456 (overlay-put overlay 'put-break t)
2457 (overlay-put overlay 'before-string string))))
2459 ;;from remove-images
2460 (defun gdb-remove-strings (start end &optional buffer)
2461 "Remove strings between START and END in BUFFER.
2462 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2463 BUFFER nil or omitted means use the current buffer."
2465 (setq buffer (current-buffer)))
2466 (dolist (overlay (overlays-in start end))
2467 (when (overlay-get overlay 'put-break)
2468 (delete-overlay overlay))))
2470 (defun gdb-put-breakpoint-icon (enabled bptno)
2471 (let ((start (- (line-beginning-position) 1))
2472 (end (+ (line-end-position) 1))
2473 (putstring (if enabled "B" "b")))
2474 (add-text-properties
2475 0 1 '(help-echo "mouse-1: set/clear bkpt, mouse-3: enable/disable bkpt")
2477 (if enabled (add-text-properties
2478 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2479 (add-text-properties
2480 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2481 (gdb-remove-breakpoint-icons start end)
2482 (if (display-images-p)
2483 (if (>= (car (window-fringes)) 8)
2486 `(left-fringe breakpoint
2489 'breakpoint-disabled)))
2490 (when (< left-margin-width 2)
2491 (save-current-buffer
2492 (setq left-margin-width 2)
2493 (if (get-buffer-window (current-buffer) 0)
2495 (get-buffer-window (current-buffer) 0)
2496 left-margin-width right-margin-width))))
2499 (or breakpoint-enabled-icon
2500 (setq breakpoint-enabled-icon
2501 (find-image `((:type xpm :data
2502 ,breakpoint-xpm-data
2503 :ascent 100 :pointer hand)
2505 ,breakpoint-enabled-pbm-data
2506 :ascent 100 :pointer hand)))))
2507 (or breakpoint-disabled-icon
2508 (setq breakpoint-disabled-icon
2509 (find-image `((:type xpm :data
2510 ,breakpoint-xpm-data
2511 :conversion disabled
2514 ,breakpoint-disabled-pbm-data
2519 (when (< left-margin-width 2)
2520 (save-current-buffer
2521 (setq left-margin-width 2)
2522 (if (get-buffer-window (current-buffer) 0)
2524 (get-buffer-window (current-buffer) 0)
2525 left-margin-width right-margin-width))))
2527 (propertize putstring
2528 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2531 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2532 (gdb-remove-strings start end)
2533 (if (display-images-p)
2534 (remove-images start end))
2536 (setq left-margin-width 0)
2537 (if (get-buffer-window (current-buffer) 0)
2539 (get-buffer-window (current-buffer) 0)
2540 left-margin-width right-margin-width))))
2544 ;; Assembler buffer.
2546 (gdb-set-buffer-rules 'gdb-assembler-buffer
2547 'gdb-assembler-buffer-name
2548 'gdb-assembler-mode)
2550 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2551 gdb-invalidate-assembler
2552 (concat gdb-server-prefix "disassemble "
2553 (if (member gdb-frame-address '(nil "main")) nil "0x")
2554 gdb-frame-address "\n")
2555 gdb-assembler-handler
2556 gdb-assembler-custom)
2558 (defun gdb-assembler-custom ()
2559 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2560 (pos 1) (address) (flag) (bptno))
2561 (with-current-buffer buffer
2563 (if (not (equal gdb-frame-address "main"))
2565 (goto-char (point-min))
2566 (if (and gdb-frame-address
2567 (re-search-forward gdb-frame-address nil t))
2571 (or gdb-overlay-arrow-position
2572 (setq gdb-overlay-arrow-position (make-marker)))
2573 (set-marker gdb-overlay-arrow-position
2574 (point) (current-buffer))))))
2575 ;; remove all breakpoint-icons in assembler buffer before updating.
2576 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2577 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2578 (goto-char (point-min))
2579 (while (< (point) (- (point-max) 1))
2581 (if (looking-at "[^\t].*?breakpoint")
2584 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2585 (setq bptno (match-string 1))
2586 (setq flag (char-after (match-beginning 2)))
2587 (setq address (match-string 3))
2588 (with-current-buffer buffer
2590 (goto-char (point-min))
2591 (if (re-search-forward address nil t)
2592 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2593 (if (not (equal gdb-frame-address "main"))
2594 (set-window-point (get-buffer-window buffer 0) pos))))
2596 (defvar gdb-assembler-mode-map
2597 (let ((map (make-sparse-keymap)))
2598 (suppress-keymap map)
2599 (define-key map "q" 'kill-this-buffer)
2602 (defvar gdb-assembler-font-lock-keywords
2603 '(;; <__function.name+n>
2604 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2605 (1 font-lock-function-name-face))
2606 ;; 0xNNNNNNNN <__function.name+n>: opcode
2607 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2608 (4 font-lock-keyword-face))
2609 ;; %register(at least i386)
2610 ("%\\sw+" . font-lock-variable-name-face)
2611 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2612 (1 font-lock-comment-face)
2613 (2 font-lock-function-name-face))
2614 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2615 "Font lock keywords used in `gdb-assembler-mode'.")
2617 (defun gdb-assembler-mode ()
2618 "Major mode for viewing code assembler.
2620 \\{gdb-assembler-mode-map}"
2621 (kill-all-local-variables)
2622 (setq major-mode 'gdb-assembler-mode)
2623 (setq mode-name (concat "Machine:" gdb-selected-frame))
2624 (setq gdb-overlay-arrow-position nil)
2625 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2626 (setq fringes-outside-margins t)
2627 (setq buffer-read-only t)
2628 (use-local-map gdb-assembler-mode-map)
2629 (gdb-invalidate-assembler)
2630 (set (make-local-variable 'font-lock-defaults)
2631 '(gdb-assembler-font-lock-keywords))
2632 (run-mode-hooks 'gdb-assembler-mode-hook)
2633 'gdb-invalidate-assembler)
2635 (defun gdb-assembler-buffer-name ()
2636 (with-current-buffer gud-comint-buffer
2637 (concat "*Disassembly of " (gdb-get-target-string) "*")))
2639 (defun gdb-display-assembler-buffer ()
2640 "Display disassembly view."
2642 (setq gdb-previous-frame nil)
2644 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2646 (defun gdb-frame-assembler-buffer ()
2647 "Display disassembly view in a new frame."
2649 (setq gdb-previous-frame nil)
2650 (let ((special-display-regexps (append special-display-regexps '(".*")))
2651 (special-display-frame-alist gdb-frame-parameters))
2652 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2654 ;; modified because if gdb-frame-address has changed value a new command
2655 ;; must be enqueued to update the buffer with the new output
2656 (defun gdb-invalidate-assembler (&optional ignored)
2657 (if (gdb-get-buffer 'gdb-assembler-buffer)
2659 (unless (and gdb-selected-frame
2660 (string-equal gdb-selected-frame gdb-previous-frame))
2661 (if (or (not (member 'gdb-invalidate-assembler
2662 gdb-pending-triggers))
2663 (not (string-equal gdb-frame-address
2664 gdb-previous-frame-address)))
2666 ;; take previous disassemble command, if any, off the queue
2667 (with-current-buffer gud-comint-buffer
2668 (let ((queue gdb-input-queue))
2669 (dolist (item queue)
2670 (if (equal (cdr item) '(gdb-assembler-handler))
2671 (setq gdb-input-queue
2672 (delete item gdb-input-queue))))))
2675 (concat gdb-server-prefix "disassemble "
2676 (if (member gdb-frame-address '(nil "main")) nil "0x")
2677 gdb-frame-address "\n")
2678 'gdb-assembler-handler))
2679 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2680 (setq gdb-previous-frame-address gdb-frame-address)
2681 (setq gdb-previous-frame gdb-selected-frame)))))))
2683 (defun gdb-get-selected-frame ()
2684 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2687 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2688 (push 'gdb-get-selected-frame
2689 gdb-pending-triggers))))
2691 (defun gdb-frame-handler ()
2692 (setq gdb-pending-triggers
2693 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2694 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2695 (goto-char (point-min))
2696 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2697 (setq gdb-frame-number (match-string 1)))
2698 (goto-char (point-min))
2699 (if (re-search-forward
2700 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2702 (setq gdb-selected-frame (match-string 2))
2703 (if (gdb-get-buffer 'gdb-locals-buffer)
2704 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2705 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2706 (if (gdb-get-buffer 'gdb-assembler-buffer)
2707 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2708 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2709 (setq gdb-frame-address (match-string 1))))
2710 (goto-char (point-min))
2711 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2712 (setq gdb-current-language (match-string 1))))
2713 (gdb-invalidate-assembler))
2717 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2718 ;;; gdb-ui.el ends here