1 ;;; gdb-ui.el --- User Interface for running GDB
3 ;; Author: Nick Roberts <nickrob@gnu.org>
5 ;; Keywords: unix, tools
7 ;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode acts as a graphical user interface to GDB. You can interact with
29 ;; GDB through the GUD buffer in the usual way, but there are also further
30 ;; buffers which control the execution and describe the state of your program.
31 ;; It separates the input/output of your program from that of GDB, if
32 ;; required, and watches expressions in the speedbar. It also uses features of
33 ;; Emacs 21 such as the fringe/display margin for breakpoints, and the toolbar
34 ;; (see the GDB Graphical Interface section in the Emacs info manual).
36 ;; By default, M-x gdb will start the debugger. However, if you have customised
37 ;; gud-gdb-command-name, then start it with M-x gdba.
39 ;; This file has evolved from gdba.el that was included with GDB 5.0 and
40 ;; written by Tom Lord and Jim Kingdon. It uses GDB's annotation interface.
41 ;; You don't need to know about annotations to use this mode as a debugger,
42 ;; but if you are interested developing the mode itself, then see the
43 ;; Annotations section in the GDB info manual.
45 ;; GDB developers plan to make the annotation interface obsolete. A new
46 ;; interface called GDB/MI (machine interface) has been designed to replace
47 ;; it. Some GDB/MI commands are used in this file through the CLI command
48 ;; 'interpreter mi <mi-command>'. A file called gdb-mi.el is included with
49 ;; GDB (6.2 onwards) that uses GDB/MI as the primary interface to GDB. It is
50 ;; still under development and is part of a process to migrate Emacs from
51 ;; annotations to GDB/MI.
53 ;; This mode SHOULD WORK WITH GDB 5.0 ONWARDS but you will NEED GDB 6.0
54 ;; ONWARDS TO USE WATCH EXPRESSIONS.
58 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
59 ;; explicitly in your program if you want timely display of I/O in Emacs.
60 ;; Alternatively you can make the output stream unbuffered, for example, by
64 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
67 ;; and compiling with -DUNBUFFERED while debugging.
72 ;; 1) Use MI command -data-read-memory for memory window.
73 ;; 2) Highlight changed register values (use MI commands
74 ;; -data-list-register-values and -data-list-changed-registers instead
75 ;; of 'info registers'.
76 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
77 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
78 ;; 5) After release of 22.1, use "-var-list-children --all-values"
79 ;; and "-stack-list-locals --simple-values" which need GDB 6.1 onwards.
80 ;; 6) After release of 22.1, use "-var-update --all-values" which needs
82 ;; 7) With gud-print and gud-pstar, print the variable name in the GUD
83 ;; buffer instead of the value's history number.
91 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
92 (defvar gdb-previous-frame-address nil)
93 (defvar gdb-memory-address "main")
94 (defvar gdb-previous-frame nil)
95 (defvar gdb-selected-frame nil)
96 (defvar gdb-frame-number nil)
97 (defvar gdb-current-language nil)
98 (defvar gdb-var-list nil "List of variables in watch window.")
99 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
100 (defvar gdb-main-file nil "Source file from which program execution begins.")
101 (defvar gdb-overlay-arrow-position nil)
102 (defvar gdb-server-prefix nil)
103 (defvar gdb-flush-pending-output nil)
104 (defvar gdb-location-alist nil
105 "Alist of breakpoint numbers and full filenames.")
106 (defvar gdb-find-file-unhook nil)
107 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
108 and #define directives otherwise.")
109 (defvar gdb-error "Non-nil when GDB is reporting an error.")
110 (defvar gdb-macro-info nil
111 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
112 (defvar gdb-buffer-fringe-width nil)
114 (defvar gdb-buffer-type nil
115 "One of the symbols bound in `gdb-buffer-rules'.")
116 (make-variable-buffer-local 'gdb-buffer-type)
118 (defvar gdb-input-queue ()
119 "A list of gdb command objects.")
121 (defvar gdb-prompting nil
122 "True when gdb is idle with no pending input.")
124 (defvar gdb-output-sink 'user
125 "The disposition of the output of the current gdb command.
126 Possible values are these symbols:
128 `user' -- gdb output should be copied to the GUD buffer
131 `inferior' -- gdb output should be copied to the inferior-io buffer.
133 `pre-emacs' -- output should be ignored util the post-prompt
134 annotation is received. Then the output-sink
136 `emacs' -- output should be collected in the partial-output-buffer
137 for subsequent processing by a command. This is the
138 disposition of output generated by commands that
139 gdb mode sends to gdb on its own behalf.
140 `post-emacs' -- ignore output until the prompt annotation is
141 received, then go to USER disposition.
143 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
144 \(`user' and `emacs').")
146 (defvar gdb-current-item nil
147 "The most recent command item sent to gdb.")
149 (defvar gdb-pending-triggers '()
150 "A list of trigger functions that have run later than their output
153 ;; end of gdb variables
156 (defun gdba (command-line)
157 "Run gdb on program FILE in buffer *gud-FILE*.
158 The directory containing FILE becomes the initial working directory
159 and source-file directory for your debugger.
161 If `gdb-many-windows' is nil (the default value) then gdb just
162 pops up the GUD buffer unless `gdb-show-main' is t. In this case
163 it starts with two windows: one displaying the GUD buffer and the
164 other with the source file with the main routine of the inferior.
166 If `gdb-many-windows' is t, regardless of the value of
167 `gdb-show-main', the layout below will appear unless
168 `gdb-use-inferior-io-buffer' is nil when the source buffer
169 occupies the full width of the frame. Keybindings are given in
172 Watch expressions appear in the speedbar/slowbar.
174 The following commands help control operation :
176 `gdb-many-windows' - Toggle the number of windows gdb uses.
177 `gdb-restore-windows' - To restore the window layout.
179 See Info node `(emacs)GDB Graphical Interface' for a more
180 detailed description of this mode.
183 +--------------------------------------------------------------+
185 +-------------------------------+------------------------------+
186 | GUD buffer (I/O of GDB) | Locals buffer |
190 +-------------------------------+------------------------------+
191 | Source buffer | I/O buffer (of inferior) |
199 +-------------------------------+------------------------------+
200 | Stack buffer | Breakpoints buffer |
201 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
202 | | RET gdb-goto-breakpoint |
203 | | d gdb-delete-breakpoint |
204 +-------------------------------+------------------------------+"
206 (interactive (list (gud-query-cmdline 'gdba)))
208 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
212 (defvar gdb-debug-log nil)
215 (defcustom gdb-enable-debug-log nil
216 "Non-nil means record the process input and output in `gdb-debug-log'."
221 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
222 "Shell command for generating a list of defined macros in a source file.
223 This list is used to display the #define directive associated
224 with an identifier as a tooltip. It works in a debug session with
225 GDB, when gud-tooltip-mode is t.
227 Set `gdb-cpp-define-alist-flags' for any include paths or
233 (defcustom gdb-cpp-define-alist-flags ""
234 "Preprocessor flags for `gdb-cpp-define-alist-program'."
239 (defcustom gdb-show-main nil
240 "Non-nil means display source file containing the main routine at startup.
241 Also display the main routine in the disassembly buffer if present."
246 (defcustom gdb-use-inferior-io-buffer nil
247 "Non-nil means display output from the inferior in a separate buffer."
252 (defun gdb-use-inferior-io-buffer (arg)
253 "Toggle separate IO for inferior.
254 With arg, use separate IO iff arg is positive."
256 (setq gdb-use-inferior-io-buffer
258 (not gdb-use-inferior-io-buffer)
259 (> (prefix-numeric-value arg) 0)))
260 (if (and gud-comint-buffer
261 (buffer-name gud-comint-buffer))
263 (if gdb-use-inferior-io-buffer
264 (gdb-restore-windows)
265 (kill-buffer (gdb-inferior-io-name)))
268 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
270 (defun gdb-create-define-alist ()
271 "Create an alist of #define directives for GUD tooltips."
272 (let* ((file (buffer-file-name))
274 (with-output-to-string
275 (with-current-buffer standard-output
276 (call-process shell-file-name
277 (if (file-exists-p file) file nil)
278 (list t nil) nil "-c"
279 (concat gdb-cpp-define-alist-program " "
280 gdb-cpp-define-alist-flags)))))
281 (define-list (split-string output "\n" t))
283 (setq gdb-define-alist nil)
284 (dolist (define define-list)
285 (setq name (nth 1 (split-string define "[( ]")))
286 (push (cons name define) gdb-define-alist))))
288 (defun gdb-tooltip-print ()
290 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
291 (let ((string (buffer-string)))
292 ;; remove newline for gud-tooltip-echo-area
293 (substring string 0 (- (length string) 1))))
294 (or gud-tooltip-echo-area tooltip-use-echo-area)))
296 ;; If expr is a macro for a function don't print because of possible dangerous
297 ;; side-effects. Also printing a function within a tooltip generates an
298 ;; unexpected starting annotation (phase error).
299 (defun gdb-tooltip-print-1 (expr)
300 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
301 (goto-char (point-min))
302 (if (search-forward "expands to: " nil t)
303 (unless (looking-at "\\S-+.*(.*).*")
305 (list (concat gdb-server-prefix "print " expr "\n")
306 'gdb-tooltip-print))))))
308 (defun gdb-set-gud-minor-mode (buffer)
309 "Set `gud-minor-mode' from find-file if appropriate."
310 (goto-char (point-min))
311 (unless (search-forward "No source file named " nil t)
314 (list (concat gdb-server-prefix "info source\n")
315 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
316 (error (setq gdb-find-file-unhook t)))))
318 (defun gdb-set-gud-minor-mode-1 (buffer)
319 (goto-char (point-min))
320 (when (and (search-forward "Located in " nil t)
322 (string-equal (buffer-file-name buffer)
324 (with-current-buffer buffer
325 (set (make-local-variable 'gud-minor-mode) 'gdba)
326 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
327 (when gud-tooltip-mode
328 (make-local-variable 'gdb-define-alist)
329 (gdb-create-define-alist)
330 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
332 (defun gdb-set-gud-minor-mode-existing-buffers ()
333 (dolist (buffer (buffer-list))
334 (let ((file (buffer-file-name buffer)))
338 (list (concat gdb-server-prefix "list "
339 (file-name-nondirectory file) ":1\n")
340 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
342 (defun gdb-find-watch-expression ()
343 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
344 (varno (nth 1 var)) (expr))
345 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varno)
346 (dolist (var1 gdb-var-list)
347 (if (string-equal (nth 1 var1) (match-string 1 varno))
348 (setq expr (concat (car var1) "." (match-string 2 varno)))))
352 (setq gdb-debug-log nil)
353 (set (make-local-variable 'gud-minor-mode) 'gdba)
354 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
356 (gud-def gud-break (if (not (string-match "Machine" mode-name))
357 (gud-call "break %f:%l" arg)
361 (gud-call "break *%a" arg)))
362 "\C-b" "Set breakpoint at current line or address.")
364 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
365 (gud-call "clear %f:%l" arg)
369 (gud-call "clear *%a" arg)))
370 "\C-d" "Remove breakpoint at current line or address.")
372 (gud-def gud-until (if (not (string-match "Machine" mode-name))
373 (gud-call "until %f:%l" arg)
377 (gud-call "until *%a" arg)))
378 "\C-u" "Continue to current line or address.")
380 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
381 nil "Start or continue execution.")
383 ;; For debugging Emacs only.
387 "pp1 " (if (eq (buffer-local-value
388 'major-mode (window-buffer)) 'speedbar-mode)
389 (gdb-find-watch-expression) "%e")) arg)
390 nil "Print the emacs s-expression.")
392 (define-key gud-minor-mode-map [left-margin mouse-1]
393 'gdb-mouse-set-clear-breakpoint)
394 (define-key gud-minor-mode-map [left-fringe mouse-1]
395 'gdb-mouse-set-clear-breakpoint)
396 (define-key gud-minor-mode-map [left-fringe mouse-2]
398 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
400 (define-key gud-minor-mode-map [left-margin mouse-3]
401 'gdb-mouse-toggle-breakpoint-margin)
402 (define-key gud-minor-mode-map [left-fringe mouse-3]
403 'gdb-mouse-toggle-breakpoint-fringe)
405 (setq comint-input-sender 'gdb-send)
408 (setq gdb-frame-address (if gdb-show-main "main" nil))
409 (setq gdb-previous-frame-address nil
410 gdb-memory-address "main"
411 gdb-previous-frame nil
412 gdb-selected-frame nil
413 gdb-current-language nil
421 gdb-pending-triggers nil
422 gdb-output-sink 'user
423 gdb-server-prefix "server "
424 gdb-flush-pending-output nil
425 gdb-location-alist nil
426 gdb-find-file-unhook nil
429 gdb-buffer-fringe-width (car (window-fringes)))
431 (setq gdb-buffer-type 'gdba)
433 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
435 (if (eq window-system 'w32)
436 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
437 (gdb-enqueue-input (list "set height 0\n" 'ignore))
438 (gdb-enqueue-input (list "set width 0\n" 'ignore))
439 ;; find source file and compilation directory here
440 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
441 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
442 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
444 (gdb-set-gud-minor-mode-existing-buffers)
445 (run-hooks 'gdba-mode-hook))
447 (defun gdb-mouse-until (event)
448 "Execute source lines by dragging the overlay arrow (fringe) with the mouse."
450 (if gud-overlay-arrow-position
451 (let ((start (event-start event))
452 (end (event-end event))
453 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
454 (if (not (string-match "Machine" mode-name))
455 (if (equal buffer (window-buffer (posn-window end)))
456 (with-current-buffer buffer
457 (when (or (equal start end)
458 (equal (posn-point start)
460 gud-overlay-arrow-position)))
461 (setq line (line-number-at-pos (posn-point end)))
462 (gud-call (concat "until " (number-to-string line))))))
463 (if (equal (marker-buffer gdb-overlay-arrow-position)
464 (window-buffer (posn-window end)))
465 (when (or (equal start end)
466 (equal (posn-point start)
468 gdb-overlay-arrow-position)))
470 (goto-line (line-number-at-pos (posn-point end)))
472 (gud-call (concat "until *%a")))))))))
474 (defcustom gdb-use-colon-colon-notation nil
475 "If non-nil use FUN::VAR format to display variables in the speedbar."
481 "Watch expression at point."
484 (save-selected-window
485 (let ((expr (tooltip-identifier-from-point (point))))
486 (if (and (string-equal gdb-current-language "c")
487 gdb-use-colon-colon-notation gdb-selected-frame)
488 (setq expr (concat gdb-selected-frame "::" expr)))
489 (catch 'already-watched
490 (dolist (var gdb-var-list)
491 (if (string-equal expr (car var)) (throw 'already-watched nil)))
492 (set-text-properties 0 (length expr) nil expr)
495 (if (eq gud-minor-mode 'gdba)
496 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
497 (concat"-var-create - * " expr "\n"))
498 `(lambda () (gdb-var-create-handler ,expr))))))))
500 (defconst gdb-var-create-regexp
501 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
503 (defun gdb-var-create-handler (expr)
504 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
505 (goto-char (point-min))
506 (if (re-search-forward gdb-var-create-regexp nil t)
507 (let ((var (list expr
512 (push var gdb-var-list)
514 (unless (string-equal
515 speedbar-initial-expansion-list-name "GUD")
516 (speedbar-change-initial-expansion-list "GUD"))
517 (if (or (equal (nth 2 var) "0")
518 (and (equal (nth 2 var) "1")
519 (string-match "char \\*" (nth 3 var))))
522 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
524 (concat "server interpreter mi \"-var-evaluate-expression "
526 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
527 `(lambda () (gdb-var-evaluate-expression-handler
529 (setq gdb-var-changed t)))
530 (if (re-search-forward "Undefined command" nil t)
531 (message-box "Watching expressions requires gdb 6.0 onwards")
532 (message "No symbol \"%s\" in current context." expr)))))
534 (defun gdb-var-evaluate-expression-handler (varnum changed)
535 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
536 (goto-char (point-min))
537 (re-search-forward ".*value=\\(\".*\"\\)" nil t)
540 (dolist (var gdb-var-list)
541 (if (string-equal varnum (cadr var))
543 (if changed (setcar (nthcdr 5 var) t))
544 (setcar (nthcdr 4 var) (read (match-string 1)))
545 (setcar (nthcdr num gdb-var-list) var)
546 (throw 'var-found nil)))
547 (setq num (+ num 1))))))
548 (setq gdb-var-changed t))
550 (defun gdb-var-list-children (varnum)
552 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
553 `(lambda () (gdb-var-list-children-handler ,varnum)))))
555 (defconst gdb-var-list-children-regexp
556 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",\
559 (defun gdb-var-list-children-handler (varnum)
560 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
561 (goto-char (point-min))
562 (let ((var-list nil))
563 (catch 'child-already-watched
564 (dolist (var gdb-var-list)
565 (if (string-equal varnum (cadr var))
568 (while (re-search-forward gdb-var-list-children-regexp nil t)
569 (let ((varchild (list (match-string 2)
574 (dolist (var1 gdb-var-list)
575 (if (string-equal (cadr var1) (cadr varchild))
576 (throw 'child-already-watched nil)))
577 (push varchild var-list)
578 (if (or (equal (nth 2 varchild) "0")
579 (and (equal (nth 2 varchild) "1")
580 (string-match "char \\*" (nth 3 varchild))))
584 "server interpreter mi \"-var-evaluate-expression "
585 (nth 1 varchild) "\"\n")
586 `(lambda () (gdb-var-evaluate-expression-handler
587 ,(nth 1 varchild) nil))))))))
588 (push var var-list)))
589 (setq gdb-var-list (nreverse var-list))))))
591 (defun gdb-var-update ()
592 (when (not (member 'gdb-var-update gdb-pending-triggers))
594 (list "server interpreter mi \"-var-update *\"\n"
595 'gdb-var-update-handler))
596 (push 'gdb-var-update gdb-pending-triggers)))
598 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
600 (defun gdb-var-update-handler ()
601 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
602 (goto-char (point-min))
603 (while (re-search-forward gdb-var-update-regexp nil t)
605 (let ((varnum (match-string 1)))
606 (dolist (var gdb-var-list)
607 (when (and (string-equal varnum (cadr var))
608 (or (equal (nth 2 var) "0")
609 (and (equal (nth 2 var) "1")
610 (string-match "char \\*" (nth 3 var)))))
613 (concat "server interpreter mi \"-var-evaluate-expression "
615 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t))))
616 (throw 'var-found-1 nil)))))))
617 (setq gdb-pending-triggers
618 (delq 'gdb-var-update gdb-pending-triggers))
619 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
620 ;; Dummy command to update speedbar at right time.
621 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
622 ;; Keep gdb-pending-triggers non-nil till end.
623 (push 'gdb-speedbar-timer gdb-pending-triggers)))
625 (defun gdb-speedbar-timer-fn ()
626 (setq gdb-pending-triggers
627 (delq 'gdb-speedbar-timer gdb-pending-triggers))
628 (with-current-buffer gud-comint-buffer
629 (speedbar-timer-fn)))
631 (defun gdb-var-delete ()
632 "Delete watch expression at point from the speedbar."
634 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
636 (let ((text (speedbar-line-text)))
637 (string-match "\\(\\S-+\\)" text)
638 (let* ((expr (match-string 1 text))
639 (var (assoc expr gdb-var-list))
641 (unless (string-match "\\." varnum)
644 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
646 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
647 (concat "-var-delete " varnum "\n"))
649 (setq gdb-var-list (delq var gdb-var-list))
650 (dolist (varchild gdb-var-list)
651 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
652 (setq gdb-var-list (delq varchild gdb-var-list))))
653 (setq gdb-var-changed t))))))
655 (defun gdb-edit-value (text token indent)
656 "Assign a value to a variable displayed in the speedbar."
657 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
658 (varnum (cadr var)) (value))
659 (setq value (read-string "New value: "))
662 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
663 (concat "server interpreter mi \"-var-assign "
664 varnum " " value "\"\n")
665 (concat "-var-assign " varnum " " value "\n"))
668 (defcustom gdb-show-changed-values t
669 "If non-nil highlight values that have recently changed in the speedbar.
670 The highlighting is done with `font-lock-warning-face'."
675 (defun gdb-speedbar-expand-node (text token indent)
676 "Expand the node the user clicked on.
677 TEXT is the text of the button we clicked on, a + or - item.
678 TOKEN is data related to this node.
679 INDENT is the current indentation depth."
680 (cond ((string-match "+" text) ;expand this node
681 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
682 (gdb-var-list-children token)
685 (gdbmi-var-list-children token))))
686 ((string-match "-" text) ;contract this node
687 (dolist (var gdb-var-list)
688 (if (string-match (concat token "\\.") (nth 1 var))
689 (setq gdb-var-list (delq var gdb-var-list))))
690 (setq gdb-var-changed t)
691 (with-current-buffer gud-comint-buffer
692 (speedbar-timer-fn)))))
694 (defun gdb-get-target-string ()
695 (with-current-buffer gud-comint-buffer
702 ;; Each buffer has a TYPE -- a symbol that identifies the function
703 ;; of that particular buffer.
705 ;; The usual gdb interaction buffer is given the type `gdba' and
706 ;; is constructed specially.
708 ;; Others are constructed by gdb-get-create-buffer and
709 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
711 (defvar gdb-buffer-rules-assoc '())
713 (defun gdb-get-buffer (key)
714 "Return the gdb buffer tagged with type KEY.
715 The key should be one of the cars in `gdb-buffer-rules-assoc'."
717 (gdb-look-for-tagged-buffer key (buffer-list))))
719 (defun gdb-get-create-buffer (key)
720 "Create a new gdb buffer of the type specified by KEY.
721 The key should be one of the cars in `gdb-buffer-rules-assoc'."
722 (or (gdb-get-buffer key)
723 (let* ((rules (assoc key gdb-buffer-rules-assoc))
724 (name (funcall (gdb-rules-name-maker rules)))
725 (new (get-buffer-create name)))
726 (with-current-buffer new
728 (if (cdr (cdr rules))
729 (setq trigger (funcall (car (cdr (cdr rules))))))
730 (setq gdb-buffer-type key)
731 (set (make-local-variable 'gud-minor-mode)
732 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
733 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
734 (if trigger (funcall trigger)))
737 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
739 (defun gdb-look-for-tagged-buffer (key bufs)
741 (while (and (not retval) bufs)
742 (set-buffer (car bufs))
743 (if (eq gdb-buffer-type key)
744 (setq retval (car bufs)))
745 (setq bufs (cdr bufs)))
749 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
750 ;; at least one and possible more functions. The functions have these
751 ;; roles in defining a buffer type:
753 ;; NAME - Return a name for this buffer type.
755 ;; The remaining function(s) are optional:
757 ;; MODE - called in a new buffer with no arguments, should establish
758 ;; the proper mode for the buffer.
761 (defun gdb-set-buffer-rules (buffer-type &rest rules)
762 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
764 (setcdr binding rules)
765 (push (cons buffer-type rules)
766 gdb-buffer-rules-assoc))))
768 ;; GUD buffers are an exception to the rules
769 (gdb-set-buffer-rules 'gdba 'error)
772 ;; Partial-output buffer : This accumulates output from a command executed on
773 ;; behalf of emacs (rather than the user).
775 (gdb-set-buffer-rules 'gdb-partial-output-buffer
776 'gdb-partial-output-name)
778 (defun gdb-partial-output-name ()
779 (concat "*partial-output-"
780 (gdb-get-target-string)
784 (gdb-set-buffer-rules 'gdb-inferior-io
785 'gdb-inferior-io-name
786 'gdb-inferior-io-mode)
788 (defun gdb-inferior-io-name ()
789 (concat "*input/output of "
790 (gdb-get-target-string)
793 (defun gdb-display-inferior-io-buffer ()
794 "Display IO of inferior in a separate window."
796 (if gdb-use-inferior-io-buffer
798 (gdb-get-create-buffer 'gdb-inferior-io))))
800 (defconst gdb-frame-parameters
801 '((height . 14) (width . 80)
803 (tool-bar-lines . nil)
804 (menu-bar-lines . nil)
807 (defun gdb-frame-inferior-io-buffer ()
808 "Display IO of inferior in a new frame."
810 (if gdb-use-inferior-io-buffer
811 (let ((special-display-regexps (append special-display-regexps '(".*")))
812 (special-display-frame-alist gdb-frame-parameters))
813 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
815 (defvar gdb-inferior-io-mode-map
816 (let ((map (make-sparse-keymap)))
817 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
818 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
819 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
820 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
821 (define-key map "\C-d" 'gdb-inferior-io-eof)
824 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
825 "Major mode for gdb inferior-io."
826 :syntax-table nil :abbrev-table nil
827 ;; We want to use comint because it has various nifty and familiar
828 ;; features. We don't need a process, but comint wants one, so create
830 (make-comint-in-buffer
831 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
832 (current-buffer) "hexl")
833 (setq comint-input-sender 'gdb-inferior-io-sender))
835 (defun gdb-inferior-io-sender (proc string)
836 ;; PROC is the pseudo-process created to satisfy comint.
837 (with-current-buffer (process-buffer proc)
838 (setq proc (get-buffer-process gud-comint-buffer))
839 (process-send-string proc string)
840 (process-send-string proc "\n")))
842 (defun gdb-inferior-io-interrupt ()
843 "Interrupt the program being debugged."
846 (get-buffer-process gud-comint-buffer) comint-ptyp))
848 (defun gdb-inferior-io-quit ()
849 "Send quit signal to the program being debugged."
852 (get-buffer-process gud-comint-buffer) comint-ptyp))
854 (defun gdb-inferior-io-stop ()
855 "Stop the program being debugged."
858 (get-buffer-process gud-comint-buffer) comint-ptyp))
860 (defun gdb-inferior-io-eof ()
861 "Send end-of-file to the program being debugged."
864 (get-buffer-process gud-comint-buffer)))
868 ;; gdb communications
871 ;; INPUT: things sent to gdb
873 ;; The queues are lists. Each element is either a string (indicating user or
874 ;; user-like input) or a list of the form:
876 ;; (INPUT-STRING HANDLER-FN)
878 ;; The handler function will be called from the partial-output buffer when the
879 ;; command completes. This is the way to write commands which invoke gdb
880 ;; commands autonomously.
882 ;; These lists are consumed tail first.
885 (defun gdb-send (proc string)
886 "A comint send filter for gdb.
887 This filter may simply queue input for a later time."
888 (with-current-buffer gud-comint-buffer
889 (let ((inhibit-read-only t))
890 (remove-text-properties (point-min) (point-max) '(face))))
891 (let ((item (concat string "\n")))
894 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
895 (process-send-string proc item))
896 (gdb-enqueue-input item))))
898 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
899 ;; is a query, or other non-top-level prompt.
901 (defun gdb-enqueue-input (item)
905 (setq gdb-prompting nil))
906 (push item gdb-input-queue)))
908 (defun gdb-dequeue-input ()
909 (let ((queue gdb-input-queue))
911 (let ((last (car (last queue))))
912 (unless (nbutlast queue) (setq gdb-input-queue '()))
915 (defun gdb-send-item (item)
916 (setq gdb-flush-pending-output nil)
917 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
918 (setq gdb-current-item item)
919 (let ((process (get-buffer-process gud-comint-buffer)))
920 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
923 (setq gdb-output-sink 'user)
924 (process-send-string process item))
926 (gdb-clear-partial-output)
927 (setq gdb-output-sink 'pre-emacs)
928 (process-send-string process
930 ;; case: eq gud-minor-mode 'gdbmi
931 (gdb-clear-partial-output)
932 (setq gdb-output-sink 'emacs)
933 (process-send-string process (car item)))))
936 ;; output -- things gdb prints to emacs
938 ;; GDB output is a stream interrupted by annotations.
939 ;; Annotations can be recognized by their beginning
940 ;; with \C-j\C-z\C-z<tag><opt>\C-j
942 ;; The tag is a string obeying symbol syntax.
944 ;; The optional part `<opt>' can be either the empty string
945 ;; or a space followed by more data relating to the annotation.
946 ;; For example, the SOURCE annotation is followed by a filename,
947 ;; line number and various useless goo. This data must not include
951 (defcustom gud-gdba-command-name "gdb -annotate=3"
952 "Default command to execute an executable under the GDB-UI debugger."
957 (defvar gdb-annotation-rules
958 '(("pre-prompt" gdb-pre-prompt)
959 ("prompt" gdb-prompt)
960 ("commands" gdb-subprompt)
961 ("overload-choice" gdb-subprompt)
962 ("query" gdb-subprompt)
963 ;; Need this prompt for GDB 6.1
964 ("nquery" gdb-subprompt)
965 ("prompt-for-continue" gdb-subprompt)
966 ("post-prompt" gdb-post-prompt)
967 ("source" gdb-source)
968 ("starting" gdb-starting)
969 ("exited" gdb-exited)
970 ("signalled" gdb-exited)
971 ("signal" gdb-stopping)
972 ("breakpoint" gdb-stopping)
973 ("watchpoint" gdb-stopping)
974 ("frame-begin" gdb-frame-begin)
975 ("stopped" gdb-stopped)
976 ("error-begin" gdb-error)
978 ) "An assoc mapping annotation tags to functions which process them.")
981 (setq gdb-flush-pending-output t)
982 (setq gud-running nil)
983 (setq gdb-output-sink 'user)
984 (setq gdb-input-queue nil)
985 (setq gdb-pending-triggers nil)
986 (setq gdb-prompting t))
988 (defconst gdb-source-spec-regexp
989 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
991 ;; Do not use this except as an annotation handler.
992 (defun gdb-source (args)
993 (string-match gdb-source-spec-regexp args)
994 ;; Extract the frame position from the marker.
997 (match-string 1 args)
998 (string-to-number (match-string 2 args))))
999 (setq gdb-frame-address (match-string 3 args))
1000 ;; cover for auto-display output which comes *before*
1001 ;; stopped annotation
1002 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1004 (defun gdb-pre-prompt (ignored)
1005 "An annotation handler for `pre-prompt'.
1006 This terminates the collection of output from a previous command if that
1007 happens to be in effect."
1008 (let ((sink gdb-output-sink))
1012 (setq gdb-output-sink 'post-emacs))
1015 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1017 (defun gdb-prompt (ignored)
1018 "An annotation handler for `prompt'.
1019 This sends the next command (if any) to gdb."
1020 (when gdb-first-prompt (gdb-ann3))
1021 (let ((sink gdb-output-sink))
1024 ((eq sink 'post-emacs)
1025 (setq gdb-output-sink 'user)
1027 (car (cdr gdb-current-item))))
1028 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1029 (funcall handler))))
1032 (error "Phase error in gdb-prompt (got %s)" sink))))
1033 (let ((input (gdb-dequeue-input)))
1035 (gdb-send-item input)
1037 (setq gdb-prompting t)
1038 (gud-display-frame)))))
1040 (defun gdb-subprompt (ignored)
1041 "An annotation handler for non-top-level prompts."
1042 (setq gdb-prompting t))
1044 (defun gdb-starting (ignored)
1045 "An annotation handler for `starting'.
1046 This says that I/O for the subprocess is now the program being debugged,
1048 (setq gdb-active-process t)
1049 (let ((sink gdb-output-sink))
1053 (setq gud-running t)
1054 (if gdb-use-inferior-io-buffer
1055 (setq gdb-output-sink 'inferior))))
1058 (error "Unexpected `starting' annotation")))))
1060 (defun gdb-stopping (ignored)
1061 "An annotation handler for `breakpoint' and other annotations.
1062 They say that I/O for the subprocess is now GDB, not the program
1064 (if gdb-use-inferior-io-buffer
1065 (let ((sink gdb-output-sink))
1067 ((eq sink 'inferior)
1068 (setq gdb-output-sink 'user))
1071 (error "Unexpected stopping annotation"))))))
1073 (defun gdb-exited (ignored)
1074 "An annotation handler for `exited' and `signalled'.
1075 They say that I/O for the subprocess is now GDB, not the program
1076 being debugged and that the program is no longer running. This
1077 function is used to change the focus of GUD tooltips to #define
1079 (setq gdb-active-process nil)
1080 (setq gud-overlay-arrow-position nil)
1081 (setq gdb-overlay-arrow-position nil)
1082 (gdb-stopping ignored))
1084 (defun gdb-frame-begin (ignored)
1085 (let ((sink gdb-output-sink))
1087 ((eq sink 'inferior)
1088 (setq gdb-output-sink 'user))
1090 ((eq sink 'emacs) t)
1093 (error "Unexpected frame-begin annotation (%S)" sink)))))
1095 (defun gdb-stopped (ignored)
1096 "An annotation handler for `stopped'.
1097 It is just like `gdb-stopping', except that if we already set the output
1098 sink to `user' in `gdb-stopping', that is fine."
1099 (setq gud-running nil)
1100 (let ((sink gdb-output-sink))
1102 ((eq sink 'inferior)
1103 (setq gdb-output-sink 'user))
1107 (error "Unexpected stopped annotation")))))
1109 (defun gdb-error (ignored)
1110 (setq gdb-error (not gdb-error)))
1112 (defun gdb-post-prompt (ignored)
1113 "An annotation handler for `post-prompt'.
1114 This begins the collection of output from the current command if that
1115 happens to be appropriate."
1116 (unless gdb-pending-triggers
1117 (gdb-get-selected-frame)
1118 (gdb-invalidate-frames)
1119 (gdb-invalidate-breakpoints)
1120 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1121 ;; so gdb-frame-address is updated.
1122 ;; (gdb-invalidate-assembler)
1123 (gdb-invalidate-registers)
1124 (gdb-invalidate-memory)
1125 (gdb-invalidate-locals)
1126 (gdb-invalidate-threads)
1127 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1128 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1129 ;; Only needed/used with speedbar/watch expressions.
1130 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1131 (setq gdb-var-changed t) ; force update
1132 (dolist (var gdb-var-list)
1133 (setcar (nthcdr 5 var) nil))
1135 (let ((sink gdb-output-sink))
1138 ((eq sink 'pre-emacs)
1139 (setq gdb-output-sink 'emacs))
1142 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1144 (defun gud-gdba-marker-filter (string)
1145 "A gud marker filter for gdb. Handle a burst of output from GDB."
1146 (if gdb-flush-pending-output
1148 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1149 ;; Recall the left over gud-marker-acc from last time.
1150 (setq gud-marker-acc (concat gud-marker-acc string))
1151 ;; Start accumulating output for the GUD buffer.
1154 ;; Process all the complete markers in this chunk.
1155 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1156 (let ((annotation (match-string 1 gud-marker-acc)))
1158 ;; Stuff prior to the match is just ordinary output.
1159 ;; It is either concatenated to OUTPUT or directed
1164 (substring gud-marker-acc 0 (match-beginning 0))))
1166 ;; Take that stuff off the gud-marker-acc.
1167 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1169 ;; Parse the tag from the annotation, and maybe its arguments.
1170 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1171 (let* ((annotation-type (match-string 1 annotation))
1172 (annotation-arguments (match-string 2 annotation))
1173 (annotation-rule (assoc annotation-type
1174 gdb-annotation-rules)))
1175 ;; Call the handler for this annotation.
1177 (funcall (car (cdr annotation-rule))
1178 annotation-arguments)
1179 ;; Else the annotation is not recognized. Ignore it silently,
1180 ;; so that GDB can add new annotations without causing
1184 ;; Does the remaining text end in a partial line?
1185 ;; If it does, then keep part of the gud-marker-acc until we get more.
1186 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1189 ;; Everything before the potential marker start can be output.
1191 (gdb-concat-output output
1192 (substring gud-marker-acc 0
1193 (match-beginning 0))))
1195 ;; Everything after, we save, to combine with later input.
1196 (setq gud-marker-acc (substring gud-marker-acc
1197 (match-beginning 0))))
1199 ;; In case we know the gud-marker-acc contains no partial annotations:
1201 (setq output (gdb-concat-output output gud-marker-acc))
1202 (setq gud-marker-acc "")))
1205 (defun gdb-concat-output (so-far new)
1207 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1208 (let ((sink gdb-output-sink))
1210 ((eq sink 'user) (concat so-far new))
1211 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1213 (gdb-append-to-partial-output new)
1215 ((eq sink 'inferior)
1216 (gdb-append-to-inferior-io new)
1220 (error "Bogon output sink %S" sink)))))
1222 (defun gdb-append-to-partial-output (string)
1223 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1224 (goto-char (point-max))
1227 (defun gdb-clear-partial-output ()
1228 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1231 (defun gdb-append-to-inferior-io (string)
1232 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1233 (goto-char (point-max))
1234 (insert-before-markers string))
1235 (if (not (string-equal string ""))
1236 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1238 (defun gdb-clear-inferior-io ()
1239 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1243 ;; One trick is to have a command who's output is always available in a buffer
1244 ;; of it's own, and is always up to date. We build several buffers of this
1247 ;; There are two aspects to this: gdb has to tell us when the output for that
1248 ;; command might have changed, and we have to be able to run the command
1249 ;; behind the user's back.
1251 ;; The output phasing associated with the variable gdb-output-sink
1252 ;; help us to run commands behind the user's back.
1254 ;; Below is the code for specificly managing buffers of output from one
1258 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1259 ;; It adds an input for the command we are tracking. It should be the
1260 ;; annotation rule binding of whatever gdb sends to tell us this command
1261 ;; might have changed it's output.
1263 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1264 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1265 ;; input in the input queue (see comment about ``gdb communications'' above).
1267 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1269 `(defun ,name (&optional ignored)
1270 (if (and ,demand-predicate
1272 gdb-pending-triggers)))
1275 (list ,gdb-command ',output-handler))
1276 (push ',name gdb-pending-triggers)))))
1278 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1280 (setq gdb-pending-triggers
1282 gdb-pending-triggers))
1283 (let ((buf (gdb-get-buffer ',buf-key)))
1285 (with-current-buffer buf
1286 (let* ((window (get-buffer-window buf 0))
1287 (p (window-point window))
1288 (buffer-read-only nil))
1290 (insert-buffer-substring (gdb-get-create-buffer
1291 'gdb-partial-output-buffer))
1292 (set-window-point window p)))))
1293 ;; put customisation here
1296 (defmacro def-gdb-auto-updated-buffer (buffer-key
1297 trigger-name gdb-command
1298 output-handler-name custom-defun)
1300 (def-gdb-auto-update-trigger ,trigger-name
1301 ;; The demand predicate:
1302 (gdb-get-buffer ',buffer-key)
1304 ,output-handler-name)
1305 (def-gdb-auto-update-handler ,output-handler-name
1306 ,trigger-name ,buffer-key ,custom-defun)))
1310 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1312 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1313 'gdb-breakpoints-buffer-name
1314 'gdb-breakpoints-mode)
1316 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1317 ;; This defines the auto update rule for buffers of type
1318 ;; `gdb-breakpoints-buffer'.
1320 ;; It defines a function to serve as the annotation handler that
1321 ;; handles the `foo-invalidated' message. That function is called:
1322 gdb-invalidate-breakpoints
1324 ;; To update the buffer, this command is sent to gdb.
1325 "server info breakpoints\n"
1327 ;; This also defines a function to be the handler for the output
1328 ;; from the command above. That function will copy the output into
1329 ;; the appropriately typed buffer. That function will be called:
1330 gdb-info-breakpoints-handler
1331 ;; buffer specific functions
1332 gdb-info-breakpoints-custom)
1334 (defconst breakpoint-xpm-data
1336 static char *magick[] = {
1337 /* columns rows colors chars-per-pixel */
1353 "XPM data used for breakpoint icon.")
1355 (defconst breakpoint-enabled-pbm-data
1358 0 0 0 0 1 1 1 1 0 0 0 0
1359 0 0 0 1 1 1 1 1 1 0 0 0
1360 0 0 1 1 1 1 1 1 1 1 0 0
1361 0 1 1 1 1 1 1 1 1 1 1 0
1362 0 1 1 1 1 1 1 1 1 1 1 0
1363 0 1 1 1 1 1 1 1 1 1 1 0
1364 0 1 1 1 1 1 1 1 1 1 1 0
1365 0 0 1 1 1 1 1 1 1 1 0 0
1366 0 0 0 1 1 1 1 1 1 0 0 0
1367 0 0 0 0 1 1 1 1 0 0 0 0"
1368 "PBM data used for enabled breakpoint icon.")
1370 (defconst breakpoint-disabled-pbm-data
1382 0 0 0 1 0 1 0 1 0 0"
1383 "PBM data used for disabled breakpoint icon.")
1385 (defvar breakpoint-enabled-icon nil
1386 "Icon for enabled breakpoint in display margin.")
1388 (defvar breakpoint-disabled-icon nil
1389 "Icon for disabled breakpoint in display margin.")
1391 ;; Bitmap for breakpoint in fringe
1392 (and (display-images-p)
1393 (define-fringe-bitmap 'breakpoint
1394 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1396 (defface breakpoint-enabled
1400 "Face for enabled breakpoint icon in fringe."
1403 (defface breakpoint-disabled
1404 ;; We use different values of grey for different background types,
1405 ;; so that on low-color displays it will end up as something visible
1406 ;; if it has to be approximated.
1407 '((((background dark)) :foreground "grey60")
1408 (((background light)) :foreground "grey40"))
1409 "Face for disabled breakpoint icon in fringe."
1412 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1413 (defun gdb-info-breakpoints-custom ()
1414 (let ((flag) (bptno))
1415 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1416 (dolist (buffer (buffer-list))
1417 (with-current-buffer buffer
1418 (if (and (eq gud-minor-mode 'gdba)
1419 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1420 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1421 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1423 (goto-char (point-min))
1424 (while (< (point) (- (point-max) 1))
1426 (if (looking-at "[^\t].*?breakpoint")
1428 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1429 (setq bptno (match-string 1))
1430 (setq flag (char-after (match-beginning 2)))
1432 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1434 (let ((buffer-read-only nil))
1435 (add-text-properties (match-beginning 1) (match-end 1)
1436 '(face font-lock-function-name-face)))
1437 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1438 (let ((line (match-string 2)) (buffer-read-only nil)
1439 (file (match-string 1)))
1440 (add-text-properties (line-beginning-position)
1442 '(mouse-face highlight
1443 help-echo "mouse-2, RET: visit breakpoint"))
1444 (unless (file-exists-p file)
1445 (setq file (cdr (assoc bptno gdb-location-alist))))
1447 (not (string-equal file "File not found")))
1448 (with-current-buffer
1449 (find-file-noselect file 'nowarn)
1450 (set (make-local-variable 'gud-minor-mode)
1452 (set (make-local-variable 'tool-bar-map)
1454 ;; Only want one breakpoint icon at each
1457 (goto-line (string-to-number line))
1458 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1462 (match-string-no-properties 1) ":1\n")
1465 (list "info source\n"
1466 `(lambda () (gdb-get-location
1467 ,bptno ,line ,flag))))))))))
1469 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1471 (defun gdb-mouse-set-clear-breakpoint (event)
1472 "Set/clear breakpoint in left fringe/margin with mouse click."
1474 (mouse-minibuffer-check event)
1475 (let ((posn (event-end event)))
1476 (if (numberp (posn-point posn))
1477 (with-selected-window (posn-window posn)
1479 (goto-char (posn-point posn))
1480 (if (or (posn-object posn)
1481 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1484 (gud-break nil)))))))
1486 (defun gdb-mouse-toggle-breakpoint-margin (event)
1487 "Enable/disable breakpoint in left 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 (posn-object posn)
1498 (let ((bptno (get-text-property
1499 0 'gdb-bptno (car (posn-string posn)))))
1501 (if (get-text-property
1502 0 'gdb-enabled (car (posn-string posn)))
1508 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1509 "Enable/disable breakpoint in left fringe with mouse click."
1511 (mouse-minibuffer-check event)
1512 (let* ((posn (event-end event))
1513 (pos (posn-point posn))
1516 (with-selected-window (posn-window posn)
1518 (set-buffer (window-buffer (selected-window)))
1520 (dolist (overlay (overlays-in pos pos))
1521 (when (overlay-get overlay 'put-break)
1522 (setq obj (overlay-get overlay 'before-string))))
1527 (if (get-text-property 0 'gdb-enabled obj)
1530 (get-text-property 0 'gdb-bptno obj) "\n")
1533 (defun gdb-breakpoints-buffer-name ()
1534 (with-current-buffer gud-comint-buffer
1535 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1537 (defun gdb-display-breakpoints-buffer ()
1538 "Display status of user-settable breakpoints."
1541 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1543 (defun gdb-frame-breakpoints-buffer ()
1544 "Display status of user-settable breakpoints in a new frame."
1546 (let ((special-display-regexps (append special-display-regexps '(".*")))
1547 (special-display-frame-alist gdb-frame-parameters))
1548 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1550 (defvar gdb-breakpoints-mode-map
1551 (let ((map (make-sparse-keymap))
1552 (menu (make-sparse-keymap "Breakpoints")))
1553 (define-key menu [quit] '("Quit" . kill-this-buffer))
1554 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1555 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1556 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1557 (suppress-keymap map)
1558 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1559 (define-key map " " 'gdb-toggle-breakpoint)
1560 (define-key map "d" 'gdb-delete-breakpoint)
1561 (define-key map "q" 'kill-this-buffer)
1562 (define-key map "\r" 'gdb-goto-breakpoint)
1563 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1564 (define-key map [follow-link] 'mouse-face)
1567 (defun gdb-breakpoints-mode ()
1568 "Major mode for gdb breakpoints.
1570 \\{gdb-breakpoints-mode-map}"
1571 (kill-all-local-variables)
1572 (setq major-mode 'gdb-breakpoints-mode)
1573 (setq mode-name "Breakpoints")
1574 (use-local-map gdb-breakpoints-mode-map)
1575 (setq buffer-read-only t)
1576 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1577 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1578 'gdb-invalidate-breakpoints
1579 'gdbmi-invalidate-breakpoints))
1581 (defun gdb-toggle-breakpoint ()
1582 "Enable/disable breakpoint at current line."
1585 (beginning-of-line 1)
1586 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1587 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1589 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1592 (concat gdb-server-prefix
1593 (if (eq ?y (char-after (match-beginning 2)))
1596 (match-string 1) "\n") 'ignore))
1597 (error "Not recognized as break/watchpoint line"))))
1599 (defun gdb-delete-breakpoint ()
1600 "Delete the breakpoint at current line."
1602 (beginning-of-line 1)
1603 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1604 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1606 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1609 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1610 (error "Not recognized as break/watchpoint line")))
1612 (defun gdb-goto-breakpoint (&optional event)
1613 "Display the breakpoint location specified at current line."
1614 (interactive (list last-input-event))
1615 (if event (mouse-set-point event))
1616 ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
1617 (let ((window (get-buffer-window gud-comint-buffer)))
1618 (if window (save-selected-window (select-window window))))
1620 (beginning-of-line 1)
1621 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1622 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1624 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1625 \\(\\S-+\\):\\([0-9]+\\)"))
1626 (let ((bptno (match-string 1))
1627 (file (match-string 2))
1628 (line (match-string 3)))
1629 (save-selected-window
1630 (let* ((buf (find-file-noselect
1631 (if (file-exists-p file) file
1632 (cdr (assoc bptno gdb-location-alist)))))
1633 (window (display-buffer buf)))
1634 (with-current-buffer buf
1635 (goto-line (string-to-number line))
1636 (set-window-point window (point))))))
1637 (error "Not recognized as break/watchpoint line"))))
1640 ;; Frames buffer. This displays a perpetually correct bactracktrace
1641 ;; (from the command `where').
1643 ;; Alas, if your stack is deep, it is costly.
1645 (gdb-set-buffer-rules 'gdb-stack-buffer
1646 'gdb-stack-buffer-name
1649 (def-gdb-auto-updated-buffer gdb-stack-buffer
1650 gdb-invalidate-frames
1652 gdb-info-frames-handler
1653 gdb-info-frames-custom)
1655 (defun gdb-info-frames-custom ()
1656 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1658 (let ((buffer-read-only nil)
1660 (goto-char (point-min))
1661 (while (< (point) (point-max))
1662 (setq bl (line-beginning-position)
1663 el (line-end-position))
1664 (unless (looking-at "No ")
1665 (add-text-properties bl el
1666 '(mouse-face highlight
1667 help-echo "mouse-2, RET: Select frame")))
1669 (when (looking-at "^#\\([0-9]+\\)")
1670 (when (string-equal (match-string 1) gdb-frame-number)
1671 (put-text-property bl (+ bl 4)
1672 'face '(:inverse-video t)))
1673 (when (re-search-forward
1675 (if (string-equal (match-string 1) "0") "" " in ")
1676 "\\([^ ]+\\) (") el t)
1677 (put-text-property (match-beginning 1) (match-end 1)
1678 'face font-lock-function-name-face)
1679 (setq bl (match-end 0))
1680 (while (re-search-forward "<\\([^>]+\\)>" el t)
1681 (put-text-property (match-beginning 1) (match-end 1)
1682 'face font-lock-function-name-face))
1684 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1685 (put-text-property (match-beginning 1) (match-end 1)
1686 'face font-lock-variable-name-face))))
1687 (forward-line 1))))))
1689 (defun gdb-stack-buffer-name ()
1690 (with-current-buffer gud-comint-buffer
1691 (concat "*stack frames of " (gdb-get-target-string) "*")))
1693 (defun gdb-display-stack-buffer ()
1694 "Display backtrace of current stack."
1697 (gdb-get-create-buffer 'gdb-stack-buffer)))
1699 (defun gdb-frame-stack-buffer ()
1700 "Display backtrace of current stack in a new frame."
1702 (let ((special-display-regexps (append special-display-regexps '(".*")))
1703 (special-display-frame-alist gdb-frame-parameters))
1704 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1706 (defvar gdb-frames-mode-map
1707 (let ((map (make-sparse-keymap)))
1708 (suppress-keymap map)
1709 (define-key map "q" 'kill-this-buffer)
1710 (define-key map "\r" 'gdb-frames-select)
1711 (define-key map [mouse-2] 'gdb-frames-select)
1712 (define-key map [follow-link] 'mouse-face)
1715 (defun gdb-frames-mode ()
1716 "Major mode for gdb frames.
1718 \\{gdb-frames-mode-map}"
1719 (kill-all-local-variables)
1720 (setq major-mode 'gdb-frames-mode)
1721 (setq mode-name "Frames")
1722 (setq buffer-read-only t)
1723 (use-local-map gdb-frames-mode-map)
1725 (run-mode-hooks 'gdb-frames-mode-hook)
1726 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1727 'gdb-invalidate-frames
1728 'gdbmi-invalidate-frames))
1730 (defun gdb-get-frame-number ()
1733 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1734 (n (or (and pos (match-string-no-properties 1)) "0")))
1737 (defun gdb-frames-select (&optional event)
1738 "Select the frame and display the relevant source."
1739 (interactive (list last-input-event))
1740 (if event (mouse-set-point event))
1742 (list (concat gdb-server-prefix "frame "
1743 (gdb-get-frame-number) "\n") 'ignore))
1744 (gud-display-frame))
1747 ;; Threads buffer. This displays a selectable thread list.
1749 (gdb-set-buffer-rules 'gdb-threads-buffer
1750 'gdb-threads-buffer-name
1753 (def-gdb-auto-updated-buffer gdb-threads-buffer
1754 gdb-invalidate-threads
1755 (concat gdb-server-prefix "info threads\n")
1756 gdb-info-threads-handler
1757 gdb-info-threads-custom)
1759 (defun gdb-info-threads-custom ()
1760 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1761 (let ((buffer-read-only nil))
1762 (goto-char (point-min))
1763 (while (< (point) (point-max))
1764 (unless (looking-at "No ")
1765 (add-text-properties (line-beginning-position) (line-end-position)
1766 '(mouse-face highlight
1767 help-echo "mouse-2, RET: select thread")))
1768 (forward-line 1)))))
1770 (defun gdb-threads-buffer-name ()
1771 (with-current-buffer gud-comint-buffer
1772 (concat "*threads of " (gdb-get-target-string) "*")))
1774 (defun gdb-display-threads-buffer ()
1775 "Display IDs of currently known threads."
1778 (gdb-get-create-buffer 'gdb-threads-buffer)))
1780 (defun gdb-frame-threads-buffer ()
1781 "Display IDs of currently known threads in a new frame."
1783 (let ((special-display-regexps (append special-display-regexps '(".*")))
1784 (special-display-frame-alist gdb-frame-parameters))
1785 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1787 (defvar gdb-threads-mode-map
1788 (let ((map (make-sparse-keymap)))
1789 (suppress-keymap map)
1790 (define-key map "q" 'kill-this-buffer)
1791 (define-key map "\r" 'gdb-threads-select)
1792 (define-key map [mouse-2] 'gdb-threads-select)
1795 (defvar gdb-threads-font-lock-keywords
1797 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1798 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1799 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1801 "Font lock keywords used in `gdb-threads-mode'.")
1803 (defun gdb-threads-mode ()
1804 "Major mode for gdb frames.
1806 \\{gdb-threads-mode-map}"
1807 (kill-all-local-variables)
1808 (setq major-mode 'gdb-threads-mode)
1809 (setq mode-name "Threads")
1810 (setq buffer-read-only t)
1811 (use-local-map gdb-threads-mode-map)
1812 (set (make-local-variable 'font-lock-defaults)
1813 '(gdb-threads-font-lock-keywords))
1814 (run-mode-hooks 'gdb-threads-mode-hook)
1815 'gdb-invalidate-threads)
1817 (defun gdb-get-thread-number ()
1819 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1820 (match-string-no-properties 1)))
1822 (defun gdb-threads-select (&optional event)
1823 "Select the thread and display the relevant source."
1824 (interactive (list last-input-event))
1825 (if event (mouse-set-point event))
1827 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1828 (gud-display-frame))
1831 ;; Registers buffer.
1833 (defcustom gdb-all-registers nil
1834 "Non-nil means include floating-point registers."
1839 (gdb-set-buffer-rules 'gdb-registers-buffer
1840 'gdb-registers-buffer-name
1841 'gdb-registers-mode)
1843 (def-gdb-auto-updated-buffer gdb-registers-buffer
1844 gdb-invalidate-registers
1846 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1847 gdb-info-registers-handler
1848 gdb-info-registers-custom)
1850 (defun gdb-info-registers-custom ()
1851 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1853 (let ((buffer-read-only nil)
1855 (goto-char (point-min))
1856 (while (< (point) (point-max))
1857 (setq bl (line-beginning-position))
1858 (when (looking-at "^[^ ]+")
1859 (unless (string-equal (match-string 0) "The")
1860 (put-text-property bl (match-end 0)
1861 'face font-lock-variable-name-face)))
1862 (forward-line 1))))))
1864 (defvar gdb-registers-mode-map
1865 (let ((map (make-sparse-keymap)))
1866 (suppress-keymap map)
1867 (define-key map " " 'toggle-gdb-all-registers)
1868 (define-key map "q" 'kill-this-buffer)
1871 (defun gdb-registers-mode ()
1872 "Major mode for gdb registers.
1874 \\{gdb-registers-mode-map}"
1875 (kill-all-local-variables)
1876 (setq major-mode 'gdb-registers-mode)
1877 (setq mode-name "Registers:")
1878 (setq buffer-read-only t)
1879 (use-local-map gdb-registers-mode-map)
1880 (run-mode-hooks 'gdb-registers-mode-hook)
1881 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1882 'gdb-invalidate-registers
1883 'gdbmi-invalidate-registers))
1885 (defun gdb-registers-buffer-name ()
1886 (with-current-buffer gud-comint-buffer
1887 (concat "*registers of " (gdb-get-target-string) "*")))
1889 (defun gdb-display-registers-buffer ()
1890 "Display integer register contents."
1893 (gdb-get-create-buffer 'gdb-registers-buffer)))
1895 (defun gdb-frame-registers-buffer ()
1896 "Display integer register contents in a new frame."
1898 (let ((special-display-regexps (append special-display-regexps '(".*")))
1899 (special-display-frame-alist gdb-frame-parameters))
1900 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1902 (defun toggle-gdb-all-registers ()
1903 "Toggle the display of floating-point registers."
1905 (if gdb-all-registers
1907 (setq gdb-all-registers nil)
1908 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1909 (setq mode-name "Registers:")))
1910 (setq gdb-all-registers t)
1911 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1912 (setq mode-name "Registers:All")))
1913 (gdb-invalidate-registers))
1918 (defcustom gdb-memory-repeat-count 32
1919 "Number of data items in memory window."
1924 (defcustom gdb-memory-format "x"
1925 "Display format of data items in memory window."
1926 :type '(choice (const :tag "Hexadecimal" "x")
1927 (const :tag "Signed decimal" "d")
1928 (const :tag "Unsigned decimal" "u")
1929 (const :tag "Octal" "o")
1930 (const :tag "Binary" "t"))
1934 (defcustom gdb-memory-unit "w"
1935 "Unit size of data items in memory window."
1936 :type '(choice (const :tag "Byte" "b")
1937 (const :tag "Halfword" "h")
1938 (const :tag "Word" "w")
1939 (const :tag "Giant word" "g"))
1943 (gdb-set-buffer-rules 'gdb-memory-buffer
1944 'gdb-memory-buffer-name
1947 (def-gdb-auto-updated-buffer gdb-memory-buffer
1948 gdb-invalidate-memory
1949 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1950 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1951 gdb-read-memory-handler
1952 gdb-read-memory-custom)
1954 (defun gdb-read-memory-custom ()
1956 (goto-char (point-min))
1957 (if (looking-at "0x[[:xdigit:]]+")
1958 (setq gdb-memory-address (match-string 0)))))
1960 (defvar gdb-memory-mode-map
1961 (let ((map (make-sparse-keymap)))
1962 (suppress-keymap map)
1963 (define-key map "q" 'kill-this-buffer)
1966 (defun gdb-memory-set-address (event)
1967 "Set the start memory address."
1969 (save-selected-window
1970 (select-window (posn-window (event-start event)))
1971 (let ((arg (read-from-minibuffer "Memory address: ")))
1972 (setq gdb-memory-address arg))
1973 (gdb-invalidate-memory)))
1975 (defun gdb-memory-set-repeat-count (event)
1976 "Set the number of data items in memory window."
1978 (save-selected-window
1979 (select-window (posn-window (event-start event)))
1980 (let* ((arg (read-from-minibuffer "Repeat count: "))
1981 (count (string-to-number arg)))
1983 (error "Positive numbers only")
1984 (customize-set-variable 'gdb-memory-repeat-count count)
1985 (gdb-invalidate-memory)))))
1987 (defun gdb-memory-format-binary ()
1988 "Set the display format to binary."
1990 (customize-set-variable 'gdb-memory-format "t")
1991 (gdb-invalidate-memory))
1993 (defun gdb-memory-format-octal ()
1994 "Set the display format to octal."
1996 (customize-set-variable 'gdb-memory-format "o")
1997 (gdb-invalidate-memory))
1999 (defun gdb-memory-format-unsigned ()
2000 "Set the display format to unsigned decimal."
2002 (customize-set-variable 'gdb-memory-format "u")
2003 (gdb-invalidate-memory))
2005 (defun gdb-memory-format-signed ()
2006 "Set the display format to decimal."
2008 (customize-set-variable 'gdb-memory-format "d")
2009 (gdb-invalidate-memory))
2011 (defun gdb-memory-format-hexadecimal ()
2012 "Set the display format to hexadecimal."
2014 (customize-set-variable 'gdb-memory-format "x")
2015 (gdb-invalidate-memory))
2017 (defvar gdb-memory-format-keymap
2018 (let ((map (make-sparse-keymap)))
2019 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2021 "Keymap to select format in the header line.")
2023 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2024 "Menu of display formats in the header line.")
2026 (define-key gdb-memory-format-menu [binary]
2027 '(menu-item "Binary" gdb-memory-format-binary
2028 :button (:radio . (equal gdb-memory-format "t"))))
2029 (define-key gdb-memory-format-menu [octal]
2030 '(menu-item "Octal" gdb-memory-format-octal
2031 :button (:radio . (equal gdb-memory-format "o"))))
2032 (define-key gdb-memory-format-menu [unsigned]
2033 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2034 :button (:radio . (equal gdb-memory-format "u"))))
2035 (define-key gdb-memory-format-menu [signed]
2036 '(menu-item "Signed Decimal" gdb-memory-format-signed
2037 :button (:radio . (equal gdb-memory-format "d"))))
2038 (define-key gdb-memory-format-menu [hexadecimal]
2039 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2040 :button (:radio . (equal gdb-memory-format "x"))))
2042 (defun gdb-memory-format-menu (event)
2044 (x-popup-menu event gdb-memory-format-menu))
2046 (defun gdb-memory-format-menu-1 (event)
2048 (save-selected-window
2049 (select-window (posn-window (event-start event)))
2050 (let* ((selection (gdb-memory-format-menu event))
2051 (binding (and selection (lookup-key gdb-memory-format-menu
2052 (vector (car selection))))))
2053 (if binding (call-interactively binding)))))
2055 (defun gdb-memory-unit-giant ()
2056 "Set the unit size to giant words (eight bytes)."
2058 (customize-set-variable 'gdb-memory-unit "g")
2059 (gdb-invalidate-memory))
2061 (defun gdb-memory-unit-word ()
2062 "Set the unit size to words (four bytes)."
2064 (customize-set-variable 'gdb-memory-unit "w")
2065 (gdb-invalidate-memory))
2067 (defun gdb-memory-unit-halfword ()
2068 "Set the unit size to halfwords (two bytes)."
2070 (customize-set-variable 'gdb-memory-unit "h")
2071 (gdb-invalidate-memory))
2073 (defun gdb-memory-unit-byte ()
2074 "Set the unit size to bytes."
2076 (customize-set-variable 'gdb-memory-unit "b")
2077 (gdb-invalidate-memory))
2079 (defvar gdb-memory-unit-keymap
2080 (let ((map (make-sparse-keymap)))
2081 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2083 "Keymap to select units in the header line.")
2085 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2086 "Menu of units in the header line.")
2088 (define-key gdb-memory-unit-menu [giantwords]
2089 '(menu-item "Giant words" gdb-memory-unit-giant
2090 :button (:radio . (equal gdb-memory-unit "g"))))
2091 (define-key gdb-memory-unit-menu [words]
2092 '(menu-item "Words" gdb-memory-unit-word
2093 :button (:radio . (equal gdb-memory-unit "w"))))
2094 (define-key gdb-memory-unit-menu [halfwords]
2095 '(menu-item "Halfwords" gdb-memory-unit-halfword
2096 :button (:radio . (equal gdb-memory-unit "h"))))
2097 (define-key gdb-memory-unit-menu [bytes]
2098 '(menu-item "Bytes" gdb-memory-unit-byte
2099 :button (:radio . (equal gdb-memory-unit "b"))))
2101 (defun gdb-memory-unit-menu (event)
2103 (x-popup-menu event gdb-memory-unit-menu))
2105 (defun gdb-memory-unit-menu-1 (event)
2107 (save-selected-window
2108 (select-window (posn-window (event-start event)))
2109 (let* ((selection (gdb-memory-unit-menu event))
2110 (binding (and selection (lookup-key gdb-memory-unit-menu
2111 (vector (car selection))))))
2112 (if binding (call-interactively binding)))))
2114 ;;from make-mode-line-mouse-map
2115 (defun gdb-make-header-line-mouse-map (mouse function) "\
2116 Return a keymap with single entry for mouse key MOUSE on the header line.
2117 MOUSE is defined to run function FUNCTION with no args in the buffer
2118 corresponding to the mode line clicked."
2119 (let ((map (make-sparse-keymap)))
2120 (define-key map (vector 'header-line mouse) function)
2121 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2124 (defvar gdb-memory-font-lock-keywords
2125 '(;; <__function.name+n>
2126 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2128 "Font lock keywords used in `gdb-memory-mode'.")
2130 (defun gdb-memory-mode ()
2131 "Major mode for examining memory.
2133 \\{gdb-memory-mode-map}"
2134 (kill-all-local-variables)
2135 (setq major-mode 'gdb-memory-mode)
2136 (setq mode-name "Memory")
2137 (setq buffer-read-only t)
2138 (use-local-map gdb-memory-mode-map)
2139 (setq header-line-format
2145 'face font-lock-warning-face
2146 'help-echo "mouse-1: Decrement address"
2147 'mouse-face 'mode-line-highlight
2149 (gdb-make-header-line-mouse-map
2151 #'(lambda () (interactive)
2152 (let ((gdb-memory-address
2153 ;; Let GDB do the arithmetic.
2155 gdb-memory-address " - "
2157 (* gdb-memory-repeat-count
2158 (cond ((string= gdb-memory-unit "b") 1)
2159 ((string= gdb-memory-unit "h") 2)
2160 ((string= gdb-memory-unit "w") 4)
2161 ((string= gdb-memory-unit "g") 8)))))))
2162 (gdb-invalidate-memory)))))
2165 'face font-lock-warning-face
2166 'help-echo "mouse-1: Increment address"
2167 'mouse-face 'mode-line-highlight
2168 'local-map (gdb-make-header-line-mouse-map
2170 #'(lambda () (interactive)
2171 (let ((gdb-memory-address nil))
2172 (gdb-invalidate-memory)))))
2174 (propertize gdb-memory-address
2175 'face font-lock-warning-face
2176 'help-echo "mouse-1: Set memory address"
2177 'mouse-face 'mode-line-highlight
2178 'local-map (gdb-make-header-line-mouse-map
2180 #'gdb-memory-set-address))
2182 (propertize (number-to-string gdb-memory-repeat-count)
2183 'face font-lock-warning-face
2184 'help-echo "mouse-1: Set repeat count"
2185 'mouse-face 'mode-line-highlight
2186 'local-map (gdb-make-header-line-mouse-map
2188 #'gdb-memory-set-repeat-count))
2190 (propertize gdb-memory-format
2191 'face font-lock-warning-face
2192 'help-echo "mouse-3: Select display format"
2193 'mouse-face 'mode-line-highlight
2194 'local-map gdb-memory-format-keymap)
2196 (propertize gdb-memory-unit
2197 'face font-lock-warning-face
2198 'help-echo "mouse-3: Select unit size"
2199 'mouse-face 'mode-line-highlight
2200 'local-map gdb-memory-unit-keymap))))
2201 (set (make-local-variable 'font-lock-defaults)
2202 '(gdb-memory-font-lock-keywords))
2203 (run-mode-hooks 'gdb-memory-mode-hook)
2204 'gdb-invalidate-memory)
2206 (defun gdb-memory-buffer-name ()
2207 (with-current-buffer gud-comint-buffer
2208 (concat "*memory of " (gdb-get-target-string) "*")))
2210 (defun gdb-display-memory-buffer ()
2211 "Display memory contents."
2214 (gdb-get-create-buffer 'gdb-memory-buffer)))
2216 (defun gdb-frame-memory-buffer ()
2217 "Display memory contents in a new frame."
2219 (let ((special-display-regexps (append special-display-regexps '(".*")))
2220 (special-display-frame-alist gdb-frame-parameters))
2221 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2226 (gdb-set-buffer-rules 'gdb-locals-buffer
2227 'gdb-locals-buffer-name
2230 (def-gdb-auto-update-trigger gdb-invalidate-locals
2231 (gdb-get-buffer 'gdb-locals-buffer)
2232 "server info locals\n"
2233 gdb-info-locals-handler)
2235 (defvar gdb-locals-watch-keymap
2236 (let ((map (make-sparse-keymap)))
2237 (define-key map "\r" '(lambda () (interactive)
2240 (define-key map [mouse-2] '(lambda (event) (interactive "e")
2241 (mouse-set-point event)
2245 "Keymap to create watch expression of a complex data type local variable.")
2247 (defconst gdb-struct-string
2248 (concat (propertize "[struct/union];"
2249 'mouse-face 'highlight
2250 'help-echo "mouse-2: create watch expression"
2251 'local-map gdb-locals-watch-keymap) "\n"))
2253 (defconst gdb-array-string
2254 (concat " " (propertize "[array];"
2255 'mouse-face 'highlight
2256 'help-echo "mouse-2: create watch expression"
2257 'local-map gdb-locals-watch-keymap) "\n"))
2259 ;; Abbreviate for arrays and structures.
2260 ;; These can be expanded using gud-display.
2261 (defun gdb-info-locals-handler ()
2262 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2263 gdb-pending-triggers))
2264 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2265 (with-current-buffer buf
2266 (goto-char (point-min))
2267 (while (re-search-forward "^[ }].*\n" nil t)
2268 (replace-match "" nil nil))
2269 (goto-char (point-min))
2270 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2271 (replace-match gdb-struct-string nil nil))
2272 (goto-char (point-min))
2273 (while (re-search-forward "\\s-*{.*\n" nil t)
2274 (replace-match gdb-array-string nil nil))))
2275 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2277 (with-current-buffer buf
2278 (let* ((window (get-buffer-window buf 0))
2279 (p (window-point window))
2280 (buffer-read-only nil))
2282 (insert-buffer-substring (gdb-get-create-buffer
2283 'gdb-partial-output-buffer))
2284 (set-window-point window p)))))
2285 (run-hooks 'gdb-info-locals-hook))
2287 (defvar gdb-locals-mode-map
2288 (let ((map (make-sparse-keymap)))
2289 (suppress-keymap map)
2290 (define-key map "q" 'kill-this-buffer)
2293 (defvar gdb-locals-font-lock-keywords
2295 ;; var = (struct struct_tag) value
2296 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2297 (1 font-lock-variable-name-face)
2298 (3 font-lock-keyword-face)
2299 (4 font-lock-type-face))
2300 ;; var = (type) value
2301 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2302 (1 font-lock-variable-name-face)
2303 (3 font-lock-type-face))
2305 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2306 (1 font-lock-variable-name-face))
2308 "Font lock keywords used in `gdb-local-mode'.")
2310 (defun gdb-locals-mode ()
2311 "Major mode for gdb locals.
2313 \\{gdb-locals-mode-map}"
2314 (kill-all-local-variables)
2315 (setq major-mode 'gdb-locals-mode)
2316 (setq mode-name (concat "Locals:" gdb-selected-frame))
2317 (setq buffer-read-only t)
2318 (use-local-map gdb-locals-mode-map)
2319 (set (make-local-variable 'font-lock-defaults)
2320 '(gdb-locals-font-lock-keywords))
2321 (run-mode-hooks 'gdb-locals-mode-hook)
2322 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2323 'gdb-invalidate-locals
2324 'gdbmi-invalidate-locals))
2326 (defun gdb-locals-buffer-name ()
2327 (with-current-buffer gud-comint-buffer
2328 (concat "*locals of " (gdb-get-target-string) "*")))
2330 (defun gdb-display-locals-buffer ()
2331 "Display local variables of current stack and their values."
2334 (gdb-get-create-buffer 'gdb-locals-buffer)))
2336 (defun gdb-frame-locals-buffer ()
2337 "Display local variables of current stack and their values in a new frame."
2339 (let ((special-display-regexps (append special-display-regexps '(".*")))
2340 (special-display-frame-alist gdb-frame-parameters))
2341 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2344 ;;;; Window management
2345 (defun gdb-display-buffer (buf &optional size)
2346 (let ((answer (get-buffer-window buf 0))
2349 (display-buffer buf nil 0) ;Raise the frame if necessary.
2350 ;; The buffer is not yet displayed.
2351 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2352 (let ((window (get-lru-window)))
2354 (not (eq window (get-buffer-window gud-comint-buffer))))
2356 (set-window-buffer window buf)
2357 (setq answer window))
2358 (setq must-split t)))
2360 (let* ((largest (get-largest-window))
2361 (cur-size (window-height largest))
2362 (new-size (and size (< size cur-size) (- cur-size size))))
2363 (setq answer (split-window largest new-size))
2364 (set-window-buffer answer buf)
2365 (set-window-dedicated-p answer t)))
2369 ;;; Shared keymap initialization:
2371 (let ((menu (make-sparse-keymap "GDB-Windows")))
2372 (define-key gud-menu-map [displays]
2373 `(menu-item "GDB-Windows" ,menu
2374 :visible (memq gud-minor-mode '(gdbmi gdba))))
2375 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2376 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2377 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2378 (define-key menu [disassembly]
2379 '("Disassembly" . gdb-display-assembler-buffer))
2380 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2381 (define-key menu [inferior]
2382 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2383 :enable gdb-use-inferior-io-buffer))
2384 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2385 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2386 (define-key menu [breakpoints]
2387 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2389 (let ((menu (make-sparse-keymap "GDB-Frames")))
2390 (define-key gud-menu-map [frames]
2391 `(menu-item "GDB-Frames" ,menu
2392 :visible (memq gud-minor-mode '(gdbmi gdba))))
2393 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2394 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2395 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2396 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2397 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2398 (define-key menu [inferior]
2399 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2400 :enable gdb-use-inferior-io-buffer))
2401 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2402 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2403 (define-key menu [breakpoints]
2404 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2406 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2407 (define-key gud-menu-map [ui]
2408 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2409 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2410 (define-key menu [gdb-use-inferior-io]
2411 '(menu-item "Separate inferior IO" gdb-use-inferior-io-buffer
2412 :visible (eq gud-minor-mode 'gdba)
2413 :help "Toggle separate IO for inferior."
2414 :button (:toggle . gdb-use-inferior-io-buffer)))
2415 (define-key menu [gdb-many-windows]
2416 '(menu-item "Display Other Windows" gdb-many-windows
2417 :help "Toggle display of locals, stack and breakpoint information"
2418 :button (:toggle . gdb-many-windows)))
2419 (define-key menu [gdb-restore-windows]
2420 '(menu-item "Restore Window Layout" gdb-restore-windows
2421 :help "Restore standard layout for debug session.")))
2423 (defun gdb-frame-gdb-buffer ()
2424 "Display GUD buffer in a new frame."
2426 (let ((special-display-regexps (append special-display-regexps '(".*")))
2427 (special-display-frame-alist gdb-frame-parameters)
2428 (same-window-regexps nil))
2429 (display-buffer gud-comint-buffer)))
2431 (defun gdb-display-gdb-buffer ()
2432 "Display GUD buffer."
2434 (let ((same-window-regexps nil))
2435 (pop-to-buffer gud-comint-buffer)))
2437 (defun gdb-set-window-buffer (name)
2438 (set-window-buffer (selected-window) (get-buffer name))
2439 (set-window-dedicated-p (selected-window) t))
2441 (defun gdb-setup-windows ()
2442 "Layout the window pattern for `gdb-many-windows'."
2443 (gdb-display-locals-buffer)
2444 (gdb-display-stack-buffer)
2445 (delete-other-windows)
2446 (gdb-display-breakpoints-buffer)
2447 (delete-other-windows)
2449 (pop-to-buffer gud-comint-buffer)
2450 (split-window nil ( / ( * (window-height) 3) 4))
2451 (split-window nil ( / (window-height) 3))
2452 (split-window-horizontally)
2454 (gdb-set-window-buffer (gdb-locals-buffer-name))
2457 (if gud-last-last-frame
2458 (gud-find-file (car gud-last-last-frame))
2459 (gud-find-file gdb-main-file)))
2460 (when gdb-use-inferior-io-buffer
2461 (split-window-horizontally)
2463 (gdb-set-window-buffer
2464 (gdb-get-create-buffer 'gdb-inferior-io)))
2466 (gdb-set-window-buffer (gdb-stack-buffer-name))
2467 (split-window-horizontally)
2469 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2472 (defcustom gdb-many-windows nil
2473 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2474 In this case it starts with two windows: one displaying the GUD
2475 buffer and the other with the source file with the main routine
2476 of the inferior. Non-nil means display the layout shown for
2482 (defun gdb-many-windows (arg)
2483 "Toggle the number of windows in the basic arrangement.
2484 With arg, display additional buffers iff arg is positive."
2486 (setq gdb-many-windows
2488 (not gdb-many-windows)
2489 (> (prefix-numeric-value arg) 0)))
2490 (if (and gud-comint-buffer
2491 (buffer-name gud-comint-buffer))
2493 (gdb-restore-windows)
2496 (defun gdb-restore-windows ()
2497 "Restore the basic arrangement of windows used by gdba.
2498 This arrangement depends on the value of `gdb-many-windows'."
2500 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2501 (delete-other-windows)
2502 (if gdb-many-windows
2504 (when (or gud-last-last-frame gdb-show-main)
2508 (if gud-last-last-frame
2509 (gud-find-file (car gud-last-last-frame))
2510 (gud-find-file gdb-main-file)))
2514 "Exit a debugging session cleanly.
2515 Kills the gdb buffers and resets the source buffers."
2516 (dolist (buffer (buffer-list))
2517 (unless (eq buffer gud-comint-buffer)
2518 (with-current-buffer buffer
2519 (if (memq gud-minor-mode '(gdbmi gdba))
2520 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2522 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2523 (setq gud-minor-mode nil)
2524 (kill-local-variable 'tool-bar-map)
2525 (kill-local-variable 'gdb-define-alist))))))
2526 (when (markerp gdb-overlay-arrow-position)
2527 (move-marker gdb-overlay-arrow-position nil)
2528 (setq gdb-overlay-arrow-position nil))
2529 (setq overlay-arrow-variable-list
2530 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2531 (setq gud-running nil)
2532 (setq gdb-active-process nil)
2533 (setq gdb-var-list nil)
2534 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2536 (defun gdb-source-info ()
2537 "Find the source file where the program starts and displays it with related
2539 (goto-char (point-min))
2540 (if (and (search-forward "Located in " nil t)
2541 (looking-at "\\S-+"))
2542 (setq gdb-main-file (match-string 0)))
2543 (goto-char (point-min))
2544 (if (search-forward "Includes preprocessor macro info." nil t)
2545 (setq gdb-macro-info t))
2546 (if gdb-many-windows
2548 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2550 (let ((pop-up-windows t))
2551 (display-buffer (gud-find-file gdb-main-file))))))
2553 (defun gdb-get-location (bptno line flag)
2554 "Find the directory containing the relevant source file.
2555 Put in buffer and place breakpoint icon."
2556 (goto-char (point-min))
2557 (catch 'file-not-found
2558 (if (search-forward "Located in " nil t)
2559 (when (looking-at "\\S-+")
2560 (delete (cons bptno "File not found") gdb-location-alist)
2561 (push (cons bptno (match-string 0)) gdb-location-alist))
2563 (unless (assoc bptno gdb-location-alist)
2564 (push (cons bptno "File not found") gdb-location-alist)
2565 (message-box "Cannot find source file for breakpoint location.\n\
2566 Add directory to search path for source files using the GDB command, dir."))
2567 (throw 'file-not-found nil))
2568 (with-current-buffer
2569 (find-file-noselect (match-string 0))
2570 (save-current-buffer
2571 (set (make-local-variable 'gud-minor-mode) 'gdba)
2572 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2573 ;; only want one breakpoint icon at each location
2575 (goto-line (string-to-number line))
2576 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2578 (add-hook 'find-file-hook 'gdb-find-file-hook)
2580 (defun gdb-find-file-hook ()
2581 "Set up buffer for debugging if file is part of the source code
2582 of the current session."
2583 (if (and (not gdb-find-file-unhook)
2584 ;; in case gud or gdb-ui is just loaded
2586 (buffer-name gud-comint-buffer)
2587 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2591 (list (concat gdb-server-prefix "list "
2592 (file-name-nondirectory buffer-file-name)
2594 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2595 (error (setq gdb-find-file-unhook t)))))
2598 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2599 "Put string PUTSTRING in front of POS in the current buffer.
2600 PUTSTRING is displayed by putting an overlay into the current buffer with a
2601 `before-string' string that has a `display' property whose value is
2603 (let ((string (make-string 1 ?x))
2604 (buffer (current-buffer)))
2605 (setq putstring (copy-sequence putstring))
2606 (let ((overlay (make-overlay pos pos buffer))
2608 (list (list 'margin 'left-margin) putstring))))
2609 (put-text-property 0 1 'display prop string)
2611 (add-text-properties 0 1 sprops string))
2612 (overlay-put overlay 'put-break t)
2613 (overlay-put overlay 'before-string string))))
2615 ;;from remove-images
2616 (defun gdb-remove-strings (start end &optional buffer)
2617 "Remove strings between START and END in BUFFER.
2618 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2619 BUFFER nil or omitted means use the current buffer."
2621 (setq buffer (current-buffer)))
2622 (dolist (overlay (overlays-in start end))
2623 (when (overlay-get overlay 'put-break)
2624 (delete-overlay overlay))))
2626 (defun gdb-put-breakpoint-icon (enabled bptno)
2627 (let ((start (- (line-beginning-position) 1))
2628 (end (+ (line-end-position) 1))
2629 (putstring (if enabled "B" "b"))
2630 (source-window (get-buffer-window (current-buffer) 0)))
2631 (add-text-properties
2632 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2635 (add-text-properties
2636 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2637 (add-text-properties
2638 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2639 (gdb-remove-breakpoint-icons start end)
2640 (if (display-images-p)
2641 (if (>= (or left-fringe-width
2642 (if source-window (car (window-fringes source-window)))
2643 gdb-buffer-fringe-width) 8)
2646 `(left-fringe breakpoint
2649 'breakpoint-disabled))
2651 'gdb-enabled enabled)
2652 (when (< left-margin-width 2)
2653 (save-current-buffer
2654 (setq left-margin-width 2)
2658 left-margin-width right-margin-width))))
2661 (or breakpoint-enabled-icon
2662 (setq breakpoint-enabled-icon
2663 (find-image `((:type xpm :data
2664 ,breakpoint-xpm-data
2665 :ascent 100 :pointer hand)
2667 ,breakpoint-enabled-pbm-data
2668 :ascent 100 :pointer hand)))))
2669 (or breakpoint-disabled-icon
2670 (setq breakpoint-disabled-icon
2671 (find-image `((:type xpm :data
2672 ,breakpoint-xpm-data
2673 :conversion disabled
2674 :ascent 100 :pointer hand)
2676 ,breakpoint-disabled-pbm-data
2677 :ascent 100 :pointer hand))))))
2681 (when (< left-margin-width 2)
2682 (save-current-buffer
2683 (setq left-margin-width 2)
2684 (let ((window (get-buffer-window (current-buffer) 0)))
2687 window left-margin-width right-margin-width)))))
2689 (propertize putstring
2690 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2693 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2694 (gdb-remove-strings start end)
2695 (if (display-images-p)
2696 (remove-images start end))
2698 (setq left-margin-width 0)
2699 (let ((window (get-buffer-window (current-buffer) 0)))
2702 window left-margin-width right-margin-width)))))
2706 ;; Assembler buffer.
2708 (gdb-set-buffer-rules 'gdb-assembler-buffer
2709 'gdb-assembler-buffer-name
2710 'gdb-assembler-mode)
2712 (def-gdb-auto-update-handler gdb-assembler-handler
2713 gdb-invalidate-assembler
2714 gdb-assembler-buffer
2715 gdb-assembler-custom)
2717 (defun gdb-assembler-custom ()
2718 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2719 (pos 1) (address) (flag) (bptno))
2720 (with-current-buffer buffer
2722 (if (not (equal gdb-frame-address "main"))
2724 (goto-char (point-min))
2725 (if (and gdb-frame-address
2726 (re-search-forward gdb-frame-address nil t))
2730 (or gdb-overlay-arrow-position
2731 (setq gdb-overlay-arrow-position (make-marker)))
2732 (set-marker gdb-overlay-arrow-position
2733 (point) (current-buffer))))))
2734 ;; remove all breakpoint-icons in assembler buffer before updating.
2735 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2736 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2737 (goto-char (point-min))
2738 (while (< (point) (- (point-max) 1))
2740 (if (looking-at "[^\t].*?breakpoint")
2743 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2744 (setq bptno (match-string 1))
2745 (setq flag (char-after (match-beginning 2)))
2746 (setq address (match-string 3))
2747 (with-current-buffer buffer
2749 (goto-char (point-min))
2750 (if (re-search-forward address nil t)
2751 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2752 (if (not (equal gdb-frame-address "main"))
2753 (with-current-buffer buffer
2754 (set-window-point (get-buffer-window buffer 0) pos)))))
2756 (defvar gdb-assembler-mode-map
2757 (let ((map (make-sparse-keymap)))
2758 (suppress-keymap map)
2759 (define-key map "q" 'kill-this-buffer)
2762 (defvar gdb-assembler-font-lock-keywords
2763 '(;; <__function.name+n>
2764 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2765 (1 font-lock-function-name-face))
2766 ;; 0xNNNNNNNN <__function.name+n>: opcode
2767 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2768 (4 font-lock-keyword-face))
2769 ;; %register(at least i386)
2770 ("%\\sw+" . font-lock-variable-name-face)
2771 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2772 (1 font-lock-comment-face)
2773 (2 font-lock-function-name-face))
2774 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2775 "Font lock keywords used in `gdb-assembler-mode'.")
2777 (defun gdb-assembler-mode ()
2778 "Major mode for viewing code assembler.
2780 \\{gdb-assembler-mode-map}"
2781 (kill-all-local-variables)
2782 (setq major-mode 'gdb-assembler-mode)
2783 (setq mode-name (concat "Machine:" gdb-selected-frame))
2784 (setq gdb-overlay-arrow-position nil)
2785 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2786 (setq fringes-outside-margins t)
2787 (setq buffer-read-only t)
2788 (use-local-map gdb-assembler-mode-map)
2789 (gdb-invalidate-assembler)
2790 (set (make-local-variable 'font-lock-defaults)
2791 '(gdb-assembler-font-lock-keywords))
2792 (run-mode-hooks 'gdb-assembler-mode-hook)
2793 'gdb-invalidate-assembler)
2795 (defun gdb-assembler-buffer-name ()
2796 (with-current-buffer gud-comint-buffer
2797 (concat "*disassembly of " (gdb-get-target-string) "*")))
2799 (defun gdb-display-assembler-buffer ()
2800 "Display disassembly view."
2802 (setq gdb-previous-frame nil)
2804 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2806 (defun gdb-frame-assembler-buffer ()
2807 "Display disassembly view in a new frame."
2809 (setq gdb-previous-frame nil)
2810 (let ((special-display-regexps (append special-display-regexps '(".*")))
2811 (special-display-frame-alist gdb-frame-parameters))
2812 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2814 ;; modified because if gdb-frame-address has changed value a new command
2815 ;; must be enqueued to update the buffer with the new output
2816 (defun gdb-invalidate-assembler (&optional ignored)
2817 (if (gdb-get-buffer 'gdb-assembler-buffer)
2819 (unless (and gdb-selected-frame
2820 (string-equal gdb-selected-frame gdb-previous-frame))
2821 (if (or (not (member 'gdb-invalidate-assembler
2822 gdb-pending-triggers))
2823 (not (string-equal gdb-frame-address
2824 gdb-previous-frame-address)))
2826 ;; take previous disassemble command, if any, off the queue
2827 (with-current-buffer gud-comint-buffer
2828 (let ((queue gdb-input-queue))
2829 (dolist (item queue)
2830 (if (equal (cdr item) '(gdb-assembler-handler))
2831 (setq gdb-input-queue
2832 (delete item gdb-input-queue))))))
2835 (concat gdb-server-prefix "disassemble "
2836 (if (member gdb-frame-address '(nil "main")) nil "0x")
2837 gdb-frame-address "\n")
2838 'gdb-assembler-handler))
2839 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2840 (setq gdb-previous-frame-address gdb-frame-address)
2841 (setq gdb-previous-frame gdb-selected-frame)))))))
2843 (defun gdb-get-selected-frame ()
2844 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2847 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2848 (push 'gdb-get-selected-frame
2849 gdb-pending-triggers))))
2851 (defun gdb-frame-handler ()
2852 (setq gdb-pending-triggers
2853 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2854 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2855 (goto-char (point-min))
2856 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2857 (setq gdb-frame-number (match-string 1)))
2858 (goto-char (point-min))
2859 (if (re-search-forward
2860 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2862 (setq gdb-selected-frame (match-string 2))
2863 (if (gdb-get-buffer 'gdb-locals-buffer)
2864 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2865 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2866 (if (gdb-get-buffer 'gdb-assembler-buffer)
2867 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2868 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2869 (setq gdb-frame-address (match-string 1))))
2870 (goto-char (point-min))
2871 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2872 (setq gdb-current-language (match-string 1))))
2873 (gdb-invalidate-assembler))
2877 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2878 ;;; gdb-ui.el ends here