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."
245 (defcustom gdb-use-inferior-io-buffer nil
246 "Non-nil means display output from the inferior in a separate buffer."
251 (defun gdb-use-inferior-io-buffer (arg)
252 "Toggle separate IO for inferior.
253 With arg, use separate IO iff arg is positive."
255 (setq gdb-use-inferior-io-buffer
257 (not gdb-use-inferior-io-buffer)
258 (> (prefix-numeric-value arg) 0)))
259 (if (and gud-comint-buffer
260 (buffer-name gud-comint-buffer))
262 (if gdb-use-inferior-io-buffer
263 (gdb-restore-windows)
264 (kill-buffer (gdb-inferior-io-name)))
267 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
269 (defun gdb-create-define-alist ()
270 "Create an alist of #define directives for GUD tooltips."
271 (let* ((file (buffer-file-name))
273 (with-output-to-string
274 (with-current-buffer standard-output
275 (call-process shell-file-name
276 (if (file-exists-p file) file nil)
277 (list t nil) nil "-c"
278 (concat gdb-cpp-define-alist-program " "
279 gdb-cpp-define-alist-flags)))))
280 (define-list (split-string output "\n" t))
282 (setq gdb-define-alist nil)
283 (dolist (define define-list)
284 (setq name (nth 1 (split-string define "[( ]")))
285 (push (cons name define) gdb-define-alist))))
287 (defun gdb-tooltip-print ()
289 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
290 (let ((string (buffer-string)))
291 ;; remove newline for gud-tooltip-echo-area
292 (substring string 0 (- (length string) 1))))
293 (or gud-tooltip-echo-area tooltip-use-echo-area)))
295 ;; If expr is a macro for a function don't print because of possible dangerous
296 ;; side-effects. Also printing a function within a tooltip generates an
297 ;; unexpected starting annotation (phase error).
298 (defun gdb-tooltip-print-1 (expr)
299 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
300 (goto-char (point-min))
301 (if (search-forward "expands to: " nil t)
302 (unless (looking-at "\\S-+.*(.*).*")
304 (list (concat gdb-server-prefix "print " expr "\n")
305 'gdb-tooltip-print))))))
307 (defun gdb-set-gud-minor-mode (buffer)
308 "Set `gud-minor-mode' from find-file if appropriate."
309 (goto-char (point-min))
310 (unless (search-forward "No source file named " nil t)
313 (list (concat gdb-server-prefix "info source\n")
314 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
315 (error (setq gdb-find-file-unhook t)))))
317 (defun gdb-set-gud-minor-mode-1 (buffer)
318 (goto-char (point-min))
319 (when (and (search-forward "Located in " nil t)
321 (string-equal (buffer-file-name buffer)
323 (with-current-buffer buffer
324 (set (make-local-variable 'gud-minor-mode) 'gdba)
325 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
326 (when gud-tooltip-mode
327 (make-local-variable 'gdb-define-alist)
328 (gdb-create-define-alist)
329 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
331 (defun gdb-set-gud-minor-mode-existing-buffers ()
332 (dolist (buffer (buffer-list))
333 (let ((file (buffer-file-name buffer)))
337 (list (concat gdb-server-prefix "list "
338 (file-name-nondirectory file) ":1\n")
339 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
342 (setq gdb-debug-log nil)
343 (set (make-local-variable 'gud-minor-mode) 'gdba)
344 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
346 (gud-def gud-break (if (not (string-match "Machine" mode-name))
347 (gud-call "break %f:%l" arg)
351 (gud-call "break *%a" arg)))
352 "\C-b" "Set breakpoint at current line or address.")
354 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
355 (gud-call "clear %f:%l" arg)
359 (gud-call "clear *%a" arg)))
360 "\C-d" "Remove breakpoint at current line or address.")
362 (gud-def gud-until (if (not (string-match "Machine" mode-name))
363 (gud-call "until %f:%l" arg)
367 (gud-call "until *%a" arg)))
368 "\C-u" "Continue to current line or address.")
370 (define-key gud-minor-mode-map [left-margin mouse-1]
371 'gdb-mouse-set-clear-breakpoint)
372 (define-key gud-minor-mode-map [left-fringe mouse-1]
373 'gdb-mouse-set-clear-breakpoint)
374 (define-key gud-minor-mode-map [left-fringe mouse-2]
376 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
378 (define-key gud-minor-mode-map [left-margin mouse-3]
379 'gdb-mouse-toggle-breakpoint-margin)
380 (define-key gud-minor-mode-map [left-fringe mouse-3]
381 'gdb-mouse-toggle-breakpoint-fringe)
383 (setq comint-input-sender 'gdb-send)
386 (setq gdb-frame-address (if gdb-show-main "main" nil))
387 (setq gdb-previous-frame-address nil
388 gdb-memory-address "main"
389 gdb-previous-frame nil
390 gdb-selected-frame nil
391 gdb-current-language nil
399 gdb-pending-triggers nil
400 gdb-output-sink 'user
401 gdb-server-prefix "server "
402 gdb-flush-pending-output nil
403 gdb-location-alist nil
404 gdb-find-file-unhook nil
407 gdb-buffer-fringe-width (car (window-fringes)))
409 (setq gdb-buffer-type 'gdba)
411 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
413 (if (eq window-system 'w32)
414 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
415 (gdb-enqueue-input (list "set height 0\n" 'ignore))
416 (gdb-enqueue-input (list "set width 0\n" 'ignore))
417 ;; find source file and compilation directory here
418 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
419 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
420 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
422 (gdb-set-gud-minor-mode-existing-buffers)
423 (run-hooks 'gdba-mode-hook))
425 (defun gdb-mouse-until (event)
426 "Execute source lines by dragging the overlay arrow (fringe) with the mouse."
428 (if gud-overlay-arrow-position
429 (let ((start (event-start event))
430 (end (event-end event))
431 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
432 (if (not (string-match "Machine" mode-name))
433 (if (equal buffer (window-buffer (posn-window end)))
434 (with-current-buffer buffer
435 (when (or (equal start end)
436 (equal (posn-point start)
438 gud-overlay-arrow-position)))
439 (setq line (line-number-at-pos (posn-point end)))
440 (gud-call (concat "until " (number-to-string line))))))
441 (if (equal (marker-buffer gdb-overlay-arrow-position)
442 (window-buffer (posn-window end)))
443 (when (or (equal start end)
444 (equal (posn-point start)
446 gdb-overlay-arrow-position)))
448 (goto-line (line-number-at-pos (posn-point end)))
450 (gud-call (concat "until *%a")))))))))
452 (defcustom gdb-use-colon-colon-notation nil
453 "If non-nil use FUN::VAR format to display variables in the speedbar."
459 "Watch expression at point."
462 (save-selected-window
463 (let ((expr (tooltip-identifier-from-point (point))))
464 (if (and (string-equal gdb-current-language "c")
465 gdb-use-colon-colon-notation gdb-selected-frame)
466 (setq expr (concat gdb-selected-frame "::" expr)))
467 (catch 'already-watched
468 (dolist (var gdb-var-list)
469 (if (string-equal expr (car var)) (throw 'already-watched nil)))
470 (set-text-properties 0 (length expr) nil expr)
473 (if (eq gud-minor-mode 'gdba)
474 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
475 (concat"-var-create - * " expr "\n"))
476 `(lambda () (gdb-var-create-handler ,expr))))))))
478 (defconst gdb-var-create-regexp
479 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
481 (defun gdb-var-create-handler (expr)
482 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
483 (goto-char (point-min))
484 (if (re-search-forward gdb-var-create-regexp nil t)
485 (let ((var (list expr
490 (push var gdb-var-list)
492 (unless (string-equal
493 speedbar-initial-expansion-list-name "GUD")
494 (speedbar-change-initial-expansion-list "GUD"))
495 (if (equal (nth 2 var) "0")
498 (if (with-current-buffer
499 gud-comint-buffer (eq gud-minor-mode 'gdba))
500 (concat "server interpreter mi \"-var-evaluate-expression "
502 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
503 `(lambda () (gdb-var-evaluate-expression-handler
505 (setq gdb-var-changed t)))
506 (if (re-search-forward "Undefined command" nil t)
507 (message-box "Watching expressions requires gdb 6.0 onwards")
508 (message "No symbol \"%s\" in current context." expr)))))
510 (defun gdb-var-evaluate-expression-handler (varnum changed)
511 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
512 (goto-char (point-min))
513 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t)
516 (dolist (var gdb-var-list)
517 (if (string-equal varnum (cadr var))
519 (if changed (setcar (nthcdr 5 var) t))
520 (setcar (nthcdr 4 var) (match-string 1))
521 (setcar (nthcdr num gdb-var-list) var)
522 (throw 'var-found nil)))
523 (setq num (+ num 1))))))
524 (setq gdb-var-changed t))
526 (defun gdb-var-list-children (varnum)
528 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
529 `(lambda () (gdb-var-list-children-handler ,varnum)))))
531 (defconst gdb-var-list-children-regexp
532 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
534 (defun gdb-var-list-children-handler (varnum)
535 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
536 (goto-char (point-min))
537 (let ((var-list nil))
538 (catch 'child-already-watched
539 (dolist (var gdb-var-list)
540 (if (string-equal varnum (cadr var))
543 (while (re-search-forward gdb-var-list-children-regexp nil t)
544 (let ((varchild (list (match-string 2)
548 (if (looking-at ",type=\"\\(.*?\\)\"")
549 (setcar (nthcdr 3 varchild) (match-string 1)))
550 (dolist (var1 gdb-var-list)
551 (if (string-equal (cadr var1) (cadr varchild))
552 (throw 'child-already-watched nil)))
553 (push varchild var-list)
554 (if (equal (nth 2 varchild) "0")
558 "server interpreter mi \"-var-evaluate-expression "
559 (nth 1 varchild) "\"\n")
560 `(lambda () (gdb-var-evaluate-expression-handler
561 ,(nth 1 varchild) nil))))))))
562 (push var var-list)))
563 (setq gdb-var-list (nreverse var-list))))))
565 (defun gdb-var-update ()
566 (when (not (member 'gdb-var-update gdb-pending-triggers))
568 (list "server interpreter mi \"-var-update *\"\n"
569 'gdb-var-update-handler))
570 (push 'gdb-var-update gdb-pending-triggers)))
572 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
574 (defun gdb-var-update-handler ()
575 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
576 (goto-char (point-min))
577 (while (re-search-forward gdb-var-update-regexp nil t)
578 (let ((varnum (match-string 1)))
581 (concat "server interpreter mi \"-var-evaluate-expression "
583 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
584 (setq gdb-pending-triggers
585 (delq 'gdb-var-update gdb-pending-triggers))
586 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
587 ;; Dummy command to update speedbar at right time.
588 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
589 ;; Keep gdb-pending-triggers non-nil till end.
590 (push 'gdb-speedbar-timer gdb-pending-triggers)))
592 (defun gdb-speedbar-timer-fn ()
593 (setq gdb-pending-triggers
594 (delq 'gdb-speedbar-timer gdb-pending-triggers))
595 (with-current-buffer gud-comint-buffer
596 (speedbar-timer-fn)))
598 (defun gdb-var-delete ()
599 "Delete watch expression at point from the speedbar."
601 (if (with-current-buffer
602 gud-comint-buffer (memq gud-minor-mode '(gdbmi gdba)))
603 (let ((text (speedbar-line-text)))
604 (string-match "\\(\\S-+\\)" text)
605 (let* ((expr (match-string 1 text))
606 (var (assoc expr gdb-var-list))
608 (unless (string-match "\\." varnum)
611 (if (with-current-buffer gud-comint-buffer
612 (eq gud-minor-mode 'gdba))
613 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
614 (concat "-var-delete " varnum "\n"))
616 (setq gdb-var-list (delq var gdb-var-list))
617 (dolist (varchild gdb-var-list)
618 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
619 (setq gdb-var-list (delq varchild gdb-var-list))))
620 (setq gdb-var-changed t))))))
622 (defun gdb-edit-value (text token indent)
623 "Assign a value to a variable displayed in the speedbar."
624 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
625 (varnum (cadr var)) (value))
626 (setq value (read-string "New value: "))
629 (if (with-current-buffer gud-comint-buffer
630 (eq gud-minor-mode 'gdba))
631 (concat "server interpreter mi \"-var-assign "
632 varnum " " value "\"\n")
633 (concat "-var-assign " varnum " " value "\n"))
636 (defcustom gdb-show-changed-values t
637 "If non-nil highlight values that have recently changed in the speedbar.
638 The highlighting is done with `font-lock-warning-face'."
643 (defun gdb-speedbar-expand-node (text token indent)
644 "Expand the node the user clicked on.
645 TEXT is the text of the button we clicked on, a + or - item.
646 TOKEN is data related to this node.
647 INDENT is the current indentation depth."
648 (cond ((string-match "+" text) ;expand this node
649 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
650 (gdb-var-list-children token)
653 (gdbmi-var-list-children token))))
654 ((string-match "-" text) ;contract this node
655 (dolist (var gdb-var-list)
656 (if (string-match (concat token "\\.") (nth 1 var))
657 (setq gdb-var-list (delq var gdb-var-list))))
658 (setq gdb-var-changed t)
659 (with-current-buffer gud-comint-buffer
660 (speedbar-timer-fn)))))
662 (defun gdb-get-target-string ()
663 (with-current-buffer gud-comint-buffer
670 ;; Each buffer has a TYPE -- a symbol that identifies the function
671 ;; of that particular buffer.
673 ;; The usual gdb interaction buffer is given the type `gdba' and
674 ;; is constructed specially.
676 ;; Others are constructed by gdb-get-create-buffer and
677 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
679 (defvar gdb-buffer-rules-assoc '())
681 (defun gdb-get-buffer (key)
682 "Return the gdb buffer tagged with type KEY.
683 The key should be one of the cars in `gdb-buffer-rules-assoc'."
685 (gdb-look-for-tagged-buffer key (buffer-list))))
687 (defun gdb-get-create-buffer (key)
688 "Create a new gdb buffer of the type specified by KEY.
689 The key should be one of the cars in `gdb-buffer-rules-assoc'."
690 (or (gdb-get-buffer key)
691 (let* ((rules (assoc key gdb-buffer-rules-assoc))
692 (name (funcall (gdb-rules-name-maker rules)))
693 (new (get-buffer-create name)))
694 (with-current-buffer new
696 (if (cdr (cdr rules))
697 (setq trigger (funcall (car (cdr (cdr rules))))))
698 (setq gdb-buffer-type key)
699 (set (make-local-variable 'gud-minor-mode)
700 (with-current-buffer gud-comint-buffer gud-minor-mode))
701 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
702 (if trigger (funcall trigger)))
705 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
707 (defun gdb-look-for-tagged-buffer (key bufs)
709 (while (and (not retval) bufs)
710 (set-buffer (car bufs))
711 (if (eq gdb-buffer-type key)
712 (setq retval (car bufs)))
713 (setq bufs (cdr bufs)))
717 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
718 ;; at least one and possible more functions. The functions have these
719 ;; roles in defining a buffer type:
721 ;; NAME - Return a name for this buffer type.
723 ;; The remaining function(s) are optional:
725 ;; MODE - called in a new buffer with no arguments, should establish
726 ;; the proper mode for the buffer.
729 (defun gdb-set-buffer-rules (buffer-type &rest rules)
730 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
732 (setcdr binding rules)
733 (push (cons buffer-type rules)
734 gdb-buffer-rules-assoc))))
736 ;; GUD buffers are an exception to the rules
737 (gdb-set-buffer-rules 'gdba 'error)
740 ;; Partial-output buffer : This accumulates output from a command executed on
741 ;; behalf of emacs (rather than the user).
743 (gdb-set-buffer-rules 'gdb-partial-output-buffer
744 'gdb-partial-output-name)
746 (defun gdb-partial-output-name ()
747 (concat "*partial-output-"
748 (gdb-get-target-string)
752 (gdb-set-buffer-rules 'gdb-inferior-io
753 'gdb-inferior-io-name
754 'gdb-inferior-io-mode)
756 (defun gdb-inferior-io-name ()
757 (concat "*input/output of "
758 (gdb-get-target-string)
761 (defun gdb-display-inferior-io-buffer ()
762 "Display IO of inferior in a separate window."
764 (if gdb-use-inferior-io-buffer
766 (gdb-get-create-buffer 'gdb-inferior-io))))
768 (defconst gdb-frame-parameters
769 '((height . 14) (width . 80)
771 (tool-bar-lines . nil)
772 (menu-bar-lines . nil)
775 (defun gdb-frame-inferior-io-buffer ()
776 "Display IO of inferior in a new frame."
778 (if gdb-use-inferior-io-buffer
779 (let ((special-display-regexps (append special-display-regexps '(".*")))
780 (special-display-frame-alist gdb-frame-parameters))
781 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
783 (defvar gdb-inferior-io-mode-map
784 (let ((map (make-sparse-keymap)))
785 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
786 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
787 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
788 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
789 (define-key map "\C-d" 'gdb-inferior-io-eof)
792 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
793 "Major mode for gdb inferior-io."
794 :syntax-table nil :abbrev-table nil
795 ;; We want to use comint because it has various nifty and familiar
796 ;; features. We don't need a process, but comint wants one, so create
798 (make-comint-in-buffer
799 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
800 (current-buffer) "hexl")
801 (setq comint-input-sender 'gdb-inferior-io-sender))
803 (defun gdb-inferior-io-sender (proc string)
804 ;; PROC is the pseudo-process created to satisfy comint.
805 (with-current-buffer (process-buffer proc)
806 (setq proc (get-buffer-process gud-comint-buffer))
807 (process-send-string proc string)
808 (process-send-string proc "\n")))
810 (defun gdb-inferior-io-interrupt ()
811 "Interrupt the program being debugged."
814 (get-buffer-process gud-comint-buffer) comint-ptyp))
816 (defun gdb-inferior-io-quit ()
817 "Send quit signal to the program being debugged."
820 (get-buffer-process gud-comint-buffer) comint-ptyp))
822 (defun gdb-inferior-io-stop ()
823 "Stop the program being debugged."
826 (get-buffer-process gud-comint-buffer) comint-ptyp))
828 (defun gdb-inferior-io-eof ()
829 "Send end-of-file to the program being debugged."
832 (get-buffer-process gud-comint-buffer)))
836 ;; gdb communications
839 ;; INPUT: things sent to gdb
841 ;; The queues are lists. Each element is either a string (indicating user or
842 ;; user-like input) or a list of the form:
844 ;; (INPUT-STRING HANDLER-FN)
846 ;; The handler function will be called from the partial-output buffer when the
847 ;; command completes. This is the way to write commands which invoke gdb
848 ;; commands autonomously.
850 ;; These lists are consumed tail first.
853 (defun gdb-send (proc string)
854 "A comint send filter for gdb.
855 This filter may simply queue input for a later time."
856 (with-current-buffer gud-comint-buffer
857 (let ((inhibit-read-only t))
858 (remove-text-properties (point-min) (point-max) '(face))))
859 (let ((item (concat string "\n")))
862 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
863 (process-send-string proc item))
864 (gdb-enqueue-input item))))
866 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
867 ;; is a query, or other non-top-level prompt.
869 (defun gdb-enqueue-input (item)
873 (setq gdb-prompting nil))
874 (push item gdb-input-queue)))
876 (defun gdb-dequeue-input ()
877 (let ((queue gdb-input-queue))
879 (let ((last (car (last queue))))
880 (unless (nbutlast queue) (setq gdb-input-queue '()))
883 (defun gdb-send-item (item)
884 (setq gdb-flush-pending-output nil)
885 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
886 (setq gdb-current-item item)
887 (with-current-buffer gud-comint-buffer
888 (if (eq gud-minor-mode 'gdba)
891 (setq gdb-output-sink 'user)
892 (process-send-string (get-buffer-process gud-comint-buffer) item))
894 (gdb-clear-partial-output)
895 (setq gdb-output-sink 'pre-emacs)
896 (process-send-string (get-buffer-process gud-comint-buffer)
898 ;; case: eq gud-minor-mode 'gdbmi
899 (gdb-clear-partial-output)
900 (setq gdb-output-sink 'emacs)
901 (process-send-string (get-buffer-process gud-comint-buffer)
905 ;; output -- things gdb prints to emacs
907 ;; GDB output is a stream interrupted by annotations.
908 ;; Annotations can be recognized by their beginning
909 ;; with \C-j\C-z\C-z<tag><opt>\C-j
911 ;; The tag is a string obeying symbol syntax.
913 ;; The optional part `<opt>' can be either the empty string
914 ;; or a space followed by more data relating to the annotation.
915 ;; For example, the SOURCE annotation is followed by a filename,
916 ;; line number and various useless goo. This data must not include
920 (defcustom gud-gdba-command-name "gdb -annotate=3"
921 "Default command to execute an executable under the GDB-UI debugger."
926 (defvar gdb-annotation-rules
927 '(("pre-prompt" gdb-pre-prompt)
928 ("prompt" gdb-prompt)
929 ("commands" gdb-subprompt)
930 ("overload-choice" gdb-subprompt)
931 ("query" gdb-subprompt)
932 ;; Need this prompt for GDB 6.1
933 ("nquery" gdb-subprompt)
934 ("prompt-for-continue" gdb-subprompt)
935 ("post-prompt" gdb-post-prompt)
936 ("source" gdb-source)
937 ("starting" gdb-starting)
938 ("exited" gdb-exited)
939 ("signalled" gdb-exited)
940 ("signal" gdb-stopping)
941 ("breakpoint" gdb-stopping)
942 ("watchpoint" gdb-stopping)
943 ("frame-begin" gdb-frame-begin)
944 ("stopped" gdb-stopped)
945 ("error-begin" gdb-error)
947 ) "An assoc mapping annotation tags to functions which process them.")
950 (setq gdb-flush-pending-output t)
951 (setq gud-running nil)
952 (setq gdb-output-sink 'user)
953 (setq gdb-input-queue nil)
954 (setq gdb-pending-triggers nil)
955 (setq gdb-prompting t))
957 (defconst gdb-source-spec-regexp
958 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
960 ;; Do not use this except as an annotation handler.
961 (defun gdb-source (args)
962 (string-match gdb-source-spec-regexp args)
963 ;; Extract the frame position from the marker.
966 (match-string 1 args)
967 (string-to-number (match-string 2 args))))
968 (setq gdb-frame-address (match-string 3 args))
969 ;; cover for auto-display output which comes *before*
970 ;; stopped annotation
971 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
973 (defun gdb-pre-prompt (ignored)
974 "An annotation handler for `pre-prompt'.
975 This terminates the collection of output from a previous command if that
976 happens to be in effect."
977 (let ((sink gdb-output-sink))
981 (setq gdb-output-sink 'post-emacs))
984 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
986 (defun gdb-prompt (ignored)
987 "An annotation handler for `prompt'.
988 This sends the next command (if any) to gdb."
989 (when gdb-first-prompt (gdb-ann3))
990 (let ((sink gdb-output-sink))
993 ((eq sink 'post-emacs)
994 (setq gdb-output-sink 'user)
996 (car (cdr gdb-current-item))))
997 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1001 (error "Phase error in gdb-prompt (got %s)" sink))))
1002 (let ((input (gdb-dequeue-input)))
1004 (gdb-send-item input)
1006 (setq gdb-prompting t)
1007 (gud-display-frame)))))
1009 (defun gdb-subprompt (ignored)
1010 "An annotation handler for non-top-level prompts."
1011 (setq gdb-prompting t))
1013 (defun gdb-starting (ignored)
1014 "An annotation handler for `starting'.
1015 This says that I/O for the subprocess is now the program being debugged,
1017 (setq gdb-active-process t)
1018 (let ((sink gdb-output-sink))
1022 (setq gud-running t)
1023 (if gdb-use-inferior-io-buffer
1024 (setq gdb-output-sink 'inferior))))
1027 (error "Unexpected `starting' annotation")))))
1029 (defun gdb-stopping (ignored)
1030 "An annotation handler for `breakpoint' and other annotations.
1031 They say that I/O for the subprocess is now GDB, not the program
1033 (if gdb-use-inferior-io-buffer
1034 (let ((sink gdb-output-sink))
1036 ((eq sink 'inferior)
1037 (setq gdb-output-sink 'user))
1040 (error "Unexpected stopping annotation"))))))
1042 (defun gdb-exited (ignored)
1043 "An annotation handler for `exited' and `signalled'.
1044 They say that I/O for the subprocess is now GDB, not the program
1045 being debugged and that the program is no longer running. This
1046 function is used to change the focus of GUD tooltips to #define
1048 (setq gdb-active-process nil)
1049 (setq gud-overlay-arrow-position nil)
1050 (setq gdb-overlay-arrow-position nil)
1051 (gdb-stopping ignored))
1053 (defun gdb-frame-begin (ignored)
1054 (let ((sink gdb-output-sink))
1056 ((eq sink 'inferior)
1057 (setq gdb-output-sink 'user))
1059 ((eq sink 'emacs) t)
1062 (error "Unexpected frame-begin annotation (%S)" sink)))))
1064 (defun gdb-stopped (ignored)
1065 "An annotation handler for `stopped'.
1066 It is just like `gdb-stopping', except that if we already set the output
1067 sink to `user' in `gdb-stopping', that is fine."
1068 (setq gud-running nil)
1069 (let ((sink gdb-output-sink))
1071 ((eq sink 'inferior)
1072 (setq gdb-output-sink 'user))
1076 (error "Unexpected stopped annotation")))))
1078 (defun gdb-error (ignored)
1079 (setq gdb-error (not gdb-error)))
1081 (defun gdb-post-prompt (ignored)
1082 "An annotation handler for `post-prompt'.
1083 This begins the collection of output from the current command if that
1084 happens to be appropriate."
1085 (unless gdb-pending-triggers
1086 (gdb-get-selected-frame)
1087 (gdb-invalidate-frames)
1088 (gdb-invalidate-breakpoints)
1089 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1090 ;; so gdb-frame-address is updated.
1091 ;; (gdb-invalidate-assembler)
1092 (gdb-invalidate-registers)
1093 (gdb-invalidate-memory)
1094 (gdb-invalidate-locals)
1095 (gdb-invalidate-threads)
1096 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1097 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1098 ;; Only needed/used with speedbar/watch expressions.
1099 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1100 (setq gdb-var-changed t) ; force update
1101 (dolist (var gdb-var-list)
1102 (setcar (nthcdr 5 var) nil))
1104 (let ((sink gdb-output-sink))
1107 ((eq sink 'pre-emacs)
1108 (setq gdb-output-sink 'emacs))
1111 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1113 (defun gud-gdba-marker-filter (string)
1114 "A gud marker filter for gdb. Handle a burst of output from GDB."
1115 (if gdb-flush-pending-output
1117 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1118 ;; Recall the left over gud-marker-acc from last time.
1119 (setq gud-marker-acc (concat gud-marker-acc string))
1120 ;; Start accumulating output for the GUD buffer.
1123 ;; Process all the complete markers in this chunk.
1124 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1125 (let ((annotation (match-string 1 gud-marker-acc)))
1127 ;; Stuff prior to the match is just ordinary output.
1128 ;; It is either concatenated to OUTPUT or directed
1133 (substring gud-marker-acc 0 (match-beginning 0))))
1135 ;; Take that stuff off the gud-marker-acc.
1136 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1138 ;; Parse the tag from the annotation, and maybe its arguments.
1139 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1140 (let* ((annotation-type (match-string 1 annotation))
1141 (annotation-arguments (match-string 2 annotation))
1142 (annotation-rule (assoc annotation-type
1143 gdb-annotation-rules)))
1144 ;; Call the handler for this annotation.
1146 (funcall (car (cdr annotation-rule))
1147 annotation-arguments)
1148 ;; Else the annotation is not recognized. Ignore it silently,
1149 ;; so that GDB can add new annotations without causing
1153 ;; Does the remaining text end in a partial line?
1154 ;; If it does, then keep part of the gud-marker-acc until we get more.
1155 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1158 ;; Everything before the potential marker start can be output.
1160 (gdb-concat-output output
1161 (substring gud-marker-acc 0
1162 (match-beginning 0))))
1164 ;; Everything after, we save, to combine with later input.
1165 (setq gud-marker-acc (substring gud-marker-acc
1166 (match-beginning 0))))
1168 ;; In case we know the gud-marker-acc contains no partial annotations:
1170 (setq output (gdb-concat-output output gud-marker-acc))
1171 (setq gud-marker-acc "")))
1174 (defun gdb-concat-output (so-far new)
1176 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1177 (let ((sink gdb-output-sink))
1179 ((eq sink 'user) (concat so-far new))
1180 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1182 (gdb-append-to-partial-output new)
1184 ((eq sink 'inferior)
1185 (gdb-append-to-inferior-io new)
1189 (error "Bogon output sink %S" sink)))))
1191 (defun gdb-append-to-partial-output (string)
1192 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1193 (goto-char (point-max))
1196 (defun gdb-clear-partial-output ()
1197 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1200 (defun gdb-append-to-inferior-io (string)
1201 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1202 (goto-char (point-max))
1203 (insert-before-markers string))
1204 (if (not (string-equal string ""))
1205 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1207 (defun gdb-clear-inferior-io ()
1208 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1212 ;; One trick is to have a command who's output is always available in a buffer
1213 ;; of it's own, and is always up to date. We build several buffers of this
1216 ;; There are two aspects to this: gdb has to tell us when the output for that
1217 ;; command might have changed, and we have to be able to run the command
1218 ;; behind the user's back.
1220 ;; The output phasing associated with the variable gdb-output-sink
1221 ;; help us to run commands behind the user's back.
1223 ;; Below is the code for specificly managing buffers of output from one
1227 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1228 ;; It adds an input for the command we are tracking. It should be the
1229 ;; annotation rule binding of whatever gdb sends to tell us this command
1230 ;; might have changed it's output.
1232 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1233 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1234 ;; input in the input queue (see comment about ``gdb communications'' above).
1236 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1238 `(defun ,name (&optional ignored)
1239 (if (and ,demand-predicate
1241 gdb-pending-triggers)))
1244 (list ,gdb-command ',output-handler))
1245 (push ',name gdb-pending-triggers)))))
1247 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1249 (setq gdb-pending-triggers
1251 gdb-pending-triggers))
1252 (let ((buf (gdb-get-buffer ',buf-key)))
1254 (with-current-buffer buf
1255 (let* ((window (get-buffer-window buf 0))
1256 (p (window-point window))
1257 (buffer-read-only nil))
1259 (insert-buffer-substring (gdb-get-create-buffer
1260 'gdb-partial-output-buffer))
1261 (set-window-point window p)))))
1262 ;; put customisation here
1265 (defmacro def-gdb-auto-updated-buffer (buffer-key
1266 trigger-name gdb-command
1267 output-handler-name custom-defun)
1269 (def-gdb-auto-update-trigger ,trigger-name
1270 ;; The demand predicate:
1271 (gdb-get-buffer ',buffer-key)
1273 ,output-handler-name)
1274 (def-gdb-auto-update-handler ,output-handler-name
1275 ,trigger-name ,buffer-key ,custom-defun)))
1279 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1281 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1282 'gdb-breakpoints-buffer-name
1283 'gdb-breakpoints-mode)
1285 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1286 ;; This defines the auto update rule for buffers of type
1287 ;; `gdb-breakpoints-buffer'.
1289 ;; It defines a function to serve as the annotation handler that
1290 ;; handles the `foo-invalidated' message. That function is called:
1291 gdb-invalidate-breakpoints
1293 ;; To update the buffer, this command is sent to gdb.
1294 "server info breakpoints\n"
1296 ;; This also defines a function to be the handler for the output
1297 ;; from the command above. That function will copy the output into
1298 ;; the appropriately typed buffer. That function will be called:
1299 gdb-info-breakpoints-handler
1300 ;; buffer specific functions
1301 gdb-info-breakpoints-custom)
1303 (defconst breakpoint-xpm-data
1305 static char *magick[] = {
1306 /* columns rows colors chars-per-pixel */
1322 "XPM data used for breakpoint icon.")
1324 (defconst breakpoint-enabled-pbm-data
1327 0 0 0 0 1 1 1 1 0 0 0 0
1328 0 0 0 1 1 1 1 1 1 0 0 0
1329 0 0 1 1 1 1 1 1 1 1 0 0
1330 0 1 1 1 1 1 1 1 1 1 1 0
1331 0 1 1 1 1 1 1 1 1 1 1 0
1332 0 1 1 1 1 1 1 1 1 1 1 0
1333 0 1 1 1 1 1 1 1 1 1 1 0
1334 0 0 1 1 1 1 1 1 1 1 0 0
1335 0 0 0 1 1 1 1 1 1 0 0 0
1336 0 0 0 0 1 1 1 1 0 0 0 0"
1337 "PBM data used for enabled breakpoint icon.")
1339 (defconst breakpoint-disabled-pbm-data
1351 0 0 0 1 0 1 0 1 0 0"
1352 "PBM data used for disabled breakpoint icon.")
1354 (defvar breakpoint-enabled-icon nil
1355 "Icon for enabled breakpoint in display margin.")
1357 (defvar breakpoint-disabled-icon nil
1358 "Icon for disabled breakpoint in display margin.")
1360 ;; Bitmap for breakpoint in fringe
1361 (and (display-images-p)
1362 (define-fringe-bitmap 'breakpoint
1363 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1365 (defface breakpoint-enabled
1369 "Face for enabled breakpoint icon in fringe."
1371 ;; Compatibility alias for old name.
1372 (put 'breakpoint-enabled-bitmap-face 'face-alias 'breakpoint-enabled)
1374 (defface breakpoint-disabled
1375 ;; We use different values of grey for different background types,
1376 ;; so that on low-color displays it will end up as something visible
1377 ;; if it has to be approximated.
1378 '((((background dark)) :foreground "grey60")
1379 (((background light)) :foreground "grey40"))
1380 "Face for disabled breakpoint icon in fringe."
1383 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1384 (defun gdb-info-breakpoints-custom ()
1385 (let ((flag) (bptno))
1386 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1387 (dolist (buffer (buffer-list))
1388 (with-current-buffer buffer
1389 (if (and (eq gud-minor-mode 'gdba)
1390 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1391 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1392 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1394 (goto-char (point-min))
1395 (while (< (point) (- (point-max) 1))
1397 (if (looking-at "[^\t].*?breakpoint")
1399 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1400 (setq bptno (match-string 1))
1401 (setq flag (char-after (match-beginning 2)))
1403 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1405 (let ((buffer-read-only nil))
1406 (add-text-properties (match-beginning 1) (match-end 1)
1407 '(face font-lock-function-name-face)))
1408 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1409 (let ((line (match-string 2)) (buffer-read-only nil)
1410 (file (match-string 1)))
1411 (add-text-properties (line-beginning-position)
1413 '(mouse-face highlight
1414 help-echo "mouse-2, RET: visit breakpoint"))
1415 (unless (file-exists-p file)
1416 (setq file (cdr (assoc bptno gdb-location-alist))))
1418 (not (string-equal file "File not found")))
1419 (with-current-buffer
1420 (find-file-noselect file 'nowarn)
1421 (set (make-local-variable 'gud-minor-mode)
1423 (set (make-local-variable 'tool-bar-map)
1425 ;; Only want one breakpoint icon at each
1428 (goto-line (string-to-number line))
1429 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1433 (match-string-no-properties 1) ":1\n")
1436 (list "info source\n"
1437 `(lambda () (gdb-get-location
1438 ,bptno ,line ,flag))))))))))
1440 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1442 (defun gdb-mouse-set-clear-breakpoint (event)
1443 "Set/clear breakpoint in left fringe/margin with mouse click."
1445 (mouse-minibuffer-check event)
1446 (let ((posn (event-end event)))
1447 (if (numberp (posn-point posn))
1448 (with-selected-window (posn-window posn)
1450 (goto-char (posn-point posn))
1451 (if (or (posn-object posn)
1452 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1455 (gud-break nil)))))))
1457 (defun gdb-mouse-toggle-breakpoint-margin (event)
1458 "Enable/disable breakpoint in left margin with mouse click."
1460 (mouse-minibuffer-check event)
1461 (let ((posn (event-end event)))
1462 (if (numberp (posn-point posn))
1463 (with-selected-window (posn-window posn)
1465 (goto-char (posn-point posn))
1466 (if (posn-object posn)
1469 (let ((bptno (get-text-property
1470 0 'gdb-bptno (car (posn-string posn)))))
1472 (if (get-text-property
1473 0 'gdb-enabled (car (posn-string posn)))
1479 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1480 "Enable/disable breakpoint in left fringe with mouse click."
1482 (mouse-minibuffer-check event)
1483 (let* ((posn (event-end event))
1484 (pos (posn-point posn))
1487 (with-selected-window (posn-window posn)
1489 (set-buffer (window-buffer (selected-window)))
1491 (dolist (overlay (overlays-in pos pos))
1492 (when (overlay-get overlay 'put-break)
1493 (setq obj (overlay-get overlay 'before-string))))
1498 (if (get-text-property 0 'gdb-enabled obj)
1501 (get-text-property 0 'gdb-bptno obj) "\n")
1504 (defun gdb-breakpoints-buffer-name ()
1505 (with-current-buffer gud-comint-buffer
1506 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1508 (defun gdb-display-breakpoints-buffer ()
1509 "Display status of user-settable breakpoints."
1512 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1514 (defun gdb-frame-breakpoints-buffer ()
1515 "Display status of user-settable breakpoints in a new frame."
1517 (let ((special-display-regexps (append special-display-regexps '(".*")))
1518 (special-display-frame-alist gdb-frame-parameters))
1519 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1521 (defvar gdb-breakpoints-mode-map
1522 (let ((map (make-sparse-keymap))
1523 (menu (make-sparse-keymap "Breakpoints")))
1524 (define-key menu [quit] '("Quit" . kill-this-buffer))
1525 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1526 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1527 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1528 (suppress-keymap map)
1529 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1530 (define-key map " " 'gdb-toggle-breakpoint)
1531 (define-key map "d" 'gdb-delete-breakpoint)
1532 (define-key map "q" 'kill-this-buffer)
1533 (define-key map "\r" 'gdb-goto-breakpoint)
1534 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1535 (define-key map [follow-link] 'mouse-face)
1538 (defun gdb-breakpoints-mode ()
1539 "Major mode for gdb breakpoints.
1541 \\{gdb-breakpoints-mode-map}"
1542 (kill-all-local-variables)
1543 (setq major-mode 'gdb-breakpoints-mode)
1544 (setq mode-name "Breakpoints")
1545 (use-local-map gdb-breakpoints-mode-map)
1546 (setq buffer-read-only t)
1547 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1548 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1549 'gdb-invalidate-breakpoints
1550 'gdbmi-invalidate-breakpoints))
1552 (defun gdb-toggle-breakpoint ()
1553 "Enable/disable breakpoint at current line."
1556 (beginning-of-line 1)
1557 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1558 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1560 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1563 (concat gdb-server-prefix
1564 (if (eq ?y (char-after (match-beginning 2)))
1567 (match-string 1) "\n") 'ignore))
1568 (error "Not recognized as break/watchpoint line"))))
1570 (defun gdb-delete-breakpoint ()
1571 "Delete the breakpoint at current line."
1573 (beginning-of-line 1)
1574 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1575 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1577 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1580 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1581 (error "Not recognized as break/watchpoint line")))
1583 (defun gdb-goto-breakpoint (&optional event)
1584 "Display the breakpoint location specified at current line."
1585 (interactive (list last-input-event))
1586 (if event (mouse-set-point event))
1587 ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
1588 (let ((window (get-buffer-window gud-comint-buffer)))
1589 (if window (save-selected-window (select-window window))))
1591 (beginning-of-line 1)
1592 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1593 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1595 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1596 \\(\\S-+\\):\\([0-9]+\\)"))
1597 (let ((bptno (match-string 1))
1598 (file (match-string 2))
1599 (line (match-string 3)))
1600 (save-selected-window
1601 (let* ((buf (find-file-noselect
1602 (if (file-exists-p file) file
1603 (cdr (assoc bptno gdb-location-alist)))))
1604 (window (display-buffer buf)))
1605 (with-current-buffer buf
1606 (goto-line (string-to-number line))
1607 (set-window-point window (point))))))
1608 (error "Not recognized as break/watchpoint line"))))
1611 ;; Frames buffer. This displays a perpetually correct bactracktrace
1612 ;; (from the command `where').
1614 ;; Alas, if your stack is deep, it is costly.
1616 (gdb-set-buffer-rules 'gdb-stack-buffer
1617 'gdb-stack-buffer-name
1620 (def-gdb-auto-updated-buffer gdb-stack-buffer
1621 gdb-invalidate-frames
1623 gdb-info-frames-handler
1624 gdb-info-frames-custom)
1626 (defun gdb-info-frames-custom ()
1627 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1629 (let ((buffer-read-only nil)
1631 (goto-char (point-min))
1632 (while (< (point) (point-max))
1633 (setq bl (line-beginning-position)
1634 el (line-end-position))
1635 (unless (looking-at "No ")
1636 (add-text-properties bl el
1637 '(mouse-face highlight
1638 help-echo "mouse-2, RET: Select frame")))
1640 (when (looking-at "^#\\([0-9]+\\)")
1641 (when (string-equal (match-string 1) gdb-frame-number)
1642 (put-text-property bl (+ bl 4)
1643 'face '(:inverse-video t)))
1644 (when (re-search-forward
1646 (if (string-equal (match-string 1) "0") "" " in ")
1647 "\\([^ ]+\\) (") el t)
1648 (put-text-property (match-beginning 1) (match-end 1)
1649 'face font-lock-function-name-face)
1650 (setq bl (match-end 0))
1651 (while (re-search-forward "<\\([^>]+\\)>" el t)
1652 (put-text-property (match-beginning 1) (match-end 1)
1653 'face font-lock-function-name-face))
1655 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1656 (put-text-property (match-beginning 1) (match-end 1)
1657 'face font-lock-variable-name-face))))
1658 (forward-line 1))))))
1660 (defun gdb-stack-buffer-name ()
1661 (with-current-buffer gud-comint-buffer
1662 (concat "*stack frames of " (gdb-get-target-string) "*")))
1664 (defun gdb-display-stack-buffer ()
1665 "Display backtrace of current stack."
1668 (gdb-get-create-buffer 'gdb-stack-buffer)))
1670 (defun gdb-frame-stack-buffer ()
1671 "Display backtrace of current stack in a new frame."
1673 (let ((special-display-regexps (append special-display-regexps '(".*")))
1674 (special-display-frame-alist gdb-frame-parameters))
1675 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1677 (defvar gdb-frames-mode-map
1678 (let ((map (make-sparse-keymap)))
1679 (suppress-keymap map)
1680 (define-key map "q" 'kill-this-buffer)
1681 (define-key map "\r" 'gdb-frames-select)
1682 (define-key map [mouse-2] 'gdb-frames-select)
1683 (define-key map [follow-link] 'mouse-face)
1686 (defun gdb-frames-mode ()
1687 "Major mode for gdb frames.
1689 \\{gdb-frames-mode-map}"
1690 (kill-all-local-variables)
1691 (setq major-mode 'gdb-frames-mode)
1692 (setq mode-name "Frames")
1693 (setq buffer-read-only t)
1694 (use-local-map gdb-frames-mode-map)
1696 (run-mode-hooks 'gdb-frames-mode-hook)
1697 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1698 'gdb-invalidate-frames
1699 'gdbmi-invalidate-frames))
1701 (defun gdb-get-frame-number ()
1704 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1705 (n (or (and pos (match-string-no-properties 1)) "0")))
1708 (defun gdb-frames-select (&optional event)
1709 "Select the frame and display the relevant source."
1710 (interactive (list last-input-event))
1711 (if event (mouse-set-point event))
1713 (list (concat gdb-server-prefix "frame "
1714 (gdb-get-frame-number) "\n") 'ignore))
1715 (gud-display-frame))
1718 ;; Threads buffer. This displays a selectable thread list.
1720 (gdb-set-buffer-rules 'gdb-threads-buffer
1721 'gdb-threads-buffer-name
1724 (def-gdb-auto-updated-buffer gdb-threads-buffer
1725 gdb-invalidate-threads
1726 (concat gdb-server-prefix "info threads\n")
1727 gdb-info-threads-handler
1728 gdb-info-threads-custom)
1730 (defun gdb-info-threads-custom ()
1731 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1732 (let ((buffer-read-only nil))
1733 (goto-char (point-min))
1734 (while (< (point) (point-max))
1735 (unless (looking-at "No ")
1736 (add-text-properties (line-beginning-position) (line-end-position)
1737 '(mouse-face highlight
1738 help-echo "mouse-2, RET: select thread")))
1739 (forward-line 1)))))
1741 (defun gdb-threads-buffer-name ()
1742 (with-current-buffer gud-comint-buffer
1743 (concat "*threads of " (gdb-get-target-string) "*")))
1745 (defun gdb-display-threads-buffer ()
1746 "Display IDs of currently known threads."
1749 (gdb-get-create-buffer 'gdb-threads-buffer)))
1751 (defun gdb-frame-threads-buffer ()
1752 "Display IDs of currently known threads in a new frame."
1754 (let ((special-display-regexps (append special-display-regexps '(".*")))
1755 (special-display-frame-alist gdb-frame-parameters))
1756 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1758 (defvar gdb-threads-mode-map
1759 (let ((map (make-sparse-keymap)))
1760 (suppress-keymap map)
1761 (define-key map "q" 'kill-this-buffer)
1762 (define-key map "\r" 'gdb-threads-select)
1763 (define-key map [mouse-2] 'gdb-threads-select)
1766 (defvar gdb-threads-font-lock-keywords
1768 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1769 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1770 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1772 "Font lock keywords used in `gdb-threads-mode'.")
1774 (defun gdb-threads-mode ()
1775 "Major mode for gdb frames.
1777 \\{gdb-threads-mode-map}"
1778 (kill-all-local-variables)
1779 (setq major-mode 'gdb-threads-mode)
1780 (setq mode-name "Threads")
1781 (setq buffer-read-only t)
1782 (use-local-map gdb-threads-mode-map)
1783 (set (make-local-variable 'font-lock-defaults)
1784 '(gdb-threads-font-lock-keywords))
1785 (run-mode-hooks 'gdb-threads-mode-hook)
1786 'gdb-invalidate-threads)
1788 (defun gdb-get-thread-number ()
1790 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1791 (match-string-no-properties 1)))
1793 (defun gdb-threads-select (&optional event)
1794 "Select the thread and display the relevant source."
1795 (interactive (list last-input-event))
1796 (if event (mouse-set-point event))
1798 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1799 (gud-display-frame))
1802 ;; Registers buffer.
1804 (defcustom gdb-all-registers nil
1805 "Non-nil means include floating-point registers."
1810 (gdb-set-buffer-rules 'gdb-registers-buffer
1811 'gdb-registers-buffer-name
1812 'gdb-registers-mode)
1814 (def-gdb-auto-updated-buffer gdb-registers-buffer
1815 gdb-invalidate-registers
1817 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1818 gdb-info-registers-handler
1819 gdb-info-registers-custom)
1821 (defun gdb-info-registers-custom ()
1822 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1824 (let ((buffer-read-only nil)
1826 (goto-char (point-min))
1827 (while (< (point) (point-max))
1828 (setq bl (line-beginning-position))
1829 (when (looking-at "^[^ ]+")
1830 (unless (string-equal (match-string 0) "The")
1831 (put-text-property bl (match-end 0)
1832 'face font-lock-variable-name-face)))
1833 (forward-line 1))))))
1835 (defvar gdb-registers-mode-map
1836 (let ((map (make-sparse-keymap)))
1837 (suppress-keymap map)
1838 (define-key map " " 'toggle-gdb-all-registers)
1839 (define-key map "q" 'kill-this-buffer)
1842 (defun gdb-registers-mode ()
1843 "Major mode for gdb registers.
1845 \\{gdb-registers-mode-map}"
1846 (kill-all-local-variables)
1847 (setq major-mode 'gdb-registers-mode)
1848 (setq mode-name "Registers:")
1849 (setq buffer-read-only t)
1850 (use-local-map gdb-registers-mode-map)
1851 (run-mode-hooks 'gdb-registers-mode-hook)
1852 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1853 'gdb-invalidate-registers
1854 'gdbmi-invalidate-registers))
1856 (defun gdb-registers-buffer-name ()
1857 (with-current-buffer gud-comint-buffer
1858 (concat "*registers of " (gdb-get-target-string) "*")))
1860 (defun gdb-display-registers-buffer ()
1861 "Display integer register contents."
1864 (gdb-get-create-buffer 'gdb-registers-buffer)))
1866 (defun gdb-frame-registers-buffer ()
1867 "Display integer register contents in a new frame."
1869 (let ((special-display-regexps (append special-display-regexps '(".*")))
1870 (special-display-frame-alist gdb-frame-parameters))
1871 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1873 (defun toggle-gdb-all-registers ()
1874 "Toggle the display of floating-point registers."
1876 (if gdb-all-registers
1878 (setq gdb-all-registers nil)
1879 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1880 (setq mode-name "Registers:")))
1881 (setq gdb-all-registers t)
1882 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1883 (setq mode-name "Registers:All")))
1884 (gdb-invalidate-registers))
1889 (defcustom gdb-memory-repeat-count 32
1890 "Number of data items in memory window."
1895 (defcustom gdb-memory-format "x"
1896 "Display format of data items in memory window."
1897 :type '(choice (const :tag "Hexadecimal" "x")
1898 (const :tag "Signed decimal" "d")
1899 (const :tag "Unsigned decimal" "u")
1900 (const :tag "Octal" "o")
1901 (const :tag "Binary" "t"))
1905 (defcustom gdb-memory-unit "w"
1906 "Unit size of data items in memory window."
1907 :type '(choice (const :tag "Byte" "b")
1908 (const :tag "Halfword" "h")
1909 (const :tag "Word" "w")
1910 (const :tag "Giant word" "g"))
1914 (gdb-set-buffer-rules 'gdb-memory-buffer
1915 'gdb-memory-buffer-name
1918 (def-gdb-auto-updated-buffer gdb-memory-buffer
1919 gdb-invalidate-memory
1920 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1921 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1922 gdb-read-memory-handler
1923 gdb-read-memory-custom)
1925 (defun gdb-read-memory-custom ()
1927 (goto-char (point-min))
1928 (if (looking-at "0x[[:xdigit:]]+")
1929 (setq gdb-memory-address (match-string 0)))))
1931 (defvar gdb-memory-mode-map
1932 (let ((map (make-sparse-keymap)))
1933 (suppress-keymap map)
1934 (define-key map "q" 'kill-this-buffer)
1937 (defun gdb-memory-set-address (event)
1938 "Set the start memory address."
1940 (save-selected-window
1941 (select-window (posn-window (event-start event)))
1942 (let ((arg (read-from-minibuffer "Memory address: ")))
1943 (setq gdb-memory-address arg))
1944 (gdb-invalidate-memory)))
1946 (defun gdb-memory-set-repeat-count (event)
1947 "Set the number of data items in memory window."
1949 (save-selected-window
1950 (select-window (posn-window (event-start event)))
1951 (let* ((arg (read-from-minibuffer "Repeat count: "))
1952 (count (string-to-number arg)))
1954 (error "Positive numbers only")
1955 (customize-set-variable 'gdb-memory-repeat-count count)
1956 (gdb-invalidate-memory)))))
1958 (defun gdb-memory-format-binary ()
1959 "Set the display format to binary."
1961 (customize-set-variable 'gdb-memory-format "t")
1962 (gdb-invalidate-memory))
1964 (defun gdb-memory-format-octal ()
1965 "Set the display format to octal."
1967 (customize-set-variable 'gdb-memory-format "o")
1968 (gdb-invalidate-memory))
1970 (defun gdb-memory-format-unsigned ()
1971 "Set the display format to unsigned decimal."
1973 (customize-set-variable 'gdb-memory-format "u")
1974 (gdb-invalidate-memory))
1976 (defun gdb-memory-format-signed ()
1977 "Set the display format to decimal."
1979 (customize-set-variable 'gdb-memory-format "d")
1980 (gdb-invalidate-memory))
1982 (defun gdb-memory-format-hexadecimal ()
1983 "Set the display format to hexadecimal."
1985 (customize-set-variable 'gdb-memory-format "x")
1986 (gdb-invalidate-memory))
1988 (defvar gdb-memory-format-keymap
1989 (let ((map (make-sparse-keymap)))
1990 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1992 "Keymap to select format in the header line.")
1994 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1995 "Menu of display formats in the header line.")
1997 (define-key gdb-memory-format-menu [binary]
1998 '(menu-item "Binary" gdb-memory-format-binary
1999 :button (:radio . (equal gdb-memory-format "t"))))
2000 (define-key gdb-memory-format-menu [octal]
2001 '(menu-item "Octal" gdb-memory-format-octal
2002 :button (:radio . (equal gdb-memory-format "o"))))
2003 (define-key gdb-memory-format-menu [unsigned]
2004 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2005 :button (:radio . (equal gdb-memory-format "u"))))
2006 (define-key gdb-memory-format-menu [signed]
2007 '(menu-item "Signed Decimal" gdb-memory-format-signed
2008 :button (:radio . (equal gdb-memory-format "d"))))
2009 (define-key gdb-memory-format-menu [hexadecimal]
2010 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2011 :button (:radio . (equal gdb-memory-format "x"))))
2013 (defun gdb-memory-format-menu (event)
2015 (x-popup-menu event gdb-memory-format-menu))
2017 (defun gdb-memory-format-menu-1 (event)
2019 (save-selected-window
2020 (select-window (posn-window (event-start event)))
2021 (let* ((selection (gdb-memory-format-menu event))
2022 (binding (and selection (lookup-key gdb-memory-format-menu
2023 (vector (car selection))))))
2024 (if binding (call-interactively binding)))))
2026 (defun gdb-memory-unit-giant ()
2027 "Set the unit size to giant words (eight bytes)."
2029 (customize-set-variable 'gdb-memory-unit "g")
2030 (gdb-invalidate-memory))
2032 (defun gdb-memory-unit-word ()
2033 "Set the unit size to words (four bytes)."
2035 (customize-set-variable 'gdb-memory-unit "w")
2036 (gdb-invalidate-memory))
2038 (defun gdb-memory-unit-halfword ()
2039 "Set the unit size to halfwords (two bytes)."
2041 (customize-set-variable 'gdb-memory-unit "h")
2042 (gdb-invalidate-memory))
2044 (defun gdb-memory-unit-byte ()
2045 "Set the unit size to bytes."
2047 (customize-set-variable 'gdb-memory-unit "b")
2048 (gdb-invalidate-memory))
2050 (defvar gdb-memory-unit-keymap
2051 (let ((map (make-sparse-keymap)))
2052 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2054 "Keymap to select units in the header line.")
2056 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2057 "Menu of units in the header line.")
2059 (define-key gdb-memory-unit-menu [giantwords]
2060 '(menu-item "Giant words" gdb-memory-unit-giant
2061 :button (:radio . (equal gdb-memory-unit "g"))))
2062 (define-key gdb-memory-unit-menu [words]
2063 '(menu-item "Words" gdb-memory-unit-word
2064 :button (:radio . (equal gdb-memory-unit "w"))))
2065 (define-key gdb-memory-unit-menu [halfwords]
2066 '(menu-item "Halfwords" gdb-memory-unit-halfword
2067 :button (:radio . (equal gdb-memory-unit "h"))))
2068 (define-key gdb-memory-unit-menu [bytes]
2069 '(menu-item "Bytes" gdb-memory-unit-byte
2070 :button (:radio . (equal gdb-memory-unit "b"))))
2072 (defun gdb-memory-unit-menu (event)
2074 (x-popup-menu event gdb-memory-unit-menu))
2076 (defun gdb-memory-unit-menu-1 (event)
2078 (save-selected-window
2079 (select-window (posn-window (event-start event)))
2080 (let* ((selection (gdb-memory-unit-menu event))
2081 (binding (and selection (lookup-key gdb-memory-unit-menu
2082 (vector (car selection))))))
2083 (if binding (call-interactively binding)))))
2085 ;;from make-mode-line-mouse-map
2086 (defun gdb-make-header-line-mouse-map (mouse function) "\
2087 Return a keymap with single entry for mouse key MOUSE on the header line.
2088 MOUSE is defined to run function FUNCTION with no args in the buffer
2089 corresponding to the mode line clicked."
2090 (let ((map (make-sparse-keymap)))
2091 (define-key map (vector 'header-line mouse) function)
2092 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2095 (defvar gdb-memory-font-lock-keywords
2096 '(;; <__function.name+n>
2097 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2099 "Font lock keywords used in `gdb-memory-mode'.")
2101 (defun gdb-memory-mode ()
2102 "Major mode for examining memory.
2104 \\{gdb-memory-mode-map}"
2105 (kill-all-local-variables)
2106 (setq major-mode 'gdb-memory-mode)
2107 (setq mode-name "Memory")
2108 (setq buffer-read-only t)
2109 (use-local-map gdb-memory-mode-map)
2110 (setq header-line-format
2116 'face font-lock-warning-face
2117 'help-echo "mouse-1: Decrement address"
2118 'mouse-face 'mode-line-highlight
2120 (gdb-make-header-line-mouse-map
2122 #'(lambda () (interactive)
2123 (let ((gdb-memory-address
2124 ;; Let GDB do the arithmetic.
2126 gdb-memory-address " - "
2128 (* gdb-memory-repeat-count
2129 (cond ((string= gdb-memory-unit "b") 1)
2130 ((string= gdb-memory-unit "h") 2)
2131 ((string= gdb-memory-unit "w") 4)
2132 ((string= gdb-memory-unit "g") 8)))))))
2133 (gdb-invalidate-memory)))))
2136 'face font-lock-warning-face
2137 'help-echo "mouse-1: Increment address"
2138 'mouse-face 'mode-line-highlight
2139 'local-map (gdb-make-header-line-mouse-map
2141 #'(lambda () (interactive)
2142 (let ((gdb-memory-address nil))
2143 (gdb-invalidate-memory)))))
2145 (propertize gdb-memory-address
2146 'face font-lock-warning-face
2147 'help-echo "mouse-1: Set memory address"
2148 'mouse-face 'mode-line-highlight
2149 'local-map (gdb-make-header-line-mouse-map
2151 #'gdb-memory-set-address))
2153 (propertize (number-to-string gdb-memory-repeat-count)
2154 'face font-lock-warning-face
2155 'help-echo "mouse-1: Set repeat count"
2156 'mouse-face 'mode-line-highlight
2157 'local-map (gdb-make-header-line-mouse-map
2159 #'gdb-memory-set-repeat-count))
2161 (propertize gdb-memory-format
2162 'face font-lock-warning-face
2163 'help-echo "mouse-3: Select display format"
2164 'mouse-face 'mode-line-highlight
2165 'local-map gdb-memory-format-keymap)
2167 (propertize gdb-memory-unit
2168 'face font-lock-warning-face
2169 'help-echo "mouse-3: Select unit size"
2170 'mouse-face 'mode-line-highlight
2171 'local-map gdb-memory-unit-keymap))))
2172 (set (make-local-variable 'font-lock-defaults)
2173 '(gdb-memory-font-lock-keywords))
2174 (run-mode-hooks 'gdb-memory-mode-hook)
2175 'gdb-invalidate-memory)
2177 (defun gdb-memory-buffer-name ()
2178 (with-current-buffer gud-comint-buffer
2179 (concat "*memory of " (gdb-get-target-string) "*")))
2181 (defun gdb-display-memory-buffer ()
2182 "Display memory contents."
2185 (gdb-get-create-buffer 'gdb-memory-buffer)))
2187 (defun gdb-frame-memory-buffer ()
2188 "Display memory contents in a new frame."
2190 (let ((special-display-regexps (append special-display-regexps '(".*")))
2191 (special-display-frame-alist gdb-frame-parameters))
2192 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2197 (gdb-set-buffer-rules 'gdb-locals-buffer
2198 'gdb-locals-buffer-name
2201 (def-gdb-auto-update-trigger gdb-invalidate-locals
2202 (gdb-get-buffer 'gdb-locals-buffer)
2203 "server info locals\n"
2204 gdb-info-locals-handler)
2206 ;; Abbreviate for arrays and structures.
2207 ;; These can be expanded using gud-display.
2208 (defun gdb-info-locals-handler ()
2209 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2210 gdb-pending-triggers))
2211 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2212 (with-current-buffer buf
2213 (goto-char (point-min))
2214 (while (re-search-forward "^[ }].*\n" nil t)
2215 (replace-match "" nil nil))
2216 (goto-char (point-min))
2217 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2218 (replace-match "(structure);\n" nil nil))
2219 (goto-char (point-min))
2220 (while (re-search-forward "\\s-*{.*\n" nil t)
2221 (replace-match " (array);\n" nil nil))))
2222 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2224 (with-current-buffer buf
2225 (let* ((window (get-buffer-window buf 0))
2226 (p (window-point window))
2227 (buffer-read-only nil))
2229 (insert-buffer-substring (gdb-get-create-buffer
2230 'gdb-partial-output-buffer))
2231 (set-window-point window p)))))
2232 (run-hooks 'gdb-info-locals-hook))
2234 (defvar gdb-locals-mode-map
2235 (let ((map (make-sparse-keymap)))
2236 (suppress-keymap map)
2237 (define-key map "q" 'kill-this-buffer)
2240 (defvar gdb-locals-font-lock-keywords
2242 ;; var = (struct struct_tag) value
2243 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2244 (1 font-lock-variable-name-face)
2245 (3 font-lock-keyword-face)
2246 (4 font-lock-type-face))
2247 ;; var = (type) value
2248 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2249 (1 font-lock-variable-name-face)
2250 (3 font-lock-type-face))
2252 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2253 (1 font-lock-variable-name-face))
2255 "Font lock keywords used in `gdb-local-mode'.")
2257 (defun gdb-locals-mode ()
2258 "Major mode for gdb locals.
2260 \\{gdb-locals-mode-map}"
2261 (kill-all-local-variables)
2262 (setq major-mode 'gdb-locals-mode)
2263 (setq mode-name (concat "Locals:" gdb-selected-frame))
2264 (setq buffer-read-only t)
2265 (use-local-map gdb-locals-mode-map)
2266 (set (make-local-variable 'font-lock-defaults)
2267 '(gdb-locals-font-lock-keywords))
2268 (run-mode-hooks 'gdb-locals-mode-hook)
2269 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
2270 'gdb-invalidate-locals
2271 'gdbmi-invalidate-locals))
2273 (defun gdb-locals-buffer-name ()
2274 (with-current-buffer gud-comint-buffer
2275 (concat "*locals of " (gdb-get-target-string) "*")))
2277 (defun gdb-display-locals-buffer ()
2278 "Display local variables of current stack and their values."
2281 (gdb-get-create-buffer 'gdb-locals-buffer)))
2283 (defun gdb-frame-locals-buffer ()
2284 "Display local variables of current stack and their values in a new frame."
2286 (let ((special-display-regexps (append special-display-regexps '(".*")))
2287 (special-display-frame-alist gdb-frame-parameters))
2288 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2291 ;;;; Window management
2292 (defun gdb-display-buffer (buf &optional size)
2293 (let ((answer (get-buffer-window buf 0))
2296 (display-buffer buf nil 0) ;Raise the frame if necessary.
2297 ;; The buffer is not yet displayed.
2298 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2299 (let ((window (get-lru-window)))
2301 (not (eq window (get-buffer-window gud-comint-buffer))))
2303 (set-window-buffer window buf)
2304 (setq answer window))
2305 (setq must-split t)))
2307 (let* ((largest (get-largest-window))
2308 (cur-size (window-height largest))
2309 (new-size (and size (< size cur-size) (- cur-size size))))
2310 (setq answer (split-window largest new-size))
2311 (set-window-buffer answer buf)
2312 (set-window-dedicated-p answer t)))
2316 ;;; Shared keymap initialization:
2318 (let ((menu (make-sparse-keymap "GDB-Windows")))
2319 (define-key gud-menu-map [displays]
2320 `(menu-item "GDB-Windows" ,menu
2321 :visible (memq gud-minor-mode '(gdbmi gdba))))
2322 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2323 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2324 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2325 (define-key menu [disassembly]
2326 '("Disassembly" . gdb-display-assembler-buffer))
2327 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2328 (define-key menu [inferior]
2329 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2330 :enable gdb-use-inferior-io-buffer))
2331 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2332 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2333 (define-key menu [breakpoints]
2334 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2336 (let ((menu (make-sparse-keymap "GDB-Frames")))
2337 (define-key gud-menu-map [frames]
2338 `(menu-item "GDB-Frames" ,menu
2339 :visible (memq gud-minor-mode '(gdbmi gdba))))
2340 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2341 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2342 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2343 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2344 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2345 (define-key menu [inferior]
2346 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2347 :enable gdb-use-inferior-io-buffer))
2348 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2349 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2350 (define-key menu [breakpoints]
2351 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2353 (let ((menu (make-sparse-keymap "GDB-UI")))
2354 (define-key gud-menu-map [ui]
2355 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2356 (define-key menu [gdb-use-inferior-io]
2357 '(menu-item "Separate inferior IO" gdb-use-inferior-io-buffer
2358 :help "Toggle separate IO for inferior."
2359 :button (:toggle . gdb-use-inferior-io-buffer)))
2360 (define-key menu [gdb-many-windows]
2361 '(menu-item "Display Other Windows" gdb-many-windows
2362 :help "Toggle display of locals, stack and breakpoint information"
2363 :button (:toggle . gdb-many-windows)))
2364 (define-key menu [gdb-restore-windows]
2365 '(menu-item "Restore Window Layout" gdb-restore-windows
2366 :help "Restore standard layout for debug session.")))
2368 (defun gdb-frame-gdb-buffer ()
2369 "Display GUD buffer in a new frame."
2371 (let ((special-display-regexps (append special-display-regexps '(".*")))
2372 (special-display-frame-alist gdb-frame-parameters)
2373 (same-window-regexps nil))
2374 (display-buffer gud-comint-buffer)))
2376 (defun gdb-display-gdb-buffer ()
2377 "Display GUD buffer."
2379 (let ((same-window-regexps nil))
2380 (pop-to-buffer gud-comint-buffer)))
2382 (defun gdb-set-window-buffer (name)
2383 (set-window-buffer (selected-window) (get-buffer name))
2384 (set-window-dedicated-p (selected-window) t))
2386 (defun gdb-setup-windows ()
2387 "Layout the window pattern for `gdb-many-windows'."
2388 (gdb-display-locals-buffer)
2389 (gdb-display-stack-buffer)
2390 (delete-other-windows)
2391 (gdb-display-breakpoints-buffer)
2392 (delete-other-windows)
2394 (pop-to-buffer gud-comint-buffer)
2395 (split-window nil ( / ( * (window-height) 3) 4))
2396 (split-window nil ( / (window-height) 3))
2397 (split-window-horizontally)
2399 (gdb-set-window-buffer (gdb-locals-buffer-name))
2402 (if gud-last-last-frame
2403 (gud-find-file (car gud-last-last-frame))
2404 (gud-find-file gdb-main-file)))
2405 (when gdb-use-inferior-io-buffer
2406 (split-window-horizontally)
2408 (gdb-set-window-buffer
2409 (gdb-get-create-buffer 'gdb-inferior-io)))
2411 (gdb-set-window-buffer (gdb-stack-buffer-name))
2412 (split-window-horizontally)
2414 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2417 (defcustom gdb-many-windows nil
2418 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2419 In this case it starts with two windows: one displaying the GUD
2420 buffer and the other with the source file with the main routine
2421 of the inferior. Non-nil means display the layout shown for
2427 (defun gdb-many-windows (arg)
2428 "Toggle the number of windows in the basic arrangement.
2429 With arg, display additional buffers iff arg is positive."
2431 (setq gdb-many-windows
2433 (not gdb-many-windows)
2434 (> (prefix-numeric-value arg) 0)))
2435 (if (and gud-comint-buffer
2436 (buffer-name gud-comint-buffer))
2438 (gdb-restore-windows)
2441 (defun gdb-restore-windows ()
2442 "Restore the basic arrangement of windows used by gdba.
2443 This arrangement depends on the value of `gdb-many-windows'."
2445 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2446 (delete-other-windows)
2447 (if gdb-many-windows
2449 (when (or gud-last-last-frame gdb-show-main)
2453 (if gud-last-last-frame
2454 (gud-find-file (car gud-last-last-frame))
2455 (gud-find-file gdb-main-file)))
2459 "Exit a debugging session cleanly.
2460 Kills the gdb buffers and resets the source buffers."
2461 (dolist (buffer (buffer-list))
2462 (unless (eq buffer gud-comint-buffer)
2463 (with-current-buffer buffer
2464 (if (memq gud-minor-mode '(gdbmi gdba))
2465 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2467 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2468 (setq gud-minor-mode nil)
2469 (kill-local-variable 'tool-bar-map)
2470 (kill-local-variable 'gdb-define-alist))))))
2471 (when (markerp gdb-overlay-arrow-position)
2472 (move-marker gdb-overlay-arrow-position nil)
2473 (setq gdb-overlay-arrow-position nil))
2474 (setq overlay-arrow-variable-list
2475 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2476 (setq gud-running nil)
2477 (setq gdb-active-process nil)
2478 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2480 (defun gdb-source-info ()
2481 "Find the source file where the program starts and displays it with related
2483 (goto-char (point-min))
2484 (if (and (search-forward "Located in " nil t)
2485 (looking-at "\\S-+"))
2486 (setq gdb-main-file (match-string 0)))
2487 (goto-char (point-min))
2488 (if (search-forward "Includes preprocessor macro info." nil t)
2489 (setq gdb-macro-info t))
2490 (if gdb-many-windows
2492 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2494 (let ((pop-up-windows t))
2495 (display-buffer (gud-find-file gdb-main-file))))))
2497 (defun gdb-get-location (bptno line flag)
2498 "Find the directory containing the relevant source file.
2499 Put in buffer and place breakpoint icon."
2500 (goto-char (point-min))
2501 (catch 'file-not-found
2502 (if (search-forward "Located in " nil t)
2503 (when (looking-at "\\S-+")
2504 (delete (cons bptno "File not found") gdb-location-alist)
2505 (push (cons bptno (match-string 0)) gdb-location-alist))
2507 (unless (assoc bptno gdb-location-alist)
2508 (push (cons bptno "File not found") gdb-location-alist)
2509 (message-box "Cannot find source file for breakpoint location.\n\
2510 Add directory to search path for source files using the GDB command, dir."))
2511 (throw 'file-not-found nil))
2512 (with-current-buffer
2513 (find-file-noselect (match-string 0))
2514 (save-current-buffer
2515 (set (make-local-variable 'gud-minor-mode) 'gdba)
2516 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2517 ;; only want one breakpoint icon at each location
2519 (goto-line (string-to-number line))
2520 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2522 (add-hook 'find-file-hook 'gdb-find-file-hook)
2524 (defun gdb-find-file-hook ()
2525 "Set up buffer for debugging if file is part of the source code
2526 of the current session."
2527 (if (and (not gdb-find-file-unhook)
2528 ;; in case gud or gdb-ui is just loaded
2530 (buffer-name gud-comint-buffer)
2531 (with-current-buffer gud-comint-buffer
2532 (eq gud-minor-mode 'gdba)))
2535 (list (concat gdb-server-prefix "list "
2536 (file-name-nondirectory buffer-file-name)
2538 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2539 (error (setq gdb-find-file-unhook t)))))
2542 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2543 "Put string PUTSTRING in front of POS in the current buffer.
2544 PUTSTRING is displayed by putting an overlay into the current buffer with a
2545 `before-string' string that has a `display' property whose value is
2547 (let ((string (make-string 1 ?x))
2548 (buffer (current-buffer)))
2549 (setq putstring (copy-sequence putstring))
2550 (let ((overlay (make-overlay pos pos buffer))
2552 (list (list 'margin 'left-margin) putstring))))
2553 (put-text-property 0 1 'display prop string)
2555 (add-text-properties 0 1 sprops string))
2556 (overlay-put overlay 'put-break t)
2557 (overlay-put overlay 'before-string string))))
2559 ;;from remove-images
2560 (defun gdb-remove-strings (start end &optional buffer)
2561 "Remove strings between START and END in BUFFER.
2562 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2563 BUFFER nil or omitted means use the current buffer."
2565 (setq buffer (current-buffer)))
2566 (dolist (overlay (overlays-in start end))
2567 (when (overlay-get overlay 'put-break)
2568 (delete-overlay overlay))))
2570 (defun gdb-put-breakpoint-icon (enabled bptno)
2571 (let ((start (- (line-beginning-position) 1))
2572 (end (+ (line-end-position) 1))
2573 (putstring (if enabled "B" "b"))
2574 (source-window (get-buffer-window (current-buffer) 0)))
2575 (add-text-properties
2576 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2579 (add-text-properties
2580 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2581 (add-text-properties
2582 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2583 (gdb-remove-breakpoint-icons start end)
2584 (if (display-images-p)
2585 (if (>= (or left-fringe-width
2586 (if source-window (car (window-fringes source-window)))
2587 gdb-buffer-fringe-width) 8)
2590 `(left-fringe breakpoint
2593 'breakpoint-disabled))
2595 'gdb-enabled enabled)
2596 (when (< left-margin-width 2)
2597 (save-current-buffer
2598 (setq left-margin-width 2)
2602 left-margin-width right-margin-width))))
2605 (or breakpoint-enabled-icon
2606 (setq breakpoint-enabled-icon
2607 (find-image `((:type xpm :data
2608 ,breakpoint-xpm-data
2609 :ascent 100 :pointer hand)
2611 ,breakpoint-enabled-pbm-data
2612 :ascent 100 :pointer hand)))))
2613 (or breakpoint-disabled-icon
2614 (setq breakpoint-disabled-icon
2615 (find-image `((:type xpm :data
2616 ,breakpoint-xpm-data
2617 :conversion disabled
2618 :ascent 100 :pointer hand)
2620 ,breakpoint-disabled-pbm-data
2621 :ascent 100 :pointer hand))))))
2625 (when (< left-margin-width 2)
2626 (save-current-buffer
2627 (setq left-margin-width 2)
2628 (let ((window (get-buffer-window (current-buffer) 0)))
2631 window left-margin-width right-margin-width)))))
2633 (propertize putstring
2634 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2637 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2638 (gdb-remove-strings start end)
2639 (if (display-images-p)
2640 (remove-images start end))
2642 (setq left-margin-width 0)
2643 (let ((window (get-buffer-window (current-buffer) 0)))
2646 window left-margin-width right-margin-width)))))
2650 ;; Assembler buffer.
2652 (gdb-set-buffer-rules 'gdb-assembler-buffer
2653 'gdb-assembler-buffer-name
2654 'gdb-assembler-mode)
2656 (def-gdb-auto-update-handler gdb-assembler-handler
2657 gdb-invalidate-assembler
2658 gdb-assembler-buffer
2659 gdb-assembler-custom)
2661 (defun gdb-assembler-custom ()
2662 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2663 (pos 1) (address) (flag) (bptno))
2664 (with-current-buffer buffer
2666 (if (not (equal gdb-frame-address "main"))
2668 (goto-char (point-min))
2669 (if (and gdb-frame-address
2670 (re-search-forward gdb-frame-address nil t))
2674 (or gdb-overlay-arrow-position
2675 (setq gdb-overlay-arrow-position (make-marker)))
2676 (set-marker gdb-overlay-arrow-position
2677 (point) (current-buffer))))))
2678 ;; remove all breakpoint-icons in assembler buffer before updating.
2679 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2680 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2681 (goto-char (point-min))
2682 (while (< (point) (- (point-max) 1))
2684 (if (looking-at "[^\t].*?breakpoint")
2687 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2688 (setq bptno (match-string 1))
2689 (setq flag (char-after (match-beginning 2)))
2690 (setq address (match-string 3))
2691 (with-current-buffer buffer
2693 (goto-char (point-min))
2694 (if (re-search-forward address nil t)
2695 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2696 (if (not (equal gdb-frame-address "main"))
2697 (set-window-point (get-buffer-window buffer 0) pos))))
2699 (defvar gdb-assembler-mode-map
2700 (let ((map (make-sparse-keymap)))
2701 (suppress-keymap map)
2702 (define-key map "q" 'kill-this-buffer)
2705 (defvar gdb-assembler-font-lock-keywords
2706 '(;; <__function.name+n>
2707 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2708 (1 font-lock-function-name-face))
2709 ;; 0xNNNNNNNN <__function.name+n>: opcode
2710 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2711 (4 font-lock-keyword-face))
2712 ;; %register(at least i386)
2713 ("%\\sw+" . font-lock-variable-name-face)
2714 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2715 (1 font-lock-comment-face)
2716 (2 font-lock-function-name-face))
2717 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2718 "Font lock keywords used in `gdb-assembler-mode'.")
2720 (defun gdb-assembler-mode ()
2721 "Major mode for viewing code assembler.
2723 \\{gdb-assembler-mode-map}"
2724 (kill-all-local-variables)
2725 (setq major-mode 'gdb-assembler-mode)
2726 (setq mode-name (concat "Machine:" gdb-selected-frame))
2727 (setq gdb-overlay-arrow-position nil)
2728 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2729 (setq fringes-outside-margins t)
2730 (setq buffer-read-only t)
2731 (use-local-map gdb-assembler-mode-map)
2732 (gdb-invalidate-assembler)
2733 (set (make-local-variable 'font-lock-defaults)
2734 '(gdb-assembler-font-lock-keywords))
2735 (run-mode-hooks 'gdb-assembler-mode-hook)
2736 'gdb-invalidate-assembler)
2738 (defun gdb-assembler-buffer-name ()
2739 (with-current-buffer gud-comint-buffer
2740 (concat "*disassembly of " (gdb-get-target-string) "*")))
2742 (defun gdb-display-assembler-buffer ()
2743 "Display disassembly view."
2745 (setq gdb-previous-frame nil)
2747 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2749 (defun gdb-frame-assembler-buffer ()
2750 "Display disassembly view in a new frame."
2752 (setq gdb-previous-frame nil)
2753 (let ((special-display-regexps (append special-display-regexps '(".*")))
2754 (special-display-frame-alist gdb-frame-parameters))
2755 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2757 ;; modified because if gdb-frame-address has changed value a new command
2758 ;; must be enqueued to update the buffer with the new output
2759 (defun gdb-invalidate-assembler (&optional ignored)
2760 (if (gdb-get-buffer 'gdb-assembler-buffer)
2762 (unless (and gdb-selected-frame
2763 (string-equal gdb-selected-frame gdb-previous-frame))
2764 (if (or (not (member 'gdb-invalidate-assembler
2765 gdb-pending-triggers))
2766 (not (string-equal gdb-frame-address
2767 gdb-previous-frame-address)))
2769 ;; take previous disassemble command, if any, off the queue
2770 (with-current-buffer gud-comint-buffer
2771 (let ((queue gdb-input-queue))
2772 (dolist (item queue)
2773 (if (equal (cdr item) '(gdb-assembler-handler))
2774 (setq gdb-input-queue
2775 (delete item gdb-input-queue))))))
2778 (concat gdb-server-prefix "disassemble "
2779 (if (member gdb-frame-address '(nil "main")) nil "0x")
2780 gdb-frame-address "\n")
2781 'gdb-assembler-handler))
2782 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2783 (setq gdb-previous-frame-address gdb-frame-address)
2784 (setq gdb-previous-frame gdb-selected-frame)))))))
2786 (defun gdb-get-selected-frame ()
2787 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2790 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2791 (push 'gdb-get-selected-frame
2792 gdb-pending-triggers))))
2794 (defun gdb-frame-handler ()
2795 (setq gdb-pending-triggers
2796 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2797 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2798 (goto-char (point-min))
2799 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2800 (setq gdb-frame-number (match-string 1)))
2801 (goto-char (point-min))
2802 (if (re-search-forward
2803 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2805 (setq gdb-selected-frame (match-string 2))
2806 (if (gdb-get-buffer 'gdb-locals-buffer)
2807 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2808 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2809 (if (gdb-get-buffer 'gdb-assembler-buffer)
2810 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2811 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2812 (setq gdb-frame-address (match-string 1))))
2813 (goto-char (point-min))
2814 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2815 (setq gdb-current-language (match-string 1))))
2816 (gdb-invalidate-assembler))
2820 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2821 ;;; gdb-ui.el ends here