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.
87 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
88 (defvar gdb-previous-frame-address nil)
89 (defvar gdb-memory-address "main")
90 (defvar gdb-previous-frame nil)
91 (defvar gdb-selected-frame nil)
92 (defvar gdb-frame-number nil)
93 (defvar gdb-current-language nil)
94 (defvar gdb-var-list nil "List of variables in watch window.")
95 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
96 (defvar gdb-main-file nil "Source file from which program execution begins.")
97 (defvar gdb-buffer-type nil)
98 (defvar gdb-overlay-arrow-position nil)
99 (defvar gdb-server-prefix nil)
100 (defvar gdb-flush-pending-output nil)
101 (defvar gdb-location-alist nil
102 "Alist of breakpoint numbers and full filenames.")
103 (defvar gdb-find-file-unhook nil)
104 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
105 and #define directives otherwise.")
106 (defvar gdb-error "Non-nil when GDB is reporting an error.")
107 (defvar gdb-macro-info nil
108 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
109 (defvar gdb-buffer-fringe-width nil)
111 (defvar gdb-buffer-type nil
112 "One of the symbols bound in `gdb-buffer-rules'.")
114 (defvar gdb-input-queue ()
115 "A list of gdb command objects.")
117 (defvar gdb-prompting nil
118 "True when gdb is idle with no pending input.")
120 (defvar gdb-output-sink 'user
121 "The disposition of the output of the current gdb command.
122 Possible values are these symbols:
124 `user' -- gdb output should be copied to the GUD buffer
127 `inferior' -- gdb output should be copied to the inferior-io buffer.
129 `pre-emacs' -- output should be ignored util the post-prompt
130 annotation is received. Then the output-sink
132 `emacs' -- output should be collected in the partial-output-buffer
133 for subsequent processing by a command. This is the
134 disposition of output generated by commands that
135 gdb mode sends to gdb on its own behalf.
136 `post-emacs' -- ignore output until the prompt annotation is
137 received, then go to USER disposition.
139 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
140 \(`user' and `emacs').")
142 (defvar gdb-current-item nil
143 "The most recent command item sent to gdb.")
145 (defvar gdb-pending-triggers '()
146 "A list of trigger functions that have run later than their output
149 ;; end of gdb variables
152 (defun gdba (command-line)
153 "Run gdb on program FILE in buffer *gud-FILE*.
154 The directory containing FILE becomes the initial working directory
155 and source-file directory for your debugger.
157 If `gdb-many-windows' is nil (the default value) then gdb just
158 pops up the GUD buffer unless `gdb-show-main' is t. In this case
159 it starts with two windows: one displaying the GUD buffer and the
160 other with the source file with the main routine of the inferior.
162 If `gdb-many-windows' is t, regardless of the value of
163 `gdb-show-main', the layout below will appear unless
164 `gdb-use-inferior-io-buffer' is nil when the source buffer
165 occupies the full width of the frame. Keybindings are given in
168 Watch expressions appear in the speedbar/slowbar.
170 The following commands help control operation :
172 `gdb-many-windows' - Toggle the number of windows gdb uses.
173 `gdb-restore-windows' - To restore the window layout.
175 See Info node `(emacs)GDB Graphical Interface' for a more
176 detailed description of this mode.
179 +--------------------------------------------------------------+
181 +-------------------------------+------------------------------+
182 | GUD buffer (I/O of GDB) | Locals buffer |
186 +-------------------------------+------------------------------+
187 | Source buffer | I/O buffer (of inferior) |
195 +-------------------------------+------------------------------+
196 | Stack buffer | Breakpoints buffer |
197 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
198 | | RET gdb-goto-breakpoint |
199 | | d gdb-delete-breakpoint |
200 +-------------------------------+------------------------------+"
202 (interactive (list (gud-query-cmdline 'gdba)))
204 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
208 (defvar gdb-debug-log nil)
211 (defcustom gdb-enable-debug-log nil
212 "Non-nil means record the process input and output in `gdb-debug-log'."
217 (defcustom gdb-use-inferior-io-buffer nil
218 "Non-nil means display output from the inferior in a separate buffer."
223 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
224 "Shell command for generating a list of defined macros in a source file.
225 This list is used to display the #define directive associated
226 with an identifier as a tooltip. It works in a debug session with
227 GDB, when gud-tooltip-mode is t.
229 Set `gdb-cpp-define-alist-flags' for any include paths or
235 (defcustom gdb-cpp-define-alist-flags ""
236 "Preprocessor flags for `gdb-cpp-define-alist-program'."
241 (defcustom gdb-show-main nil
242 "Non-nil means display source file containing the main routine at startup.
243 Also display the main routine in the disassembly buffer if present."
248 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
250 (defun gdb-create-define-alist ()
251 "Create an alist of #define directives for GUD tooltips."
252 (let* ((file (buffer-file-name))
254 (with-output-to-string
255 (with-current-buffer standard-output
256 (call-process shell-file-name
257 (if (file-exists-p file) file nil)
258 (list t nil) nil "-c"
259 (concat gdb-cpp-define-alist-program " "
260 gdb-cpp-define-alist-flags)))))
261 (define-list (split-string output "\n" t))
263 (setq gdb-define-alist nil)
264 (dolist (define define-list)
265 (setq name (nth 1 (split-string define "[( ]")))
266 (push (cons name define) gdb-define-alist))))
268 (defun gdb-tooltip-print ()
270 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
271 (let ((string (buffer-string)))
272 ;; remove newline for gud-tooltip-echo-area
273 (substring string 0 (- (length string) 1))))
274 (or gud-tooltip-echo-area tooltip-use-echo-area)))
276 ;; If expr is a macro for a function don't print because of possible dangerous
277 ;; side-effects. Also printing a function within a tooltip generates an
278 ;; unexpected starting annotation (phase error).
279 (defun gdb-tooltip-print-1 (expr)
280 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
281 (goto-char (point-min))
282 (if (search-forward "expands to: " nil t)
283 (unless (looking-at "\\S-+.*(.*).*")
285 (list (concat gdb-server-prefix "print " expr "\n")
286 'gdb-tooltip-print))))))
288 (defun gdb-set-gud-minor-mode (buffer)
289 "Set `gud-minor-mode' from find-file if appropriate."
290 (goto-char (point-min))
291 (unless (search-forward "No source file named " nil t)
294 (list (concat gdb-server-prefix "info source\n")
295 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
296 (error (setq gdb-find-file-unhook t)))))
298 (defun gdb-set-gud-minor-mode-1 (buffer)
299 (goto-char (point-min))
300 (when (and (search-forward "Located in " nil t)
302 (string-equal (buffer-file-name buffer)
304 (with-current-buffer buffer
305 (set (make-local-variable 'gud-minor-mode) 'gdba)
306 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
307 (when gud-tooltip-mode
308 (make-local-variable 'gdb-define-alist)
309 (gdb-create-define-alist)
310 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
312 (defun gdb-set-gud-minor-mode-existing-buffers ()
313 (dolist (buffer (buffer-list))
314 (let ((file (buffer-file-name buffer)))
318 (list (concat gdb-server-prefix "list "
319 (file-name-nondirectory file) ":1\n")
320 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
323 (setq gdb-debug-log nil)
324 (set (make-local-variable 'gud-minor-mode) 'gdba)
325 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
327 (gud-def gud-break (if (not (string-match "Machine" mode-name))
328 (gud-call "break %f:%l" arg)
332 (gud-call "break *%a" arg)))
333 "\C-b" "Set breakpoint at current line or address.")
335 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
336 (gud-call "clear %f:%l" arg)
340 (gud-call "clear *%a" arg)))
341 "\C-d" "Remove breakpoint at current line or address.")
343 (gud-def gud-until (if (not (string-match "Machine" mode-name))
344 (gud-call "until %f:%l" arg)
348 (gud-call "until *%a" arg)))
349 "\C-u" "Continue to current line or address.")
351 (define-key gud-minor-mode-map [left-margin mouse-1]
352 'gdb-mouse-set-clear-breakpoint)
353 (define-key gud-minor-mode-map [left-fringe mouse-1]
354 'gdb-mouse-set-clear-breakpoint)
355 (define-key gud-minor-mode-map [left-fringe mouse-2]
357 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
359 (define-key gud-minor-mode-map [left-margin mouse-3]
360 'gdb-mouse-toggle-breakpoint-margin)
361 (define-key gud-minor-mode-map [left-fringe mouse-3]
362 'gdb-mouse-toggle-breakpoint-fringe)
364 (setq comint-input-sender 'gdb-send)
367 (setq gdb-frame-address (if gdb-show-main "main" nil))
368 (setq gdb-previous-frame-address nil
369 gdb-memory-address "main"
370 gdb-previous-frame nil
371 gdb-selected-frame nil
372 gdb-current-language nil
380 gdb-pending-triggers nil
381 gdb-output-sink 'user
382 gdb-server-prefix "server "
383 gdb-flush-pending-output nil
384 gdb-location-alist nil
385 gdb-find-file-unhook nil
388 gdb-buffer-fringe-width (car (window-fringes)))
390 (setq gdb-buffer-type 'gdba)
392 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
394 (if (eq window-system 'w32)
395 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
396 (gdb-enqueue-input (list "set height 0\n" 'ignore))
397 (gdb-enqueue-input (list "set width 0\n" 'ignore))
398 ;; find source file and compilation directory here
399 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
400 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
401 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
403 (gdb-set-gud-minor-mode-existing-buffers)
404 (run-hooks 'gdba-mode-hook))
406 (defun gdb-mouse-until (event)
407 "Execute source lines by dragging the overlay arrow (fringe) with the mouse."
409 (if gud-overlay-arrow-position
410 (let ((start (event-start event))
411 (end (event-end event))
412 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
413 (if (equal buffer (window-buffer (posn-window end)))
414 (with-current-buffer buffer
415 (when (or (equal start end)
416 (equal (posn-point start)
417 (marker-position gud-overlay-arrow-position)))
418 (setq line (line-number-at-pos (posn-point end)))
419 (gud-call (concat "until " (number-to-string line)))))))))
421 (defcustom gdb-use-colon-colon-notation nil
422 "If non-nil use FUN::VAR format to display variables in the speedbar."
428 "Watch expression at point."
431 (let ((expr (tooltip-identifier-from-point (point))))
432 (if (and (string-equal gdb-current-language "c")
433 gdb-use-colon-colon-notation gdb-selected-frame)
434 (setq expr (concat gdb-selected-frame "::" expr)))
435 (catch 'already-watched
436 (dolist (var gdb-var-list)
437 (if (string-equal expr (car var)) (throw 'already-watched nil)))
438 (set-text-properties 0 (length expr) nil expr)
441 (if (eq gud-minor-mode 'gdba)
442 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
443 (concat"-var-create - * " expr "\n"))
444 `(lambda () (gdb-var-create-handler ,expr))))))
445 (select-window (get-buffer-window gud-comint-buffer 0)))
447 (defconst gdb-var-create-regexp
448 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
450 (defun gdb-var-create-handler (expr)
451 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
452 (goto-char (point-min))
453 (if (re-search-forward gdb-var-create-regexp nil t)
454 (let ((var (list expr
459 (push var gdb-var-list)
461 (unless (string-equal
462 speedbar-initial-expansion-list-name "GUD")
463 (speedbar-change-initial-expansion-list "GUD"))
464 (if (equal (nth 2 var) "0")
467 (if (with-current-buffer
468 gud-comint-buffer (eq gud-minor-mode 'gdba))
469 (concat "server interpreter mi \"-var-evaluate-expression "
471 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
472 `(lambda () (gdb-var-evaluate-expression-handler
474 (setq gdb-var-changed t)))
475 (if (re-search-forward "Undefined command" nil t)
476 (message-box "Watching expressions requires gdb 6.0 onwards")
477 (message "No symbol \"%s\" in current context." expr)))))
479 (defun gdb-var-evaluate-expression-handler (varnum changed)
480 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
481 (goto-char (point-min))
482 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t)
485 (dolist (var gdb-var-list)
486 (if (string-equal varnum (cadr var))
488 (if changed (setcar (nthcdr 5 var) t))
489 (setcar (nthcdr 4 var) (match-string 1))
490 (setcar (nthcdr num gdb-var-list) var)
491 (throw 'var-found nil)))
492 (setq num (+ num 1))))))
493 (setq gdb-var-changed t))
495 (defun gdb-var-list-children (varnum)
497 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
498 `(lambda () (gdb-var-list-children-handler ,varnum)))))
500 (defconst gdb-var-list-children-regexp
501 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
503 (defun gdb-var-list-children-handler (varnum)
504 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
505 (goto-char (point-min))
506 (let ((var-list nil))
507 (catch 'child-already-watched
508 (dolist (var gdb-var-list)
509 (if (string-equal varnum (cadr var))
512 (while (re-search-forward gdb-var-list-children-regexp nil t)
513 (let ((varchild (list (match-string 2)
517 (if (looking-at ",type=\"\\(.*?\\)\"")
518 (setcar (nthcdr 3 varchild) (match-string 1)))
519 (dolist (var1 gdb-var-list)
520 (if (string-equal (cadr var1) (cadr varchild))
521 (throw 'child-already-watched nil)))
522 (push varchild var-list)
523 (if (equal (nth 2 varchild) "0")
527 "server interpreter mi \"-var-evaluate-expression "
528 (nth 1 varchild) "\"\n")
529 `(lambda () (gdb-var-evaluate-expression-handler
530 ,(nth 1 varchild) nil))))))))
531 (push var var-list)))
532 (setq gdb-var-list (nreverse var-list))))))
534 (defun gdb-var-update ()
535 (when (not (member 'gdb-var-update gdb-pending-triggers))
537 (list "server interpreter mi \"-var-update *\"\n"
538 'gdb-var-update-handler))
539 (push 'gdb-var-update gdb-pending-triggers)))
541 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
543 (defun gdb-var-update-handler ()
544 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
545 (goto-char (point-min))
546 (while (re-search-forward gdb-var-update-regexp nil t)
547 (let ((varnum (match-string 1)))
550 (concat "server interpreter mi \"-var-evaluate-expression "
552 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
553 (setq gdb-pending-triggers
554 (delq 'gdb-var-update gdb-pending-triggers))
555 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
556 ;; Dummy command to update speedbar at right time.
557 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
558 ;; Keep gdb-pending-triggers non-nil till end.
559 (push 'gdb-speedbar-timer gdb-pending-triggers)))
561 (defun gdb-speedbar-timer-fn ()
562 (setq gdb-pending-triggers
563 (delq 'gdb-speedbar-timer gdb-pending-triggers))
564 (with-current-buffer gud-comint-buffer
565 (speedbar-timer-fn)))
567 (defun gdb-var-delete ()
568 "Delete watch expression at point from the speedbar."
570 (if (with-current-buffer
571 gud-comint-buffer (memq gud-minor-mode '(gdbmi gdba)))
572 (let ((text (speedbar-line-text)))
573 (string-match "\\(\\S-+\\)" text)
574 (let* ((expr (match-string 1 text))
575 (var (assoc expr gdb-var-list))
577 (unless (string-match "\\." varnum)
580 (if (with-current-buffer gud-comint-buffer
581 (eq gud-minor-mode 'gdba))
582 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
583 (concat "-var-delete " varnum "\n"))
585 (setq gdb-var-list (delq var gdb-var-list))
586 (dolist (varchild gdb-var-list)
587 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
588 (setq gdb-var-list (delq varchild gdb-var-list))))
589 (setq gdb-var-changed t))))))
591 (defun gdb-edit-value (text token indent)
592 "Assign a value to a variable displayed in the speedbar."
593 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
594 (varnum (cadr var)) (value))
595 (setq value (read-string "New value: "))
598 (if (with-current-buffer gud-comint-buffer
599 (eq gud-minor-mode 'gdba))
600 (concat "server interpreter mi \"-var-assign "
601 varnum " " value "\"\n")
602 (concat "-var-assign " varnum " " value "\n"))
605 (defcustom gdb-show-changed-values t
606 "If non-nil highlight values that have recently changed in the speedbar.
607 The highlighting is done with `font-lock-warning-face'."
612 (defun gdb-speedbar-expand-node (text token indent)
613 "Expand the node the user clicked on.
614 TEXT is the text of the button we clicked on, a + or - item.
615 TOKEN is data related to this node.
616 INDENT is the current indentation depth."
617 (cond ((string-match "+" text) ;expand this node
618 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
619 (gdb-var-list-children token)
622 (gdbmi-var-list-children token))))
623 ((string-match "-" text) ;contract this node
624 (dolist (var gdb-var-list)
625 (if (string-match (concat token "\\.") (nth 1 var))
626 (setq gdb-var-list (delq var gdb-var-list))))
627 (setq gdb-var-changed t)
628 (with-current-buffer gud-comint-buffer
629 (speedbar-timer-fn)))))
631 (defun gdb-get-target-string ()
632 (with-current-buffer gud-comint-buffer
639 ;; Each buffer has a TYPE -- a symbol that identifies the function
640 ;; of that particular buffer.
642 ;; The usual gdb interaction buffer is given the type `gdba' and
643 ;; is constructed specially.
645 ;; Others are constructed by gdb-get-create-buffer and
646 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
648 (defvar gdb-buffer-rules-assoc '())
650 (defun gdb-get-buffer (key)
651 "Return the gdb buffer tagged with type KEY.
652 The key should be one of the cars in `gdb-buffer-rules-assoc'."
654 (gdb-look-for-tagged-buffer key (buffer-list))))
656 (defun gdb-get-create-buffer (key)
657 "Create a new gdb buffer of the type specified by KEY.
658 The key should be one of the cars in `gdb-buffer-rules-assoc'."
659 (or (gdb-get-buffer key)
660 (let* ((rules (assoc key gdb-buffer-rules-assoc))
661 (name (funcall (gdb-rules-name-maker rules)))
662 (new (get-buffer-create name)))
663 (with-current-buffer new
665 (if (cdr (cdr rules))
666 (setq trigger (funcall (car (cdr (cdr rules))))))
667 (set (make-local-variable 'gdb-buffer-type) key)
668 (set (make-local-variable 'gud-minor-mode)
669 (with-current-buffer gud-comint-buffer gud-minor-mode))
670 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
671 (if trigger (funcall trigger)))
674 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
676 (defun gdb-look-for-tagged-buffer (key bufs)
678 (while (and (not retval) bufs)
679 (set-buffer (car bufs))
680 (if (eq gdb-buffer-type key)
681 (setq retval (car bufs)))
682 (setq bufs (cdr bufs)))
686 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
687 ;; at least one and possible more functions. The functions have these
688 ;; roles in defining a buffer type:
690 ;; NAME - Return a name for this buffer type.
692 ;; The remaining function(s) are optional:
694 ;; MODE - called in a new buffer with no arguments, should establish
695 ;; the proper mode for the buffer.
698 (defun gdb-set-buffer-rules (buffer-type &rest rules)
699 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
701 (setcdr binding rules)
702 (push (cons buffer-type rules)
703 gdb-buffer-rules-assoc))))
705 ;; GUD buffers are an exception to the rules
706 (gdb-set-buffer-rules 'gdba 'error)
709 ;; Partial-output buffer : This accumulates output from a command executed on
710 ;; behalf of emacs (rather than the user).
712 (gdb-set-buffer-rules 'gdb-partial-output-buffer
713 'gdb-partial-output-name)
715 (defun gdb-partial-output-name ()
716 (concat "*partial-output-"
717 (gdb-get-target-string)
721 (gdb-set-buffer-rules 'gdb-inferior-io
722 'gdb-inferior-io-name
723 'gdb-inferior-io-mode)
725 (defun gdb-inferior-io-name ()
726 (concat "*input/output of "
727 (gdb-get-target-string)
730 (defun gdb-display-inferior-io-buffer ()
731 "Display IO of inferior in a separate window."
733 (if gdb-use-inferior-io-buffer
735 (gdb-get-create-buffer 'gdb-inferior-io))))
737 (defconst gdb-frame-parameters
738 '((height . 14) (width . 80)
740 (tool-bar-lines . nil)
741 (menu-bar-lines . nil)
744 (defun gdb-frame-inferior-io-buffer ()
745 "Display IO of inferior in a new frame."
747 (if gdb-use-inferior-io-buffer
748 (let ((special-display-regexps (append special-display-regexps '(".*")))
749 (special-display-frame-alist gdb-frame-parameters))
750 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
752 (defvar gdb-inferior-io-mode-map
753 (let ((map (make-sparse-keymap)))
754 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
755 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
756 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
757 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
758 (define-key map "\C-d" 'gdb-inferior-io-eof)
761 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
762 "Major mode for gdb inferior-io."
763 :syntax-table nil :abbrev-table nil
764 ;; We want to use comint because it has various nifty and familiar
765 ;; features. We don't need a process, but comint wants one, so create
767 (make-comint-in-buffer
768 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
769 (current-buffer) "hexl")
770 (setq comint-input-sender 'gdb-inferior-io-sender))
772 (defun gdb-inferior-io-sender (proc string)
773 ;; PROC is the pseudo-process created to satisfy comint.
774 (with-current-buffer (process-buffer proc)
775 (setq proc (get-buffer-process gud-comint-buffer))
776 (process-send-string proc string)
777 (process-send-string proc "\n")))
779 (defun gdb-inferior-io-interrupt ()
780 "Interrupt the program being debugged."
783 (get-buffer-process gud-comint-buffer) comint-ptyp))
785 (defun gdb-inferior-io-quit ()
786 "Send quit signal to the program being debugged."
789 (get-buffer-process gud-comint-buffer) comint-ptyp))
791 (defun gdb-inferior-io-stop ()
792 "Stop the program being debugged."
795 (get-buffer-process gud-comint-buffer) comint-ptyp))
797 (defun gdb-inferior-io-eof ()
798 "Send end-of-file to the program being debugged."
801 (get-buffer-process gud-comint-buffer)))
805 ;; gdb communications
808 ;; INPUT: things sent to gdb
810 ;; The queues are lists. Each element is either a string (indicating user or
811 ;; user-like input) or a list of the form:
813 ;; (INPUT-STRING HANDLER-FN)
815 ;; The handler function will be called from the partial-output buffer when the
816 ;; command completes. This is the way to write commands which invoke gdb
817 ;; commands autonomously.
819 ;; These lists are consumed tail first.
822 (defun gdb-send (proc string)
823 "A comint send filter for gdb.
824 This filter may simply queue input for a later time."
825 (with-current-buffer gud-comint-buffer
826 (let ((inhibit-read-only t))
827 (remove-text-properties (point-min) (point-max) '(face))))
828 (let ((item (concat string "\n")))
831 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
832 (process-send-string proc item))
833 (gdb-enqueue-input item))))
835 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
836 ;; is a query, or other non-top-level prompt.
838 (defun gdb-enqueue-input (item)
842 (setq gdb-prompting nil))
843 (push item gdb-input-queue)))
845 (defun gdb-dequeue-input ()
846 (let ((queue gdb-input-queue))
848 (let ((last (car (last queue))))
849 (unless (nbutlast queue) (setq gdb-input-queue '()))
852 (defun gdb-send-item (item)
853 (setq gdb-flush-pending-output nil)
854 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
855 (setq gdb-current-item item)
856 (with-current-buffer gud-comint-buffer
857 (if (eq gud-minor-mode 'gdba)
860 (setq gdb-output-sink 'user)
861 (process-send-string (get-buffer-process gud-comint-buffer) item))
863 (gdb-clear-partial-output)
864 (setq gdb-output-sink 'pre-emacs)
865 (process-send-string (get-buffer-process gud-comint-buffer)
867 ;; case: eq gud-minor-mode 'gdbmi
868 (gdb-clear-partial-output)
869 (setq gdb-output-sink 'emacs)
870 (process-send-string (get-buffer-process gud-comint-buffer)
874 ;; output -- things gdb prints to emacs
876 ;; GDB output is a stream interrupted by annotations.
877 ;; Annotations can be recognized by their beginning
878 ;; with \C-j\C-z\C-z<tag><opt>\C-j
880 ;; The tag is a string obeying symbol syntax.
882 ;; The optional part `<opt>' can be either the empty string
883 ;; or a space followed by more data relating to the annotation.
884 ;; For example, the SOURCE annotation is followed by a filename,
885 ;; line number and various useless goo. This data must not include
889 (defcustom gud-gdba-command-name "gdb -annotate=3"
890 "Default command to execute an executable under the GDB-UI debugger."
895 (defvar gdb-annotation-rules
896 '(("pre-prompt" gdb-pre-prompt)
897 ("prompt" gdb-prompt)
898 ("commands" gdb-subprompt)
899 ("overload-choice" gdb-subprompt)
900 ("query" gdb-subprompt)
901 ;; Need this prompt for GDB 6.1
902 ("nquery" gdb-subprompt)
903 ("prompt-for-continue" gdb-subprompt)
904 ("post-prompt" gdb-post-prompt)
905 ("source" gdb-source)
906 ("starting" gdb-starting)
907 ("exited" gdb-exited)
908 ("signalled" gdb-exited)
909 ("signal" gdb-stopping)
910 ("breakpoint" gdb-stopping)
911 ("watchpoint" gdb-stopping)
912 ("frame-begin" gdb-frame-begin)
913 ("stopped" gdb-stopped)
914 ("error-begin" gdb-error)
916 ) "An assoc mapping annotation tags to functions which process them.")
919 (setq gdb-flush-pending-output t)
920 (setq gud-running nil)
921 (setq gdb-output-sink 'user)
922 (setq gdb-input-queue nil)
923 (setq gdb-pending-triggers nil)
924 (setq gdb-prompting t))
926 (defconst gdb-source-spec-regexp
927 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
929 ;; Do not use this except as an annotation handler.
930 (defun gdb-source (args)
931 (string-match gdb-source-spec-regexp args)
932 ;; Extract the frame position from the marker.
935 (match-string 1 args)
936 (string-to-number (match-string 2 args))))
937 (setq gdb-frame-address (match-string 3 args))
938 ;; cover for auto-display output which comes *before*
939 ;; stopped annotation
940 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
942 (defun gdb-pre-prompt (ignored)
943 "An annotation handler for `pre-prompt'.
944 This terminates the collection of output from a previous command if that
945 happens to be in effect."
946 (let ((sink gdb-output-sink))
950 (setq gdb-output-sink 'post-emacs))
953 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
955 (defun gdb-prompt (ignored)
956 "An annotation handler for `prompt'.
957 This sends the next command (if any) to gdb."
958 (when gdb-first-prompt (gdb-ann3))
959 (let ((sink gdb-output-sink))
962 ((eq sink 'post-emacs)
963 (setq gdb-output-sink 'user)
965 (car (cdr gdb-current-item))))
966 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
970 (error "Phase error in gdb-prompt (got %s)" sink))))
971 (let ((input (gdb-dequeue-input)))
973 (gdb-send-item input)
975 (setq gdb-prompting t)
976 (gud-display-frame)))))
978 (defun gdb-subprompt (ignored)
979 "An annotation handler for non-top-level prompts."
980 (setq gdb-prompting t))
982 (defun gdb-starting (ignored)
983 "An annotation handler for `starting'.
984 This says that I/O for the subprocess is now the program being debugged,
986 (setq gdb-active-process t)
987 (let ((sink gdb-output-sink))
992 (if gdb-use-inferior-io-buffer
993 (setq gdb-output-sink 'inferior))))
996 (error "Unexpected `starting' annotation")))))
998 (defun gdb-stopping (ignored)
999 "An annotation handler for `breakpoint' and other annotations.
1000 They say that I/O for the subprocess is now GDB, not the program
1002 (if gdb-use-inferior-io-buffer
1003 (let ((sink gdb-output-sink))
1005 ((eq sink 'inferior)
1006 (setq gdb-output-sink 'user))
1009 (error "Unexpected stopping annotation"))))))
1011 (defun gdb-exited (ignored)
1012 "An annotation handler for `exited' and `signalled'.
1013 They say that I/O for the subprocess is now GDB, not the program
1014 being debugged and that the program is no longer running. This
1015 function is used to change the focus of GUD tooltips to #define
1017 (setq gdb-active-process nil)
1018 (gdb-stopping ignored))
1020 (defun gdb-frame-begin (ignored)
1021 (let ((sink gdb-output-sink))
1023 ((eq sink 'inferior)
1024 (setq gdb-output-sink 'user))
1026 ((eq sink 'emacs) t)
1029 (error "Unexpected frame-begin annotation (%S)" sink)))))
1031 (defun gdb-stopped (ignored)
1032 "An annotation handler for `stopped'.
1033 It is just like `gdb-stopping', except that if we already set the output
1034 sink to `user' in `gdb-stopping', that is fine."
1035 (setq gud-running nil)
1036 (let ((sink gdb-output-sink))
1038 ((eq sink 'inferior)
1039 (setq gdb-output-sink 'user))
1043 (error "Unexpected stopped annotation")))))
1045 (defun gdb-error (ignored)
1046 (setq gdb-error (not gdb-error)))
1048 (defun gdb-post-prompt (ignored)
1049 "An annotation handler for `post-prompt'.
1050 This begins the collection of output from the current command if that
1051 happens to be appropriate."
1052 (unless gdb-pending-triggers
1053 (gdb-get-selected-frame)
1054 (gdb-invalidate-frames)
1055 (gdb-invalidate-breakpoints)
1056 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1057 ;; so gdb-frame-address is updated.
1058 ;; (gdb-invalidate-assembler)
1059 (gdb-invalidate-registers)
1060 (gdb-invalidate-memory)
1061 (gdb-invalidate-locals)
1062 (gdb-invalidate-threads)
1063 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1064 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1065 ;; Only needed/used with speedbar/watch expressions.
1066 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1067 (setq gdb-var-changed t) ; force update
1068 (dolist (var gdb-var-list)
1069 (setcar (nthcdr 5 var) nil))
1071 (let ((sink gdb-output-sink))
1074 ((eq sink 'pre-emacs)
1075 (setq gdb-output-sink 'emacs))
1078 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1080 (defun gud-gdba-marker-filter (string)
1081 "A gud marker filter for gdb. Handle a burst of output from GDB."
1082 (if gdb-flush-pending-output
1084 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1085 ;; Recall the left over gud-marker-acc from last time.
1086 (setq gud-marker-acc (concat gud-marker-acc string))
1087 ;; Start accumulating output for the GUD buffer.
1090 ;; Process all the complete markers in this chunk.
1091 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1092 (let ((annotation (match-string 1 gud-marker-acc)))
1094 ;; Stuff prior to the match is just ordinary output.
1095 ;; It is either concatenated to OUTPUT or directed
1100 (substring gud-marker-acc 0 (match-beginning 0))))
1102 ;; Take that stuff off the gud-marker-acc.
1103 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1105 ;; Parse the tag from the annotation, and maybe its arguments.
1106 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1107 (let* ((annotation-type (match-string 1 annotation))
1108 (annotation-arguments (match-string 2 annotation))
1109 (annotation-rule (assoc annotation-type
1110 gdb-annotation-rules)))
1111 ;; Call the handler for this annotation.
1113 (funcall (car (cdr annotation-rule))
1114 annotation-arguments)
1115 ;; Else the annotation is not recognized. Ignore it silently,
1116 ;; so that GDB can add new annotations without causing
1120 ;; Does the remaining text end in a partial line?
1121 ;; If it does, then keep part of the gud-marker-acc until we get more.
1122 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1125 ;; Everything before the potential marker start can be output.
1127 (gdb-concat-output output
1128 (substring gud-marker-acc 0
1129 (match-beginning 0))))
1131 ;; Everything after, we save, to combine with later input.
1132 (setq gud-marker-acc (substring gud-marker-acc
1133 (match-beginning 0))))
1135 ;; In case we know the gud-marker-acc contains no partial annotations:
1137 (setq output (gdb-concat-output output gud-marker-acc))
1138 (setq gud-marker-acc "")))
1141 (defun gdb-concat-output (so-far new)
1143 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1144 (let ((sink gdb-output-sink))
1146 ((eq sink 'user) (concat so-far new))
1147 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1149 (gdb-append-to-partial-output new)
1151 ((eq sink 'inferior)
1152 (gdb-append-to-inferior-io new)
1156 (error "Bogon output sink %S" sink)))))
1158 (defun gdb-append-to-partial-output (string)
1159 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1160 (goto-char (point-max))
1163 (defun gdb-clear-partial-output ()
1164 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1167 (defun gdb-append-to-inferior-io (string)
1168 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1169 (goto-char (point-max))
1170 (insert-before-markers string))
1171 (if (not (string-equal string ""))
1172 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1174 (defun gdb-clear-inferior-io ()
1175 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1179 ;; One trick is to have a command who's output is always available in a buffer
1180 ;; of it's own, and is always up to date. We build several buffers of this
1183 ;; There are two aspects to this: gdb has to tell us when the output for that
1184 ;; command might have changed, and we have to be able to run the command
1185 ;; behind the user's back.
1187 ;; The output phasing associated with the variable gdb-output-sink
1188 ;; help us to run commands behind the user's back.
1190 ;; Below is the code for specificly managing buffers of output from one
1194 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1195 ;; It adds an input for the command we are tracking. It should be the
1196 ;; annotation rule binding of whatever gdb sends to tell us this command
1197 ;; might have changed it's output.
1199 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1200 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1201 ;; input in the input queue (see comment about ``gdb communications'' above).
1203 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1205 `(defun ,name (&optional ignored)
1206 (if (and ,demand-predicate
1208 gdb-pending-triggers)))
1211 (list ,gdb-command ',output-handler))
1212 (push ',name gdb-pending-triggers)))))
1214 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1216 (setq gdb-pending-triggers
1218 gdb-pending-triggers))
1219 (let ((buf (gdb-get-buffer ',buf-key)))
1221 (with-current-buffer buf
1222 (let* ((window (get-buffer-window buf 0))
1223 (p (window-point window))
1224 (buffer-read-only nil))
1226 (insert-buffer-substring (gdb-get-create-buffer
1227 'gdb-partial-output-buffer))
1228 (set-window-point window p)))))
1229 ;; put customisation here
1232 (defmacro def-gdb-auto-updated-buffer (buffer-key
1233 trigger-name gdb-command
1234 output-handler-name custom-defun)
1236 (def-gdb-auto-update-trigger ,trigger-name
1237 ;; The demand predicate:
1238 (gdb-get-buffer ',buffer-key)
1240 ,output-handler-name)
1241 (def-gdb-auto-update-handler ,output-handler-name
1242 ,trigger-name ,buffer-key ,custom-defun)))
1246 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1248 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1249 'gdb-breakpoints-buffer-name
1250 'gdb-breakpoints-mode)
1252 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1253 ;; This defines the auto update rule for buffers of type
1254 ;; `gdb-breakpoints-buffer'.
1256 ;; It defines a function to serve as the annotation handler that
1257 ;; handles the `foo-invalidated' message. That function is called:
1258 gdb-invalidate-breakpoints
1260 ;; To update the buffer, this command is sent to gdb.
1261 "server info breakpoints\n"
1263 ;; This also defines a function to be the handler for the output
1264 ;; from the command above. That function will copy the output into
1265 ;; the appropriately typed buffer. That function will be called:
1266 gdb-info-breakpoints-handler
1267 ;; buffer specific functions
1268 gdb-info-breakpoints-custom)
1270 (defconst breakpoint-xpm-data
1272 static char *magick[] = {
1273 /* columns rows colors chars-per-pixel */
1289 "XPM data used for breakpoint icon.")
1291 (defconst breakpoint-enabled-pbm-data
1294 0 0 0 0 1 1 1 1 0 0 0 0
1295 0 0 0 1 1 1 1 1 1 0 0 0
1296 0 0 1 1 1 1 1 1 1 1 0 0
1297 0 1 1 1 1 1 1 1 1 1 1 0
1298 0 1 1 1 1 1 1 1 1 1 1 0
1299 0 1 1 1 1 1 1 1 1 1 1 0
1300 0 1 1 1 1 1 1 1 1 1 1 0
1301 0 0 1 1 1 1 1 1 1 1 0 0
1302 0 0 0 1 1 1 1 1 1 0 0 0
1303 0 0 0 0 1 1 1 1 0 0 0 0"
1304 "PBM data used for enabled breakpoint icon.")
1306 (defconst breakpoint-disabled-pbm-data
1318 0 0 0 1 0 1 0 1 0 0"
1319 "PBM data used for disabled breakpoint icon.")
1321 (defvar breakpoint-enabled-icon nil
1322 "Icon for enabled breakpoint in display margin.")
1324 (defvar breakpoint-disabled-icon nil
1325 "Icon for disabled breakpoint in display margin.")
1327 ;; Bitmap for breakpoint in fringe
1328 (and (display-images-p)
1329 (define-fringe-bitmap 'breakpoint
1330 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1332 (defface breakpoint-enabled
1336 "Face for enabled breakpoint icon in fringe."
1338 ;; Compatibility alias for old name.
1339 (put 'breakpoint-enabled-bitmap-face 'face-alias 'breakpoint-enabled)
1341 (defface breakpoint-disabled
1342 ;; We use different values of grey for different background types,
1343 ;; so that on low-color displays it will end up as something visible
1344 ;; if it has to be approximated.
1345 '((((background dark)) :foreground "grey60")
1346 (((background light)) :foreground "grey40"))
1347 "Face for disabled breakpoint icon in fringe."
1350 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1351 (defun gdb-info-breakpoints-custom ()
1352 (let ((flag) (bptno))
1353 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1354 (dolist (buffer (buffer-list))
1355 (with-current-buffer buffer
1356 (if (and (eq gud-minor-mode 'gdba)
1357 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1358 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1359 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1361 (goto-char (point-min))
1362 (while (< (point) (- (point-max) 1))
1364 (if (looking-at "[^\t].*?breakpoint")
1366 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1367 (setq bptno (match-string 1))
1368 (setq flag (char-after (match-beginning 2)))
1370 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1372 (let ((buffer-read-only nil))
1373 (add-text-properties (match-beginning 1) (match-end 1)
1374 '(face font-lock-function-name-face)))
1375 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1376 (let ((line (match-string 2)) (buffer-read-only nil)
1377 (file (match-string 1)))
1378 (add-text-properties (line-beginning-position)
1380 '(mouse-face highlight
1381 help-echo "mouse-2, RET: visit breakpoint"))
1382 (unless (file-exists-p file)
1383 (setq file (cdr (assoc bptno gdb-location-alist))))
1385 (not (string-equal file "File not found")))
1386 (with-current-buffer
1387 (find-file-noselect file 'nowarn)
1388 (set (make-local-variable 'gud-minor-mode)
1390 (set (make-local-variable 'tool-bar-map)
1392 ;; Only want one breakpoint icon at each
1395 (goto-line (string-to-number line))
1396 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1400 (match-string-no-properties 1) ":1\n")
1403 (list "info source\n"
1404 `(lambda () (gdb-get-location
1405 ,bptno ,line ,flag))))))))))
1407 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1409 (defun gdb-mouse-set-clear-breakpoint (event)
1410 "Set/clear breakpoint in left fringe/margin with mouse click."
1412 (mouse-minibuffer-check event)
1413 (let ((posn (event-end event)))
1414 (if (numberp (posn-point posn))
1415 (with-selected-window (posn-window posn)
1417 (goto-char (posn-point posn))
1418 (if (or (posn-object posn)
1419 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1422 (gud-break nil)))))))
1424 (defun gdb-mouse-toggle-breakpoint-margin (event)
1425 "Enable/disable breakpoint in left margin with mouse click."
1427 (mouse-minibuffer-check event)
1428 (let ((posn (event-end event)))
1429 (if (numberp (posn-point posn))
1430 (with-selected-window (posn-window posn)
1432 (goto-char (posn-point posn))
1433 (if (posn-object posn)
1436 (let ((bptno (get-text-property
1437 0 'gdb-bptno (car (posn-string posn)))))
1439 (if (get-text-property
1440 0 'gdb-enabled (car (posn-string posn)))
1446 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1447 "Enable/disable breakpoint in left fringe with mouse click."
1449 (mouse-minibuffer-check event)
1450 (let* ((posn (event-end event))
1451 (pos (posn-point posn))
1454 (with-selected-window (posn-window posn)
1456 (set-buffer (window-buffer (selected-window)))
1458 (dolist (overlay (overlays-in pos pos))
1459 (when (overlay-get overlay 'put-break)
1460 (setq obj (overlay-get overlay 'before-string))))
1465 (if (get-text-property 0 'gdb-enabled obj)
1468 (get-text-property 0 'gdb-bptno obj) "\n")
1471 (defun gdb-breakpoints-buffer-name ()
1472 (with-current-buffer gud-comint-buffer
1473 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1475 (defun gdb-display-breakpoints-buffer ()
1476 "Display status of user-settable breakpoints."
1479 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1481 (defun gdb-frame-breakpoints-buffer ()
1482 "Display status of user-settable breakpoints in a new frame."
1484 (let ((special-display-regexps (append special-display-regexps '(".*")))
1485 (special-display-frame-alist gdb-frame-parameters))
1486 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1488 (defvar gdb-breakpoints-mode-map
1489 (let ((map (make-sparse-keymap))
1490 (menu (make-sparse-keymap "Breakpoints")))
1491 (define-key menu [quit] '("Quit" . kill-this-buffer))
1492 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1493 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1494 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1495 (suppress-keymap map)
1496 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1497 (define-key map " " 'gdb-toggle-breakpoint)
1498 (define-key map "d" 'gdb-delete-breakpoint)
1499 (define-key map "q" 'kill-this-buffer)
1500 (define-key map "\r" 'gdb-goto-breakpoint)
1501 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1502 (define-key map [follow-link] 'mouse-face)
1505 (defun gdb-breakpoints-mode ()
1506 "Major mode for gdb breakpoints.
1508 \\{gdb-breakpoints-mode-map}"
1509 (kill-all-local-variables)
1510 (setq major-mode 'gdb-breakpoints-mode)
1511 (setq mode-name "Breakpoints")
1512 (use-local-map gdb-breakpoints-mode-map)
1513 (setq buffer-read-only t)
1514 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1515 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1516 'gdb-invalidate-breakpoints
1517 'gdbmi-invalidate-breakpoints))
1519 (defun gdb-toggle-breakpoint ()
1520 "Enable/disable breakpoint at current line."
1523 (beginning-of-line 1)
1524 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1525 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1527 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1530 (concat gdb-server-prefix
1531 (if (eq ?y (char-after (match-beginning 2)))
1534 (match-string 1) "\n") 'ignore))
1535 (error "Not recognized as break/watchpoint line"))))
1537 (defun gdb-delete-breakpoint ()
1538 "Delete the breakpoint at current line."
1540 (beginning-of-line 1)
1541 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1542 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1544 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1547 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1548 (error "Not recognized as break/watchpoint line")))
1550 (defun gdb-goto-breakpoint (&optional event)
1551 "Display the breakpoint location specified at current line."
1552 (interactive (list last-input-event))
1553 (if event (mouse-set-point event))
1555 (beginning-of-line 1)
1556 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1557 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1559 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1560 \\(\\S-+\\):\\([0-9]+\\)"))
1561 (let ((bptno (match-string 1))
1562 (file (match-string 2))
1563 (line (match-string 3)))
1564 (save-selected-window
1565 (let* ((buf (find-file-noselect
1566 (if (file-exists-p file) file
1567 (cdr (assoc bptno gdb-location-alist)))))
1568 (window (display-buffer buf)))
1569 (with-current-buffer buf
1570 (goto-line (string-to-number line))
1571 (set-window-point window (point))))))
1572 (error "Not recognized as break/watchpoint line"))))
1575 ;; Frames buffer. This displays a perpetually correct bactracktrace
1576 ;; (from the command `where').
1578 ;; Alas, if your stack is deep, it is costly.
1580 (gdb-set-buffer-rules 'gdb-stack-buffer
1581 'gdb-stack-buffer-name
1584 (def-gdb-auto-updated-buffer gdb-stack-buffer
1585 gdb-invalidate-frames
1587 gdb-info-frames-handler
1588 gdb-info-frames-custom)
1590 (defun gdb-info-frames-custom ()
1591 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1593 (let ((buffer-read-only nil)
1595 (goto-char (point-min))
1596 (while (< (point) (point-max))
1597 (setq bl (line-beginning-position)
1598 el (line-end-position))
1599 (add-text-properties bl el
1600 '(mouse-face highlight
1601 help-echo "mouse-2, RET: Select frame"))
1603 (when (looking-at "^#\\([0-9]+\\)")
1604 (when (string-equal (match-string 1) gdb-frame-number)
1605 (put-text-property bl (+ bl 4)
1606 'face '(:inverse-video t)))
1607 (when (re-search-forward
1609 (if (string-equal (match-string 1) "0") "" " in ")
1610 "\\([^ ]+\\) (") el t)
1611 (put-text-property (match-beginning 1) (match-end 1)
1612 'face font-lock-function-name-face)
1613 (setq bl (match-end 0))
1614 (while (re-search-forward "<\\([^>]+\\)>" el t)
1615 (put-text-property (match-beginning 1) (match-end 1)
1616 'face font-lock-function-name-face))
1618 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1619 (put-text-property (match-beginning 1) (match-end 1)
1620 'face font-lock-variable-name-face))))
1621 (forward-line 1))))))
1623 (defun gdb-stack-buffer-name ()
1624 (with-current-buffer gud-comint-buffer
1625 (concat "*stack frames of " (gdb-get-target-string) "*")))
1627 (defun gdb-display-stack-buffer ()
1628 "Display backtrace of current stack."
1631 (gdb-get-create-buffer 'gdb-stack-buffer)))
1633 (defun gdb-frame-stack-buffer ()
1634 "Display backtrace of current stack in a new frame."
1636 (let ((special-display-regexps (append special-display-regexps '(".*")))
1637 (special-display-frame-alist gdb-frame-parameters))
1638 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1640 (defvar gdb-frames-mode-map
1641 (let ((map (make-sparse-keymap)))
1642 (suppress-keymap map)
1643 (define-key map "q" 'kill-this-buffer)
1644 (define-key map "\r" 'gdb-frames-select)
1645 (define-key map [mouse-2] 'gdb-frames-select)
1646 (define-key map [follow-link] 'mouse-face)
1649 (defun gdb-frames-mode ()
1650 "Major mode for gdb frames.
1652 \\{gdb-frames-mode-map}"
1653 (kill-all-local-variables)
1654 (setq major-mode 'gdb-frames-mode)
1655 (setq mode-name "Frames")
1656 (setq buffer-read-only t)
1657 (use-local-map gdb-frames-mode-map)
1659 (run-mode-hooks 'gdb-frames-mode-hook)
1660 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1661 'gdb-invalidate-frames
1662 'gdbmi-invalidate-frames))
1664 (defun gdb-get-frame-number ()
1667 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1668 (n (or (and pos (match-string-no-properties 1)) "0")))
1671 (defun gdb-frames-select (&optional event)
1672 "Select the frame and display the relevant source."
1673 (interactive (list last-input-event))
1674 (if event (mouse-set-point event))
1676 (list (concat gdb-server-prefix "frame "
1677 (gdb-get-frame-number) "\n") 'ignore))
1678 (gud-display-frame))
1681 ;; Threads buffer. This displays a selectable thread list.
1683 (gdb-set-buffer-rules 'gdb-threads-buffer
1684 'gdb-threads-buffer-name
1687 (def-gdb-auto-updated-buffer gdb-threads-buffer
1688 gdb-invalidate-threads
1689 (concat gdb-server-prefix "info threads\n")
1690 gdb-info-threads-handler
1691 gdb-info-threads-custom)
1693 (defun gdb-info-threads-custom ()
1694 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1695 (let ((buffer-read-only nil))
1696 (goto-char (point-min))
1697 (while (< (point) (point-max))
1698 (add-text-properties (line-beginning-position) (line-end-position)
1699 '(mouse-face highlight
1700 help-echo "mouse-2, RET: select thread"))
1701 (forward-line 1)))))
1703 (defun gdb-threads-buffer-name ()
1704 (with-current-buffer gud-comint-buffer
1705 (concat "*threads of " (gdb-get-target-string) "*")))
1707 (defun gdb-display-threads-buffer ()
1708 "Display IDs of currently known threads."
1711 (gdb-get-create-buffer 'gdb-threads-buffer)))
1713 (defun gdb-frame-threads-buffer ()
1714 "Display IDs of currently known threads in a new frame."
1716 (let ((special-display-regexps (append special-display-regexps '(".*")))
1717 (special-display-frame-alist gdb-frame-parameters))
1718 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1720 (defvar gdb-threads-mode-map
1721 (let ((map (make-sparse-keymap)))
1722 (suppress-keymap map)
1723 (define-key map "q" 'kill-this-buffer)
1724 (define-key map "\r" 'gdb-threads-select)
1725 (define-key map [mouse-2] 'gdb-threads-select)
1728 (defvar gdb-threads-font-lock-keywords
1730 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1731 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1732 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1734 "Font lock keywords used in `gdb-threads-mode'.")
1736 (defun gdb-threads-mode ()
1737 "Major mode for gdb frames.
1739 \\{gdb-threads-mode-map}"
1740 (kill-all-local-variables)
1741 (setq major-mode 'gdb-threads-mode)
1742 (setq mode-name "Threads")
1743 (setq buffer-read-only t)
1744 (use-local-map gdb-threads-mode-map)
1745 (set (make-local-variable 'font-lock-defaults)
1746 '(gdb-threads-font-lock-keywords))
1747 (run-mode-hooks 'gdb-threads-mode-hook)
1748 'gdb-invalidate-threads)
1750 (defun gdb-get-thread-number ()
1752 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1753 (match-string-no-properties 1)))
1755 (defun gdb-threads-select (&optional event)
1756 "Select the thread and display the relevant source."
1757 (interactive (list last-input-event))
1758 (if event (mouse-set-point event))
1760 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1761 (gud-display-frame))
1764 ;; Registers buffer.
1766 (defcustom gdb-all-registers nil
1767 "Non-nil means include floating-point registers."
1772 (gdb-set-buffer-rules 'gdb-registers-buffer
1773 'gdb-registers-buffer-name
1774 'gdb-registers-mode)
1776 (def-gdb-auto-updated-buffer gdb-registers-buffer
1777 gdb-invalidate-registers
1779 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1780 gdb-info-registers-handler
1781 gdb-info-registers-custom)
1783 (defun gdb-info-registers-custom ()
1784 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1786 (let ((buffer-read-only nil)
1788 (goto-char (point-min))
1789 (while (< (point) (point-max))
1790 (setq bl (line-beginning-position))
1791 (when (looking-at "^[^ ]+")
1792 (put-text-property bl (match-end 0)
1793 'face font-lock-variable-name-face))
1794 (forward-line 1))))))
1796 (defvar gdb-registers-mode-map
1797 (let ((map (make-sparse-keymap)))
1798 (suppress-keymap map)
1799 (define-key map " " 'toggle-gdb-all-registers)
1800 (define-key map "q" 'kill-this-buffer)
1803 (defun gdb-registers-mode ()
1804 "Major mode for gdb registers.
1806 \\{gdb-registers-mode-map}"
1807 (kill-all-local-variables)
1808 (setq major-mode 'gdb-registers-mode)
1809 (setq mode-name "Registers:")
1810 (setq buffer-read-only t)
1811 (use-local-map gdb-registers-mode-map)
1812 (run-mode-hooks 'gdb-registers-mode-hook)
1813 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1814 'gdb-invalidate-registers
1815 'gdbmi-invalidate-registers))
1817 (defun gdb-registers-buffer-name ()
1818 (with-current-buffer gud-comint-buffer
1819 (concat "*registers of " (gdb-get-target-string) "*")))
1821 (defun gdb-display-registers-buffer ()
1822 "Display integer register contents."
1825 (gdb-get-create-buffer 'gdb-registers-buffer)))
1827 (defun gdb-frame-registers-buffer ()
1828 "Display integer register contents in a new frame."
1830 (let ((special-display-regexps (append special-display-regexps '(".*")))
1831 (special-display-frame-alist gdb-frame-parameters))
1832 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1834 (defun toggle-gdb-all-registers ()
1835 "Toggle the display of floating-point registers."
1837 (if gdb-all-registers
1839 (setq gdb-all-registers nil)
1840 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1841 (setq mode-name "Registers:")))
1842 (setq gdb-all-registers t)
1843 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1844 (setq mode-name "Registers:All")))
1845 (gdb-invalidate-registers))
1850 (defcustom gdb-memory-repeat-count 32
1851 "Number of data items in memory window."
1856 (defcustom gdb-memory-format "x"
1857 "Display format of data items in memory window."
1858 :type '(choice (const :tag "Hexadecimal" "x")
1859 (const :tag "Signed decimal" "d")
1860 (const :tag "Unsigned decimal" "u")
1861 (const :tag "Octal" "o")
1862 (const :tag "Binary" "t"))
1866 (defcustom gdb-memory-unit "w"
1867 "Unit size of data items in memory window."
1868 :type '(choice (const :tag "Byte" "b")
1869 (const :tag "Halfword" "h")
1870 (const :tag "Word" "w")
1871 (const :tag "Giant word" "g"))
1875 (gdb-set-buffer-rules 'gdb-memory-buffer
1876 'gdb-memory-buffer-name
1879 (def-gdb-auto-updated-buffer gdb-memory-buffer
1880 gdb-invalidate-memory
1881 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1882 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1883 gdb-read-memory-handler
1884 gdb-read-memory-custom)
1886 (defun gdb-read-memory-custom ()
1888 (goto-char (point-min))
1889 (if (looking-at "0x[[:xdigit:]]+")
1890 (setq gdb-memory-address (match-string 0)))))
1892 (defvar gdb-memory-mode-map
1893 (let ((map (make-sparse-keymap)))
1894 (suppress-keymap map)
1895 (define-key map "q" 'kill-this-buffer)
1898 (defun gdb-memory-set-address (event)
1899 "Set the start memory address."
1901 (save-selected-window
1902 (select-window (posn-window (event-start event)))
1903 (let ((arg (read-from-minibuffer "Memory address: ")))
1904 (setq gdb-memory-address arg))
1905 (gdb-invalidate-memory)))
1907 (defun gdb-memory-set-repeat-count (event)
1908 "Set the number of data items in memory window."
1910 (save-selected-window
1911 (select-window (posn-window (event-start event)))
1912 (let* ((arg (read-from-minibuffer "Repeat count: "))
1913 (count (string-to-number arg)))
1915 (error "Positive numbers only")
1916 (customize-set-variable 'gdb-memory-repeat-count count)
1917 (gdb-invalidate-memory)))))
1919 (defun gdb-memory-format-binary ()
1920 "Set the display format to binary."
1922 (customize-set-variable 'gdb-memory-format "t")
1923 (gdb-invalidate-memory))
1925 (defun gdb-memory-format-octal ()
1926 "Set the display format to octal."
1928 (customize-set-variable 'gdb-memory-format "o")
1929 (gdb-invalidate-memory))
1931 (defun gdb-memory-format-unsigned ()
1932 "Set the display format to unsigned decimal."
1934 (customize-set-variable 'gdb-memory-format "u")
1935 (gdb-invalidate-memory))
1937 (defun gdb-memory-format-signed ()
1938 "Set the display format to decimal."
1940 (customize-set-variable 'gdb-memory-format "d")
1941 (gdb-invalidate-memory))
1943 (defun gdb-memory-format-hexadecimal ()
1944 "Set the display format to hexadecimal."
1946 (customize-set-variable 'gdb-memory-format "x")
1947 (gdb-invalidate-memory))
1949 (defvar gdb-memory-format-keymap
1950 (let ((map (make-sparse-keymap)))
1951 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1953 "Keymap to select format in the header line.")
1955 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1956 "Menu of display formats in the header line.")
1958 (define-key gdb-memory-format-menu [binary]
1959 '(menu-item "Binary" gdb-memory-format-binary
1960 :button (:radio . (equal gdb-memory-format "t"))))
1961 (define-key gdb-memory-format-menu [octal]
1962 '(menu-item "Octal" gdb-memory-format-octal
1963 :button (:radio . (equal gdb-memory-format "o"))))
1964 (define-key gdb-memory-format-menu [unsigned]
1965 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
1966 :button (:radio . (equal gdb-memory-format "u"))))
1967 (define-key gdb-memory-format-menu [signed]
1968 '(menu-item "Signed Decimal" gdb-memory-format-signed
1969 :button (:radio . (equal gdb-memory-format "d"))))
1970 (define-key gdb-memory-format-menu [hexadecimal]
1971 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
1972 :button (:radio . (equal gdb-memory-format "x"))))
1974 (defun gdb-memory-format-menu (event)
1976 (x-popup-menu event gdb-memory-format-menu))
1978 (defun gdb-memory-format-menu-1 (event)
1980 (save-selected-window
1981 (select-window (posn-window (event-start event)))
1982 (let* ((selection (gdb-memory-format-menu event))
1983 (binding (and selection (lookup-key gdb-memory-format-menu
1984 (vector (car selection))))))
1985 (if binding (call-interactively binding)))))
1987 (defun gdb-memory-unit-giant ()
1988 "Set the unit size to giant words (eight bytes)."
1990 (customize-set-variable 'gdb-memory-unit "g")
1991 (gdb-invalidate-memory))
1993 (defun gdb-memory-unit-word ()
1994 "Set the unit size to words (four bytes)."
1996 (customize-set-variable 'gdb-memory-unit "w")
1997 (gdb-invalidate-memory))
1999 (defun gdb-memory-unit-halfword ()
2000 "Set the unit size to halfwords (two bytes)."
2002 (customize-set-variable 'gdb-memory-unit "h")
2003 (gdb-invalidate-memory))
2005 (defun gdb-memory-unit-byte ()
2006 "Set the unit size to bytes."
2008 (customize-set-variable 'gdb-memory-unit "b")
2009 (gdb-invalidate-memory))
2011 (defvar gdb-memory-unit-keymap
2012 (let ((map (make-sparse-keymap)))
2013 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2015 "Keymap to select units in the header line.")
2017 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2018 "Menu of units in the header line.")
2020 (define-key gdb-memory-unit-menu [giantwords]
2021 '(menu-item "Giant words" gdb-memory-unit-giant
2022 :button (:radio . (equal gdb-memory-unit "g"))))
2023 (define-key gdb-memory-unit-menu [words]
2024 '(menu-item "Words" gdb-memory-unit-word
2025 :button (:radio . (equal gdb-memory-unit "w"))))
2026 (define-key gdb-memory-unit-menu [halfwords]
2027 '(menu-item "Halfwords" gdb-memory-unit-halfword
2028 :button (:radio . (equal gdb-memory-unit "h"))))
2029 (define-key gdb-memory-unit-menu [bytes]
2030 '(menu-item "Bytes" gdb-memory-unit-byte
2031 :button (:radio . (equal gdb-memory-unit "b"))))
2033 (defun gdb-memory-unit-menu (event)
2035 (x-popup-menu event gdb-memory-unit-menu))
2037 (defun gdb-memory-unit-menu-1 (event)
2039 (save-selected-window
2040 (select-window (posn-window (event-start event)))
2041 (let* ((selection (gdb-memory-unit-menu event))
2042 (binding (and selection (lookup-key gdb-memory-unit-menu
2043 (vector (car selection))))))
2044 (if binding (call-interactively binding)))))
2046 ;;from make-mode-line-mouse-map
2047 (defun gdb-make-header-line-mouse-map (mouse function) "\
2048 Return a keymap with single entry for mouse key MOUSE on the header line.
2049 MOUSE is defined to run function FUNCTION with no args in the buffer
2050 corresponding to the mode line clicked."
2051 (let ((map (make-sparse-keymap)))
2052 (define-key map (vector 'header-line mouse) function)
2053 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2056 (defvar gdb-memory-font-lock-keywords
2057 '(;; <__function.name+n>
2058 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2060 "Font lock keywords used in `gdb-memory-mode'.")
2062 (defun gdb-memory-mode ()
2063 "Major mode for examining memory.
2065 \\{gdb-memory-mode-map}"
2066 (kill-all-local-variables)
2067 (setq major-mode 'gdb-memory-mode)
2068 (setq mode-name "Memory")
2069 (setq buffer-read-only t)
2070 (use-local-map gdb-memory-mode-map)
2071 (setq header-line-format
2077 'face font-lock-warning-face
2078 'help-echo "mouse-1: Decrement address"
2079 'mouse-face 'mode-line-highlight
2081 (gdb-make-header-line-mouse-map
2083 #'(lambda () (interactive)
2084 (let ((gdb-memory-address
2085 ;; Let GDB do the arithmetic.
2087 gdb-memory-address " - "
2089 (* gdb-memory-repeat-count
2090 (cond ((string= gdb-memory-unit "b") 1)
2091 ((string= gdb-memory-unit "h") 2)
2092 ((string= gdb-memory-unit "w") 4)
2093 ((string= gdb-memory-unit "g") 8)))))))
2094 (gdb-invalidate-memory)))))
2097 'face font-lock-warning-face
2098 'help-echo "mouse-1: Increment address"
2099 'mouse-face 'mode-line-highlight
2100 'local-map (gdb-make-header-line-mouse-map
2102 #'(lambda () (interactive)
2103 (let ((gdb-memory-address nil))
2104 (gdb-invalidate-memory)))))
2106 (propertize gdb-memory-address
2107 'face font-lock-warning-face
2108 'help-echo "mouse-1: Set memory address"
2109 'mouse-face 'mode-line-highlight
2110 'local-map (gdb-make-header-line-mouse-map
2112 #'gdb-memory-set-address))
2114 (propertize (number-to-string gdb-memory-repeat-count)
2115 'face font-lock-warning-face
2116 'help-echo "mouse-1: Set repeat count"
2117 'mouse-face 'mode-line-highlight
2118 'local-map (gdb-make-header-line-mouse-map
2120 #'gdb-memory-set-repeat-count))
2122 (propertize gdb-memory-format
2123 'face font-lock-warning-face
2124 'help-echo "mouse-3: Select display format"
2125 'mouse-face 'mode-line-highlight
2126 'local-map gdb-memory-format-keymap)
2128 (propertize gdb-memory-unit
2129 'face font-lock-warning-face
2130 'help-echo "mouse-3: Select unit size"
2131 'mouse-face 'mode-line-highlight
2132 'local-map gdb-memory-unit-keymap))))
2133 (set (make-local-variable 'font-lock-defaults)
2134 '(gdb-memory-font-lock-keywords))
2135 (run-mode-hooks 'gdb-memory-mode-hook)
2136 'gdb-invalidate-memory)
2138 (defun gdb-memory-buffer-name ()
2139 (with-current-buffer gud-comint-buffer
2140 (concat "*memory of " (gdb-get-target-string) "*")))
2142 (defun gdb-display-memory-buffer ()
2143 "Display memory contents."
2146 (gdb-get-create-buffer 'gdb-memory-buffer)))
2148 (defun gdb-frame-memory-buffer ()
2149 "Display memory contents in a new frame."
2151 (let ((special-display-regexps (append special-display-regexps '(".*")))
2152 (special-display-frame-alist gdb-frame-parameters))
2153 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2158 (gdb-set-buffer-rules 'gdb-locals-buffer
2159 'gdb-locals-buffer-name
2162 (def-gdb-auto-update-trigger gdb-invalidate-locals
2163 (gdb-get-buffer 'gdb-locals-buffer)
2164 "server info locals\n"
2165 gdb-info-locals-handler)
2167 ;; Abbreviate for arrays and structures.
2168 ;; These can be expanded using gud-display.
2169 (defun gdb-info-locals-handler ()
2170 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2171 gdb-pending-triggers))
2172 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2173 (with-current-buffer buf
2174 (goto-char (point-min))
2175 (while (re-search-forward "^[ }].*\n" nil t)
2176 (replace-match "" nil nil))
2177 (goto-char (point-min))
2178 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2179 (replace-match "(structure);\n" nil nil))
2180 (goto-char (point-min))
2181 (while (re-search-forward "\\s-*{.*\n" nil t)
2182 (replace-match " (array);\n" nil nil))))
2183 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2185 (with-current-buffer buf
2186 (let* ((window (get-buffer-window buf 0))
2187 (p (window-point window))
2188 (buffer-read-only nil))
2190 (insert-buffer-substring (gdb-get-create-buffer
2191 'gdb-partial-output-buffer))
2192 (set-window-point window p)))))
2193 (run-hooks 'gdb-info-locals-hook))
2195 (defvar gdb-locals-mode-map
2196 (let ((map (make-sparse-keymap)))
2197 (suppress-keymap map)
2198 (define-key map "q" 'kill-this-buffer)
2201 (defvar gdb-locals-font-lock-keywords
2203 ;; var = (struct struct_tag) value
2204 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2205 (1 font-lock-variable-name-face)
2206 (3 font-lock-keyword-face)
2207 (4 font-lock-type-face))
2208 ;; var = (type) value
2209 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2210 (1 font-lock-variable-name-face)
2211 (3 font-lock-type-face))
2213 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2214 (1 font-lock-variable-name-face))
2216 "Font lock keywords used in `gdb-local-mode'.")
2218 (defun gdb-locals-mode ()
2219 "Major mode for gdb locals.
2221 \\{gdb-locals-mode-map}"
2222 (kill-all-local-variables)
2223 (setq major-mode 'gdb-locals-mode)
2224 (setq mode-name (concat "Locals:" gdb-selected-frame))
2225 (setq buffer-read-only t)
2226 (use-local-map gdb-locals-mode-map)
2227 (set (make-local-variable 'font-lock-defaults)
2228 '(gdb-locals-font-lock-keywords))
2229 (run-mode-hooks 'gdb-locals-mode-hook)
2230 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
2231 'gdb-invalidate-locals
2232 'gdbmi-invalidate-locals))
2234 (defun gdb-locals-buffer-name ()
2235 (with-current-buffer gud-comint-buffer
2236 (concat "*locals of " (gdb-get-target-string) "*")))
2238 (defun gdb-display-locals-buffer ()
2239 "Display local variables of current stack and their values."
2242 (gdb-get-create-buffer 'gdb-locals-buffer)))
2244 (defun gdb-frame-locals-buffer ()
2245 "Display local variables of current stack and their values in a new frame."
2247 (let ((special-display-regexps (append special-display-regexps '(".*")))
2248 (special-display-frame-alist gdb-frame-parameters))
2249 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2252 ;;;; Window management
2253 (defun gdb-display-buffer (buf &optional size)
2254 (let ((answer (get-buffer-window buf 0))
2257 (display-buffer buf nil 0) ;Raise the frame if necessary.
2258 ;; The buffer is not yet displayed.
2259 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2260 (let ((window (get-lru-window)))
2262 (not (eq window (get-buffer-window gud-comint-buffer))))
2264 (set-window-buffer window buf)
2265 (setq answer window))
2266 (setq must-split t)))
2268 (let* ((largest (get-largest-window))
2269 (cur-size (window-height largest))
2270 (new-size (and size (< size cur-size) (- cur-size size))))
2271 (setq answer (split-window largest new-size))
2272 (set-window-buffer answer buf)
2273 (set-window-dedicated-p answer t)))
2277 ;;; Shared keymap initialization:
2279 (let ((menu (make-sparse-keymap "GDB-Windows")))
2280 (define-key gud-menu-map [displays]
2281 `(menu-item "GDB-Windows" ,menu
2282 :visible (memq gud-minor-mode '(gdbmi gdba))))
2283 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2284 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2285 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2286 (define-key menu [disassembly]
2287 '("Disassembly" . gdb-display-assembler-buffer))
2288 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2289 (define-key menu [inferior]
2290 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2291 :enable gdb-use-inferior-io-buffer))
2292 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2293 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2294 (define-key menu [breakpoints]
2295 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2297 (let ((menu (make-sparse-keymap "GDB-Frames")))
2298 (define-key gud-menu-map [frames]
2299 `(menu-item "GDB-Frames" ,menu
2300 :visible (memq gud-minor-mode '(gdbmi gdba))))
2301 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2302 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2303 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2304 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2305 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2306 (define-key menu [inferior]
2307 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2308 :enable gdb-use-inferior-io-buffer))
2309 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2310 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2311 (define-key menu [breakpoints]
2312 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2314 (let ((menu (make-sparse-keymap "GDB-UI")))
2315 (define-key gud-menu-map [ui]
2316 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2317 (define-key menu [gdb-use-inferior-io]
2318 ;; See defadvice below.
2319 (menu-bar-make-toggle toggle-gdb-use-inferior-io-buffer
2320 gdb-use-inferior-io-buffer
2321 "Separate inferior IO" "Use separate IO %s"
2322 "Toggle separate IO for inferior."))
2323 (define-key menu [gdb-many-windows]
2324 '(menu-item "Display Other Windows" gdb-many-windows
2325 :help "Toggle display of locals, stack and breakpoint information"
2326 :button (:toggle . gdb-many-windows)))
2327 (define-key menu [gdb-restore-windows]
2328 '(menu-item "Restore Window Layout" gdb-restore-windows
2329 :help "Restore standard layout for debug session.")))
2331 ;; This function is defined above through a macro.
2332 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
2333 (unless gdb-use-inferior-io-buffer
2334 (kill-buffer (gdb-inferior-io-name))))
2336 (defun gdb-frame-gdb-buffer ()
2337 "Display GUD buffer in a new frame."
2339 (select-frame (make-frame gdb-frame-parameters))
2340 (switch-to-buffer (gdb-get-create-buffer 'gdba))
2341 (set-window-dedicated-p (selected-window) t))
2343 (defun gdb-display-gdb-buffer ()
2344 "Display GUD buffer."
2347 (gdb-get-create-buffer 'gdba)))
2349 (defun gdb-set-window-buffer (name)
2350 (set-window-buffer (selected-window) (get-buffer name))
2351 (set-window-dedicated-p (selected-window) t))
2353 (defun gdb-setup-windows ()
2354 "Layout the window pattern for `gdb-many-windows'."
2355 (gdb-display-locals-buffer)
2356 (gdb-display-stack-buffer)
2357 (delete-other-windows)
2358 (gdb-display-breakpoints-buffer)
2359 (delete-other-windows)
2361 (pop-to-buffer gud-comint-buffer)
2362 (split-window nil ( / ( * (window-height) 3) 4))
2363 (split-window nil ( / (window-height) 3))
2364 (split-window-horizontally)
2366 (gdb-set-window-buffer (gdb-locals-buffer-name))
2369 (if gud-last-last-frame
2370 (gud-find-file (car gud-last-last-frame))
2371 (gud-find-file gdb-main-file)))
2372 (when gdb-use-inferior-io-buffer
2373 (split-window-horizontally)
2375 (gdb-set-window-buffer
2376 (gdb-get-create-buffer 'gdb-inferior-io)))
2378 (gdb-set-window-buffer (gdb-stack-buffer-name))
2379 (split-window-horizontally)
2381 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2384 (defcustom gdb-many-windows nil
2385 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2386 In this case it starts with two windows: one displaying the GUD
2387 buffer and the other with the source file with the main routine
2388 of the inferior. Non-nil means display the layout shown for
2394 (defun gdb-many-windows (arg)
2395 "Toggle the number of windows in the basic arrangement."
2397 (setq gdb-many-windows
2399 (not gdb-many-windows)
2400 (> (prefix-numeric-value arg) 0)))
2401 (if (and gud-comint-buffer
2402 (buffer-name gud-comint-buffer))
2404 (gdb-restore-windows)
2407 (defun gdb-restore-windows ()
2408 "Restore the basic arrangement of windows used by gdba.
2409 This arrangement depends on the value of `gdb-many-windows'."
2411 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2412 (delete-other-windows)
2413 (if gdb-many-windows
2418 (if gud-last-last-frame
2419 (gud-find-file (car gud-last-last-frame))
2420 (gud-find-file gdb-main-file)))
2424 "Exit a debugging session cleanly.
2425 Kills the gdb buffers and resets the source buffers."
2426 (dolist (buffer (buffer-list))
2427 (unless (eq buffer gud-comint-buffer)
2428 (with-current-buffer buffer
2429 (if (memq gud-minor-mode '(gdbmi gdba))
2430 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2432 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2433 (setq gud-minor-mode nil)
2434 (kill-local-variable 'tool-bar-map)
2435 (kill-local-variable 'gdb-define-alist))))))
2436 (when (markerp gdb-overlay-arrow-position)
2437 (move-marker gdb-overlay-arrow-position nil)
2438 (setq gdb-overlay-arrow-position nil))
2439 (setq overlay-arrow-variable-list
2440 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2441 (setq gud-running nil)
2442 (setq gdb-active-process nil)
2443 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2445 (defun gdb-source-info ()
2446 "Find the source file where the program starts and displays it with related
2448 (goto-char (point-min))
2449 (if (and (search-forward "Located in " nil t)
2450 (looking-at "\\S-+"))
2451 (setq gdb-main-file (match-string 0)))
2452 (goto-char (point-min))
2453 (if (search-forward "Includes preprocessor macro info." nil t)
2454 (setq gdb-macro-info t))
2455 (if gdb-many-windows
2457 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2459 (let ((pop-up-windows t))
2460 (display-buffer (gud-find-file gdb-main-file))))))
2462 (defun gdb-get-location (bptno line flag)
2463 "Find the directory containing the relevant source file.
2464 Put in buffer and place breakpoint icon."
2465 (goto-char (point-min))
2466 (catch 'file-not-found
2467 (if (search-forward "Located in " nil t)
2468 (when (looking-at "\\S-+")
2469 (delete (cons bptno "File not found") gdb-location-alist)
2470 (push (cons bptno (match-string 0)) gdb-location-alist))
2472 (unless (assoc bptno gdb-location-alist)
2473 (push (cons bptno "File not found") gdb-location-alist)
2474 (message-box "Cannot find source file for breakpoint location.\n\
2475 Add directory to search path for source files using the GDB command, dir."))
2476 (throw 'file-not-found nil))
2477 (with-current-buffer
2478 (find-file-noselect (match-string 0))
2479 (save-current-buffer
2480 (set (make-local-variable 'gud-minor-mode) 'gdba)
2481 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2482 ;; only want one breakpoint icon at each location
2484 (goto-line (string-to-number line))
2485 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2487 (add-hook 'find-file-hook 'gdb-find-file-hook)
2489 (defun gdb-find-file-hook ()
2490 "Set up buffer for debugging if file is part of the source code
2491 of the current session."
2492 (if (and (not gdb-find-file-unhook)
2493 ;; in case gud or gdb-ui is just loaded
2495 (buffer-name gud-comint-buffer)
2496 (with-current-buffer gud-comint-buffer
2497 (eq gud-minor-mode 'gdba)))
2500 (list (concat gdb-server-prefix "list "
2501 (file-name-nondirectory buffer-file-name)
2503 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2504 (error (setq gdb-find-file-unhook t)))))
2507 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2508 "Put string PUTSTRING in front of POS in the current buffer.
2509 PUTSTRING is displayed by putting an overlay into the current buffer with a
2510 `before-string' string that has a `display' property whose value is
2512 (let ((string (make-string 1 ?x))
2513 (buffer (current-buffer)))
2514 (setq putstring (copy-sequence putstring))
2515 (let ((overlay (make-overlay pos pos buffer))
2517 (list (list 'margin 'left-margin) putstring))))
2518 (put-text-property 0 1 'display prop string)
2520 (add-text-properties 0 1 sprops string))
2521 (overlay-put overlay 'put-break t)
2522 (overlay-put overlay 'before-string string))))
2524 ;;from remove-images
2525 (defun gdb-remove-strings (start end &optional buffer)
2526 "Remove strings between START and END in BUFFER.
2527 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2528 BUFFER nil or omitted means use the current buffer."
2530 (setq buffer (current-buffer)))
2531 (dolist (overlay (overlays-in start end))
2532 (when (overlay-get overlay 'put-break)
2533 (delete-overlay overlay))))
2535 (defun gdb-put-breakpoint-icon (enabled bptno)
2536 (let ((start (- (line-beginning-position) 1))
2537 (end (+ (line-end-position) 1))
2538 (putstring (if enabled "B" "b"))
2539 (source-window (get-buffer-window (current-buffer) 0)))
2540 (add-text-properties
2541 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2544 (add-text-properties
2545 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2546 (add-text-properties
2547 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2548 (gdb-remove-breakpoint-icons start end)
2549 (if (display-images-p)
2550 (if (>= (or left-fringe-width
2551 (if source-window (car (window-fringes source-window)))
2552 gdb-buffer-fringe-width) 8)
2555 `(left-fringe breakpoint
2558 'breakpoint-disabled))
2560 'gdb-enabled enabled)
2561 (when (< left-margin-width 2)
2562 (save-current-buffer
2563 (setq left-margin-width 2)
2567 left-margin-width right-margin-width))))
2570 (or breakpoint-enabled-icon
2571 (setq breakpoint-enabled-icon
2572 (find-image `((:type xpm :data
2573 ,breakpoint-xpm-data
2574 :ascent 100 :pointer hand)
2576 ,breakpoint-enabled-pbm-data
2577 :ascent 100 :pointer hand)))))
2578 (or breakpoint-disabled-icon
2579 (setq breakpoint-disabled-icon
2580 (find-image `((:type xpm :data
2581 ,breakpoint-xpm-data
2582 :conversion disabled
2583 :ascent 100 :pointer hand)
2585 ,breakpoint-disabled-pbm-data
2586 :ascent 100 :pointer hand))))))
2590 (when (< left-margin-width 2)
2591 (save-current-buffer
2592 (setq left-margin-width 2)
2593 (let ((window (get-buffer-window (current-buffer) 0)))
2596 window left-margin-width right-margin-width)))))
2598 (propertize putstring
2599 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2602 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2603 (gdb-remove-strings start end)
2604 (if (display-images-p)
2605 (remove-images start end))
2607 (setq left-margin-width 0)
2608 (let ((window (get-buffer-window (current-buffer) 0)))
2611 window left-margin-width right-margin-width)))))
2615 ;; Assembler buffer.
2617 (gdb-set-buffer-rules 'gdb-assembler-buffer
2618 'gdb-assembler-buffer-name
2619 'gdb-assembler-mode)
2621 (def-gdb-auto-update-handler gdb-assembler-handler
2622 gdb-invalidate-assembler
2623 gdb-assembler-buffer
2624 gdb-assembler-custom)
2626 (defun gdb-assembler-custom ()
2627 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2628 (pos 1) (address) (flag) (bptno))
2629 (with-current-buffer buffer
2631 (if (not (equal gdb-frame-address "main"))
2633 (goto-char (point-min))
2634 (if (and gdb-frame-address
2635 (re-search-forward gdb-frame-address nil t))
2639 (or gdb-overlay-arrow-position
2640 (setq gdb-overlay-arrow-position (make-marker)))
2641 (set-marker gdb-overlay-arrow-position
2642 (point) (current-buffer))))))
2643 ;; remove all breakpoint-icons in assembler buffer before updating.
2644 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2645 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2646 (goto-char (point-min))
2647 (while (< (point) (- (point-max) 1))
2649 (if (looking-at "[^\t].*?breakpoint")
2652 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2653 (setq bptno (match-string 1))
2654 (setq flag (char-after (match-beginning 2)))
2655 (setq address (match-string 3))
2656 (with-current-buffer buffer
2658 (goto-char (point-min))
2659 (if (re-search-forward address nil t)
2660 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2661 (if (not (equal gdb-frame-address "main"))
2662 (set-window-point (get-buffer-window buffer 0) pos))))
2664 (defvar gdb-assembler-mode-map
2665 (let ((map (make-sparse-keymap)))
2666 (suppress-keymap map)
2667 (define-key map "q" 'kill-this-buffer)
2670 (defvar gdb-assembler-font-lock-keywords
2671 '(;; <__function.name+n>
2672 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2673 (1 font-lock-function-name-face))
2674 ;; 0xNNNNNNNN <__function.name+n>: opcode
2675 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2676 (4 font-lock-keyword-face))
2677 ;; %register(at least i386)
2678 ("%\\sw+" . font-lock-variable-name-face)
2679 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2680 (1 font-lock-comment-face)
2681 (2 font-lock-function-name-face))
2682 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2683 "Font lock keywords used in `gdb-assembler-mode'.")
2685 (defun gdb-assembler-mode ()
2686 "Major mode for viewing code assembler.
2688 \\{gdb-assembler-mode-map}"
2689 (kill-all-local-variables)
2690 (setq major-mode 'gdb-assembler-mode)
2691 (setq mode-name (concat "Machine:" gdb-selected-frame))
2692 (setq gdb-overlay-arrow-position nil)
2693 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2694 (setq fringes-outside-margins t)
2695 (setq buffer-read-only t)
2696 (use-local-map gdb-assembler-mode-map)
2697 (gdb-invalidate-assembler)
2698 (set (make-local-variable 'font-lock-defaults)
2699 '(gdb-assembler-font-lock-keywords))
2700 (run-mode-hooks 'gdb-assembler-mode-hook)
2701 'gdb-invalidate-assembler)
2703 (defun gdb-assembler-buffer-name ()
2704 (with-current-buffer gud-comint-buffer
2705 (concat "*Disassembly of " (gdb-get-target-string) "*")))
2707 (defun gdb-display-assembler-buffer ()
2708 "Display disassembly view."
2710 (setq gdb-previous-frame nil)
2712 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2714 (defun gdb-frame-assembler-buffer ()
2715 "Display disassembly view in a new frame."
2717 (setq gdb-previous-frame nil)
2718 (let ((special-display-regexps (append special-display-regexps '(".*")))
2719 (special-display-frame-alist gdb-frame-parameters))
2720 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2722 ;; modified because if gdb-frame-address has changed value a new command
2723 ;; must be enqueued to update the buffer with the new output
2724 (defun gdb-invalidate-assembler (&optional ignored)
2725 (if (gdb-get-buffer 'gdb-assembler-buffer)
2727 (unless (and gdb-selected-frame
2728 (string-equal gdb-selected-frame gdb-previous-frame))
2729 (if (or (not (member 'gdb-invalidate-assembler
2730 gdb-pending-triggers))
2731 (not (string-equal gdb-frame-address
2732 gdb-previous-frame-address)))
2734 ;; take previous disassemble command, if any, off the queue
2735 (with-current-buffer gud-comint-buffer
2736 (let ((queue gdb-input-queue))
2737 (dolist (item queue)
2738 (if (equal (cdr item) '(gdb-assembler-handler))
2739 (setq gdb-input-queue
2740 (delete item gdb-input-queue))))))
2743 (concat gdb-server-prefix "disassemble "
2744 (if (member gdb-frame-address '(nil "main")) nil "0x")
2745 gdb-frame-address "\n")
2746 'gdb-assembler-handler))
2747 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2748 (setq gdb-previous-frame-address gdb-frame-address)
2749 (setq gdb-previous-frame gdb-selected-frame)))))))
2751 (defun gdb-get-selected-frame ()
2752 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2755 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2756 (push 'gdb-get-selected-frame
2757 gdb-pending-triggers))))
2759 (defun gdb-frame-handler ()
2760 (setq gdb-pending-triggers
2761 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2762 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2763 (goto-char (point-min))
2764 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2765 (setq gdb-frame-number (match-string 1)))
2766 (goto-char (point-min))
2767 (if (re-search-forward
2768 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2770 (setq gdb-selected-frame (match-string 2))
2771 (if (gdb-get-buffer 'gdb-locals-buffer)
2772 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2773 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2774 (if (gdb-get-buffer 'gdb-assembler-buffer)
2775 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2776 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2777 (setq gdb-frame-address (match-string 1))))
2778 (goto-char (point-min))
2779 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2780 (setq gdb-current-language (match-string 1))))
2781 (gdb-invalidate-assembler))
2785 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2786 ;;; gdb-ui.el ends here