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 2' which need GDB 6.1 onwards.
80 ;; 6) With gud-print and gud-pstar, print the variable name in the GUD
81 ;; buffer instead of the value's history number.
89 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
90 (defvar gdb-previous-frame-address nil)
91 (defvar gdb-memory-address "main")
92 (defvar gdb-previous-frame nil)
93 (defvar gdb-selected-frame nil)
94 (defvar gdb-frame-number nil)
95 (defvar gdb-current-language nil)
96 (defvar gdb-var-list nil "List of variables in watch window.")
97 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
98 (defvar gdb-main-file nil "Source file from which program execution begins.")
99 (defvar gdb-overlay-arrow-position nil)
100 (defvar gdb-server-prefix nil)
101 (defvar gdb-flush-pending-output nil)
102 (defvar gdb-location-alist nil
103 "Alist of breakpoint numbers and full filenames.")
104 (defvar gdb-find-file-unhook nil)
105 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
106 and #define directives otherwise.")
107 (defvar gdb-error "Non-nil when GDB is reporting an error.")
108 (defvar gdb-macro-info nil
109 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
110 (defvar gdb-buffer-fringe-width nil)
112 (defvar gdb-buffer-type nil
113 "One of the symbols bound in `gdb-buffer-rules'.")
114 (make-variable-buffer-local 'gdb-buffer-type)
116 (defvar gdb-input-queue ()
117 "A list of gdb command objects.")
119 (defvar gdb-prompting nil
120 "True when gdb is idle with no pending input.")
122 (defvar gdb-output-sink 'user
123 "The disposition of the output of the current gdb command.
124 Possible values are these symbols:
126 `user' -- gdb output should be copied to the GUD buffer
129 `inferior' -- gdb output should be copied to the inferior-io buffer.
131 `pre-emacs' -- output should be ignored util the post-prompt
132 annotation is received. Then the output-sink
134 `emacs' -- output should be collected in the partial-output-buffer
135 for subsequent processing by a command. This is the
136 disposition of output generated by commands that
137 gdb mode sends to gdb on its own behalf.
138 `post-emacs' -- ignore output until the prompt annotation is
139 received, then go to USER disposition.
141 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
142 \(`user' and `emacs').")
144 (defvar gdb-current-item nil
145 "The most recent command item sent to gdb.")
147 (defvar gdb-pending-triggers '()
148 "A list of trigger functions that have run later than their output
151 ;; end of gdb variables
154 (defun gdba (command-line)
155 "Run gdb on program FILE in buffer *gud-FILE*.
156 The directory containing FILE becomes the initial working directory
157 and source-file directory for your debugger.
159 If `gdb-many-windows' is nil (the default value) then gdb just
160 pops up the GUD buffer unless `gdb-show-main' is t. In this case
161 it starts with two windows: one displaying the GUD buffer and the
162 other with the source file with the main routine of the inferior.
164 If `gdb-many-windows' is t, regardless of the value of
165 `gdb-show-main', the layout below will appear unless
166 `gdb-use-inferior-io-buffer' is nil when the source buffer
167 occupies the full width of the frame. Keybindings are given in
170 Watch expressions appear in the speedbar/slowbar.
172 The following commands help control operation :
174 `gdb-many-windows' - Toggle the number of windows gdb uses.
175 `gdb-restore-windows' - To restore the window layout.
177 See Info node `(emacs)GDB Graphical Interface' for a more
178 detailed description of this mode.
181 +--------------------------------------------------------------+
183 +-------------------------------+------------------------------+
184 | GUD buffer (I/O of GDB) | Locals buffer |
188 +-------------------------------+------------------------------+
189 | Source buffer | I/O buffer (of inferior) |
197 +-------------------------------+------------------------------+
198 | Stack buffer | Breakpoints buffer |
199 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
200 | | RET gdb-goto-breakpoint |
201 | | d gdb-delete-breakpoint |
202 +-------------------------------+------------------------------+"
204 (interactive (list (gud-query-cmdline 'gdba)))
206 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
210 (defvar gdb-debug-log nil)
213 (defcustom gdb-enable-debug-log nil
214 "Non-nil means record the process input and output in `gdb-debug-log'."
219 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
220 "Shell command for generating a list of defined macros in a source file.
221 This list is used to display the #define directive associated
222 with an identifier as a tooltip. It works in a debug session with
223 GDB, when gud-tooltip-mode is t.
225 Set `gdb-cpp-define-alist-flags' for any include paths or
231 (defcustom gdb-cpp-define-alist-flags ""
232 "Preprocessor flags for `gdb-cpp-define-alist-program'."
237 (defcustom gdb-show-main nil
238 "Non-nil means display source file containing the main routine at startup.
239 Also display the main routine in the disassembly buffer if present."
244 (defcustom gdb-use-inferior-io-buffer nil
245 "Non-nil means display output from the inferior in a separate buffer."
250 (defun gdb-use-inferior-io-buffer (arg)
251 "Toggle separate IO for inferior.
252 With arg, use separate IO iff arg is positive."
254 (setq gdb-use-inferior-io-buffer
256 (not gdb-use-inferior-io-buffer)
257 (> (prefix-numeric-value arg) 0)))
258 (if (and gud-comint-buffer
259 (buffer-name gud-comint-buffer))
261 (if gdb-use-inferior-io-buffer
262 (gdb-restore-windows)
263 (kill-buffer (gdb-inferior-io-name)))
266 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
268 (defun gdb-create-define-alist ()
269 "Create an alist of #define directives for GUD tooltips."
270 (let* ((file (buffer-file-name))
272 (with-output-to-string
273 (with-current-buffer standard-output
274 (call-process shell-file-name
275 (if (file-exists-p file) file nil)
276 (list t nil) nil "-c"
277 (concat gdb-cpp-define-alist-program " "
278 gdb-cpp-define-alist-flags)))))
279 (define-list (split-string output "\n" t))
281 (setq gdb-define-alist nil)
282 (dolist (define define-list)
283 (setq name (nth 1 (split-string define "[( ]")))
284 (push (cons name define) gdb-define-alist))))
286 (defun gdb-tooltip-print ()
288 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
289 (let ((string (buffer-string)))
290 ;; remove newline for gud-tooltip-echo-area
291 (substring string 0 (- (length string) 1))))
292 (or gud-tooltip-echo-area tooltip-use-echo-area)))
294 ;; If expr is a macro for a function don't print because of possible dangerous
295 ;; side-effects. Also printing a function within a tooltip generates an
296 ;; unexpected starting annotation (phase error).
297 (defun gdb-tooltip-print-1 (expr)
298 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
299 (goto-char (point-min))
300 (if (search-forward "expands to: " nil t)
301 (unless (looking-at "\\S-+.*(.*).*")
303 (list (concat gdb-server-prefix "print " expr "\n")
304 'gdb-tooltip-print))))))
306 (defun gdb-set-gud-minor-mode (buffer)
307 "Set `gud-minor-mode' from find-file if appropriate."
308 (goto-char (point-min))
309 (unless (search-forward "No source file named " nil t)
312 (list (concat gdb-server-prefix "info source\n")
313 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
314 (error (setq gdb-find-file-unhook t)))))
316 (defun gdb-set-gud-minor-mode-1 (buffer)
317 (goto-char (point-min))
318 (when (and (search-forward "Located in " nil t)
320 (string-equal (buffer-file-name buffer)
322 (with-current-buffer buffer
323 (set (make-local-variable 'gud-minor-mode) 'gdba)
324 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
325 (when gud-tooltip-mode
326 (make-local-variable 'gdb-define-alist)
327 (gdb-create-define-alist)
328 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
330 (defun gdb-set-gud-minor-mode-existing-buffers ()
331 (dolist (buffer (buffer-list))
332 (let ((file (buffer-file-name buffer)))
336 (list (concat gdb-server-prefix "list "
337 (file-name-nondirectory file) ":1\n")
338 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
340 (defun gdb-find-watch-expression ()
341 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
342 (varno (nth 1 var)) (expr))
343 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varno)
344 (dolist (var1 gdb-var-list)
345 (if (string-equal (nth 1 var1) (match-string 1 varno))
346 (setq expr (concat (car var1) "." (match-string 2 varno)))))
350 (setq gdb-debug-log nil)
351 (set (make-local-variable 'gud-minor-mode) 'gdba)
352 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
354 (gud-def gud-break (if (not (string-match "Machine" mode-name))
355 (gud-call "break %f:%l" arg)
359 (gud-call "break *%a" arg)))
360 "\C-b" "Set breakpoint at current line or address.")
362 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
363 (gud-call "clear %f:%l" arg)
367 (gud-call "clear *%a" arg)))
368 "\C-d" "Remove breakpoint at current line or address.")
370 (gud-def gud-until (if (not (string-match "Machine" mode-name))
371 (gud-call "until %f:%l" arg)
375 (gud-call "until *%a" arg)))
376 "\C-u" "Continue to current line or address.")
378 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
379 nil "Start or continue execution.")
381 ;; For debugging Emacs only.
385 "pp1 " (if (eq (buffer-local-value
386 'major-mode (window-buffer)) 'speedbar-mode)
387 (gdb-find-watch-expression) "%e")) arg)
388 nil "Print the emacs s-expression.")
390 (define-key gud-minor-mode-map [left-margin mouse-1]
391 'gdb-mouse-set-clear-breakpoint)
392 (define-key gud-minor-mode-map [left-fringe mouse-1]
393 'gdb-mouse-set-clear-breakpoint)
394 (define-key gud-minor-mode-map [left-fringe mouse-2]
396 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
398 (define-key gud-minor-mode-map [left-margin mouse-3]
399 'gdb-mouse-toggle-breakpoint-margin)
400 (define-key gud-minor-mode-map [left-fringe mouse-3]
401 'gdb-mouse-toggle-breakpoint-fringe)
403 (setq comint-input-sender 'gdb-send)
406 (setq gdb-frame-address (if gdb-show-main "main" nil))
407 (setq gdb-previous-frame-address nil
408 gdb-memory-address "main"
409 gdb-previous-frame nil
410 gdb-selected-frame nil
411 gdb-current-language nil
419 gdb-pending-triggers nil
420 gdb-output-sink 'user
421 gdb-server-prefix "server "
422 gdb-flush-pending-output nil
423 gdb-location-alist nil
424 gdb-find-file-unhook nil
427 gdb-buffer-fringe-width (car (window-fringes)))
429 (setq gdb-buffer-type 'gdba)
431 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
433 (if (eq window-system 'w32)
434 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
435 (gdb-enqueue-input (list "set height 0\n" 'ignore))
436 (gdb-enqueue-input (list "set width 0\n" 'ignore))
437 ;; find source file and compilation directory here
438 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
439 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
440 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
442 (gdb-set-gud-minor-mode-existing-buffers)
443 (run-hooks 'gdba-mode-hook))
445 (defun gdb-mouse-until (event)
446 "Execute source lines by dragging the overlay arrow (fringe) with the mouse."
448 (if gud-overlay-arrow-position
449 (let ((start (event-start event))
450 (end (event-end event))
451 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
452 (if (not (string-match "Machine" mode-name))
453 (if (equal buffer (window-buffer (posn-window end)))
454 (with-current-buffer buffer
455 (when (or (equal start end)
456 (equal (posn-point start)
458 gud-overlay-arrow-position)))
459 (setq line (line-number-at-pos (posn-point end)))
460 (gud-call (concat "until " (number-to-string line))))))
461 (if (equal (marker-buffer gdb-overlay-arrow-position)
462 (window-buffer (posn-window end)))
463 (when (or (equal start end)
464 (equal (posn-point start)
466 gdb-overlay-arrow-position)))
468 (goto-line (line-number-at-pos (posn-point end)))
470 (gud-call (concat "until *%a")))))))))
472 (defcustom gdb-use-colon-colon-notation nil
473 "If non-nil use FUN::VAR format to display variables in the speedbar."
479 "Watch expression at point."
482 (save-selected-window
483 (let ((expr (tooltip-identifier-from-point (point))))
484 (if (and (string-equal gdb-current-language "c")
485 gdb-use-colon-colon-notation gdb-selected-frame)
486 (setq expr (concat gdb-selected-frame "::" expr)))
487 (catch 'already-watched
488 (dolist (var gdb-var-list)
489 (if (string-equal expr (car var)) (throw 'already-watched nil)))
490 (set-text-properties 0 (length expr) nil expr)
493 (if (eq gud-minor-mode 'gdba)
494 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
495 (concat"-var-create - * " expr "\n"))
496 `(lambda () (gdb-var-create-handler ,expr))))))))
498 (defconst gdb-var-create-regexp
499 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
501 (defun gdb-var-create-handler (expr)
502 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
503 (goto-char (point-min))
504 (if (re-search-forward gdb-var-create-regexp nil t)
505 (let ((var (list expr
510 (push var gdb-var-list)
512 (unless (string-equal
513 speedbar-initial-expansion-list-name "GUD")
514 (speedbar-change-initial-expansion-list "GUD"))
515 (if (or (equal (nth 2 var) "0")
516 (and (equal (nth 2 var) "1")
517 (string-match "char \\*" (nth 3 var))))
520 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
522 (concat "server interpreter mi \"-var-evaluate-expression "
524 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
525 `(lambda () (gdb-var-evaluate-expression-handler
527 (setq gdb-var-changed t)))
528 (if (re-search-forward "Undefined command" nil t)
529 (message-box "Watching expressions requires gdb 6.0 onwards")
530 (message "No symbol \"%s\" in current context." expr)))))
532 (defun gdb-var-evaluate-expression-handler (varnum changed)
533 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
534 (goto-char (point-min))
535 (re-search-forward ".*value=\\(\".*\"\\)" nil t)
538 (dolist (var gdb-var-list)
539 (if (string-equal varnum (cadr var))
541 (if changed (setcar (nthcdr 5 var) t))
542 (setcar (nthcdr 4 var) (read (match-string 1)))
543 (setcar (nthcdr num gdb-var-list) var)
544 (throw 'var-found nil)))
545 (setq num (+ num 1))))))
546 (setq gdb-var-changed t))
548 (defun gdb-var-list-children (varnum)
550 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
551 `(lambda () (gdb-var-list-children-handler ,varnum)))))
553 (defconst gdb-var-list-children-regexp
554 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",\
557 (defun gdb-var-list-children-handler (varnum)
558 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
559 (goto-char (point-min))
560 (let ((var-list nil))
561 (catch 'child-already-watched
562 (dolist (var gdb-var-list)
563 (if (string-equal varnum (cadr var))
566 (while (re-search-forward gdb-var-list-children-regexp nil t)
567 (let ((varchild (list (match-string 2)
572 (dolist (var1 gdb-var-list)
573 (if (string-equal (cadr var1) (cadr varchild))
574 (throw 'child-already-watched nil)))
575 (push varchild var-list)
576 (if (or (equal (nth 2 varchild) "0")
577 (and (equal (nth 2 varchild) "1")
578 (string-match "char \\*" (nth 3 varchild))))
582 "server interpreter mi \"-var-evaluate-expression "
583 (nth 1 varchild) "\"\n")
584 `(lambda () (gdb-var-evaluate-expression-handler
585 ,(nth 1 varchild) nil))))))))
586 (push var var-list)))
587 (setq gdb-var-list (nreverse var-list))))))
589 (defun gdb-var-update ()
590 (when (not (member 'gdb-var-update gdb-pending-triggers))
592 (list "server interpreter mi \"-var-update *\"\n"
593 'gdb-var-update-handler))
594 (push 'gdb-var-update gdb-pending-triggers)))
596 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
598 (defun gdb-var-update-handler ()
599 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
600 (goto-char (point-min))
601 (while (re-search-forward gdb-var-update-regexp nil t)
603 (let ((varnum (match-string 1)))
604 (dolist (var gdb-var-list)
605 (when (and (string-equal varnum (cadr var))
606 (or (equal (nth 2 var) "0")
607 (and (equal (nth 2 var) "1")
608 (string-match "char \\*" (nth 3 var)))))
611 (concat "server interpreter mi \"-var-evaluate-expression "
613 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t))))
614 (throw 'var-found-1 nil)))))))
615 (setq gdb-pending-triggers
616 (delq 'gdb-var-update gdb-pending-triggers))
617 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
618 ;; Dummy command to update speedbar at right time.
619 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
620 ;; Keep gdb-pending-triggers non-nil till end.
621 (push 'gdb-speedbar-timer gdb-pending-triggers)))
623 (defun gdb-speedbar-timer-fn ()
624 (setq gdb-pending-triggers
625 (delq 'gdb-speedbar-timer gdb-pending-triggers))
626 (with-current-buffer gud-comint-buffer
627 (speedbar-timer-fn)))
629 (defun gdb-var-delete ()
630 "Delete watch expression at point from the speedbar."
632 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
634 (let ((text (speedbar-line-text)))
635 (string-match "\\(\\S-+\\)" text)
636 (let* ((expr (match-string 1 text))
637 (var (assoc expr gdb-var-list))
639 (unless (string-match "\\." varnum)
642 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
644 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
645 (concat "-var-delete " varnum "\n"))
647 (setq gdb-var-list (delq var gdb-var-list))
648 (dolist (varchild gdb-var-list)
649 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
650 (setq gdb-var-list (delq varchild gdb-var-list))))
651 (setq gdb-var-changed t))))))
653 (defun gdb-edit-value (text token indent)
654 "Assign a value to a variable displayed in the speedbar."
655 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
656 (varnum (cadr var)) (value))
657 (setq value (read-string "New value: "))
660 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
661 (concat "server interpreter mi \"-var-assign "
662 varnum " " value "\"\n")
663 (concat "-var-assign " varnum " " value "\n"))
666 (defcustom gdb-show-changed-values t
667 "If non-nil highlight values that have recently changed in the speedbar.
668 The highlighting is done with `font-lock-warning-face'."
673 (defun gdb-speedbar-expand-node (text token indent)
674 "Expand the node the user clicked on.
675 TEXT is the text of the button we clicked on, a + or - item.
676 TOKEN is data related to this node.
677 INDENT is the current indentation depth."
678 (cond ((string-match "+" text) ;expand this node
679 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
680 (gdb-var-list-children token)
683 (gdbmi-var-list-children token))))
684 ((string-match "-" text) ;contract this node
685 (dolist (var gdb-var-list)
686 (if (string-match (concat token "\\.") (nth 1 var))
687 (setq gdb-var-list (delq var gdb-var-list))))
688 (setq gdb-var-changed t)
689 (with-current-buffer gud-comint-buffer
690 (speedbar-timer-fn)))))
692 (defun gdb-get-target-string ()
693 (with-current-buffer gud-comint-buffer
700 ;; Each buffer has a TYPE -- a symbol that identifies the function
701 ;; of that particular buffer.
703 ;; The usual gdb interaction buffer is given the type `gdba' and
704 ;; is constructed specially.
706 ;; Others are constructed by gdb-get-create-buffer and
707 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
709 (defvar gdb-buffer-rules-assoc '())
711 (defun gdb-get-buffer (key)
712 "Return the gdb buffer tagged with type KEY.
713 The key should be one of the cars in `gdb-buffer-rules-assoc'."
715 (gdb-look-for-tagged-buffer key (buffer-list))))
717 (defun gdb-get-create-buffer (key)
718 "Create a new gdb buffer of the type specified by KEY.
719 The key should be one of the cars in `gdb-buffer-rules-assoc'."
720 (or (gdb-get-buffer key)
721 (let* ((rules (assoc key gdb-buffer-rules-assoc))
722 (name (funcall (gdb-rules-name-maker rules)))
723 (new (get-buffer-create name)))
724 (with-current-buffer new
726 (if (cdr (cdr rules))
727 (setq trigger (funcall (car (cdr (cdr rules))))))
728 (setq gdb-buffer-type key)
729 (set (make-local-variable 'gud-minor-mode)
730 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
731 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
732 (if trigger (funcall trigger)))
735 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
737 (defun gdb-look-for-tagged-buffer (key bufs)
739 (while (and (not retval) bufs)
740 (set-buffer (car bufs))
741 (if (eq gdb-buffer-type key)
742 (setq retval (car bufs)))
743 (setq bufs (cdr bufs)))
747 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
748 ;; at least one and possible more functions. The functions have these
749 ;; roles in defining a buffer type:
751 ;; NAME - Return a name for this buffer type.
753 ;; The remaining function(s) are optional:
755 ;; MODE - called in a new buffer with no arguments, should establish
756 ;; the proper mode for the buffer.
759 (defun gdb-set-buffer-rules (buffer-type &rest rules)
760 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
762 (setcdr binding rules)
763 (push (cons buffer-type rules)
764 gdb-buffer-rules-assoc))))
766 ;; GUD buffers are an exception to the rules
767 (gdb-set-buffer-rules 'gdba 'error)
770 ;; Partial-output buffer : This accumulates output from a command executed on
771 ;; behalf of emacs (rather than the user).
773 (gdb-set-buffer-rules 'gdb-partial-output-buffer
774 'gdb-partial-output-name)
776 (defun gdb-partial-output-name ()
777 (concat "*partial-output-"
778 (gdb-get-target-string)
782 (gdb-set-buffer-rules 'gdb-inferior-io
783 'gdb-inferior-io-name
784 'gdb-inferior-io-mode)
786 (defun gdb-inferior-io-name ()
787 (concat "*input/output of "
788 (gdb-get-target-string)
791 (defun gdb-display-inferior-io-buffer ()
792 "Display IO of inferior in a separate window."
794 (if gdb-use-inferior-io-buffer
796 (gdb-get-create-buffer 'gdb-inferior-io))))
798 (defconst gdb-frame-parameters
799 '((height . 14) (width . 80)
801 (tool-bar-lines . nil)
802 (menu-bar-lines . nil)
805 (defun gdb-frame-inferior-io-buffer ()
806 "Display IO of inferior in a new frame."
808 (if gdb-use-inferior-io-buffer
809 (let ((special-display-regexps (append special-display-regexps '(".*")))
810 (special-display-frame-alist gdb-frame-parameters))
811 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
813 (defvar gdb-inferior-io-mode-map
814 (let ((map (make-sparse-keymap)))
815 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
816 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
817 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
818 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
819 (define-key map "\C-d" 'gdb-inferior-io-eof)
822 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
823 "Major mode for gdb inferior-io."
824 :syntax-table nil :abbrev-table nil
825 ;; We want to use comint because it has various nifty and familiar
826 ;; features. We don't need a process, but comint wants one, so create
828 (make-comint-in-buffer
829 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
830 (current-buffer) "hexl")
831 (setq comint-input-sender 'gdb-inferior-io-sender))
833 (defun gdb-inferior-io-sender (proc string)
834 ;; PROC is the pseudo-process created to satisfy comint.
835 (with-current-buffer (process-buffer proc)
836 (setq proc (get-buffer-process gud-comint-buffer))
837 (process-send-string proc string)
838 (process-send-string proc "\n")))
840 (defun gdb-inferior-io-interrupt ()
841 "Interrupt the program being debugged."
844 (get-buffer-process gud-comint-buffer) comint-ptyp))
846 (defun gdb-inferior-io-quit ()
847 "Send quit signal to the program being debugged."
850 (get-buffer-process gud-comint-buffer) comint-ptyp))
852 (defun gdb-inferior-io-stop ()
853 "Stop the program being debugged."
856 (get-buffer-process gud-comint-buffer) comint-ptyp))
858 (defun gdb-inferior-io-eof ()
859 "Send end-of-file to the program being debugged."
862 (get-buffer-process gud-comint-buffer)))
866 ;; gdb communications
869 ;; INPUT: things sent to gdb
871 ;; The queues are lists. Each element is either a string (indicating user or
872 ;; user-like input) or a list of the form:
874 ;; (INPUT-STRING HANDLER-FN)
876 ;; The handler function will be called from the partial-output buffer when the
877 ;; command completes. This is the way to write commands which invoke gdb
878 ;; commands autonomously.
880 ;; These lists are consumed tail first.
883 (defun gdb-send (proc string)
884 "A comint send filter for gdb.
885 This filter may simply queue input for a later time."
886 (with-current-buffer gud-comint-buffer
887 (let ((inhibit-read-only t))
888 (remove-text-properties (point-min) (point-max) '(face))))
889 (let ((item (concat string "\n")))
892 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
893 (process-send-string proc item))
894 (gdb-enqueue-input item))))
896 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
897 ;; is a query, or other non-top-level prompt.
899 (defun gdb-enqueue-input (item)
903 (setq gdb-prompting nil))
904 (push item gdb-input-queue)))
906 (defun gdb-dequeue-input ()
907 (let ((queue gdb-input-queue))
909 (let ((last (car (last queue))))
910 (unless (nbutlast queue) (setq gdb-input-queue '()))
913 (defun gdb-send-item (item)
914 (setq gdb-flush-pending-output nil)
915 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
916 (setq gdb-current-item item)
917 (let ((process (get-buffer-process gud-comint-buffer)))
918 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
921 (setq gdb-output-sink 'user)
922 (process-send-string process item))
924 (gdb-clear-partial-output)
925 (setq gdb-output-sink 'pre-emacs)
926 (process-send-string process
928 ;; case: eq gud-minor-mode 'gdbmi
929 (gdb-clear-partial-output)
930 (setq gdb-output-sink 'emacs)
931 (process-send-string process (car item)))))
934 ;; output -- things gdb prints to emacs
936 ;; GDB output is a stream interrupted by annotations.
937 ;; Annotations can be recognized by their beginning
938 ;; with \C-j\C-z\C-z<tag><opt>\C-j
940 ;; The tag is a string obeying symbol syntax.
942 ;; The optional part `<opt>' can be either the empty string
943 ;; or a space followed by more data relating to the annotation.
944 ;; For example, the SOURCE annotation is followed by a filename,
945 ;; line number and various useless goo. This data must not include
949 (defcustom gud-gdba-command-name "gdb -annotate=3"
950 "Default command to execute an executable under the GDB-UI debugger."
955 (defvar gdb-annotation-rules
956 '(("pre-prompt" gdb-pre-prompt)
957 ("prompt" gdb-prompt)
958 ("commands" gdb-subprompt)
959 ("overload-choice" gdb-subprompt)
960 ("query" gdb-subprompt)
961 ;; Need this prompt for GDB 6.1
962 ("nquery" gdb-subprompt)
963 ("prompt-for-continue" gdb-subprompt)
964 ("post-prompt" gdb-post-prompt)
965 ("source" gdb-source)
966 ("starting" gdb-starting)
967 ("exited" gdb-exited)
968 ("signalled" gdb-exited)
969 ("signal" gdb-stopping)
970 ("breakpoint" gdb-stopping)
971 ("watchpoint" gdb-stopping)
972 ("frame-begin" gdb-frame-begin)
973 ("stopped" gdb-stopped)
974 ("error-begin" gdb-error)
976 ) "An assoc mapping annotation tags to functions which process them.")
979 (setq gdb-flush-pending-output t)
980 (setq gud-running nil)
981 (setq gdb-output-sink 'user)
982 (setq gdb-input-queue nil)
983 (setq gdb-pending-triggers nil)
984 (setq gdb-prompting t))
986 (defconst gdb-source-spec-regexp
987 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
989 ;; Do not use this except as an annotation handler.
990 (defun gdb-source (args)
991 (string-match gdb-source-spec-regexp args)
992 ;; Extract the frame position from the marker.
995 (match-string 1 args)
996 (string-to-number (match-string 2 args))))
997 (setq gdb-frame-address (match-string 3 args))
998 ;; cover for auto-display output which comes *before*
999 ;; stopped annotation
1000 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1002 (defun gdb-pre-prompt (ignored)
1003 "An annotation handler for `pre-prompt'.
1004 This terminates the collection of output from a previous command if that
1005 happens to be in effect."
1006 (let ((sink gdb-output-sink))
1010 (setq gdb-output-sink 'post-emacs))
1013 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1015 (defun gdb-prompt (ignored)
1016 "An annotation handler for `prompt'.
1017 This sends the next command (if any) to gdb."
1018 (when gdb-first-prompt (gdb-ann3))
1019 (let ((sink gdb-output-sink))
1022 ((eq sink 'post-emacs)
1023 (setq gdb-output-sink 'user)
1025 (car (cdr gdb-current-item))))
1026 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1027 (funcall handler))))
1030 (error "Phase error in gdb-prompt (got %s)" sink))))
1031 (let ((input (gdb-dequeue-input)))
1033 (gdb-send-item input)
1035 (setq gdb-prompting t)
1036 (gud-display-frame)))))
1038 (defun gdb-subprompt (ignored)
1039 "An annotation handler for non-top-level prompts."
1040 (setq gdb-prompting t))
1042 (defun gdb-starting (ignored)
1043 "An annotation handler for `starting'.
1044 This says that I/O for the subprocess is now the program being debugged,
1046 (setq gdb-active-process t)
1047 (let ((sink gdb-output-sink))
1051 (setq gud-running t)
1052 (if gdb-use-inferior-io-buffer
1053 (setq gdb-output-sink 'inferior))))
1056 (error "Unexpected `starting' annotation")))))
1058 (defun gdb-stopping (ignored)
1059 "An annotation handler for `breakpoint' and other annotations.
1060 They say that I/O for the subprocess is now GDB, not the program
1062 (if gdb-use-inferior-io-buffer
1063 (let ((sink gdb-output-sink))
1065 ((eq sink 'inferior)
1066 (setq gdb-output-sink 'user))
1069 (error "Unexpected stopping annotation"))))))
1071 (defun gdb-exited (ignored)
1072 "An annotation handler for `exited' and `signalled'.
1073 They say that I/O for the subprocess is now GDB, not the program
1074 being debugged and that the program is no longer running. This
1075 function is used to change the focus of GUD tooltips to #define
1077 (setq gdb-active-process nil)
1078 (setq gud-overlay-arrow-position nil)
1079 (setq gdb-overlay-arrow-position nil)
1080 (gdb-stopping ignored))
1082 (defun gdb-frame-begin (ignored)
1083 (let ((sink gdb-output-sink))
1085 ((eq sink 'inferior)
1086 (setq gdb-output-sink 'user))
1088 ((eq sink 'emacs) t)
1091 (error "Unexpected frame-begin annotation (%S)" sink)))))
1093 (defun gdb-stopped (ignored)
1094 "An annotation handler for `stopped'.
1095 It is just like `gdb-stopping', except that if we already set the output
1096 sink to `user' in `gdb-stopping', that is fine."
1097 (setq gud-running nil)
1098 (let ((sink gdb-output-sink))
1100 ((eq sink 'inferior)
1101 (setq gdb-output-sink 'user))
1105 (error "Unexpected stopped annotation")))))
1107 (defun gdb-error (ignored)
1108 (setq gdb-error (not gdb-error)))
1110 (defun gdb-post-prompt (ignored)
1111 "An annotation handler for `post-prompt'.
1112 This begins the collection of output from the current command if that
1113 happens to be appropriate."
1114 (unless gdb-pending-triggers
1115 (gdb-get-selected-frame)
1116 (gdb-invalidate-frames)
1117 (gdb-invalidate-breakpoints)
1118 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1119 ;; so gdb-frame-address is updated.
1120 ;; (gdb-invalidate-assembler)
1121 (gdb-invalidate-registers)
1122 (gdb-invalidate-memory)
1123 (gdb-invalidate-locals)
1124 (gdb-invalidate-threads)
1125 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1126 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1127 ;; Only needed/used with speedbar/watch expressions.
1128 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1129 (setq gdb-var-changed t) ; force update
1130 (dolist (var gdb-var-list)
1131 (setcar (nthcdr 5 var) nil))
1133 (let ((sink gdb-output-sink))
1136 ((eq sink 'pre-emacs)
1137 (setq gdb-output-sink 'emacs))
1140 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1142 (defun gud-gdba-marker-filter (string)
1143 "A gud marker filter for gdb. Handle a burst of output from GDB."
1144 (if gdb-flush-pending-output
1146 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1147 ;; Recall the left over gud-marker-acc from last time.
1148 (setq gud-marker-acc (concat gud-marker-acc string))
1149 ;; Start accumulating output for the GUD buffer.
1152 ;; Process all the complete markers in this chunk.
1153 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1154 (let ((annotation (match-string 1 gud-marker-acc)))
1156 ;; Stuff prior to the match is just ordinary output.
1157 ;; It is either concatenated to OUTPUT or directed
1162 (substring gud-marker-acc 0 (match-beginning 0))))
1164 ;; Take that stuff off the gud-marker-acc.
1165 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1167 ;; Parse the tag from the annotation, and maybe its arguments.
1168 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1169 (let* ((annotation-type (match-string 1 annotation))
1170 (annotation-arguments (match-string 2 annotation))
1171 (annotation-rule (assoc annotation-type
1172 gdb-annotation-rules)))
1173 ;; Call the handler for this annotation.
1175 (funcall (car (cdr annotation-rule))
1176 annotation-arguments)
1177 ;; Else the annotation is not recognized. Ignore it silently,
1178 ;; so that GDB can add new annotations without causing
1182 ;; Does the remaining text end in a partial line?
1183 ;; If it does, then keep part of the gud-marker-acc until we get more.
1184 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1187 ;; Everything before the potential marker start can be output.
1189 (gdb-concat-output output
1190 (substring gud-marker-acc 0
1191 (match-beginning 0))))
1193 ;; Everything after, we save, to combine with later input.
1194 (setq gud-marker-acc (substring gud-marker-acc
1195 (match-beginning 0))))
1197 ;; In case we know the gud-marker-acc contains no partial annotations:
1199 (setq output (gdb-concat-output output gud-marker-acc))
1200 (setq gud-marker-acc "")))
1203 (defun gdb-concat-output (so-far new)
1205 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1206 (let ((sink gdb-output-sink))
1208 ((eq sink 'user) (concat so-far new))
1209 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1211 (gdb-append-to-partial-output new)
1213 ((eq sink 'inferior)
1214 (gdb-append-to-inferior-io new)
1218 (error "Bogon output sink %S" sink)))))
1220 (defun gdb-append-to-partial-output (string)
1221 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1222 (goto-char (point-max))
1225 (defun gdb-clear-partial-output ()
1226 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1229 (defun gdb-append-to-inferior-io (string)
1230 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1231 (goto-char (point-max))
1232 (insert-before-markers string))
1233 (if (not (string-equal string ""))
1234 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1236 (defun gdb-clear-inferior-io ()
1237 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1241 ;; One trick is to have a command who's output is always available in a buffer
1242 ;; of it's own, and is always up to date. We build several buffers of this
1245 ;; There are two aspects to this: gdb has to tell us when the output for that
1246 ;; command might have changed, and we have to be able to run the command
1247 ;; behind the user's back.
1249 ;; The output phasing associated with the variable gdb-output-sink
1250 ;; help us to run commands behind the user's back.
1252 ;; Below is the code for specificly managing buffers of output from one
1256 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1257 ;; It adds an input for the command we are tracking. It should be the
1258 ;; annotation rule binding of whatever gdb sends to tell us this command
1259 ;; might have changed it's output.
1261 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1262 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1263 ;; input in the input queue (see comment about ``gdb communications'' above).
1265 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1267 `(defun ,name (&optional ignored)
1268 (if (and ,demand-predicate
1270 gdb-pending-triggers)))
1273 (list ,gdb-command ',output-handler))
1274 (push ',name gdb-pending-triggers)))))
1276 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1278 (setq gdb-pending-triggers
1280 gdb-pending-triggers))
1281 (let ((buf (gdb-get-buffer ',buf-key)))
1283 (with-current-buffer buf
1284 (let* ((window (get-buffer-window buf 0))
1285 (p (window-point window))
1286 (buffer-read-only nil))
1288 (insert-buffer-substring (gdb-get-create-buffer
1289 'gdb-partial-output-buffer))
1290 (set-window-point window p)))))
1291 ;; put customisation here
1294 (defmacro def-gdb-auto-updated-buffer (buffer-key
1295 trigger-name gdb-command
1296 output-handler-name custom-defun)
1298 (def-gdb-auto-update-trigger ,trigger-name
1299 ;; The demand predicate:
1300 (gdb-get-buffer ',buffer-key)
1302 ,output-handler-name)
1303 (def-gdb-auto-update-handler ,output-handler-name
1304 ,trigger-name ,buffer-key ,custom-defun)))
1308 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1310 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1311 'gdb-breakpoints-buffer-name
1312 'gdb-breakpoints-mode)
1314 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1315 ;; This defines the auto update rule for buffers of type
1316 ;; `gdb-breakpoints-buffer'.
1318 ;; It defines a function to serve as the annotation handler that
1319 ;; handles the `foo-invalidated' message. That function is called:
1320 gdb-invalidate-breakpoints
1322 ;; To update the buffer, this command is sent to gdb.
1323 "server info breakpoints\n"
1325 ;; This also defines a function to be the handler for the output
1326 ;; from the command above. That function will copy the output into
1327 ;; the appropriately typed buffer. That function will be called:
1328 gdb-info-breakpoints-handler
1329 ;; buffer specific functions
1330 gdb-info-breakpoints-custom)
1332 (defconst breakpoint-xpm-data
1334 static char *magick[] = {
1335 /* columns rows colors chars-per-pixel */
1351 "XPM data used for breakpoint icon.")
1353 (defconst breakpoint-enabled-pbm-data
1356 0 0 0 0 1 1 1 1 0 0 0 0
1357 0 0 0 1 1 1 1 1 1 0 0 0
1358 0 0 1 1 1 1 1 1 1 1 0 0
1359 0 1 1 1 1 1 1 1 1 1 1 0
1360 0 1 1 1 1 1 1 1 1 1 1 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 0 1 1 1 1 1 1 1 1 0 0
1364 0 0 0 1 1 1 1 1 1 0 0 0
1365 0 0 0 0 1 1 1 1 0 0 0 0"
1366 "PBM data used for enabled breakpoint icon.")
1368 (defconst breakpoint-disabled-pbm-data
1380 0 0 0 1 0 1 0 1 0 0"
1381 "PBM data used for disabled breakpoint icon.")
1383 (defvar breakpoint-enabled-icon nil
1384 "Icon for enabled breakpoint in display margin.")
1386 (defvar breakpoint-disabled-icon nil
1387 "Icon for disabled breakpoint in display margin.")
1389 ;; Bitmap for breakpoint in fringe
1390 (and (display-images-p)
1391 (define-fringe-bitmap 'breakpoint
1392 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1394 (defface breakpoint-enabled
1398 "Face for enabled breakpoint icon in fringe."
1401 (defface breakpoint-disabled
1402 ;; We use different values of grey for different background types,
1403 ;; so that on low-color displays it will end up as something visible
1404 ;; if it has to be approximated.
1405 '((((background dark)) :foreground "grey60")
1406 (((background light)) :foreground "grey40"))
1407 "Face for disabled breakpoint icon in fringe."
1410 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1411 (defun gdb-info-breakpoints-custom ()
1412 (let ((flag) (bptno))
1413 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1414 (dolist (buffer (buffer-list))
1415 (with-current-buffer buffer
1416 (if (and (eq gud-minor-mode 'gdba)
1417 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1418 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1419 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1421 (goto-char (point-min))
1422 (while (< (point) (- (point-max) 1))
1424 (if (looking-at "[^\t].*?breakpoint")
1426 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1427 (setq bptno (match-string 1))
1428 (setq flag (char-after (match-beginning 2)))
1430 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1432 (let ((buffer-read-only nil))
1433 (add-text-properties (match-beginning 1) (match-end 1)
1434 '(face font-lock-function-name-face)))
1435 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1436 (let ((line (match-string 2)) (buffer-read-only nil)
1437 (file (match-string 1)))
1438 (add-text-properties (line-beginning-position)
1440 '(mouse-face highlight
1441 help-echo "mouse-2, RET: visit breakpoint"))
1442 (unless (file-exists-p file)
1443 (setq file (cdr (assoc bptno gdb-location-alist))))
1445 (not (string-equal file "File not found")))
1446 (with-current-buffer
1447 (find-file-noselect file 'nowarn)
1448 (set (make-local-variable 'gud-minor-mode)
1450 (set (make-local-variable 'tool-bar-map)
1452 ;; Only want one breakpoint icon at each
1455 (goto-line (string-to-number line))
1456 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1460 (match-string-no-properties 1) ":1\n")
1463 (list "info source\n"
1464 `(lambda () (gdb-get-location
1465 ,bptno ,line ,flag))))))))))
1467 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1469 (defun gdb-mouse-set-clear-breakpoint (event)
1470 "Set/clear breakpoint in left fringe/margin with mouse click."
1472 (mouse-minibuffer-check event)
1473 (let ((posn (event-end event)))
1474 (if (numberp (posn-point posn))
1475 (with-selected-window (posn-window posn)
1477 (goto-char (posn-point posn))
1478 (if (or (posn-object posn)
1479 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1482 (gud-break nil)))))))
1484 (defun gdb-mouse-toggle-breakpoint-margin (event)
1485 "Enable/disable breakpoint in left margin with mouse click."
1487 (mouse-minibuffer-check event)
1488 (let ((posn (event-end event)))
1489 (if (numberp (posn-point posn))
1490 (with-selected-window (posn-window posn)
1492 (goto-char (posn-point posn))
1493 (if (posn-object posn)
1496 (let ((bptno (get-text-property
1497 0 'gdb-bptno (car (posn-string posn)))))
1499 (if (get-text-property
1500 0 'gdb-enabled (car (posn-string posn)))
1506 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1507 "Enable/disable breakpoint in left fringe with mouse click."
1509 (mouse-minibuffer-check event)
1510 (let* ((posn (event-end event))
1511 (pos (posn-point posn))
1514 (with-selected-window (posn-window posn)
1516 (set-buffer (window-buffer (selected-window)))
1518 (dolist (overlay (overlays-in pos pos))
1519 (when (overlay-get overlay 'put-break)
1520 (setq obj (overlay-get overlay 'before-string))))
1525 (if (get-text-property 0 'gdb-enabled obj)
1528 (get-text-property 0 'gdb-bptno obj) "\n")
1531 (defun gdb-breakpoints-buffer-name ()
1532 (with-current-buffer gud-comint-buffer
1533 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1535 (defun gdb-display-breakpoints-buffer ()
1536 "Display status of user-settable breakpoints."
1539 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1541 (defun gdb-frame-breakpoints-buffer ()
1542 "Display status of user-settable breakpoints in a new frame."
1544 (let ((special-display-regexps (append special-display-regexps '(".*")))
1545 (special-display-frame-alist gdb-frame-parameters))
1546 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1548 (defvar gdb-breakpoints-mode-map
1549 (let ((map (make-sparse-keymap))
1550 (menu (make-sparse-keymap "Breakpoints")))
1551 (define-key menu [quit] '("Quit" . kill-this-buffer))
1552 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1553 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1554 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1555 (suppress-keymap map)
1556 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1557 (define-key map " " 'gdb-toggle-breakpoint)
1558 (define-key map "d" 'gdb-delete-breakpoint)
1559 (define-key map "q" 'kill-this-buffer)
1560 (define-key map "\r" 'gdb-goto-breakpoint)
1561 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1562 (define-key map [follow-link] 'mouse-face)
1565 (defun gdb-breakpoints-mode ()
1566 "Major mode for gdb breakpoints.
1568 \\{gdb-breakpoints-mode-map}"
1569 (kill-all-local-variables)
1570 (setq major-mode 'gdb-breakpoints-mode)
1571 (setq mode-name "Breakpoints")
1572 (use-local-map gdb-breakpoints-mode-map)
1573 (setq buffer-read-only t)
1574 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1575 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1576 'gdb-invalidate-breakpoints
1577 'gdbmi-invalidate-breakpoints))
1579 (defun gdb-toggle-breakpoint ()
1580 "Enable/disable breakpoint at current line."
1583 (beginning-of-line 1)
1584 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1585 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1587 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1590 (concat gdb-server-prefix
1591 (if (eq ?y (char-after (match-beginning 2)))
1594 (match-string 1) "\n") 'ignore))
1595 (error "Not recognized as break/watchpoint line"))))
1597 (defun gdb-delete-breakpoint ()
1598 "Delete the 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-+\\(.\\)")
1604 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1607 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1608 (error "Not recognized as break/watchpoint line")))
1610 (defun gdb-goto-breakpoint (&optional event)
1611 "Display the breakpoint location specified at current line."
1612 (interactive (list last-input-event))
1613 (if event (mouse-set-point event))
1614 ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
1615 (let ((window (get-buffer-window gud-comint-buffer)))
1616 (if window (save-selected-window (select-window window))))
1618 (beginning-of-line 1)
1619 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1620 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1622 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1623 \\(\\S-+\\):\\([0-9]+\\)"))
1624 (let ((bptno (match-string 1))
1625 (file (match-string 2))
1626 (line (match-string 3)))
1627 (save-selected-window
1628 (let* ((buf (find-file-noselect
1629 (if (file-exists-p file) file
1630 (cdr (assoc bptno gdb-location-alist)))))
1631 (window (display-buffer buf)))
1632 (with-current-buffer buf
1633 (goto-line (string-to-number line))
1634 (set-window-point window (point))))))
1635 (error "Not recognized as break/watchpoint line"))))
1638 ;; Frames buffer. This displays a perpetually correct bactracktrace
1639 ;; (from the command `where').
1641 ;; Alas, if your stack is deep, it is costly.
1643 (gdb-set-buffer-rules 'gdb-stack-buffer
1644 'gdb-stack-buffer-name
1647 (def-gdb-auto-updated-buffer gdb-stack-buffer
1648 gdb-invalidate-frames
1650 gdb-info-frames-handler
1651 gdb-info-frames-custom)
1653 (defun gdb-info-frames-custom ()
1654 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1656 (let ((buffer-read-only nil)
1658 (goto-char (point-min))
1659 (while (< (point) (point-max))
1660 (setq bl (line-beginning-position)
1661 el (line-end-position))
1662 (unless (looking-at "No ")
1663 (add-text-properties bl el
1664 '(mouse-face highlight
1665 help-echo "mouse-2, RET: Select frame")))
1667 (when (looking-at "^#\\([0-9]+\\)")
1668 (when (string-equal (match-string 1) gdb-frame-number)
1669 (put-text-property bl (+ bl 4)
1670 'face '(:inverse-video t)))
1671 (when (re-search-forward
1673 (if (string-equal (match-string 1) "0") "" " in ")
1674 "\\([^ ]+\\) (") el t)
1675 (put-text-property (match-beginning 1) (match-end 1)
1676 'face font-lock-function-name-face)
1677 (setq bl (match-end 0))
1678 (while (re-search-forward "<\\([^>]+\\)>" el t)
1679 (put-text-property (match-beginning 1) (match-end 1)
1680 'face font-lock-function-name-face))
1682 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1683 (put-text-property (match-beginning 1) (match-end 1)
1684 'face font-lock-variable-name-face))))
1685 (forward-line 1))))))
1687 (defun gdb-stack-buffer-name ()
1688 (with-current-buffer gud-comint-buffer
1689 (concat "*stack frames of " (gdb-get-target-string) "*")))
1691 (defun gdb-display-stack-buffer ()
1692 "Display backtrace of current stack."
1695 (gdb-get-create-buffer 'gdb-stack-buffer)))
1697 (defun gdb-frame-stack-buffer ()
1698 "Display backtrace of current stack in a new frame."
1700 (let ((special-display-regexps (append special-display-regexps '(".*")))
1701 (special-display-frame-alist gdb-frame-parameters))
1702 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1704 (defvar gdb-frames-mode-map
1705 (let ((map (make-sparse-keymap)))
1706 (suppress-keymap map)
1707 (define-key map "q" 'kill-this-buffer)
1708 (define-key map "\r" 'gdb-frames-select)
1709 (define-key map [mouse-2] 'gdb-frames-select)
1710 (define-key map [follow-link] 'mouse-face)
1713 (defun gdb-frames-mode ()
1714 "Major mode for gdb frames.
1716 \\{gdb-frames-mode-map}"
1717 (kill-all-local-variables)
1718 (setq major-mode 'gdb-frames-mode)
1719 (setq mode-name "Frames")
1720 (setq buffer-read-only t)
1721 (use-local-map gdb-frames-mode-map)
1723 (run-mode-hooks 'gdb-frames-mode-hook)
1724 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1725 'gdb-invalidate-frames
1726 'gdbmi-invalidate-frames))
1728 (defun gdb-get-frame-number ()
1731 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1732 (n (or (and pos (match-string-no-properties 1)) "0")))
1735 (defun gdb-frames-select (&optional event)
1736 "Select the frame and display the relevant source."
1737 (interactive (list last-input-event))
1738 (if event (mouse-set-point event))
1740 (list (concat gdb-server-prefix "frame "
1741 (gdb-get-frame-number) "\n") 'ignore))
1742 (gud-display-frame))
1745 ;; Threads buffer. This displays a selectable thread list.
1747 (gdb-set-buffer-rules 'gdb-threads-buffer
1748 'gdb-threads-buffer-name
1751 (def-gdb-auto-updated-buffer gdb-threads-buffer
1752 gdb-invalidate-threads
1753 (concat gdb-server-prefix "info threads\n")
1754 gdb-info-threads-handler
1755 gdb-info-threads-custom)
1757 (defun gdb-info-threads-custom ()
1758 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1759 (let ((buffer-read-only nil))
1760 (goto-char (point-min))
1761 (while (< (point) (point-max))
1762 (unless (looking-at "No ")
1763 (add-text-properties (line-beginning-position) (line-end-position)
1764 '(mouse-face highlight
1765 help-echo "mouse-2, RET: select thread")))
1766 (forward-line 1)))))
1768 (defun gdb-threads-buffer-name ()
1769 (with-current-buffer gud-comint-buffer
1770 (concat "*threads of " (gdb-get-target-string) "*")))
1772 (defun gdb-display-threads-buffer ()
1773 "Display IDs of currently known threads."
1776 (gdb-get-create-buffer 'gdb-threads-buffer)))
1778 (defun gdb-frame-threads-buffer ()
1779 "Display IDs of currently known threads in a new frame."
1781 (let ((special-display-regexps (append special-display-regexps '(".*")))
1782 (special-display-frame-alist gdb-frame-parameters))
1783 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1785 (defvar gdb-threads-mode-map
1786 (let ((map (make-sparse-keymap)))
1787 (suppress-keymap map)
1788 (define-key map "q" 'kill-this-buffer)
1789 (define-key map "\r" 'gdb-threads-select)
1790 (define-key map [mouse-2] 'gdb-threads-select)
1793 (defvar gdb-threads-font-lock-keywords
1795 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1796 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1797 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1799 "Font lock keywords used in `gdb-threads-mode'.")
1801 (defun gdb-threads-mode ()
1802 "Major mode for gdb frames.
1804 \\{gdb-threads-mode-map}"
1805 (kill-all-local-variables)
1806 (setq major-mode 'gdb-threads-mode)
1807 (setq mode-name "Threads")
1808 (setq buffer-read-only t)
1809 (use-local-map gdb-threads-mode-map)
1810 (set (make-local-variable 'font-lock-defaults)
1811 '(gdb-threads-font-lock-keywords))
1812 (run-mode-hooks 'gdb-threads-mode-hook)
1813 'gdb-invalidate-threads)
1815 (defun gdb-get-thread-number ()
1817 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1818 (match-string-no-properties 1)))
1820 (defun gdb-threads-select (&optional event)
1821 "Select the thread and display the relevant source."
1822 (interactive (list last-input-event))
1823 (if event (mouse-set-point event))
1825 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1826 (gud-display-frame))
1829 ;; Registers buffer.
1831 (defcustom gdb-all-registers nil
1832 "Non-nil means include floating-point registers."
1837 (gdb-set-buffer-rules 'gdb-registers-buffer
1838 'gdb-registers-buffer-name
1839 'gdb-registers-mode)
1841 (def-gdb-auto-updated-buffer gdb-registers-buffer
1842 gdb-invalidate-registers
1844 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1845 gdb-info-registers-handler
1846 gdb-info-registers-custom)
1848 (defun gdb-info-registers-custom ()
1849 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1851 (let ((buffer-read-only nil)
1853 (goto-char (point-min))
1854 (while (< (point) (point-max))
1855 (setq bl (line-beginning-position))
1856 (when (looking-at "^[^ ]+")
1857 (unless (string-equal (match-string 0) "The")
1858 (put-text-property bl (match-end 0)
1859 'face font-lock-variable-name-face)))
1860 (forward-line 1))))))
1862 (defvar gdb-registers-mode-map
1863 (let ((map (make-sparse-keymap)))
1864 (suppress-keymap map)
1865 (define-key map " " 'toggle-gdb-all-registers)
1866 (define-key map "q" 'kill-this-buffer)
1869 (defun gdb-registers-mode ()
1870 "Major mode for gdb registers.
1872 \\{gdb-registers-mode-map}"
1873 (kill-all-local-variables)
1874 (setq major-mode 'gdb-registers-mode)
1875 (setq mode-name "Registers:")
1876 (setq buffer-read-only t)
1877 (use-local-map gdb-registers-mode-map)
1878 (run-mode-hooks 'gdb-registers-mode-hook)
1879 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1880 'gdb-invalidate-registers
1881 'gdbmi-invalidate-registers))
1883 (defun gdb-registers-buffer-name ()
1884 (with-current-buffer gud-comint-buffer
1885 (concat "*registers of " (gdb-get-target-string) "*")))
1887 (defun gdb-display-registers-buffer ()
1888 "Display integer register contents."
1891 (gdb-get-create-buffer 'gdb-registers-buffer)))
1893 (defun gdb-frame-registers-buffer ()
1894 "Display integer register contents in a new frame."
1896 (let ((special-display-regexps (append special-display-regexps '(".*")))
1897 (special-display-frame-alist gdb-frame-parameters))
1898 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1900 (defun toggle-gdb-all-registers ()
1901 "Toggle the display of floating-point registers."
1903 (if gdb-all-registers
1905 (setq gdb-all-registers nil)
1906 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1907 (setq mode-name "Registers:")))
1908 (setq gdb-all-registers t)
1909 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1910 (setq mode-name "Registers:All")))
1911 (gdb-invalidate-registers))
1916 (defcustom gdb-memory-repeat-count 32
1917 "Number of data items in memory window."
1922 (defcustom gdb-memory-format "x"
1923 "Display format of data items in memory window."
1924 :type '(choice (const :tag "Hexadecimal" "x")
1925 (const :tag "Signed decimal" "d")
1926 (const :tag "Unsigned decimal" "u")
1927 (const :tag "Octal" "o")
1928 (const :tag "Binary" "t"))
1932 (defcustom gdb-memory-unit "w"
1933 "Unit size of data items in memory window."
1934 :type '(choice (const :tag "Byte" "b")
1935 (const :tag "Halfword" "h")
1936 (const :tag "Word" "w")
1937 (const :tag "Giant word" "g"))
1941 (gdb-set-buffer-rules 'gdb-memory-buffer
1942 'gdb-memory-buffer-name
1945 (def-gdb-auto-updated-buffer gdb-memory-buffer
1946 gdb-invalidate-memory
1947 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1948 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1949 gdb-read-memory-handler
1950 gdb-read-memory-custom)
1952 (defun gdb-read-memory-custom ()
1954 (goto-char (point-min))
1955 (if (looking-at "0x[[:xdigit:]]+")
1956 (setq gdb-memory-address (match-string 0)))))
1958 (defvar gdb-memory-mode-map
1959 (let ((map (make-sparse-keymap)))
1960 (suppress-keymap map)
1961 (define-key map "q" 'kill-this-buffer)
1964 (defun gdb-memory-set-address (event)
1965 "Set the start memory address."
1967 (save-selected-window
1968 (select-window (posn-window (event-start event)))
1969 (let ((arg (read-from-minibuffer "Memory address: ")))
1970 (setq gdb-memory-address arg))
1971 (gdb-invalidate-memory)))
1973 (defun gdb-memory-set-repeat-count (event)
1974 "Set the number of data items in memory window."
1976 (save-selected-window
1977 (select-window (posn-window (event-start event)))
1978 (let* ((arg (read-from-minibuffer "Repeat count: "))
1979 (count (string-to-number arg)))
1981 (error "Positive numbers only")
1982 (customize-set-variable 'gdb-memory-repeat-count count)
1983 (gdb-invalidate-memory)))))
1985 (defun gdb-memory-format-binary ()
1986 "Set the display format to binary."
1988 (customize-set-variable 'gdb-memory-format "t")
1989 (gdb-invalidate-memory))
1991 (defun gdb-memory-format-octal ()
1992 "Set the display format to octal."
1994 (customize-set-variable 'gdb-memory-format "o")
1995 (gdb-invalidate-memory))
1997 (defun gdb-memory-format-unsigned ()
1998 "Set the display format to unsigned decimal."
2000 (customize-set-variable 'gdb-memory-format "u")
2001 (gdb-invalidate-memory))
2003 (defun gdb-memory-format-signed ()
2004 "Set the display format to decimal."
2006 (customize-set-variable 'gdb-memory-format "d")
2007 (gdb-invalidate-memory))
2009 (defun gdb-memory-format-hexadecimal ()
2010 "Set the display format to hexadecimal."
2012 (customize-set-variable 'gdb-memory-format "x")
2013 (gdb-invalidate-memory))
2015 (defvar gdb-memory-format-keymap
2016 (let ((map (make-sparse-keymap)))
2017 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2019 "Keymap to select format in the header line.")
2021 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2022 "Menu of display formats in the header line.")
2024 (define-key gdb-memory-format-menu [binary]
2025 '(menu-item "Binary" gdb-memory-format-binary
2026 :button (:radio . (equal gdb-memory-format "t"))))
2027 (define-key gdb-memory-format-menu [octal]
2028 '(menu-item "Octal" gdb-memory-format-octal
2029 :button (:radio . (equal gdb-memory-format "o"))))
2030 (define-key gdb-memory-format-menu [unsigned]
2031 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2032 :button (:radio . (equal gdb-memory-format "u"))))
2033 (define-key gdb-memory-format-menu [signed]
2034 '(menu-item "Signed Decimal" gdb-memory-format-signed
2035 :button (:radio . (equal gdb-memory-format "d"))))
2036 (define-key gdb-memory-format-menu [hexadecimal]
2037 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2038 :button (:radio . (equal gdb-memory-format "x"))))
2040 (defun gdb-memory-format-menu (event)
2042 (x-popup-menu event gdb-memory-format-menu))
2044 (defun gdb-memory-format-menu-1 (event)
2046 (save-selected-window
2047 (select-window (posn-window (event-start event)))
2048 (let* ((selection (gdb-memory-format-menu event))
2049 (binding (and selection (lookup-key gdb-memory-format-menu
2050 (vector (car selection))))))
2051 (if binding (call-interactively binding)))))
2053 (defun gdb-memory-unit-giant ()
2054 "Set the unit size to giant words (eight bytes)."
2056 (customize-set-variable 'gdb-memory-unit "g")
2057 (gdb-invalidate-memory))
2059 (defun gdb-memory-unit-word ()
2060 "Set the unit size to words (four bytes)."
2062 (customize-set-variable 'gdb-memory-unit "w")
2063 (gdb-invalidate-memory))
2065 (defun gdb-memory-unit-halfword ()
2066 "Set the unit size to halfwords (two bytes)."
2068 (customize-set-variable 'gdb-memory-unit "h")
2069 (gdb-invalidate-memory))
2071 (defun gdb-memory-unit-byte ()
2072 "Set the unit size to bytes."
2074 (customize-set-variable 'gdb-memory-unit "b")
2075 (gdb-invalidate-memory))
2077 (defvar gdb-memory-unit-keymap
2078 (let ((map (make-sparse-keymap)))
2079 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2081 "Keymap to select units in the header line.")
2083 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2084 "Menu of units in the header line.")
2086 (define-key gdb-memory-unit-menu [giantwords]
2087 '(menu-item "Giant words" gdb-memory-unit-giant
2088 :button (:radio . (equal gdb-memory-unit "g"))))
2089 (define-key gdb-memory-unit-menu [words]
2090 '(menu-item "Words" gdb-memory-unit-word
2091 :button (:radio . (equal gdb-memory-unit "w"))))
2092 (define-key gdb-memory-unit-menu [halfwords]
2093 '(menu-item "Halfwords" gdb-memory-unit-halfword
2094 :button (:radio . (equal gdb-memory-unit "h"))))
2095 (define-key gdb-memory-unit-menu [bytes]
2096 '(menu-item "Bytes" gdb-memory-unit-byte
2097 :button (:radio . (equal gdb-memory-unit "b"))))
2099 (defun gdb-memory-unit-menu (event)
2101 (x-popup-menu event gdb-memory-unit-menu))
2103 (defun gdb-memory-unit-menu-1 (event)
2105 (save-selected-window
2106 (select-window (posn-window (event-start event)))
2107 (let* ((selection (gdb-memory-unit-menu event))
2108 (binding (and selection (lookup-key gdb-memory-unit-menu
2109 (vector (car selection))))))
2110 (if binding (call-interactively binding)))))
2112 ;;from make-mode-line-mouse-map
2113 (defun gdb-make-header-line-mouse-map (mouse function) "\
2114 Return a keymap with single entry for mouse key MOUSE on the header line.
2115 MOUSE is defined to run function FUNCTION with no args in the buffer
2116 corresponding to the mode line clicked."
2117 (let ((map (make-sparse-keymap)))
2118 (define-key map (vector 'header-line mouse) function)
2119 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2122 (defvar gdb-memory-font-lock-keywords
2123 '(;; <__function.name+n>
2124 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2126 "Font lock keywords used in `gdb-memory-mode'.")
2128 (defun gdb-memory-mode ()
2129 "Major mode for examining memory.
2131 \\{gdb-memory-mode-map}"
2132 (kill-all-local-variables)
2133 (setq major-mode 'gdb-memory-mode)
2134 (setq mode-name "Memory")
2135 (setq buffer-read-only t)
2136 (use-local-map gdb-memory-mode-map)
2137 (setq header-line-format
2143 'face font-lock-warning-face
2144 'help-echo "mouse-1: Decrement address"
2145 'mouse-face 'mode-line-highlight
2147 (gdb-make-header-line-mouse-map
2149 #'(lambda () (interactive)
2150 (let ((gdb-memory-address
2151 ;; Let GDB do the arithmetic.
2153 gdb-memory-address " - "
2155 (* gdb-memory-repeat-count
2156 (cond ((string= gdb-memory-unit "b") 1)
2157 ((string= gdb-memory-unit "h") 2)
2158 ((string= gdb-memory-unit "w") 4)
2159 ((string= gdb-memory-unit "g") 8)))))))
2160 (gdb-invalidate-memory)))))
2163 'face font-lock-warning-face
2164 'help-echo "mouse-1: Increment address"
2165 'mouse-face 'mode-line-highlight
2166 'local-map (gdb-make-header-line-mouse-map
2168 #'(lambda () (interactive)
2169 (let ((gdb-memory-address nil))
2170 (gdb-invalidate-memory)))))
2172 (propertize gdb-memory-address
2173 'face font-lock-warning-face
2174 'help-echo "mouse-1: Set memory address"
2175 'mouse-face 'mode-line-highlight
2176 'local-map (gdb-make-header-line-mouse-map
2178 #'gdb-memory-set-address))
2180 (propertize (number-to-string gdb-memory-repeat-count)
2181 'face font-lock-warning-face
2182 'help-echo "mouse-1: Set repeat count"
2183 'mouse-face 'mode-line-highlight
2184 'local-map (gdb-make-header-line-mouse-map
2186 #'gdb-memory-set-repeat-count))
2188 (propertize gdb-memory-format
2189 'face font-lock-warning-face
2190 'help-echo "mouse-3: Select display format"
2191 'mouse-face 'mode-line-highlight
2192 'local-map gdb-memory-format-keymap)
2194 (propertize gdb-memory-unit
2195 'face font-lock-warning-face
2196 'help-echo "mouse-3: Select unit size"
2197 'mouse-face 'mode-line-highlight
2198 'local-map gdb-memory-unit-keymap))))
2199 (set (make-local-variable 'font-lock-defaults)
2200 '(gdb-memory-font-lock-keywords))
2201 (run-mode-hooks 'gdb-memory-mode-hook)
2202 'gdb-invalidate-memory)
2204 (defun gdb-memory-buffer-name ()
2205 (with-current-buffer gud-comint-buffer
2206 (concat "*memory of " (gdb-get-target-string) "*")))
2208 (defun gdb-display-memory-buffer ()
2209 "Display memory contents."
2212 (gdb-get-create-buffer 'gdb-memory-buffer)))
2214 (defun gdb-frame-memory-buffer ()
2215 "Display memory contents in a new frame."
2217 (let ((special-display-regexps (append special-display-regexps '(".*")))
2218 (special-display-frame-alist gdb-frame-parameters))
2219 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2224 (gdb-set-buffer-rules 'gdb-locals-buffer
2225 'gdb-locals-buffer-name
2228 (def-gdb-auto-update-trigger gdb-invalidate-locals
2229 (gdb-get-buffer 'gdb-locals-buffer)
2230 "server info locals\n"
2231 gdb-info-locals-handler)
2233 ;; Abbreviate for arrays and structures.
2234 ;; These can be expanded using gud-display.
2235 (defun gdb-info-locals-handler ()
2236 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2237 gdb-pending-triggers))
2238 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2239 (with-current-buffer buf
2240 (goto-char (point-min))
2241 (while (re-search-forward "^[ }].*\n" nil t)
2242 (replace-match "" nil nil))
2243 (goto-char (point-min))
2244 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2245 (replace-match "(structure);\n" nil nil))
2246 (goto-char (point-min))
2247 (while (re-search-forward "\\s-*{.*\n" nil t)
2248 (replace-match " (array);\n" nil nil))))
2249 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2251 (with-current-buffer buf
2252 (let* ((window (get-buffer-window buf 0))
2253 (p (window-point window))
2254 (buffer-read-only nil))
2256 (insert-buffer-substring (gdb-get-create-buffer
2257 'gdb-partial-output-buffer))
2258 (set-window-point window p)))))
2259 (run-hooks 'gdb-info-locals-hook))
2261 (defvar gdb-locals-mode-map
2262 (let ((map (make-sparse-keymap)))
2263 (suppress-keymap map)
2264 (define-key map "q" 'kill-this-buffer)
2267 (defvar gdb-locals-font-lock-keywords
2269 ;; var = (struct struct_tag) value
2270 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2271 (1 font-lock-variable-name-face)
2272 (3 font-lock-keyword-face)
2273 (4 font-lock-type-face))
2274 ;; var = (type) value
2275 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2276 (1 font-lock-variable-name-face)
2277 (3 font-lock-type-face))
2279 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2280 (1 font-lock-variable-name-face))
2282 "Font lock keywords used in `gdb-local-mode'.")
2284 (defun gdb-locals-mode ()
2285 "Major mode for gdb locals.
2287 \\{gdb-locals-mode-map}"
2288 (kill-all-local-variables)
2289 (setq major-mode 'gdb-locals-mode)
2290 (setq mode-name (concat "Locals:" gdb-selected-frame))
2291 (setq buffer-read-only t)
2292 (use-local-map gdb-locals-mode-map)
2293 (set (make-local-variable 'font-lock-defaults)
2294 '(gdb-locals-font-lock-keywords))
2295 (run-mode-hooks 'gdb-locals-mode-hook)
2296 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2297 'gdb-invalidate-locals
2298 'gdbmi-invalidate-locals))
2300 (defun gdb-locals-buffer-name ()
2301 (with-current-buffer gud-comint-buffer
2302 (concat "*locals of " (gdb-get-target-string) "*")))
2304 (defun gdb-display-locals-buffer ()
2305 "Display local variables of current stack and their values."
2308 (gdb-get-create-buffer 'gdb-locals-buffer)))
2310 (defun gdb-frame-locals-buffer ()
2311 "Display local variables of current stack and their values in a new frame."
2313 (let ((special-display-regexps (append special-display-regexps '(".*")))
2314 (special-display-frame-alist gdb-frame-parameters))
2315 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2318 ;;;; Window management
2319 (defun gdb-display-buffer (buf &optional size)
2320 (let ((answer (get-buffer-window buf 0))
2323 (display-buffer buf nil 0) ;Raise the frame if necessary.
2324 ;; The buffer is not yet displayed.
2325 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2326 (let ((window (get-lru-window)))
2328 (not (eq window (get-buffer-window gud-comint-buffer))))
2330 (set-window-buffer window buf)
2331 (setq answer window))
2332 (setq must-split t)))
2334 (let* ((largest (get-largest-window))
2335 (cur-size (window-height largest))
2336 (new-size (and size (< size cur-size) (- cur-size size))))
2337 (setq answer (split-window largest new-size))
2338 (set-window-buffer answer buf)
2339 (set-window-dedicated-p answer t)))
2343 ;;; Shared keymap initialization:
2345 (let ((menu (make-sparse-keymap "GDB-Windows")))
2346 (define-key gud-menu-map [displays]
2347 `(menu-item "GDB-Windows" ,menu
2348 :visible (memq gud-minor-mode '(gdbmi gdba))))
2349 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2350 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2351 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2352 (define-key menu [disassembly]
2353 '("Disassembly" . gdb-display-assembler-buffer))
2354 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2355 (define-key menu [inferior]
2356 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2357 :enable gdb-use-inferior-io-buffer))
2358 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2359 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2360 (define-key menu [breakpoints]
2361 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2363 (let ((menu (make-sparse-keymap "GDB-Frames")))
2364 (define-key gud-menu-map [frames]
2365 `(menu-item "GDB-Frames" ,menu
2366 :visible (memq gud-minor-mode '(gdbmi gdba))))
2367 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2368 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2369 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2370 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2371 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2372 (define-key menu [inferior]
2373 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2374 :enable gdb-use-inferior-io-buffer))
2375 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2376 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2377 (define-key menu [breakpoints]
2378 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2380 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2381 (define-key gud-menu-map [ui]
2382 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2383 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2384 (define-key menu [gdb-use-inferior-io]
2385 '(menu-item "Separate inferior IO" gdb-use-inferior-io-buffer
2386 :visible (eq gud-minor-mode 'gdba)
2387 :help "Toggle separate IO for inferior."
2388 :button (:toggle . gdb-use-inferior-io-buffer)))
2389 (define-key menu [gdb-many-windows]
2390 '(menu-item "Display Other Windows" gdb-many-windows
2391 :help "Toggle display of locals, stack and breakpoint information"
2392 :button (:toggle . gdb-many-windows)))
2393 (define-key menu [gdb-restore-windows]
2394 '(menu-item "Restore Window Layout" gdb-restore-windows
2395 :help "Restore standard layout for debug session.")))
2397 (defun gdb-frame-gdb-buffer ()
2398 "Display GUD buffer in a new frame."
2400 (let ((special-display-regexps (append special-display-regexps '(".*")))
2401 (special-display-frame-alist gdb-frame-parameters)
2402 (same-window-regexps nil))
2403 (display-buffer gud-comint-buffer)))
2405 (defun gdb-display-gdb-buffer ()
2406 "Display GUD buffer."
2408 (let ((same-window-regexps nil))
2409 (pop-to-buffer gud-comint-buffer)))
2411 (defun gdb-set-window-buffer (name)
2412 (set-window-buffer (selected-window) (get-buffer name))
2413 (set-window-dedicated-p (selected-window) t))
2415 (defun gdb-setup-windows ()
2416 "Layout the window pattern for `gdb-many-windows'."
2417 (gdb-display-locals-buffer)
2418 (gdb-display-stack-buffer)
2419 (delete-other-windows)
2420 (gdb-display-breakpoints-buffer)
2421 (delete-other-windows)
2423 (pop-to-buffer gud-comint-buffer)
2424 (split-window nil ( / ( * (window-height) 3) 4))
2425 (split-window nil ( / (window-height) 3))
2426 (split-window-horizontally)
2428 (gdb-set-window-buffer (gdb-locals-buffer-name))
2431 (if gud-last-last-frame
2432 (gud-find-file (car gud-last-last-frame))
2433 (gud-find-file gdb-main-file)))
2434 (when gdb-use-inferior-io-buffer
2435 (split-window-horizontally)
2437 (gdb-set-window-buffer
2438 (gdb-get-create-buffer 'gdb-inferior-io)))
2440 (gdb-set-window-buffer (gdb-stack-buffer-name))
2441 (split-window-horizontally)
2443 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2446 (defcustom gdb-many-windows nil
2447 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2448 In this case it starts with two windows: one displaying the GUD
2449 buffer and the other with the source file with the main routine
2450 of the inferior. Non-nil means display the layout shown for
2456 (defun gdb-many-windows (arg)
2457 "Toggle the number of windows in the basic arrangement.
2458 With arg, display additional buffers iff arg is positive."
2460 (setq gdb-many-windows
2462 (not gdb-many-windows)
2463 (> (prefix-numeric-value arg) 0)))
2464 (if (and gud-comint-buffer
2465 (buffer-name gud-comint-buffer))
2467 (gdb-restore-windows)
2470 (defun gdb-restore-windows ()
2471 "Restore the basic arrangement of windows used by gdba.
2472 This arrangement depends on the value of `gdb-many-windows'."
2474 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2475 (delete-other-windows)
2476 (if gdb-many-windows
2478 (when (or gud-last-last-frame gdb-show-main)
2482 (if gud-last-last-frame
2483 (gud-find-file (car gud-last-last-frame))
2484 (gud-find-file gdb-main-file)))
2488 "Exit a debugging session cleanly.
2489 Kills the gdb buffers and resets the source buffers."
2490 (dolist (buffer (buffer-list))
2491 (unless (eq buffer gud-comint-buffer)
2492 (with-current-buffer buffer
2493 (if (memq gud-minor-mode '(gdbmi gdba))
2494 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2496 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2497 (setq gud-minor-mode nil)
2498 (kill-local-variable 'tool-bar-map)
2499 (kill-local-variable 'gdb-define-alist))))))
2500 (when (markerp gdb-overlay-arrow-position)
2501 (move-marker gdb-overlay-arrow-position nil)
2502 (setq gdb-overlay-arrow-position nil))
2503 (setq overlay-arrow-variable-list
2504 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2505 (setq gud-running nil)
2506 (setq gdb-active-process nil)
2507 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2509 (defun gdb-source-info ()
2510 "Find the source file where the program starts and displays it with related
2512 (goto-char (point-min))
2513 (if (and (search-forward "Located in " nil t)
2514 (looking-at "\\S-+"))
2515 (setq gdb-main-file (match-string 0)))
2516 (goto-char (point-min))
2517 (if (search-forward "Includes preprocessor macro info." nil t)
2518 (setq gdb-macro-info t))
2519 (if gdb-many-windows
2521 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2523 (let ((pop-up-windows t))
2524 (display-buffer (gud-find-file gdb-main-file))))))
2526 (defun gdb-get-location (bptno line flag)
2527 "Find the directory containing the relevant source file.
2528 Put in buffer and place breakpoint icon."
2529 (goto-char (point-min))
2530 (catch 'file-not-found
2531 (if (search-forward "Located in " nil t)
2532 (when (looking-at "\\S-+")
2533 (delete (cons bptno "File not found") gdb-location-alist)
2534 (push (cons bptno (match-string 0)) gdb-location-alist))
2536 (unless (assoc bptno gdb-location-alist)
2537 (push (cons bptno "File not found") gdb-location-alist)
2538 (message-box "Cannot find source file for breakpoint location.\n\
2539 Add directory to search path for source files using the GDB command, dir."))
2540 (throw 'file-not-found nil))
2541 (with-current-buffer
2542 (find-file-noselect (match-string 0))
2543 (save-current-buffer
2544 (set (make-local-variable 'gud-minor-mode) 'gdba)
2545 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2546 ;; only want one breakpoint icon at each location
2548 (goto-line (string-to-number line))
2549 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2551 (add-hook 'find-file-hook 'gdb-find-file-hook)
2553 (defun gdb-find-file-hook ()
2554 "Set up buffer for debugging if file is part of the source code
2555 of the current session."
2556 (if (and (not gdb-find-file-unhook)
2557 ;; in case gud or gdb-ui is just loaded
2559 (buffer-name gud-comint-buffer)
2560 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2564 (list (concat gdb-server-prefix "list "
2565 (file-name-nondirectory buffer-file-name)
2567 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2568 (error (setq gdb-find-file-unhook t)))))
2571 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2572 "Put string PUTSTRING in front of POS in the current buffer.
2573 PUTSTRING is displayed by putting an overlay into the current buffer with a
2574 `before-string' string that has a `display' property whose value is
2576 (let ((string (make-string 1 ?x))
2577 (buffer (current-buffer)))
2578 (setq putstring (copy-sequence putstring))
2579 (let ((overlay (make-overlay pos pos buffer))
2581 (list (list 'margin 'left-margin) putstring))))
2582 (put-text-property 0 1 'display prop string)
2584 (add-text-properties 0 1 sprops string))
2585 (overlay-put overlay 'put-break t)
2586 (overlay-put overlay 'before-string string))))
2588 ;;from remove-images
2589 (defun gdb-remove-strings (start end &optional buffer)
2590 "Remove strings between START and END in BUFFER.
2591 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2592 BUFFER nil or omitted means use the current buffer."
2594 (setq buffer (current-buffer)))
2595 (dolist (overlay (overlays-in start end))
2596 (when (overlay-get overlay 'put-break)
2597 (delete-overlay overlay))))
2599 (defun gdb-put-breakpoint-icon (enabled bptno)
2600 (let ((start (- (line-beginning-position) 1))
2601 (end (+ (line-end-position) 1))
2602 (putstring (if enabled "B" "b"))
2603 (source-window (get-buffer-window (current-buffer) 0)))
2604 (add-text-properties
2605 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2608 (add-text-properties
2609 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2610 (add-text-properties
2611 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2612 (gdb-remove-breakpoint-icons start end)
2613 (if (display-images-p)
2614 (if (>= (or left-fringe-width
2615 (if source-window (car (window-fringes source-window)))
2616 gdb-buffer-fringe-width) 8)
2619 `(left-fringe breakpoint
2622 'breakpoint-disabled))
2624 'gdb-enabled enabled)
2625 (when (< left-margin-width 2)
2626 (save-current-buffer
2627 (setq left-margin-width 2)
2631 left-margin-width right-margin-width))))
2634 (or breakpoint-enabled-icon
2635 (setq breakpoint-enabled-icon
2636 (find-image `((:type xpm :data
2637 ,breakpoint-xpm-data
2638 :ascent 100 :pointer hand)
2640 ,breakpoint-enabled-pbm-data
2641 :ascent 100 :pointer hand)))))
2642 (or breakpoint-disabled-icon
2643 (setq breakpoint-disabled-icon
2644 (find-image `((:type xpm :data
2645 ,breakpoint-xpm-data
2646 :conversion disabled
2647 :ascent 100 :pointer hand)
2649 ,breakpoint-disabled-pbm-data
2650 :ascent 100 :pointer hand))))))
2654 (when (< left-margin-width 2)
2655 (save-current-buffer
2656 (setq left-margin-width 2)
2657 (let ((window (get-buffer-window (current-buffer) 0)))
2660 window left-margin-width right-margin-width)))))
2662 (propertize putstring
2663 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2666 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2667 (gdb-remove-strings start end)
2668 (if (display-images-p)
2669 (remove-images start end))
2671 (setq left-margin-width 0)
2672 (let ((window (get-buffer-window (current-buffer) 0)))
2675 window left-margin-width right-margin-width)))))
2679 ;; Assembler buffer.
2681 (gdb-set-buffer-rules 'gdb-assembler-buffer
2682 'gdb-assembler-buffer-name
2683 'gdb-assembler-mode)
2685 (def-gdb-auto-update-handler gdb-assembler-handler
2686 gdb-invalidate-assembler
2687 gdb-assembler-buffer
2688 gdb-assembler-custom)
2690 (defun gdb-assembler-custom ()
2691 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2692 (pos 1) (address) (flag) (bptno))
2693 (with-current-buffer buffer
2695 (if (not (equal gdb-frame-address "main"))
2697 (goto-char (point-min))
2698 (if (and gdb-frame-address
2699 (re-search-forward gdb-frame-address nil t))
2703 (or gdb-overlay-arrow-position
2704 (setq gdb-overlay-arrow-position (make-marker)))
2705 (set-marker gdb-overlay-arrow-position
2706 (point) (current-buffer))))))
2707 ;; remove all breakpoint-icons in assembler buffer before updating.
2708 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2709 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2710 (goto-char (point-min))
2711 (while (< (point) (- (point-max) 1))
2713 (if (looking-at "[^\t].*?breakpoint")
2716 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2717 (setq bptno (match-string 1))
2718 (setq flag (char-after (match-beginning 2)))
2719 (setq address (match-string 3))
2720 (with-current-buffer buffer
2722 (goto-char (point-min))
2723 (if (re-search-forward address nil t)
2724 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2725 (if (not (equal gdb-frame-address "main"))
2726 (with-current-buffer buffer
2727 (set-window-point (get-buffer-window buffer 0) pos)))))
2729 (defvar gdb-assembler-mode-map
2730 (let ((map (make-sparse-keymap)))
2731 (suppress-keymap map)
2732 (define-key map "q" 'kill-this-buffer)
2735 (defvar gdb-assembler-font-lock-keywords
2736 '(;; <__function.name+n>
2737 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2738 (1 font-lock-function-name-face))
2739 ;; 0xNNNNNNNN <__function.name+n>: opcode
2740 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2741 (4 font-lock-keyword-face))
2742 ;; %register(at least i386)
2743 ("%\\sw+" . font-lock-variable-name-face)
2744 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2745 (1 font-lock-comment-face)
2746 (2 font-lock-function-name-face))
2747 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2748 "Font lock keywords used in `gdb-assembler-mode'.")
2750 (defun gdb-assembler-mode ()
2751 "Major mode for viewing code assembler.
2753 \\{gdb-assembler-mode-map}"
2754 (kill-all-local-variables)
2755 (setq major-mode 'gdb-assembler-mode)
2756 (setq mode-name (concat "Machine:" gdb-selected-frame))
2757 (setq gdb-overlay-arrow-position nil)
2758 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2759 (setq fringes-outside-margins t)
2760 (setq buffer-read-only t)
2761 (use-local-map gdb-assembler-mode-map)
2762 (gdb-invalidate-assembler)
2763 (set (make-local-variable 'font-lock-defaults)
2764 '(gdb-assembler-font-lock-keywords))
2765 (run-mode-hooks 'gdb-assembler-mode-hook)
2766 'gdb-invalidate-assembler)
2768 (defun gdb-assembler-buffer-name ()
2769 (with-current-buffer gud-comint-buffer
2770 (concat "*disassembly of " (gdb-get-target-string) "*")))
2772 (defun gdb-display-assembler-buffer ()
2773 "Display disassembly view."
2775 (setq gdb-previous-frame nil)
2777 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2779 (defun gdb-frame-assembler-buffer ()
2780 "Display disassembly view in a new frame."
2782 (setq gdb-previous-frame nil)
2783 (let ((special-display-regexps (append special-display-regexps '(".*")))
2784 (special-display-frame-alist gdb-frame-parameters))
2785 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2787 ;; modified because if gdb-frame-address has changed value a new command
2788 ;; must be enqueued to update the buffer with the new output
2789 (defun gdb-invalidate-assembler (&optional ignored)
2790 (if (gdb-get-buffer 'gdb-assembler-buffer)
2792 (unless (and gdb-selected-frame
2793 (string-equal gdb-selected-frame gdb-previous-frame))
2794 (if (or (not (member 'gdb-invalidate-assembler
2795 gdb-pending-triggers))
2796 (not (string-equal gdb-frame-address
2797 gdb-previous-frame-address)))
2799 ;; take previous disassemble command, if any, off the queue
2800 (with-current-buffer gud-comint-buffer
2801 (let ((queue gdb-input-queue))
2802 (dolist (item queue)
2803 (if (equal (cdr item) '(gdb-assembler-handler))
2804 (setq gdb-input-queue
2805 (delete item gdb-input-queue))))))
2808 (concat gdb-server-prefix "disassemble "
2809 (if (member gdb-frame-address '(nil "main")) nil "0x")
2810 gdb-frame-address "\n")
2811 'gdb-assembler-handler))
2812 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2813 (setq gdb-previous-frame-address gdb-frame-address)
2814 (setq gdb-previous-frame gdb-selected-frame)))))))
2816 (defun gdb-get-selected-frame ()
2817 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2820 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2821 (push 'gdb-get-selected-frame
2822 gdb-pending-triggers))))
2824 (defun gdb-frame-handler ()
2825 (setq gdb-pending-triggers
2826 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2827 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2828 (goto-char (point-min))
2829 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2830 (setq gdb-frame-number (match-string 1)))
2831 (goto-char (point-min))
2832 (if (re-search-forward
2833 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2835 (setq gdb-selected-frame (match-string 2))
2836 (if (gdb-get-buffer 'gdb-locals-buffer)
2837 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2838 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2839 (if (gdb-get-buffer 'gdb-assembler-buffer)
2840 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2841 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2842 (setq gdb-frame-address (match-string 1))))
2843 (goto-char (point-min))
2844 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2845 (setq gdb-current-language (match-string 1))))
2846 (gdb-invalidate-assembler))
2850 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2851 ;;; gdb-ui.el ends here