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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, 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.
56 ;; 1) Use MI command -data-read-memory for memory window.
57 ;; 2) Highlight changed register values (use MI commands
58 ;; -data-list-register-values and -data-list-changed-registers instead
59 ;; of 'info registers'.
60 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
61 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
62 ;; 5) After release of 22.1 use '-var-list-children --all-values'
63 ;; and '-stack-list-locals 2' which need GDB 6.1 onwards.
69 (defvar gdb-frame-address
"main" "Initialisation for Assembler buffer.")
70 (defvar gdb-previous-frame-address nil
)
71 (defvar gdb-memory-address
"main")
72 (defvar gdb-previous-frame nil
)
73 (defvar gdb-selected-frame nil
)
74 (defvar gdb-frame-number nil
)
75 (defvar gdb-current-language nil
)
76 (defvar gdb-var-list nil
"List of variables in watch window.")
77 (defvar gdb-var-changed nil
"Non-nil means that gdb-var-list has changed.")
78 (defvar gdb-main-file nil
"Source file from which program execution begins.")
79 (defvar gdb-buffer-type nil
)
80 (defvar gdb-overlay-arrow-position nil
)
81 (defvar gdb-server-prefix nil
)
82 (defvar gdb-flush-pending-output nil
)
83 (defvar gdb-location-alist nil
84 "Alist of breakpoint numbers and full filenames.")
85 (defvar gdb-find-file-unhook nil
)
86 (defvar gdb-active-process nil
"GUD tooltips display variable values when t, \
87 and #define directives otherwise.")
88 (defvar gdb-error
"Non-nil when GDB is reporting an error.")
89 (defvar gdb-macro-info nil
90 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
92 (defvar gdb-buffer-type nil
93 "One of the symbols bound in `gdb-buffer-rules'.")
95 (defvar gdb-input-queue
()
96 "A list of gdb command objects.")
98 (defvar gdb-prompting nil
99 "True when gdb is idle with no pending input.")
101 (defvar gdb-output-sink
'user
102 "The disposition of the output of the current gdb command.
103 Possible values are these symbols:
105 `user' -- gdb output should be copied to the GUD buffer
108 `inferior' -- gdb output should be copied to the inferior-io buffer
110 `pre-emacs' -- output should be ignored util the post-prompt
111 annotation is received. Then the output-sink
113 `emacs' -- output should be collected in the partial-output-buffer
114 for subsequent processing by a command. This is the
115 disposition of output generated by commands that
116 gdb mode sends to gdb on its own behalf.
117 `post-emacs' -- ignore output until the prompt annotation is
118 received, then go to USER disposition.
120 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
121 \(`user' and `emacs').")
123 (defvar gdb-current-item nil
124 "The most recent command item sent to gdb.")
126 (defvar gdb-pending-triggers
'()
127 "A list of trigger functions that have run later than their output
130 ;; end of gdb variables
133 (defun gdba (command-line)
134 "Run gdb on program FILE in buffer *gud-FILE*.
135 The directory containing FILE becomes the initial working directory
136 and source-file directory for your debugger.
138 If `gdb-many-windows' is nil (the default value) then gdb just
139 pops up the GUD buffer unless `gdb-show-main' is t. In this case
140 it starts with two windows: one displaying the GUD buffer and the
141 other with the source file with the main routine of the inferior.
143 If `gdb-many-windows' is t, regardless of the value of
144 `gdb-show-main', the layout below will appear unless
145 `gdb-use-inferior-io-buffer' is nil when the source buffer
146 occupies the full width of the frame. Keybindings are given in
149 Watch expressions appear in the speedbar/slowbar.
151 The following commands help control operation :
153 `gdb-many-windows' - Toggle the number of windows gdb uses.
154 `gdb-restore-windows' - To restore the window layout.
156 See Info node `(emacs)GDB Graphical Interface' for a more
157 detailed description of this mode.
160 ---------------------------------------------------------------------
162 ---------------------------------------------------------------------
163 GUD buffer (I/O of GDB) | Locals buffer
167 ---------------------------------------------------------------------
168 Source buffer | Input/Output (of inferior) buffer
176 ---------------------------------------------------------------------
177 Stack buffer | Breakpoints buffer
178 RET gdb-frames-select | SPC gdb-toggle-breakpoint
179 | RET gdb-goto-breakpoint
180 | d gdb-delete-breakpoint
181 ---------------------------------------------------------------------"
183 (interactive (list (gud-query-cmdline 'gdba
)))
185 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
189 (defvar gdb-debug-log nil
)
191 (defcustom gdb-enable-debug-log nil
192 "Non-nil means record the process input and output in `gdb-debug-log'."
197 (defcustom gdb-use-inferior-io-buffer nil
198 "Non-nil means display output from the inferior in a separate buffer."
203 (defcustom gdb-cpp-define-alist-program
"gcc -E -dM -"
204 "Shell command for generating a list of defined macros in a source file.
205 This list is used to display the #define directive associated
206 with an identifier as a tooltip. It works in a debug session with
207 GDB, when gud-tooltip-mode is t.
209 Set `gdb-cpp-define-alist-flags' for any include paths or
215 (defcustom gdb-cpp-define-alist-flags
""
216 "Preprocessor flags for `gdb-cpp-define-alist-program'."
221 (defcustom gdb-show-main nil
222 "Non-nil means display source file containing the main routine at startup.
223 Also display the main routine in the disassembly buffer if present."
228 (defvar gdb-define-alist nil
"Alist of #define directives for GUD tooltips.")
230 (defun gdb-create-define-alist ()
231 "Create an alist of #define directives for GUD tooltips."
232 (let* ((file (buffer-file-name))
234 (with-output-to-string
235 (with-current-buffer standard-output
236 (call-process shell-file-name
237 (if (file-exists-p file
) file nil
)
238 (list t nil
) nil
"-c"
239 (concat gdb-cpp-define-alist-program
" "
240 gdb-cpp-define-alist-flags
)))))
241 (define-list (split-string output
"\n" t
))
243 (setq gdb-define-alist nil
)
244 (dolist (define define-list
)
245 (setq name
(nth 1 (split-string define
"[( ]")))
246 (push (cons name define
) gdb-define-alist
))))
248 (defun gdb-tooltip-print ()
250 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer
)
251 (let ((string (buffer-string)))
252 ;; remove newline for gud-tooltip-echo-area
253 (substring string
0 (- (length string
) 1))))
254 (or gud-tooltip-echo-area tooltip-use-echo-area
)))
256 ;; If expr is a macro for a function don't print because of possible dangerous
257 ;; side-effects. Also printing a function within a tooltip generates an
258 ;; unexpected starting annotation (phase error).
259 (defun gdb-tooltip-print-1 (expr)
260 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer
)
261 (goto-char (point-min))
262 (if (search-forward "expands to: " nil t
)
263 (unless (looking-at "\\S+.*(.*).*")
265 (list (concat gdb-server-prefix
"print " expr
"\n")
266 'gdb-tooltip-print
))))))
268 (defun gdb-set-gud-minor-mode (buffer)
269 "Set gud-minor-mode from find-file if appropriate."
270 (goto-char (point-min))
271 (unless (search-forward "No source file named " nil t
)
274 (list (concat gdb-server-prefix
"info source\n")
275 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer
))))
276 (error (setq gdb-find-file-unhook t
)))))
278 (defun gdb-set-gud-minor-mode-1 (buffer)
279 (goto-char (point-min))
280 (when (and (search-forward "Located in " nil t
)
282 (string-equal (buffer-file-name buffer
)
284 (with-current-buffer buffer
285 (set (make-local-variable 'gud-minor-mode
) 'gdba
)
286 (set (make-local-variable 'tool-bar-map
) gud-tool-bar-map
)
287 (when gud-tooltip-mode
288 (make-local-variable 'gdb-define-alist
)
289 (gdb-create-define-alist)
290 (add-hook 'after-save-hook
'gdb-create-define-alist nil t
)))))
292 (defun gdb-set-gud-minor-mode-existing-buffers ()
293 (dolist (buffer (buffer-list))
294 (let ((file (buffer-file-name buffer
)))
298 (list (concat gdb-server-prefix
"list "
299 (file-name-nondirectory file
) ":1\n")
300 `(lambda () (gdb-set-gud-minor-mode ,buffer
)))))))))
303 (setq gdb-debug-log nil
)
304 (set (make-local-variable 'gud-minor-mode
) 'gdba
)
305 (set (make-local-variable 'gud-marker-filter
) 'gud-gdba-marker-filter
)
307 (gud-def gud-break
(if (not (string-match "Machine" mode-name
))
308 (gud-call "break %f:%l" arg
)
312 (gud-call "break *%a" arg
)))
313 "\C-b" "Set breakpoint at current line or address.")
315 (gud-def gud-remove
(if (not (string-match "Machine" mode-name
))
316 (gud-call "clear %f:%l" arg
)
320 (gud-call "clear *%a" arg
)))
321 "\C-d" "Remove breakpoint at current line or address.")
323 (gud-def gud-until
(if (not (string-match "Machine" mode-name
))
324 (gud-call "until %f:%l" arg
)
328 (gud-call "until *%a" arg
)))
329 "\C-u" "Continue to current line or address.")
331 (define-key gud-minor-mode-map
[left-margin mouse-1
]
332 'gdb-mouse-set-clear-breakpoint
)
333 (define-key gud-minor-mode-map
[left-fringe mouse-1
]
334 'gdb-mouse-set-clear-breakpoint
)
335 (define-key gud-minor-mode-map
[left-margin mouse-3
]
336 'gdb-mouse-toggle-breakpoint
)
337 ; Currently only works in margin.
338 ; (define-key gud-minor-mode-map [left-fringe mouse-3]
339 ; 'gdb-mouse-toggle-breakpoint)
341 (setq comint-input-sender
'gdb-send
)
344 (setq gdb-frame-address
(if gdb-show-main
"main" nil
))
345 (setq gdb-previous-frame-address nil
346 gdb-memory-address
"main"
347 gdb-previous-frame nil
348 gdb-selected-frame nil
349 gdb-current-language nil
357 gdb-pending-triggers nil
358 gdb-output-sink
'user
359 gdb-server-prefix
"server "
360 gdb-flush-pending-output nil
361 gdb-location-alist nil
362 gdb-find-file-unhook nil
366 (setq gdb-buffer-type
'gdba
)
368 (if gdb-use-inferior-io-buffer
(gdb-clear-inferior-io))
370 (if (eq window-system
'w32
)
371 (gdb-enqueue-input (list "set new-console off\n" 'ignore
)))
372 (gdb-enqueue-input (list "set height 0\n" 'ignore
))
373 (gdb-enqueue-input (list "set width 0\n" 'ignore
))
374 ;; find source file and compilation directory here
375 (gdb-enqueue-input (list "server list main\n" 'ignore
)) ; C program
376 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore
)) ; Fortran program
377 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info
))
379 (gdb-set-gud-minor-mode-existing-buffers)
380 (run-hooks 'gdba-mode-hook
))
382 (defcustom gdb-use-colon-colon-notation nil
383 "If non-nil use FUN::VAR format to display variables in the speedbar."
389 "Watch expression at point."
392 (let ((expr (tooltip-identifier-from-point (point))))
393 (if (and (string-equal gdb-current-language
"c")
394 gdb-use-colon-colon-notation gdb-selected-frame
)
395 (setq expr
(concat gdb-selected-frame
"::" expr
)))
396 (catch 'already-watched
397 (dolist (var gdb-var-list
)
398 (if (string-equal expr
(car var
)) (throw 'already-watched nil
)))
399 (set-text-properties 0 (length expr
) nil expr
)
402 (if (eq gud-minor-mode
'gdba
)
403 (concat "server interpreter mi \"-var-create - * " expr
"\"\n")
404 (concat"-var-create - * " expr
"\n"))
405 `(lambda () (gdb-var-create-handler ,expr
))))))
406 (select-window (get-buffer-window gud-comint-buffer
0)))
408 (defconst gdb-var-create-regexp
409 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
411 (defun gdb-var-create-handler (expr)
412 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer
)
413 (goto-char (point-min))
414 (if (re-search-forward gdb-var-create-regexp nil t
)
415 (let ((var (list expr
420 (push var gdb-var-list
)
422 (if (equal (nth 2 var
) "0")
425 (if (with-current-buffer
426 gud-comint-buffer
(eq gud-minor-mode
'gdba
))
427 (concat "server interpreter mi \"-var-evaluate-expression "
429 (concat "-var-evaluate-expression " (nth 1 var
) "\n"))
430 `(lambda () (gdb-var-evaluate-expression-handler
432 (setq gdb-var-changed t
)))
433 (if (re-search-forward "Undefined command" nil t
)
434 (message-box "Watching expressions requires gdb 6.0 onwards")
435 (message "No symbol %s in current context." expr
)))))
437 (defun gdb-var-evaluate-expression-handler (varnum changed
)
438 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer
)
439 (goto-char (point-min))
440 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t
)
443 (dolist (var gdb-var-list
)
444 (if (string-equal varnum
(cadr var
))
446 (if changed
(setcar (nthcdr 5 var
) t
))
447 (setcar (nthcdr 4 var
) (match-string 1))
448 (setcar (nthcdr num gdb-var-list
) var
)
449 (throw 'var-found nil
)))
450 (setq num
(+ num
1))))))
451 (setq gdb-var-changed t
))
453 (defun gdb-var-list-children (varnum)
455 (list (concat "server interpreter mi \"-var-list-children " varnum
"\"\n")
456 `(lambda () (gdb-var-list-children-handler ,varnum
)))))
458 (defconst gdb-var-list-children-regexp
459 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
461 (defun gdb-var-list-children-handler (varnum)
462 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer
)
463 (goto-char (point-min))
464 (let ((var-list nil
))
465 (catch 'child-already-watched
466 (dolist (var gdb-var-list
)
467 (if (string-equal varnum
(cadr var
))
470 (while (re-search-forward gdb-var-list-children-regexp nil t
)
471 (let ((varchild (list (match-string 2)
475 (if (looking-at ",type=\"\\(.*?\\)\"")
476 (setcar (nthcdr 3 varchild
) (match-string 1)))
477 (dolist (var1 gdb-var-list
)
478 (if (string-equal (cadr var1
) (cadr varchild
))
479 (throw 'child-already-watched nil
)))
480 (push varchild var-list
)
481 (if (equal (nth 2 varchild
) "0")
485 "server interpreter mi \"-var-evaluate-expression "
486 (nth 1 varchild
) "\"\n")
487 `(lambda () (gdb-var-evaluate-expression-handler
488 ,(nth 1 varchild
) nil
))))))))
489 (push var var-list
)))
490 (setq gdb-var-list
(nreverse var-list
))))))
492 (defun gdb-var-update ()
493 (if (not (member 'gdb-var-update gdb-pending-triggers
))
497 (if (with-current-buffer gud-comint-buffer
(eq gud-minor-mode
'gdba
))
498 "server interpreter mi \"-var-update *\"\n"
500 'gdb-var-update-handler
))
501 (push 'gdb-var-update gdb-pending-triggers
))))
503 (defconst gdb-var-update-regexp
"name=\"\\(.*?\\)\"")
505 (defun gdb-var-update-handler ()
506 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer
)
507 (goto-char (point-min))
508 (while (re-search-forward gdb-var-update-regexp nil t
)
509 (let ((varnum (match-string 1)))
512 (if (with-current-buffer gud-comint-buffer
513 (eq gud-minor-mode
'gdba
))
514 (concat "server interpreter mi \"-var-evaluate-expression "
516 (concat "-var-evaluate-expression " varnum
"\n"))
517 `(lambda () (gdb-var-evaluate-expression-handler
519 (setq gdb-pending-triggers
520 (delq 'gdb-var-update gdb-pending-triggers
))
521 (when (and (boundp 'speedbar-frame
) (frame-live-p speedbar-frame
))
522 ;; dummy command to update speedbar at right time
523 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn
))
524 ;; keep gdb-pending-triggers non-nil till end
525 (push 'gdb-speedbar-timer gdb-pending-triggers
)))
527 (defun gdb-speedbar-timer-fn ()
528 (setq gdb-pending-triggers
529 (delq 'gdb-speedbar-timer gdb-pending-triggers
))
530 (with-current-buffer gud-comint-buffer
531 (speedbar-timer-fn)))
533 (defun gdb-var-delete ()
534 "Delete watched expression from the speedbar."
536 (if (with-current-buffer gud-comint-buffer
(eq gud-minor-mode
'gdba
))
537 (let ((text (speedbar-line-text)))
538 (string-match "\\(\\S-+\\)" text
)
539 (let* ((expr (match-string 1 text
))
540 (var (assoc expr gdb-var-list
))
542 (unless (string-match "\\." varnum
)
545 (if (with-current-buffer gud-comint-buffer
546 (eq gud-minor-mode
'gdba
))
547 (concat "server interpreter mi \"-var-delete " varnum
"\"\n")
548 (concat "-var-delete " varnum
"\n"))
550 (setq gdb-var-list
(delq var gdb-var-list
))
551 (dolist (varchild gdb-var-list
)
552 (if (string-match (concat (nth 1 var
) "\\.") (nth 1 varchild
))
553 (setq gdb-var-list
(delq varchild gdb-var-list
))))
554 (setq gdb-var-changed t
))))))
556 (defun gdb-edit-value (text token indent
)
557 "Assign a value to a variable displayed in the speedbar."
558 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list
))
559 (varnum (cadr var
)) (value))
560 (setq value
(read-string "New value: "))
563 (if (with-current-buffer gud-comint-buffer
564 (eq gud-minor-mode
'gdba
))
565 (concat "server interpreter mi \"-var-assign "
566 varnum
" " value
"\"\n")
567 (concat "-var-assign " varnum
" " value
"\n"))
570 (defcustom gdb-show-changed-values t
571 "If non-nil highlight values that have recently changed in the speedbar.
572 The highlighting is done with `font-lock-warning-face'."
577 (defun gdb-speedbar-expand-node (text token indent
)
578 "Expand the node the user clicked on.
579 TEXT is the text of the button we clicked on, a + or - item.
580 TOKEN is data related to this node.
581 INDENT is the current indentation depth."
582 (cond ((string-match "+" text
) ;expand this node
583 (if (with-current-buffer gud-comint-buffer
(eq gud-minor-mode
'gdba
))
584 (gdb-var-list-children token
)
585 (gdbmi-var-list-children token
)))
586 ((string-match "-" text
) ;contract this node
587 (dolist (var gdb-var-list
)
588 (if (string-match (concat token
"\\.") (nth 1 var
))
589 (setq gdb-var-list
(delq var gdb-var-list
))))
590 (setq gdb-var-changed t
))))
592 (defun gdb-get-target-string ()
593 (with-current-buffer gud-comint-buffer
600 ;; Each buffer has a TYPE -- a symbol that identifies the function
601 ;; of that particular buffer.
603 ;; The usual gdb interaction buffer is given the type `gdba' and
604 ;; is constructed specially.
606 ;; Others are constructed by gdb-get-create-buffer and
607 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
609 (defvar gdb-buffer-rules-assoc
'())
611 (defun gdb-get-buffer (key)
612 "Return the gdb buffer tagged with type KEY.
613 The key should be one of the cars in `gdb-buffer-rules-assoc'."
615 (gdb-look-for-tagged-buffer key
(buffer-list))))
617 (defun gdb-get-create-buffer (key)
618 "Create a new gdb buffer of the type specified by KEY.
619 The key should be one of the cars in `gdb-buffer-rules-assoc'."
620 (or (gdb-get-buffer key
)
621 (let* ((rules (assoc key gdb-buffer-rules-assoc
))
622 (name (funcall (gdb-rules-name-maker rules
)))
623 (new (get-buffer-create name
)))
624 (with-current-buffer new
626 (if (cdr (cdr rules
))
627 (setq trigger
(funcall (car (cdr (cdr rules
))))))
628 (set (make-local-variable 'gdb-buffer-type
) key
)
629 (set (make-local-variable 'gud-minor-mode
)
630 (with-current-buffer gud-comint-buffer gud-minor-mode
))
631 (set (make-local-variable 'tool-bar-map
) gud-tool-bar-map
)
632 (if trigger
(funcall trigger
)))
635 (defun gdb-rules-name-maker (rules) (car (cdr rules
)))
637 (defun gdb-look-for-tagged-buffer (key bufs
)
639 (while (and (not retval
) bufs
)
640 (set-buffer (car bufs
))
641 (if (eq gdb-buffer-type key
)
642 (setq retval
(car bufs
)))
643 (setq bufs
(cdr bufs
)))
647 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
648 ;; at least one and possible more functions. The functions have these
649 ;; roles in defining a buffer type:
651 ;; NAME - Return a name for this buffer type.
653 ;; The remaining function(s) are optional:
655 ;; MODE - called in a new buffer with no arguments, should establish
656 ;; the proper mode for the buffer.
659 (defun gdb-set-buffer-rules (buffer-type &rest rules
)
660 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc
)))
662 (setcdr binding rules
)
663 (push (cons buffer-type rules
)
664 gdb-buffer-rules-assoc
))))
666 ;; GUD buffers are an exception to the rules
667 (gdb-set-buffer-rules 'gdba
'error
)
670 ;; Partial-output buffer : This accumulates output from a command executed on
671 ;; behalf of emacs (rather than the user).
673 (gdb-set-buffer-rules 'gdb-partial-output-buffer
674 'gdb-partial-output-name
)
676 (defun gdb-partial-output-name ()
677 (concat "*partial-output-"
678 (gdb-get-target-string)
682 (gdb-set-buffer-rules 'gdb-inferior-io
683 'gdb-inferior-io-name
684 'gdb-inferior-io-mode
)
686 (defun gdb-inferior-io-name ()
687 (concat "*input/output of "
688 (gdb-get-target-string)
691 (defun gdb-display-inferior-io-buffer ()
692 "Display IO of inferior in a separate window."
694 (if gdb-use-inferior-io-buffer
696 (gdb-get-create-buffer 'gdb-inferior-io
))))
698 (defun gdb-frame-inferior-io-buffer ()
699 "Display IO of inferior in a new frame."
701 (if gdb-use-inferior-io-buffer
702 (let ((special-display-regexps (append special-display-regexps
'(".*")))
703 (special-display-frame-alist gdb-frame-parameters
))
704 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io
)))))
706 (defvar gdb-inferior-io-mode-map
707 (let ((map (make-sparse-keymap)))
708 (define-key map
"\C-c\C-c" 'gdb-inferior-io-interrupt
)
709 (define-key map
"\C-c\C-z" 'gdb-inferior-io-stop
)
710 (define-key map
"\C-c\C-\\" 'gdb-inferior-io-quit
)
711 (define-key map
"\C-c\C-d" 'gdb-inferior-io-eof
)
712 (define-key map
"\C-d" 'gdb-inferior-io-eof
)
715 (define-derived-mode gdb-inferior-io-mode comint-mode
"Inferior I/O"
716 "Major mode for gdb inferior-io."
717 :syntax-table nil
:abbrev-table nil
718 ;; We want to use comint because it has various nifty and familiar
719 ;; features. We don't need a process, but comint wants one, so create
721 (make-comint-in-buffer
722 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
723 (current-buffer) "hexl")
724 (setq comint-input-sender
'gdb-inferior-io-sender
))
726 (defun gdb-inferior-io-sender (proc string
)
727 ;; PROC is the pseudo-process created to satisfy comint.
728 (with-current-buffer (process-buffer proc
)
729 (setq proc
(get-buffer-process gud-comint-buffer
))
730 (process-send-string proc string
)
731 (process-send-string proc
"\n")))
733 (defun gdb-inferior-io-interrupt ()
734 "Interrupt the program being debugged."
737 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
739 (defun gdb-inferior-io-quit ()
740 "Send quit signal to the program being debugged."
743 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
745 (defun gdb-inferior-io-stop ()
746 "Stop the program being debugged."
749 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
751 (defun gdb-inferior-io-eof ()
752 "Send end-of-file to the program being debugged."
755 (get-buffer-process gud-comint-buffer
)))
759 ;; gdb communications
762 ;; INPUT: things sent to gdb
764 ;; The queues are lists. Each element is either a string (indicating user or
765 ;; user-like input) or a list of the form:
767 ;; (INPUT-STRING HANDLER-FN)
769 ;; The handler function will be called from the partial-output buffer when the
770 ;; command completes. This is the way to write commands which invoke gdb
771 ;; commands autonomously.
773 ;; These lists are consumed tail first.
776 (defun gdb-send (proc string
)
777 "A comint send filter for gdb.
778 This filter may simply queue input for a later time."
779 (let ((item (concat string
"\n")))
782 (if gdb-enable-debug-log
(push (cons 'send item
) gdb-debug-log
))
783 (process-send-string proc item
))
784 (gdb-enqueue-input item
))))
786 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
787 ;; is a query, or other non-top-level prompt.
789 (defun gdb-enqueue-input (item)
793 (setq gdb-prompting nil
))
794 (push item gdb-input-queue
)))
796 (defun gdb-dequeue-input ()
797 (let ((queue gdb-input-queue
))
799 (let ((last (car (last queue
))))
800 (unless (nbutlast queue
) (setq gdb-input-queue
'()))
803 (defun gdb-send-item (item)
804 (setq gdb-flush-pending-output nil
)
805 (if gdb-enable-debug-log
(push (cons 'send-item item
) gdb-debug-log
))
806 (setq gdb-current-item item
)
807 (with-current-buffer gud-comint-buffer
808 (if (eq gud-minor-mode
'gdba
)
811 (setq gdb-output-sink
'user
)
812 (process-send-string (get-buffer-process gud-comint-buffer
) item
))
814 (gdb-clear-partial-output)
815 (setq gdb-output-sink
'pre-emacs
)
816 (process-send-string (get-buffer-process gud-comint-buffer
)
818 ;; case: eq gud-minor-mode 'gdbmi
819 (gdb-clear-partial-output)
820 (setq gdb-output-sink
'emacs
)
821 (process-send-string (get-buffer-process gud-comint-buffer
)
825 ;; output -- things gdb prints to emacs
827 ;; GDB output is a stream interrupted by annotations.
828 ;; Annotations can be recognized by their beginning
829 ;; with \C-j\C-z\C-z<tag><opt>\C-j
831 ;; The tag is a string obeying symbol syntax.
833 ;; The optional part `<opt>' can be either the empty string
834 ;; or a space followed by more data relating to the annotation.
835 ;; For example, the SOURCE annotation is followed by a filename,
836 ;; line number and various useless goo. This data must not include
840 (defcustom gud-gdba-command-name
"gdb -annotate=3"
841 "Default command to execute an executable under the GDB-UI debugger."
846 (defvar gdb-annotation-rules
847 '(("pre-prompt" gdb-pre-prompt
)
848 ("prompt" gdb-prompt
)
849 ("commands" gdb-subprompt
)
850 ("overload-choice" gdb-subprompt
)
851 ("query" gdb-subprompt
)
852 ;; Need this prompt for GDB 6.1
853 ("nquery" gdb-subprompt
)
854 ("prompt-for-continue" gdb-subprompt
)
855 ("post-prompt" gdb-post-prompt
)
856 ("source" gdb-source
)
857 ("starting" gdb-starting
)
858 ("exited" gdb-exited
)
859 ("signalled" gdb-exited
)
860 ("signal" gdb-stopping
)
861 ("breakpoint" gdb-stopping
)
862 ("watchpoint" gdb-stopping
)
863 ("frame-begin" gdb-frame-begin
)
864 ("stopped" gdb-stopped
)
865 ("error-begin" gdb-error
)
867 ) "An assoc mapping annotation tags to functions which process them.")
870 (setq gdb-flush-pending-output t
)
871 (setq gud-running nil
)
872 (setq gdb-output-sink
'user
)
873 (setq gdb-input-queue nil
)
874 (setq gdb-pending-triggers nil
)
875 (setq gdb-prompting t
))
877 (defconst gdb-source-spec-regexp
878 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
880 ;; Do not use this except as an annotation handler.
881 (defun gdb-source (args)
882 (string-match gdb-source-spec-regexp args
)
883 ;; Extract the frame position from the marker.
886 (match-string 1 args
)
887 (string-to-number (match-string 2 args
))))
888 (setq gdb-frame-address
(match-string 3 args
))
889 ;; cover for auto-display output which comes *before*
890 ;; stopped annotation
891 (if (eq gdb-output-sink
'inferior
) (setq gdb-output-sink
'user
)))
893 (defun gdb-pre-prompt (ignored)
894 "An annotation handler for `pre-prompt'.
895 This terminates the collection of output from a previous command if that
896 happens to be in effect."
897 (let ((sink gdb-output-sink
))
901 (setq gdb-output-sink
'post-emacs
))
904 (error "Phase error in gdb-pre-prompt (got %s)" sink
)))))
906 (defun gdb-prompt (ignored)
907 "An annotation handler for `prompt'.
908 This sends the next command (if any) to gdb."
909 (when gdb-first-prompt
(gdb-ann3))
910 (let ((sink gdb-output-sink
))
913 ((eq sink
'post-emacs
)
914 (setq gdb-output-sink
'user
)
916 (car (cdr gdb-current-item
))))
917 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer
)
921 (error "Phase error in gdb-prompt (got %s)" sink
))))
922 (let ((input (gdb-dequeue-input)))
924 (gdb-send-item input
)
926 (setq gdb-prompting t
)
927 (gud-display-frame)))))
929 (defun gdb-subprompt (ignored)
930 "An annotation handler for non-top-level prompts."
931 (setq gdb-prompting t
))
933 (defun gdb-starting (ignored)
934 "An annotation handler for `starting'.
935 This says that I/O for the subprocess is now the program being debugged,
937 (setq gdb-active-process t
)
938 (let ((sink gdb-output-sink
))
943 (if gdb-use-inferior-io-buffer
944 (setq gdb-output-sink
'inferior
))))
947 (error "Unexpected `starting' annotation")))))
949 (defun gdb-stopping (ignored)
950 "An annotation handler for `breakpoint' and other annotations.
951 They say that I/O for the subprocess is now GDB, not the program
953 (if gdb-use-inferior-io-buffer
954 (let ((sink gdb-output-sink
))
957 (setq gdb-output-sink
'user
))
960 (error "Unexpected stopping annotation"))))))
962 (defun gdb-exited (ignored)
963 "An annotation handler for `exited' and `signalled'.
964 They say that I/O for the subprocess is now GDB, not the program
965 being debugged and that the program is no longer running. This
966 function is used to change the focus of GUD tooltips to #define
968 (setq gdb-active-process nil
)
969 (gdb-stopping ignored
))
971 (defun gdb-frame-begin (ignored)
972 (let ((sink gdb-output-sink
))
975 (setq gdb-output-sink
'user
))
980 (error "Unexpected frame-begin annotation (%S)" sink
)))))
982 (defun gdb-stopped (ignored)
983 "An annotation handler for `stopped'.
984 It is just like `gdb-stopping', except that if we already set the output
985 sink to `user' in `gdb-stopping', that is fine."
986 (setq gud-running nil
)
987 (let ((sink gdb-output-sink
))
990 (setq gdb-output-sink
'user
))
994 (error "Unexpected stopped annotation")))))
996 (defun gdb-error (ignored)
997 (setq gdb-error
(not gdb-error
)))
999 (defun gdb-post-prompt (ignored)
1000 "An annotation handler for `post-prompt'.
1001 This begins the collection of output from the current command if that
1002 happens to be appropriate."
1003 (unless gdb-pending-triggers
1004 (gdb-get-selected-frame)
1005 (gdb-invalidate-frames)
1006 (gdb-invalidate-breakpoints)
1007 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1008 ;; so gdb-frame-address is updated.
1009 ;; (gdb-invalidate-assembler)
1010 (gdb-invalidate-registers)
1011 (gdb-invalidate-memory)
1012 (gdb-invalidate-locals)
1013 (gdb-invalidate-threads)
1014 (unless (eq system-type
'darwin
) ;Breaks on Darwin's GDB-5.3.
1015 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1016 ;; only needed/used with speedbar/watch expressions
1017 (when (and (boundp 'speedbar-frame
) (frame-live-p speedbar-frame
))
1018 (setq gdb-var-changed t
) ; force update
1019 (dolist (var gdb-var-list
)
1020 (setcar (nthcdr 5 var
) nil
))
1022 (let ((sink gdb-output-sink
))
1025 ((eq sink
'pre-emacs
)
1026 (setq gdb-output-sink
'emacs
))
1029 (error "Phase error in gdb-post-prompt (got %s)" sink
)))))
1031 (defun gud-gdba-marker-filter (string)
1032 "A gud marker filter for gdb. Handle a burst of output from GDB."
1033 (if gdb-flush-pending-output
1035 (if gdb-enable-debug-log
(push (cons 'recv string
) gdb-debug-log
))
1036 ;; Recall the left over gud-marker-acc from last time
1037 (setq gud-marker-acc
(concat gud-marker-acc string
))
1038 ;; Start accumulating output for the GUD buffer
1041 ;; Process all the complete markers in this chunk.
1042 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc
)
1043 (let ((annotation (match-string 1 gud-marker-acc
)))
1045 ;; Stuff prior to the match is just ordinary output.
1046 ;; It is either concatenated to OUTPUT or directed
1051 (substring gud-marker-acc
0 (match-beginning 0))))
1053 ;; Take that stuff off the gud-marker-acc.
1054 (setq gud-marker-acc
(substring gud-marker-acc
(match-end 0)))
1056 ;; Parse the tag from the annotation, and maybe its arguments.
1057 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation
)
1058 (let* ((annotation-type (match-string 1 annotation
))
1059 (annotation-arguments (match-string 2 annotation
))
1060 (annotation-rule (assoc annotation-type
1061 gdb-annotation-rules
)))
1062 ;; Call the handler for this annotation.
1064 (funcall (car (cdr annotation-rule
))
1065 annotation-arguments
)
1066 ;; Else the annotation is not recognized. Ignore it silently,
1067 ;; so that GDB can add new annotations without causing
1071 ;; Does the remaining text end in a partial line?
1072 ;; If it does, then keep part of the gud-marker-acc until we get more.
1073 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1076 ;; Everything before the potential marker start can be output.
1078 (gdb-concat-output output
1079 (substring gud-marker-acc
0
1080 (match-beginning 0))))
1082 ;; Everything after, we save, to combine with later input.
1083 (setq gud-marker-acc
(substring gud-marker-acc
1084 (match-beginning 0))))
1086 ;; In case we know the gud-marker-acc contains no partial annotations:
1088 (setq output
(gdb-concat-output output gud-marker-acc
))
1089 (setq gud-marker-acc
"")))
1092 (defun gdb-concat-output (so-far new
)
1094 (put-text-property 0 (length new
) 'face font-lock-warning-face new
))
1095 (let ((sink gdb-output-sink
))
1097 ((eq sink
'user
) (concat so-far new
))
1098 ((or (eq sink
'pre-emacs
) (eq sink
'post-emacs
)) so-far
)
1100 (gdb-append-to-partial-output new
)
1102 ((eq sink
'inferior
)
1103 (gdb-append-to-inferior-io new
)
1107 (error "Bogon output sink %S" sink
)))))
1109 (defun gdb-append-to-partial-output (string)
1110 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer
)
1111 (goto-char (point-max))
1114 (defun gdb-clear-partial-output ()
1115 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer
)
1118 (defun gdb-append-to-inferior-io (string)
1119 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io
)
1120 (goto-char (point-max))
1121 (insert-before-markers string
))
1122 (if (not (string-equal string
""))
1123 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io
))))
1125 (defun gdb-clear-inferior-io ()
1126 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io
)
1130 ;; One trick is to have a command who's output is always available in a buffer
1131 ;; of it's own, and is always up to date. We build several buffers of this
1134 ;; There are two aspects to this: gdb has to tell us when the output for that
1135 ;; command might have changed, and we have to be able to run the command
1136 ;; behind the user's back.
1138 ;; The output phasing associated with the variable gdb-output-sink
1139 ;; help us to run commands behind the user's back.
1141 ;; Below is the code for specificly managing buffers of output from one
1145 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1146 ;; It adds an input for the command we are tracking. It should be the
1147 ;; annotation rule binding of whatever gdb sends to tell us this command
1148 ;; might have changed it's output.
1150 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1151 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1152 ;; input in the input queue (see comment about ``gdb communications'' above).
1154 (defmacro def-gdb-auto-update-trigger
(name demand-predicate gdb-command
1156 `(defun ,name
(&optional ignored
)
1157 (if (and (,demand-predicate
)
1159 gdb-pending-triggers
)))
1162 (list ,gdb-command
',output-handler
))
1163 (push ',name gdb-pending-triggers
)))))
1165 (defmacro def-gdb-auto-update-handler
(name trigger buf-key custom-defun
)
1167 (setq gdb-pending-triggers
1169 gdb-pending-triggers
))
1170 (let ((buf (gdb-get-buffer ',buf-key
)))
1172 (with-current-buffer buf
1173 (let ((p (window-point (get-buffer-window buf
0)))
1174 (buffer-read-only nil
))
1176 (insert-buffer-substring (gdb-get-create-buffer
1177 'gdb-partial-output-buffer
))
1178 (set-window-point (get-buffer-window buf
0) p
)))))
1179 ;; put customisation here
1182 (defmacro def-gdb-auto-updated-buffer
(buffer-key
1183 trigger-name gdb-command
1184 output-handler-name custom-defun
)
1186 (def-gdb-auto-update-trigger ,trigger-name
1187 ;; The demand predicate:
1188 (lambda () (gdb-get-buffer ',buffer-key
))
1190 ,output-handler-name
)
1191 (def-gdb-auto-update-handler ,output-handler-name
1192 ,trigger-name
,buffer-key
,custom-defun
)))
1196 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1198 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1199 'gdb-breakpoints-buffer-name
1200 'gdb-breakpoints-mode
)
1202 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1203 ;; This defines the auto update rule for buffers of type
1204 ;; `gdb-breakpoints-buffer'.
1206 ;; It defines a function to serve as the annotation handler that
1207 ;; handles the `foo-invalidated' message. That function is called:
1208 gdb-invalidate-breakpoints
1210 ;; To update the buffer, this command is sent to gdb.
1211 "server info breakpoints\n"
1213 ;; This also defines a function to be the handler for the output
1214 ;; from the command above. That function will copy the output into
1215 ;; the appropriately typed buffer. That function will be called:
1216 gdb-info-breakpoints-handler
1217 ;; buffer specific functions
1218 gdb-info-breakpoints-custom
)
1220 (defconst breakpoint-xpm-data
1222 static char *magick[] = {
1223 /* columns rows colors chars-per-pixel */
1239 "XPM data used for breakpoint icon.")
1241 (defconst breakpoint-enabled-pbm-data
1244 0 0 0 0 1 1 1 1 0 0 0 0
1245 0 0 0 1 1 1 1 1 1 0 0 0
1246 0 0 1 1 1 1 1 1 1 1 0 0
1247 0 1 1 1 1 1 1 1 1 1 1 0
1248 0 1 1 1 1 1 1 1 1 1 1 0
1249 0 1 1 1 1 1 1 1 1 1 1 0
1250 0 1 1 1 1 1 1 1 1 1 1 0
1251 0 0 1 1 1 1 1 1 1 1 0 0
1252 0 0 0 1 1 1 1 1 1 0 0 0
1253 0 0 0 0 1 1 1 1 0 0 0 0"
1254 "PBM data used for enabled breakpoint icon.")
1256 (defconst breakpoint-disabled-pbm-data
1268 0 0 0 1 0 1 0 1 0 0"
1269 "PBM data used for disabled breakpoint icon.")
1271 (defvar breakpoint-enabled-icon nil
1272 "Icon for enabled breakpoint in display margin.")
1274 (defvar breakpoint-disabled-icon nil
1275 "Icon for disabled breakpoint in display margin.")
1277 ;; Bitmap for breakpoint in fringe
1278 (and (display-images-p)
1279 (define-fringe-bitmap 'breakpoint
1280 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1282 (defface breakpoint-enabled
1286 "Face for enabled breakpoint icon in fringe."
1288 ;; compatibility alias for old name
1289 (put 'breakpoint-enabled-bitmap-face
'face-alias
'breakpoint-enabled
)
1291 (defface breakpoint-disabled
1292 ;; We use different values of grey for different background types,
1293 ;; so that on low-color displays it will end up as something visible
1294 ;; if it has to be approximated.
1295 '((((background dark
)) :foreground
"grey60")
1296 (((background light
)) :foreground
"grey40"))
1297 "Face for disabled breakpoint icon in fringe."
1299 ;; compatibility alias for old name
1300 (put 'breakpoint-disabled-bitmap-face
'face-alias
'breakpoint-disabled
)
1302 ;;-put breakpoint icons in relevant margins (even those set in the GUD buffer)
1303 (defun gdb-info-breakpoints-custom ()
1304 (let ((flag) (bptno))
1305 ;; remove all breakpoint-icons in source buffers but not assembler buffer
1306 (dolist (buffer (buffer-list))
1307 (with-current-buffer buffer
1308 (if (and (eq gud-minor-mode
'gdba
)
1309 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1310 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1311 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer
)
1313 (goto-char (point-min))
1314 (while (< (point) (- (point-max) 1))
1316 (if (looking-at "[^\t].*?breakpoint")
1318 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1319 (setq bptno
(match-string 1))
1320 (setq flag
(char-after (match-beginning 2)))
1322 (if (re-search-forward " in .* at\\s-+" nil t
)
1324 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1325 (let ((line (match-string 2)) (buffer-read-only nil
)
1326 (file (match-string 1)))
1327 (add-text-properties (line-beginning-position)
1329 '(mouse-face highlight
1330 help-echo
"mouse-2, RET: visit breakpoint"))
1331 (unless (file-exists-p file
)
1332 (setq file
(cdr (assoc bptno gdb-location-alist
))))
1334 (not (string-equal file
"File not found")))
1335 (with-current-buffer (find-file-noselect file
)
1336 (set (make-local-variable 'gud-minor-mode
)
1338 (set (make-local-variable 'tool-bar-map
)
1340 ;; only want one breakpoint icon at each
1343 (goto-line (string-to-number line
))
1344 (gdb-put-breakpoint-icon (eq flag ?y
) bptno
)))
1348 (match-string-no-properties 1) ":1\n")
1351 (list "info source\n"
1352 `(lambda () (gdb-get-location
1353 ,bptno
,line
,flag
))))))))))
1355 (if (gdb-get-buffer 'gdb-assembler-buffer
) (gdb-assembler-custom)))
1357 (defun gdb-mouse-set-clear-breakpoint (event)
1358 "Set/clear breakpoint in left fringe/margin with mouse click."
1360 (mouse-minibuffer-check event
)
1361 (let ((posn (event-end event
)))
1362 (if (numberp (posn-point posn
))
1363 (with-selected-window (posn-window posn
)
1365 (goto-char (posn-point posn
))
1366 (if (or (posn-object posn
)
1367 (eq (car (fringe-bitmaps-at-pos (posn-point posn
)))
1370 (gud-break nil
)))))))
1372 (defun gdb-mouse-toggle-breakpoint (event)
1373 "Enable/disable breakpoint in left fringe/margin with mouse click."
1375 (mouse-minibuffer-check event
)
1376 (let ((posn (event-end event
)))
1377 (if (numberp (posn-point posn
))
1378 (with-selected-window (posn-window posn
)
1380 (goto-char (posn-point posn
))
1384 ; (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1388 (let ((bptno (get-text-property
1389 0 'gdb-bptno
(car (posn-string posn
)))))
1391 (if (get-text-property
1392 0 'gdb-enabled
(car (posn-string posn
)))
1395 bptno
"\n")) 'ignore
))))))))
1397 (defun gdb-breakpoints-buffer-name ()
1398 (with-current-buffer gud-comint-buffer
1399 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1401 (defun gdb-display-breakpoints-buffer ()
1402 "Display status of user-settable breakpoints."
1405 (gdb-get-create-buffer 'gdb-breakpoints-buffer
)))
1407 (defconst gdb-frame-parameters
1408 '((height .
14) (width .
80)
1410 (tool-bar-lines . nil
)
1411 (menu-bar-lines . nil
)
1412 (minibuffer . nil
)))
1414 (defun gdb-frame-breakpoints-buffer ()
1415 "Display status of user-settable breakpoints in a new frame."
1417 (let ((special-display-regexps (append special-display-regexps
'(".*")))
1418 (special-display-frame-alist gdb-frame-parameters
))
1419 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer
))))
1421 (defvar gdb-breakpoints-mode-map
1422 (let ((map (make-sparse-keymap))
1423 (menu (make-sparse-keymap "Breakpoints")))
1424 (define-key menu
[quit] '("Quit" . kill-this-buffer))
1425 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1426 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1427 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1428 (suppress-keymap map)
1429 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1430 (define-key map " " 'gdb-toggle-breakpoint)
1431 (define-key map "d" 'gdb-delete-breakpoint)
1432 (define-key map "q" 'kill-this-buffer)
1433 (define-key map "\r" 'gdb-goto-breakpoint)
1434 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1435 (define-key map [follow-link] 'mouse-face)
1438 (defun gdb-breakpoints-mode ()
1439 "Major mode for gdb breakpoints.
1441 \\{gdb-breakpoints-mode-map}"
1442 (kill-all-local-variables)
1443 (setq major-mode 'gdb-breakpoints-mode)
1444 (setq mode-name "Breakpoints")
1445 (use-local-map gdb-breakpoints-mode-map)
1446 (setq buffer-read-only t)
1447 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1448 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1449 'gdb-invalidate-breakpoints
1450 'gdbmi-invalidate-breakpoints))
1452 (defun gdb-toggle-breakpoint ()
1453 "Enable/disable breakpoint at current line."
1456 (beginning-of-line 1)
1457 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1458 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1460 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1463 (concat gdb-server-prefix
1464 (if (eq ?y (char-after (match-beginning 2)))
1467 (match-string 1) "\n") 'ignore))
1468 (error "Not recognized as break/watchpoint line"))))
1470 (defun gdb-delete-breakpoint ()
1471 "Delete the breakpoint at current line."
1473 (beginning-of-line 1)
1474 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1475 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1477 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1480 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1481 (error "Not recognized as break/watchpoint line")))
1483 (defun gdb-goto-breakpoint (&optional event)
1484 "Display the breakpoint location specified at current line."
1485 (interactive (list last-input-event))
1486 (if event (mouse-set-point event))
1488 (beginning-of-line 1)
1489 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1490 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1492 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1493 \\(\\S-+\\):\\([0-9]+\\)"))
1494 (let ((bptno (match-string 1))
1495 (file (match-string 2))
1496 (line (match-string 3)))
1497 (save-selected-window
1498 (let* ((buf (find-file-noselect
1499 (if (file-exists-p file) file
1500 (cdr (assoc bptno gdb-location-alist)))))
1501 (window (display-buffer buf)))
1502 (with-current-buffer buf
1503 (goto-line (string-to-number line))
1504 (set-window-point window (point))))))
1505 (error "Not recognized as break/watchpoint line"))))
1508 ;; Frames buffer. This displays a perpetually correct bactracktrace
1509 ;; (from the command `where').
1511 ;; Alas, if your stack is deep, it is costly.
1513 (gdb-set-buffer-rules 'gdb-stack-buffer
1514 'gdb-stack-buffer-name
1517 (def-gdb-auto-updated-buffer gdb-stack-buffer
1518 gdb-invalidate-frames
1520 gdb-info-frames-handler
1521 gdb-info-frames-custom)
1523 (defun gdb-info-frames-custom ()
1524 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1526 (let ((buffer-read-only nil))
1527 (goto-char (point-min))
1528 (while (< (point) (point-max))
1529 (add-text-properties (line-beginning-position) (line-end-position)
1530 '(mouse-face highlight
1531 help-echo "mouse-2, RET: Select frame"))
1533 (when (and (looking-at "^#\\([0-9]+\\)")
1534 (equal (match-string 1) gdb-frame-number))
1535 (put-text-property (line-beginning-position) (line-end-position)
1536 'face '(:inverse-video t)))
1537 (forward-line 1))))))
1539 (defun gdb-stack-buffer-name ()
1540 (with-current-buffer gud-comint-buffer
1541 (concat "*stack frames of " (gdb-get-target-string) "*")))
1543 (defun gdb-display-stack-buffer ()
1544 "Display backtrace of current stack."
1547 (gdb-get-create-buffer 'gdb-stack-buffer)))
1549 (defun gdb-frame-stack-buffer ()
1550 "Display backtrace of current stack in a new frame."
1552 (let ((special-display-regexps (append special-display-regexps '(".*")))
1553 (special-display-frame-alist gdb-frame-parameters))
1554 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1556 (defvar gdb-frames-mode-map
1557 (let ((map (make-sparse-keymap)))
1558 (suppress-keymap map)
1559 (define-key map "q" 'kill-this-buffer)
1560 (define-key map "\r" 'gdb-frames-select)
1561 (define-key map [mouse-2] 'gdb-frames-select)
1562 (define-key map [follow-link] 'mouse-face)
1565 (defun gdb-frames-mode ()
1566 "Major mode for gdb frames.
1568 \\{gdb-frames-mode-map}"
1569 (kill-all-local-variables)
1570 (setq major-mode 'gdb-frames-mode)
1571 (setq mode-name "Frames")
1572 (setq buffer-read-only t)
1573 (use-local-map gdb-frames-mode-map)
1575 (run-mode-hooks 'gdb-frames-mode-hook)
1576 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1577 'gdb-invalidate-frames
1578 'gdbmi-invalidate-frames))
1580 (defun gdb-get-frame-number ()
1582 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1583 (n (or (and pos (match-string-no-properties 1)) "0")))
1586 (defun gdb-frames-select (&optional event)
1587 "Select the frame and display the relevant source."
1588 (interactive (list last-input-event))
1589 (if event (mouse-set-point event))
1591 (list (concat gdb-server-prefix "frame "
1592 (gdb-get-frame-number) "\n") 'ignore))
1593 (gud-display-frame))
1596 ;; Threads buffer. This displays a selectable thread list.
1598 (gdb-set-buffer-rules 'gdb-threads-buffer
1599 'gdb-threads-buffer-name
1602 (def-gdb-auto-updated-buffer gdb-threads-buffer
1603 gdb-invalidate-threads
1604 (concat gdb-server-prefix "info threads\n")
1605 gdb-info-threads-handler
1606 gdb-info-threads-custom)
1608 (defun gdb-info-threads-custom ()
1609 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1610 (let ((buffer-read-only nil))
1611 (goto-char (point-min))
1612 (while (< (point) (point-max))
1613 (add-text-properties (line-beginning-position) (line-end-position)
1614 '(mouse-face highlight
1615 help-echo "mouse-2, RET: select thread"))
1616 (forward-line 1)))))
1618 (defun gdb-threads-buffer-name ()
1619 (with-current-buffer gud-comint-buffer
1620 (concat "*threads of " (gdb-get-target-string) "*")))
1622 (defun gdb-display-threads-buffer ()
1623 "Display IDs of currently known threads."
1626 (gdb-get-create-buffer 'gdb-threads-buffer)))
1628 (defun gdb-frame-threads-buffer ()
1629 "Display IDs of currently known threads in a new frame."
1631 (let ((special-display-regexps (append special-display-regexps '(".*")))
1632 (special-display-frame-alist gdb-frame-parameters))
1633 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1635 (defvar gdb-threads-mode-map
1636 (let ((map (make-sparse-keymap)))
1637 (suppress-keymap map)
1638 (define-key map "q" 'kill-this-buffer)
1639 (define-key map "\r" 'gdb-threads-select)
1640 (define-key map [mouse-2] 'gdb-threads-select)
1643 (defun gdb-threads-mode ()
1644 "Major mode for gdb frames.
1646 \\{gdb-threads-mode-map}"
1647 (kill-all-local-variables)
1648 (setq major-mode 'gdb-threads-mode)
1649 (setq mode-name "Threads")
1650 (setq buffer-read-only t)
1651 (use-local-map gdb-threads-mode-map)
1652 (run-mode-hooks 'gdb-threads-mode-hook)
1653 'gdb-invalidate-threads)
1655 (defun gdb-get-thread-number ()
1657 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1658 (match-string-no-properties 1)))
1660 (defun gdb-threads-select (&optional event)
1661 "Select the thread and display the relevant source."
1662 (interactive (list last-input-event))
1663 (if event (mouse-set-point event))
1665 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1666 (gud-display-frame))
1669 ;; Registers buffer.
1671 (defcustom gdb-all-registers nil
1672 "Non-nil means include floating-point registers."
1677 (gdb-set-buffer-rules 'gdb-registers-buffer
1678 'gdb-registers-buffer-name
1679 'gdb-registers-mode)
1681 (def-gdb-auto-updated-buffer gdb-registers-buffer
1682 gdb-invalidate-registers
1684 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1685 gdb-info-registers-handler
1686 gdb-info-registers-custom)
1688 (defun gdb-info-registers-custom ())
1690 (defvar gdb-registers-mode-map
1691 (let ((map (make-sparse-keymap)))
1692 (suppress-keymap map)
1693 (define-key map " " 'toggle-gdb-all-registers)
1694 (define-key map "q" 'kill-this-buffer)
1697 (defun gdb-registers-mode ()
1698 "Major mode for gdb registers.
1700 \\{gdb-registers-mode-map}"
1701 (kill-all-local-variables)
1702 (setq major-mode 'gdb-registers-mode)
1703 (setq mode-name "Registers:")
1704 (setq buffer-read-only t)
1705 (use-local-map gdb-registers-mode-map)
1706 (run-mode-hooks 'gdb-registers-mode-hook)
1707 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1708 'gdb-invalidate-registers
1709 'gdbmi-invalidate-registers))
1711 (defun gdb-registers-buffer-name ()
1712 (with-current-buffer gud-comint-buffer
1713 (concat "*registers of " (gdb-get-target-string) "*")))
1715 (defun gdb-display-registers-buffer ()
1716 "Display integer register contents."
1719 (gdb-get-create-buffer 'gdb-registers-buffer)))
1721 (defun gdb-frame-registers-buffer ()
1722 "Display integer register contents in a new frame."
1724 (let ((special-display-regexps (append special-display-regexps '(".*")))
1725 (special-display-frame-alist gdb-frame-parameters))
1726 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1728 (defun toggle-gdb-all-registers ()
1729 "Toggle the display of floating-point registers."
1731 (if gdb-all-registers
1733 (setq gdb-all-registers nil)
1734 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1735 (setq mode-name "Registers:")))
1736 (setq gdb-all-registers t)
1737 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1738 (setq mode-name "Registers:All")))
1739 (gdb-invalidate-registers))
1744 (defcustom gdb-memory-repeat-count 32
1745 "Number of data items in memory window."
1750 (defcustom gdb-memory-format "x"
1751 "Display format of data items in memory window."
1752 :type '(choice (const :tag "Hexadecimal" "x")
1753 (const :tag "Signed decimal" "d")
1754 (const :tag "Unsigned decimal" "u")
1755 (const :tag "Octal" "o")
1756 (const :tag "Binary" "t"))
1760 (defcustom gdb-memory-unit "w"
1761 "Unit size of data items in memory window."
1762 :type '(choice (const :tag "Byte" "b")
1763 (const :tag "Halfword" "h")
1764 (const :tag "Word" "w")
1765 (const :tag "Giant word" "g"))
1769 (gdb-set-buffer-rules 'gdb-memory-buffer
1770 'gdb-memory-buffer-name
1773 (def-gdb-auto-updated-buffer gdb-memory-buffer
1774 gdb-invalidate-memory
1775 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1776 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1777 gdb-read-memory-handler
1778 gdb-read-memory-custom)
1780 (defun gdb-read-memory-custom ()
1782 (goto-char (point-min))
1783 (if (looking-at "0x[[:xdigit:]]+")
1784 (setq gdb-memory-address (match-string 0)))))
1786 (defvar gdb-memory-mode-map
1787 (let ((map (make-sparse-keymap)))
1788 (suppress-keymap map)
1789 (define-key map "q" 'kill-this-buffer)
1792 (defun gdb-memory-set-address (event)
1793 "Set the start memory address."
1795 (save-selected-window
1796 (select-window (posn-window (event-start event)))
1797 (let ((arg (read-from-minibuffer "Memory address: ")))
1798 (setq gdb-memory-address arg))
1799 (gdb-invalidate-memory)))
1801 (defun gdb-memory-set-repeat-count (event)
1802 "Set the number of data items in memory window."
1804 (save-selected-window
1805 (select-window (posn-window (event-start event)))
1806 (let* ((arg (read-from-minibuffer "Repeat count: "))
1807 (count (string-to-number arg)))
1809 (error "Positive numbers only")
1810 (customize-set-variable 'gdb-memory-repeat-count count)
1811 (gdb-invalidate-memory)))))
1813 (defun gdb-memory-format-binary ()
1814 "Set the display format to binary."
1816 (customize-set-variable 'gdb-memory-format "t")
1817 (gdb-invalidate-memory))
1819 (defun gdb-memory-format-octal ()
1820 "Set the display format to octal."
1822 (customize-set-variable 'gdb-memory-format "o")
1823 (gdb-invalidate-memory))
1825 (defun gdb-memory-format-unsigned ()
1826 "Set the display format to unsigned decimal."
1828 (customize-set-variable 'gdb-memory-format "u")
1829 (gdb-invalidate-memory))
1831 (defun gdb-memory-format-signed ()
1832 "Set the display format to decimal."
1834 (customize-set-variable 'gdb-memory-format "d")
1835 (gdb-invalidate-memory))
1837 (defun gdb-memory-format-hexadecimal ()
1838 "Set the display format to hexadecimal."
1840 (customize-set-variable 'gdb-memory-format "x")
1841 (gdb-invalidate-memory))
1843 (defvar gdb-memory-format-keymap
1844 (let ((map (make-sparse-keymap)))
1845 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1847 "Keymap to select format in the header line.")
1849 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1850 "Menu of display formats in the header line.")
1852 (define-key gdb-memory-format-menu [binary]
1853 '(menu-item "Binary" gdb-memory-format-binary
1854 :button (:radio . (equal gdb-memory-format "t"))))
1855 (define-key gdb-memory-format-menu [octal]
1856 '(menu-item "Octal" gdb-memory-format-octal
1857 :button (:radio . (equal gdb-memory-format "o"))))
1858 (define-key gdb-memory-format-menu [unsigned]
1859 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
1860 :button (:radio . (equal gdb-memory-format "u"))))
1861 (define-key gdb-memory-format-menu [signed]
1862 '(menu-item "Signed Decimal" gdb-memory-format-signed
1863 :button (:radio . (equal gdb-memory-format "d"))))
1864 (define-key gdb-memory-format-menu [hexadecimal]
1865 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
1866 :button (:radio . (equal gdb-memory-format "x"))))
1868 (defun gdb-memory-format-menu (event)
1870 (x-popup-menu event gdb-memory-format-menu))
1872 (defun gdb-memory-format-menu-1 (event)
1874 (save-selected-window
1875 (select-window (posn-window (event-start event)))
1876 (let* ((selection (gdb-memory-format-menu event))
1877 (binding (and selection (lookup-key gdb-memory-format-menu
1878 (vector (car selection))))))
1879 (if binding (call-interactively binding)))))
1881 (defun gdb-memory-unit-giant ()
1882 "Set the unit size to giant words (eight bytes)."
1884 (customize-set-variable 'gdb-memory-unit "g")
1885 (gdb-invalidate-memory))
1887 (defun gdb-memory-unit-word ()
1888 "Set the unit size to words (four bytes)."
1890 (customize-set-variable 'gdb-memory-unit "w")
1891 (gdb-invalidate-memory))
1893 (defun gdb-memory-unit-halfword ()
1894 "Set the unit size to halfwords (two bytes)."
1896 (customize-set-variable 'gdb-memory-unit "h")
1897 (gdb-invalidate-memory))
1899 (defun gdb-memory-unit-byte ()
1900 "Set the unit size to bytes."
1902 (customize-set-variable 'gdb-memory-unit "b")
1903 (gdb-invalidate-memory))
1905 (defvar gdb-memory-unit-keymap
1906 (let ((map (make-sparse-keymap)))
1907 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
1909 "Keymap to select units in the header line.")
1911 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
1912 "Menu of units in the header line.")
1914 (define-key gdb-memory-unit-menu [giantwords]
1915 '(menu-item "Giant words" gdb-memory-unit-giant
1916 :button (:radio . (equal gdb-memory-unit "g"))))
1917 (define-key gdb-memory-unit-menu [words]
1918 '(menu-item "Words" gdb-memory-unit-word
1919 :button (:radio . (equal gdb-memory-unit "w"))))
1920 (define-key gdb-memory-unit-menu [halfwords]
1921 '(menu-item "Halfwords" gdb-memory-unit-halfword
1922 :button (:radio . (equal gdb-memory-unit "h"))))
1923 (define-key gdb-memory-unit-menu [bytes]
1924 '(menu-item "Bytes" gdb-memory-unit-byte
1925 :button (:radio . (equal gdb-memory-unit "b"))))
1927 (defun gdb-memory-unit-menu (event)
1929 (x-popup-menu event gdb-memory-unit-menu))
1931 (defun gdb-memory-unit-menu-1 (event)
1933 (save-selected-window
1934 (select-window (posn-window (event-start event)))
1935 (let* ((selection (gdb-memory-unit-menu event))
1936 (binding (and selection (lookup-key gdb-memory-unit-menu
1937 (vector (car selection))))))
1938 (if binding (call-interactively binding)))))
1940 ;;from make-mode-line-mouse-map
1941 (defun gdb-make-header-line-mouse-map (mouse function) "\
1942 Return a keymap with single entry for mouse key MOUSE on the header line.
1943 MOUSE is defined to run function FUNCTION with no args in the buffer
1944 corresponding to the mode line clicked."
1945 (let ((map (make-sparse-keymap)))
1946 (define-key map (vector 'header-line mouse) function)
1947 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
1950 (defun gdb-memory-mode ()
1951 "Major mode for examining memory.
1953 \\{gdb-memory-mode-map}"
1954 (kill-all-local-variables)
1955 (setq major-mode 'gdb-memory-mode)
1956 (setq mode-name "Memory")
1957 (setq buffer-read-only t)
1958 (use-local-map gdb-memory-mode-map)
1959 (setq header-line-format
1965 'face font-lock-warning-face
1966 'help-echo "mouse-1: Decrement address"
1967 'mouse-face 'mode-line-highlight
1969 (gdb-make-header-line-mouse-map
1971 #'(lambda () (interactive)
1972 (let ((gdb-memory-address
1973 ;; let GDB do the arithmetic
1975 gdb-memory-address " - "
1977 (* gdb-memory-repeat-count
1978 (cond ((string= gdb-memory-unit "b") 1)
1979 ((string= gdb-memory-unit "h") 2)
1980 ((string= gdb-memory-unit "w") 4)
1981 ((string= gdb-memory-unit "g") 8)))))))
1982 (gdb-invalidate-memory)))))
1985 'face font-lock-warning-face
1986 'help-echo "mouse-1: Increment address"
1987 'mouse-face 'mode-line-highlight
1988 'local-map (gdb-make-header-line-mouse-map
1990 #'(lambda () (interactive)
1991 (let ((gdb-memory-address nil))
1992 (gdb-invalidate-memory)))))
1994 (propertize gdb-memory-address
1995 'face font-lock-warning-face
1996 'help-echo "mouse-1: Set memory address"
1997 'mouse-face 'mode-line-highlight
1998 'local-map (gdb-make-header-line-mouse-map
2000 #'gdb-memory-set-address))
2002 (propertize (number-to-string gdb-memory-repeat-count)
2003 'face font-lock-warning-face
2004 'help-echo "mouse-1: Set repeat count"
2005 'mouse-face 'mode-line-highlight
2006 'local-map (gdb-make-header-line-mouse-map
2008 #'gdb-memory-set-repeat-count))
2010 (propertize gdb-memory-format
2011 'face font-lock-warning-face
2012 'help-echo "mouse-3: Select display format"
2013 'mouse-face 'mode-line-highlight
2014 'local-map gdb-memory-format-keymap)
2016 (propertize gdb-memory-unit
2017 'face font-lock-warning-face
2018 'help-echo "mouse-3: Select unit size"
2019 'mouse-face 'mode-line-highlight
2020 'local-map gdb-memory-unit-keymap))))
2021 (run-mode-hooks 'gdb-memory-mode-hook)
2022 'gdb-invalidate-memory)
2024 (defun gdb-memory-buffer-name ()
2025 (with-current-buffer gud-comint-buffer
2026 (concat "*memory of " (gdb-get-target-string) "*")))
2028 (defun gdb-display-memory-buffer ()
2029 "Display memory contents."
2032 (gdb-get-create-buffer 'gdb-memory-buffer)))
2034 (defun gdb-frame-memory-buffer ()
2035 "Display memory contents in a new frame."
2037 (let ((special-display-regexps (append special-display-regexps '(".*")))
2038 (special-display-frame-alist gdb-frame-parameters))
2039 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2044 (gdb-set-buffer-rules 'gdb-locals-buffer
2045 'gdb-locals-buffer-name
2048 (def-gdb-auto-updated-buffer gdb-locals-buffer
2049 gdb-invalidate-locals
2050 "server info locals\n"
2051 gdb-info-locals-handler
2052 gdb-info-locals-custom)
2054 ;; Abbreviate for arrays and structures.
2055 ;; These can be expanded using gud-display.
2056 (defun gdb-info-locals-handler nil
2057 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2058 gdb-pending-triggers))
2059 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2060 (with-current-buffer buf
2061 (goto-char (point-min))
2062 (while (re-search-forward "^[ }].*\n" nil t)
2063 (replace-match "" nil nil))
2064 (goto-char (point-min))
2065 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2066 (replace-match "(structure);\n" nil nil))
2067 (goto-char (point-min))
2068 (while (re-search-forward "\\s-*{.*\n" nil t)
2069 (replace-match " (array);\n" nil nil))))
2070 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2071 (and buf (with-current-buffer buf
2072 (let ((p (window-point (get-buffer-window buf 0)))
2073 (buffer-read-only nil))
2075 (insert-buffer-substring (gdb-get-create-buffer
2076 'gdb-partial-output-buffer))
2077 (set-window-point (get-buffer-window buf 0) p)))))
2078 (run-hooks 'gdb-info-locals-hook))
2080 (defun gdb-info-locals-custom ()
2083 (defvar gdb-locals-mode-map
2084 (let ((map (make-sparse-keymap)))
2085 (suppress-keymap map)
2086 (define-key map "q" 'kill-this-buffer)
2089 (defun gdb-locals-mode ()
2090 "Major mode for gdb locals.
2092 \\{gdb-locals-mode-map}"
2093 (kill-all-local-variables)
2094 (setq major-mode 'gdb-locals-mode)
2095 (setq mode-name (concat "Locals:" gdb-selected-frame))
2096 (setq buffer-read-only t)
2097 (use-local-map gdb-locals-mode-map)
2098 (run-mode-hooks 'gdb-locals-mode-hook)
2099 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
2100 'gdb-invalidate-locals
2101 'gdbmi-invalidate-locals))
2103 (defun gdb-locals-buffer-name ()
2104 (with-current-buffer gud-comint-buffer
2105 (concat "*locals of " (gdb-get-target-string) "*")))
2107 (defun gdb-display-locals-buffer ()
2108 "Display local variables of current stack and their values."
2111 (gdb-get-create-buffer 'gdb-locals-buffer)))
2113 (defun gdb-frame-locals-buffer ()
2114 "Display local variables of current stack and their values in a new frame."
2116 (let ((special-display-regexps (append special-display-regexps '(".*")))
2117 (special-display-frame-alist gdb-frame-parameters))
2118 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2121 ;;;; Window management
2122 (defun gdb-display-buffer (buf &optional size)
2123 (let ((answer (get-buffer-window buf 0))
2126 (display-buffer buf nil 0) ;Raise the frame if necessary.
2127 ;; The buffer is not yet displayed.
2128 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2129 (let ((window (get-lru-window)))
2131 (not (eq window (get-buffer-window gud-comint-buffer))))
2133 (set-window-buffer window buf)
2134 (setq answer window))
2135 (setq must-split t)))
2137 (let* ((largest (get-largest-window))
2138 (cur-size (window-height largest))
2139 (new-size (and size (< size cur-size) (- cur-size size))))
2140 (setq answer (split-window largest new-size))
2141 (set-window-buffer answer buf)
2142 (set-window-dedicated-p answer t)))
2146 ;;; Shared keymap initialization:
2148 (let ((menu (make-sparse-keymap "GDB-Windows")))
2149 (define-key gud-menu-map [displays]
2150 `(menu-item "GDB-Windows" ,menu
2151 :visible (memq gud-minor-mode '(gdbmi gdba))))
2152 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2153 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2154 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2155 (define-key menu [disassembly]
2156 '("Disassembly" . gdb-display-assembler-buffer))
2157 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2158 (define-key menu [inferior]
2159 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2160 :enable gdb-use-inferior-io-buffer))
2161 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2162 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2163 (define-key menu [breakpoints]
2164 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2166 (let ((menu (make-sparse-keymap "GDB-Frames")))
2167 (define-key gud-menu-map [frames]
2168 `(menu-item "GDB-Frames" ,menu
2169 :visible (memq gud-minor-mode '(gdbmi gdba))))
2170 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2171 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2172 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2173 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2174 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2175 (define-key menu [inferior]
2176 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2177 :enable gdb-use-inferior-io-buffer))
2178 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2179 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2180 (define-key menu [breakpoints]
2181 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2183 (let ((menu (make-sparse-keymap "GDB-UI")))
2184 (define-key gud-menu-map [ui]
2185 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2186 (define-key menu [gdb-use-inferior-io]
2187 (menu-bar-make-toggle toggle-gdb-use-inferior-io-buffer
2188 gdb-use-inferior-io-buffer
2189 "Separate inferior IO" "Use separate IO %s"
2190 "Toggle separate IO for inferior."))
2191 (define-key menu [gdb-many-windows]
2192 '(menu-item "Display Other Windows" gdb-many-windows
2193 :help "Toggle display of locals, stack and breakpoint information"
2194 :button (:toggle . gdb-many-windows)))
2195 (define-key menu [gdb-restore-windows]
2196 '(menu-item "Restore Window Layout" gdb-restore-windows
2197 :help "Restore standard layout for debug session.")))
2199 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
2200 (unless gdb-use-inferior-io-buffer
2201 (kill-buffer (gdb-inferior-io-name))))
2203 (defun gdb-frame-gdb-buffer ()
2204 "Display GUD buffer in a new frame."
2206 (select-frame (make-frame gdb-frame-parameters))
2207 (switch-to-buffer (gdb-get-create-buffer 'gdba))
2208 (set-window-dedicated-p (selected-window) t))
2210 (defun gdb-display-gdb-buffer ()
2211 "Display GUD buffer."
2214 (gdb-get-create-buffer 'gdba)))
2216 (defun gdb-set-window-buffer (name)
2217 (set-window-buffer (selected-window) (get-buffer name))
2218 (set-window-dedicated-p (selected-window) t))
2220 (defun gdb-setup-windows ()
2221 "Layout the window pattern for gdb-many-windows."
2222 (gdb-display-locals-buffer)
2223 (gdb-display-stack-buffer)
2224 (delete-other-windows)
2225 (gdb-display-breakpoints-buffer)
2226 (delete-other-windows)
2228 (pop-to-buffer gud-comint-buffer)
2229 (split-window nil ( / ( * (window-height) 3) 4))
2230 (split-window nil ( / (window-height) 3))
2231 (split-window-horizontally)
2233 (gdb-set-window-buffer (gdb-locals-buffer-name))
2236 (if gud-last-last-frame
2237 (gud-find-file (car gud-last-last-frame))
2238 (gud-find-file gdb-main-file)))
2239 (when gdb-use-inferior-io-buffer
2240 (split-window-horizontally)
2242 (gdb-set-window-buffer
2243 (gdb-get-create-buffer 'gdb-inferior-io)))
2245 (gdb-set-window-buffer (gdb-stack-buffer-name))
2246 (split-window-horizontally)
2248 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2251 (defcustom gdb-many-windows nil
2252 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2253 In this case it starts with two windows: one displaying the GUD
2254 buffer and the other with the source file with the main routine
2255 of the inferior. Non-nil means display the layout shown for
2261 (defun gdb-many-windows (arg)
2262 "Toggle the number of windows in the basic arrangement."
2264 (setq gdb-many-windows
2266 (not gdb-many-windows)
2267 (> (prefix-numeric-value arg) 0)))
2269 (gdb-restore-windows)
2272 (defun gdb-restore-windows ()
2273 "Restore the basic arrangement of windows used by gdba.
2274 This arrangement depends on the value of `gdb-many-windows'."
2276 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2277 (delete-other-windows)
2278 (if gdb-many-windows
2283 (if gud-last-last-frame
2284 (gud-find-file (car gud-last-last-frame))
2285 (gud-find-file gdb-main-file)))
2289 "Exit a debugging session cleanly.
2290 Kills the gdb buffers and resets the source buffers."
2291 (dolist (buffer (buffer-list))
2292 (unless (eq buffer gud-comint-buffer)
2293 (with-current-buffer buffer
2294 (if (memq gud-minor-mode '(gdbmi gdba))
2295 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2297 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2298 (setq gud-minor-mode nil)
2299 (kill-local-variable 'tool-bar-map)
2300 (kill-local-variable 'gdb-define-alist))))))
2301 (when (markerp gdb-overlay-arrow-position)
2302 (move-marker gdb-overlay-arrow-position nil)
2303 (setq gdb-overlay-arrow-position nil))
2304 (setq overlay-arrow-variable-list
2305 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2306 (setq gud-running nil)
2307 (setq gdb-active-process nil)
2308 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2310 (defun gdb-source-info ()
2311 "Find the source file where the program starts and displays it with related
2313 (goto-char (point-min))
2314 (if (and (search-forward "Located in " nil t)
2315 (looking-at "\\S-+"))
2316 (setq gdb-main-file (match-string 0)))
2317 (goto-char (point-min))
2318 (if (search-forward "Includes preprocessor macro info." nil t)
2319 (setq gdb-macro-info t))
2320 (if gdb-many-windows
2322 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2324 (let ((pop-up-windows t))
2325 (display-buffer (gud-find-file gdb-main-file))))))
2327 (defun gdb-get-location (bptno line flag)
2328 "Find the directory containing the relevant source file.
2329 Put in buffer and place breakpoint icon."
2330 (goto-char (point-min))
2331 (catch 'file-not-found
2332 (if (search-forward "Located in " nil t)
2333 (when (looking-at "\\S-+")
2334 (delete (cons bptno "File not found") gdb-location-alist)
2335 (push (cons bptno (match-string 0)) gdb-location-alist))
2337 (unless (assoc bptno gdb-location-alist)
2338 (push (cons bptno "File not found") gdb-location-alist)
2339 (message-box "Cannot find source file for breakpoint location.\n\
2340 Add directory to search path for source files using the GDB command, dir."))
2341 (throw 'file-not-found nil))
2342 (with-current-buffer
2343 (find-file-noselect (match-string 0))
2344 (save-current-buffer
2345 (set (make-local-variable 'gud-minor-mode) 'gdba)
2346 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2347 ;; only want one breakpoint icon at each location
2349 (goto-line (string-to-number line))
2350 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2352 (add-hook 'find-file-hook 'gdb-find-file-hook)
2354 (defun gdb-find-file-hook ()
2355 "Set up buffer for debugging if file is part of the source code
2356 of the current session."
2357 (if (and (not gdb-find-file-unhook)
2358 ;; in case gud or gdb-ui is just loaded
2360 (buffer-name gud-comint-buffer)
2361 (with-current-buffer gud-comint-buffer
2362 (eq gud-minor-mode 'gdba)))
2365 (list (concat gdb-server-prefix "list "
2366 (file-name-nondirectory buffer-file-name)
2368 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2369 (error (setq gdb-find-file-unhook t)))))
2372 (defun gdb-put-string (putstring pos &optional dprop)
2373 "Put string PUTSTRING in front of POS in the current buffer.
2374 PUTSTRING is displayed by putting an overlay into the current buffer with a
2375 `before-string' STRING that has a `display' property whose value is
2377 (let ((string (make-string 1 ?x))
2378 (buffer (current-buffer)))
2379 (setq putstring (copy-sequence putstring))
2380 (let ((overlay (make-overlay pos pos buffer))
2382 (list (list 'margin 'left-margin) putstring))))
2383 (put-text-property 0 (length string) 'display prop string)
2384 (overlay-put overlay 'put-break t)
2385 (overlay-put overlay 'before-string string))))
2387 ;;from remove-images
2388 (defun gdb-remove-strings (start end &optional buffer)
2389 "Remove strings between START and END in BUFFER.
2390 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2391 BUFFER nil or omitted means use the current buffer."
2393 (setq buffer (current-buffer)))
2394 (dolist (overlay (overlays-in start end))
2395 (when (overlay-get overlay 'put-break)
2396 (delete-overlay overlay))))
2398 (defun gdb-put-breakpoint-icon (enabled bptno)
2399 (let ((start (- (line-beginning-position) 1))
2400 (end (+ (line-end-position) 1))
2401 (putstring (if enabled "B" "b")))
2402 (add-text-properties
2403 0 1 '(help-echo "mouse-1: set/clear bkpt, mouse-3: enable/disable bkpt")
2405 (if enabled (add-text-properties
2406 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2407 (add-text-properties
2408 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2409 (gdb-remove-breakpoint-icons start end)
2410 (if (display-images-p)
2411 (if (>= (car (window-fringes)) 8)
2414 `(left-fringe breakpoint
2417 'breakpoint-disabled)))
2418 (when (< left-margin-width 2)
2419 (save-current-buffer
2420 (setq left-margin-width 2)
2421 (if (get-buffer-window (current-buffer) 0)
2423 (get-buffer-window (current-buffer) 0)
2424 left-margin-width right-margin-width))))
2427 (or breakpoint-enabled-icon
2428 (setq breakpoint-enabled-icon
2429 (find-image `((:type xpm :data
2430 ,breakpoint-xpm-data
2431 :ascent 100 :pointer hand)
2433 ,breakpoint-enabled-pbm-data
2434 :ascent 100 :pointer hand)))))
2435 (or breakpoint-disabled-icon
2436 (setq breakpoint-disabled-icon
2437 (find-image `((:type xpm :data
2438 ,breakpoint-xpm-data
2439 :conversion disabled
2442 ,breakpoint-disabled-pbm-data
2447 (when (< left-margin-width 2)
2448 (save-current-buffer
2449 (setq left-margin-width 2)
2450 (if (get-buffer-window (current-buffer) 0)
2452 (get-buffer-window (current-buffer) 0)
2453 left-margin-width right-margin-width))))
2455 (propertize putstring
2456 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2459 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2460 (gdb-remove-strings start end)
2461 (if (display-images-p)
2462 (remove-images start end))
2464 (setq left-margin-width 0)
2465 (if (get-buffer-window (current-buffer) 0)
2467 (get-buffer-window (current-buffer) 0)
2468 left-margin-width right-margin-width))))
2472 ;; Assembler buffer.
2474 (gdb-set-buffer-rules 'gdb-assembler-buffer
2475 'gdb-assembler-buffer-name
2476 'gdb-assembler-mode)
2478 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2479 gdb-invalidate-assembler
2480 (concat gdb-server-prefix "disassemble "
2481 (if (member gdb-frame-address '(nil "main")) nil "0x")
2482 gdb-frame-address "\n")
2483 gdb-assembler-handler
2484 gdb-assembler-custom)
2486 (defun gdb-assembler-custom ()
2487 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2488 (pos 1) (address) (flag) (bptno))
2489 (with-current-buffer buffer
2491 (if (not (equal gdb-frame-address "main"))
2493 (goto-char (point-min))
2494 (if (and gdb-frame-address
2495 (re-search-forward gdb-frame-address nil t))
2499 (or gdb-overlay-arrow-position
2500 (setq gdb-overlay-arrow-position (make-marker)))
2501 (set-marker gdb-overlay-arrow-position
2502 (point) (current-buffer))))))
2503 ;; remove all breakpoint-icons in assembler buffer before updating.
2504 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2505 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2506 (goto-char (point-min))
2507 (while (< (point) (- (point-max) 1))
2509 (if (looking-at "[^\t].*?breakpoint")
2512 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2513 (setq bptno (match-string 1))
2514 (setq flag (char-after (match-beginning 2)))
2515 (setq address (match-string 3))
2516 (with-current-buffer buffer
2518 (goto-char (point-min))
2519 (if (re-search-forward address nil t)
2520 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2521 (if (not (equal gdb-frame-address "main"))
2522 (set-window-point (get-buffer-window buffer 0) pos))))
2524 (defvar gdb-assembler-mode-map
2525 (let ((map (make-sparse-keymap)))
2526 (suppress-keymap map)
2527 (define-key map "q" 'kill-this-buffer)
2530 (defvar gdb-assembler-font-lock-keywords
2531 '(;; <__function.name+n>
2532 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2533 (1 font-lock-function-name-face))
2534 ;; 0xNNNNNNNN <__function.name+n>: opcode
2535 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2536 (4 font-lock-keyword-face))
2537 ;; %register(at least i386)
2538 ("%\\sw+" . font-lock-variable-name-face)
2539 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2540 (1 font-lock-comment-face)
2541 (2 font-lock-function-name-face))
2542 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2543 "Font lock keywords used in `gdb-assembler-mode'.")
2545 (defun gdb-assembler-mode ()
2546 "Major mode for viewing code assembler.
2548 \\{gdb-assembler-mode-map}"
2549 (kill-all-local-variables)
2550 (setq major-mode 'gdb-assembler-mode)
2551 (setq mode-name (concat "Machine:" gdb-selected-frame))
2552 (setq gdb-overlay-arrow-position nil)
2553 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2554 (setq fringes-outside-margins t)
2555 (setq buffer-read-only t)
2556 (use-local-map gdb-assembler-mode-map)
2557 (gdb-invalidate-assembler)
2558 (set (make-local-variable 'font-lock-defaults)
2559 '(gdb-assembler-font-lock-keywords))
2560 (run-mode-hooks 'gdb-assembler-mode-hook)
2561 'gdb-invalidate-assembler)
2563 (defun gdb-assembler-buffer-name ()
2564 (with-current-buffer gud-comint-buffer
2565 (concat "*Disassembly of " (gdb-get-target-string) "*")))
2567 (defun gdb-display-assembler-buffer ()
2568 "Display disassembly view."
2570 (setq gdb-previous-frame nil)
2572 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2574 (defun gdb-frame-assembler-buffer ()
2575 "Display disassembly view in a new frame."
2577 (setq gdb-previous-frame nil)
2578 (let ((special-display-regexps (append special-display-regexps '(".*")))
2579 (special-display-frame-alist gdb-frame-parameters))
2580 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2582 ;; modified because if gdb-frame-address has changed value a new command
2583 ;; must be enqueued to update the buffer with the new output
2584 (defun gdb-invalidate-assembler (&optional ignored)
2585 (if (gdb-get-buffer 'gdb-assembler-buffer)
2587 (unless (and gdb-selected-frame
2588 (string-equal gdb-selected-frame gdb-previous-frame))
2589 (if (or (not (member 'gdb-invalidate-assembler
2590 gdb-pending-triggers))
2591 (not (string-equal gdb-frame-address
2592 gdb-previous-frame-address)))
2594 ;; take previous disassemble command, if any, off the queue
2595 (with-current-buffer gud-comint-buffer
2596 (let ((queue gdb-input-queue))
2597 (dolist (item queue)
2598 (if (equal (cdr item) '(gdb-assembler-handler))
2599 (setq gdb-input-queue
2600 (delete item gdb-input-queue))))))
2603 (concat gdb-server-prefix "disassemble "
2604 (if (member gdb-frame-address '(nil "main")) nil "0x")
2605 gdb-frame-address "\n")
2606 'gdb-assembler-handler))
2607 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2608 (setq gdb-previous-frame-address gdb-frame-address)
2609 (setq gdb-previous-frame gdb-selected-frame)))))))
2611 (defun gdb-get-selected-frame ()
2612 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2615 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2616 (push 'gdb-get-selected-frame
2617 gdb-pending-triggers))))
2619 (defun gdb-frame-handler ()
2620 (setq gdb-pending-triggers
2621 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2622 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2623 (goto-char (point-min))
2624 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2625 (setq gdb-frame-number (match-string 1)))
2626 (goto-char (point-min))
2627 (if (re-search-forward
2628 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2630 (setq gdb-selected-frame (match-string 2))
2631 (if (gdb-get-buffer 'gdb-locals-buffer)
2632 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2633 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2634 (if (gdb-get-buffer 'gdb-assembler-buffer)
2635 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2636 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2637 (setq gdb-frame-address (match-string 1))))
2638 (goto-char (point-min))
2639 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2640 (setq gdb-current-language (match-string 1))))
2641 (gdb-invalidate-assembler))
2645 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2646 ;;; gdb-ui.el ends here