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.
53 ;; This mode SHOULD WORK WITH GDB 5.0 ONWARDS but you will NEED GDB 6.0
54 ;; ONWARDS TO USE WATCH EXPRESSIONS.
58 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
59 ;; explicitly in your program if you want timely display of I/O in Emacs.
60 ;; Alternatively you can make the output stream unbuffered, for example, by
64 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
67 ;; and compiling with -DUNBUFFERED while debugging.
70 ;; 1) Strings that are watched don't update in the speedbar when their
72 ;; 2) Watch expressions go out of scope when the inferior is re-run.
75 ;; 1) Use MI command -data-read-memory for memory window.
76 ;; 2) Highlight changed register values (use MI commands
77 ;; -data-list-register-values and -data-list-changed-registers instead
78 ;; of 'info registers'.
79 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
80 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
81 ;; 5) After release of 22.1, use "-var-list-children --all-values"
82 ;; and "-stack-list-locals --simple-values" which need GDB 6.1 onwards.
83 ;; 6) After release of 22.1, use "-var-update --all-values" which needs
85 ;; 7) With gud-print and gud-pstar, print the variable name in the GUD
86 ;; buffer instead of the value's history number.
94 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
95 (defvar gdb-previous-frame-address nil)
96 (defvar gdb-memory-address "main")
97 (defvar gdb-previous-frame nil)
98 (defvar gdb-selected-frame nil)
99 (defvar gdb-frame-number nil)
100 (defvar gdb-current-language nil)
101 (defvar gdb-var-list nil "List of variables in watch window.")
102 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
103 (defvar gdb-main-file nil "Source file from which program execution begins.")
104 (defvar gdb-overlay-arrow-position nil)
105 (defvar gdb-server-prefix nil)
106 (defvar gdb-flush-pending-output nil)
107 (defvar gdb-location-alist nil
108 "Alist of breakpoint numbers and full filenames.")
109 (defvar gdb-find-file-unhook nil)
110 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
111 and #define directives otherwise.")
112 (defvar gdb-error "Non-nil when GDB is reporting an error.")
113 (defvar gdb-macro-info nil
114 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
115 (defvar gdb-buffer-fringe-width nil)
117 (defvar gdb-buffer-type nil
118 "One of the symbols bound in `gdb-buffer-rules'.")
119 (make-variable-buffer-local 'gdb-buffer-type)
121 (defvar gdb-input-queue ()
122 "A list of gdb command objects.")
124 (defvar gdb-prompting nil
125 "True when gdb is idle with no pending input.")
127 (defvar gdb-output-sink 'user
128 "The disposition of the output of the current gdb command.
129 Possible values are these symbols:
131 `user' -- gdb output should be copied to the GUD buffer
134 `inferior' -- gdb output should be copied to the inferior-io buffer.
136 `pre-emacs' -- output should be ignored util the post-prompt
137 annotation is received. Then the output-sink
139 `emacs' -- output should be collected in the partial-output-buffer
140 for subsequent processing by a command. This is the
141 disposition of output generated by commands that
142 gdb mode sends to gdb on its own behalf.
143 `post-emacs' -- ignore output until the prompt annotation is
144 received, then go to USER disposition.
146 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
147 \(`user' and `emacs').")
149 (defvar gdb-current-item nil
150 "The most recent command item sent to gdb.")
152 (defvar gdb-pending-triggers '()
153 "A list of trigger functions that have run later than their output
156 ;; end of gdb variables
159 (defun gdba (command-line)
160 "Run gdb on program FILE in buffer *gud-FILE*.
161 The directory containing FILE becomes the initial working directory
162 and source-file directory for your debugger.
164 If `gdb-many-windows' is nil (the default value) then gdb just
165 pops up the GUD buffer unless `gdb-show-main' is t. In this case
166 it starts with two windows: one displaying the GUD buffer and the
167 other with the source file with the main routine of the inferior.
169 If `gdb-many-windows' is t, regardless of the value of
170 `gdb-show-main', the layout below will appear unless
171 `gdb-use-inferior-io-buffer' is nil when the source buffer
172 occupies the full width of the frame. Keybindings are given in
175 Watch expressions appear in the speedbar/slowbar.
177 The following commands help control operation :
179 `gdb-many-windows' - Toggle the number of windows gdb uses.
180 `gdb-restore-windows' - To restore the window layout.
182 See Info node `(emacs)GDB Graphical Interface' for a more
183 detailed description of this mode.
186 +--------------------------------------------------------------+
188 +-------------------------------+------------------------------+
189 | GUD buffer (I/O of GDB) | Locals buffer |
193 +-------------------------------+------------------------------+
194 | Source buffer | I/O buffer (of inferior) |
202 +-------------------------------+------------------------------+
203 | Stack buffer | Breakpoints buffer |
204 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
205 | | RET gdb-goto-breakpoint |
206 | | d gdb-delete-breakpoint |
207 +-------------------------------+------------------------------+"
209 (interactive (list (gud-query-cmdline 'gdba)))
211 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
215 (defvar gdb-debug-log nil)
218 (defcustom gdb-enable-debug-log nil
219 "Non-nil means record the process input and output in `gdb-debug-log'."
224 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
225 "Shell command for generating a list of defined macros in a source file.
226 This list is used to display the #define directive associated
227 with an identifier as a tooltip. It works in a debug session with
228 GDB, when gud-tooltip-mode is t.
230 Set `gdb-cpp-define-alist-flags' for any include paths or
236 (defcustom gdb-cpp-define-alist-flags ""
237 "Preprocessor flags for `gdb-cpp-define-alist-program'."
242 (defcustom gdb-show-main nil
243 "Non-nil means display source file containing the main routine at startup.
244 Also display the main routine in the disassembly buffer if present."
249 (defcustom gdb-use-inferior-io-buffer nil
250 "Non-nil means display output from the inferior in a separate buffer."
255 (defun gdb-use-inferior-io-buffer (arg)
256 "Toggle separate IO for inferior.
257 With arg, use separate IO iff arg is positive."
259 (setq gdb-use-inferior-io-buffer
261 (not gdb-use-inferior-io-buffer)
262 (> (prefix-numeric-value arg) 0)))
263 (if (and gud-comint-buffer
264 (buffer-name gud-comint-buffer))
266 (if gdb-use-inferior-io-buffer
267 (gdb-restore-windows)
268 (kill-buffer (gdb-inferior-io-name)))
271 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
273 (defun gdb-create-define-alist ()
274 "Create an alist of #define directives for GUD tooltips."
275 (let* ((file (buffer-file-name))
277 (with-output-to-string
278 (with-current-buffer standard-output
279 (call-process shell-file-name
280 (if (file-exists-p file) file nil)
281 (list t nil) nil "-c"
282 (concat gdb-cpp-define-alist-program " "
283 gdb-cpp-define-alist-flags)))))
284 (define-list (split-string output "\n" t))
286 (setq gdb-define-alist nil)
287 (dolist (define define-list)
288 (setq name (nth 1 (split-string define "[( ]")))
289 (push (cons name define) gdb-define-alist))))
291 (defun gdb-tooltip-print ()
293 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
294 (let ((string (buffer-string)))
295 ;; remove newline for gud-tooltip-echo-area
296 (substring string 0 (- (length string) 1))))
297 (or gud-tooltip-echo-area tooltip-use-echo-area)))
299 ;; If expr is a macro for a function don't print because of possible dangerous
300 ;; side-effects. Also printing a function within a tooltip generates an
301 ;; unexpected starting annotation (phase error).
302 (defun gdb-tooltip-print-1 (expr)
303 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
304 (goto-char (point-min))
305 (if (search-forward "expands to: " nil t)
306 (unless (looking-at "\\S-+.*(.*).*")
308 (list (concat gdb-server-prefix "print " expr "\n")
309 'gdb-tooltip-print))))))
311 (defun gdb-set-gud-minor-mode (buffer)
312 "Set `gud-minor-mode' from find-file if appropriate."
313 (goto-char (point-min))
314 (unless (search-forward "No source file named " nil t)
317 (list (concat gdb-server-prefix "info source\n")
318 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
319 (error (setq gdb-find-file-unhook t)))))
321 (defun gdb-set-gud-minor-mode-1 (buffer)
322 (goto-char (point-min))
323 (when (and (search-forward "Located in " nil t)
325 (string-equal (buffer-file-name buffer)
327 (with-current-buffer buffer
328 (set (make-local-variable 'gud-minor-mode) 'gdba)
329 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
330 (when gud-tooltip-mode
331 (make-local-variable 'gdb-define-alist)
332 (gdb-create-define-alist)
333 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
335 (defun gdb-set-gud-minor-mode-existing-buffers ()
336 (dolist (buffer (buffer-list))
337 (let ((file (buffer-file-name buffer)))
341 (list (concat gdb-server-prefix "list "
342 (file-name-nondirectory file) ":1\n")
343 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
345 (defun gdb-find-watch-expression ()
346 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
347 (varno (nth 1 var)) (expr))
348 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varno)
349 (dolist (var1 gdb-var-list)
350 (if (string-equal (nth 1 var1) (match-string 1 varno))
351 (setq expr (concat (car var1) "." (match-string 2 varno)))))
355 (setq gdb-debug-log nil)
356 (set (make-local-variable 'gud-minor-mode) 'gdba)
357 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
359 (gud-def gud-break (if (not (string-match "Machine" mode-name))
360 (gud-call "break %f:%l" arg)
364 (gud-call "break *%a" arg)))
365 "\C-b" "Set breakpoint at current line or address.")
367 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
368 (gud-call "clear %f:%l" arg)
372 (gud-call "clear *%a" arg)))
373 "\C-d" "Remove breakpoint at current line or address.")
375 (gud-def gud-until (if (not (string-match "Machine" mode-name))
376 (gud-call "until %f:%l" arg)
380 (gud-call "until *%a" arg)))
381 "\C-u" "Continue to current line or address.")
383 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
384 nil "Start or continue execution.")
386 ;; For debugging Emacs only.
390 "pp1 " (if (eq (buffer-local-value
391 'major-mode (window-buffer)) 'speedbar-mode)
392 (gdb-find-watch-expression) "%e")) arg)
393 nil "Print the emacs s-expression.")
395 (define-key gud-minor-mode-map [left-margin mouse-1]
396 'gdb-mouse-set-clear-breakpoint)
397 (define-key gud-minor-mode-map [left-fringe mouse-1]
398 'gdb-mouse-set-clear-breakpoint)
399 (define-key gud-minor-mode-map [left-fringe mouse-2]
401 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
403 (define-key gud-minor-mode-map [left-margin mouse-3]
404 'gdb-mouse-toggle-breakpoint-margin)
405 (define-key gud-minor-mode-map [left-fringe mouse-3]
406 'gdb-mouse-toggle-breakpoint-fringe)
408 (setq comint-input-sender 'gdb-send)
411 (setq gdb-frame-address (if gdb-show-main "main" nil))
412 (setq gdb-previous-frame-address nil
413 gdb-memory-address "main"
414 gdb-previous-frame nil
415 gdb-selected-frame nil
416 gdb-current-language nil
424 gdb-pending-triggers nil
425 gdb-output-sink 'user
426 gdb-server-prefix "server "
427 gdb-flush-pending-output nil
428 gdb-location-alist nil
429 gdb-find-file-unhook nil
432 gdb-buffer-fringe-width (car (window-fringes)))
434 (setq gdb-buffer-type 'gdba)
436 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
438 (if (eq window-system 'w32)
439 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
440 (gdb-enqueue-input (list "set height 0\n" 'ignore))
441 (gdb-enqueue-input (list "set width 0\n" 'ignore))
442 ;; find source file and compilation directory here
443 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
444 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
445 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
447 (gdb-set-gud-minor-mode-existing-buffers)
448 (run-hooks 'gdba-mode-hook))
450 (defun gdb-mouse-until (event)
451 "Execute source lines by dragging the overlay arrow (fringe) with the mouse."
453 (if gud-overlay-arrow-position
454 (let ((start (event-start event))
455 (end (event-end event))
456 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
457 (if (not (string-match "Machine" mode-name))
458 (if (equal buffer (window-buffer (posn-window end)))
459 (with-current-buffer buffer
460 (when (or (equal start end)
461 (equal (posn-point start)
463 gud-overlay-arrow-position)))
464 (setq line (line-number-at-pos (posn-point end)))
465 (gud-call (concat "until " (number-to-string line))))))
466 (if (equal (marker-buffer gdb-overlay-arrow-position)
467 (window-buffer (posn-window end)))
468 (when (or (equal start end)
469 (equal (posn-point start)
471 gdb-overlay-arrow-position)))
473 (goto-line (line-number-at-pos (posn-point end)))
475 (gud-call (concat "until *%a")))))))))
477 (defcustom gdb-speedbar-auto-raise t
478 "If non-nil raise speedbar every time display of watch expressions is\
484 (defun gdb-speedbar-auto-raise (arg)
485 "Toggle automatic raising of the speedbar for watch expressions."
487 (setq gdb-speedbar-auto-raise
489 (not gdb-speedbar-auto-raise)
490 (> (prefix-numeric-value arg) 0))))
492 (defcustom gdb-use-colon-colon-notation nil
493 "If non-nil use FUN::VAR format to display variables in the speedbar."
499 "Watch expression at point."
502 (save-selected-window
503 (let ((expr (tooltip-identifier-from-point (point))))
504 (if (and (string-equal gdb-current-language "c")
505 gdb-use-colon-colon-notation gdb-selected-frame)
506 (setq expr (concat gdb-selected-frame "::" expr)))
507 (catch 'already-watched
508 (dolist (var gdb-var-list)
509 (if (string-equal expr (car var)) (throw 'already-watched nil)))
510 (set-text-properties 0 (length expr) nil expr)
513 (if (eq gud-minor-mode 'gdba)
514 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
515 (concat"-var-create - * " expr "\n"))
516 `(lambda () (gdb-var-create-handler ,expr))))))))
518 (defconst gdb-var-create-regexp
519 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
521 (defun gdb-var-create-handler (expr)
522 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
523 (goto-char (point-min))
524 (if (re-search-forward gdb-var-create-regexp nil t)
525 (let ((var (list expr
530 (push var gdb-var-list)
532 (unless (string-equal
533 speedbar-initial-expansion-list-name "GUD")
534 (speedbar-change-initial-expansion-list "GUD"))
537 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
539 (concat "server interpreter mi \"-var-evaluate-expression "
541 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
542 `(lambda () (gdb-var-evaluate-expression-handler
544 (setq gdb-var-changed t))
545 (if (re-search-forward "Undefined command" nil t)
546 (message-box "Watching expressions requires gdb 6.0 onwards")
547 (message "No symbol \"%s\" in current context." expr)))))
549 (defun gdb-var-evaluate-expression-handler (varnum changed)
550 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
551 (goto-char (point-min))
552 (re-search-forward ".*value=\\(\".*\"\\)" nil t)
555 (dolist (var gdb-var-list)
556 (if (string-equal varnum (cadr var))
558 (if changed (setcar (nthcdr 5 var) t))
559 (setcar (nthcdr 4 var) (read (match-string 1)))
560 (setcar (nthcdr num gdb-var-list) var)
561 (throw 'var-found nil)))
562 (setq num (+ num 1))))))
563 (setq gdb-var-changed t))
565 (defun gdb-var-list-children (varnum)
567 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
568 `(lambda () (gdb-var-list-children-handler ,varnum)))))
570 (defconst gdb-var-list-children-regexp
571 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",\
574 (defun gdb-var-list-children-handler (varnum)
575 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
576 (goto-char (point-min))
577 (let ((var-list nil))
578 (catch 'child-already-watched
579 (dolist (var gdb-var-list)
580 (if (string-equal varnum (cadr var))
583 (while (re-search-forward gdb-var-list-children-regexp nil t)
584 (let ((varchild (list (match-string 2)
589 (dolist (var1 gdb-var-list)
590 (if (string-equal (cadr var1) (cadr varchild))
591 (throw 'child-already-watched nil)))
592 (push varchild var-list)
596 "server interpreter mi \"-var-evaluate-expression "
597 (nth 1 varchild) "\"\n")
598 `(lambda () (gdb-var-evaluate-expression-handler
599 ,(nth 1 varchild) nil)))))))
600 (push var var-list)))
601 (setq gdb-var-list (nreverse var-list))))))
603 (defun gdb-var-update ()
604 (when (not (member 'gdb-var-update gdb-pending-triggers))
606 (list "server interpreter mi \"-var-update *\"\n"
607 'gdb-var-update-handler))
608 (push 'gdb-var-update gdb-pending-triggers)))
610 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
612 (defun gdb-var-update-handler ()
613 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
614 (goto-char (point-min))
615 (while (re-search-forward gdb-var-update-regexp nil t)
617 (let ((varnum (match-string 1)))
618 (dolist (var gdb-var-list)
621 (concat "server interpreter mi \"-var-evaluate-expression "
623 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t))))
624 (throw 'var-found-1 nil))))))
625 (setq gdb-pending-triggers
626 (delq 'gdb-var-update gdb-pending-triggers))
627 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
628 ;; Dummy command to update speedbar at right time.
629 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
630 ;; Keep gdb-pending-triggers non-nil till end.
631 (push 'gdb-speedbar-timer gdb-pending-triggers)))
633 (defun gdb-speedbar-timer-fn ()
634 (setq gdb-pending-triggers
635 (delq 'gdb-speedbar-timer gdb-pending-triggers))
636 (with-current-buffer gud-comint-buffer
637 (speedbar-timer-fn)))
639 (defun gdb-var-delete ()
640 "Delete watch expression at point from the speedbar."
642 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
644 (let ((text (speedbar-line-text)))
645 (string-match "\\(\\S-+\\)" text)
646 (let* ((expr (match-string 1 text))
647 (var (assoc expr gdb-var-list))
649 (unless (string-match "\\." varnum)
652 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
654 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
655 (concat "-var-delete " varnum "\n"))
657 (setq gdb-var-list (delq var gdb-var-list))
658 (dolist (varchild gdb-var-list)
659 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
660 (setq gdb-var-list (delq varchild gdb-var-list))))
661 (setq gdb-var-changed t))))))
663 (defun gdb-edit-value (text token indent)
664 "Assign a value to a variable displayed in the speedbar."
665 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
666 (varnum (cadr var)) (value))
667 (setq value (read-string "New value: "))
670 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
671 (concat "server interpreter mi \"-var-assign "
672 varnum " " value "\"\n")
673 (concat "-var-assign " varnum " " value "\n"))
676 (defcustom gdb-show-changed-values t
677 "If non-nil highlight values that have recently changed in the speedbar.
678 The highlighting is done with `font-lock-warning-face'."
683 (defun gdb-speedbar-expand-node (text token indent)
684 "Expand the node the user clicked on.
685 TEXT is the text of the button we clicked on, a + or - item.
686 TOKEN is data related to this node.
687 INDENT is the current indentation depth."
688 (cond ((string-match "+" text) ;expand this node
689 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
690 (gdb-var-list-children token)
693 (gdbmi-var-list-children token))))
694 ((string-match "-" text) ;contract this node
695 (dolist (var gdb-var-list)
696 (if (string-match (concat token "\\.") (nth 1 var))
697 (setq gdb-var-list (delq var gdb-var-list))))
698 (setq gdb-var-changed t)
699 (with-current-buffer gud-comint-buffer
700 (speedbar-timer-fn)))))
702 (defun gdb-get-target-string ()
703 (with-current-buffer gud-comint-buffer
710 ;; Each buffer has a TYPE -- a symbol that identifies the function
711 ;; of that particular buffer.
713 ;; The usual gdb interaction buffer is given the type `gdba' and
714 ;; is constructed specially.
716 ;; Others are constructed by gdb-get-create-buffer and
717 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
719 (defvar gdb-buffer-rules-assoc '())
721 (defun gdb-get-buffer (key)
722 "Return the gdb buffer tagged with type KEY.
723 The key should be one of the cars in `gdb-buffer-rules-assoc'."
725 (gdb-look-for-tagged-buffer key (buffer-list))))
727 (defun gdb-get-create-buffer (key)
728 "Create a new gdb buffer of the type specified by KEY.
729 The key should be one of the cars in `gdb-buffer-rules-assoc'."
730 (or (gdb-get-buffer key)
731 (let* ((rules (assoc key gdb-buffer-rules-assoc))
732 (name (funcall (gdb-rules-name-maker rules)))
733 (new (get-buffer-create name)))
734 (with-current-buffer new
736 (if (cdr (cdr rules))
737 (setq trigger (funcall (car (cdr (cdr rules))))))
738 (setq gdb-buffer-type key)
739 (set (make-local-variable 'gud-minor-mode)
740 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
741 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
742 (if trigger (funcall trigger)))
745 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
747 (defun gdb-look-for-tagged-buffer (key bufs)
749 (while (and (not retval) bufs)
750 (set-buffer (car bufs))
751 (if (eq gdb-buffer-type key)
752 (setq retval (car bufs)))
753 (setq bufs (cdr bufs)))
757 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
758 ;; at least one and possible more functions. The functions have these
759 ;; roles in defining a buffer type:
761 ;; NAME - Return a name for this buffer type.
763 ;; The remaining function(s) are optional:
765 ;; MODE - called in a new buffer with no arguments, should establish
766 ;; the proper mode for the buffer.
769 (defun gdb-set-buffer-rules (buffer-type &rest rules)
770 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
772 (setcdr binding rules)
773 (push (cons buffer-type rules)
774 gdb-buffer-rules-assoc))))
776 ;; GUD buffers are an exception to the rules
777 (gdb-set-buffer-rules 'gdba 'error)
780 ;; Partial-output buffer : This accumulates output from a command executed on
781 ;; behalf of emacs (rather than the user).
783 (gdb-set-buffer-rules 'gdb-partial-output-buffer
784 'gdb-partial-output-name)
786 (defun gdb-partial-output-name ()
787 (concat "*partial-output-"
788 (gdb-get-target-string)
792 (gdb-set-buffer-rules 'gdb-inferior-io
793 'gdb-inferior-io-name
794 'gdb-inferior-io-mode)
796 (defun gdb-inferior-io-name ()
797 (concat "*input/output of "
798 (gdb-get-target-string)
801 (defun gdb-display-inferior-io-buffer ()
802 "Display IO of inferior in a separate window."
804 (if gdb-use-inferior-io-buffer
806 (gdb-get-create-buffer 'gdb-inferior-io))))
808 (defconst gdb-frame-parameters
809 '((height . 14) (width . 80)
811 (tool-bar-lines . nil)
812 (menu-bar-lines . nil)
815 (defun gdb-frame-inferior-io-buffer ()
816 "Display IO of inferior in a new frame."
818 (if gdb-use-inferior-io-buffer
819 (let ((special-display-regexps (append special-display-regexps '(".*")))
820 (special-display-frame-alist gdb-frame-parameters))
821 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
823 (defvar gdb-inferior-io-mode-map
824 (let ((map (make-sparse-keymap)))
825 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
826 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
827 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
828 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
829 (define-key map "\C-d" 'gdb-inferior-io-eof)
832 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
833 "Major mode for gdb inferior-io."
834 :syntax-table nil :abbrev-table nil
835 ;; We want to use comint because it has various nifty and familiar
836 ;; features. We don't need a process, but comint wants one, so create
838 (make-comint-in-buffer
839 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
840 (current-buffer) "hexl")
841 (setq comint-input-sender 'gdb-inferior-io-sender))
843 (defun gdb-inferior-io-sender (proc string)
844 ;; PROC is the pseudo-process created to satisfy comint.
845 (with-current-buffer (process-buffer proc)
846 (setq proc (get-buffer-process gud-comint-buffer))
847 (process-send-string proc string)
848 (process-send-string proc "\n")))
850 (defun gdb-inferior-io-interrupt ()
851 "Interrupt the program being debugged."
854 (get-buffer-process gud-comint-buffer) comint-ptyp))
856 (defun gdb-inferior-io-quit ()
857 "Send quit signal to the program being debugged."
860 (get-buffer-process gud-comint-buffer) comint-ptyp))
862 (defun gdb-inferior-io-stop ()
863 "Stop the program being debugged."
866 (get-buffer-process gud-comint-buffer) comint-ptyp))
868 (defun gdb-inferior-io-eof ()
869 "Send end-of-file to the program being debugged."
872 (get-buffer-process gud-comint-buffer)))
876 ;; gdb communications
879 ;; INPUT: things sent to gdb
881 ;; The queues are lists. Each element is either a string (indicating user or
882 ;; user-like input) or a list of the form:
884 ;; (INPUT-STRING HANDLER-FN)
886 ;; The handler function will be called from the partial-output buffer when the
887 ;; command completes. This is the way to write commands which invoke gdb
888 ;; commands autonomously.
890 ;; These lists are consumed tail first.
893 (defun gdb-send (proc string)
894 "A comint send filter for gdb.
895 This filter may simply queue input for a later time."
896 (with-current-buffer gud-comint-buffer
897 (let ((inhibit-read-only t))
898 (remove-text-properties (point-min) (point-max) '(face))))
899 (let ((item (concat string "\n")))
902 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
903 (process-send-string proc item))
904 (gdb-enqueue-input item))))
906 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
907 ;; is a query, or other non-top-level prompt.
909 (defun gdb-enqueue-input (item)
913 (setq gdb-prompting nil))
914 (push item gdb-input-queue)))
916 (defun gdb-dequeue-input ()
917 (let ((queue gdb-input-queue))
919 (let ((last (car (last queue))))
920 (unless (nbutlast queue) (setq gdb-input-queue '()))
923 (defun gdb-send-item (item)
924 (setq gdb-flush-pending-output nil)
925 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
926 (setq gdb-current-item item)
927 (let ((process (get-buffer-process gud-comint-buffer)))
928 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
931 (setq gdb-output-sink 'user)
932 (process-send-string process item))
934 (gdb-clear-partial-output)
935 (setq gdb-output-sink 'pre-emacs)
936 (process-send-string process
938 ;; case: eq gud-minor-mode 'gdbmi
939 (gdb-clear-partial-output)
940 (setq gdb-output-sink 'emacs)
941 (process-send-string process (car item)))))
944 ;; output -- things gdb prints to emacs
946 ;; GDB output is a stream interrupted by annotations.
947 ;; Annotations can be recognized by their beginning
948 ;; with \C-j\C-z\C-z<tag><opt>\C-j
950 ;; The tag is a string obeying symbol syntax.
952 ;; The optional part `<opt>' can be either the empty string
953 ;; or a space followed by more data relating to the annotation.
954 ;; For example, the SOURCE annotation is followed by a filename,
955 ;; line number and various useless goo. This data must not include
959 (defcustom gud-gdba-command-name "gdb -annotate=3"
960 "Default command to execute an executable under the GDB-UI debugger."
965 (defvar gdb-annotation-rules
966 '(("pre-prompt" gdb-pre-prompt)
967 ("prompt" gdb-prompt)
968 ("commands" gdb-subprompt)
969 ("overload-choice" gdb-subprompt)
970 ("query" gdb-subprompt)
971 ;; Need this prompt for GDB 6.1
972 ("nquery" gdb-subprompt)
973 ("prompt-for-continue" gdb-subprompt)
974 ("post-prompt" gdb-post-prompt)
975 ("source" gdb-source)
976 ("starting" gdb-starting)
977 ("exited" gdb-exited)
978 ("signalled" gdb-exited)
979 ("signal" gdb-stopping)
980 ("breakpoint" gdb-stopping)
981 ("watchpoint" gdb-stopping)
982 ("frame-begin" gdb-frame-begin)
983 ("stopped" gdb-stopped)
984 ("error-begin" gdb-error)
986 ) "An assoc mapping annotation tags to functions which process them.")
989 (setq gdb-flush-pending-output t)
990 (setq gud-running nil)
991 (setq gdb-output-sink 'user)
992 (setq gdb-input-queue nil)
993 (setq gdb-pending-triggers nil)
994 (setq gdb-prompting t))
996 (defconst gdb-source-spec-regexp
997 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
999 ;; Do not use this except as an annotation handler.
1000 (defun gdb-source (args)
1001 (string-match gdb-source-spec-regexp args)
1002 ;; Extract the frame position from the marker.
1003 (setq gud-last-frame
1005 (match-string 1 args)
1006 (string-to-number (match-string 2 args))))
1007 (setq gdb-frame-address (match-string 3 args))
1008 ;; cover for auto-display output which comes *before*
1009 ;; stopped annotation
1010 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1012 (defun gdb-pre-prompt (ignored)
1013 "An annotation handler for `pre-prompt'.
1014 This terminates the collection of output from a previous command if that
1015 happens to be in effect."
1016 (let ((sink gdb-output-sink))
1020 (setq gdb-output-sink 'post-emacs))
1023 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1025 (defun gdb-prompt (ignored)
1026 "An annotation handler for `prompt'.
1027 This sends the next command (if any) to gdb."
1028 (when gdb-first-prompt (gdb-ann3))
1029 (let ((sink gdb-output-sink))
1032 ((eq sink 'post-emacs)
1033 (setq gdb-output-sink 'user)
1035 (car (cdr gdb-current-item))))
1036 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1037 (funcall handler))))
1040 (error "Phase error in gdb-prompt (got %s)" sink))))
1041 (let ((input (gdb-dequeue-input)))
1043 (gdb-send-item input)
1045 (setq gdb-prompting t)
1046 (gud-display-frame)))))
1048 (defun gdb-subprompt (ignored)
1049 "An annotation handler for non-top-level prompts."
1050 (setq gdb-prompting t))
1052 (defun gdb-starting (ignored)
1053 "An annotation handler for `starting'.
1054 This says that I/O for the subprocess is now the program being debugged,
1056 (setq gdb-active-process t)
1057 (let ((sink gdb-output-sink))
1061 (setq gud-running t)
1062 (if gdb-use-inferior-io-buffer
1063 (setq gdb-output-sink 'inferior))))
1066 (error "Unexpected `starting' annotation")))))
1068 (defun gdb-stopping (ignored)
1069 "An annotation handler for `breakpoint' and other annotations.
1070 They say that I/O for the subprocess is now GDB, not the program
1072 (if gdb-use-inferior-io-buffer
1073 (let ((sink gdb-output-sink))
1075 ((eq sink 'inferior)
1076 (setq gdb-output-sink 'user))
1079 (error "Unexpected stopping annotation"))))))
1081 (defun gdb-exited (ignored)
1082 "An annotation handler for `exited' and `signalled'.
1083 They say that I/O for the subprocess is now GDB, not the program
1084 being debugged and that the program is no longer running. This
1085 function is used to change the focus of GUD tooltips to #define
1087 (setq gdb-active-process nil)
1088 (setq gud-overlay-arrow-position nil)
1089 (setq gdb-overlay-arrow-position nil)
1090 (gdb-stopping ignored))
1092 (defun gdb-frame-begin (ignored)
1093 (let ((sink gdb-output-sink))
1095 ((eq sink 'inferior)
1096 (setq gdb-output-sink 'user))
1098 ((eq sink 'emacs) t)
1101 (error "Unexpected frame-begin annotation (%S)" sink)))))
1103 (defun gdb-stopped (ignored)
1104 "An annotation handler for `stopped'.
1105 It is just like `gdb-stopping', except that if we already set the output
1106 sink to `user' in `gdb-stopping', that is fine."
1107 (setq gud-running nil)
1108 (let ((sink gdb-output-sink))
1110 ((eq sink 'inferior)
1111 (setq gdb-output-sink 'user))
1115 (error "Unexpected stopped annotation")))))
1117 (defun gdb-error (ignored)
1118 (setq gdb-error (not gdb-error)))
1120 (defun gdb-post-prompt (ignored)
1121 "An annotation handler for `post-prompt'.
1122 This begins the collection of output from the current command if that
1123 happens to be appropriate."
1124 (unless gdb-pending-triggers
1125 (gdb-get-selected-frame)
1126 (gdb-invalidate-frames)
1127 (gdb-invalidate-breakpoints)
1128 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1129 ;; so gdb-frame-address is updated.
1130 ;; (gdb-invalidate-assembler)
1131 (gdb-invalidate-registers)
1132 (gdb-invalidate-memory)
1133 (gdb-invalidate-locals)
1134 (gdb-invalidate-threads)
1135 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1136 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1137 ;; Only needed/used with speedbar/watch expressions.
1138 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1139 (setq gdb-var-changed t) ; force update
1140 (dolist (var gdb-var-list)
1141 (setcar (nthcdr 5 var) nil))
1143 (let ((sink gdb-output-sink))
1146 ((eq sink 'pre-emacs)
1147 (setq gdb-output-sink 'emacs))
1150 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1152 (defun gud-gdba-marker-filter (string)
1153 "A gud marker filter for gdb. Handle a burst of output from GDB."
1154 (if gdb-flush-pending-output
1156 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1157 ;; Recall the left over gud-marker-acc from last time.
1158 (setq gud-marker-acc (concat gud-marker-acc string))
1159 ;; Start accumulating output for the GUD buffer.
1162 ;; Process all the complete markers in this chunk.
1163 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1164 (let ((annotation (match-string 1 gud-marker-acc)))
1166 ;; Stuff prior to the match is just ordinary output.
1167 ;; It is either concatenated to OUTPUT or directed
1172 (substring gud-marker-acc 0 (match-beginning 0))))
1174 ;; Take that stuff off the gud-marker-acc.
1175 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1177 ;; Parse the tag from the annotation, and maybe its arguments.
1178 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1179 (let* ((annotation-type (match-string 1 annotation))
1180 (annotation-arguments (match-string 2 annotation))
1181 (annotation-rule (assoc annotation-type
1182 gdb-annotation-rules)))
1183 ;; Call the handler for this annotation.
1185 (funcall (car (cdr annotation-rule))
1186 annotation-arguments)
1187 ;; Else the annotation is not recognized. Ignore it silently,
1188 ;; so that GDB can add new annotations without causing
1192 ;; Does the remaining text end in a partial line?
1193 ;; If it does, then keep part of the gud-marker-acc until we get more.
1194 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1197 ;; Everything before the potential marker start can be output.
1199 (gdb-concat-output output
1200 (substring gud-marker-acc 0
1201 (match-beginning 0))))
1203 ;; Everything after, we save, to combine with later input.
1204 (setq gud-marker-acc (substring gud-marker-acc
1205 (match-beginning 0))))
1207 ;; In case we know the gud-marker-acc contains no partial annotations:
1209 (setq output (gdb-concat-output output gud-marker-acc))
1210 (setq gud-marker-acc "")))
1213 (defun gdb-concat-output (so-far new)
1215 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1216 (let ((sink gdb-output-sink))
1218 ((eq sink 'user) (concat so-far new))
1219 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1221 (gdb-append-to-partial-output new)
1223 ((eq sink 'inferior)
1224 (gdb-append-to-inferior-io new)
1228 (error "Bogon output sink %S" sink)))))
1230 (defun gdb-append-to-partial-output (string)
1231 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1232 (goto-char (point-max))
1235 (defun gdb-clear-partial-output ()
1236 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1239 (defun gdb-append-to-inferior-io (string)
1240 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1241 (goto-char (point-max))
1242 (insert-before-markers string))
1243 (if (not (string-equal string ""))
1244 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1246 (defun gdb-clear-inferior-io ()
1247 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1251 ;; One trick is to have a command who's output is always available in a buffer
1252 ;; of it's own, and is always up to date. We build several buffers of this
1255 ;; There are two aspects to this: gdb has to tell us when the output for that
1256 ;; command might have changed, and we have to be able to run the command
1257 ;; behind the user's back.
1259 ;; The output phasing associated with the variable gdb-output-sink
1260 ;; help us to run commands behind the user's back.
1262 ;; Below is the code for specificly managing buffers of output from one
1266 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1267 ;; It adds an input for the command we are tracking. It should be the
1268 ;; annotation rule binding of whatever gdb sends to tell us this command
1269 ;; might have changed it's output.
1271 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1272 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1273 ;; input in the input queue (see comment about ``gdb communications'' above).
1275 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1277 `(defun ,name (&optional ignored)
1278 (if (and ,demand-predicate
1280 gdb-pending-triggers)))
1283 (list ,gdb-command ',output-handler))
1284 (push ',name gdb-pending-triggers)))))
1286 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1288 (setq gdb-pending-triggers
1290 gdb-pending-triggers))
1291 (let ((buf (gdb-get-buffer ',buf-key)))
1293 (with-current-buffer buf
1294 (let* ((window (get-buffer-window buf 0))
1295 (p (window-point window))
1296 (buffer-read-only nil))
1298 (insert-buffer-substring (gdb-get-create-buffer
1299 'gdb-partial-output-buffer))
1300 (set-window-point window p)))))
1301 ;; put customisation here
1304 (defmacro def-gdb-auto-updated-buffer (buffer-key
1305 trigger-name gdb-command
1306 output-handler-name custom-defun)
1308 (def-gdb-auto-update-trigger ,trigger-name
1309 ;; The demand predicate:
1310 (gdb-get-buffer ',buffer-key)
1312 ,output-handler-name)
1313 (def-gdb-auto-update-handler ,output-handler-name
1314 ,trigger-name ,buffer-key ,custom-defun)))
1318 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1320 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1321 'gdb-breakpoints-buffer-name
1322 'gdb-breakpoints-mode)
1324 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1325 ;; This defines the auto update rule for buffers of type
1326 ;; `gdb-breakpoints-buffer'.
1328 ;; It defines a function to serve as the annotation handler that
1329 ;; handles the `foo-invalidated' message. That function is called:
1330 gdb-invalidate-breakpoints
1332 ;; To update the buffer, this command is sent to gdb.
1333 "server info breakpoints\n"
1335 ;; This also defines a function to be the handler for the output
1336 ;; from the command above. That function will copy the output into
1337 ;; the appropriately typed buffer. That function will be called:
1338 gdb-info-breakpoints-handler
1339 ;; buffer specific functions
1340 gdb-info-breakpoints-custom)
1342 (defconst breakpoint-xpm-data
1344 static char *magick[] = {
1345 /* columns rows colors chars-per-pixel */
1361 "XPM data used for breakpoint icon.")
1363 (defconst breakpoint-enabled-pbm-data
1366 0 0 0 0 1 1 1 1 0 0 0 0
1367 0 0 0 1 1 1 1 1 1 0 0 0
1368 0 0 1 1 1 1 1 1 1 1 0 0
1369 0 1 1 1 1 1 1 1 1 1 1 0
1370 0 1 1 1 1 1 1 1 1 1 1 0
1371 0 1 1 1 1 1 1 1 1 1 1 0
1372 0 1 1 1 1 1 1 1 1 1 1 0
1373 0 0 1 1 1 1 1 1 1 1 0 0
1374 0 0 0 1 1 1 1 1 1 0 0 0
1375 0 0 0 0 1 1 1 1 0 0 0 0"
1376 "PBM data used for enabled breakpoint icon.")
1378 (defconst breakpoint-disabled-pbm-data
1390 0 0 0 1 0 1 0 1 0 0"
1391 "PBM data used for disabled breakpoint icon.")
1393 (defvar breakpoint-enabled-icon nil
1394 "Icon for enabled breakpoint in display margin.")
1396 (defvar breakpoint-disabled-icon nil
1397 "Icon for disabled breakpoint in display margin.")
1399 ;; Bitmap for breakpoint in fringe
1400 (and (display-images-p)
1401 (define-fringe-bitmap 'breakpoint
1402 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1404 (defface breakpoint-enabled
1408 "Face for enabled breakpoint icon in fringe."
1411 (defface breakpoint-disabled
1412 ;; We use different values of grey for different background types,
1413 ;; so that on low-color displays it will end up as something visible
1414 ;; if it has to be approximated.
1415 '((((background dark)) :foreground "grey60")
1416 (((background light)) :foreground "grey40"))
1417 "Face for disabled breakpoint icon in fringe."
1420 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1421 (defun gdb-info-breakpoints-custom ()
1422 (let ((flag) (bptno))
1423 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1424 (dolist (buffer (buffer-list))
1425 (with-current-buffer buffer
1426 (if (and (eq gud-minor-mode 'gdba)
1427 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1428 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1429 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1431 (goto-char (point-min))
1432 (while (< (point) (- (point-max) 1))
1434 (if (looking-at "[^\t].*?breakpoint")
1436 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1437 (setq bptno (match-string 1))
1438 (setq flag (char-after (match-beginning 2)))
1440 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1442 (let ((buffer-read-only nil))
1443 (add-text-properties (match-beginning 1) (match-end 1)
1444 '(face font-lock-function-name-face)))
1445 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1446 (let ((line (match-string 2)) (buffer-read-only nil)
1447 (file (match-string 1)))
1448 (add-text-properties (line-beginning-position)
1450 '(mouse-face highlight
1451 help-echo "mouse-2, RET: visit breakpoint"))
1452 (unless (file-exists-p file)
1453 (setq file (cdr (assoc bptno gdb-location-alist))))
1455 (not (string-equal file "File not found")))
1456 (with-current-buffer
1457 (find-file-noselect file 'nowarn)
1458 (set (make-local-variable 'gud-minor-mode)
1460 (set (make-local-variable 'tool-bar-map)
1462 ;; Only want one breakpoint icon at each
1465 (goto-line (string-to-number line))
1466 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1469 (concat gdb-server-prefix "list "
1470 (match-string-no-properties 1) ":1\n")
1473 (list (concat gdb-server-prefix "info source\n")
1474 `(lambda () (gdb-get-location
1475 ,bptno ,line ,flag))))))))))
1477 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1479 (defun gdb-mouse-set-clear-breakpoint (event)
1480 "Set/clear breakpoint in left fringe/margin with mouse click."
1482 (mouse-minibuffer-check event)
1483 (let ((posn (event-end event)))
1484 (if (numberp (posn-point posn))
1485 (with-selected-window (posn-window posn)
1487 (goto-char (posn-point posn))
1488 (if (or (posn-object posn)
1489 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1492 (gud-break nil)))))))
1494 (defun gdb-mouse-toggle-breakpoint-margin (event)
1495 "Enable/disable breakpoint in left margin with mouse click."
1497 (mouse-minibuffer-check event)
1498 (let ((posn (event-end event)))
1499 (if (numberp (posn-point posn))
1500 (with-selected-window (posn-window posn)
1502 (goto-char (posn-point posn))
1503 (if (posn-object posn)
1506 (let ((bptno (get-text-property
1507 0 'gdb-bptno (car (posn-string posn)))))
1508 (concat gdb-server-prefix
1509 (if (get-text-property
1510 0 'gdb-enabled (car (posn-string posn)))
1516 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1517 "Enable/disable breakpoint in left fringe with mouse click."
1519 (mouse-minibuffer-check event)
1520 (let* ((posn (event-end event))
1521 (pos (posn-point posn))
1524 (with-selected-window (posn-window posn)
1526 (set-buffer (window-buffer (selected-window)))
1528 (dolist (overlay (overlays-in pos pos))
1529 (when (overlay-get overlay 'put-break)
1530 (setq obj (overlay-get overlay 'before-string))))
1534 (concat gdb-server-prefix
1535 (if (get-text-property 0 'gdb-enabled obj)
1538 (get-text-property 0 'gdb-bptno obj) "\n")
1541 (defun gdb-breakpoints-buffer-name ()
1542 (with-current-buffer gud-comint-buffer
1543 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1545 (defun gdb-display-breakpoints-buffer ()
1546 "Display status of user-settable breakpoints."
1549 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1551 (defun gdb-frame-breakpoints-buffer ()
1552 "Display status of user-settable breakpoints in a new frame."
1554 (let ((special-display-regexps (append special-display-regexps '(".*")))
1555 (special-display-frame-alist gdb-frame-parameters))
1556 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1558 (defvar gdb-breakpoints-mode-map
1559 (let ((map (make-sparse-keymap))
1560 (menu (make-sparse-keymap "Breakpoints")))
1561 (define-key menu [quit] '("Quit" . kill-this-buffer))
1562 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1563 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1564 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1565 (suppress-keymap map)
1566 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1567 (define-key map " " 'gdb-toggle-breakpoint)
1568 (define-key map "d" 'gdb-delete-breakpoint)
1569 (define-key map "q" 'kill-this-buffer)
1570 (define-key map "\r" 'gdb-goto-breakpoint)
1571 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1572 (define-key map [follow-link] 'mouse-face)
1575 (defun gdb-breakpoints-mode ()
1576 "Major mode for gdb breakpoints.
1578 \\{gdb-breakpoints-mode-map}"
1579 (kill-all-local-variables)
1580 (setq major-mode 'gdb-breakpoints-mode)
1581 (setq mode-name "Breakpoints")
1582 (use-local-map gdb-breakpoints-mode-map)
1583 (setq buffer-read-only t)
1584 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1585 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1586 'gdb-invalidate-breakpoints
1587 'gdbmi-invalidate-breakpoints))
1589 (defun gdb-toggle-breakpoint ()
1590 "Enable/disable breakpoint at current line."
1593 (beginning-of-line 1)
1594 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1595 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1597 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1600 (concat gdb-server-prefix
1601 (if (eq ?y (char-after (match-beginning 2)))
1604 (match-string 1) "\n") 'ignore))
1605 (error "Not recognized as break/watchpoint line"))))
1607 (defun gdb-delete-breakpoint ()
1608 "Delete the breakpoint at current line."
1610 (beginning-of-line 1)
1611 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1612 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1614 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1617 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1618 (error "Not recognized as break/watchpoint line")))
1620 (defun gdb-goto-breakpoint (&optional event)
1621 "Display the breakpoint location specified at current line."
1622 (interactive (list last-input-event))
1623 (if event (posn-set-point (event-end event)))
1624 ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
1625 (let ((window (get-buffer-window gud-comint-buffer)))
1626 (if window (save-selected-window (select-window window))))
1628 (beginning-of-line 1)
1629 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1630 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1632 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1633 \\(\\S-+\\):\\([0-9]+\\)"))
1634 (let ((bptno (match-string 1))
1635 (file (match-string 2))
1636 (line (match-string 3)))
1637 (save-selected-window
1638 (let* ((buf (find-file-noselect
1639 (if (file-exists-p file) file
1640 (cdr (assoc bptno gdb-location-alist)))))
1641 (window (display-buffer buf)))
1642 (with-current-buffer buf
1643 (goto-line (string-to-number line))
1644 (set-window-point window (point))))))
1645 (error "Not recognized as break/watchpoint line"))))
1648 ;; Frames buffer. This displays a perpetually correct bactracktrace
1649 ;; (from the command `where').
1651 ;; Alas, if your stack is deep, it is costly.
1653 (gdb-set-buffer-rules 'gdb-stack-buffer
1654 'gdb-stack-buffer-name
1657 (def-gdb-auto-updated-buffer gdb-stack-buffer
1658 gdb-invalidate-frames
1660 gdb-info-frames-handler
1661 gdb-info-frames-custom)
1663 (defun gdb-info-frames-custom ()
1664 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1666 (let ((buffer-read-only nil)
1668 (goto-char (point-min))
1669 (while (< (point) (point-max))
1670 (setq bl (line-beginning-position)
1671 el (line-end-position))
1672 (when (looking-at "#")
1673 (add-text-properties bl el
1674 '(mouse-face highlight
1675 help-echo "mouse-2, RET: Select frame")))
1677 (when (looking-at "^#\\([0-9]+\\)")
1678 (when (string-equal (match-string 1) gdb-frame-number)
1679 (put-text-property bl (+ bl 4)
1680 'face '(:inverse-video t)))
1681 (when (re-search-forward
1683 (if (string-equal (match-string 1) "0") "" " in ")
1684 "\\([^ ]+\\) (") el t)
1685 (put-text-property (match-beginning 1) (match-end 1)
1686 'face font-lock-function-name-face)
1687 (setq bl (match-end 0))
1688 (while (re-search-forward "<\\([^>]+\\)>" el t)
1689 (put-text-property (match-beginning 1) (match-end 1)
1690 'face font-lock-function-name-face))
1692 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1693 (put-text-property (match-beginning 1) (match-end 1)
1694 'face font-lock-variable-name-face))))
1695 (forward-line 1))))))
1697 (defun gdb-stack-buffer-name ()
1698 (with-current-buffer gud-comint-buffer
1699 (concat "*stack frames of " (gdb-get-target-string) "*")))
1701 (defun gdb-display-stack-buffer ()
1702 "Display backtrace of current stack."
1705 (gdb-get-create-buffer 'gdb-stack-buffer)))
1707 (defun gdb-frame-stack-buffer ()
1708 "Display backtrace of current stack in a new frame."
1710 (let ((special-display-regexps (append special-display-regexps '(".*")))
1711 (special-display-frame-alist gdb-frame-parameters))
1712 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1714 (defvar gdb-frames-mode-map
1715 (let ((map (make-sparse-keymap)))
1716 (suppress-keymap map)
1717 (define-key map "q" 'kill-this-buffer)
1718 (define-key map "\r" 'gdb-frames-select)
1719 (define-key map [mouse-2] 'gdb-frames-select)
1720 (define-key map [follow-link] 'mouse-face)
1723 (defun gdb-frames-mode ()
1724 "Major mode for gdb frames.
1726 \\{gdb-frames-mode-map}"
1727 (kill-all-local-variables)
1728 (setq major-mode 'gdb-frames-mode)
1729 (setq mode-name "Frames")
1730 (setq buffer-read-only t)
1731 (use-local-map gdb-frames-mode-map)
1733 (run-mode-hooks 'gdb-frames-mode-hook)
1734 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1735 'gdb-invalidate-frames
1736 'gdbmi-invalidate-frames))
1738 (defun gdb-get-frame-number ()
1741 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1742 (n (or (and pos (match-string-no-properties 1)) "0")))
1745 (defun gdb-frames-select (&optional event)
1746 "Select the frame and display the relevant source."
1747 (interactive (list last-input-event))
1748 (if event (posn-set-point (event-end event)))
1750 (list (concat gdb-server-prefix "frame "
1751 (gdb-get-frame-number) "\n") 'ignore))
1752 (gud-display-frame))
1755 ;; Threads buffer. This displays a selectable thread list.
1757 (gdb-set-buffer-rules 'gdb-threads-buffer
1758 'gdb-threads-buffer-name
1761 (def-gdb-auto-updated-buffer gdb-threads-buffer
1762 gdb-invalidate-threads
1763 (concat gdb-server-prefix "info threads\n")
1764 gdb-info-threads-handler
1765 gdb-info-threads-custom)
1767 (defun gdb-info-threads-custom ()
1768 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1769 (let ((buffer-read-only nil))
1770 (goto-char (point-min))
1771 (while (< (point) (point-max))
1772 (unless (looking-at "No ")
1773 (add-text-properties (line-beginning-position) (line-end-position)
1774 '(mouse-face highlight
1775 help-echo "mouse-2, RET: select thread")))
1776 (forward-line 1)))))
1778 (defun gdb-threads-buffer-name ()
1779 (with-current-buffer gud-comint-buffer
1780 (concat "*threads of " (gdb-get-target-string) "*")))
1782 (defun gdb-display-threads-buffer ()
1783 "Display IDs of currently known threads."
1786 (gdb-get-create-buffer 'gdb-threads-buffer)))
1788 (defun gdb-frame-threads-buffer ()
1789 "Display IDs of currently known threads in a new frame."
1791 (let ((special-display-regexps (append special-display-regexps '(".*")))
1792 (special-display-frame-alist gdb-frame-parameters))
1793 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1795 (defvar gdb-threads-mode-map
1796 (let ((map (make-sparse-keymap)))
1797 (suppress-keymap map)
1798 (define-key map "q" 'kill-this-buffer)
1799 (define-key map "\r" 'gdb-threads-select)
1800 (define-key map [mouse-2] 'gdb-threads-select)
1803 (defvar gdb-threads-font-lock-keywords
1805 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1806 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1807 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1809 "Font lock keywords used in `gdb-threads-mode'.")
1811 (defun gdb-threads-mode ()
1812 "Major mode for gdb frames.
1814 \\{gdb-threads-mode-map}"
1815 (kill-all-local-variables)
1816 (setq major-mode 'gdb-threads-mode)
1817 (setq mode-name "Threads")
1818 (setq buffer-read-only t)
1819 (use-local-map gdb-threads-mode-map)
1820 (set (make-local-variable 'font-lock-defaults)
1821 '(gdb-threads-font-lock-keywords))
1822 (run-mode-hooks 'gdb-threads-mode-hook)
1823 'gdb-invalidate-threads)
1825 (defun gdb-get-thread-number ()
1827 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1828 (match-string-no-properties 1)))
1830 (defun gdb-threads-select (&optional event)
1831 "Select the thread and display the relevant source."
1832 (interactive (list last-input-event))
1833 (if event (posn-set-point (event-end event)))
1835 (list (concat gdb-server-prefix "thread "
1836 (gdb-get-thread-number) "\n") 'ignore))
1837 (gud-display-frame))
1840 ;; Registers buffer.
1842 (defcustom gdb-all-registers nil
1843 "Non-nil means include floating-point registers."
1848 (gdb-set-buffer-rules 'gdb-registers-buffer
1849 'gdb-registers-buffer-name
1850 'gdb-registers-mode)
1852 (def-gdb-auto-updated-buffer gdb-registers-buffer
1853 gdb-invalidate-registers
1855 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1856 gdb-info-registers-handler
1857 gdb-info-registers-custom)
1859 (defun gdb-info-registers-custom ()
1860 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1862 (let ((buffer-read-only nil)
1864 (goto-char (point-min))
1865 (while (< (point) (point-max))
1866 (setq start (line-beginning-position))
1867 (setq end (line-end-position))
1868 (when (looking-at "^[^ ]+")
1869 (unless (string-equal (match-string 0) "The")
1870 (put-text-property start (match-end 0)
1871 'face font-lock-variable-name-face)
1872 (add-text-properties start end
1873 '(help-echo "mouse-2: edit value"
1874 mouse-face highlight))))
1875 (forward-line 1))))))
1877 (defun gdb-edit-register-value (&optional event)
1878 (interactive (list last-input-event))
1880 (if event (posn-set-point (event-end event)))
1882 (let* ((register (current-word))
1883 (value (read-string (format "New value (%s): " register))))
1885 (list (concat gdb-server-prefix "set $" register "=" value "\n")
1888 (defvar gdb-registers-mode-map
1889 (let ((map (make-sparse-keymap)))
1890 (suppress-keymap map)
1891 (define-key map "\r" 'gdb-edit-register-value)
1892 (define-key map [mouse-2] 'gdb-edit-register-value)
1893 (define-key map " " 'toggle-gdb-all-registers)
1894 (define-key map "q" 'kill-this-buffer)
1897 (defun gdb-registers-mode ()
1898 "Major mode for gdb registers.
1900 \\{gdb-registers-mode-map}"
1901 (kill-all-local-variables)
1902 (setq major-mode 'gdb-registers-mode)
1903 (setq mode-name "Registers:")
1904 (setq buffer-read-only t)
1905 (use-local-map gdb-registers-mode-map)
1906 (run-mode-hooks 'gdb-registers-mode-hook)
1907 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1908 'gdb-invalidate-registers
1909 'gdbmi-invalidate-registers))
1911 (defun gdb-registers-buffer-name ()
1912 (with-current-buffer gud-comint-buffer
1913 (concat "*registers of " (gdb-get-target-string) "*")))
1915 (defun gdb-display-registers-buffer ()
1916 "Display integer register contents."
1919 (gdb-get-create-buffer 'gdb-registers-buffer)))
1921 (defun gdb-frame-registers-buffer ()
1922 "Display integer register contents in a new frame."
1924 (let ((special-display-regexps (append special-display-regexps '(".*")))
1925 (special-display-frame-alist gdb-frame-parameters))
1926 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1928 (defun toggle-gdb-all-registers ()
1929 "Toggle the display of floating-point registers."
1931 (if gdb-all-registers
1933 (setq gdb-all-registers nil)
1934 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1935 (setq mode-name "Registers:")))
1936 (setq gdb-all-registers t)
1937 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1938 (setq mode-name "Registers:All")))
1939 (gdb-invalidate-registers))
1944 (defcustom gdb-memory-repeat-count 32
1945 "Number of data items in memory window."
1950 (defcustom gdb-memory-format "x"
1951 "Display format of data items in memory window."
1952 :type '(choice (const :tag "Hexadecimal" "x")
1953 (const :tag "Signed decimal" "d")
1954 (const :tag "Unsigned decimal" "u")
1955 (const :tag "Octal" "o")
1956 (const :tag "Binary" "t"))
1960 (defcustom gdb-memory-unit "w"
1961 "Unit size of data items in memory window."
1962 :type '(choice (const :tag "Byte" "b")
1963 (const :tag "Halfword" "h")
1964 (const :tag "Word" "w")
1965 (const :tag "Giant word" "g"))
1969 (gdb-set-buffer-rules 'gdb-memory-buffer
1970 'gdb-memory-buffer-name
1973 (def-gdb-auto-updated-buffer gdb-memory-buffer
1974 gdb-invalidate-memory
1975 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1976 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1977 gdb-read-memory-handler
1978 gdb-read-memory-custom)
1980 (defun gdb-read-memory-custom ()
1982 (goto-char (point-min))
1983 (if (looking-at "0x[[:xdigit:]]+")
1984 (setq gdb-memory-address (match-string 0)))))
1986 (defvar gdb-memory-mode-map
1987 (let ((map (make-sparse-keymap)))
1988 (suppress-keymap map)
1989 (define-key map "q" 'kill-this-buffer)
1992 (defun gdb-memory-set-address (event)
1993 "Set the start memory address."
1995 (save-selected-window
1996 (select-window (posn-window (event-start event)))
1997 (let ((arg (read-from-minibuffer "Memory address: ")))
1998 (setq gdb-memory-address arg))
1999 (gdb-invalidate-memory)))
2001 (defun gdb-memory-set-repeat-count (event)
2002 "Set the number of data items in memory window."
2004 (save-selected-window
2005 (select-window (posn-window (event-start event)))
2006 (let* ((arg (read-from-minibuffer "Repeat count: "))
2007 (count (string-to-number arg)))
2009 (error "Positive numbers only")
2010 (customize-set-variable 'gdb-memory-repeat-count count)
2011 (gdb-invalidate-memory)))))
2013 (defun gdb-memory-format-binary ()
2014 "Set the display format to binary."
2016 (customize-set-variable 'gdb-memory-format "t")
2017 (gdb-invalidate-memory))
2019 (defun gdb-memory-format-octal ()
2020 "Set the display format to octal."
2022 (customize-set-variable 'gdb-memory-format "o")
2023 (gdb-invalidate-memory))
2025 (defun gdb-memory-format-unsigned ()
2026 "Set the display format to unsigned decimal."
2028 (customize-set-variable 'gdb-memory-format "u")
2029 (gdb-invalidate-memory))
2031 (defun gdb-memory-format-signed ()
2032 "Set the display format to decimal."
2034 (customize-set-variable 'gdb-memory-format "d")
2035 (gdb-invalidate-memory))
2037 (defun gdb-memory-format-hexadecimal ()
2038 "Set the display format to hexadecimal."
2040 (customize-set-variable 'gdb-memory-format "x")
2041 (gdb-invalidate-memory))
2043 (defvar gdb-memory-format-keymap
2044 (let ((map (make-sparse-keymap)))
2045 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2047 "Keymap to select format in the header line.")
2049 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2050 "Menu of display formats in the header line.")
2052 (define-key gdb-memory-format-menu [binary]
2053 '(menu-item "Binary" gdb-memory-format-binary
2054 :button (:radio . (equal gdb-memory-format "t"))))
2055 (define-key gdb-memory-format-menu [octal]
2056 '(menu-item "Octal" gdb-memory-format-octal
2057 :button (:radio . (equal gdb-memory-format "o"))))
2058 (define-key gdb-memory-format-menu [unsigned]
2059 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2060 :button (:radio . (equal gdb-memory-format "u"))))
2061 (define-key gdb-memory-format-menu [signed]
2062 '(menu-item "Signed Decimal" gdb-memory-format-signed
2063 :button (:radio . (equal gdb-memory-format "d"))))
2064 (define-key gdb-memory-format-menu [hexadecimal]
2065 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2066 :button (:radio . (equal gdb-memory-format "x"))))
2068 (defun gdb-memory-format-menu (event)
2070 (x-popup-menu event gdb-memory-format-menu))
2072 (defun gdb-memory-format-menu-1 (event)
2074 (save-selected-window
2075 (select-window (posn-window (event-start event)))
2076 (let* ((selection (gdb-memory-format-menu event))
2077 (binding (and selection (lookup-key gdb-memory-format-menu
2078 (vector (car selection))))))
2079 (if binding (call-interactively binding)))))
2081 (defun gdb-memory-unit-giant ()
2082 "Set the unit size to giant words (eight bytes)."
2084 (customize-set-variable 'gdb-memory-unit "g")
2085 (gdb-invalidate-memory))
2087 (defun gdb-memory-unit-word ()
2088 "Set the unit size to words (four bytes)."
2090 (customize-set-variable 'gdb-memory-unit "w")
2091 (gdb-invalidate-memory))
2093 (defun gdb-memory-unit-halfword ()
2094 "Set the unit size to halfwords (two bytes)."
2096 (customize-set-variable 'gdb-memory-unit "h")
2097 (gdb-invalidate-memory))
2099 (defun gdb-memory-unit-byte ()
2100 "Set the unit size to bytes."
2102 (customize-set-variable 'gdb-memory-unit "b")
2103 (gdb-invalidate-memory))
2105 (defvar gdb-memory-unit-keymap
2106 (let ((map (make-sparse-keymap)))
2107 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2109 "Keymap to select units in the header line.")
2111 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2112 "Menu of units in the header line.")
2114 (define-key gdb-memory-unit-menu [giantwords]
2115 '(menu-item "Giant words" gdb-memory-unit-giant
2116 :button (:radio . (equal gdb-memory-unit "g"))))
2117 (define-key gdb-memory-unit-menu [words]
2118 '(menu-item "Words" gdb-memory-unit-word
2119 :button (:radio . (equal gdb-memory-unit "w"))))
2120 (define-key gdb-memory-unit-menu [halfwords]
2121 '(menu-item "Halfwords" gdb-memory-unit-halfword
2122 :button (:radio . (equal gdb-memory-unit "h"))))
2123 (define-key gdb-memory-unit-menu [bytes]
2124 '(menu-item "Bytes" gdb-memory-unit-byte
2125 :button (:radio . (equal gdb-memory-unit "b"))))
2127 (defun gdb-memory-unit-menu (event)
2129 (x-popup-menu event gdb-memory-unit-menu))
2131 (defun gdb-memory-unit-menu-1 (event)
2133 (save-selected-window
2134 (select-window (posn-window (event-start event)))
2135 (let* ((selection (gdb-memory-unit-menu event))
2136 (binding (and selection (lookup-key gdb-memory-unit-menu
2137 (vector (car selection))))))
2138 (if binding (call-interactively binding)))))
2140 ;;from make-mode-line-mouse-map
2141 (defun gdb-make-header-line-mouse-map (mouse function) "\
2142 Return a keymap with single entry for mouse key MOUSE on the header line.
2143 MOUSE is defined to run function FUNCTION with no args in the buffer
2144 corresponding to the mode line clicked."
2145 (let ((map (make-sparse-keymap)))
2146 (define-key map (vector 'header-line mouse) function)
2147 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2150 (defvar gdb-memory-font-lock-keywords
2151 '(;; <__function.name+n>
2152 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2154 "Font lock keywords used in `gdb-memory-mode'.")
2156 (defun gdb-memory-mode ()
2157 "Major mode for examining memory.
2159 \\{gdb-memory-mode-map}"
2160 (kill-all-local-variables)
2161 (setq major-mode 'gdb-memory-mode)
2162 (setq mode-name "Memory")
2163 (setq buffer-read-only t)
2164 (use-local-map gdb-memory-mode-map)
2165 (setq header-line-format
2171 'face font-lock-warning-face
2172 'help-echo "mouse-1: Decrement address"
2173 'mouse-face 'mode-line-highlight
2175 (gdb-make-header-line-mouse-map
2177 #'(lambda () (interactive)
2178 (let ((gdb-memory-address
2179 ;; Let GDB do the arithmetic.
2181 gdb-memory-address " - "
2183 (* gdb-memory-repeat-count
2184 (cond ((string= gdb-memory-unit "b") 1)
2185 ((string= gdb-memory-unit "h") 2)
2186 ((string= gdb-memory-unit "w") 4)
2187 ((string= gdb-memory-unit "g") 8)))))))
2188 (gdb-invalidate-memory)))))
2191 'face font-lock-warning-face
2192 'help-echo "mouse-1: Increment address"
2193 'mouse-face 'mode-line-highlight
2194 'local-map (gdb-make-header-line-mouse-map
2196 #'(lambda () (interactive)
2197 (let ((gdb-memory-address nil))
2198 (gdb-invalidate-memory)))))
2200 (propertize gdb-memory-address
2201 'face font-lock-warning-face
2202 'help-echo "mouse-1: Set memory address"
2203 'mouse-face 'mode-line-highlight
2204 'local-map (gdb-make-header-line-mouse-map
2206 #'gdb-memory-set-address))
2208 (propertize (number-to-string gdb-memory-repeat-count)
2209 'face font-lock-warning-face
2210 'help-echo "mouse-1: Set repeat count"
2211 'mouse-face 'mode-line-highlight
2212 'local-map (gdb-make-header-line-mouse-map
2214 #'gdb-memory-set-repeat-count))
2216 (propertize gdb-memory-format
2217 'face font-lock-warning-face
2218 'help-echo "mouse-3: Select display format"
2219 'mouse-face 'mode-line-highlight
2220 'local-map gdb-memory-format-keymap)
2222 (propertize gdb-memory-unit
2223 'face font-lock-warning-face
2224 'help-echo "mouse-3: Select unit size"
2225 'mouse-face 'mode-line-highlight
2226 'local-map gdb-memory-unit-keymap))))
2227 (set (make-local-variable 'font-lock-defaults)
2228 '(gdb-memory-font-lock-keywords))
2229 (run-mode-hooks 'gdb-memory-mode-hook)
2230 'gdb-invalidate-memory)
2232 (defun gdb-memory-buffer-name ()
2233 (with-current-buffer gud-comint-buffer
2234 (concat "*memory of " (gdb-get-target-string) "*")))
2236 (defun gdb-display-memory-buffer ()
2237 "Display memory contents."
2240 (gdb-get-create-buffer 'gdb-memory-buffer)))
2242 (defun gdb-frame-memory-buffer ()
2243 "Display memory contents in a new frame."
2245 (let ((special-display-regexps (append special-display-regexps '(".*")))
2246 (special-display-frame-alist gdb-frame-parameters))
2247 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2252 (gdb-set-buffer-rules 'gdb-locals-buffer
2253 'gdb-locals-buffer-name
2256 (def-gdb-auto-update-trigger gdb-invalidate-locals
2257 (gdb-get-buffer 'gdb-locals-buffer)
2258 "server info locals\n"
2259 gdb-info-locals-handler)
2261 (defvar gdb-locals-watch-keymap
2262 (let ((map (make-sparse-keymap)))
2263 (define-key map "\r" '(lambda () (interactive)
2266 (define-key map [mouse-2] '(lambda (event) (interactive "e")
2267 (mouse-set-point event)
2271 "Keymap to create watch expression of a complex data type local variable.")
2273 (defconst gdb-struct-string
2274 (concat (propertize "[struct/union]"
2275 'mouse-face 'highlight
2276 'help-echo "mouse-2: create watch expression"
2277 'local-map gdb-locals-watch-keymap) "\n"))
2279 (defconst gdb-array-string
2280 (concat " " (propertize "[array]"
2281 'mouse-face 'highlight
2282 'help-echo "mouse-2: create watch expression"
2283 'local-map gdb-locals-watch-keymap) "\n"))
2285 ;; Abbreviate for arrays and structures.
2286 ;; These can be expanded using gud-display.
2287 (defun gdb-info-locals-handler ()
2288 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2289 gdb-pending-triggers))
2290 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2291 (with-current-buffer buf
2292 (goto-char (point-min))
2293 (while (re-search-forward "^[ }].*\n" nil t)
2294 (replace-match "" nil nil))
2295 (goto-char (point-min))
2296 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2297 (replace-match gdb-struct-string nil nil))
2298 (goto-char (point-min))
2299 (while (re-search-forward "\\s-*{.*\n" nil t)
2300 (replace-match gdb-array-string nil nil))))
2301 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2303 (with-current-buffer buf
2304 (let* ((window (get-buffer-window buf 0))
2305 (p (window-point window))
2306 (buffer-read-only nil))
2308 (insert-buffer-substring (gdb-get-create-buffer
2309 'gdb-partial-output-buffer))
2310 (set-window-point window p)))))
2311 (run-hooks 'gdb-info-locals-hook))
2313 (defvar gdb-locals-mode-map
2314 (let ((map (make-sparse-keymap)))
2315 (suppress-keymap map)
2316 (define-key map "q" 'kill-this-buffer)
2319 (defvar gdb-locals-font-lock-keywords
2321 ;; var = (struct struct_tag) value
2322 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2323 (1 font-lock-variable-name-face)
2324 (3 font-lock-keyword-face)
2325 (4 font-lock-type-face))
2326 ;; var = (type) value
2327 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2328 (1 font-lock-variable-name-face)
2329 (3 font-lock-type-face))
2331 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2332 (1 font-lock-variable-name-face))
2334 "Font lock keywords used in `gdb-local-mode'.")
2336 (defun gdb-locals-mode ()
2337 "Major mode for gdb locals.
2339 \\{gdb-locals-mode-map}"
2340 (kill-all-local-variables)
2341 (setq major-mode 'gdb-locals-mode)
2342 (setq mode-name (concat "Locals:" gdb-selected-frame))
2343 (setq buffer-read-only t)
2344 (use-local-map gdb-locals-mode-map)
2345 (set (make-local-variable 'font-lock-defaults)
2346 '(gdb-locals-font-lock-keywords))
2347 (run-mode-hooks 'gdb-locals-mode-hook)
2348 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2349 'gdb-invalidate-locals
2350 'gdbmi-invalidate-locals))
2352 (defun gdb-locals-buffer-name ()
2353 (with-current-buffer gud-comint-buffer
2354 (concat "*locals of " (gdb-get-target-string) "*")))
2356 (defun gdb-display-locals-buffer ()
2357 "Display local variables of current stack and their values."
2360 (gdb-get-create-buffer 'gdb-locals-buffer)))
2362 (defun gdb-frame-locals-buffer ()
2363 "Display local variables of current stack and their values in a new frame."
2365 (let ((special-display-regexps (append special-display-regexps '(".*")))
2366 (special-display-frame-alist gdb-frame-parameters))
2367 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2370 ;;;; Window management
2371 (defun gdb-display-buffer (buf &optional size)
2372 (let ((answer (get-buffer-window buf 0))
2375 (display-buffer buf nil 0) ;Raise the frame if necessary.
2376 ;; The buffer is not yet displayed.
2377 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2378 (let ((window (get-lru-window)))
2380 (not (eq window (get-buffer-window gud-comint-buffer))))
2382 (set-window-buffer window buf)
2383 (setq answer window))
2384 (setq must-split t)))
2386 (let* ((largest (get-largest-window))
2387 (cur-size (window-height largest))
2388 (new-size (and size (< size cur-size) (- cur-size size))))
2389 (setq answer (split-window largest new-size))
2390 (set-window-buffer answer buf)
2391 (set-window-dedicated-p answer t)))
2395 ;;; Shared keymap initialization:
2397 (let ((menu (make-sparse-keymap "GDB-Windows")))
2398 (define-key gud-menu-map [displays]
2399 `(menu-item "GDB-Windows" ,menu
2400 :visible (memq gud-minor-mode '(gdbmi gdba))))
2401 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2402 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2403 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2404 (define-key menu [disassembly]
2405 '("Disassembly" . gdb-display-assembler-buffer))
2406 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2407 (define-key menu [inferior]
2408 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2409 :enable gdb-use-inferior-io-buffer))
2410 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2411 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2412 (define-key menu [breakpoints]
2413 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2415 (let ((menu (make-sparse-keymap "GDB-Frames")))
2416 (define-key gud-menu-map [frames]
2417 `(menu-item "GDB-Frames" ,menu
2418 :visible (memq gud-minor-mode '(gdbmi gdba))))
2419 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2420 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2421 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2422 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2423 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2424 (define-key menu [inferior]
2425 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2426 :enable gdb-use-inferior-io-buffer))
2427 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2428 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2429 (define-key menu [breakpoints]
2430 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2432 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2433 (define-key gud-menu-map [ui]
2434 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2435 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2436 (define-key menu [gdb-use-inferior-io]
2437 '(menu-item "Separate inferior IO" gdb-use-inferior-io-buffer
2438 :visible (eq gud-minor-mode 'gdba)
2439 :help "Toggle separate IO for inferior."
2440 :button (:toggle . gdb-use-inferior-io-buffer)))
2441 (define-key menu [gdb-many-windows]
2442 '(menu-item "Display Other Windows" gdb-many-windows
2443 :help "Toggle display of locals, stack and breakpoint information"
2444 :button (:toggle . gdb-many-windows)))
2445 (define-key menu [gdb-restore-windows]
2446 '(menu-item "Restore Window Layout" gdb-restore-windows
2447 :help "Restore standard layout for debug session.")))
2449 (defun gdb-frame-gdb-buffer ()
2450 "Display GUD buffer in a new frame."
2452 (let ((special-display-regexps (append special-display-regexps '(".*")))
2453 (special-display-frame-alist gdb-frame-parameters)
2454 (same-window-regexps nil))
2455 (display-buffer gud-comint-buffer)))
2457 (defun gdb-display-gdb-buffer ()
2458 "Display GUD buffer."
2460 (let ((same-window-regexps nil))
2461 (pop-to-buffer gud-comint-buffer)))
2463 (defun gdb-set-window-buffer (name)
2464 (set-window-buffer (selected-window) (get-buffer name))
2465 (set-window-dedicated-p (selected-window) t))
2467 (defun gdb-setup-windows ()
2468 "Layout the window pattern for `gdb-many-windows'."
2469 (gdb-display-locals-buffer)
2470 (gdb-display-stack-buffer)
2471 (delete-other-windows)
2472 (gdb-display-breakpoints-buffer)
2473 (delete-other-windows)
2475 (pop-to-buffer gud-comint-buffer)
2476 (split-window nil ( / ( * (window-height) 3) 4))
2477 (split-window nil ( / (window-height) 3))
2478 (split-window-horizontally)
2480 (gdb-set-window-buffer (gdb-locals-buffer-name))
2483 (if gud-last-last-frame
2484 (gud-find-file (car gud-last-last-frame))
2485 (gud-find-file gdb-main-file)))
2486 (when gdb-use-inferior-io-buffer
2487 (split-window-horizontally)
2489 (gdb-set-window-buffer
2490 (gdb-get-create-buffer 'gdb-inferior-io)))
2492 (gdb-set-window-buffer (gdb-stack-buffer-name))
2493 (split-window-horizontally)
2495 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2498 (defcustom gdb-many-windows nil
2499 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2500 In this case it starts with two windows: one displaying the GUD
2501 buffer and the other with the source file with the main routine
2502 of the inferior. Non-nil means display the layout shown for
2508 (defun gdb-many-windows (arg)
2509 "Toggle the number of windows in the basic arrangement.
2510 With arg, display additional buffers iff arg is positive."
2512 (setq gdb-many-windows
2514 (not gdb-many-windows)
2515 (> (prefix-numeric-value arg) 0)))
2516 (if (and gud-comint-buffer
2517 (buffer-name gud-comint-buffer))
2519 (gdb-restore-windows)
2522 (defun gdb-restore-windows ()
2523 "Restore the basic arrangement of windows used by gdba.
2524 This arrangement depends on the value of `gdb-many-windows'."
2526 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2527 (delete-other-windows)
2528 (if gdb-many-windows
2530 (when (or gud-last-last-frame gdb-show-main)
2534 (if gud-last-last-frame
2535 (gud-find-file (car gud-last-last-frame))
2536 (gud-find-file gdb-main-file)))
2540 "Exit a debugging session cleanly.
2541 Kills the gdb buffers and resets the source buffers."
2542 (dolist (buffer (buffer-list))
2543 (unless (eq buffer gud-comint-buffer)
2544 (with-current-buffer buffer
2545 (if (memq gud-minor-mode '(gdbmi gdba))
2546 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2548 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2549 (setq gud-minor-mode nil)
2550 (kill-local-variable 'tool-bar-map)
2551 (kill-local-variable 'gdb-define-alist))))))
2552 (when (markerp gdb-overlay-arrow-position)
2553 (move-marker gdb-overlay-arrow-position nil)
2554 (setq gdb-overlay-arrow-position nil))
2555 (setq overlay-arrow-variable-list
2556 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2557 (setq gud-running nil)
2558 (setq gdb-active-process nil)
2559 (setq gdb-var-list nil)
2560 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2562 (defun gdb-source-info ()
2563 "Find the source file where the program starts and displays it with related
2565 (goto-char (point-min))
2566 (if (and (search-forward "Located in " nil t)
2567 (looking-at "\\S-+"))
2568 (setq gdb-main-file (match-string 0)))
2569 (goto-char (point-min))
2570 (if (search-forward "Includes preprocessor macro info." nil t)
2571 (setq gdb-macro-info t))
2572 (if gdb-many-windows
2574 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2576 (let ((pop-up-windows t))
2577 (display-buffer (gud-find-file gdb-main-file))))))
2579 (defun gdb-get-location (bptno line flag)
2580 "Find the directory containing the relevant source file.
2581 Put in buffer and place breakpoint icon."
2582 (goto-char (point-min))
2583 (catch 'file-not-found
2584 (if (search-forward "Located in " nil t)
2585 (when (looking-at "\\S-+")
2586 (delete (cons bptno "File not found") gdb-location-alist)
2587 (push (cons bptno (match-string 0)) gdb-location-alist))
2589 (unless (assoc bptno gdb-location-alist)
2590 (push (cons bptno "File not found") gdb-location-alist)
2591 (message-box "Cannot find source file for breakpoint location.\n\
2592 Add directory to search path for source files using the GDB command, dir."))
2593 (throw 'file-not-found nil))
2594 (with-current-buffer
2595 (find-file-noselect (match-string 0))
2596 (save-current-buffer
2597 (set (make-local-variable 'gud-minor-mode) 'gdba)
2598 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2599 ;; only want one breakpoint icon at each location
2601 (goto-line (string-to-number line))
2602 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2604 (add-hook 'find-file-hook 'gdb-find-file-hook)
2606 (defun gdb-find-file-hook ()
2607 "Set up buffer for debugging if file is part of the source code
2608 of the current session."
2609 (if (and (not gdb-find-file-unhook)
2610 ;; in case gud or gdb-ui is just loaded
2612 (buffer-name gud-comint-buffer)
2613 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2617 (list (concat gdb-server-prefix "list "
2618 (file-name-nondirectory buffer-file-name)
2620 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2621 (error (setq gdb-find-file-unhook t)))))
2624 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2625 "Put string PUTSTRING in front of POS in the current buffer.
2626 PUTSTRING is displayed by putting an overlay into the current buffer with a
2627 `before-string' string that has a `display' property whose value is
2629 (let ((string (make-string 1 ?x))
2630 (buffer (current-buffer)))
2631 (setq putstring (copy-sequence putstring))
2632 (let ((overlay (make-overlay pos pos buffer))
2634 (list (list 'margin 'left-margin) putstring))))
2635 (put-text-property 0 1 'display prop string)
2637 (add-text-properties 0 1 sprops string))
2638 (overlay-put overlay 'put-break t)
2639 (overlay-put overlay 'before-string string))))
2641 ;;from remove-images
2642 (defun gdb-remove-strings (start end &optional buffer)
2643 "Remove strings between START and END in BUFFER.
2644 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2645 BUFFER nil or omitted means use the current buffer."
2647 (setq buffer (current-buffer)))
2648 (dolist (overlay (overlays-in start end))
2649 (when (overlay-get overlay 'put-break)
2650 (delete-overlay overlay))))
2652 (defun gdb-put-breakpoint-icon (enabled bptno)
2653 (let ((start (- (line-beginning-position) 1))
2654 (end (+ (line-end-position) 1))
2655 (putstring (if enabled "B" "b"))
2656 (source-window (get-buffer-window (current-buffer) 0)))
2657 (add-text-properties
2658 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2661 (add-text-properties
2662 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2663 (add-text-properties
2664 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2665 (gdb-remove-breakpoint-icons start end)
2666 (if (display-images-p)
2667 (if (>= (or left-fringe-width
2668 (if source-window (car (window-fringes source-window)))
2669 gdb-buffer-fringe-width) 8)
2672 `(left-fringe breakpoint
2675 'breakpoint-disabled))
2677 'gdb-enabled enabled)
2678 (when (< left-margin-width 2)
2679 (save-current-buffer
2680 (setq left-margin-width 2)
2684 left-margin-width right-margin-width))))
2687 (or breakpoint-enabled-icon
2688 (setq breakpoint-enabled-icon
2689 (find-image `((:type xpm :data
2690 ,breakpoint-xpm-data
2691 :ascent 100 :pointer hand)
2693 ,breakpoint-enabled-pbm-data
2694 :ascent 100 :pointer hand)))))
2695 (or breakpoint-disabled-icon
2696 (setq breakpoint-disabled-icon
2697 (find-image `((:type xpm :data
2698 ,breakpoint-xpm-data
2699 :conversion disabled
2700 :ascent 100 :pointer hand)
2702 ,breakpoint-disabled-pbm-data
2703 :ascent 100 :pointer hand))))))
2707 (when (< left-margin-width 2)
2708 (save-current-buffer
2709 (setq left-margin-width 2)
2710 (let ((window (get-buffer-window (current-buffer) 0)))
2713 window left-margin-width right-margin-width)))))
2715 (propertize putstring
2716 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2719 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2720 (gdb-remove-strings start end)
2721 (if (display-images-p)
2722 (remove-images start end))
2724 (setq left-margin-width 0)
2725 (let ((window (get-buffer-window (current-buffer) 0)))
2728 window left-margin-width right-margin-width)))))
2732 ;; Assembler buffer.
2734 (gdb-set-buffer-rules 'gdb-assembler-buffer
2735 'gdb-assembler-buffer-name
2736 'gdb-assembler-mode)
2738 (def-gdb-auto-update-handler gdb-assembler-handler
2739 gdb-invalidate-assembler
2740 gdb-assembler-buffer
2741 gdb-assembler-custom)
2743 (defun gdb-assembler-custom ()
2744 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2745 (pos 1) (address) (flag) (bptno))
2746 (with-current-buffer buffer
2748 (if (not (equal gdb-frame-address "main"))
2750 (goto-char (point-min))
2751 (if (and gdb-frame-address
2752 (re-search-forward gdb-frame-address nil t))
2756 (or gdb-overlay-arrow-position
2757 (setq gdb-overlay-arrow-position (make-marker)))
2758 (set-marker gdb-overlay-arrow-position
2759 (point) (current-buffer))))))
2760 ;; remove all breakpoint-icons in assembler buffer before updating.
2761 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2762 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2763 (goto-char (point-min))
2764 (while (< (point) (- (point-max) 1))
2766 (if (looking-at "[^\t].*?breakpoint")
2769 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2770 (setq bptno (match-string 1))
2771 (setq flag (char-after (match-beginning 2)))
2772 (setq address (match-string 3))
2773 (with-current-buffer buffer
2775 (goto-char (point-min))
2776 (if (re-search-forward address nil t)
2777 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2778 (if (not (equal gdb-frame-address "main"))
2779 (with-current-buffer buffer
2780 (set-window-point (get-buffer-window buffer 0) pos)))))
2782 (defvar gdb-assembler-mode-map
2783 (let ((map (make-sparse-keymap)))
2784 (suppress-keymap map)
2785 (define-key map "q" 'kill-this-buffer)
2788 (defvar gdb-assembler-font-lock-keywords
2789 '(;; <__function.name+n>
2790 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2791 (1 font-lock-function-name-face))
2792 ;; 0xNNNNNNNN <__function.name+n>: opcode
2793 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2794 (4 font-lock-keyword-face))
2795 ;; %register(at least i386)
2796 ("%\\sw+" . font-lock-variable-name-face)
2797 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2798 (1 font-lock-comment-face)
2799 (2 font-lock-function-name-face))
2800 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2801 "Font lock keywords used in `gdb-assembler-mode'.")
2803 (defun gdb-assembler-mode ()
2804 "Major mode for viewing code assembler.
2806 \\{gdb-assembler-mode-map}"
2807 (kill-all-local-variables)
2808 (setq major-mode 'gdb-assembler-mode)
2809 (setq mode-name (concat "Machine:" gdb-selected-frame))
2810 (setq gdb-overlay-arrow-position nil)
2811 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2812 (setq fringes-outside-margins t)
2813 (setq buffer-read-only t)
2814 (use-local-map gdb-assembler-mode-map)
2815 (gdb-invalidate-assembler)
2816 (set (make-local-variable 'font-lock-defaults)
2817 '(gdb-assembler-font-lock-keywords))
2818 (run-mode-hooks 'gdb-assembler-mode-hook)
2819 'gdb-invalidate-assembler)
2821 (defun gdb-assembler-buffer-name ()
2822 (with-current-buffer gud-comint-buffer
2823 (concat "*disassembly of " (gdb-get-target-string) "*")))
2825 (defun gdb-display-assembler-buffer ()
2826 "Display disassembly view."
2828 (setq gdb-previous-frame nil)
2830 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2832 (defun gdb-frame-assembler-buffer ()
2833 "Display disassembly view in a new frame."
2835 (setq gdb-previous-frame nil)
2836 (let ((special-display-regexps (append special-display-regexps '(".*")))
2837 (special-display-frame-alist gdb-frame-parameters))
2838 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2840 ;; modified because if gdb-frame-address has changed value a new command
2841 ;; must be enqueued to update the buffer with the new output
2842 (defun gdb-invalidate-assembler (&optional ignored)
2843 (if (gdb-get-buffer 'gdb-assembler-buffer)
2845 (unless (and gdb-selected-frame
2846 (string-equal gdb-selected-frame gdb-previous-frame))
2847 (if (or (not (member 'gdb-invalidate-assembler
2848 gdb-pending-triggers))
2849 (not (string-equal gdb-frame-address
2850 gdb-previous-frame-address)))
2852 ;; take previous disassemble command, if any, off the queue
2853 (with-current-buffer gud-comint-buffer
2854 (let ((queue gdb-input-queue))
2855 (dolist (item queue)
2856 (if (equal (cdr item) '(gdb-assembler-handler))
2857 (setq gdb-input-queue
2858 (delete item gdb-input-queue))))))
2861 (concat gdb-server-prefix "disassemble "
2862 (if (member gdb-frame-address '(nil "main")) nil "0x")
2863 gdb-frame-address "\n")
2864 'gdb-assembler-handler))
2865 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2866 (setq gdb-previous-frame-address gdb-frame-address)
2867 (setq gdb-previous-frame gdb-selected-frame)))))))
2869 (defun gdb-get-selected-frame ()
2870 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2873 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2874 (push 'gdb-get-selected-frame
2875 gdb-pending-triggers))))
2877 (defun gdb-frame-handler ()
2878 (setq gdb-pending-triggers
2879 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2880 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2881 (goto-char (point-min))
2882 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2883 (setq gdb-frame-number (match-string 1)))
2884 (goto-char (point-min))
2885 (if (re-search-forward
2886 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2888 (setq gdb-selected-frame (match-string 2))
2889 (if (gdb-get-buffer 'gdb-locals-buffer)
2890 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2891 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2892 (if (gdb-get-buffer 'gdb-assembler-buffer)
2893 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2894 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2895 (setq gdb-frame-address (match-string 1))))
2896 (goto-char (point-min))
2897 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2898 (setq gdb-current-language (match-string 1))))
2899 (gdb-invalidate-assembler))
2903 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2904 ;;; gdb-ui.el ends here