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.
56 ;;; Windows Platforms:
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.
71 ;; 1) Strings that are watched don't update in the speedbar when their
73 ;; 2) Watch expressions go out of scope when the inferior is re-run.
74 ;; 3) Cannot handle multiple debug sessions.
78 ;; 1) Use MI command -data-read-memory for memory window.
79 ;; 2) Highlight changed register values (use MI commands
80 ;; -data-list-register-values and -data-list-changed-registers instead
81 ;; of 'info registers'.
82 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
83 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
84 ;; 5) After release of 22.1, use "-var-list-children --all-values"
85 ;; and "-stack-list-locals --simple-values" which need GDB 6.1 onwards.
86 ;; 6) After release of 22.1, use "-var-update --all-values" which needs
88 ;; 7) With gud-print and gud-pstar, print the variable name in the GUD
89 ;; buffer instead of the value's history number.
97 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
98 (defvar gdb-previous-frame-address nil)
99 (defvar gdb-memory-address "main")
100 (defvar gdb-previous-frame nil)
101 (defvar gdb-selected-frame nil)
102 (defvar gdb-frame-number nil)
103 (defvar gdb-current-language nil)
104 (defvar gdb-var-list nil "List of variables in watch window.")
105 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
106 (defvar gdb-main-file nil "Source file from which program execution begins.")
107 (defvar gdb-overlay-arrow-position nil)
108 (defvar gdb-server-prefix nil)
109 (defvar gdb-flush-pending-output nil)
110 (defvar gdb-location-alist nil
111 "Alist of breakpoint numbers and full filenames.")
112 (defvar gdb-find-file-unhook nil)
113 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
114 and #define directives otherwise.")
115 (defvar gdb-error "Non-nil when GDB is reporting an error.")
116 (defvar gdb-macro-info nil
117 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
118 (defvar gdb-buffer-fringe-width nil)
120 (defvar gdb-buffer-type nil
121 "One of the symbols bound in `gdb-buffer-rules'.")
122 (make-variable-buffer-local 'gdb-buffer-type)
124 (defvar gdb-input-queue ()
125 "A list of gdb command objects.")
127 (defvar gdb-prompting nil
128 "True when gdb is idle with no pending input.")
130 (defvar gdb-output-sink 'user
131 "The disposition of the output of the current gdb command.
132 Possible values are these symbols:
134 `user' -- gdb output should be copied to the GUD buffer
137 `inferior' -- gdb output should be copied to the inferior-io buffer.
139 `pre-emacs' -- output should be ignored util the post-prompt
140 annotation is received. Then the output-sink
142 `emacs' -- output should be collected in the partial-output-buffer
143 for subsequent processing by a command. This is the
144 disposition of output generated by commands that
145 gdb mode sends to gdb on its own behalf.
146 `post-emacs' -- ignore output until the prompt annotation is
147 received, then go to USER disposition.
149 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
150 \(`user' and `emacs').")
152 (defvar gdb-current-item nil
153 "The most recent command item sent to gdb.")
155 (defvar gdb-pending-triggers '()
156 "A list of trigger functions that have run later than their output
159 ;; end of gdb variables
162 (defun gdba (command-line)
163 "Run gdb on program FILE in buffer *gud-FILE*.
164 The directory containing FILE becomes the initial working directory
165 and source-file directory for your debugger.
167 If `gdb-many-windows' is nil (the default value) then gdb just
168 pops up the GUD buffer unless `gdb-show-main' is t. In this case
169 it starts with two windows: one displaying the GUD buffer and the
170 other with the source file with the main routine of the inferior.
172 If `gdb-many-windows' is t, regardless of the value of
173 `gdb-show-main', the layout below will appear unless
174 `gdb-use-inferior-io-buffer' is nil when the source buffer
175 occupies the full width of the frame. Keybindings are given in
178 Watch expressions appear in the speedbar/slowbar.
180 The following commands help control operation :
182 `gdb-many-windows' - Toggle the number of windows gdb uses.
183 `gdb-restore-windows' - To restore the window layout.
185 See Info node `(emacs)GDB Graphical Interface' for a more
186 detailed description of this mode.
189 +--------------------------------------------------------------+
191 +-------------------------------+------------------------------+
192 | GUD buffer (I/O of GDB) | Locals buffer |
196 +-------------------------------+------------------------------+
197 | Source buffer | I/O buffer (of inferior) |
205 +-------------------------------+------------------------------+
206 | Stack buffer | Breakpoints buffer |
207 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
208 | | RET gdb-goto-breakpoint |
209 | | d gdb-delete-breakpoint |
210 +-------------------------------+------------------------------+"
212 (interactive (list (gud-query-cmdline 'gdba)))
214 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
218 (defvar gdb-debug-log nil)
221 (defcustom gdb-enable-debug-log nil
222 "Non-nil means record the process input and output in `gdb-debug-log'."
227 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
228 "Shell command for generating a list of defined macros in a source file.
229 This list is used to display the #define directive associated
230 with an identifier as a tooltip. It works in a debug session with
231 GDB, when gud-tooltip-mode is t.
233 Set `gdb-cpp-define-alist-flags' for any include paths or
239 (defcustom gdb-cpp-define-alist-flags ""
240 "Preprocessor flags for `gdb-cpp-define-alist-program'."
245 (defcustom gdb-show-main nil
246 "Non-nil means display source file containing the main routine at startup.
247 Also display the main routine in the disassembly buffer if present."
252 (defcustom gdb-use-inferior-io-buffer nil
253 "Non-nil means display output from the inferior in a separate buffer."
258 (defun gdb-use-inferior-io-buffer (arg)
259 "Toggle separate IO for inferior.
260 With arg, use separate IO iff arg is positive."
262 (setq gdb-use-inferior-io-buffer
264 (not gdb-use-inferior-io-buffer)
265 (> (prefix-numeric-value arg) 0)))
266 (if (and gud-comint-buffer
267 (buffer-name gud-comint-buffer))
269 (if gdb-use-inferior-io-buffer
270 (gdb-restore-windows)
271 (kill-buffer (gdb-inferior-io-name)))
274 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
276 (defun gdb-create-define-alist ()
277 "Create an alist of #define directives for GUD tooltips."
278 (let* ((file (buffer-file-name))
280 (with-output-to-string
281 (with-current-buffer standard-output
282 (call-process shell-file-name
283 (if (file-exists-p file) file nil)
284 (list t nil) nil "-c"
285 (concat gdb-cpp-define-alist-program " "
286 gdb-cpp-define-alist-flags)))))
287 (define-list (split-string output "\n" t))
289 (setq gdb-define-alist nil)
290 (dolist (define define-list)
291 (setq name (nth 1 (split-string define "[( ]")))
292 (push (cons name define) gdb-define-alist))))
294 (defun gdb-tooltip-print ()
296 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
297 (let ((string (buffer-string)))
298 ;; remove newline for gud-tooltip-echo-area
299 (substring string 0 (- (length string) 1))))
300 (or gud-tooltip-echo-area tooltip-use-echo-area)))
302 ;; If expr is a macro for a function don't print because of possible dangerous
303 ;; side-effects. Also printing a function within a tooltip generates an
304 ;; unexpected starting annotation (phase error).
305 (defun gdb-tooltip-print-1 (expr)
306 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
307 (goto-char (point-min))
308 (if (search-forward "expands to: " nil t)
309 (unless (looking-at "\\S-+.*(.*).*")
311 (list (concat gdb-server-prefix "print " expr "\n")
312 'gdb-tooltip-print))))))
314 (defun gdb-set-gud-minor-mode (buffer)
315 "Set `gud-minor-mode' from find-file if appropriate."
316 (goto-char (point-min))
317 (unless (search-forward "No source file named " nil t)
320 (list (concat gdb-server-prefix "info source\n")
321 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
322 (error (setq gdb-find-file-unhook t)))))
324 (defun gdb-set-gud-minor-mode-1 (buffer)
325 (goto-char (point-min))
326 (when (and (search-forward "Located in " nil t)
328 (string-equal (buffer-file-name buffer)
330 (with-current-buffer buffer
331 (set (make-local-variable 'gud-minor-mode) 'gdba)
332 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
333 (when gud-tooltip-mode
334 (make-local-variable 'gdb-define-alist)
335 (gdb-create-define-alist)
336 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
338 (defun gdb-set-gud-minor-mode-existing-buffers ()
339 (dolist (buffer (buffer-list))
340 (let ((file (buffer-file-name buffer)))
344 (list (concat gdb-server-prefix "list "
345 (file-name-nondirectory file) ":1\n")
346 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
348 (defun gdb-find-watch-expression ()
349 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
350 (varno (nth 1 var)) (expr))
351 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varno)
352 (dolist (var1 gdb-var-list)
353 (if (string-equal (nth 1 var1) (match-string 1 varno))
354 (setq expr (concat (car var1) "." (match-string 2 varno)))))
358 (setq gdb-debug-log nil)
359 (set (make-local-variable 'gud-minor-mode) 'gdba)
360 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
362 (gud-def gud-break (if (not (string-match "Machine" mode-name))
363 (gud-call "break %f:%l" arg)
367 (gud-call "break *%a" arg)))
368 "\C-b" "Set breakpoint at current line or address.")
370 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
371 (gud-call "clear %f:%l" arg)
375 (gud-call "clear *%a" arg)))
376 "\C-d" "Remove breakpoint at current line or address.")
378 (gud-def gud-until (if (not (string-match "Machine" mode-name))
379 (gud-call "until %f:%l" arg)
383 (gud-call "until *%a" arg)))
384 "\C-u" "Continue to current line or address.")
386 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
387 nil "Start or continue execution.")
389 ;; For debugging Emacs only.
393 "pp1 " (if (eq (buffer-local-value
394 'major-mode (window-buffer)) 'speedbar-mode)
395 (gdb-find-watch-expression) "%e")) arg)
396 nil "Print the emacs s-expression.")
398 (define-key gud-minor-mode-map [left-margin mouse-1]
399 'gdb-mouse-set-clear-breakpoint)
400 (define-key gud-minor-mode-map [left-fringe mouse-1]
401 'gdb-mouse-set-clear-breakpoint)
402 (define-key gud-minor-mode-map [left-fringe mouse-2]
404 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
406 (define-key gud-minor-mode-map [left-margin mouse-2]
408 (define-key gud-minor-mode-map [left-margin mouse-3]
409 'gdb-mouse-toggle-breakpoint-margin)
410 (define-key gud-minor-mode-map [left-fringe mouse-3]
411 'gdb-mouse-toggle-breakpoint-fringe)
413 (setq comint-input-sender 'gdb-send)
416 (setq gdb-frame-address (if gdb-show-main "main" nil))
417 (setq gdb-previous-frame-address nil
418 gdb-memory-address "main"
419 gdb-previous-frame nil
420 gdb-selected-frame nil
421 gdb-current-language nil
429 gdb-pending-triggers nil
430 gdb-output-sink 'user
431 gdb-server-prefix "server "
432 gdb-flush-pending-output nil
433 gdb-location-alist nil
434 gdb-find-file-unhook nil
437 gdb-buffer-fringe-width (car (window-fringes)))
439 (setq gdb-buffer-type 'gdba)
441 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
443 (if (eq window-system 'w32)
444 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
445 (gdb-enqueue-input (list "set height 0\n" 'ignore))
446 (gdb-enqueue-input (list "set width 0\n" 'ignore))
447 ;; find source file and compilation directory here
448 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
449 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
450 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
452 (gdb-set-gud-minor-mode-existing-buffers)
453 (run-hooks 'gdba-mode-hook))
455 (defun gdb-mouse-until (event)
456 "Execute source lines by dragging the overlay arrow (fringe) with the mouse."
458 (if gud-overlay-arrow-position
459 (let ((start (event-start event))
460 (end (event-end event))
461 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
462 (if (not (string-match "Machine" mode-name))
463 (if (equal buffer (window-buffer (posn-window end)))
464 (with-current-buffer buffer
465 (when (or (equal start end)
466 (equal (posn-point start)
468 gud-overlay-arrow-position)))
469 (setq line (line-number-at-pos (posn-point end)))
470 (gud-call (concat "until " (number-to-string line))))))
471 (if (equal (marker-buffer gdb-overlay-arrow-position)
472 (window-buffer (posn-window end)))
473 (when (or (equal start end)
474 (equal (posn-point start)
476 gdb-overlay-arrow-position)))
478 (goto-line (line-number-at-pos (posn-point end)))
480 (gud-call (concat "until *%a")))))))))
482 (defcustom gdb-speedbar-auto-raise t
483 "If non-nil raise speedbar every time display of watch expressions is\
489 (defun gdb-speedbar-auto-raise (arg)
490 "Toggle automatic raising of the speedbar for watch expressions."
492 (setq gdb-speedbar-auto-raise
494 (not gdb-speedbar-auto-raise)
495 (> (prefix-numeric-value arg) 0))))
497 (defcustom gdb-use-colon-colon-notation nil
498 "If non-nil use FUN::VAR format to display variables in the speedbar."
504 "Watch expression at point."
507 (save-selected-window
508 (let ((expr (tooltip-identifier-from-point (point))))
509 (if (and (string-equal gdb-current-language "c")
510 gdb-use-colon-colon-notation gdb-selected-frame)
511 (setq expr (concat gdb-selected-frame "::" expr)))
512 (catch 'already-watched
513 (dolist (var gdb-var-list)
514 (if (string-equal expr (car var)) (throw 'already-watched nil)))
515 (set-text-properties 0 (length expr) nil expr)
518 (if (eq gud-minor-mode 'gdba)
519 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
520 (concat"-var-create - * " expr "\n"))
521 `(lambda () (gdb-var-create-handler ,expr))))))))
523 (defconst gdb-var-create-regexp
524 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
526 (defun gdb-var-create-handler (expr)
527 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
528 (goto-char (point-min))
529 (if (re-search-forward gdb-var-create-regexp nil t)
530 (let ((var (list expr
535 (push var gdb-var-list)
537 (unless (string-equal
538 speedbar-initial-expansion-list-name "GUD")
539 (speedbar-change-initial-expansion-list "GUD"))
542 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
544 (concat "server interpreter mi \"-var-evaluate-expression "
546 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
547 `(lambda () (gdb-var-evaluate-expression-handler
549 (setq gdb-var-changed t))
550 (if (re-search-forward "Undefined command" nil t)
551 (message-box "Watching expressions requires gdb 6.0 onwards")
552 (message "No symbol \"%s\" in current context." expr)))))
554 (defun gdb-var-evaluate-expression-handler (varnum changed)
555 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
556 (goto-char (point-min))
557 (re-search-forward ".*value=\\(\".*\"\\)" nil t)
560 (dolist (var gdb-var-list)
561 (if (string-equal varnum (cadr var))
563 (if changed (setcar (nthcdr 5 var) t))
564 (setcar (nthcdr 4 var) (read (match-string 1)))
565 (setcar (nthcdr num gdb-var-list) var)
566 (throw 'var-found nil)))
567 (setq num (+ num 1))))))
568 (setq gdb-var-changed t))
570 (defun gdb-var-list-children (varnum)
572 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
573 `(lambda () (gdb-var-list-children-handler ,varnum)))))
575 (defconst gdb-var-list-children-regexp
576 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",\
579 (defun gdb-var-list-children-handler (varnum)
580 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
581 (goto-char (point-min))
582 (let ((var-list nil))
583 (catch 'child-already-watched
584 (dolist (var gdb-var-list)
585 (if (string-equal varnum (cadr var))
588 (while (re-search-forward gdb-var-list-children-regexp nil t)
589 (let ((varchild (list (match-string 2)
594 (dolist (var1 gdb-var-list)
595 (if (string-equal (cadr var1) (cadr varchild))
596 (throw 'child-already-watched nil)))
597 (push varchild var-list)
601 "server interpreter mi \"-var-evaluate-expression "
602 (nth 1 varchild) "\"\n")
603 `(lambda () (gdb-var-evaluate-expression-handler
604 ,(nth 1 varchild) nil)))))))
605 (push var var-list)))
606 (setq gdb-var-list (nreverse var-list))))))
608 (defun gdb-var-update ()
609 (when (not (member 'gdb-var-update gdb-pending-triggers))
611 (list "server interpreter mi \"-var-update *\"\n"
612 'gdb-var-update-handler))
613 (push 'gdb-var-update gdb-pending-triggers)))
615 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
617 (defun gdb-var-update-handler ()
618 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
619 (goto-char (point-min))
620 (while (re-search-forward gdb-var-update-regexp nil t)
622 (let ((varnum (match-string 1)))
623 (dolist (var gdb-var-list)
626 (concat "server interpreter mi \"-var-evaluate-expression "
628 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t))))
629 (throw 'var-found-1 nil))))))
630 (setq gdb-pending-triggers
631 (delq 'gdb-var-update gdb-pending-triggers))
632 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
633 ;; Dummy command to update speedbar at right time.
634 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
635 ;; Keep gdb-pending-triggers non-nil till end.
636 (push 'gdb-speedbar-timer gdb-pending-triggers)))
638 (defun gdb-speedbar-timer-fn ()
639 (setq gdb-pending-triggers
640 (delq 'gdb-speedbar-timer gdb-pending-triggers))
641 (with-current-buffer gud-comint-buffer
642 (speedbar-timer-fn)))
644 (defun gdb-var-delete ()
645 "Delete watch expression at point from the speedbar."
647 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
649 (let ((text (speedbar-line-text)))
650 (string-match "\\(\\S-+\\)" text)
651 (let* ((expr (match-string 1 text))
652 (var (assoc expr gdb-var-list))
654 (unless (string-match "\\." varnum)
657 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
659 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
660 (concat "-var-delete " varnum "\n"))
662 (setq gdb-var-list (delq var gdb-var-list))
663 (dolist (varchild gdb-var-list)
664 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
665 (setq gdb-var-list (delq varchild gdb-var-list))))
666 (setq gdb-var-changed t))))))
668 (defun gdb-edit-value (text token indent)
669 "Assign a value to a variable displayed in the speedbar."
670 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
671 (varnum (cadr var)) (value))
672 (setq value (read-string "New value: "))
675 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
676 (concat "server interpreter mi \"-var-assign "
677 varnum " " value "\"\n")
678 (concat "-var-assign " varnum " " value "\n"))
681 (defcustom gdb-show-changed-values t
682 "If non-nil highlight values that have recently changed in the speedbar.
683 The highlighting is done with `font-lock-warning-face'."
688 (defun gdb-speedbar-expand-node (text token indent)
689 "Expand the node the user clicked on.
690 TEXT is the text of the button we clicked on, a + or - item.
691 TOKEN is data related to this node.
692 INDENT is the current indentation depth."
693 (cond ((string-match "+" text) ;expand this node
694 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
695 (gdb-var-list-children token)
698 (gdbmi-var-list-children token))))
699 ((string-match "-" text) ;contract this node
700 (dolist (var gdb-var-list)
701 (if (string-match (concat token "\\.") (nth 1 var))
702 (setq gdb-var-list (delq var gdb-var-list))))
703 (setq gdb-var-changed t)
704 (with-current-buffer gud-comint-buffer
705 (speedbar-timer-fn)))))
707 (defun gdb-get-target-string ()
708 (with-current-buffer gud-comint-buffer
715 ;; Each buffer has a TYPE -- a symbol that identifies the function
716 ;; of that particular buffer.
718 ;; The usual gdb interaction buffer is given the type `gdba' and
719 ;; is constructed specially.
721 ;; Others are constructed by gdb-get-create-buffer and
722 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
724 (defvar gdb-buffer-rules-assoc '())
726 (defun gdb-get-buffer (key)
727 "Return the gdb buffer tagged with type KEY.
728 The key should be one of the cars in `gdb-buffer-rules-assoc'."
730 (gdb-look-for-tagged-buffer key (buffer-list))))
732 (defun gdb-get-create-buffer (key)
733 "Create a new gdb buffer of the type specified by KEY.
734 The key should be one of the cars in `gdb-buffer-rules-assoc'."
735 (or (gdb-get-buffer key)
736 (let* ((rules (assoc key gdb-buffer-rules-assoc))
737 (name (funcall (gdb-rules-name-maker rules)))
738 (new (get-buffer-create name)))
739 (with-current-buffer new
741 (if (cdr (cdr rules))
742 (setq trigger (funcall (car (cdr (cdr rules))))))
743 (setq gdb-buffer-type key)
744 (set (make-local-variable 'gud-minor-mode)
745 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
746 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
747 (if trigger (funcall trigger)))
750 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
752 (defun gdb-look-for-tagged-buffer (key bufs)
754 (while (and (not retval) bufs)
755 (set-buffer (car bufs))
756 (if (eq gdb-buffer-type key)
757 (setq retval (car bufs)))
758 (setq bufs (cdr bufs)))
762 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
763 ;; at least one and possible more functions. The functions have these
764 ;; roles in defining a buffer type:
766 ;; NAME - Return a name for this buffer type.
768 ;; The remaining function(s) are optional:
770 ;; MODE - called in a new buffer with no arguments, should establish
771 ;; the proper mode for the buffer.
774 (defun gdb-set-buffer-rules (buffer-type &rest rules)
775 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
777 (setcdr binding rules)
778 (push (cons buffer-type rules)
779 gdb-buffer-rules-assoc))))
781 ;; GUD buffers are an exception to the rules
782 (gdb-set-buffer-rules 'gdba 'error)
785 ;; Partial-output buffer : This accumulates output from a command executed on
786 ;; behalf of emacs (rather than the user).
788 (gdb-set-buffer-rules 'gdb-partial-output-buffer
789 'gdb-partial-output-name)
791 (defun gdb-partial-output-name ()
792 (concat "*partial-output-"
793 (gdb-get-target-string)
797 (gdb-set-buffer-rules 'gdb-inferior-io
798 'gdb-inferior-io-name
799 'gdb-inferior-io-mode)
801 (defun gdb-inferior-io-name ()
802 (concat "*input/output of "
803 (gdb-get-target-string)
806 (defun gdb-display-inferior-io-buffer ()
807 "Display IO of inferior in a separate window."
809 (if gdb-use-inferior-io-buffer
811 (gdb-get-create-buffer 'gdb-inferior-io))))
813 (defconst gdb-frame-parameters
814 '((height . 14) (width . 80)
816 (tool-bar-lines . nil)
817 (menu-bar-lines . nil)
820 (defun gdb-frame-inferior-io-buffer ()
821 "Display IO of inferior in a new frame."
823 (if gdb-use-inferior-io-buffer
824 (let ((special-display-regexps (append special-display-regexps '(".*")))
825 (special-display-frame-alist gdb-frame-parameters))
826 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
828 (defvar gdb-inferior-io-mode-map
829 (let ((map (make-sparse-keymap)))
830 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
831 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
832 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
833 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
834 (define-key map "\C-d" 'gdb-inferior-io-eof)
837 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
838 "Major mode for gdb inferior-io."
839 :syntax-table nil :abbrev-table nil
840 ;; We want to use comint because it has various nifty and familiar
841 ;; features. We don't need a process, but comint wants one, so create
843 (make-comint-in-buffer
844 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
845 (current-buffer) "hexl")
846 (setq comint-input-sender 'gdb-inferior-io-sender))
848 (defun gdb-inferior-io-sender (proc string)
849 ;; PROC is the pseudo-process created to satisfy comint.
850 (with-current-buffer (process-buffer proc)
851 (setq proc (get-buffer-process gud-comint-buffer))
852 (process-send-string proc string)
853 (process-send-string proc "\n")))
855 (defun gdb-inferior-io-interrupt ()
856 "Interrupt the program being debugged."
859 (get-buffer-process gud-comint-buffer) comint-ptyp))
861 (defun gdb-inferior-io-quit ()
862 "Send quit signal to the program being debugged."
865 (get-buffer-process gud-comint-buffer) comint-ptyp))
867 (defun gdb-inferior-io-stop ()
868 "Stop the program being debugged."
871 (get-buffer-process gud-comint-buffer) comint-ptyp))
873 (defun gdb-inferior-io-eof ()
874 "Send end-of-file to the program being debugged."
877 (get-buffer-process gud-comint-buffer)))
881 ;; gdb communications
884 ;; INPUT: things sent to gdb
886 ;; The queues are lists. Each element is either a string (indicating user or
887 ;; user-like input) or a list of the form:
889 ;; (INPUT-STRING HANDLER-FN)
891 ;; The handler function will be called from the partial-output buffer when the
892 ;; command completes. This is the way to write commands which invoke gdb
893 ;; commands autonomously.
895 ;; These lists are consumed tail first.
898 (defun gdb-send (proc string)
899 "A comint send filter for gdb.
900 This filter may simply queue input for a later time."
901 (with-current-buffer gud-comint-buffer
902 (let ((inhibit-read-only t))
903 (remove-text-properties (point-min) (point-max) '(face))))
904 (let ((item (concat string "\n")))
907 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
908 (process-send-string proc item))
909 (gdb-enqueue-input item))))
911 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
912 ;; is a query, or other non-top-level prompt.
914 (defun gdb-enqueue-input (item)
918 (setq gdb-prompting nil))
919 (push item gdb-input-queue)))
921 (defun gdb-dequeue-input ()
922 (let ((queue gdb-input-queue))
924 (let ((last (car (last queue))))
925 (unless (nbutlast queue) (setq gdb-input-queue '()))
928 (defun gdb-send-item (item)
929 (setq gdb-flush-pending-output nil)
930 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
931 (setq gdb-current-item item)
932 (let ((process (get-buffer-process gud-comint-buffer)))
933 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
936 (setq gdb-output-sink 'user)
937 (process-send-string process item))
939 (gdb-clear-partial-output)
940 (setq gdb-output-sink 'pre-emacs)
941 (process-send-string process
943 ;; case: eq gud-minor-mode 'gdbmi
944 (gdb-clear-partial-output)
945 (setq gdb-output-sink 'emacs)
946 (process-send-string process (car item)))))
949 ;; output -- things gdb prints to emacs
951 ;; GDB output is a stream interrupted by annotations.
952 ;; Annotations can be recognized by their beginning
953 ;; with \C-j\C-z\C-z<tag><opt>\C-j
955 ;; The tag is a string obeying symbol syntax.
957 ;; The optional part `<opt>' can be either the empty string
958 ;; or a space followed by more data relating to the annotation.
959 ;; For example, the SOURCE annotation is followed by a filename,
960 ;; line number and various useless goo. This data must not include
964 (defcustom gud-gdba-command-name "gdb -annotate=3"
965 "Default command to execute an executable under the GDB-UI debugger."
970 (defvar gdb-annotation-rules
971 '(("pre-prompt" gdb-pre-prompt)
972 ("prompt" gdb-prompt)
973 ("commands" gdb-subprompt)
974 ("overload-choice" gdb-subprompt)
975 ("query" gdb-subprompt)
976 ;; Need this prompt for GDB 6.1
977 ("nquery" gdb-subprompt)
978 ("prompt-for-continue" gdb-subprompt)
979 ("post-prompt" gdb-post-prompt)
980 ("source" gdb-source)
981 ("starting" gdb-starting)
982 ("exited" gdb-exited)
983 ("signalled" gdb-exited)
984 ("signal" gdb-stopping)
985 ("breakpoint" gdb-stopping)
986 ("watchpoint" gdb-stopping)
987 ("frame-begin" gdb-frame-begin)
988 ("stopped" gdb-stopped)
989 ("error-begin" gdb-error)
991 ) "An assoc mapping annotation tags to functions which process them.")
994 (setq gdb-flush-pending-output t)
995 (setq gud-running nil)
996 (setq gdb-output-sink 'user)
997 (setq gdb-input-queue nil)
998 (setq gdb-pending-triggers nil)
999 (setq gdb-prompting t))
1001 (defconst gdb-source-spec-regexp
1002 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
1004 ;; Do not use this except as an annotation handler.
1005 (defun gdb-source (args)
1006 (string-match gdb-source-spec-regexp args)
1007 ;; Extract the frame position from the marker.
1008 (setq gud-last-frame
1010 (match-string 1 args)
1011 (string-to-number (match-string 2 args))))
1012 (setq gdb-frame-address (match-string 3 args))
1013 ;; cover for auto-display output which comes *before*
1014 ;; stopped annotation
1015 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1017 (defun gdb-pre-prompt (ignored)
1018 "An annotation handler for `pre-prompt'.
1019 This terminates the collection of output from a previous command if that
1020 happens to be in effect."
1021 (setq gdb-error nil)
1022 (let ((sink gdb-output-sink))
1026 (setq gdb-output-sink 'post-emacs))
1029 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1031 (defun gdb-prompt (ignored)
1032 "An annotation handler for `prompt'.
1033 This sends the next command (if any) to gdb."
1034 (when gdb-first-prompt (gdb-ann3))
1035 (let ((sink gdb-output-sink))
1038 ((eq sink 'post-emacs)
1039 (setq gdb-output-sink 'user)
1041 (car (cdr gdb-current-item))))
1042 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1043 (funcall handler))))
1046 (error "Phase error in gdb-prompt (got %s)" sink))))
1047 (let ((input (gdb-dequeue-input)))
1049 (gdb-send-item input)
1051 (setq gdb-prompting t)
1052 (gud-display-frame)))))
1054 (defun gdb-subprompt (ignored)
1055 "An annotation handler for non-top-level prompts."
1056 (setq gdb-prompting t))
1058 (defun gdb-starting (ignored)
1059 "An annotation handler for `starting'.
1060 This says that I/O for the subprocess is now the program being debugged,
1062 (setq gdb-active-process t)
1063 (let ((sink gdb-output-sink))
1067 (setq gud-running t)
1068 (if gdb-use-inferior-io-buffer
1069 (setq gdb-output-sink 'inferior))))
1072 (error "Unexpected `starting' annotation")))))
1074 (defun gdb-stopping (ignored)
1075 "An annotation handler for `breakpoint' and other annotations.
1076 They say that I/O for the subprocess is now GDB, not the program
1078 (if gdb-use-inferior-io-buffer
1079 (let ((sink gdb-output-sink))
1081 ((eq sink 'inferior)
1082 (setq gdb-output-sink 'user))
1085 (error "Unexpected stopping annotation"))))))
1087 (defun gdb-exited (ignored)
1088 "An annotation handler for `exited' and `signalled'.
1089 They say that I/O for the subprocess is now GDB, not the program
1090 being debugged and that the program is no longer running. This
1091 function is used to change the focus of GUD tooltips to #define
1093 (setq gdb-active-process nil)
1094 (setq gud-overlay-arrow-position nil)
1095 (setq gdb-overlay-arrow-position nil)
1096 (gdb-stopping ignored))
1098 (defun gdb-frame-begin (ignored)
1099 (let ((sink gdb-output-sink))
1101 ((eq sink 'inferior)
1102 (setq gdb-output-sink 'user))
1104 ((eq sink 'emacs) t)
1107 (error "Unexpected frame-begin annotation (%S)" sink)))))
1109 (defun gdb-stopped (ignored)
1110 "An annotation handler for `stopped'.
1111 It is just like `gdb-stopping', except that if we already set the output
1112 sink to `user' in `gdb-stopping', that is fine."
1113 (setq gud-running nil)
1114 (setq gdb-active-process t)
1115 (let ((sink gdb-output-sink))
1117 ((eq sink 'inferior)
1118 (setq gdb-output-sink 'user))
1122 (error "Unexpected stopped annotation")))))
1124 (defun gdb-error (ignored)
1125 (setq gdb-error (not gdb-error)))
1127 (defun gdb-post-prompt (ignored)
1128 "An annotation handler for `post-prompt'.
1129 This begins the collection of output from the current command if that
1130 happens to be appropriate."
1131 (unless gdb-pending-triggers
1132 (gdb-get-selected-frame)
1133 (gdb-invalidate-frames)
1134 (gdb-invalidate-breakpoints)
1135 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1136 ;; so gdb-frame-address is updated.
1137 ;; (gdb-invalidate-assembler)
1138 (gdb-invalidate-registers)
1139 (gdb-invalidate-memory)
1140 (gdb-invalidate-locals)
1141 (gdb-invalidate-threads)
1142 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1143 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1144 ;; Only needed/used with speedbar/watch expressions.
1145 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1146 (setq gdb-var-changed t) ; force update
1147 (dolist (var gdb-var-list)
1148 (setcar (nthcdr 5 var) nil))
1150 (let ((sink gdb-output-sink))
1153 ((eq sink 'pre-emacs)
1154 (setq gdb-output-sink 'emacs))
1157 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1159 (defun gud-gdba-marker-filter (string)
1160 "A gud marker filter for gdb. Handle a burst of output from GDB."
1161 (if gdb-flush-pending-output
1163 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1164 ;; Recall the left over gud-marker-acc from last time.
1165 (setq gud-marker-acc (concat gud-marker-acc string))
1166 ;; Start accumulating output for the GUD buffer.
1169 ;; Process all the complete markers in this chunk.
1170 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1171 (let ((annotation (match-string 1 gud-marker-acc)))
1173 ;; Stuff prior to the match is just ordinary output.
1174 ;; It is either concatenated to OUTPUT or directed
1179 (substring gud-marker-acc 0 (match-beginning 0))))
1181 ;; Take that stuff off the gud-marker-acc.
1182 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1184 ;; Parse the tag from the annotation, and maybe its arguments.
1185 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1186 (let* ((annotation-type (match-string 1 annotation))
1187 (annotation-arguments (match-string 2 annotation))
1188 (annotation-rule (assoc annotation-type
1189 gdb-annotation-rules)))
1190 ;; Call the handler for this annotation.
1192 (funcall (car (cdr annotation-rule))
1193 annotation-arguments)
1194 ;; Else the annotation is not recognized. Ignore it silently,
1195 ;; so that GDB can add new annotations without causing
1199 ;; Does the remaining text end in a partial line?
1200 ;; If it does, then keep part of the gud-marker-acc until we get more.
1201 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1204 ;; Everything before the potential marker start can be output.
1206 (gdb-concat-output output
1207 (substring gud-marker-acc 0
1208 (match-beginning 0))))
1210 ;; Everything after, we save, to combine with later input.
1211 (setq gud-marker-acc (substring gud-marker-acc
1212 (match-beginning 0))))
1214 ;; In case we know the gud-marker-acc contains no partial annotations:
1216 (setq output (gdb-concat-output output gud-marker-acc))
1217 (setq gud-marker-acc "")))
1220 (defun gdb-concat-output (so-far new)
1222 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1223 (let ((sink gdb-output-sink))
1225 ((eq sink 'user) (concat so-far new))
1226 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1228 (gdb-append-to-partial-output new)
1230 ((eq sink 'inferior)
1231 (gdb-append-to-inferior-io new)
1235 (error "Bogon output sink %S" sink)))))
1237 (defun gdb-append-to-partial-output (string)
1238 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1239 (goto-char (point-max))
1242 (defun gdb-clear-partial-output ()
1243 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1246 (defun gdb-append-to-inferior-io (string)
1247 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1248 (goto-char (point-max))
1249 (insert-before-markers string))
1250 (if (not (string-equal string ""))
1251 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1253 (defun gdb-clear-inferior-io ()
1254 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1258 ;; One trick is to have a command who's output is always available in a buffer
1259 ;; of it's own, and is always up to date. We build several buffers of this
1262 ;; There are two aspects to this: gdb has to tell us when the output for that
1263 ;; command might have changed, and we have to be able to run the command
1264 ;; behind the user's back.
1266 ;; The output phasing associated with the variable gdb-output-sink
1267 ;; help us to run commands behind the user's back.
1269 ;; Below is the code for specificly managing buffers of output from one
1273 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1274 ;; It adds an input for the command we are tracking. It should be the
1275 ;; annotation rule binding of whatever gdb sends to tell us this command
1276 ;; might have changed it's output.
1278 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1279 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1280 ;; input in the input queue (see comment about ``gdb communications'' above).
1282 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1284 `(defun ,name (&optional ignored)
1285 (if (and ,demand-predicate
1287 gdb-pending-triggers)))
1290 (list ,gdb-command ',output-handler))
1291 (push ',name gdb-pending-triggers)))))
1293 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1295 (setq gdb-pending-triggers
1297 gdb-pending-triggers))
1298 (let ((buf (gdb-get-buffer ',buf-key)))
1300 (with-current-buffer buf
1301 (let* ((window (get-buffer-window buf 0))
1302 (p (window-point window))
1303 (buffer-read-only nil))
1305 (insert-buffer-substring (gdb-get-create-buffer
1306 'gdb-partial-output-buffer))
1307 (set-window-point window p)))))
1308 ;; put customisation here
1311 (defmacro def-gdb-auto-updated-buffer (buffer-key
1312 trigger-name gdb-command
1313 output-handler-name custom-defun)
1315 (def-gdb-auto-update-trigger ,trigger-name
1316 ;; The demand predicate:
1317 (gdb-get-buffer ',buffer-key)
1319 ,output-handler-name)
1320 (def-gdb-auto-update-handler ,output-handler-name
1321 ,trigger-name ,buffer-key ,custom-defun)))
1325 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1327 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1328 'gdb-breakpoints-buffer-name
1329 'gdb-breakpoints-mode)
1331 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1332 ;; This defines the auto update rule for buffers of type
1333 ;; `gdb-breakpoints-buffer'.
1335 ;; It defines a function to serve as the annotation handler that
1336 ;; handles the `foo-invalidated' message. That function is called:
1337 gdb-invalidate-breakpoints
1339 ;; To update the buffer, this command is sent to gdb.
1340 "server info breakpoints\n"
1342 ;; This also defines a function to be the handler for the output
1343 ;; from the command above. That function will copy the output into
1344 ;; the appropriately typed buffer. That function will be called:
1345 gdb-info-breakpoints-handler
1346 ;; buffer specific functions
1347 gdb-info-breakpoints-custom)
1349 (defconst breakpoint-xpm-data
1351 static char *magick[] = {
1352 /* columns rows colors chars-per-pixel */
1368 "XPM data used for breakpoint icon.")
1370 (defconst breakpoint-enabled-pbm-data
1373 0 0 0 0 1 1 1 1 0 0 0 0
1374 0 0 0 1 1 1 1 1 1 0 0 0
1375 0 0 1 1 1 1 1 1 1 1 0 0
1376 0 1 1 1 1 1 1 1 1 1 1 0
1377 0 1 1 1 1 1 1 1 1 1 1 0
1378 0 1 1 1 1 1 1 1 1 1 1 0
1379 0 1 1 1 1 1 1 1 1 1 1 0
1380 0 0 1 1 1 1 1 1 1 1 0 0
1381 0 0 0 1 1 1 1 1 1 0 0 0
1382 0 0 0 0 1 1 1 1 0 0 0 0"
1383 "PBM data used for enabled breakpoint icon.")
1385 (defconst breakpoint-disabled-pbm-data
1397 0 0 0 1 0 1 0 1 0 0"
1398 "PBM data used for disabled breakpoint icon.")
1400 (defvar breakpoint-enabled-icon nil
1401 "Icon for enabled breakpoint in display margin.")
1403 (defvar breakpoint-disabled-icon nil
1404 "Icon for disabled breakpoint in display margin.")
1406 ;; Bitmap for breakpoint in fringe
1407 (and (display-images-p)
1408 (define-fringe-bitmap 'breakpoint
1409 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1411 (defface breakpoint-enabled
1415 "Face for enabled breakpoint icon in fringe."
1418 (defface breakpoint-disabled
1419 ;; We use different values of grey for different background types,
1420 ;; so that on low-color displays it will end up as something visible
1421 ;; if it has to be approximated.
1422 '((((background dark)) :foreground "grey60")
1423 (((background light)) :foreground "grey40"))
1424 "Face for disabled breakpoint icon in fringe."
1427 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1428 (defun gdb-info-breakpoints-custom ()
1429 (let ((flag) (bptno))
1430 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1431 (dolist (buffer (buffer-list))
1432 (with-current-buffer buffer
1433 (if (and (eq gud-minor-mode 'gdba)
1434 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1435 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1436 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1438 (goto-char (point-min))
1439 (while (< (point) (- (point-max) 1))
1441 (if (looking-at "[^\t].*?breakpoint")
1443 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1444 (setq bptno (match-string 1))
1445 (setq flag (char-after (match-beginning 2)))
1447 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1449 (let ((buffer-read-only nil))
1450 (add-text-properties (match-beginning 1) (match-end 1)
1451 '(face font-lock-function-name-face)))
1452 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1453 (let ((line (match-string 2)) (buffer-read-only nil)
1454 (file (match-string 1)))
1455 (add-text-properties (line-beginning-position)
1457 '(mouse-face highlight
1458 help-echo "mouse-2, RET: visit breakpoint"))
1459 (unless (file-exists-p file)
1460 (setq file (cdr (assoc bptno gdb-location-alist))))
1462 (not (string-equal file "File not found")))
1463 (with-current-buffer
1464 (find-file-noselect file 'nowarn)
1465 (set (make-local-variable 'gud-minor-mode)
1467 (set (make-local-variable 'tool-bar-map)
1469 ;; Only want one breakpoint icon at each
1472 (goto-line (string-to-number line))
1473 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1476 (concat gdb-server-prefix "list "
1477 (match-string-no-properties 1) ":1\n")
1480 (list (concat gdb-server-prefix "info source\n")
1481 `(lambda () (gdb-get-location
1482 ,bptno ,line ,flag))))))))))
1484 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1486 (defun gdb-mouse-set-clear-breakpoint (event)
1487 "Set/clear breakpoint in left fringe/margin with mouse click."
1489 (mouse-minibuffer-check event)
1490 (let ((posn (event-end event)))
1491 (if (numberp (posn-point posn))
1492 (with-selected-window (posn-window posn)
1494 (goto-char (posn-point posn))
1495 (if (or (posn-object posn)
1496 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1499 (gud-break nil)))))))
1501 (defun gdb-mouse-toggle-breakpoint-margin (event)
1502 "Enable/disable breakpoint in left margin with mouse click."
1504 (mouse-minibuffer-check event)
1505 (let ((posn (event-end event)))
1506 (if (numberp (posn-point posn))
1507 (with-selected-window (posn-window posn)
1509 (goto-char (posn-point posn))
1510 (if (posn-object posn)
1513 (let ((bptno (get-text-property
1514 0 'gdb-bptno (car (posn-string posn)))))
1515 (concat gdb-server-prefix
1516 (if (get-text-property
1517 0 'gdb-enabled (car (posn-string posn)))
1523 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1524 "Enable/disable breakpoint in left fringe with mouse click."
1526 (mouse-minibuffer-check event)
1527 (let* ((posn (event-end event))
1528 (pos (posn-point posn))
1531 (with-selected-window (posn-window posn)
1533 (set-buffer (window-buffer (selected-window)))
1535 (dolist (overlay (overlays-in pos pos))
1536 (when (overlay-get overlay 'put-break)
1537 (setq obj (overlay-get overlay 'before-string))))
1541 (concat gdb-server-prefix
1542 (if (get-text-property 0 'gdb-enabled obj)
1545 (get-text-property 0 'gdb-bptno obj) "\n")
1548 (defun gdb-breakpoints-buffer-name ()
1549 (with-current-buffer gud-comint-buffer
1550 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1552 (defun gdb-display-breakpoints-buffer ()
1553 "Display status of user-settable breakpoints."
1556 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1558 (defun gdb-frame-breakpoints-buffer ()
1559 "Display status of user-settable breakpoints in a new frame."
1561 (let ((special-display-regexps (append special-display-regexps '(".*")))
1562 (special-display-frame-alist gdb-frame-parameters))
1563 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1565 (defvar gdb-breakpoints-mode-map
1566 (let ((map (make-sparse-keymap))
1567 (menu (make-sparse-keymap "Breakpoints")))
1568 (define-key menu [quit] '("Quit" . kill-this-buffer))
1569 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1570 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1571 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1572 (suppress-keymap map)
1573 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1574 (define-key map " " 'gdb-toggle-breakpoint)
1575 (define-key map "D" 'gdb-delete-breakpoint)
1576 (define-key map "q" 'kill-this-buffer)
1577 (define-key map "\r" 'gdb-goto-breakpoint)
1578 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1579 (define-key map [follow-link] 'mouse-face)
1582 (defun gdb-breakpoints-mode ()
1583 "Major mode for gdb breakpoints.
1585 \\{gdb-breakpoints-mode-map}"
1586 (kill-all-local-variables)
1587 (setq major-mode 'gdb-breakpoints-mode)
1588 (setq mode-name "Breakpoints")
1589 (use-local-map gdb-breakpoints-mode-map)
1590 (setq buffer-read-only t)
1591 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1592 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1593 'gdb-invalidate-breakpoints
1594 'gdbmi-invalidate-breakpoints))
1596 (defun gdb-toggle-breakpoint ()
1597 "Enable/disable breakpoint at current line."
1600 (beginning-of-line 1)
1601 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1602 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1604 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1607 (concat gdb-server-prefix
1608 (if (eq ?y (char-after (match-beginning 2)))
1611 (match-string 1) "\n") 'ignore))
1612 (error "Not recognized as break/watchpoint line"))))
1614 (defun gdb-delete-breakpoint ()
1615 "Delete the breakpoint at current line."
1617 (beginning-of-line 1)
1618 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1619 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1621 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1624 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1625 (error "Not recognized as break/watchpoint line")))
1627 (defun gdb-goto-breakpoint (&optional event)
1628 "Display the breakpoint location specified at current line."
1629 (interactive (list last-input-event))
1630 (if event (posn-set-point (event-end event)))
1631 ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
1632 (let ((window (get-buffer-window gud-comint-buffer)))
1633 (if window (save-selected-window (select-window window))))
1635 (beginning-of-line 1)
1636 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1637 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1639 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1640 \\(\\S-+\\):\\([0-9]+\\)"))
1641 (let ((bptno (match-string 1))
1642 (file (match-string 2))
1643 (line (match-string 3)))
1644 (save-selected-window
1645 (let* ((buf (find-file-noselect
1646 (if (file-exists-p file) file
1647 (cdr (assoc bptno gdb-location-alist)))))
1648 (window (display-buffer buf)))
1649 (with-current-buffer buf
1650 (goto-line (string-to-number line))
1651 (set-window-point window (point))))))
1652 (error "Not recognized as break/watchpoint line"))))
1655 ;; Frames buffer. This displays a perpetually correct bactracktrace
1656 ;; (from the command `where').
1658 ;; Alas, if your stack is deep, it is costly.
1660 (gdb-set-buffer-rules 'gdb-stack-buffer
1661 'gdb-stack-buffer-name
1664 (def-gdb-auto-updated-buffer gdb-stack-buffer
1665 gdb-invalidate-frames
1667 gdb-info-frames-handler
1668 gdb-info-frames-custom)
1670 (defun gdb-info-frames-custom ()
1671 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1673 (let ((buffer-read-only nil)
1675 (goto-char (point-min))
1676 (while (< (point) (point-max))
1677 (setq bl (line-beginning-position)
1678 el (line-end-position))
1679 (when (looking-at "#")
1680 (add-text-properties bl el
1681 '(mouse-face highlight
1682 help-echo "mouse-2, RET: Select frame")))
1684 (when (looking-at "^#\\([0-9]+\\)")
1685 (when (string-equal (match-string 1) gdb-frame-number)
1686 (put-text-property bl (+ bl 4)
1687 'face '(:inverse-video t)))
1688 (when (re-search-forward
1690 (if (string-equal (match-string 1) "0") "" " in ")
1691 "\\([^ ]+\\) (") el t)
1692 (put-text-property (match-beginning 1) (match-end 1)
1693 'face font-lock-function-name-face)
1694 (setq bl (match-end 0))
1695 (while (re-search-forward "<\\([^>]+\\)>" el t)
1696 (put-text-property (match-beginning 1) (match-end 1)
1697 'face font-lock-function-name-face))
1699 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1700 (put-text-property (match-beginning 1) (match-end 1)
1701 'face font-lock-variable-name-face))))
1702 (forward-line 1))))))
1704 (defun gdb-stack-buffer-name ()
1705 (with-current-buffer gud-comint-buffer
1706 (concat "*stack frames of " (gdb-get-target-string) "*")))
1708 (defun gdb-display-stack-buffer ()
1709 "Display backtrace of current stack."
1712 (gdb-get-create-buffer 'gdb-stack-buffer)))
1714 (defun gdb-frame-stack-buffer ()
1715 "Display backtrace of current stack in a new frame."
1717 (let ((special-display-regexps (append special-display-regexps '(".*")))
1718 (special-display-frame-alist gdb-frame-parameters))
1719 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1721 (defvar gdb-frames-mode-map
1722 (let ((map (make-sparse-keymap)))
1723 (suppress-keymap map)
1724 (define-key map "q" 'kill-this-buffer)
1725 (define-key map "\r" 'gdb-frames-select)
1726 (define-key map [mouse-2] 'gdb-frames-select)
1727 (define-key map [follow-link] 'mouse-face)
1730 (defun gdb-frames-mode ()
1731 "Major mode for gdb frames.
1733 \\{gdb-frames-mode-map}"
1734 (kill-all-local-variables)
1735 (setq major-mode 'gdb-frames-mode)
1736 (setq mode-name "Frames")
1737 (setq buffer-read-only t)
1738 (use-local-map gdb-frames-mode-map)
1740 (run-mode-hooks 'gdb-frames-mode-hook)
1741 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1742 'gdb-invalidate-frames
1743 'gdbmi-invalidate-frames))
1745 (defun gdb-get-frame-number ()
1748 (let* ((start (line-beginning-position))
1749 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
1750 (n (or (and pos (match-string-no-properties 1)) "0")))
1753 (defun gdb-frames-select (&optional event)
1754 "Select the frame and display the relevant source."
1755 (interactive (list last-input-event))
1756 (if event (posn-set-point (event-end event)))
1758 (list (concat gdb-server-prefix "frame "
1759 (gdb-get-frame-number) "\n") 'ignore))
1760 (gud-display-frame))
1763 ;; Threads buffer. This displays a selectable thread list.
1765 (gdb-set-buffer-rules 'gdb-threads-buffer
1766 'gdb-threads-buffer-name
1769 (def-gdb-auto-updated-buffer gdb-threads-buffer
1770 gdb-invalidate-threads
1771 (concat gdb-server-prefix "info threads\n")
1772 gdb-info-threads-handler
1773 gdb-info-threads-custom)
1775 (defun gdb-info-threads-custom ()
1776 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1777 (let ((buffer-read-only nil))
1778 (goto-char (point-min))
1779 (while (< (point) (point-max))
1780 (unless (looking-at "No ")
1781 (add-text-properties (line-beginning-position) (line-end-position)
1782 '(mouse-face highlight
1783 help-echo "mouse-2, RET: select thread")))
1784 (forward-line 1)))))
1786 (defun gdb-threads-buffer-name ()
1787 (with-current-buffer gud-comint-buffer
1788 (concat "*threads of " (gdb-get-target-string) "*")))
1790 (defun gdb-display-threads-buffer ()
1791 "Display IDs of currently known threads."
1794 (gdb-get-create-buffer 'gdb-threads-buffer)))
1796 (defun gdb-frame-threads-buffer ()
1797 "Display IDs of currently known threads in a new frame."
1799 (let ((special-display-regexps (append special-display-regexps '(".*")))
1800 (special-display-frame-alist gdb-frame-parameters))
1801 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1803 (defvar gdb-threads-mode-map
1804 (let ((map (make-sparse-keymap)))
1805 (suppress-keymap map)
1806 (define-key map "q" 'kill-this-buffer)
1807 (define-key map "\r" 'gdb-threads-select)
1808 (define-key map [mouse-2] 'gdb-threads-select)
1809 (define-key map [follow-link] 'mouse-face)
1812 (defvar gdb-threads-font-lock-keywords
1814 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1815 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1816 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1818 "Font lock keywords used in `gdb-threads-mode'.")
1820 (defun gdb-threads-mode ()
1821 "Major mode for gdb frames.
1823 \\{gdb-threads-mode-map}"
1824 (kill-all-local-variables)
1825 (setq major-mode 'gdb-threads-mode)
1826 (setq mode-name "Threads")
1827 (setq buffer-read-only t)
1828 (use-local-map gdb-threads-mode-map)
1829 (set (make-local-variable 'font-lock-defaults)
1830 '(gdb-threads-font-lock-keywords))
1831 (run-mode-hooks 'gdb-threads-mode-hook)
1832 'gdb-invalidate-threads)
1834 (defun gdb-get-thread-number ()
1836 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1837 (match-string-no-properties 1)))
1839 (defun gdb-threads-select (&optional event)
1840 "Select the thread and display the relevant source."
1841 (interactive (list last-input-event))
1842 (if event (posn-set-point (event-end event)))
1844 (list (concat gdb-server-prefix "thread "
1845 (gdb-get-thread-number) "\n") 'ignore))
1846 (gud-display-frame))
1849 ;; Registers buffer.
1851 (defcustom gdb-all-registers nil
1852 "Non-nil means include floating-point registers."
1857 (gdb-set-buffer-rules 'gdb-registers-buffer
1858 'gdb-registers-buffer-name
1859 'gdb-registers-mode)
1861 (def-gdb-auto-updated-buffer gdb-registers-buffer
1862 gdb-invalidate-registers
1864 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1865 gdb-info-registers-handler
1866 gdb-info-registers-custom)
1868 (defun gdb-info-registers-custom ()
1869 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1871 (let ((buffer-read-only nil)
1873 (goto-char (point-min))
1874 (while (< (point) (point-max))
1875 (setq start (line-beginning-position))
1876 (setq end (line-end-position))
1877 (when (looking-at "^[^ ]+")
1878 (unless (string-equal (match-string 0) "The")
1879 (put-text-property start (match-end 0)
1880 'face font-lock-variable-name-face)
1881 (add-text-properties start end
1882 '(help-echo "mouse-2: edit value"
1883 mouse-face highlight))))
1884 (forward-line 1))))))
1886 (defun gdb-edit-register-value (&optional event)
1887 (interactive (list last-input-event))
1889 (if event (posn-set-point (event-end event)))
1891 (let* ((register (current-word))
1892 (value (read-string (format "New value (%s): " register))))
1894 (list (concat gdb-server-prefix "set $" register "=" value "\n")
1897 (defvar gdb-registers-mode-map
1898 (let ((map (make-sparse-keymap)))
1899 (suppress-keymap map)
1900 (define-key map "\r" 'gdb-edit-register-value)
1901 (define-key map [mouse-2] 'gdb-edit-register-value)
1902 (define-key map " " 'toggle-gdb-all-registers)
1903 (define-key map "q" 'kill-this-buffer)
1906 (defun gdb-registers-mode ()
1907 "Major mode for gdb registers.
1909 \\{gdb-registers-mode-map}"
1910 (kill-all-local-variables)
1911 (setq major-mode 'gdb-registers-mode)
1912 (setq mode-name "Registers:")
1913 (setq buffer-read-only t)
1914 (use-local-map gdb-registers-mode-map)
1915 (run-mode-hooks 'gdb-registers-mode-hook)
1916 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1917 'gdb-invalidate-registers
1918 'gdbmi-invalidate-registers))
1920 (defun gdb-registers-buffer-name ()
1921 (with-current-buffer gud-comint-buffer
1922 (concat "*registers of " (gdb-get-target-string) "*")))
1924 (defun gdb-display-registers-buffer ()
1925 "Display integer register contents."
1928 (gdb-get-create-buffer 'gdb-registers-buffer)))
1930 (defun gdb-frame-registers-buffer ()
1931 "Display integer register contents in a new frame."
1933 (let ((special-display-regexps (append special-display-regexps '(".*")))
1934 (special-display-frame-alist gdb-frame-parameters))
1935 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1937 (defun toggle-gdb-all-registers ()
1938 "Toggle the display of floating-point registers."
1940 (if gdb-all-registers
1942 (setq gdb-all-registers nil)
1943 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1944 (setq mode-name "Registers:")))
1945 (setq gdb-all-registers t)
1946 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1947 (setq mode-name "Registers:All")))
1948 (gdb-invalidate-registers))
1953 (defcustom gdb-memory-repeat-count 32
1954 "Number of data items in memory window."
1959 (defcustom gdb-memory-format "x"
1960 "Display format of data items in memory window."
1961 :type '(choice (const :tag "Hexadecimal" "x")
1962 (const :tag "Signed decimal" "d")
1963 (const :tag "Unsigned decimal" "u")
1964 (const :tag "Octal" "o")
1965 (const :tag "Binary" "t"))
1969 (defcustom gdb-memory-unit "w"
1970 "Unit size of data items in memory window."
1971 :type '(choice (const :tag "Byte" "b")
1972 (const :tag "Halfword" "h")
1973 (const :tag "Word" "w")
1974 (const :tag "Giant word" "g"))
1978 (gdb-set-buffer-rules 'gdb-memory-buffer
1979 'gdb-memory-buffer-name
1982 (def-gdb-auto-updated-buffer gdb-memory-buffer
1983 gdb-invalidate-memory
1984 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1985 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1986 gdb-read-memory-handler
1987 gdb-read-memory-custom)
1989 (defun gdb-read-memory-custom ()
1991 (goto-char (point-min))
1992 (if (looking-at "0x[[:xdigit:]]+")
1993 (setq gdb-memory-address (match-string 0)))))
1995 (defvar gdb-memory-mode-map
1996 (let ((map (make-sparse-keymap)))
1997 (suppress-keymap map)
1998 (define-key map "q" 'kill-this-buffer)
2001 (defun gdb-memory-set-address (event)
2002 "Set the start memory address."
2004 (save-selected-window
2005 (select-window (posn-window (event-start event)))
2006 (let ((arg (read-from-minibuffer "Memory address: ")))
2007 (setq gdb-memory-address arg))
2008 (gdb-invalidate-memory)))
2010 (defun gdb-memory-set-repeat-count (event)
2011 "Set the number of data items in memory window."
2013 (save-selected-window
2014 (select-window (posn-window (event-start event)))
2015 (let* ((arg (read-from-minibuffer "Repeat count: "))
2016 (count (string-to-number arg)))
2018 (error "Positive numbers only")
2019 (customize-set-variable 'gdb-memory-repeat-count count)
2020 (gdb-invalidate-memory)))))
2022 (defun gdb-memory-format-binary ()
2023 "Set the display format to binary."
2025 (customize-set-variable 'gdb-memory-format "t")
2026 (gdb-invalidate-memory))
2028 (defun gdb-memory-format-octal ()
2029 "Set the display format to octal."
2031 (customize-set-variable 'gdb-memory-format "o")
2032 (gdb-invalidate-memory))
2034 (defun gdb-memory-format-unsigned ()
2035 "Set the display format to unsigned decimal."
2037 (customize-set-variable 'gdb-memory-format "u")
2038 (gdb-invalidate-memory))
2040 (defun gdb-memory-format-signed ()
2041 "Set the display format to decimal."
2043 (customize-set-variable 'gdb-memory-format "d")
2044 (gdb-invalidate-memory))
2046 (defun gdb-memory-format-hexadecimal ()
2047 "Set the display format to hexadecimal."
2049 (customize-set-variable 'gdb-memory-format "x")
2050 (gdb-invalidate-memory))
2052 (defvar gdb-memory-format-keymap
2053 (let ((map (make-sparse-keymap)))
2054 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2056 "Keymap to select format in the header line.")
2058 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2059 "Menu of display formats in the header line.")
2061 (define-key gdb-memory-format-menu [binary]
2062 '(menu-item "Binary" gdb-memory-format-binary
2063 :button (:radio . (equal gdb-memory-format "t"))))
2064 (define-key gdb-memory-format-menu [octal]
2065 '(menu-item "Octal" gdb-memory-format-octal
2066 :button (:radio . (equal gdb-memory-format "o"))))
2067 (define-key gdb-memory-format-menu [unsigned]
2068 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2069 :button (:radio . (equal gdb-memory-format "u"))))
2070 (define-key gdb-memory-format-menu [signed]
2071 '(menu-item "Signed Decimal" gdb-memory-format-signed
2072 :button (:radio . (equal gdb-memory-format "d"))))
2073 (define-key gdb-memory-format-menu [hexadecimal]
2074 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2075 :button (:radio . (equal gdb-memory-format "x"))))
2077 (defun gdb-memory-format-menu (event)
2079 (x-popup-menu event gdb-memory-format-menu))
2081 (defun gdb-memory-format-menu-1 (event)
2083 (save-selected-window
2084 (select-window (posn-window (event-start event)))
2085 (let* ((selection (gdb-memory-format-menu event))
2086 (binding (and selection (lookup-key gdb-memory-format-menu
2087 (vector (car selection))))))
2088 (if binding (call-interactively binding)))))
2090 (defun gdb-memory-unit-giant ()
2091 "Set the unit size to giant words (eight bytes)."
2093 (customize-set-variable 'gdb-memory-unit "g")
2094 (gdb-invalidate-memory))
2096 (defun gdb-memory-unit-word ()
2097 "Set the unit size to words (four bytes)."
2099 (customize-set-variable 'gdb-memory-unit "w")
2100 (gdb-invalidate-memory))
2102 (defun gdb-memory-unit-halfword ()
2103 "Set the unit size to halfwords (two bytes)."
2105 (customize-set-variable 'gdb-memory-unit "h")
2106 (gdb-invalidate-memory))
2108 (defun gdb-memory-unit-byte ()
2109 "Set the unit size to bytes."
2111 (customize-set-variable 'gdb-memory-unit "b")
2112 (gdb-invalidate-memory))
2114 (defvar gdb-memory-unit-keymap
2115 (let ((map (make-sparse-keymap)))
2116 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2118 "Keymap to select units in the header line.")
2120 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2121 "Menu of units in the header line.")
2123 (define-key gdb-memory-unit-menu [giantwords]
2124 '(menu-item "Giant words" gdb-memory-unit-giant
2125 :button (:radio . (equal gdb-memory-unit "g"))))
2126 (define-key gdb-memory-unit-menu [words]
2127 '(menu-item "Words" gdb-memory-unit-word
2128 :button (:radio . (equal gdb-memory-unit "w"))))
2129 (define-key gdb-memory-unit-menu [halfwords]
2130 '(menu-item "Halfwords" gdb-memory-unit-halfword
2131 :button (:radio . (equal gdb-memory-unit "h"))))
2132 (define-key gdb-memory-unit-menu [bytes]
2133 '(menu-item "Bytes" gdb-memory-unit-byte
2134 :button (:radio . (equal gdb-memory-unit "b"))))
2136 (defun gdb-memory-unit-menu (event)
2138 (x-popup-menu event gdb-memory-unit-menu))
2140 (defun gdb-memory-unit-menu-1 (event)
2142 (save-selected-window
2143 (select-window (posn-window (event-start event)))
2144 (let* ((selection (gdb-memory-unit-menu event))
2145 (binding (and selection (lookup-key gdb-memory-unit-menu
2146 (vector (car selection))))))
2147 (if binding (call-interactively binding)))))
2149 ;;from make-mode-line-mouse-map
2150 (defun gdb-make-header-line-mouse-map (mouse function) "\
2151 Return a keymap with single entry for mouse key MOUSE on the header line.
2152 MOUSE is defined to run function FUNCTION with no args in the buffer
2153 corresponding to the mode line clicked."
2154 (let ((map (make-sparse-keymap)))
2155 (define-key map (vector 'header-line mouse) function)
2156 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2159 (defvar gdb-memory-font-lock-keywords
2160 '(;; <__function.name+n>
2161 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2163 "Font lock keywords used in `gdb-memory-mode'.")
2165 (defun gdb-memory-mode ()
2166 "Major mode for examining memory.
2168 \\{gdb-memory-mode-map}"
2169 (kill-all-local-variables)
2170 (setq major-mode 'gdb-memory-mode)
2171 (setq mode-name "Memory")
2172 (setq buffer-read-only t)
2173 (use-local-map gdb-memory-mode-map)
2174 (setq header-line-format
2180 'face font-lock-warning-face
2181 'help-echo "mouse-1: Decrement address"
2182 'mouse-face 'mode-line-highlight
2184 (gdb-make-header-line-mouse-map
2186 #'(lambda () (interactive)
2187 (let ((gdb-memory-address
2188 ;; Let GDB do the arithmetic.
2190 gdb-memory-address " - "
2192 (* gdb-memory-repeat-count
2193 (cond ((string= gdb-memory-unit "b") 1)
2194 ((string= gdb-memory-unit "h") 2)
2195 ((string= gdb-memory-unit "w") 4)
2196 ((string= gdb-memory-unit "g") 8)))))))
2197 (gdb-invalidate-memory)))))
2200 'face font-lock-warning-face
2201 'help-echo "mouse-1: Increment address"
2202 'mouse-face 'mode-line-highlight
2203 'local-map (gdb-make-header-line-mouse-map
2205 #'(lambda () (interactive)
2206 (let ((gdb-memory-address nil))
2207 (gdb-invalidate-memory)))))
2209 (propertize gdb-memory-address
2210 'face font-lock-warning-face
2211 'help-echo "mouse-1: Set memory address"
2212 'mouse-face 'mode-line-highlight
2213 'local-map (gdb-make-header-line-mouse-map
2215 #'gdb-memory-set-address))
2217 (propertize (number-to-string gdb-memory-repeat-count)
2218 'face font-lock-warning-face
2219 'help-echo "mouse-1: Set repeat count"
2220 'mouse-face 'mode-line-highlight
2221 'local-map (gdb-make-header-line-mouse-map
2223 #'gdb-memory-set-repeat-count))
2225 (propertize gdb-memory-format
2226 'face font-lock-warning-face
2227 'help-echo "mouse-3: Select display format"
2228 'mouse-face 'mode-line-highlight
2229 'local-map gdb-memory-format-keymap)
2231 (propertize gdb-memory-unit
2232 'face font-lock-warning-face
2233 'help-echo "mouse-3: Select unit size"
2234 'mouse-face 'mode-line-highlight
2235 'local-map gdb-memory-unit-keymap))))
2236 (set (make-local-variable 'font-lock-defaults)
2237 '(gdb-memory-font-lock-keywords))
2238 (run-mode-hooks 'gdb-memory-mode-hook)
2239 'gdb-invalidate-memory)
2241 (defun gdb-memory-buffer-name ()
2242 (with-current-buffer gud-comint-buffer
2243 (concat "*memory of " (gdb-get-target-string) "*")))
2245 (defun gdb-display-memory-buffer ()
2246 "Display memory contents."
2249 (gdb-get-create-buffer 'gdb-memory-buffer)))
2251 (defun gdb-frame-memory-buffer ()
2252 "Display memory contents in a new frame."
2254 (let ((special-display-regexps (append special-display-regexps '(".*")))
2255 (special-display-frame-alist gdb-frame-parameters))
2256 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2261 (gdb-set-buffer-rules 'gdb-locals-buffer
2262 'gdb-locals-buffer-name
2265 (def-gdb-auto-update-trigger gdb-invalidate-locals
2266 (gdb-get-buffer 'gdb-locals-buffer)
2267 "server info locals\n"
2268 gdb-info-locals-handler)
2270 (defvar gdb-locals-watch-keymap
2271 (let ((map (make-sparse-keymap)))
2272 (define-key map "\r" '(lambda () (interactive)
2275 (define-key map [mouse-2] '(lambda (event) (interactive "e")
2276 (mouse-set-point event)
2280 "Keymap to create watch expression of a complex data type local variable.")
2282 (defconst gdb-struct-string
2283 (concat (propertize "[struct/union]"
2284 'mouse-face 'highlight
2285 'help-echo "mouse-2: create watch expression"
2286 'local-map gdb-locals-watch-keymap) "\n"))
2288 (defconst gdb-array-string
2289 (concat " " (propertize "[array]"
2290 'mouse-face 'highlight
2291 'help-echo "mouse-2: create watch expression"
2292 'local-map gdb-locals-watch-keymap) "\n"))
2294 ;; Abbreviate for arrays and structures.
2295 ;; These can be expanded using gud-display.
2296 (defun gdb-info-locals-handler ()
2297 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2298 gdb-pending-triggers))
2299 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2300 (with-current-buffer buf
2301 (goto-char (point-min))
2302 (while (re-search-forward "^[ }].*\n" nil t)
2303 (replace-match "" nil nil))
2304 (goto-char (point-min))
2305 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2306 (replace-match gdb-struct-string nil nil))
2307 (goto-char (point-min))
2308 (while (re-search-forward "\\s-*{.*\n" nil t)
2309 (replace-match gdb-array-string nil nil))))
2310 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2312 (with-current-buffer buf
2313 (let* ((window (get-buffer-window buf 0))
2314 (p (window-point window))
2315 (buffer-read-only nil))
2317 (insert-buffer-substring (gdb-get-create-buffer
2318 'gdb-partial-output-buffer))
2319 (set-window-point window p)))))
2320 (run-hooks 'gdb-info-locals-hook))
2322 (defvar gdb-locals-mode-map
2323 (let ((map (make-sparse-keymap)))
2324 (suppress-keymap map)
2325 (define-key map "q" 'kill-this-buffer)
2328 (defvar gdb-locals-font-lock-keywords
2330 ;; var = (struct struct_tag) value
2331 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2332 (1 font-lock-variable-name-face)
2333 (3 font-lock-keyword-face)
2334 (4 font-lock-type-face))
2335 ;; var = (type) value
2336 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2337 (1 font-lock-variable-name-face)
2338 (3 font-lock-type-face))
2340 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2341 (1 font-lock-variable-name-face))
2343 "Font lock keywords used in `gdb-local-mode'.")
2345 (defun gdb-locals-mode ()
2346 "Major mode for gdb locals.
2348 \\{gdb-locals-mode-map}"
2349 (kill-all-local-variables)
2350 (setq major-mode 'gdb-locals-mode)
2351 (setq mode-name (concat "Locals:" gdb-selected-frame))
2352 (setq buffer-read-only t)
2353 (use-local-map gdb-locals-mode-map)
2354 (set (make-local-variable 'font-lock-defaults)
2355 '(gdb-locals-font-lock-keywords))
2356 (run-mode-hooks 'gdb-locals-mode-hook)
2357 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2358 'gdb-invalidate-locals
2359 'gdbmi-invalidate-locals))
2361 (defun gdb-locals-buffer-name ()
2362 (with-current-buffer gud-comint-buffer
2363 (concat "*locals of " (gdb-get-target-string) "*")))
2365 (defun gdb-display-locals-buffer ()
2366 "Display local variables of current stack and their values."
2369 (gdb-get-create-buffer 'gdb-locals-buffer)))
2371 (defun gdb-frame-locals-buffer ()
2372 "Display local variables of current stack and their values in a new frame."
2374 (let ((special-display-regexps (append special-display-regexps '(".*")))
2375 (special-display-frame-alist gdb-frame-parameters))
2376 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2379 ;;;; Window management
2380 (defun gdb-display-buffer (buf &optional size)
2381 (let ((answer (get-buffer-window buf 0))
2384 (display-buffer buf nil 0) ;Raise the frame if necessary.
2385 ;; The buffer is not yet displayed.
2386 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2387 (let ((window (get-lru-window)))
2389 (not (eq window (get-buffer-window gud-comint-buffer))))
2391 (set-window-buffer window buf)
2392 (setq answer window))
2393 (setq must-split t)))
2395 (let* ((largest (get-largest-window))
2396 (cur-size (window-height largest))
2397 (new-size (and size (< size cur-size) (- cur-size size))))
2398 (setq answer (split-window largest new-size))
2399 (set-window-buffer answer buf)
2400 (set-window-dedicated-p answer t)))
2404 ;;; Shared keymap initialization:
2406 (let ((menu (make-sparse-keymap "GDB-Windows")))
2407 (define-key gud-menu-map [displays]
2408 `(menu-item "GDB-Windows" ,menu
2409 :visible (memq gud-minor-mode '(gdbmi gdba))))
2410 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2411 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2412 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2413 (define-key menu [disassembly]
2414 '("Disassembly" . gdb-display-assembler-buffer))
2415 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2416 (define-key menu [inferior]
2417 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2418 :enable gdb-use-inferior-io-buffer))
2419 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2420 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2421 (define-key menu [breakpoints]
2422 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2424 (let ((menu (make-sparse-keymap "GDB-Frames")))
2425 (define-key gud-menu-map [frames]
2426 `(menu-item "GDB-Frames" ,menu
2427 :visible (memq gud-minor-mode '(gdbmi gdba))))
2428 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2429 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2430 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2431 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2432 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2433 (define-key menu [inferior]
2434 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2435 :enable gdb-use-inferior-io-buffer))
2436 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2437 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2438 (define-key menu [breakpoints]
2439 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2441 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2442 (define-key gud-menu-map [ui]
2443 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2444 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2445 (define-key menu [gdb-use-inferior-io]
2446 '(menu-item "Separate inferior IO" gdb-use-inferior-io-buffer
2447 :visible (eq gud-minor-mode 'gdba)
2448 :help "Toggle separate IO for inferior."
2449 :button (:toggle . gdb-use-inferior-io-buffer)))
2450 (define-key menu [gdb-many-windows]
2451 '(menu-item "Display Other Windows" gdb-many-windows
2452 :help "Toggle display of locals, stack and breakpoint information"
2453 :button (:toggle . gdb-many-windows)))
2454 (define-key menu [gdb-restore-windows]
2455 '(menu-item "Restore Window Layout" gdb-restore-windows
2456 :help "Restore standard layout for debug session.")))
2458 (defun gdb-frame-gdb-buffer ()
2459 "Display GUD buffer in a new frame."
2461 (let ((special-display-regexps (append special-display-regexps '(".*")))
2462 (special-display-frame-alist gdb-frame-parameters)
2463 (same-window-regexps nil))
2464 (display-buffer gud-comint-buffer)))
2466 (defun gdb-display-gdb-buffer ()
2467 "Display GUD buffer."
2469 (let ((same-window-regexps nil))
2470 (pop-to-buffer gud-comint-buffer)))
2472 (defun gdb-set-window-buffer (name)
2473 (set-window-buffer (selected-window) (get-buffer name))
2474 (set-window-dedicated-p (selected-window) t))
2476 (defun gdb-setup-windows ()
2477 "Layout the window pattern for `gdb-many-windows'."
2478 (gdb-display-locals-buffer)
2479 (gdb-display-stack-buffer)
2480 (delete-other-windows)
2481 (gdb-display-breakpoints-buffer)
2482 (delete-other-windows)
2484 (pop-to-buffer gud-comint-buffer)
2485 (split-window nil ( / ( * (window-height) 3) 4))
2486 (split-window nil ( / (window-height) 3))
2487 (split-window-horizontally)
2489 (gdb-set-window-buffer (gdb-locals-buffer-name))
2492 (if gud-last-last-frame
2493 (gud-find-file (car gud-last-last-frame))
2494 (gud-find-file gdb-main-file)))
2495 (when gdb-use-inferior-io-buffer
2496 (split-window-horizontally)
2498 (gdb-set-window-buffer
2499 (gdb-get-create-buffer 'gdb-inferior-io)))
2501 (gdb-set-window-buffer (gdb-stack-buffer-name))
2502 (split-window-horizontally)
2504 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2507 (defcustom gdb-many-windows nil
2508 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2509 In this case it starts with two windows: one displaying the GUD
2510 buffer and the other with the source file with the main routine
2511 of the inferior. Non-nil means display the layout shown for
2517 (defun gdb-many-windows (arg)
2518 "Toggle the number of windows in the basic arrangement.
2519 With arg, display additional buffers iff arg is positive."
2521 (setq gdb-many-windows
2523 (not gdb-many-windows)
2524 (> (prefix-numeric-value arg) 0)))
2525 (if (and gud-comint-buffer
2526 (buffer-name gud-comint-buffer))
2528 (gdb-restore-windows)
2531 (defun gdb-restore-windows ()
2532 "Restore the basic arrangement of windows used by gdba.
2533 This arrangement depends on the value of `gdb-many-windows'."
2535 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2536 (delete-other-windows)
2537 (if gdb-many-windows
2539 (when (or gud-last-last-frame gdb-show-main)
2543 (if gud-last-last-frame
2544 (gud-find-file (car gud-last-last-frame))
2545 (gud-find-file gdb-main-file)))
2549 "Exit a debugging session cleanly.
2550 Kills the gdb buffers and resets the source buffers."
2551 (dolist (buffer (buffer-list))
2552 (unless (eq buffer gud-comint-buffer)
2553 (with-current-buffer buffer
2554 (if (memq gud-minor-mode '(gdbmi gdba))
2555 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2557 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2558 (setq gud-minor-mode nil)
2559 (kill-local-variable 'tool-bar-map)
2560 (kill-local-variable 'gdb-define-alist))))))
2561 (when (markerp gdb-overlay-arrow-position)
2562 (move-marker gdb-overlay-arrow-position nil)
2563 (setq gdb-overlay-arrow-position nil))
2564 (setq overlay-arrow-variable-list
2565 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2566 (setq gud-running nil)
2567 (setq gdb-active-process nil)
2568 (setq gdb-var-list nil)
2569 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2571 (defun gdb-source-info ()
2572 "Find the source file where the program starts and displays it with related
2574 (goto-char (point-min))
2575 (if (and (search-forward "Located in " nil t)
2576 (looking-at "\\S-+"))
2577 (setq gdb-main-file (match-string 0)))
2578 (goto-char (point-min))
2579 (if (search-forward "Includes preprocessor macro info." nil t)
2580 (setq gdb-macro-info t))
2581 (if gdb-many-windows
2583 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2585 (let ((pop-up-windows t))
2586 (display-buffer (gud-find-file gdb-main-file))))))
2588 (defun gdb-get-location (bptno line flag)
2589 "Find the directory containing the relevant source file.
2590 Put in buffer and place breakpoint icon."
2591 (goto-char (point-min))
2592 (catch 'file-not-found
2593 (if (search-forward "Located in " nil t)
2594 (when (looking-at "\\S-+")
2595 (delete (cons bptno "File not found") gdb-location-alist)
2596 (push (cons bptno (match-string 0)) gdb-location-alist))
2598 (unless (assoc bptno gdb-location-alist)
2599 (push (cons bptno "File not found") gdb-location-alist)
2600 (message-box "Cannot find source file for breakpoint location.\n\
2601 Add directory to search path for source files using the GDB command, dir."))
2602 (throw 'file-not-found nil))
2603 (with-current-buffer
2604 (find-file-noselect (match-string 0))
2605 (save-current-buffer
2606 (set (make-local-variable 'gud-minor-mode) 'gdba)
2607 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2608 ;; only want one breakpoint icon at each location
2610 (goto-line (string-to-number line))
2611 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2613 (add-hook 'find-file-hook 'gdb-find-file-hook)
2615 (defun gdb-find-file-hook ()
2616 "Set up buffer for debugging if file is part of the source code
2617 of the current session."
2618 (if (and (not gdb-find-file-unhook)
2619 ;; in case gud or gdb-ui is just loaded
2621 (buffer-name gud-comint-buffer)
2622 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2626 (list (concat gdb-server-prefix "list "
2627 (file-name-nondirectory buffer-file-name)
2629 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2630 (error (setq gdb-find-file-unhook t)))))
2633 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2634 "Put string PUTSTRING in front of POS in the current buffer.
2635 PUTSTRING is displayed by putting an overlay into the current buffer with a
2636 `before-string' string that has a `display' property whose value is
2638 (let ((string (make-string 1 ?x))
2639 (buffer (current-buffer)))
2640 (setq putstring (copy-sequence putstring))
2641 (let ((overlay (make-overlay pos pos buffer))
2643 (list (list 'margin 'left-margin) putstring))))
2644 (put-text-property 0 1 'display prop string)
2646 (add-text-properties 0 1 sprops string))
2647 (overlay-put overlay 'put-break t)
2648 (overlay-put overlay 'before-string string))))
2650 ;;from remove-images
2651 (defun gdb-remove-strings (start end &optional buffer)
2652 "Remove strings between START and END in BUFFER.
2653 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2654 BUFFER nil or omitted means use the current buffer."
2656 (setq buffer (current-buffer)))
2657 (dolist (overlay (overlays-in start end))
2658 (when (overlay-get overlay 'put-break)
2659 (delete-overlay overlay))))
2661 (defun gdb-put-breakpoint-icon (enabled bptno)
2662 (let ((start (- (line-beginning-position) 1))
2663 (end (+ (line-end-position) 1))
2664 (putstring (if enabled "B" "b"))
2665 (source-window (get-buffer-window (current-buffer) 0)))
2666 (add-text-properties
2667 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2670 (add-text-properties
2671 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2672 (add-text-properties
2673 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2674 (gdb-remove-breakpoint-icons start end)
2675 (if (display-images-p)
2676 (if (>= (or left-fringe-width
2677 (if source-window (car (window-fringes source-window)))
2678 gdb-buffer-fringe-width) 8)
2681 `(left-fringe breakpoint
2684 'breakpoint-disabled))
2686 'gdb-enabled enabled)
2687 (when (< left-margin-width 2)
2688 (save-current-buffer
2689 (setq left-margin-width 2)
2693 left-margin-width right-margin-width))))
2696 (or breakpoint-enabled-icon
2697 (setq breakpoint-enabled-icon
2698 (find-image `((:type xpm :data
2699 ,breakpoint-xpm-data
2700 :ascent 100 :pointer hand)
2702 ,breakpoint-enabled-pbm-data
2703 :ascent 100 :pointer hand)))))
2704 (or breakpoint-disabled-icon
2705 (setq breakpoint-disabled-icon
2706 (find-image `((:type xpm :data
2707 ,breakpoint-xpm-data
2708 :conversion disabled
2709 :ascent 100 :pointer hand)
2711 ,breakpoint-disabled-pbm-data
2712 :ascent 100 :pointer hand))))))
2716 (when (< left-margin-width 2)
2717 (save-current-buffer
2718 (setq left-margin-width 2)
2719 (let ((window (get-buffer-window (current-buffer) 0)))
2722 window left-margin-width right-margin-width)))))
2724 (propertize putstring
2725 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2728 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2729 (gdb-remove-strings start end)
2730 (if (display-images-p)
2731 (remove-images start end))
2733 (setq left-margin-width 0)
2734 (let ((window (get-buffer-window (current-buffer) 0)))
2737 window left-margin-width right-margin-width)))))
2741 ;; Assembler buffer.
2743 (gdb-set-buffer-rules 'gdb-assembler-buffer
2744 'gdb-assembler-buffer-name
2745 'gdb-assembler-mode)
2747 (def-gdb-auto-update-handler gdb-assembler-handler
2748 gdb-invalidate-assembler
2749 gdb-assembler-buffer
2750 gdb-assembler-custom)
2752 (defun gdb-assembler-custom ()
2753 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2754 (pos 1) (address) (flag) (bptno))
2755 (with-current-buffer buffer
2757 (if (not (equal gdb-frame-address "main"))
2759 (goto-char (point-min))
2760 (if (and gdb-frame-address
2761 (re-search-forward gdb-frame-address nil t))
2765 (or gdb-overlay-arrow-position
2766 (setq gdb-overlay-arrow-position (make-marker)))
2767 (set-marker gdb-overlay-arrow-position
2768 (point) (current-buffer))))))
2769 ;; remove all breakpoint-icons in assembler buffer before updating.
2770 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2771 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2772 (goto-char (point-min))
2773 (while (< (point) (- (point-max) 1))
2775 (if (looking-at "[^\t].*?breakpoint")
2778 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2779 (setq bptno (match-string 1))
2780 (setq flag (char-after (match-beginning 2)))
2781 (setq address (match-string 3))
2782 (with-current-buffer buffer
2784 (goto-char (point-min))
2785 (if (re-search-forward address nil t)
2786 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2787 (if (not (equal gdb-frame-address "main"))
2788 (with-current-buffer buffer
2789 (set-window-point (get-buffer-window buffer 0) pos)))))
2791 (defvar gdb-assembler-mode-map
2792 (let ((map (make-sparse-keymap)))
2793 (suppress-keymap map)
2794 (define-key map "q" 'kill-this-buffer)
2797 (defvar gdb-assembler-font-lock-keywords
2798 '(;; <__function.name+n>
2799 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2800 (1 font-lock-function-name-face))
2801 ;; 0xNNNNNNNN <__function.name+n>: opcode
2802 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2803 (4 font-lock-keyword-face))
2804 ;; %register(at least i386)
2805 ("%\\sw+" . font-lock-variable-name-face)
2806 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2807 (1 font-lock-comment-face)
2808 (2 font-lock-function-name-face))
2809 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2810 "Font lock keywords used in `gdb-assembler-mode'.")
2812 (defun gdb-assembler-mode ()
2813 "Major mode for viewing code assembler.
2815 \\{gdb-assembler-mode-map}"
2816 (kill-all-local-variables)
2817 (setq major-mode 'gdb-assembler-mode)
2818 (setq mode-name (concat "Machine:" gdb-selected-frame))
2819 (setq gdb-overlay-arrow-position nil)
2820 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2821 (setq fringes-outside-margins t)
2822 (setq buffer-read-only t)
2823 (use-local-map gdb-assembler-mode-map)
2824 (gdb-invalidate-assembler)
2825 (set (make-local-variable 'font-lock-defaults)
2826 '(gdb-assembler-font-lock-keywords))
2827 (run-mode-hooks 'gdb-assembler-mode-hook)
2828 'gdb-invalidate-assembler)
2830 (defun gdb-assembler-buffer-name ()
2831 (with-current-buffer gud-comint-buffer
2832 (concat "*disassembly of " (gdb-get-target-string) "*")))
2834 (defun gdb-display-assembler-buffer ()
2835 "Display disassembly view."
2837 (setq gdb-previous-frame nil)
2839 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2841 (defun gdb-frame-assembler-buffer ()
2842 "Display disassembly view in a new frame."
2844 (setq gdb-previous-frame nil)
2845 (let ((special-display-regexps (append special-display-regexps '(".*")))
2846 (special-display-frame-alist gdb-frame-parameters))
2847 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2849 ;; modified because if gdb-frame-address has changed value a new command
2850 ;; must be enqueued to update the buffer with the new output
2851 (defun gdb-invalidate-assembler (&optional ignored)
2852 (if (gdb-get-buffer 'gdb-assembler-buffer)
2854 (unless (and gdb-selected-frame
2855 (string-equal gdb-selected-frame gdb-previous-frame))
2856 (if (or (not (member 'gdb-invalidate-assembler
2857 gdb-pending-triggers))
2858 (not (string-equal gdb-frame-address
2859 gdb-previous-frame-address)))
2861 ;; take previous disassemble command, if any, off the queue
2862 (with-current-buffer gud-comint-buffer
2863 (let ((queue gdb-input-queue))
2864 (dolist (item queue)
2865 (if (equal (cdr item) '(gdb-assembler-handler))
2866 (setq gdb-input-queue
2867 (delete item gdb-input-queue))))))
2870 (concat gdb-server-prefix "disassemble "
2871 (if (member gdb-frame-address '(nil "main")) nil "0x")
2872 gdb-frame-address "\n")
2873 'gdb-assembler-handler))
2874 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2875 (setq gdb-previous-frame-address gdb-frame-address)
2876 (setq gdb-previous-frame gdb-selected-frame)))))))
2878 (defun gdb-get-selected-frame ()
2879 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2882 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2883 (push 'gdb-get-selected-frame
2884 gdb-pending-triggers))))
2886 (defun gdb-frame-handler ()
2887 (setq gdb-pending-triggers
2888 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2889 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2890 (goto-char (point-min))
2891 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2892 (setq gdb-frame-number (match-string 1)))
2893 (goto-char (point-min))
2894 (if (re-search-forward
2895 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2897 (setq gdb-selected-frame (match-string 2))
2898 (if (gdb-get-buffer 'gdb-locals-buffer)
2899 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2900 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2901 (if (gdb-get-buffer 'gdb-assembler-buffer)
2902 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2903 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2904 (setq gdb-frame-address (match-string 1))))
2905 (goto-char (point-min))
2906 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2907 (setq gdb-current-language (match-string 1))))
2908 (gdb-invalidate-assembler))
2912 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2913 ;;; gdb-ui.el ends here