1 ;;; gdb-ui.el --- User Interface for running GDB
3 ;; Author: Nick Roberts <nickrob@gnu.org>
5 ;; Keywords: unix, tools
7 ;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode acts as a graphical user interface to GDB. You can interact with
29 ;; GDB through the GUD buffer in the usual way, but there are also further
30 ;; buffers which control the execution and describe the state of your program.
31 ;; It separates the input/output of your program from that of GDB, if
32 ;; required, and watches expressions in the speedbar. It also uses features of
33 ;; Emacs 21 such as the fringe/display margin for breakpoints, and the toolbar
34 ;; (see the GDB Graphical Interface section in the Emacs info manual).
36 ;; By default, M-x gdb will start the debugger. However, if you have customised
37 ;; gud-gdb-command-name, then start it with M-x gdba.
39 ;; This file has evolved from gdba.el that was included with GDB 5.0 and
40 ;; written by Tom Lord and Jim Kingdon. It uses GDB's annotation interface.
41 ;; You don't need to know about annotations to use this mode as a debugger,
42 ;; but if you are interested developing the mode itself, then see the
43 ;; Annotations section in the GDB info manual.
45 ;; GDB developers plan to make the annotation interface obsolete. A new
46 ;; interface called GDB/MI (machine interface) has been designed to replace
47 ;; it. Some GDB/MI commands are used in this file through the CLI command
48 ;; 'interpreter mi <mi-command>'. A file called gdb-mi.el is included with
49 ;; GDB (6.2 onwards) that uses GDB/MI as the primary interface to GDB. It is
50 ;; still under development and is part of a process to migrate Emacs from
51 ;; annotations to GDB/MI.
55 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
56 ;; explicitly in your program if you want timely display of I/O in Emacs.
57 ;; Alternatively you can make the output stream unbuffered, for example, by
61 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
64 ;; and compiling with -DUNBUFFERED while debugging.
69 ;; 1) Use MI command -data-read-memory for memory window.
70 ;; 2) Highlight changed register values (use MI commands
71 ;; -data-list-register-values and -data-list-changed-registers instead
72 ;; of 'info registers'.
73 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
74 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
75 ;; 5) After release of 22.1 use '-var-list-children --all-values'
76 ;; and '-stack-list-locals 2' which need GDB 6.1 onwards.
84 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
85 (defvar gdb-previous-frame-address nil)
86 (defvar gdb-memory-address "main")
87 (defvar gdb-previous-frame nil)
88 (defvar gdb-selected-frame nil)
89 (defvar gdb-frame-number nil)
90 (defvar gdb-current-language nil)
91 (defvar gdb-var-list nil "List of variables in watch window.")
92 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
93 (defvar gdb-main-file nil "Source file from which program execution begins.")
94 (defvar gdb-buffer-type nil)
95 (defvar gdb-overlay-arrow-position nil)
96 (defvar gdb-server-prefix nil)
97 (defvar gdb-flush-pending-output nil)
98 (defvar gdb-location-alist nil
99 "Alist of breakpoint numbers and full filenames.")
100 (defvar gdb-find-file-unhook nil)
101 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
102 and #define directives otherwise.")
103 (defvar gdb-error "Non-nil when GDB is reporting an error.")
104 (defvar gdb-macro-info nil
105 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
106 (defvar gdb-buffer-fringe-width nil)
108 (defvar gdb-buffer-type nil
109 "One of the symbols bound in `gdb-buffer-rules'.")
111 (defvar gdb-input-queue ()
112 "A list of gdb command objects.")
114 (defvar gdb-prompting nil
115 "True when gdb is idle with no pending input.")
117 (defvar gdb-output-sink 'user
118 "The disposition of the output of the current gdb command.
119 Possible values are these symbols:
121 `user' -- gdb output should be copied to the GUD buffer
124 `inferior' -- gdb output should be copied to the inferior-io buffer.
126 `pre-emacs' -- output should be ignored util the post-prompt
127 annotation is received. Then the output-sink
129 `emacs' -- output should be collected in the partial-output-buffer
130 for subsequent processing by a command. This is the
131 disposition of output generated by commands that
132 gdb mode sends to gdb on its own behalf.
133 `post-emacs' -- ignore output until the prompt annotation is
134 received, then go to USER disposition.
136 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
137 \(`user' and `emacs').")
139 (defvar gdb-current-item nil
140 "The most recent command item sent to gdb.")
142 (defvar gdb-pending-triggers '()
143 "A list of trigger functions that have run later than their output
146 ;; end of gdb variables
149 (defun gdba (command-line)
150 "Run gdb on program FILE in buffer *gud-FILE*.
151 The directory containing FILE becomes the initial working directory
152 and source-file directory for your debugger.
154 If `gdb-many-windows' is nil (the default value) then gdb just
155 pops up the GUD buffer unless `gdb-show-main' is t. In this case
156 it starts with two windows: one displaying the GUD buffer and the
157 other with the source file with the main routine of the inferior.
159 If `gdb-many-windows' is t, regardless of the value of
160 `gdb-show-main', the layout below will appear unless
161 `gdb-use-inferior-io-buffer' is nil when the source buffer
162 occupies the full width of the frame. Keybindings are given in
165 Watch expressions appear in the speedbar/slowbar.
167 The following commands help control operation :
169 `gdb-many-windows' - Toggle the number of windows gdb uses.
170 `gdb-restore-windows' - To restore the window layout.
172 See Info node `(emacs)GDB Graphical Interface' for a more
173 detailed description of this mode.
176 +--------------------------------------------------------------+
178 +-------------------------------+------------------------------+
179 | GUD buffer (I/O of GDB) | Locals buffer |
183 +-------------------------------+------------------------------+
184 | Source buffer | I/O buffer (of inferior) |
192 +-------------------------------+------------------------------+
193 | Stack buffer | Breakpoints buffer |
194 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
195 | | RET gdb-goto-breakpoint |
196 | | d gdb-delete-breakpoint |
197 +-------------------------------+------------------------------+"
199 (interactive (list (gud-query-cmdline 'gdba)))
201 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
205 (defvar gdb-debug-log nil)
208 (defcustom gdb-enable-debug-log nil
209 "Non-nil means record the process input and output in `gdb-debug-log'."
214 (defcustom gdb-use-inferior-io-buffer nil
215 "Non-nil means display output from the inferior in a separate buffer."
220 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
221 "Shell command for generating a list of defined macros in a source file.
222 This list is used to display the #define directive associated
223 with an identifier as a tooltip. It works in a debug session with
224 GDB, when gud-tooltip-mode is t.
226 Set `gdb-cpp-define-alist-flags' for any include paths or
232 (defcustom gdb-cpp-define-alist-flags ""
233 "Preprocessor flags for `gdb-cpp-define-alist-program'."
238 (defcustom gdb-show-main nil
239 "Non-nil means display source file containing the main routine at startup.
240 Also display the main routine in the disassembly buffer if present."
245 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
247 (defun gdb-create-define-alist ()
248 "Create an alist of #define directives for GUD tooltips."
249 (let* ((file (buffer-file-name))
251 (with-output-to-string
252 (with-current-buffer standard-output
253 (call-process shell-file-name
254 (if (file-exists-p file) file nil)
255 (list t nil) nil "-c"
256 (concat gdb-cpp-define-alist-program " "
257 gdb-cpp-define-alist-flags)))))
258 (define-list (split-string output "\n" t))
260 (setq gdb-define-alist nil)
261 (dolist (define define-list)
262 (setq name (nth 1 (split-string define "[( ]")))
263 (push (cons name define) gdb-define-alist))))
265 (defun gdb-tooltip-print ()
267 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
268 (let ((string (buffer-string)))
269 ;; remove newline for gud-tooltip-echo-area
270 (substring string 0 (- (length string) 1))))
271 (or gud-tooltip-echo-area tooltip-use-echo-area)))
273 ;; If expr is a macro for a function don't print because of possible dangerous
274 ;; side-effects. Also printing a function within a tooltip generates an
275 ;; unexpected starting annotation (phase error).
276 (defun gdb-tooltip-print-1 (expr)
277 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
278 (goto-char (point-min))
279 (if (search-forward "expands to: " nil t)
280 (unless (looking-at "\\S+.*(.*).*")
282 (list (concat gdb-server-prefix "print " expr "\n")
283 'gdb-tooltip-print))))))
285 (defun gdb-set-gud-minor-mode (buffer)
286 "Set `gud-minor-mode' from find-file if appropriate."
287 (goto-char (point-min))
288 (unless (search-forward "No source file named " nil t)
291 (list (concat gdb-server-prefix "info source\n")
292 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
293 (error (setq gdb-find-file-unhook t)))))
295 (defun gdb-set-gud-minor-mode-1 (buffer)
296 (goto-char (point-min))
297 (when (and (search-forward "Located in " nil t)
299 (string-equal (buffer-file-name buffer)
301 (with-current-buffer buffer
302 (set (make-local-variable 'gud-minor-mode) 'gdba)
303 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
304 (when gud-tooltip-mode
305 (make-local-variable 'gdb-define-alist)
306 (gdb-create-define-alist)
307 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
309 (defun gdb-set-gud-minor-mode-existing-buffers ()
310 (dolist (buffer (buffer-list))
311 (let ((file (buffer-file-name buffer)))
315 (list (concat gdb-server-prefix "list "
316 (file-name-nondirectory file) ":1\n")
317 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
320 (setq gdb-debug-log nil)
321 (set (make-local-variable 'gud-minor-mode) 'gdba)
322 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
324 (gud-def gud-break (if (not (string-match "Machine" mode-name))
325 (gud-call "break %f:%l" arg)
329 (gud-call "break *%a" arg)))
330 "\C-b" "Set breakpoint at current line or address.")
332 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
333 (gud-call "clear %f:%l" arg)
337 (gud-call "clear *%a" arg)))
338 "\C-d" "Remove breakpoint at current line or address.")
340 (gud-def gud-until (if (not (string-match "Machine" mode-name))
341 (gud-call "until %f:%l" arg)
345 (gud-call "until *%a" arg)))
346 "\C-u" "Continue to current line or address.")
348 (define-key gud-minor-mode-map [left-margin mouse-1]
349 'gdb-mouse-set-clear-breakpoint)
350 (define-key gud-minor-mode-map [left-fringe mouse-1]
351 'gdb-mouse-set-clear-breakpoint)
352 (define-key gud-minor-mode-map [left-margin mouse-3]
353 'gdb-mouse-toggle-breakpoint-margin)
354 (define-key gud-minor-mode-map [left-fringe mouse-3]
355 'gdb-mouse-toggle-breakpoint-fringe)
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
381 gdb-buffer-fringe-width (car (window-fringes)))
383 (setq gdb-buffer-type 'gdba)
385 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
387 (if (eq window-system 'w32)
388 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
389 (gdb-enqueue-input (list "set height 0\n" 'ignore))
390 (gdb-enqueue-input (list "set width 0\n" 'ignore))
391 ;; find source file and compilation directory here
392 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
393 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
394 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
396 (gdb-set-gud-minor-mode-existing-buffers)
397 (run-hooks 'gdba-mode-hook))
399 (defcustom gdb-use-colon-colon-notation nil
400 "If non-nil use FUN::VAR format to display variables in the speedbar."
406 "Watch expression at point."
409 (let ((expr (tooltip-identifier-from-point (point))))
410 (if (and (string-equal gdb-current-language "c")
411 gdb-use-colon-colon-notation gdb-selected-frame)
412 (setq expr (concat gdb-selected-frame "::" expr)))
413 (catch 'already-watched
414 (dolist (var gdb-var-list)
415 (if (string-equal expr (car var)) (throw 'already-watched nil)))
416 (set-text-properties 0 (length expr) nil expr)
419 (if (eq gud-minor-mode 'gdba)
420 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
421 (concat"-var-create - * " expr "\n"))
422 `(lambda () (gdb-var-create-handler ,expr))))))
423 (select-window (get-buffer-window gud-comint-buffer 0)))
425 (defconst gdb-var-create-regexp
426 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
428 (defun gdb-var-create-handler (expr)
429 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
430 (goto-char (point-min))
431 (if (re-search-forward gdb-var-create-regexp nil t)
432 (let ((var (list expr
437 (push var gdb-var-list)
439 (unless (string-equal
440 speedbar-initial-expansion-list-name "GUD")
441 (speedbar-change-initial-expansion-list "GUD"))
442 (if (equal (nth 2 var) "0")
445 (if (with-current-buffer
446 gud-comint-buffer (eq gud-minor-mode 'gdba))
447 (concat "server interpreter mi \"-var-evaluate-expression "
449 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
450 `(lambda () (gdb-var-evaluate-expression-handler
452 (setq gdb-var-changed t)))
453 (if (re-search-forward "Undefined command" nil t)
454 (message-box "Watching expressions requires gdb 6.0 onwards")
455 (message "No symbol \"%s\" in current context." expr)))))
457 (defun gdb-var-evaluate-expression-handler (varnum changed)
458 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
459 (goto-char (point-min))
460 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t)
463 (dolist (var gdb-var-list)
464 (if (string-equal varnum (cadr var))
466 (if changed (setcar (nthcdr 5 var) t))
467 (setcar (nthcdr 4 var) (match-string 1))
468 (setcar (nthcdr num gdb-var-list) var)
469 (throw 'var-found nil)))
470 (setq num (+ num 1))))))
471 (setq gdb-var-changed t))
473 (defun gdb-var-list-children (varnum)
475 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
476 `(lambda () (gdb-var-list-children-handler ,varnum)))))
478 (defconst gdb-var-list-children-regexp
479 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
481 (defun gdb-var-list-children-handler (varnum)
482 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
483 (goto-char (point-min))
484 (let ((var-list nil))
485 (catch 'child-already-watched
486 (dolist (var gdb-var-list)
487 (if (string-equal varnum (cadr var))
490 (while (re-search-forward gdb-var-list-children-regexp nil t)
491 (let ((varchild (list (match-string 2)
495 (if (looking-at ",type=\"\\(.*?\\)\"")
496 (setcar (nthcdr 3 varchild) (match-string 1)))
497 (dolist (var1 gdb-var-list)
498 (if (string-equal (cadr var1) (cadr varchild))
499 (throw 'child-already-watched nil)))
500 (push varchild var-list)
501 (if (equal (nth 2 varchild) "0")
505 "server interpreter mi \"-var-evaluate-expression "
506 (nth 1 varchild) "\"\n")
507 `(lambda () (gdb-var-evaluate-expression-handler
508 ,(nth 1 varchild) nil))))))))
509 (push var var-list)))
510 (setq gdb-var-list (nreverse var-list))))))
512 (defun gdb-var-update ()
513 (when (not (member 'gdb-var-update gdb-pending-triggers))
515 (list "server interpreter mi \"-var-update *\"\n"
516 'gdb-var-update-handler))
517 (push 'gdb-var-update gdb-pending-triggers)))
519 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
521 (defun gdb-var-update-handler ()
522 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
523 (goto-char (point-min))
524 (while (re-search-forward gdb-var-update-regexp nil t)
525 (let ((varnum (match-string 1)))
528 (concat "server interpreter mi \"-var-evaluate-expression "
530 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
531 (setq gdb-pending-triggers
532 (delq 'gdb-var-update gdb-pending-triggers))
533 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
534 ;; Dummy command to update speedbar at right time.
535 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
536 ;; Keep gdb-pending-triggers non-nil till end.
537 (push 'gdb-speedbar-timer gdb-pending-triggers)))
539 (defun gdb-speedbar-timer-fn ()
540 (setq gdb-pending-triggers
541 (delq 'gdb-speedbar-timer gdb-pending-triggers))
542 (with-current-buffer gud-comint-buffer
543 (speedbar-timer-fn)))
545 (defun gdb-var-delete ()
546 "Delete watch expression at point from the speedbar."
548 (if (with-current-buffer
549 gud-comint-buffer (memq gud-minor-mode '(gdbmi gdba)))
550 (let ((text (speedbar-line-text)))
551 (string-match "\\(\\S-+\\)" text)
552 (let* ((expr (match-string 1 text))
553 (var (assoc expr gdb-var-list))
555 (unless (string-match "\\." varnum)
558 (if (with-current-buffer gud-comint-buffer
559 (eq gud-minor-mode 'gdba))
560 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
561 (concat "-var-delete " varnum "\n"))
563 (setq gdb-var-list (delq var gdb-var-list))
564 (dolist (varchild gdb-var-list)
565 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
566 (setq gdb-var-list (delq varchild gdb-var-list))))
567 (setq gdb-var-changed t))))))
569 (defun gdb-edit-value (text token indent)
570 "Assign a value to a variable displayed in the speedbar."
571 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
572 (varnum (cadr var)) (value))
573 (setq value (read-string "New value: "))
576 (if (with-current-buffer gud-comint-buffer
577 (eq gud-minor-mode 'gdba))
578 (concat "server interpreter mi \"-var-assign "
579 varnum " " value "\"\n")
580 (concat "-var-assign " varnum " " value "\n"))
583 (defcustom gdb-show-changed-values t
584 "If non-nil highlight values that have recently changed in the speedbar.
585 The highlighting is done with `font-lock-warning-face'."
590 (defun gdb-speedbar-expand-node (text token indent)
591 "Expand the node the user clicked on.
592 TEXT is the text of the button we clicked on, a + or - item.
593 TOKEN is data related to this node.
594 INDENT is the current indentation depth."
595 (cond ((string-match "+" text) ;expand this node
596 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
597 (gdb-var-list-children token)
600 (gdbmi-var-list-children token))))
601 ((string-match "-" text) ;contract this node
602 (dolist (var gdb-var-list)
603 (if (string-match (concat token "\\.") (nth 1 var))
604 (setq gdb-var-list (delq var gdb-var-list))))
605 (setq gdb-var-changed t)
606 (with-current-buffer gud-comint-buffer
607 (speedbar-timer-fn)))))
609 (defun gdb-get-target-string ()
610 (with-current-buffer gud-comint-buffer
617 ;; Each buffer has a TYPE -- a symbol that identifies the function
618 ;; of that particular buffer.
620 ;; The usual gdb interaction buffer is given the type `gdba' and
621 ;; is constructed specially.
623 ;; Others are constructed by gdb-get-create-buffer and
624 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
626 (defvar gdb-buffer-rules-assoc '())
628 (defun gdb-get-buffer (key)
629 "Return the gdb buffer tagged with type KEY.
630 The key should be one of the cars in `gdb-buffer-rules-assoc'."
632 (gdb-look-for-tagged-buffer key (buffer-list))))
634 (defun gdb-get-create-buffer (key)
635 "Create a new gdb buffer of the type specified by KEY.
636 The key should be one of the cars in `gdb-buffer-rules-assoc'."
637 (or (gdb-get-buffer key)
638 (let* ((rules (assoc key gdb-buffer-rules-assoc))
639 (name (funcall (gdb-rules-name-maker rules)))
640 (new (get-buffer-create name)))
641 (with-current-buffer new
643 (if (cdr (cdr rules))
644 (setq trigger (funcall (car (cdr (cdr rules))))))
645 (set (make-local-variable 'gdb-buffer-type) key)
646 (set (make-local-variable 'gud-minor-mode)
647 (with-current-buffer gud-comint-buffer gud-minor-mode))
648 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
649 (if trigger (funcall trigger)))
652 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
654 (defun gdb-look-for-tagged-buffer (key bufs)
656 (while (and (not retval) bufs)
657 (set-buffer (car bufs))
658 (if (eq gdb-buffer-type key)
659 (setq retval (car bufs)))
660 (setq bufs (cdr bufs)))
664 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
665 ;; at least one and possible more functions. The functions have these
666 ;; roles in defining a buffer type:
668 ;; NAME - Return a name for this buffer type.
670 ;; The remaining function(s) are optional:
672 ;; MODE - called in a new buffer with no arguments, should establish
673 ;; the proper mode for the buffer.
676 (defun gdb-set-buffer-rules (buffer-type &rest rules)
677 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
679 (setcdr binding rules)
680 (push (cons buffer-type rules)
681 gdb-buffer-rules-assoc))))
683 ;; GUD buffers are an exception to the rules
684 (gdb-set-buffer-rules 'gdba 'error)
687 ;; Partial-output buffer : This accumulates output from a command executed on
688 ;; behalf of emacs (rather than the user).
690 (gdb-set-buffer-rules 'gdb-partial-output-buffer
691 'gdb-partial-output-name)
693 (defun gdb-partial-output-name ()
694 (concat "*partial-output-"
695 (gdb-get-target-string)
699 (gdb-set-buffer-rules 'gdb-inferior-io
700 'gdb-inferior-io-name
701 'gdb-inferior-io-mode)
703 (defun gdb-inferior-io-name ()
704 (concat "*input/output of "
705 (gdb-get-target-string)
708 (defun gdb-display-inferior-io-buffer ()
709 "Display IO of inferior in a separate window."
711 (if gdb-use-inferior-io-buffer
713 (gdb-get-create-buffer 'gdb-inferior-io))))
715 (defconst gdb-frame-parameters
716 '((height . 14) (width . 80)
718 (tool-bar-lines . nil)
719 (menu-bar-lines . nil)
722 (defun gdb-frame-inferior-io-buffer ()
723 "Display IO of inferior in a new frame."
725 (if gdb-use-inferior-io-buffer
726 (let ((special-display-regexps (append special-display-regexps '(".*")))
727 (special-display-frame-alist gdb-frame-parameters))
728 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
730 (defvar gdb-inferior-io-mode-map
731 (let ((map (make-sparse-keymap)))
732 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
733 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
734 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
735 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
736 (define-key map "\C-d" 'gdb-inferior-io-eof)
739 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
740 "Major mode for gdb inferior-io."
741 :syntax-table nil :abbrev-table nil
742 ;; We want to use comint because it has various nifty and familiar
743 ;; features. We don't need a process, but comint wants one, so create
745 (make-comint-in-buffer
746 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
747 (current-buffer) "hexl")
748 (setq comint-input-sender 'gdb-inferior-io-sender))
750 (defun gdb-inferior-io-sender (proc string)
751 ;; PROC is the pseudo-process created to satisfy comint.
752 (with-current-buffer (process-buffer proc)
753 (setq proc (get-buffer-process gud-comint-buffer))
754 (process-send-string proc string)
755 (process-send-string proc "\n")))
757 (defun gdb-inferior-io-interrupt ()
758 "Interrupt the program being debugged."
761 (get-buffer-process gud-comint-buffer) comint-ptyp))
763 (defun gdb-inferior-io-quit ()
764 "Send quit signal to the program being debugged."
767 (get-buffer-process gud-comint-buffer) comint-ptyp))
769 (defun gdb-inferior-io-stop ()
770 "Stop the program being debugged."
773 (get-buffer-process gud-comint-buffer) comint-ptyp))
775 (defun gdb-inferior-io-eof ()
776 "Send end-of-file to the program being debugged."
779 (get-buffer-process gud-comint-buffer)))
783 ;; gdb communications
786 ;; INPUT: things sent to gdb
788 ;; The queues are lists. Each element is either a string (indicating user or
789 ;; user-like input) or a list of the form:
791 ;; (INPUT-STRING HANDLER-FN)
793 ;; The handler function will be called from the partial-output buffer when the
794 ;; command completes. This is the way to write commands which invoke gdb
795 ;; commands autonomously.
797 ;; These lists are consumed tail first.
800 (defun gdb-send (proc string)
801 "A comint send filter for gdb.
802 This filter may simply queue input for a later time."
803 (with-current-buffer gud-comint-buffer
804 (let ((inhibit-read-only t))
805 (remove-text-properties (point-min) (point-max) '(face))))
806 (let ((item (concat string "\n")))
809 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
810 (process-send-string proc item))
811 (gdb-enqueue-input item))))
813 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
814 ;; is a query, or other non-top-level prompt.
816 (defun gdb-enqueue-input (item)
820 (setq gdb-prompting nil))
821 (push item gdb-input-queue)))
823 (defun gdb-dequeue-input ()
824 (let ((queue gdb-input-queue))
826 (let ((last (car (last queue))))
827 (unless (nbutlast queue) (setq gdb-input-queue '()))
830 (defun gdb-send-item (item)
831 (setq gdb-flush-pending-output nil)
832 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
833 (setq gdb-current-item item)
834 (with-current-buffer gud-comint-buffer
835 (if (eq gud-minor-mode 'gdba)
838 (setq gdb-output-sink 'user)
839 (process-send-string (get-buffer-process gud-comint-buffer) item))
841 (gdb-clear-partial-output)
842 (setq gdb-output-sink 'pre-emacs)
843 (process-send-string (get-buffer-process gud-comint-buffer)
845 ;; case: eq gud-minor-mode 'gdbmi
846 (gdb-clear-partial-output)
847 (setq gdb-output-sink 'emacs)
848 (process-send-string (get-buffer-process gud-comint-buffer)
852 ;; output -- things gdb prints to emacs
854 ;; GDB output is a stream interrupted by annotations.
855 ;; Annotations can be recognized by their beginning
856 ;; with \C-j\C-z\C-z<tag><opt>\C-j
858 ;; The tag is a string obeying symbol syntax.
860 ;; The optional part `<opt>' can be either the empty string
861 ;; or a space followed by more data relating to the annotation.
862 ;; For example, the SOURCE annotation is followed by a filename,
863 ;; line number and various useless goo. This data must not include
867 (defcustom gud-gdba-command-name "gdb -annotate=3"
868 "Default command to execute an executable under the GDB-UI debugger."
873 (defvar gdb-annotation-rules
874 '(("pre-prompt" gdb-pre-prompt)
875 ("prompt" gdb-prompt)
876 ("commands" gdb-subprompt)
877 ("overload-choice" gdb-subprompt)
878 ("query" gdb-subprompt)
879 ;; Need this prompt for GDB 6.1
880 ("nquery" gdb-subprompt)
881 ("prompt-for-continue" gdb-subprompt)
882 ("post-prompt" gdb-post-prompt)
883 ("source" gdb-source)
884 ("starting" gdb-starting)
885 ("exited" gdb-exited)
886 ("signalled" gdb-exited)
887 ("signal" gdb-stopping)
888 ("breakpoint" gdb-stopping)
889 ("watchpoint" gdb-stopping)
890 ("frame-begin" gdb-frame-begin)
891 ("stopped" gdb-stopped)
892 ("error-begin" gdb-error)
894 ) "An assoc mapping annotation tags to functions which process them.")
897 (setq gdb-flush-pending-output t)
898 (setq gud-running nil)
899 (setq gdb-output-sink 'user)
900 (setq gdb-input-queue nil)
901 (setq gdb-pending-triggers nil)
902 (setq gdb-prompting t))
904 (defconst gdb-source-spec-regexp
905 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
907 ;; Do not use this except as an annotation handler.
908 (defun gdb-source (args)
909 (string-match gdb-source-spec-regexp args)
910 ;; Extract the frame position from the marker.
913 (match-string 1 args)
914 (string-to-number (match-string 2 args))))
915 (setq gdb-frame-address (match-string 3 args))
916 ;; cover for auto-display output which comes *before*
917 ;; stopped annotation
918 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
920 (defun gdb-pre-prompt (ignored)
921 "An annotation handler for `pre-prompt'.
922 This terminates the collection of output from a previous command if that
923 happens to be in effect."
924 (let ((sink gdb-output-sink))
928 (setq gdb-output-sink 'post-emacs))
931 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
933 (defun gdb-prompt (ignored)
934 "An annotation handler for `prompt'.
935 This sends the next command (if any) to gdb."
936 (when gdb-first-prompt (gdb-ann3))
937 (let ((sink gdb-output-sink))
940 ((eq sink 'post-emacs)
941 (setq gdb-output-sink 'user)
943 (car (cdr gdb-current-item))))
944 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
948 (error "Phase error in gdb-prompt (got %s)" sink))))
949 (let ((input (gdb-dequeue-input)))
951 (gdb-send-item input)
953 (setq gdb-prompting t)
954 (gud-display-frame)))))
956 (defun gdb-subprompt (ignored)
957 "An annotation handler for non-top-level prompts."
958 (setq gdb-prompting t))
960 (defun gdb-starting (ignored)
961 "An annotation handler for `starting'.
962 This says that I/O for the subprocess is now the program being debugged,
964 (setq gdb-active-process t)
965 (let ((sink gdb-output-sink))
970 (if gdb-use-inferior-io-buffer
971 (setq gdb-output-sink 'inferior))))
974 (error "Unexpected `starting' annotation")))))
976 (defun gdb-stopping (ignored)
977 "An annotation handler for `breakpoint' and other annotations.
978 They say that I/O for the subprocess is now GDB, not the program
980 (if gdb-use-inferior-io-buffer
981 (let ((sink gdb-output-sink))
984 (setq gdb-output-sink 'user))
987 (error "Unexpected stopping annotation"))))))
989 (defun gdb-exited (ignored)
990 "An annotation handler for `exited' and `signalled'.
991 They say that I/O for the subprocess is now GDB, not the program
992 being debugged and that the program is no longer running. This
993 function is used to change the focus of GUD tooltips to #define
995 (setq gdb-active-process nil)
996 (gdb-stopping ignored))
998 (defun gdb-frame-begin (ignored)
999 (let ((sink gdb-output-sink))
1001 ((eq sink 'inferior)
1002 (setq gdb-output-sink 'user))
1004 ((eq sink 'emacs) t)
1007 (error "Unexpected frame-begin annotation (%S)" sink)))))
1009 (defun gdb-stopped (ignored)
1010 "An annotation handler for `stopped'.
1011 It is just like `gdb-stopping', except that if we already set the output
1012 sink to `user' in `gdb-stopping', that is fine."
1013 (setq gud-running nil)
1014 (let ((sink gdb-output-sink))
1016 ((eq sink 'inferior)
1017 (setq gdb-output-sink 'user))
1021 (error "Unexpected stopped annotation")))))
1023 (defun gdb-error (ignored)
1024 (setq gdb-error (not gdb-error)))
1026 (defun gdb-post-prompt (ignored)
1027 "An annotation handler for `post-prompt'.
1028 This begins the collection of output from the current command if that
1029 happens to be appropriate."
1030 (unless gdb-pending-triggers
1031 (gdb-get-selected-frame)
1032 (gdb-invalidate-frames)
1033 (gdb-invalidate-breakpoints)
1034 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1035 ;; so gdb-frame-address is updated.
1036 ;; (gdb-invalidate-assembler)
1037 (gdb-invalidate-registers)
1038 (gdb-invalidate-memory)
1039 (gdb-invalidate-locals)
1040 (gdb-invalidate-threads)
1041 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1042 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1043 ;; Only needed/used with speedbar/watch expressions.
1044 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1045 (setq gdb-var-changed t) ; force update
1046 (dolist (var gdb-var-list)
1047 (setcar (nthcdr 5 var) nil))
1049 (let ((sink gdb-output-sink))
1052 ((eq sink 'pre-emacs)
1053 (setq gdb-output-sink 'emacs))
1056 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1058 (defun gud-gdba-marker-filter (string)
1059 "A gud marker filter for gdb. Handle a burst of output from GDB."
1060 (if gdb-flush-pending-output
1062 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1063 ;; Recall the left over gud-marker-acc from last time.
1064 (setq gud-marker-acc (concat gud-marker-acc string))
1065 ;; Start accumulating output for the GUD buffer.
1068 ;; Process all the complete markers in this chunk.
1069 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1070 (let ((annotation (match-string 1 gud-marker-acc)))
1072 ;; Stuff prior to the match is just ordinary output.
1073 ;; It is either concatenated to OUTPUT or directed
1078 (substring gud-marker-acc 0 (match-beginning 0))))
1080 ;; Take that stuff off the gud-marker-acc.
1081 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1083 ;; Parse the tag from the annotation, and maybe its arguments.
1084 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1085 (let* ((annotation-type (match-string 1 annotation))
1086 (annotation-arguments (match-string 2 annotation))
1087 (annotation-rule (assoc annotation-type
1088 gdb-annotation-rules)))
1089 ;; Call the handler for this annotation.
1091 (funcall (car (cdr annotation-rule))
1092 annotation-arguments)
1093 ;; Else the annotation is not recognized. Ignore it silently,
1094 ;; so that GDB can add new annotations without causing
1098 ;; Does the remaining text end in a partial line?
1099 ;; If it does, then keep part of the gud-marker-acc until we get more.
1100 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1103 ;; Everything before the potential marker start can be output.
1105 (gdb-concat-output output
1106 (substring gud-marker-acc 0
1107 (match-beginning 0))))
1109 ;; Everything after, we save, to combine with later input.
1110 (setq gud-marker-acc (substring gud-marker-acc
1111 (match-beginning 0))))
1113 ;; In case we know the gud-marker-acc contains no partial annotations:
1115 (setq output (gdb-concat-output output gud-marker-acc))
1116 (setq gud-marker-acc "")))
1119 (defun gdb-concat-output (so-far new)
1121 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1122 (let ((sink gdb-output-sink))
1124 ((eq sink 'user) (concat so-far new))
1125 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1127 (gdb-append-to-partial-output new)
1129 ((eq sink 'inferior)
1130 (gdb-append-to-inferior-io new)
1134 (error "Bogon output sink %S" sink)))))
1136 (defun gdb-append-to-partial-output (string)
1137 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1138 (goto-char (point-max))
1141 (defun gdb-clear-partial-output ()
1142 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1145 (defun gdb-append-to-inferior-io (string)
1146 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1147 (goto-char (point-max))
1148 (insert-before-markers string))
1149 (if (not (string-equal string ""))
1150 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1152 (defun gdb-clear-inferior-io ()
1153 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1157 ;; One trick is to have a command who's output is always available in a buffer
1158 ;; of it's own, and is always up to date. We build several buffers of this
1161 ;; There are two aspects to this: gdb has to tell us when the output for that
1162 ;; command might have changed, and we have to be able to run the command
1163 ;; behind the user's back.
1165 ;; The output phasing associated with the variable gdb-output-sink
1166 ;; help us to run commands behind the user's back.
1168 ;; Below is the code for specificly managing buffers of output from one
1172 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1173 ;; It adds an input for the command we are tracking. It should be the
1174 ;; annotation rule binding of whatever gdb sends to tell us this command
1175 ;; might have changed it's output.
1177 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1178 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1179 ;; input in the input queue (see comment about ``gdb communications'' above).
1181 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1183 `(defun ,name (&optional ignored)
1184 (if (and (,demand-predicate)
1186 gdb-pending-triggers)))
1189 (list ,gdb-command ',output-handler))
1190 (push ',name gdb-pending-triggers)))))
1192 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1194 (setq gdb-pending-triggers
1196 gdb-pending-triggers))
1197 (let ((buf (gdb-get-buffer ',buf-key)))
1199 (with-current-buffer buf
1200 (let* ((window (get-buffer-window buf 0))
1201 (p (window-point window))
1202 (buffer-read-only nil))
1204 (insert-buffer-substring (gdb-get-create-buffer
1205 'gdb-partial-output-buffer))
1206 (set-window-point window p)))))
1207 ;; put customisation here
1210 (defmacro def-gdb-auto-updated-buffer (buffer-key
1211 trigger-name gdb-command
1212 output-handler-name custom-defun)
1214 (def-gdb-auto-update-trigger ,trigger-name
1215 ;; The demand predicate:
1216 (lambda () (gdb-get-buffer ',buffer-key))
1218 ,output-handler-name)
1219 (def-gdb-auto-update-handler ,output-handler-name
1220 ,trigger-name ,buffer-key ,custom-defun)))
1224 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1226 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1227 'gdb-breakpoints-buffer-name
1228 'gdb-breakpoints-mode)
1230 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1231 ;; This defines the auto update rule for buffers of type
1232 ;; `gdb-breakpoints-buffer'.
1234 ;; It defines a function to serve as the annotation handler that
1235 ;; handles the `foo-invalidated' message. That function is called:
1236 gdb-invalidate-breakpoints
1238 ;; To update the buffer, this command is sent to gdb.
1239 "server info breakpoints\n"
1241 ;; This also defines a function to be the handler for the output
1242 ;; from the command above. That function will copy the output into
1243 ;; the appropriately typed buffer. That function will be called:
1244 gdb-info-breakpoints-handler
1245 ;; buffer specific functions
1246 gdb-info-breakpoints-custom)
1248 (defconst breakpoint-xpm-data
1250 static char *magick[] = {
1251 /* columns rows colors chars-per-pixel */
1267 "XPM data used for breakpoint icon.")
1269 (defconst breakpoint-enabled-pbm-data
1272 0 0 0 0 1 1 1 1 0 0 0 0
1273 0 0 0 1 1 1 1 1 1 0 0 0
1274 0 0 1 1 1 1 1 1 1 1 0 0
1275 0 1 1 1 1 1 1 1 1 1 1 0
1276 0 1 1 1 1 1 1 1 1 1 1 0
1277 0 1 1 1 1 1 1 1 1 1 1 0
1278 0 1 1 1 1 1 1 1 1 1 1 0
1279 0 0 1 1 1 1 1 1 1 1 0 0
1280 0 0 0 1 1 1 1 1 1 0 0 0
1281 0 0 0 0 1 1 1 1 0 0 0 0"
1282 "PBM data used for enabled breakpoint icon.")
1284 (defconst breakpoint-disabled-pbm-data
1296 0 0 0 1 0 1 0 1 0 0"
1297 "PBM data used for disabled breakpoint icon.")
1299 (defvar breakpoint-enabled-icon nil
1300 "Icon for enabled breakpoint in display margin.")
1302 (defvar breakpoint-disabled-icon nil
1303 "Icon for disabled breakpoint in display margin.")
1305 ;; Bitmap for breakpoint in fringe
1306 (and (display-images-p)
1307 (define-fringe-bitmap 'breakpoint
1308 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1310 (defface breakpoint-enabled
1314 "Face for enabled breakpoint icon in fringe."
1316 ;; Compatibility alias for old name.
1317 (put 'breakpoint-enabled-bitmap-face 'face-alias 'breakpoint-enabled)
1319 (defface breakpoint-disabled
1320 ;; We use different values of grey for different background types,
1321 ;; so that on low-color displays it will end up as something visible
1322 ;; if it has to be approximated.
1323 '((((background dark)) :foreground "grey60")
1324 (((background light)) :foreground "grey40"))
1325 "Face for disabled breakpoint icon in fringe."
1328 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1329 (defun gdb-info-breakpoints-custom ()
1330 (let ((flag) (bptno))
1331 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1332 (dolist (buffer (buffer-list))
1333 (with-current-buffer buffer
1334 (if (and (eq gud-minor-mode 'gdba)
1335 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1336 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1337 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1339 (goto-char (point-min))
1340 (while (< (point) (- (point-max) 1))
1342 (if (looking-at "[^\t].*?breakpoint")
1344 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1345 (setq bptno (match-string 1))
1346 (setq flag (char-after (match-beginning 2)))
1348 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1350 (let ((buffer-read-only nil))
1351 (add-text-properties (match-beginning 1) (match-end 1)
1352 '(face font-lock-function-name-face)))
1353 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1354 (let ((line (match-string 2)) (buffer-read-only nil)
1355 (file (match-string 1)))
1356 (add-text-properties (line-beginning-position)
1358 '(mouse-face highlight
1359 help-echo "mouse-2, RET: visit breakpoint"))
1360 (unless (file-exists-p file)
1361 (setq file (cdr (assoc bptno gdb-location-alist))))
1363 (not (string-equal file "File not found")))
1364 (with-current-buffer
1365 (find-file-noselect file 'nowarn)
1366 (set (make-local-variable 'gud-minor-mode)
1368 (set (make-local-variable 'tool-bar-map)
1370 ;; Only want one breakpoint icon at each
1373 (goto-line (string-to-number line))
1374 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1378 (match-string-no-properties 1) ":1\n")
1381 (list "info source\n"
1382 `(lambda () (gdb-get-location
1383 ,bptno ,line ,flag))))))))))
1385 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1387 (defun gdb-mouse-set-clear-breakpoint (event)
1388 "Set/clear breakpoint in left fringe/margin with mouse click."
1390 (mouse-minibuffer-check event)
1391 (let ((posn (event-end event)))
1392 (if (numberp (posn-point posn))
1393 (with-selected-window (posn-window posn)
1395 (goto-char (posn-point posn))
1396 (if (or (posn-object posn)
1397 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1400 (gud-break nil)))))))
1402 (defun gdb-mouse-toggle-breakpoint-margin (event)
1403 "Enable/disable breakpoint in left margin with mouse click."
1405 (mouse-minibuffer-check event)
1406 (let ((posn (event-end event)))
1407 (if (numberp (posn-point posn))
1408 (with-selected-window (posn-window posn)
1410 (goto-char (posn-point posn))
1411 (if (posn-object posn)
1414 (let ((bptno (get-text-property
1415 0 'gdb-bptno (car (posn-string posn)))))
1417 (if (get-text-property
1418 0 'gdb-enabled (car (posn-string posn)))
1424 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1425 "Enable/disable breakpoint in left fringe with mouse click."
1427 (mouse-minibuffer-check event)
1428 (let* ((posn (event-end event))
1429 (pos (posn-point posn))
1432 (with-selected-window (posn-window posn)
1434 (set-buffer (window-buffer (selected-window)))
1436 (dolist (overlay (overlays-in pos pos))
1437 (when (overlay-get overlay 'put-break)
1438 (setq obj (overlay-get overlay 'before-string))))
1443 (if (get-text-property 0 'gdb-enabled obj)
1446 (get-text-property 0 'gdb-bptno obj) "\n")
1449 (defun gdb-breakpoints-buffer-name ()
1450 (with-current-buffer gud-comint-buffer
1451 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1453 (defun gdb-display-breakpoints-buffer ()
1454 "Display status of user-settable breakpoints."
1457 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1459 (defun gdb-frame-breakpoints-buffer ()
1460 "Display status of user-settable breakpoints in a new frame."
1462 (let ((special-display-regexps (append special-display-regexps '(".*")))
1463 (special-display-frame-alist gdb-frame-parameters))
1464 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1466 (defvar gdb-breakpoints-mode-map
1467 (let ((map (make-sparse-keymap))
1468 (menu (make-sparse-keymap "Breakpoints")))
1469 (define-key menu [quit] '("Quit" . kill-this-buffer))
1470 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1471 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1472 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1473 (suppress-keymap map)
1474 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1475 (define-key map " " 'gdb-toggle-breakpoint)
1476 (define-key map "d" 'gdb-delete-breakpoint)
1477 (define-key map "q" 'kill-this-buffer)
1478 (define-key map "\r" 'gdb-goto-breakpoint)
1479 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1480 (define-key map [follow-link] 'mouse-face)
1483 (defun gdb-breakpoints-mode ()
1484 "Major mode for gdb breakpoints.
1486 \\{gdb-breakpoints-mode-map}"
1487 (kill-all-local-variables)
1488 (setq major-mode 'gdb-breakpoints-mode)
1489 (setq mode-name "Breakpoints")
1490 (use-local-map gdb-breakpoints-mode-map)
1491 (setq buffer-read-only t)
1492 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1493 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1494 'gdb-invalidate-breakpoints
1495 'gdbmi-invalidate-breakpoints))
1497 (defun gdb-toggle-breakpoint ()
1498 "Enable/disable breakpoint at current line."
1501 (beginning-of-line 1)
1502 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1503 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1505 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1508 (concat gdb-server-prefix
1509 (if (eq ?y (char-after (match-beginning 2)))
1512 (match-string 1) "\n") 'ignore))
1513 (error "Not recognized as break/watchpoint line"))))
1515 (defun gdb-delete-breakpoint ()
1516 "Delete the breakpoint at current line."
1518 (beginning-of-line 1)
1519 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1520 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1522 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1525 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1526 (error "Not recognized as break/watchpoint line")))
1528 (defun gdb-goto-breakpoint (&optional event)
1529 "Display the breakpoint location specified at current line."
1530 (interactive (list last-input-event))
1531 (if event (mouse-set-point event))
1533 (beginning-of-line 1)
1534 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1535 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1537 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1538 \\(\\S-+\\):\\([0-9]+\\)"))
1539 (let ((bptno (match-string 1))
1540 (file (match-string 2))
1541 (line (match-string 3)))
1542 (save-selected-window
1543 (let* ((buf (find-file-noselect
1544 (if (file-exists-p file) file
1545 (cdr (assoc bptno gdb-location-alist)))))
1546 (window (display-buffer buf)))
1547 (with-current-buffer buf
1548 (goto-line (string-to-number line))
1549 (set-window-point window (point))))))
1550 (error "Not recognized as break/watchpoint line"))))
1553 ;; Frames buffer. This displays a perpetually correct bactracktrace
1554 ;; (from the command `where').
1556 ;; Alas, if your stack is deep, it is costly.
1558 (gdb-set-buffer-rules 'gdb-stack-buffer
1559 'gdb-stack-buffer-name
1562 (def-gdb-auto-updated-buffer gdb-stack-buffer
1563 gdb-invalidate-frames
1565 gdb-info-frames-handler
1566 gdb-info-frames-custom)
1568 (defun gdb-info-frames-custom ()
1569 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1571 (let ((buffer-read-only nil)
1573 (goto-char (point-min))
1574 (while (< (point) (point-max))
1575 (setq bl (line-beginning-position)
1576 el (line-end-position))
1577 (add-text-properties bl el
1578 '(mouse-face highlight
1579 help-echo "mouse-2, RET: Select frame"))
1581 (when (looking-at "^#\\([0-9]+\\)")
1582 (when (string-equal (match-string 1) gdb-frame-number)
1583 (put-text-property bl (+ bl 4)
1584 'face '(:inverse-video t)))
1585 (when (re-search-forward
1587 (if (string-equal (match-string 1) "0") "" " in ")
1588 "\\([^ ]+\\) (") el t)
1589 (put-text-property (match-beginning 1) (match-end 1)
1590 'face font-lock-function-name-face)
1591 (setq bl (match-end 0))
1592 (while (re-search-forward "<\\([^>]+\\)>" el t)
1593 (put-text-property (match-beginning 1) (match-end 1)
1594 'face font-lock-function-name-face))
1596 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1597 (put-text-property (match-beginning 1) (match-end 1)
1598 'face font-lock-variable-name-face))))
1599 (forward-line 1))))))
1601 (defun gdb-stack-buffer-name ()
1602 (with-current-buffer gud-comint-buffer
1603 (concat "*stack frames of " (gdb-get-target-string) "*")))
1605 (defun gdb-display-stack-buffer ()
1606 "Display backtrace of current stack."
1609 (gdb-get-create-buffer 'gdb-stack-buffer)))
1611 (defun gdb-frame-stack-buffer ()
1612 "Display backtrace of current stack in a new frame."
1614 (let ((special-display-regexps (append special-display-regexps '(".*")))
1615 (special-display-frame-alist gdb-frame-parameters))
1616 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1618 (defvar gdb-frames-mode-map
1619 (let ((map (make-sparse-keymap)))
1620 (suppress-keymap map)
1621 (define-key map "q" 'kill-this-buffer)
1622 (define-key map "\r" 'gdb-frames-select)
1623 (define-key map [mouse-2] 'gdb-frames-select)
1624 (define-key map [follow-link] 'mouse-face)
1627 (defun gdb-frames-mode ()
1628 "Major mode for gdb frames.
1630 \\{gdb-frames-mode-map}"
1631 (kill-all-local-variables)
1632 (setq major-mode 'gdb-frames-mode)
1633 (setq mode-name "Frames")
1634 (setq buffer-read-only t)
1635 (use-local-map gdb-frames-mode-map)
1637 (run-mode-hooks 'gdb-frames-mode-hook)
1638 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1639 'gdb-invalidate-frames
1640 'gdbmi-invalidate-frames))
1642 (defun gdb-get-frame-number ()
1645 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1646 (n (or (and pos (match-string-no-properties 1)) "0")))
1649 (defun gdb-frames-select (&optional event)
1650 "Select the frame and display the relevant source."
1651 (interactive (list last-input-event))
1652 (if event (mouse-set-point event))
1654 (list (concat gdb-server-prefix "frame "
1655 (gdb-get-frame-number) "\n") 'ignore))
1656 (gud-display-frame))
1659 ;; Threads buffer. This displays a selectable thread list.
1661 (gdb-set-buffer-rules 'gdb-threads-buffer
1662 'gdb-threads-buffer-name
1665 (def-gdb-auto-updated-buffer gdb-threads-buffer
1666 gdb-invalidate-threads
1667 (concat gdb-server-prefix "info threads\n")
1668 gdb-info-threads-handler
1669 gdb-info-threads-custom)
1671 (defun gdb-info-threads-custom ()
1672 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1673 (let ((buffer-read-only nil))
1674 (goto-char (point-min))
1675 (while (< (point) (point-max))
1676 (add-text-properties (line-beginning-position) (line-end-position)
1677 '(mouse-face highlight
1678 help-echo "mouse-2, RET: select thread"))
1679 (forward-line 1)))))
1681 (defun gdb-threads-buffer-name ()
1682 (with-current-buffer gud-comint-buffer
1683 (concat "*threads of " (gdb-get-target-string) "*")))
1685 (defun gdb-display-threads-buffer ()
1686 "Display IDs of currently known threads."
1689 (gdb-get-create-buffer 'gdb-threads-buffer)))
1691 (defun gdb-frame-threads-buffer ()
1692 "Display IDs of currently known threads in a new frame."
1694 (let ((special-display-regexps (append special-display-regexps '(".*")))
1695 (special-display-frame-alist gdb-frame-parameters))
1696 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1698 (defvar gdb-threads-mode-map
1699 (let ((map (make-sparse-keymap)))
1700 (suppress-keymap map)
1701 (define-key map "q" 'kill-this-buffer)
1702 (define-key map "\r" 'gdb-threads-select)
1703 (define-key map [mouse-2] 'gdb-threads-select)
1706 (defvar gdb-threads-font-lock-keywords
1708 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1709 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1710 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1712 "Font lock keywords used in `gdb-threads-mode'.")
1714 (defun gdb-threads-mode ()
1715 "Major mode for gdb frames.
1717 \\{gdb-threads-mode-map}"
1718 (kill-all-local-variables)
1719 (setq major-mode 'gdb-threads-mode)
1720 (setq mode-name "Threads")
1721 (setq buffer-read-only t)
1722 (use-local-map gdb-threads-mode-map)
1723 (set (make-local-variable 'font-lock-defaults)
1724 '(gdb-threads-font-lock-keywords))
1725 (run-mode-hooks 'gdb-threads-mode-hook)
1726 'gdb-invalidate-threads)
1728 (defun gdb-get-thread-number ()
1730 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1731 (match-string-no-properties 1)))
1733 (defun gdb-threads-select (&optional event)
1734 "Select the thread and display the relevant source."
1735 (interactive (list last-input-event))
1736 (if event (mouse-set-point event))
1738 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1739 (gud-display-frame))
1742 ;; Registers buffer.
1744 (defcustom gdb-all-registers nil
1745 "Non-nil means include floating-point registers."
1750 (gdb-set-buffer-rules 'gdb-registers-buffer
1751 'gdb-registers-buffer-name
1752 'gdb-registers-mode)
1754 (def-gdb-auto-updated-buffer gdb-registers-buffer
1755 gdb-invalidate-registers
1757 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1758 gdb-info-registers-handler
1759 gdb-info-registers-custom)
1761 (defun gdb-info-registers-custom ())
1763 (defvar gdb-registers-mode-map
1764 (let ((map (make-sparse-keymap)))
1765 (suppress-keymap map)
1766 (define-key map " " 'toggle-gdb-all-registers)
1767 (define-key map "q" 'kill-this-buffer)
1770 (defvar gdb-registers-font-lock-keywords
1772 ("^[^ ]+" . font-lock-variable-name-face)
1774 "Font lock keywords used in `gdb-registers-mode'.")
1776 (defun gdb-registers-mode ()
1777 "Major mode for gdb registers.
1779 \\{gdb-registers-mode-map}"
1780 (kill-all-local-variables)
1781 (setq major-mode 'gdb-registers-mode)
1782 (setq mode-name "Registers:")
1783 (setq buffer-read-only t)
1784 (use-local-map gdb-registers-mode-map)
1785 (set (make-local-variable 'font-lock-defaults)
1786 '(gdb-registers-font-lock-keywords))
1787 (run-mode-hooks 'gdb-registers-mode-hook)
1788 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1789 'gdb-invalidate-registers
1790 'gdbmi-invalidate-registers))
1792 (defun gdb-registers-buffer-name ()
1793 (with-current-buffer gud-comint-buffer
1794 (concat "*registers of " (gdb-get-target-string) "*")))
1796 (defun gdb-display-registers-buffer ()
1797 "Display integer register contents."
1800 (gdb-get-create-buffer 'gdb-registers-buffer)))
1802 (defun gdb-frame-registers-buffer ()
1803 "Display integer register contents in a new frame."
1805 (let ((special-display-regexps (append special-display-regexps '(".*")))
1806 (special-display-frame-alist gdb-frame-parameters))
1807 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1809 (defun toggle-gdb-all-registers ()
1810 "Toggle the display of floating-point registers."
1812 (if gdb-all-registers
1814 (setq gdb-all-registers nil)
1815 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1816 (setq mode-name "Registers:")))
1817 (setq gdb-all-registers t)
1818 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1819 (setq mode-name "Registers:All")))
1820 (gdb-invalidate-registers))
1825 (defcustom gdb-memory-repeat-count 32
1826 "Number of data items in memory window."
1831 (defcustom gdb-memory-format "x"
1832 "Display format of data items in memory window."
1833 :type '(choice (const :tag "Hexadecimal" "x")
1834 (const :tag "Signed decimal" "d")
1835 (const :tag "Unsigned decimal" "u")
1836 (const :tag "Octal" "o")
1837 (const :tag "Binary" "t"))
1841 (defcustom gdb-memory-unit "w"
1842 "Unit size of data items in memory window."
1843 :type '(choice (const :tag "Byte" "b")
1844 (const :tag "Halfword" "h")
1845 (const :tag "Word" "w")
1846 (const :tag "Giant word" "g"))
1850 (gdb-set-buffer-rules 'gdb-memory-buffer
1851 'gdb-memory-buffer-name
1854 (def-gdb-auto-updated-buffer gdb-memory-buffer
1855 gdb-invalidate-memory
1856 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1857 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1858 gdb-read-memory-handler
1859 gdb-read-memory-custom)
1861 (defun gdb-read-memory-custom ()
1863 (goto-char (point-min))
1864 (if (looking-at "0x[[:xdigit:]]+")
1865 (setq gdb-memory-address (match-string 0)))))
1867 (defvar gdb-memory-mode-map
1868 (let ((map (make-sparse-keymap)))
1869 (suppress-keymap map)
1870 (define-key map "q" 'kill-this-buffer)
1873 (defun gdb-memory-set-address (event)
1874 "Set the start memory address."
1876 (save-selected-window
1877 (select-window (posn-window (event-start event)))
1878 (let ((arg (read-from-minibuffer "Memory address: ")))
1879 (setq gdb-memory-address arg))
1880 (gdb-invalidate-memory)))
1882 (defun gdb-memory-set-repeat-count (event)
1883 "Set the number of data items in memory window."
1885 (save-selected-window
1886 (select-window (posn-window (event-start event)))
1887 (let* ((arg (read-from-minibuffer "Repeat count: "))
1888 (count (string-to-number arg)))
1890 (error "Positive numbers only")
1891 (customize-set-variable 'gdb-memory-repeat-count count)
1892 (gdb-invalidate-memory)))))
1894 (defun gdb-memory-format-binary ()
1895 "Set the display format to binary."
1897 (customize-set-variable 'gdb-memory-format "t")
1898 (gdb-invalidate-memory))
1900 (defun gdb-memory-format-octal ()
1901 "Set the display format to octal."
1903 (customize-set-variable 'gdb-memory-format "o")
1904 (gdb-invalidate-memory))
1906 (defun gdb-memory-format-unsigned ()
1907 "Set the display format to unsigned decimal."
1909 (customize-set-variable 'gdb-memory-format "u")
1910 (gdb-invalidate-memory))
1912 (defun gdb-memory-format-signed ()
1913 "Set the display format to decimal."
1915 (customize-set-variable 'gdb-memory-format "d")
1916 (gdb-invalidate-memory))
1918 (defun gdb-memory-format-hexadecimal ()
1919 "Set the display format to hexadecimal."
1921 (customize-set-variable 'gdb-memory-format "x")
1922 (gdb-invalidate-memory))
1924 (defvar gdb-memory-format-keymap
1925 (let ((map (make-sparse-keymap)))
1926 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1928 "Keymap to select format in the header line.")
1930 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1931 "Menu of display formats in the header line.")
1933 (define-key gdb-memory-format-menu [binary]
1934 '(menu-item "Binary" gdb-memory-format-binary
1935 :button (:radio . (equal gdb-memory-format "t"))))
1936 (define-key gdb-memory-format-menu [octal]
1937 '(menu-item "Octal" gdb-memory-format-octal
1938 :button (:radio . (equal gdb-memory-format "o"))))
1939 (define-key gdb-memory-format-menu [unsigned]
1940 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
1941 :button (:radio . (equal gdb-memory-format "u"))))
1942 (define-key gdb-memory-format-menu [signed]
1943 '(menu-item "Signed Decimal" gdb-memory-format-signed
1944 :button (:radio . (equal gdb-memory-format "d"))))
1945 (define-key gdb-memory-format-menu [hexadecimal]
1946 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
1947 :button (:radio . (equal gdb-memory-format "x"))))
1949 (defun gdb-memory-format-menu (event)
1951 (x-popup-menu event gdb-memory-format-menu))
1953 (defun gdb-memory-format-menu-1 (event)
1955 (save-selected-window
1956 (select-window (posn-window (event-start event)))
1957 (let* ((selection (gdb-memory-format-menu event))
1958 (binding (and selection (lookup-key gdb-memory-format-menu
1959 (vector (car selection))))))
1960 (if binding (call-interactively binding)))))
1962 (defun gdb-memory-unit-giant ()
1963 "Set the unit size to giant words (eight bytes)."
1965 (customize-set-variable 'gdb-memory-unit "g")
1966 (gdb-invalidate-memory))
1968 (defun gdb-memory-unit-word ()
1969 "Set the unit size to words (four bytes)."
1971 (customize-set-variable 'gdb-memory-unit "w")
1972 (gdb-invalidate-memory))
1974 (defun gdb-memory-unit-halfword ()
1975 "Set the unit size to halfwords (two bytes)."
1977 (customize-set-variable 'gdb-memory-unit "h")
1978 (gdb-invalidate-memory))
1980 (defun gdb-memory-unit-byte ()
1981 "Set the unit size to bytes."
1983 (customize-set-variable 'gdb-memory-unit "b")
1984 (gdb-invalidate-memory))
1986 (defvar gdb-memory-unit-keymap
1987 (let ((map (make-sparse-keymap)))
1988 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
1990 "Keymap to select units in the header line.")
1992 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
1993 "Menu of units in the header line.")
1995 (define-key gdb-memory-unit-menu [giantwords]
1996 '(menu-item "Giant words" gdb-memory-unit-giant
1997 :button (:radio . (equal gdb-memory-unit "g"))))
1998 (define-key gdb-memory-unit-menu [words]
1999 '(menu-item "Words" gdb-memory-unit-word
2000 :button (:radio . (equal gdb-memory-unit "w"))))
2001 (define-key gdb-memory-unit-menu [halfwords]
2002 '(menu-item "Halfwords" gdb-memory-unit-halfword
2003 :button (:radio . (equal gdb-memory-unit "h"))))
2004 (define-key gdb-memory-unit-menu [bytes]
2005 '(menu-item "Bytes" gdb-memory-unit-byte
2006 :button (:radio . (equal gdb-memory-unit "b"))))
2008 (defun gdb-memory-unit-menu (event)
2010 (x-popup-menu event gdb-memory-unit-menu))
2012 (defun gdb-memory-unit-menu-1 (event)
2014 (save-selected-window
2015 (select-window (posn-window (event-start event)))
2016 (let* ((selection (gdb-memory-unit-menu event))
2017 (binding (and selection (lookup-key gdb-memory-unit-menu
2018 (vector (car selection))))))
2019 (if binding (call-interactively binding)))))
2021 ;;from make-mode-line-mouse-map
2022 (defun gdb-make-header-line-mouse-map (mouse function) "\
2023 Return a keymap with single entry for mouse key MOUSE on the header line.
2024 MOUSE is defined to run function FUNCTION with no args in the buffer
2025 corresponding to the mode line clicked."
2026 (let ((map (make-sparse-keymap)))
2027 (define-key map (vector 'header-line mouse) function)
2028 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2031 (defvar gdb-memory-font-lock-keywords
2032 '(;; <__function.name+n>
2033 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2035 "Font lock keywords used in `gdb-memory-mode'.")
2037 (defun gdb-memory-mode ()
2038 "Major mode for examining memory.
2040 \\{gdb-memory-mode-map}"
2041 (kill-all-local-variables)
2042 (setq major-mode 'gdb-memory-mode)
2043 (setq mode-name "Memory")
2044 (setq buffer-read-only t)
2045 (use-local-map gdb-memory-mode-map)
2046 (setq header-line-format
2052 'face font-lock-warning-face
2053 'help-echo "mouse-1: Decrement address"
2054 'mouse-face 'mode-line-highlight
2056 (gdb-make-header-line-mouse-map
2058 #'(lambda () (interactive)
2059 (let ((gdb-memory-address
2060 ;; Let GDB do the arithmetic.
2062 gdb-memory-address " - "
2064 (* gdb-memory-repeat-count
2065 (cond ((string= gdb-memory-unit "b") 1)
2066 ((string= gdb-memory-unit "h") 2)
2067 ((string= gdb-memory-unit "w") 4)
2068 ((string= gdb-memory-unit "g") 8)))))))
2069 (gdb-invalidate-memory)))))
2072 'face font-lock-warning-face
2073 'help-echo "mouse-1: Increment address"
2074 'mouse-face 'mode-line-highlight
2075 'local-map (gdb-make-header-line-mouse-map
2077 #'(lambda () (interactive)
2078 (let ((gdb-memory-address nil))
2079 (gdb-invalidate-memory)))))
2081 (propertize gdb-memory-address
2082 'face font-lock-warning-face
2083 'help-echo "mouse-1: Set memory address"
2084 'mouse-face 'mode-line-highlight
2085 'local-map (gdb-make-header-line-mouse-map
2087 #'gdb-memory-set-address))
2089 (propertize (number-to-string gdb-memory-repeat-count)
2090 'face font-lock-warning-face
2091 'help-echo "mouse-1: Set repeat count"
2092 'mouse-face 'mode-line-highlight
2093 'local-map (gdb-make-header-line-mouse-map
2095 #'gdb-memory-set-repeat-count))
2097 (propertize gdb-memory-format
2098 'face font-lock-warning-face
2099 'help-echo "mouse-3: Select display format"
2100 'mouse-face 'mode-line-highlight
2101 'local-map gdb-memory-format-keymap)
2103 (propertize gdb-memory-unit
2104 'face font-lock-warning-face
2105 'help-echo "mouse-3: Select unit size"
2106 'mouse-face 'mode-line-highlight
2107 'local-map gdb-memory-unit-keymap))))
2108 (set (make-local-variable 'font-lock-defaults)
2109 '(gdb-memory-font-lock-keywords))
2110 (run-mode-hooks 'gdb-memory-mode-hook)
2111 'gdb-invalidate-memory)
2113 (defun gdb-memory-buffer-name ()
2114 (with-current-buffer gud-comint-buffer
2115 (concat "*memory of " (gdb-get-target-string) "*")))
2117 (defun gdb-display-memory-buffer ()
2118 "Display memory contents."
2121 (gdb-get-create-buffer 'gdb-memory-buffer)))
2123 (defun gdb-frame-memory-buffer ()
2124 "Display memory contents in a new frame."
2126 (let ((special-display-regexps (append special-display-regexps '(".*")))
2127 (special-display-frame-alist gdb-frame-parameters))
2128 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2133 (gdb-set-buffer-rules 'gdb-locals-buffer
2134 'gdb-locals-buffer-name
2137 (def-gdb-auto-updated-buffer gdb-locals-buffer
2138 gdb-invalidate-locals
2139 "server info locals\n"
2140 gdb-info-locals-handler
2141 gdb-info-locals-custom)
2143 ;; Abbreviate for arrays and structures.
2144 ;; These can be expanded using gud-display.
2145 (defun gdb-info-locals-handler nil
2146 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2147 gdb-pending-triggers))
2148 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2149 (with-current-buffer buf
2150 (goto-char (point-min))
2151 (while (re-search-forward "^[ }].*\n" nil t)
2152 (replace-match "" nil nil))
2153 (goto-char (point-min))
2154 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2155 (replace-match "(structure);\n" nil nil))
2156 (goto-char (point-min))
2157 (while (re-search-forward "\\s-*{.*\n" nil t)
2158 (replace-match " (array);\n" nil nil))))
2159 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2161 (with-current-buffer buf
2162 (let* ((window (get-buffer-window buf 0))
2163 (p (window-point window))
2164 (buffer-read-only nil))
2166 (insert-buffer-substring (gdb-get-create-buffer
2167 'gdb-partial-output-buffer))
2168 (set-window-point window p)))))
2169 (run-hooks 'gdb-info-locals-hook))
2171 (defun gdb-info-locals-custom ()
2174 (defvar gdb-locals-mode-map
2175 (let ((map (make-sparse-keymap)))
2176 (suppress-keymap map)
2177 (define-key map "q" 'kill-this-buffer)
2180 (defvar gdb-local-font-lock-keywords
2182 ;; var = (struct struct_tag) value
2183 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2184 (1 font-lock-variable-name-face)
2185 (3 font-lock-keyword-face)
2186 (4 font-lock-type-face))
2187 ;; var = (type) value
2188 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2189 (1 font-lock-variable-name-face)
2190 (3 font-lock-type-face))
2192 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2193 (1 font-lock-variable-name-face))
2195 "Font lock keywords used in `gdb-local-mode'.")
2197 (defun gdb-locals-mode ()
2198 "Major mode for gdb locals.
2200 \\{gdb-locals-mode-map}"
2201 (kill-all-local-variables)
2202 (setq major-mode 'gdb-locals-mode)
2203 (setq mode-name (concat "Locals:" gdb-selected-frame))
2204 (setq buffer-read-only t)
2205 (use-local-map gdb-locals-mode-map)
2206 (set (make-local-variable 'font-lock-defaults)
2207 '(gdb-local-font-lock-keywords))
2208 (run-mode-hooks 'gdb-locals-mode-hook)
2209 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
2210 'gdb-invalidate-locals
2211 'gdbmi-invalidate-locals))
2213 (defun gdb-locals-buffer-name ()
2214 (with-current-buffer gud-comint-buffer
2215 (concat "*locals of " (gdb-get-target-string) "*")))
2217 (defun gdb-display-locals-buffer ()
2218 "Display local variables of current stack and their values."
2221 (gdb-get-create-buffer 'gdb-locals-buffer)))
2223 (defun gdb-frame-locals-buffer ()
2224 "Display local variables of current stack and their values in a new frame."
2226 (let ((special-display-regexps (append special-display-regexps '(".*")))
2227 (special-display-frame-alist gdb-frame-parameters))
2228 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2231 ;;;; Window management
2232 (defun gdb-display-buffer (buf &optional size)
2233 (let ((answer (get-buffer-window buf 0))
2236 (display-buffer buf nil 0) ;Raise the frame if necessary.
2237 ;; The buffer is not yet displayed.
2238 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2239 (let ((window (get-lru-window)))
2241 (not (eq window (get-buffer-window gud-comint-buffer))))
2243 (set-window-buffer window buf)
2244 (setq answer window))
2245 (setq must-split t)))
2247 (let* ((largest (get-largest-window))
2248 (cur-size (window-height largest))
2249 (new-size (and size (< size cur-size) (- cur-size size))))
2250 (setq answer (split-window largest new-size))
2251 (set-window-buffer answer buf)
2252 (set-window-dedicated-p answer t)))
2256 ;;; Shared keymap initialization:
2258 (let ((menu (make-sparse-keymap "GDB-Windows")))
2259 (define-key gud-menu-map [displays]
2260 `(menu-item "GDB-Windows" ,menu
2261 :visible (memq gud-minor-mode '(gdbmi gdba))))
2262 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2263 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2264 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2265 (define-key menu [disassembly]
2266 '("Disassembly" . gdb-display-assembler-buffer))
2267 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2268 (define-key menu [inferior]
2269 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2270 :enable gdb-use-inferior-io-buffer))
2271 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2272 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2273 (define-key menu [breakpoints]
2274 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2276 (let ((menu (make-sparse-keymap "GDB-Frames")))
2277 (define-key gud-menu-map [frames]
2278 `(menu-item "GDB-Frames" ,menu
2279 :visible (memq gud-minor-mode '(gdbmi gdba))))
2280 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2281 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2282 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2283 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2284 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2285 (define-key menu [inferior]
2286 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2287 :enable gdb-use-inferior-io-buffer))
2288 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2289 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2290 (define-key menu [breakpoints]
2291 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2293 (let ((menu (make-sparse-keymap "GDB-UI")))
2294 (define-key gud-menu-map [ui]
2295 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2296 (define-key menu [gdb-use-inferior-io]
2297 ;; See defadvice below.
2298 (menu-bar-make-toggle toggle-gdb-use-inferior-io-buffer
2299 gdb-use-inferior-io-buffer
2300 "Separate inferior IO" "Use separate IO %s"
2301 "Toggle separate IO for inferior."))
2302 (define-key menu [gdb-many-windows]
2303 '(menu-item "Display Other Windows" gdb-many-windows
2304 :help "Toggle display of locals, stack and breakpoint information"
2305 :button (:toggle . gdb-many-windows)))
2306 (define-key menu [gdb-restore-windows]
2307 '(menu-item "Restore Window Layout" gdb-restore-windows
2308 :help "Restore standard layout for debug session.")))
2310 ;; This function is defined above through a macro.
2311 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
2312 (unless gdb-use-inferior-io-buffer
2313 (kill-buffer (gdb-inferior-io-name))))
2315 (defun gdb-frame-gdb-buffer ()
2316 "Display GUD buffer in a new frame."
2318 (select-frame (make-frame gdb-frame-parameters))
2319 (switch-to-buffer (gdb-get-create-buffer 'gdba))
2320 (set-window-dedicated-p (selected-window) t))
2322 (defun gdb-display-gdb-buffer ()
2323 "Display GUD buffer."
2326 (gdb-get-create-buffer 'gdba)))
2328 (defun gdb-set-window-buffer (name)
2329 (set-window-buffer (selected-window) (get-buffer name))
2330 (set-window-dedicated-p (selected-window) t))
2332 (defun gdb-setup-windows ()
2333 "Layout the window pattern for `gdb-many-windows'."
2334 (gdb-display-locals-buffer)
2335 (gdb-display-stack-buffer)
2336 (delete-other-windows)
2337 (gdb-display-breakpoints-buffer)
2338 (delete-other-windows)
2340 (pop-to-buffer gud-comint-buffer)
2341 (split-window nil ( / ( * (window-height) 3) 4))
2342 (split-window nil ( / (window-height) 3))
2343 (split-window-horizontally)
2345 (gdb-set-window-buffer (gdb-locals-buffer-name))
2348 (if gud-last-last-frame
2349 (gud-find-file (car gud-last-last-frame))
2350 (gud-find-file gdb-main-file)))
2351 (when gdb-use-inferior-io-buffer
2352 (split-window-horizontally)
2354 (gdb-set-window-buffer
2355 (gdb-get-create-buffer 'gdb-inferior-io)))
2357 (gdb-set-window-buffer (gdb-stack-buffer-name))
2358 (split-window-horizontally)
2360 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2363 (defcustom gdb-many-windows nil
2364 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2365 In this case it starts with two windows: one displaying the GUD
2366 buffer and the other with the source file with the main routine
2367 of the inferior. Non-nil means display the layout shown for
2373 (defun gdb-many-windows (arg)
2374 "Toggle the number of windows in the basic arrangement."
2376 (setq gdb-many-windows
2378 (not gdb-many-windows)
2379 (> (prefix-numeric-value arg) 0)))
2381 (gdb-restore-windows)
2384 (defun gdb-restore-windows ()
2385 "Restore the basic arrangement of windows used by gdba.
2386 This arrangement depends on the value of `gdb-many-windows'."
2388 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2389 (delete-other-windows)
2390 (if gdb-many-windows
2395 (if gud-last-last-frame
2396 (gud-find-file (car gud-last-last-frame))
2397 (gud-find-file gdb-main-file)))
2401 "Exit a debugging session cleanly.
2402 Kills the gdb buffers and resets the source buffers."
2403 (dolist (buffer (buffer-list))
2404 (unless (eq buffer gud-comint-buffer)
2405 (with-current-buffer buffer
2406 (if (memq gud-minor-mode '(gdbmi gdba))
2407 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2409 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2410 (setq gud-minor-mode nil)
2411 (kill-local-variable 'tool-bar-map)
2412 (kill-local-variable 'gdb-define-alist))))))
2413 (when (markerp gdb-overlay-arrow-position)
2414 (move-marker gdb-overlay-arrow-position nil)
2415 (setq gdb-overlay-arrow-position nil))
2416 (setq overlay-arrow-variable-list
2417 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2418 (setq gud-running nil)
2419 (setq gdb-active-process nil)
2420 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2422 (defun gdb-source-info ()
2423 "Find the source file where the program starts and displays it with related
2425 (goto-char (point-min))
2426 (if (and (search-forward "Located in " nil t)
2427 (looking-at "\\S-+"))
2428 (setq gdb-main-file (match-string 0)))
2429 (goto-char (point-min))
2430 (if (search-forward "Includes preprocessor macro info." nil t)
2431 (setq gdb-macro-info t))
2432 (if gdb-many-windows
2434 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2436 (let ((pop-up-windows t))
2437 (display-buffer (gud-find-file gdb-main-file))))))
2439 (defun gdb-get-location (bptno line flag)
2440 "Find the directory containing the relevant source file.
2441 Put in buffer and place breakpoint icon."
2442 (goto-char (point-min))
2443 (catch 'file-not-found
2444 (if (search-forward "Located in " nil t)
2445 (when (looking-at "\\S-+")
2446 (delete (cons bptno "File not found") gdb-location-alist)
2447 (push (cons bptno (match-string 0)) gdb-location-alist))
2449 (unless (assoc bptno gdb-location-alist)
2450 (push (cons bptno "File not found") gdb-location-alist)
2451 (message-box "Cannot find source file for breakpoint location.\n\
2452 Add directory to search path for source files using the GDB command, dir."))
2453 (throw 'file-not-found nil))
2454 (with-current-buffer
2455 (find-file-noselect (match-string 0))
2456 (save-current-buffer
2457 (set (make-local-variable 'gud-minor-mode) 'gdba)
2458 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2459 ;; only want one breakpoint icon at each location
2461 (goto-line (string-to-number line))
2462 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2464 (add-hook 'find-file-hook 'gdb-find-file-hook)
2466 (defun gdb-find-file-hook ()
2467 "Set up buffer for debugging if file is part of the source code
2468 of the current session."
2469 (if (and (not gdb-find-file-unhook)
2470 ;; in case gud or gdb-ui is just loaded
2472 (buffer-name gud-comint-buffer)
2473 (with-current-buffer gud-comint-buffer
2474 (eq gud-minor-mode 'gdba)))
2477 (list (concat gdb-server-prefix "list "
2478 (file-name-nondirectory buffer-file-name)
2480 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2481 (error (setq gdb-find-file-unhook t)))))
2484 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2485 "Put string PUTSTRING in front of POS in the current buffer.
2486 PUTSTRING is displayed by putting an overlay into the current buffer with a
2487 `before-string' string that has a `display' property whose value is
2489 (let ((string (make-string 1 ?x))
2490 (buffer (current-buffer)))
2491 (setq putstring (copy-sequence putstring))
2492 (let ((overlay (make-overlay pos pos buffer))
2494 (list (list 'margin 'left-margin) putstring))))
2495 (put-text-property 0 1 'display prop string)
2497 (add-text-properties 0 1 sprops string))
2498 (overlay-put overlay 'put-break t)
2499 (overlay-put overlay 'before-string string))))
2501 ;;from remove-images
2502 (defun gdb-remove-strings (start end &optional buffer)
2503 "Remove strings between START and END in BUFFER.
2504 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2505 BUFFER nil or omitted means use the current buffer."
2507 (setq buffer (current-buffer)))
2508 (dolist (overlay (overlays-in start end))
2509 (when (overlay-get overlay 'put-break)
2510 (delete-overlay overlay))))
2512 (defun gdb-put-breakpoint-icon (enabled bptno)
2513 (let ((start (- (line-beginning-position) 1))
2514 (end (+ (line-end-position) 1))
2515 (putstring (if enabled "B" "b"))
2516 (source-window (get-buffer-window (current-buffer) 0)))
2517 (add-text-properties
2518 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2521 (add-text-properties
2522 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2523 (add-text-properties
2524 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2525 (gdb-remove-breakpoint-icons start end)
2526 (if (display-images-p)
2527 (if (>= (or left-fringe-width
2528 (if source-window (car (window-fringes source-window)))
2529 gdb-buffer-fringe-width) 8)
2532 `(left-fringe breakpoint
2535 'breakpoint-disabled))
2537 'gdb-enabled enabled)
2538 (when (< left-margin-width 2)
2539 (save-current-buffer
2540 (setq left-margin-width 2)
2544 left-margin-width right-margin-width))))
2547 (or breakpoint-enabled-icon
2548 (setq breakpoint-enabled-icon
2549 (find-image `((:type xpm :data
2550 ,breakpoint-xpm-data
2551 :ascent 100 :pointer hand)
2553 ,breakpoint-enabled-pbm-data
2554 :ascent 100 :pointer hand)))))
2555 (or breakpoint-disabled-icon
2556 (setq breakpoint-disabled-icon
2557 (find-image `((:type xpm :data
2558 ,breakpoint-xpm-data
2559 :conversion disabled
2560 :ascent 100 :pointer hand)
2562 ,breakpoint-disabled-pbm-data
2563 :ascent 100 :pointer hand))))))
2567 (when (< left-margin-width 2)
2568 (save-current-buffer
2569 (setq left-margin-width 2)
2570 (let ((window (get-buffer-window (current-buffer) 0)))
2573 window left-margin-width right-margin-width)))))
2575 (propertize putstring
2576 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2579 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2580 (gdb-remove-strings start end)
2581 (if (display-images-p)
2582 (remove-images start end))
2584 (setq left-margin-width 0)
2585 (let ((window (get-buffer-window (current-buffer) 0)))
2588 window left-margin-width right-margin-width)))))
2592 ;; Assembler buffer.
2594 (gdb-set-buffer-rules 'gdb-assembler-buffer
2595 'gdb-assembler-buffer-name
2596 'gdb-assembler-mode)
2598 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2599 gdb-invalidate-assembler
2600 (concat gdb-server-prefix "disassemble "
2601 (if (member gdb-frame-address '(nil "main")) nil "0x")
2602 gdb-frame-address "\n")
2603 gdb-assembler-handler
2604 gdb-assembler-custom)
2606 (defun gdb-assembler-custom ()
2607 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2608 (pos 1) (address) (flag) (bptno))
2609 (with-current-buffer buffer
2611 (if (not (equal gdb-frame-address "main"))
2613 (goto-char (point-min))
2614 (if (and gdb-frame-address
2615 (re-search-forward gdb-frame-address nil t))
2619 (or gdb-overlay-arrow-position
2620 (setq gdb-overlay-arrow-position (make-marker)))
2621 (set-marker gdb-overlay-arrow-position
2622 (point) (current-buffer))))))
2623 ;; remove all breakpoint-icons in assembler buffer before updating.
2624 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2625 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2626 (goto-char (point-min))
2627 (while (< (point) (- (point-max) 1))
2629 (if (looking-at "[^\t].*?breakpoint")
2632 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2633 (setq bptno (match-string 1))
2634 (setq flag (char-after (match-beginning 2)))
2635 (setq address (match-string 3))
2636 (with-current-buffer buffer
2638 (goto-char (point-min))
2639 (if (re-search-forward address nil t)
2640 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2641 (if (not (equal gdb-frame-address "main"))
2642 (set-window-point (get-buffer-window buffer 0) pos))))
2644 (defvar gdb-assembler-mode-map
2645 (let ((map (make-sparse-keymap)))
2646 (suppress-keymap map)
2647 (define-key map "q" 'kill-this-buffer)
2650 (defvar gdb-assembler-font-lock-keywords
2651 '(;; <__function.name+n>
2652 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2653 (1 font-lock-function-name-face))
2654 ;; 0xNNNNNNNN <__function.name+n>: opcode
2655 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2656 (4 font-lock-keyword-face))
2657 ;; %register(at least i386)
2658 ("%\\sw+" . font-lock-variable-name-face)
2659 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2660 (1 font-lock-comment-face)
2661 (2 font-lock-function-name-face))
2662 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2663 "Font lock keywords used in `gdb-assembler-mode'.")
2665 (defun gdb-assembler-mode ()
2666 "Major mode for viewing code assembler.
2668 \\{gdb-assembler-mode-map}"
2669 (kill-all-local-variables)
2670 (setq major-mode 'gdb-assembler-mode)
2671 (setq mode-name (concat "Machine:" gdb-selected-frame))
2672 (setq gdb-overlay-arrow-position nil)
2673 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2674 (setq fringes-outside-margins t)
2675 (setq buffer-read-only t)
2676 (use-local-map gdb-assembler-mode-map)
2677 (gdb-invalidate-assembler)
2678 (set (make-local-variable 'font-lock-defaults)
2679 '(gdb-assembler-font-lock-keywords))
2680 (run-mode-hooks 'gdb-assembler-mode-hook)
2681 'gdb-invalidate-assembler)
2683 (defun gdb-assembler-buffer-name ()
2684 (with-current-buffer gud-comint-buffer
2685 (concat "*Disassembly of " (gdb-get-target-string) "*")))
2687 (defun gdb-display-assembler-buffer ()
2688 "Display disassembly view."
2690 (setq gdb-previous-frame nil)
2692 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2694 (defun gdb-frame-assembler-buffer ()
2695 "Display disassembly view in a new frame."
2697 (setq gdb-previous-frame nil)
2698 (let ((special-display-regexps (append special-display-regexps '(".*")))
2699 (special-display-frame-alist gdb-frame-parameters))
2700 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2702 ;; modified because if gdb-frame-address has changed value a new command
2703 ;; must be enqueued to update the buffer with the new output
2704 (defun gdb-invalidate-assembler (&optional ignored)
2705 (if (gdb-get-buffer 'gdb-assembler-buffer)
2707 (unless (and gdb-selected-frame
2708 (string-equal gdb-selected-frame gdb-previous-frame))
2709 (if (or (not (member 'gdb-invalidate-assembler
2710 gdb-pending-triggers))
2711 (not (string-equal gdb-frame-address
2712 gdb-previous-frame-address)))
2714 ;; take previous disassemble command, if any, off the queue
2715 (with-current-buffer gud-comint-buffer
2716 (let ((queue gdb-input-queue))
2717 (dolist (item queue)
2718 (if (equal (cdr item) '(gdb-assembler-handler))
2719 (setq gdb-input-queue
2720 (delete item gdb-input-queue))))))
2723 (concat gdb-server-prefix "disassemble "
2724 (if (member gdb-frame-address '(nil "main")) nil "0x")
2725 gdb-frame-address "\n")
2726 'gdb-assembler-handler))
2727 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2728 (setq gdb-previous-frame-address gdb-frame-address)
2729 (setq gdb-previous-frame gdb-selected-frame)))))))
2731 (defun gdb-get-selected-frame ()
2732 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2735 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2736 (push 'gdb-get-selected-frame
2737 gdb-pending-triggers))))
2739 (defun gdb-frame-handler ()
2740 (setq gdb-pending-triggers
2741 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2742 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2743 (goto-char (point-min))
2744 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2745 (setq gdb-frame-number (match-string 1)))
2746 (goto-char (point-min))
2747 (if (re-search-forward
2748 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2750 (setq gdb-selected-frame (match-string 2))
2751 (if (gdb-get-buffer 'gdb-locals-buffer)
2752 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2753 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2754 (if (gdb-get-buffer 'gdb-assembler-buffer)
2755 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2756 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2757 (setq gdb-frame-address (match-string 1))))
2758 (goto-char (point-min))
2759 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2760 (setq gdb-current-language (match-string 1))))
2761 (gdb-invalidate-assembler))
2765 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2766 ;;; gdb-ui.el ends here