]> code.delx.au - gnu-emacs/blob - lisp/progmodes/gdb-ui.el
(gdb-locals-watch-keymap): Add "\r" binding to local map.
[gnu-emacs] / lisp / progmodes / gdb-ui.el
1 ;;; gdb-ui.el --- User Interface for running GDB
2
3 ;; Author: Nick Roberts <nickrob@gnu.org>
4 ;; Maintainer: FSF
5 ;; Keywords: unix, tools
6
7 ;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
8
9 ;; This file is part of GNU Emacs.
10
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)
14 ;; any later version.
15
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.
20
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.
25
26 ;;; Commentary:
27
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).
35
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.
38
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.
44 ;;
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.
52 ;;
53 ;; This mode SHOULD WORK WITH GDB 5.0 ONWARDS but you will NEED GDB 6.0
54 ;; ONWARDS TO USE WATCH EXPRESSIONS.
55 ;;
56 ;; Windows Platforms:
57 ;;
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
61 ;; using a macro:
62 ;;
63 ;; #ifdef UNBUFFERED
64 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
65 ;; #endif
66 ;;
67 ;; and compiling with -DUNBUFFERED while debugging.
68 ;;
69 ;; Known Bugs:
70 ;;
71 ;; TODO:
72 ;; 1) Use MI command -data-read-memory for memory window.
73 ;; 2) Highlight changed register values (use MI commands
74 ;; -data-list-register-values and -data-list-changed-registers instead
75 ;; of 'info registers'.
76 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
77 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
78 ;; 5) After release of 22.1, use "-var-list-children --all-values"
79 ;; and "-stack-list-locals --simple-values" which need GDB 6.1 onwards.
80 ;; 6) After release of 22.1, use "-var-update --all-values" which needs
81 ;; GDB 6.4 onwards.
82 ;; 7) With gud-print and gud-pstar, print the variable name in the GUD
83 ;; buffer instead of the value's history number.
84
85 ;;; Code:
86
87 (require 'gud)
88
89 (defvar tool-bar-map)
90
91 (defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
92 (defvar gdb-previous-frame-address nil)
93 (defvar gdb-memory-address "main")
94 (defvar gdb-previous-frame nil)
95 (defvar gdb-selected-frame nil)
96 (defvar gdb-frame-number nil)
97 (defvar gdb-current-language nil)
98 (defvar gdb-var-list nil "List of variables in watch window.")
99 (defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
100 (defvar gdb-main-file nil "Source file from which program execution begins.")
101 (defvar gdb-overlay-arrow-position nil)
102 (defvar gdb-server-prefix nil)
103 (defvar gdb-flush-pending-output nil)
104 (defvar gdb-location-alist nil
105 "Alist of breakpoint numbers and full filenames.")
106 (defvar gdb-find-file-unhook nil)
107 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
108 and #define directives otherwise.")
109 (defvar gdb-error "Non-nil when GDB is reporting an error.")
110 (defvar gdb-macro-info nil
111 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
112 (defvar gdb-buffer-fringe-width nil)
113
114 (defvar gdb-buffer-type nil
115 "One of the symbols bound in `gdb-buffer-rules'.")
116 (make-variable-buffer-local 'gdb-buffer-type)
117
118 (defvar gdb-input-queue ()
119 "A list of gdb command objects.")
120
121 (defvar gdb-prompting nil
122 "True when gdb is idle with no pending input.")
123
124 (defvar gdb-output-sink 'user
125 "The disposition of the output of the current gdb command.
126 Possible values are these symbols:
127
128 `user' -- gdb output should be copied to the GUD buffer
129 for the user to see.
130
131 `inferior' -- gdb output should be copied to the inferior-io buffer.
132
133 `pre-emacs' -- output should be ignored util the post-prompt
134 annotation is received. Then the output-sink
135 becomes:...
136 `emacs' -- output should be collected in the partial-output-buffer
137 for subsequent processing by a command. This is the
138 disposition of output generated by commands that
139 gdb mode sends to gdb on its own behalf.
140 `post-emacs' -- ignore output until the prompt annotation is
141 received, then go to USER disposition.
142
143 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
144 \(`user' and `emacs').")
145
146 (defvar gdb-current-item nil
147 "The most recent command item sent to gdb.")
148
149 (defvar gdb-pending-triggers '()
150 "A list of trigger functions that have run later than their output
151 handlers.")
152
153 ;; end of gdb variables
154
155 ;;;###autoload
156 (defun gdba (command-line)
157 "Run gdb on program FILE in buffer *gud-FILE*.
158 The directory containing FILE becomes the initial working directory
159 and source-file directory for your debugger.
160
161 If `gdb-many-windows' is nil (the default value) then gdb just
162 pops up the GUD buffer unless `gdb-show-main' is t. In this case
163 it starts with two windows: one displaying the GUD buffer and the
164 other with the source file with the main routine of the inferior.
165
166 If `gdb-many-windows' is t, regardless of the value of
167 `gdb-show-main', the layout below will appear unless
168 `gdb-use-inferior-io-buffer' is nil when the source buffer
169 occupies the full width of the frame. Keybindings are given in
170 relevant buffer.
171
172 Watch expressions appear in the speedbar/slowbar.
173
174 The following commands help control operation :
175
176 `gdb-many-windows' - Toggle the number of windows gdb uses.
177 `gdb-restore-windows' - To restore the window layout.
178
179 See Info node `(emacs)GDB Graphical Interface' for a more
180 detailed description of this mode.
181
182
183 +--------------------------------------------------------------+
184 | GDB Toolbar |
185 +-------------------------------+------------------------------+
186 | GUD buffer (I/O of GDB) | Locals buffer |
187 | | |
188 | | |
189 | | |
190 +-------------------------------+------------------------------+
191 | Source buffer | I/O buffer (of inferior) |
192 | | (comint-mode) |
193 | | |
194 | | |
195 | | |
196 | | |
197 | | |
198 | | |
199 +-------------------------------+------------------------------+
200 | Stack buffer | Breakpoints buffer |
201 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
202 | | RET gdb-goto-breakpoint |
203 | | d gdb-delete-breakpoint |
204 +-------------------------------+------------------------------+"
205 ;;
206 (interactive (list (gud-query-cmdline 'gdba)))
207 ;;
208 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
209 (gdb command-line)
210 (gdb-ann3))
211
212 (defvar gdb-debug-log nil)
213
214 ;;;###autoload
215 (defcustom gdb-enable-debug-log nil
216 "Non-nil means record the process input and output in `gdb-debug-log'."
217 :type 'boolean
218 :group 'gud
219 :version "22.1")
220
221 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
222 "Shell command for generating a list of defined macros in a source file.
223 This list is used to display the #define directive associated
224 with an identifier as a tooltip. It works in a debug session with
225 GDB, when gud-tooltip-mode is t.
226
227 Set `gdb-cpp-define-alist-flags' for any include paths or
228 predefined macros."
229 :type 'string
230 :group 'gud
231 :version "22.1")
232
233 (defcustom gdb-cpp-define-alist-flags ""
234 "Preprocessor flags for `gdb-cpp-define-alist-program'."
235 :type 'string
236 :group 'gud
237 :version "22.1")
238
239 (defcustom gdb-show-main nil
240 "Non-nil means display source file containing the main routine at startup.
241 Also display the main routine in the disassembly buffer if present."
242 :type 'boolean
243 :group 'gud
244 :version "22.1")
245
246 (defcustom gdb-use-inferior-io-buffer nil
247 "Non-nil means display output from the inferior in a separate buffer."
248 :type 'boolean
249 :group 'gud
250 :version "22.1")
251
252 (defun gdb-use-inferior-io-buffer (arg)
253 "Toggle separate IO for inferior.
254 With arg, use separate IO iff arg is positive."
255 (interactive "P")
256 (setq gdb-use-inferior-io-buffer
257 (if (null arg)
258 (not gdb-use-inferior-io-buffer)
259 (> (prefix-numeric-value arg) 0)))
260 (if (and gud-comint-buffer
261 (buffer-name gud-comint-buffer))
262 (condition-case nil
263 (if gdb-use-inferior-io-buffer
264 (gdb-restore-windows)
265 (kill-buffer (gdb-inferior-io-name)))
266 (error nil))))
267
268 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
269
270 (defun gdb-create-define-alist ()
271 "Create an alist of #define directives for GUD tooltips."
272 (let* ((file (buffer-file-name))
273 (output
274 (with-output-to-string
275 (with-current-buffer standard-output
276 (call-process shell-file-name
277 (if (file-exists-p file) file nil)
278 (list t nil) nil "-c"
279 (concat gdb-cpp-define-alist-program " "
280 gdb-cpp-define-alist-flags)))))
281 (define-list (split-string output "\n" t))
282 (name))
283 (setq gdb-define-alist nil)
284 (dolist (define define-list)
285 (setq name (nth 1 (split-string define "[( ]")))
286 (push (cons name define) gdb-define-alist))))
287
288 (defun gdb-tooltip-print ()
289 (tooltip-show
290 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
291 (let ((string (buffer-string)))
292 ;; remove newline for gud-tooltip-echo-area
293 (substring string 0 (- (length string) 1))))
294 (or gud-tooltip-echo-area tooltip-use-echo-area)))
295
296 ;; If expr is a macro for a function don't print because of possible dangerous
297 ;; side-effects. Also printing a function within a tooltip generates an
298 ;; unexpected starting annotation (phase error).
299 (defun gdb-tooltip-print-1 (expr)
300 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
301 (goto-char (point-min))
302 (if (search-forward "expands to: " nil t)
303 (unless (looking-at "\\S-+.*(.*).*")
304 (gdb-enqueue-input
305 (list (concat gdb-server-prefix "print " expr "\n")
306 'gdb-tooltip-print))))))
307
308 (defun gdb-set-gud-minor-mode (buffer)
309 "Set `gud-minor-mode' from find-file if appropriate."
310 (goto-char (point-min))
311 (unless (search-forward "No source file named " nil t)
312 (condition-case nil
313 (gdb-enqueue-input
314 (list (concat gdb-server-prefix "info source\n")
315 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
316 (error (setq gdb-find-file-unhook t)))))
317
318 (defun gdb-set-gud-minor-mode-1 (buffer)
319 (goto-char (point-min))
320 (when (and (search-forward "Located in " nil t)
321 (looking-at "\\S-+")
322 (string-equal (buffer-file-name buffer)
323 (match-string 0)))
324 (with-current-buffer buffer
325 (set (make-local-variable 'gud-minor-mode) 'gdba)
326 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
327 (when gud-tooltip-mode
328 (make-local-variable 'gdb-define-alist)
329 (gdb-create-define-alist)
330 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
331
332 (defun gdb-set-gud-minor-mode-existing-buffers ()
333 (dolist (buffer (buffer-list))
334 (let ((file (buffer-file-name buffer)))
335 (if file
336 (progn
337 (gdb-enqueue-input
338 (list (concat gdb-server-prefix "list "
339 (file-name-nondirectory file) ":1\n")
340 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
341
342 (defun gdb-find-watch-expression ()
343 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
344 (varno (nth 1 var)) (expr))
345 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varno)
346 (dolist (var1 gdb-var-list)
347 (if (string-equal (nth 1 var1) (match-string 1 varno))
348 (setq expr (concat (car var1) "." (match-string 2 varno)))))
349 expr))
350
351 (defun gdb-ann3 ()
352 (setq gdb-debug-log nil)
353 (set (make-local-variable 'gud-minor-mode) 'gdba)
354 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
355 ;;
356 (gud-def gud-break (if (not (string-match "Machine" mode-name))
357 (gud-call "break %f:%l" arg)
358 (save-excursion
359 (beginning-of-line)
360 (forward-char 2)
361 (gud-call "break *%a" arg)))
362 "\C-b" "Set breakpoint at current line or address.")
363 ;;
364 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
365 (gud-call "clear %f:%l" arg)
366 (save-excursion
367 (beginning-of-line)
368 (forward-char 2)
369 (gud-call "clear *%a" arg)))
370 "\C-d" "Remove breakpoint at current line or address.")
371 ;;
372 (gud-def gud-until (if (not (string-match "Machine" mode-name))
373 (gud-call "until %f:%l" arg)
374 (save-excursion
375 (beginning-of-line)
376 (forward-char 2)
377 (gud-call "until *%a" arg)))
378 "\C-u" "Continue to current line or address.")
379 ;;
380 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
381 nil "Start or continue execution.")
382
383 ;; For debugging Emacs only.
384 (gud-def gud-pp
385 (gud-call
386 (concat
387 "pp1 " (if (eq (buffer-local-value
388 'major-mode (window-buffer)) 'speedbar-mode)
389 (gdb-find-watch-expression) "%e")) arg)
390 nil "Print the emacs s-expression.")
391
392 (define-key gud-minor-mode-map [left-margin mouse-1]
393 'gdb-mouse-set-clear-breakpoint)
394 (define-key gud-minor-mode-map [left-fringe mouse-1]
395 'gdb-mouse-set-clear-breakpoint)
396 (define-key gud-minor-mode-map [left-fringe mouse-2]
397 'gdb-mouse-until)
398 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
399 'gdb-mouse-until)
400 (define-key gud-minor-mode-map [left-margin mouse-3]
401 'gdb-mouse-toggle-breakpoint-margin)
402 (define-key gud-minor-mode-map [left-fringe mouse-3]
403 'gdb-mouse-toggle-breakpoint-fringe)
404
405 (setq comint-input-sender 'gdb-send)
406 ;;
407 ;; (re-)initialize
408 (setq gdb-frame-address (if gdb-show-main "main" nil))
409 (setq gdb-previous-frame-address nil
410 gdb-memory-address "main"
411 gdb-previous-frame nil
412 gdb-selected-frame nil
413 gdb-current-language nil
414 gdb-frame-number nil
415 gdb-var-list nil
416 gdb-var-changed nil
417 gdb-first-prompt nil
418 gdb-prompting nil
419 gdb-input-queue nil
420 gdb-current-item nil
421 gdb-pending-triggers nil
422 gdb-output-sink 'user
423 gdb-server-prefix "server "
424 gdb-flush-pending-output nil
425 gdb-location-alist nil
426 gdb-find-file-unhook nil
427 gdb-error nil
428 gdb-macro-info nil
429 gdb-buffer-fringe-width (car (window-fringes)))
430 ;;
431 (setq gdb-buffer-type 'gdba)
432 ;;
433 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
434 ;;
435 (if (eq window-system 'w32)
436 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
437 (gdb-enqueue-input (list "set height 0\n" 'ignore))
438 (gdb-enqueue-input (list "set width 0\n" 'ignore))
439 ;; find source file and compilation directory here
440 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
441 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
442 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
443 ;;
444 (gdb-set-gud-minor-mode-existing-buffers)
445 (run-hooks 'gdba-mode-hook))
446
447 (defun gdb-mouse-until (event)
448 "Execute source lines by dragging the overlay arrow (fringe) with the mouse."
449 (interactive "e")
450 (if gud-overlay-arrow-position
451 (let ((start (event-start event))
452 (end (event-end event))
453 (buffer (marker-buffer gud-overlay-arrow-position)) (line))
454 (if (not (string-match "Machine" mode-name))
455 (if (equal buffer (window-buffer (posn-window end)))
456 (with-current-buffer buffer
457 (when (or (equal start end)
458 (equal (posn-point start)
459 (marker-position
460 gud-overlay-arrow-position)))
461 (setq line (line-number-at-pos (posn-point end)))
462 (gud-call (concat "until " (number-to-string line))))))
463 (if (equal (marker-buffer gdb-overlay-arrow-position)
464 (window-buffer (posn-window end)))
465 (when (or (equal start end)
466 (equal (posn-point start)
467 (marker-position
468 gdb-overlay-arrow-position)))
469 (save-excursion
470 (goto-line (line-number-at-pos (posn-point end)))
471 (forward-char 2)
472 (gud-call (concat "until *%a")))))))))
473
474 (defcustom gdb-use-colon-colon-notation nil
475 "If non-nil use FUN::VAR format to display variables in the speedbar."
476 :type 'boolean
477 :group 'gud
478 :version "22.1")
479
480 (defun gud-watch ()
481 "Watch expression at point."
482 (interactive)
483 (require 'tooltip)
484 (save-selected-window
485 (let ((expr (tooltip-identifier-from-point (point))))
486 (if (and (string-equal gdb-current-language "c")
487 gdb-use-colon-colon-notation gdb-selected-frame)
488 (setq expr (concat gdb-selected-frame "::" expr)))
489 (catch 'already-watched
490 (dolist (var gdb-var-list)
491 (if (string-equal expr (car var)) (throw 'already-watched nil)))
492 (set-text-properties 0 (length expr) nil expr)
493 (gdb-enqueue-input
494 (list
495 (if (eq gud-minor-mode 'gdba)
496 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
497 (concat"-var-create - * " expr "\n"))
498 `(lambda () (gdb-var-create-handler ,expr))))))))
499
500 (defconst gdb-var-create-regexp
501 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
502
503 (defun gdb-var-create-handler (expr)
504 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
505 (goto-char (point-min))
506 (if (re-search-forward gdb-var-create-regexp nil t)
507 (let ((var (list expr
508 (match-string 1)
509 (match-string 2)
510 (match-string 3)
511 nil nil)))
512 (push var gdb-var-list)
513 (speedbar 1)
514 (unless (string-equal
515 speedbar-initial-expansion-list-name "GUD")
516 (speedbar-change-initial-expansion-list "GUD"))
517 (if (or (equal (nth 2 var) "0")
518 (and (equal (nth 2 var) "1")
519 (string-match "char \\*" (nth 3 var))))
520 (gdb-enqueue-input
521 (list
522 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
523 'gdba)
524 (concat "server interpreter mi \"-var-evaluate-expression "
525 (nth 1 var) "\"\n")
526 (concat "-var-evaluate-expression " (nth 1 var) "\n"))
527 `(lambda () (gdb-var-evaluate-expression-handler
528 ,(nth 1 var) nil))))
529 (setq gdb-var-changed t)))
530 (if (re-search-forward "Undefined command" nil t)
531 (message-box "Watching expressions requires gdb 6.0 onwards")
532 (message "No symbol \"%s\" in current context." expr)))))
533
534 (defun gdb-var-evaluate-expression-handler (varnum changed)
535 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
536 (goto-char (point-min))
537 (re-search-forward ".*value=\\(\".*\"\\)" nil t)
538 (catch 'var-found
539 (let ((num 0))
540 (dolist (var gdb-var-list)
541 (if (string-equal varnum (cadr var))
542 (progn
543 (if changed (setcar (nthcdr 5 var) t))
544 (setcar (nthcdr 4 var) (read (match-string 1)))
545 (setcar (nthcdr num gdb-var-list) var)
546 (throw 'var-found nil)))
547 (setq num (+ num 1))))))
548 (setq gdb-var-changed t))
549
550 (defun gdb-var-list-children (varnum)
551 (gdb-enqueue-input
552 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
553 `(lambda () (gdb-var-list-children-handler ,varnum)))))
554
555 (defconst gdb-var-list-children-regexp
556 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",\
557 type=\"\\(.*?\\)\"")
558
559 (defun gdb-var-list-children-handler (varnum)
560 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
561 (goto-char (point-min))
562 (let ((var-list nil))
563 (catch 'child-already-watched
564 (dolist (var gdb-var-list)
565 (if (string-equal varnum (cadr var))
566 (progn
567 (push var var-list)
568 (while (re-search-forward gdb-var-list-children-regexp nil t)
569 (let ((varchild (list (match-string 2)
570 (match-string 1)
571 (match-string 3)
572 (match-string 4)
573 nil nil)))
574 (dolist (var1 gdb-var-list)
575 (if (string-equal (cadr var1) (cadr varchild))
576 (throw 'child-already-watched nil)))
577 (push varchild var-list)
578 (if (or (equal (nth 2 varchild) "0")
579 (and (equal (nth 2 varchild) "1")
580 (string-match "char \\*" (nth 3 varchild))))
581 (gdb-enqueue-input
582 (list
583 (concat
584 "server interpreter mi \"-var-evaluate-expression "
585 (nth 1 varchild) "\"\n")
586 `(lambda () (gdb-var-evaluate-expression-handler
587 ,(nth 1 varchild) nil))))))))
588 (push var var-list)))
589 (setq gdb-var-list (nreverse var-list))))))
590
591 (defun gdb-var-update ()
592 (when (not (member 'gdb-var-update gdb-pending-triggers))
593 (gdb-enqueue-input
594 (list "server interpreter mi \"-var-update *\"\n"
595 'gdb-var-update-handler))
596 (push 'gdb-var-update gdb-pending-triggers)))
597
598 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
599
600 (defun gdb-var-update-handler ()
601 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
602 (goto-char (point-min))
603 (while (re-search-forward gdb-var-update-regexp nil t)
604 (catch 'var-found-1
605 (let ((varnum (match-string 1)))
606 (dolist (var gdb-var-list)
607 (when (and (string-equal varnum (cadr var))
608 (or (equal (nth 2 var) "0")
609 (and (equal (nth 2 var) "1")
610 (string-match "char \\*" (nth 3 var)))))
611 (gdb-enqueue-input
612 (list
613 (concat "server interpreter mi \"-var-evaluate-expression "
614 varnum "\"\n")
615 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t))))
616 (throw 'var-found-1 nil)))))))
617 (setq gdb-pending-triggers
618 (delq 'gdb-var-update gdb-pending-triggers))
619 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
620 ;; Dummy command to update speedbar at right time.
621 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
622 ;; Keep gdb-pending-triggers non-nil till end.
623 (push 'gdb-speedbar-timer gdb-pending-triggers)))
624
625 (defun gdb-speedbar-timer-fn ()
626 (setq gdb-pending-triggers
627 (delq 'gdb-speedbar-timer gdb-pending-triggers))
628 (with-current-buffer gud-comint-buffer
629 (speedbar-timer-fn)))
630
631 (defun gdb-var-delete ()
632 "Delete watch expression at point from the speedbar."
633 (interactive)
634 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
635 '(gdbmi gdba))
636 (let ((text (speedbar-line-text)))
637 (string-match "\\(\\S-+\\)" text)
638 (let* ((expr (match-string 1 text))
639 (var (assoc expr gdb-var-list))
640 (varnum (cadr var)))
641 (unless (string-match "\\." varnum)
642 (gdb-enqueue-input
643 (list
644 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
645 'gdba)
646 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
647 (concat "-var-delete " varnum "\n"))
648 'ignore))
649 (setq gdb-var-list (delq var gdb-var-list))
650 (dolist (varchild gdb-var-list)
651 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
652 (setq gdb-var-list (delq varchild gdb-var-list))))
653 (setq gdb-var-changed t))))))
654
655 (defun gdb-edit-value (text token indent)
656 "Assign a value to a variable displayed in the speedbar."
657 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
658 (varnum (cadr var)) (value))
659 (setq value (read-string "New value: "))
660 (gdb-enqueue-input
661 (list
662 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
663 (concat "server interpreter mi \"-var-assign "
664 varnum " " value "\"\n")
665 (concat "-var-assign " varnum " " value "\n"))
666 'ignore))))
667
668 (defcustom gdb-show-changed-values t
669 "If non-nil highlight values that have recently changed in the speedbar.
670 The highlighting is done with `font-lock-warning-face'."
671 :type 'boolean
672 :group 'gud
673 :version "22.1")
674
675 (defun gdb-speedbar-expand-node (text token indent)
676 "Expand the node the user clicked on.
677 TEXT is the text of the button we clicked on, a + or - item.
678 TOKEN is data related to this node.
679 INDENT is the current indentation depth."
680 (cond ((string-match "+" text) ;expand this node
681 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
682 (gdb-var-list-children token)
683 (progn
684 (gdbmi-var-update)
685 (gdbmi-var-list-children token))))
686 ((string-match "-" text) ;contract this node
687 (dolist (var gdb-var-list)
688 (if (string-match (concat token "\\.") (nth 1 var))
689 (setq gdb-var-list (delq var gdb-var-list))))
690 (setq gdb-var-changed t)
691 (with-current-buffer gud-comint-buffer
692 (speedbar-timer-fn)))))
693
694 (defun gdb-get-target-string ()
695 (with-current-buffer gud-comint-buffer
696 gud-target-name))
697 \f
698
699 ;;
700 ;; gdb buffers.
701 ;;
702 ;; Each buffer has a TYPE -- a symbol that identifies the function
703 ;; of that particular buffer.
704 ;;
705 ;; The usual gdb interaction buffer is given the type `gdba' and
706 ;; is constructed specially.
707 ;;
708 ;; Others are constructed by gdb-get-create-buffer and
709 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
710
711 (defvar gdb-buffer-rules-assoc '())
712
713 (defun gdb-get-buffer (key)
714 "Return the gdb buffer tagged with type KEY.
715 The key should be one of the cars in `gdb-buffer-rules-assoc'."
716 (save-excursion
717 (gdb-look-for-tagged-buffer key (buffer-list))))
718
719 (defun gdb-get-create-buffer (key)
720 "Create a new gdb buffer of the type specified by KEY.
721 The key should be one of the cars in `gdb-buffer-rules-assoc'."
722 (or (gdb-get-buffer key)
723 (let* ((rules (assoc key gdb-buffer-rules-assoc))
724 (name (funcall (gdb-rules-name-maker rules)))
725 (new (get-buffer-create name)))
726 (with-current-buffer new
727 (let ((trigger))
728 (if (cdr (cdr rules))
729 (setq trigger (funcall (car (cdr (cdr rules))))))
730 (setq gdb-buffer-type key)
731 (set (make-local-variable 'gud-minor-mode)
732 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
733 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
734 (if trigger (funcall trigger)))
735 new))))
736
737 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
738
739 (defun gdb-look-for-tagged-buffer (key bufs)
740 (let ((retval nil))
741 (while (and (not retval) bufs)
742 (set-buffer (car bufs))
743 (if (eq gdb-buffer-type key)
744 (setq retval (car bufs)))
745 (setq bufs (cdr bufs)))
746 retval))
747
748 ;;
749 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
750 ;; at least one and possible more functions. The functions have these
751 ;; roles in defining a buffer type:
752 ;;
753 ;; NAME - Return a name for this buffer type.
754 ;;
755 ;; The remaining function(s) are optional:
756 ;;
757 ;; MODE - called in a new buffer with no arguments, should establish
758 ;; the proper mode for the buffer.
759 ;;
760
761 (defun gdb-set-buffer-rules (buffer-type &rest rules)
762 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
763 (if binding
764 (setcdr binding rules)
765 (push (cons buffer-type rules)
766 gdb-buffer-rules-assoc))))
767
768 ;; GUD buffers are an exception to the rules
769 (gdb-set-buffer-rules 'gdba 'error)
770
771 ;;
772 ;; Partial-output buffer : This accumulates output from a command executed on
773 ;; behalf of emacs (rather than the user).
774 ;;
775 (gdb-set-buffer-rules 'gdb-partial-output-buffer
776 'gdb-partial-output-name)
777
778 (defun gdb-partial-output-name ()
779 (concat "*partial-output-"
780 (gdb-get-target-string)
781 "*"))
782
783 \f
784 (gdb-set-buffer-rules 'gdb-inferior-io
785 'gdb-inferior-io-name
786 'gdb-inferior-io-mode)
787
788 (defun gdb-inferior-io-name ()
789 (concat "*input/output of "
790 (gdb-get-target-string)
791 "*"))
792
793 (defun gdb-display-inferior-io-buffer ()
794 "Display IO of inferior in a separate window."
795 (interactive)
796 (if gdb-use-inferior-io-buffer
797 (gdb-display-buffer
798 (gdb-get-create-buffer 'gdb-inferior-io))))
799
800 (defconst gdb-frame-parameters
801 '((height . 14) (width . 80)
802 (unsplittable . t)
803 (tool-bar-lines . nil)
804 (menu-bar-lines . nil)
805 (minibuffer . nil)))
806
807 (defun gdb-frame-inferior-io-buffer ()
808 "Display IO of inferior in a new frame."
809 (interactive)
810 (if gdb-use-inferior-io-buffer
811 (let ((special-display-regexps (append special-display-regexps '(".*")))
812 (special-display-frame-alist gdb-frame-parameters))
813 (display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
814
815 (defvar gdb-inferior-io-mode-map
816 (let ((map (make-sparse-keymap)))
817 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
818 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
819 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
820 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
821 (define-key map "\C-d" 'gdb-inferior-io-eof)
822 map))
823
824 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
825 "Major mode for gdb inferior-io."
826 :syntax-table nil :abbrev-table nil
827 ;; We want to use comint because it has various nifty and familiar
828 ;; features. We don't need a process, but comint wants one, so create
829 ;; a dummy one.
830 (make-comint-in-buffer
831 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
832 (current-buffer) "hexl")
833 (setq comint-input-sender 'gdb-inferior-io-sender))
834
835 (defun gdb-inferior-io-sender (proc string)
836 ;; PROC is the pseudo-process created to satisfy comint.
837 (with-current-buffer (process-buffer proc)
838 (setq proc (get-buffer-process gud-comint-buffer))
839 (process-send-string proc string)
840 (process-send-string proc "\n")))
841
842 (defun gdb-inferior-io-interrupt ()
843 "Interrupt the program being debugged."
844 (interactive)
845 (interrupt-process
846 (get-buffer-process gud-comint-buffer) comint-ptyp))
847
848 (defun gdb-inferior-io-quit ()
849 "Send quit signal to the program being debugged."
850 (interactive)
851 (quit-process
852 (get-buffer-process gud-comint-buffer) comint-ptyp))
853
854 (defun gdb-inferior-io-stop ()
855 "Stop the program being debugged."
856 (interactive)
857 (stop-process
858 (get-buffer-process gud-comint-buffer) comint-ptyp))
859
860 (defun gdb-inferior-io-eof ()
861 "Send end-of-file to the program being debugged."
862 (interactive)
863 (process-send-eof
864 (get-buffer-process gud-comint-buffer)))
865 \f
866
867 ;;
868 ;; gdb communications
869 ;;
870
871 ;; INPUT: things sent to gdb
872 ;;
873 ;; The queues are lists. Each element is either a string (indicating user or
874 ;; user-like input) or a list of the form:
875 ;;
876 ;; (INPUT-STRING HANDLER-FN)
877 ;;
878 ;; The handler function will be called from the partial-output buffer when the
879 ;; command completes. This is the way to write commands which invoke gdb
880 ;; commands autonomously.
881 ;;
882 ;; These lists are consumed tail first.
883 ;;
884
885 (defun gdb-send (proc string)
886 "A comint send filter for gdb.
887 This filter may simply queue input for a later time."
888 (with-current-buffer gud-comint-buffer
889 (let ((inhibit-read-only t))
890 (remove-text-properties (point-min) (point-max) '(face))))
891 (let ((item (concat string "\n")))
892 (if gud-running
893 (progn
894 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
895 (process-send-string proc item))
896 (gdb-enqueue-input item))))
897
898 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
899 ;; is a query, or other non-top-level prompt.
900
901 (defun gdb-enqueue-input (item)
902 (if gdb-prompting
903 (progn
904 (gdb-send-item item)
905 (setq gdb-prompting nil))
906 (push item gdb-input-queue)))
907
908 (defun gdb-dequeue-input ()
909 (let ((queue gdb-input-queue))
910 (and queue
911 (let ((last (car (last queue))))
912 (unless (nbutlast queue) (setq gdb-input-queue '()))
913 last))))
914
915 (defun gdb-send-item (item)
916 (setq gdb-flush-pending-output nil)
917 (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
918 (setq gdb-current-item item)
919 (let ((process (get-buffer-process gud-comint-buffer)))
920 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
921 (if (stringp item)
922 (progn
923 (setq gdb-output-sink 'user)
924 (process-send-string process item))
925 (progn
926 (gdb-clear-partial-output)
927 (setq gdb-output-sink 'pre-emacs)
928 (process-send-string process
929 (car item))))
930 ;; case: eq gud-minor-mode 'gdbmi
931 (gdb-clear-partial-output)
932 (setq gdb-output-sink 'emacs)
933 (process-send-string process (car item)))))
934 \f
935 ;;
936 ;; output -- things gdb prints to emacs
937 ;;
938 ;; GDB output is a stream interrupted by annotations.
939 ;; Annotations can be recognized by their beginning
940 ;; with \C-j\C-z\C-z<tag><opt>\C-j
941 ;;
942 ;; The tag is a string obeying symbol syntax.
943 ;;
944 ;; The optional part `<opt>' can be either the empty string
945 ;; or a space followed by more data relating to the annotation.
946 ;; For example, the SOURCE annotation is followed by a filename,
947 ;; line number and various useless goo. This data must not include
948 ;; any newlines.
949 ;;
950
951 (defcustom gud-gdba-command-name "gdb -annotate=3"
952 "Default command to execute an executable under the GDB-UI debugger."
953 :type 'string
954 :group 'gud
955 :version "22.1")
956
957 (defvar gdb-annotation-rules
958 '(("pre-prompt" gdb-pre-prompt)
959 ("prompt" gdb-prompt)
960 ("commands" gdb-subprompt)
961 ("overload-choice" gdb-subprompt)
962 ("query" gdb-subprompt)
963 ;; Need this prompt for GDB 6.1
964 ("nquery" gdb-subprompt)
965 ("prompt-for-continue" gdb-subprompt)
966 ("post-prompt" gdb-post-prompt)
967 ("source" gdb-source)
968 ("starting" gdb-starting)
969 ("exited" gdb-exited)
970 ("signalled" gdb-exited)
971 ("signal" gdb-stopping)
972 ("breakpoint" gdb-stopping)
973 ("watchpoint" gdb-stopping)
974 ("frame-begin" gdb-frame-begin)
975 ("stopped" gdb-stopped)
976 ("error-begin" gdb-error)
977 ("error" gdb-error)
978 ) "An assoc mapping annotation tags to functions which process them.")
979
980 (defun gdb-resync()
981 (setq gdb-flush-pending-output t)
982 (setq gud-running nil)
983 (setq gdb-output-sink 'user)
984 (setq gdb-input-queue nil)
985 (setq gdb-pending-triggers nil)
986 (setq gdb-prompting t))
987
988 (defconst gdb-source-spec-regexp
989 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
990
991 ;; Do not use this except as an annotation handler.
992 (defun gdb-source (args)
993 (string-match gdb-source-spec-regexp args)
994 ;; Extract the frame position from the marker.
995 (setq gud-last-frame
996 (cons
997 (match-string 1 args)
998 (string-to-number (match-string 2 args))))
999 (setq gdb-frame-address (match-string 3 args))
1000 ;; cover for auto-display output which comes *before*
1001 ;; stopped annotation
1002 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1003
1004 (defun gdb-pre-prompt (ignored)
1005 "An annotation handler for `pre-prompt'.
1006 This terminates the collection of output from a previous command if that
1007 happens to be in effect."
1008 (let ((sink gdb-output-sink))
1009 (cond
1010 ((eq sink 'user) t)
1011 ((eq sink 'emacs)
1012 (setq gdb-output-sink 'post-emacs))
1013 (t
1014 (gdb-resync)
1015 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1016
1017 (defun gdb-prompt (ignored)
1018 "An annotation handler for `prompt'.
1019 This sends the next command (if any) to gdb."
1020 (when gdb-first-prompt (gdb-ann3))
1021 (let ((sink gdb-output-sink))
1022 (cond
1023 ((eq sink 'user) t)
1024 ((eq sink 'post-emacs)
1025 (setq gdb-output-sink 'user)
1026 (let ((handler
1027 (car (cdr gdb-current-item))))
1028 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1029 (funcall handler))))
1030 (t
1031 (gdb-resync)
1032 (error "Phase error in gdb-prompt (got %s)" sink))))
1033 (let ((input (gdb-dequeue-input)))
1034 (if input
1035 (gdb-send-item input)
1036 (progn
1037 (setq gdb-prompting t)
1038 (gud-display-frame)))))
1039
1040 (defun gdb-subprompt (ignored)
1041 "An annotation handler for non-top-level prompts."
1042 (setq gdb-prompting t))
1043
1044 (defun gdb-starting (ignored)
1045 "An annotation handler for `starting'.
1046 This says that I/O for the subprocess is now the program being debugged,
1047 not GDB."
1048 (setq gdb-active-process t)
1049 (let ((sink gdb-output-sink))
1050 (cond
1051 ((eq sink 'user)
1052 (progn
1053 (setq gud-running t)
1054 (if gdb-use-inferior-io-buffer
1055 (setq gdb-output-sink 'inferior))))
1056 (t
1057 (gdb-resync)
1058 (error "Unexpected `starting' annotation")))))
1059
1060 (defun gdb-stopping (ignored)
1061 "An annotation handler for `breakpoint' and other annotations.
1062 They say that I/O for the subprocess is now GDB, not the program
1063 being debugged."
1064 (if gdb-use-inferior-io-buffer
1065 (let ((sink gdb-output-sink))
1066 (cond
1067 ((eq sink 'inferior)
1068 (setq gdb-output-sink 'user))
1069 (t
1070 (gdb-resync)
1071 (error "Unexpected stopping annotation"))))))
1072
1073 (defun gdb-exited (ignored)
1074 "An annotation handler for `exited' and `signalled'.
1075 They say that I/O for the subprocess is now GDB, not the program
1076 being debugged and that the program is no longer running. This
1077 function is used to change the focus of GUD tooltips to #define
1078 directives."
1079 (setq gdb-active-process nil)
1080 (setq gud-overlay-arrow-position nil)
1081 (setq gdb-overlay-arrow-position nil)
1082 (gdb-stopping ignored))
1083
1084 (defun gdb-frame-begin (ignored)
1085 (let ((sink gdb-output-sink))
1086 (cond
1087 ((eq sink 'inferior)
1088 (setq gdb-output-sink 'user))
1089 ((eq sink 'user) t)
1090 ((eq sink 'emacs) t)
1091 (t
1092 (gdb-resync)
1093 (error "Unexpected frame-begin annotation (%S)" sink)))))
1094
1095 (defun gdb-stopped (ignored)
1096 "An annotation handler for `stopped'.
1097 It is just like `gdb-stopping', except that if we already set the output
1098 sink to `user' in `gdb-stopping', that is fine."
1099 (setq gud-running nil)
1100 (let ((sink gdb-output-sink))
1101 (cond
1102 ((eq sink 'inferior)
1103 (setq gdb-output-sink 'user))
1104 ((eq sink 'user) t)
1105 (t
1106 (gdb-resync)
1107 (error "Unexpected stopped annotation")))))
1108
1109 (defun gdb-error (ignored)
1110 (setq gdb-error (not gdb-error)))
1111
1112 (defun gdb-post-prompt (ignored)
1113 "An annotation handler for `post-prompt'.
1114 This begins the collection of output from the current command if that
1115 happens to be appropriate."
1116 (unless gdb-pending-triggers
1117 (gdb-get-selected-frame)
1118 (gdb-invalidate-frames)
1119 (gdb-invalidate-breakpoints)
1120 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1121 ;; so gdb-frame-address is updated.
1122 ;; (gdb-invalidate-assembler)
1123 (gdb-invalidate-registers)
1124 (gdb-invalidate-memory)
1125 (gdb-invalidate-locals)
1126 (gdb-invalidate-threads)
1127 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
1128 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1129 ;; Only needed/used with speedbar/watch expressions.
1130 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1131 (setq gdb-var-changed t) ; force update
1132 (dolist (var gdb-var-list)
1133 (setcar (nthcdr 5 var) nil))
1134 (gdb-var-update))))
1135 (let ((sink gdb-output-sink))
1136 (cond
1137 ((eq sink 'user) t)
1138 ((eq sink 'pre-emacs)
1139 (setq gdb-output-sink 'emacs))
1140 (t
1141 (gdb-resync)
1142 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1143
1144 (defun gud-gdba-marker-filter (string)
1145 "A gud marker filter for gdb. Handle a burst of output from GDB."
1146 (if gdb-flush-pending-output
1147 nil
1148 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
1149 ;; Recall the left over gud-marker-acc from last time.
1150 (setq gud-marker-acc (concat gud-marker-acc string))
1151 ;; Start accumulating output for the GUD buffer.
1152 (let ((output ""))
1153 ;;
1154 ;; Process all the complete markers in this chunk.
1155 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1156 (let ((annotation (match-string 1 gud-marker-acc)))
1157 ;;
1158 ;; Stuff prior to the match is just ordinary output.
1159 ;; It is either concatenated to OUTPUT or directed
1160 ;; elsewhere.
1161 (setq output
1162 (gdb-concat-output
1163 output
1164 (substring gud-marker-acc 0 (match-beginning 0))))
1165 ;;
1166 ;; Take that stuff off the gud-marker-acc.
1167 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
1168 ;;
1169 ;; Parse the tag from the annotation, and maybe its arguments.
1170 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1171 (let* ((annotation-type (match-string 1 annotation))
1172 (annotation-arguments (match-string 2 annotation))
1173 (annotation-rule (assoc annotation-type
1174 gdb-annotation-rules)))
1175 ;; Call the handler for this annotation.
1176 (if annotation-rule
1177 (funcall (car (cdr annotation-rule))
1178 annotation-arguments)
1179 ;; Else the annotation is not recognized. Ignore it silently,
1180 ;; so that GDB can add new annotations without causing
1181 ;; us to blow up.
1182 ))))
1183 ;;
1184 ;; Does the remaining text end in a partial line?
1185 ;; If it does, then keep part of the gud-marker-acc until we get more.
1186 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1187 gud-marker-acc)
1188 (progn
1189 ;; Everything before the potential marker start can be output.
1190 (setq output
1191 (gdb-concat-output output
1192 (substring gud-marker-acc 0
1193 (match-beginning 0))))
1194 ;;
1195 ;; Everything after, we save, to combine with later input.
1196 (setq gud-marker-acc (substring gud-marker-acc
1197 (match-beginning 0))))
1198 ;;
1199 ;; In case we know the gud-marker-acc contains no partial annotations:
1200 (progn
1201 (setq output (gdb-concat-output output gud-marker-acc))
1202 (setq gud-marker-acc "")))
1203 output)))
1204
1205 (defun gdb-concat-output (so-far new)
1206 (if gdb-error
1207 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1208 (let ((sink gdb-output-sink))
1209 (cond
1210 ((eq sink 'user) (concat so-far new))
1211 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1212 ((eq sink 'emacs)
1213 (gdb-append-to-partial-output new)
1214 so-far)
1215 ((eq sink 'inferior)
1216 (gdb-append-to-inferior-io new)
1217 so-far)
1218 (t
1219 (gdb-resync)
1220 (error "Bogon output sink %S" sink)))))
1221
1222 (defun gdb-append-to-partial-output (string)
1223 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1224 (goto-char (point-max))
1225 (insert string)))
1226
1227 (defun gdb-clear-partial-output ()
1228 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1229 (erase-buffer)))
1230
1231 (defun gdb-append-to-inferior-io (string)
1232 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1233 (goto-char (point-max))
1234 (insert-before-markers string))
1235 (if (not (string-equal string ""))
1236 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1237
1238 (defun gdb-clear-inferior-io ()
1239 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1240 (erase-buffer)))
1241 \f
1242
1243 ;; One trick is to have a command who's output is always available in a buffer
1244 ;; of it's own, and is always up to date. We build several buffers of this
1245 ;; type.
1246 ;;
1247 ;; There are two aspects to this: gdb has to tell us when the output for that
1248 ;; command might have changed, and we have to be able to run the command
1249 ;; behind the user's back.
1250 ;;
1251 ;; The output phasing associated with the variable gdb-output-sink
1252 ;; help us to run commands behind the user's back.
1253 ;;
1254 ;; Below is the code for specificly managing buffers of output from one
1255 ;; command.
1256 ;;
1257
1258 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1259 ;; It adds an input for the command we are tracking. It should be the
1260 ;; annotation rule binding of whatever gdb sends to tell us this command
1261 ;; might have changed it's output.
1262 ;;
1263 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1264 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1265 ;; input in the input queue (see comment about ``gdb communications'' above).
1266
1267 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1268 output-handler)
1269 `(defun ,name (&optional ignored)
1270 (if (and ,demand-predicate
1271 (not (member ',name
1272 gdb-pending-triggers)))
1273 (progn
1274 (gdb-enqueue-input
1275 (list ,gdb-command ',output-handler))
1276 (push ',name gdb-pending-triggers)))))
1277
1278 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1279 `(defun ,name ()
1280 (setq gdb-pending-triggers
1281 (delq ',trigger
1282 gdb-pending-triggers))
1283 (let ((buf (gdb-get-buffer ',buf-key)))
1284 (and buf
1285 (with-current-buffer buf
1286 (let* ((window (get-buffer-window buf 0))
1287 (p (window-point window))
1288 (buffer-read-only nil))
1289 (erase-buffer)
1290 (insert-buffer-substring (gdb-get-create-buffer
1291 'gdb-partial-output-buffer))
1292 (set-window-point window p)))))
1293 ;; put customisation here
1294 (,custom-defun)))
1295
1296 (defmacro def-gdb-auto-updated-buffer (buffer-key
1297 trigger-name gdb-command
1298 output-handler-name custom-defun)
1299 `(progn
1300 (def-gdb-auto-update-trigger ,trigger-name
1301 ;; The demand predicate:
1302 (gdb-get-buffer ',buffer-key)
1303 ,gdb-command
1304 ,output-handler-name)
1305 (def-gdb-auto-update-handler ,output-handler-name
1306 ,trigger-name ,buffer-key ,custom-defun)))
1307
1308 \f
1309 ;;
1310 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1311 ;;
1312 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1313 'gdb-breakpoints-buffer-name
1314 'gdb-breakpoints-mode)
1315
1316 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1317 ;; This defines the auto update rule for buffers of type
1318 ;; `gdb-breakpoints-buffer'.
1319 ;;
1320 ;; It defines a function to serve as the annotation handler that
1321 ;; handles the `foo-invalidated' message. That function is called:
1322 gdb-invalidate-breakpoints
1323 ;;
1324 ;; To update the buffer, this command is sent to gdb.
1325 "server info breakpoints\n"
1326 ;;
1327 ;; This also defines a function to be the handler for the output
1328 ;; from the command above. That function will copy the output into
1329 ;; the appropriately typed buffer. That function will be called:
1330 gdb-info-breakpoints-handler
1331 ;; buffer specific functions
1332 gdb-info-breakpoints-custom)
1333
1334 (defconst breakpoint-xpm-data
1335 "/* XPM */
1336 static char *magick[] = {
1337 /* columns rows colors chars-per-pixel */
1338 \"10 10 2 1\",
1339 \" c red\",
1340 \"+ c None\",
1341 /* pixels */
1342 \"+++ +++\",
1343 \"++ ++\",
1344 \"+ +\",
1345 \" \",
1346 \" \",
1347 \" \",
1348 \" \",
1349 \"+ +\",
1350 \"++ ++\",
1351 \"+++ +++\",
1352 };"
1353 "XPM data used for breakpoint icon.")
1354
1355 (defconst breakpoint-enabled-pbm-data
1356 "P1
1357 10 10\",
1358 0 0 0 0 1 1 1 1 0 0 0 0
1359 0 0 0 1 1 1 1 1 1 0 0 0
1360 0 0 1 1 1 1 1 1 1 1 0 0
1361 0 1 1 1 1 1 1 1 1 1 1 0
1362 0 1 1 1 1 1 1 1 1 1 1 0
1363 0 1 1 1 1 1 1 1 1 1 1 0
1364 0 1 1 1 1 1 1 1 1 1 1 0
1365 0 0 1 1 1 1 1 1 1 1 0 0
1366 0 0 0 1 1 1 1 1 1 0 0 0
1367 0 0 0 0 1 1 1 1 0 0 0 0"
1368 "PBM data used for enabled breakpoint icon.")
1369
1370 (defconst breakpoint-disabled-pbm-data
1371 "P1
1372 10 10\",
1373 0 0 1 0 1 0 1 0 0 0
1374 0 1 0 1 0 1 0 1 0 0
1375 1 0 1 0 1 0 1 0 1 0
1376 0 1 0 1 0 1 0 1 0 1
1377 1 0 1 0 1 0 1 0 1 0
1378 0 1 0 1 0 1 0 1 0 1
1379 1 0 1 0 1 0 1 0 1 0
1380 0 1 0 1 0 1 0 1 0 1
1381 0 0 1 0 1 0 1 0 1 0
1382 0 0 0 1 0 1 0 1 0 0"
1383 "PBM data used for disabled breakpoint icon.")
1384
1385 (defvar breakpoint-enabled-icon nil
1386 "Icon for enabled breakpoint in display margin.")
1387
1388 (defvar breakpoint-disabled-icon nil
1389 "Icon for disabled breakpoint in display margin.")
1390
1391 ;; Bitmap for breakpoint in fringe
1392 (and (display-images-p)
1393 (define-fringe-bitmap 'breakpoint
1394 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1395
1396 (defface breakpoint-enabled
1397 '((t
1398 :foreground "red"
1399 :weight bold))
1400 "Face for enabled breakpoint icon in fringe."
1401 :group 'gud)
1402
1403 (defface breakpoint-disabled
1404 ;; We use different values of grey for different background types,
1405 ;; so that on low-color displays it will end up as something visible
1406 ;; if it has to be approximated.
1407 '((((background dark)) :foreground "grey60")
1408 (((background light)) :foreground "grey40"))
1409 "Face for disabled breakpoint icon in fringe."
1410 :group 'gud)
1411
1412 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1413 (defun gdb-info-breakpoints-custom ()
1414 (let ((flag) (bptno))
1415 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1416 (dolist (buffer (buffer-list))
1417 (with-current-buffer buffer
1418 (if (and (eq gud-minor-mode 'gdba)
1419 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1420 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1421 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1422 (save-excursion
1423 (goto-char (point-min))
1424 (while (< (point) (- (point-max) 1))
1425 (forward-line 1)
1426 (if (looking-at "[^\t].*?breakpoint")
1427 (progn
1428 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1429 (setq bptno (match-string 1))
1430 (setq flag (char-after (match-beginning 2)))
1431 (beginning-of-line)
1432 (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
1433 (progn
1434 (let ((buffer-read-only nil))
1435 (add-text-properties (match-beginning 1) (match-end 1)
1436 '(face font-lock-function-name-face)))
1437 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1438 (let ((line (match-string 2)) (buffer-read-only nil)
1439 (file (match-string 1)))
1440 (add-text-properties (line-beginning-position)
1441 (line-end-position)
1442 '(mouse-face highlight
1443 help-echo "mouse-2, RET: visit breakpoint"))
1444 (unless (file-exists-p file)
1445 (setq file (cdr (assoc bptno gdb-location-alist))))
1446 (if (and file
1447 (not (string-equal file "File not found")))
1448 (with-current-buffer
1449 (find-file-noselect file 'nowarn)
1450 (set (make-local-variable 'gud-minor-mode)
1451 'gdba)
1452 (set (make-local-variable 'tool-bar-map)
1453 gud-tool-bar-map)
1454 ;; Only want one breakpoint icon at each
1455 ;; location.
1456 (save-excursion
1457 (goto-line (string-to-number line))
1458 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1459 (gdb-enqueue-input
1460 (list
1461 (concat "list "
1462 (match-string-no-properties 1) ":1\n")
1463 'ignore))
1464 (gdb-enqueue-input
1465 (list "info source\n"
1466 `(lambda () (gdb-get-location
1467 ,bptno ,line ,flag))))))))))
1468 (end-of-line)))))
1469 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1470
1471 (defun gdb-mouse-set-clear-breakpoint (event)
1472 "Set/clear breakpoint in left fringe/margin with mouse click."
1473 (interactive "e")
1474 (mouse-minibuffer-check event)
1475 (let ((posn (event-end event)))
1476 (if (numberp (posn-point posn))
1477 (with-selected-window (posn-window posn)
1478 (save-excursion
1479 (goto-char (posn-point posn))
1480 (if (or (posn-object posn)
1481 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1482 'breakpoint))
1483 (gud-remove nil)
1484 (gud-break nil)))))))
1485
1486 (defun gdb-mouse-toggle-breakpoint-margin (event)
1487 "Enable/disable breakpoint in left margin with mouse click."
1488 (interactive "e")
1489 (mouse-minibuffer-check event)
1490 (let ((posn (event-end event)))
1491 (if (numberp (posn-point posn))
1492 (with-selected-window (posn-window posn)
1493 (save-excursion
1494 (goto-char (posn-point posn))
1495 (if (posn-object posn)
1496 (gdb-enqueue-input
1497 (list
1498 (let ((bptno (get-text-property
1499 0 'gdb-bptno (car (posn-string posn)))))
1500 (concat
1501 (if (get-text-property
1502 0 'gdb-enabled (car (posn-string posn)))
1503 "disable "
1504 "enable ")
1505 bptno "\n"))
1506 'ignore))))))))
1507
1508 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1509 "Enable/disable breakpoint in left fringe with mouse click."
1510 (interactive "e")
1511 (mouse-minibuffer-check event)
1512 (let* ((posn (event-end event))
1513 (pos (posn-point posn))
1514 obj)
1515 (when (numberp pos)
1516 (with-selected-window (posn-window posn)
1517 (save-excursion
1518 (set-buffer (window-buffer (selected-window)))
1519 (goto-char pos)
1520 (dolist (overlay (overlays-in pos pos))
1521 (when (overlay-get overlay 'put-break)
1522 (setq obj (overlay-get overlay 'before-string))))
1523 (when (stringp obj)
1524 (gdb-enqueue-input
1525 (list
1526 (concat
1527 (if (get-text-property 0 'gdb-enabled obj)
1528 "disable "
1529 "enable ")
1530 (get-text-property 0 'gdb-bptno obj) "\n")
1531 'ignore))))))))
1532
1533 (defun gdb-breakpoints-buffer-name ()
1534 (with-current-buffer gud-comint-buffer
1535 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1536
1537 (defun gdb-display-breakpoints-buffer ()
1538 "Display status of user-settable breakpoints."
1539 (interactive)
1540 (gdb-display-buffer
1541 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1542
1543 (defun gdb-frame-breakpoints-buffer ()
1544 "Display status of user-settable breakpoints in a new frame."
1545 (interactive)
1546 (let ((special-display-regexps (append special-display-regexps '(".*")))
1547 (special-display-frame-alist gdb-frame-parameters))
1548 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1549
1550 (defvar gdb-breakpoints-mode-map
1551 (let ((map (make-sparse-keymap))
1552 (menu (make-sparse-keymap "Breakpoints")))
1553 (define-key menu [quit] '("Quit" . kill-this-buffer))
1554 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1555 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1556 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1557 (suppress-keymap map)
1558 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1559 (define-key map " " 'gdb-toggle-breakpoint)
1560 (define-key map "d" 'gdb-delete-breakpoint)
1561 (define-key map "q" 'kill-this-buffer)
1562 (define-key map "\r" 'gdb-goto-breakpoint)
1563 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1564 (define-key map [follow-link] 'mouse-face)
1565 map))
1566
1567 (defun gdb-breakpoints-mode ()
1568 "Major mode for gdb breakpoints.
1569
1570 \\{gdb-breakpoints-mode-map}"
1571 (kill-all-local-variables)
1572 (setq major-mode 'gdb-breakpoints-mode)
1573 (setq mode-name "Breakpoints")
1574 (use-local-map gdb-breakpoints-mode-map)
1575 (setq buffer-read-only t)
1576 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1577 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1578 'gdb-invalidate-breakpoints
1579 'gdbmi-invalidate-breakpoints))
1580
1581 (defun gdb-toggle-breakpoint ()
1582 "Enable/disable breakpoint at current line."
1583 (interactive)
1584 (save-excursion
1585 (beginning-of-line 1)
1586 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1587 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
1588 (looking-at
1589 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1590 (gdb-enqueue-input
1591 (list
1592 (concat gdb-server-prefix
1593 (if (eq ?y (char-after (match-beginning 2)))
1594 "disable "
1595 "enable ")
1596 (match-string 1) "\n") 'ignore))
1597 (error "Not recognized as break/watchpoint line"))))
1598
1599 (defun gdb-delete-breakpoint ()
1600 "Delete the breakpoint at current line."
1601 (interactive)
1602 (beginning-of-line 1)
1603 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1604 (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
1605 (looking-at
1606 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
1607 (gdb-enqueue-input
1608 (list
1609 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1610 (error "Not recognized as break/watchpoint line")))
1611
1612 (defun gdb-goto-breakpoint (&optional event)
1613 "Display the breakpoint location specified at current line."
1614 (interactive (list last-input-event))
1615 (if event (mouse-set-point event))
1616 ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
1617 (let ((window (get-buffer-window gud-comint-buffer)))
1618 (if window (save-selected-window (select-window window))))
1619 (save-excursion
1620 (beginning-of-line 1)
1621 (if (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1622 (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
1623 (looking-at
1624 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
1625 \\(\\S-+\\):\\([0-9]+\\)"))
1626 (let ((bptno (match-string 1))
1627 (file (match-string 2))
1628 (line (match-string 3)))
1629 (save-selected-window
1630 (let* ((buf (find-file-noselect
1631 (if (file-exists-p file) file
1632 (cdr (assoc bptno gdb-location-alist)))))
1633 (window (display-buffer buf)))
1634 (with-current-buffer buf
1635 (goto-line (string-to-number line))
1636 (set-window-point window (point))))))
1637 (error "Not recognized as break/watchpoint line"))))
1638 \f
1639
1640 ;; Frames buffer. This displays a perpetually correct bactracktrace
1641 ;; (from the command `where').
1642 ;;
1643 ;; Alas, if your stack is deep, it is costly.
1644 ;;
1645 (gdb-set-buffer-rules 'gdb-stack-buffer
1646 'gdb-stack-buffer-name
1647 'gdb-frames-mode)
1648
1649 (def-gdb-auto-updated-buffer gdb-stack-buffer
1650 gdb-invalidate-frames
1651 "server where\n"
1652 gdb-info-frames-handler
1653 gdb-info-frames-custom)
1654
1655 (defun gdb-info-frames-custom ()
1656 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1657 (save-excursion
1658 (let ((buffer-read-only nil)
1659 bl el)
1660 (goto-char (point-min))
1661 (while (< (point) (point-max))
1662 (setq bl (line-beginning-position)
1663 el (line-end-position))
1664 (unless (looking-at "No ")
1665 (add-text-properties bl el
1666 '(mouse-face highlight
1667 help-echo "mouse-2, RET: Select frame")))
1668 (goto-char bl)
1669 (when (looking-at "^#\\([0-9]+\\)")
1670 (when (string-equal (match-string 1) gdb-frame-number)
1671 (put-text-property bl (+ bl 4)
1672 'face '(:inverse-video t)))
1673 (when (re-search-forward
1674 (concat
1675 (if (string-equal (match-string 1) "0") "" " in ")
1676 "\\([^ ]+\\) (") el t)
1677 (put-text-property (match-beginning 1) (match-end 1)
1678 'face font-lock-function-name-face)
1679 (setq bl (match-end 0))
1680 (while (re-search-forward "<\\([^>]+\\)>" el t)
1681 (put-text-property (match-beginning 1) (match-end 1)
1682 'face font-lock-function-name-face))
1683 (goto-char bl)
1684 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
1685 (put-text-property (match-beginning 1) (match-end 1)
1686 'face font-lock-variable-name-face))))
1687 (forward-line 1))))))
1688
1689 (defun gdb-stack-buffer-name ()
1690 (with-current-buffer gud-comint-buffer
1691 (concat "*stack frames of " (gdb-get-target-string) "*")))
1692
1693 (defun gdb-display-stack-buffer ()
1694 "Display backtrace of current stack."
1695 (interactive)
1696 (gdb-display-buffer
1697 (gdb-get-create-buffer 'gdb-stack-buffer)))
1698
1699 (defun gdb-frame-stack-buffer ()
1700 "Display backtrace of current stack in a new frame."
1701 (interactive)
1702 (let ((special-display-regexps (append special-display-regexps '(".*")))
1703 (special-display-frame-alist gdb-frame-parameters))
1704 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1705
1706 (defvar gdb-frames-mode-map
1707 (let ((map (make-sparse-keymap)))
1708 (suppress-keymap map)
1709 (define-key map "q" 'kill-this-buffer)
1710 (define-key map "\r" 'gdb-frames-select)
1711 (define-key map [mouse-2] 'gdb-frames-select)
1712 (define-key map [follow-link] 'mouse-face)
1713 map))
1714
1715 (defun gdb-frames-mode ()
1716 "Major mode for gdb frames.
1717
1718 \\{gdb-frames-mode-map}"
1719 (kill-all-local-variables)
1720 (setq major-mode 'gdb-frames-mode)
1721 (setq mode-name "Frames")
1722 (setq buffer-read-only t)
1723 (use-local-map gdb-frames-mode-map)
1724 (font-lock-mode -1)
1725 (run-mode-hooks 'gdb-frames-mode-hook)
1726 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1727 'gdb-invalidate-frames
1728 'gdbmi-invalidate-frames))
1729
1730 (defun gdb-get-frame-number ()
1731 (save-excursion
1732 (end-of-line)
1733 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1734 (n (or (and pos (match-string-no-properties 1)) "0")))
1735 n)))
1736
1737 (defun gdb-frames-select (&optional event)
1738 "Select the frame and display the relevant source."
1739 (interactive (list last-input-event))
1740 (if event (mouse-set-point event))
1741 (gdb-enqueue-input
1742 (list (concat gdb-server-prefix "frame "
1743 (gdb-get-frame-number) "\n") 'ignore))
1744 (gud-display-frame))
1745 \f
1746
1747 ;; Threads buffer. This displays a selectable thread list.
1748 ;;
1749 (gdb-set-buffer-rules 'gdb-threads-buffer
1750 'gdb-threads-buffer-name
1751 'gdb-threads-mode)
1752
1753 (def-gdb-auto-updated-buffer gdb-threads-buffer
1754 gdb-invalidate-threads
1755 (concat gdb-server-prefix "info threads\n")
1756 gdb-info-threads-handler
1757 gdb-info-threads-custom)
1758
1759 (defun gdb-info-threads-custom ()
1760 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1761 (let ((buffer-read-only nil))
1762 (goto-char (point-min))
1763 (while (< (point) (point-max))
1764 (unless (looking-at "No ")
1765 (add-text-properties (line-beginning-position) (line-end-position)
1766 '(mouse-face highlight
1767 help-echo "mouse-2, RET: select thread")))
1768 (forward-line 1)))))
1769
1770 (defun gdb-threads-buffer-name ()
1771 (with-current-buffer gud-comint-buffer
1772 (concat "*threads of " (gdb-get-target-string) "*")))
1773
1774 (defun gdb-display-threads-buffer ()
1775 "Display IDs of currently known threads."
1776 (interactive)
1777 (gdb-display-buffer
1778 (gdb-get-create-buffer 'gdb-threads-buffer)))
1779
1780 (defun gdb-frame-threads-buffer ()
1781 "Display IDs of currently known threads in a new frame."
1782 (interactive)
1783 (let ((special-display-regexps (append special-display-regexps '(".*")))
1784 (special-display-frame-alist gdb-frame-parameters))
1785 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1786
1787 (defvar gdb-threads-mode-map
1788 (let ((map (make-sparse-keymap)))
1789 (suppress-keymap map)
1790 (define-key map "q" 'kill-this-buffer)
1791 (define-key map "\r" 'gdb-threads-select)
1792 (define-key map [mouse-2] 'gdb-threads-select)
1793 map))
1794
1795 (defvar gdb-threads-font-lock-keywords
1796 '(
1797 (") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
1798 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1799 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face))
1800 )
1801 "Font lock keywords used in `gdb-threads-mode'.")
1802
1803 (defun gdb-threads-mode ()
1804 "Major mode for gdb frames.
1805
1806 \\{gdb-threads-mode-map}"
1807 (kill-all-local-variables)
1808 (setq major-mode 'gdb-threads-mode)
1809 (setq mode-name "Threads")
1810 (setq buffer-read-only t)
1811 (use-local-map gdb-threads-mode-map)
1812 (set (make-local-variable 'font-lock-defaults)
1813 '(gdb-threads-font-lock-keywords))
1814 (run-mode-hooks 'gdb-threads-mode-hook)
1815 'gdb-invalidate-threads)
1816
1817 (defun gdb-get-thread-number ()
1818 (save-excursion
1819 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1820 (match-string-no-properties 1)))
1821
1822 (defun gdb-threads-select (&optional event)
1823 "Select the thread and display the relevant source."
1824 (interactive (list last-input-event))
1825 (if event (mouse-set-point event))
1826 (gdb-enqueue-input
1827 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1828 (gud-display-frame))
1829 \f
1830
1831 ;; Registers buffer.
1832 ;;
1833 (defcustom gdb-all-registers nil
1834 "Non-nil means include floating-point registers."
1835 :type 'boolean
1836 :group 'gud
1837 :version "22.1")
1838
1839 (gdb-set-buffer-rules 'gdb-registers-buffer
1840 'gdb-registers-buffer-name
1841 'gdb-registers-mode)
1842
1843 (def-gdb-auto-updated-buffer gdb-registers-buffer
1844 gdb-invalidate-registers
1845 (concat
1846 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
1847 gdb-info-registers-handler
1848 gdb-info-registers-custom)
1849
1850 (defun gdb-info-registers-custom ()
1851 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1852 (save-excursion
1853 (let ((buffer-read-only nil)
1854 bl)
1855 (goto-char (point-min))
1856 (while (< (point) (point-max))
1857 (setq bl (line-beginning-position))
1858 (when (looking-at "^[^ ]+")
1859 (unless (string-equal (match-string 0) "The")
1860 (put-text-property bl (match-end 0)
1861 'face font-lock-variable-name-face)))
1862 (forward-line 1))))))
1863
1864 (defvar gdb-registers-mode-map
1865 (let ((map (make-sparse-keymap)))
1866 (suppress-keymap map)
1867 (define-key map " " 'toggle-gdb-all-registers)
1868 (define-key map "q" 'kill-this-buffer)
1869 map))
1870
1871 (defun gdb-registers-mode ()
1872 "Major mode for gdb registers.
1873
1874 \\{gdb-registers-mode-map}"
1875 (kill-all-local-variables)
1876 (setq major-mode 'gdb-registers-mode)
1877 (setq mode-name "Registers:")
1878 (setq buffer-read-only t)
1879 (use-local-map gdb-registers-mode-map)
1880 (run-mode-hooks 'gdb-registers-mode-hook)
1881 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1882 'gdb-invalidate-registers
1883 'gdbmi-invalidate-registers))
1884
1885 (defun gdb-registers-buffer-name ()
1886 (with-current-buffer gud-comint-buffer
1887 (concat "*registers of " (gdb-get-target-string) "*")))
1888
1889 (defun gdb-display-registers-buffer ()
1890 "Display integer register contents."
1891 (interactive)
1892 (gdb-display-buffer
1893 (gdb-get-create-buffer 'gdb-registers-buffer)))
1894
1895 (defun gdb-frame-registers-buffer ()
1896 "Display integer register contents in a new frame."
1897 (interactive)
1898 (let ((special-display-regexps (append special-display-regexps '(".*")))
1899 (special-display-frame-alist gdb-frame-parameters))
1900 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1901
1902 (defun toggle-gdb-all-registers ()
1903 "Toggle the display of floating-point registers."
1904 (interactive)
1905 (if gdb-all-registers
1906 (progn
1907 (setq gdb-all-registers nil)
1908 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1909 (setq mode-name "Registers:")))
1910 (setq gdb-all-registers t)
1911 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
1912 (setq mode-name "Registers:All")))
1913 (gdb-invalidate-registers))
1914 \f
1915
1916 ;; Memory buffer.
1917 ;;
1918 (defcustom gdb-memory-repeat-count 32
1919 "Number of data items in memory window."
1920 :type 'integer
1921 :group 'gud
1922 :version "22.1")
1923
1924 (defcustom gdb-memory-format "x"
1925 "Display format of data items in memory window."
1926 :type '(choice (const :tag "Hexadecimal" "x")
1927 (const :tag "Signed decimal" "d")
1928 (const :tag "Unsigned decimal" "u")
1929 (const :tag "Octal" "o")
1930 (const :tag "Binary" "t"))
1931 :group 'gud
1932 :version "22.1")
1933
1934 (defcustom gdb-memory-unit "w"
1935 "Unit size of data items in memory window."
1936 :type '(choice (const :tag "Byte" "b")
1937 (const :tag "Halfword" "h")
1938 (const :tag "Word" "w")
1939 (const :tag "Giant word" "g"))
1940 :group 'gud
1941 :version "22.1")
1942
1943 (gdb-set-buffer-rules 'gdb-memory-buffer
1944 'gdb-memory-buffer-name
1945 'gdb-memory-mode)
1946
1947 (def-gdb-auto-updated-buffer gdb-memory-buffer
1948 gdb-invalidate-memory
1949 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1950 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1951 gdb-read-memory-handler
1952 gdb-read-memory-custom)
1953
1954 (defun gdb-read-memory-custom ()
1955 (save-excursion
1956 (goto-char (point-min))
1957 (if (looking-at "0x[[:xdigit:]]+")
1958 (setq gdb-memory-address (match-string 0)))))
1959
1960 (defvar gdb-memory-mode-map
1961 (let ((map (make-sparse-keymap)))
1962 (suppress-keymap map)
1963 (define-key map "q" 'kill-this-buffer)
1964 map))
1965
1966 (defun gdb-memory-set-address (event)
1967 "Set the start memory address."
1968 (interactive "e")
1969 (save-selected-window
1970 (select-window (posn-window (event-start event)))
1971 (let ((arg (read-from-minibuffer "Memory address: ")))
1972 (setq gdb-memory-address arg))
1973 (gdb-invalidate-memory)))
1974
1975 (defun gdb-memory-set-repeat-count (event)
1976 "Set the number of data items in memory window."
1977 (interactive "e")
1978 (save-selected-window
1979 (select-window (posn-window (event-start event)))
1980 (let* ((arg (read-from-minibuffer "Repeat count: "))
1981 (count (string-to-number arg)))
1982 (if (<= count 0)
1983 (error "Positive numbers only")
1984 (customize-set-variable 'gdb-memory-repeat-count count)
1985 (gdb-invalidate-memory)))))
1986
1987 (defun gdb-memory-format-binary ()
1988 "Set the display format to binary."
1989 (interactive)
1990 (customize-set-variable 'gdb-memory-format "t")
1991 (gdb-invalidate-memory))
1992
1993 (defun gdb-memory-format-octal ()
1994 "Set the display format to octal."
1995 (interactive)
1996 (customize-set-variable 'gdb-memory-format "o")
1997 (gdb-invalidate-memory))
1998
1999 (defun gdb-memory-format-unsigned ()
2000 "Set the display format to unsigned decimal."
2001 (interactive)
2002 (customize-set-variable 'gdb-memory-format "u")
2003 (gdb-invalidate-memory))
2004
2005 (defun gdb-memory-format-signed ()
2006 "Set the display format to decimal."
2007 (interactive)
2008 (customize-set-variable 'gdb-memory-format "d")
2009 (gdb-invalidate-memory))
2010
2011 (defun gdb-memory-format-hexadecimal ()
2012 "Set the display format to hexadecimal."
2013 (interactive)
2014 (customize-set-variable 'gdb-memory-format "x")
2015 (gdb-invalidate-memory))
2016
2017 (defvar gdb-memory-format-keymap
2018 (let ((map (make-sparse-keymap)))
2019 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2020 map)
2021 "Keymap to select format in the header line.")
2022
2023 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2024 "Menu of display formats in the header line.")
2025
2026 (define-key gdb-memory-format-menu [binary]
2027 '(menu-item "Binary" gdb-memory-format-binary
2028 :button (:radio . (equal gdb-memory-format "t"))))
2029 (define-key gdb-memory-format-menu [octal]
2030 '(menu-item "Octal" gdb-memory-format-octal
2031 :button (:radio . (equal gdb-memory-format "o"))))
2032 (define-key gdb-memory-format-menu [unsigned]
2033 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2034 :button (:radio . (equal gdb-memory-format "u"))))
2035 (define-key gdb-memory-format-menu [signed]
2036 '(menu-item "Signed Decimal" gdb-memory-format-signed
2037 :button (:radio . (equal gdb-memory-format "d"))))
2038 (define-key gdb-memory-format-menu [hexadecimal]
2039 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2040 :button (:radio . (equal gdb-memory-format "x"))))
2041
2042 (defun gdb-memory-format-menu (event)
2043 (interactive "@e")
2044 (x-popup-menu event gdb-memory-format-menu))
2045
2046 (defun gdb-memory-format-menu-1 (event)
2047 (interactive "e")
2048 (save-selected-window
2049 (select-window (posn-window (event-start event)))
2050 (let* ((selection (gdb-memory-format-menu event))
2051 (binding (and selection (lookup-key gdb-memory-format-menu
2052 (vector (car selection))))))
2053 (if binding (call-interactively binding)))))
2054
2055 (defun gdb-memory-unit-giant ()
2056 "Set the unit size to giant words (eight bytes)."
2057 (interactive)
2058 (customize-set-variable 'gdb-memory-unit "g")
2059 (gdb-invalidate-memory))
2060
2061 (defun gdb-memory-unit-word ()
2062 "Set the unit size to words (four bytes)."
2063 (interactive)
2064 (customize-set-variable 'gdb-memory-unit "w")
2065 (gdb-invalidate-memory))
2066
2067 (defun gdb-memory-unit-halfword ()
2068 "Set the unit size to halfwords (two bytes)."
2069 (interactive)
2070 (customize-set-variable 'gdb-memory-unit "h")
2071 (gdb-invalidate-memory))
2072
2073 (defun gdb-memory-unit-byte ()
2074 "Set the unit size to bytes."
2075 (interactive)
2076 (customize-set-variable 'gdb-memory-unit "b")
2077 (gdb-invalidate-memory))
2078
2079 (defvar gdb-memory-unit-keymap
2080 (let ((map (make-sparse-keymap)))
2081 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2082 map)
2083 "Keymap to select units in the header line.")
2084
2085 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2086 "Menu of units in the header line.")
2087
2088 (define-key gdb-memory-unit-menu [giantwords]
2089 '(menu-item "Giant words" gdb-memory-unit-giant
2090 :button (:radio . (equal gdb-memory-unit "g"))))
2091 (define-key gdb-memory-unit-menu [words]
2092 '(menu-item "Words" gdb-memory-unit-word
2093 :button (:radio . (equal gdb-memory-unit "w"))))
2094 (define-key gdb-memory-unit-menu [halfwords]
2095 '(menu-item "Halfwords" gdb-memory-unit-halfword
2096 :button (:radio . (equal gdb-memory-unit "h"))))
2097 (define-key gdb-memory-unit-menu [bytes]
2098 '(menu-item "Bytes" gdb-memory-unit-byte
2099 :button (:radio . (equal gdb-memory-unit "b"))))
2100
2101 (defun gdb-memory-unit-menu (event)
2102 (interactive "@e")
2103 (x-popup-menu event gdb-memory-unit-menu))
2104
2105 (defun gdb-memory-unit-menu-1 (event)
2106 (interactive "e")
2107 (save-selected-window
2108 (select-window (posn-window (event-start event)))
2109 (let* ((selection (gdb-memory-unit-menu event))
2110 (binding (and selection (lookup-key gdb-memory-unit-menu
2111 (vector (car selection))))))
2112 (if binding (call-interactively binding)))))
2113
2114 ;;from make-mode-line-mouse-map
2115 (defun gdb-make-header-line-mouse-map (mouse function) "\
2116 Return a keymap with single entry for mouse key MOUSE on the header line.
2117 MOUSE is defined to run function FUNCTION with no args in the buffer
2118 corresponding to the mode line clicked."
2119 (let ((map (make-sparse-keymap)))
2120 (define-key map (vector 'header-line mouse) function)
2121 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2122 map))
2123
2124 (defvar gdb-memory-font-lock-keywords
2125 '(;; <__function.name+n>
2126 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2127 )
2128 "Font lock keywords used in `gdb-memory-mode'.")
2129
2130 (defun gdb-memory-mode ()
2131 "Major mode for examining memory.
2132
2133 \\{gdb-memory-mode-map}"
2134 (kill-all-local-variables)
2135 (setq major-mode 'gdb-memory-mode)
2136 (setq mode-name "Memory")
2137 (setq buffer-read-only t)
2138 (use-local-map gdb-memory-mode-map)
2139 (setq header-line-format
2140 '(:eval
2141 (concat
2142 "Read address["
2143 (propertize
2144 "-"
2145 'face font-lock-warning-face
2146 'help-echo "mouse-1: Decrement address"
2147 'mouse-face 'mode-line-highlight
2148 'local-map
2149 (gdb-make-header-line-mouse-map
2150 'mouse-1
2151 #'(lambda () (interactive)
2152 (let ((gdb-memory-address
2153 ;; Let GDB do the arithmetic.
2154 (concat
2155 gdb-memory-address " - "
2156 (number-to-string
2157 (* gdb-memory-repeat-count
2158 (cond ((string= gdb-memory-unit "b") 1)
2159 ((string= gdb-memory-unit "h") 2)
2160 ((string= gdb-memory-unit "w") 4)
2161 ((string= gdb-memory-unit "g") 8)))))))
2162 (gdb-invalidate-memory)))))
2163 "|"
2164 (propertize "+"
2165 'face font-lock-warning-face
2166 'help-echo "mouse-1: Increment address"
2167 'mouse-face 'mode-line-highlight
2168 'local-map (gdb-make-header-line-mouse-map
2169 'mouse-1
2170 #'(lambda () (interactive)
2171 (let ((gdb-memory-address nil))
2172 (gdb-invalidate-memory)))))
2173 "]: "
2174 (propertize gdb-memory-address
2175 'face font-lock-warning-face
2176 'help-echo "mouse-1: Set memory address"
2177 'mouse-face 'mode-line-highlight
2178 'local-map (gdb-make-header-line-mouse-map
2179 'mouse-1
2180 #'gdb-memory-set-address))
2181 " Repeat Count: "
2182 (propertize (number-to-string gdb-memory-repeat-count)
2183 'face font-lock-warning-face
2184 'help-echo "mouse-1: Set repeat count"
2185 'mouse-face 'mode-line-highlight
2186 'local-map (gdb-make-header-line-mouse-map
2187 'mouse-1
2188 #'gdb-memory-set-repeat-count))
2189 " Display Format: "
2190 (propertize gdb-memory-format
2191 'face font-lock-warning-face
2192 'help-echo "mouse-3: Select display format"
2193 'mouse-face 'mode-line-highlight
2194 'local-map gdb-memory-format-keymap)
2195 " Unit Size: "
2196 (propertize gdb-memory-unit
2197 'face font-lock-warning-face
2198 'help-echo "mouse-3: Select unit size"
2199 'mouse-face 'mode-line-highlight
2200 'local-map gdb-memory-unit-keymap))))
2201 (set (make-local-variable 'font-lock-defaults)
2202 '(gdb-memory-font-lock-keywords))
2203 (run-mode-hooks 'gdb-memory-mode-hook)
2204 'gdb-invalidate-memory)
2205
2206 (defun gdb-memory-buffer-name ()
2207 (with-current-buffer gud-comint-buffer
2208 (concat "*memory of " (gdb-get-target-string) "*")))
2209
2210 (defun gdb-display-memory-buffer ()
2211 "Display memory contents."
2212 (interactive)
2213 (gdb-display-buffer
2214 (gdb-get-create-buffer 'gdb-memory-buffer)))
2215
2216 (defun gdb-frame-memory-buffer ()
2217 "Display memory contents in a new frame."
2218 (interactive)
2219 (let ((special-display-regexps (append special-display-regexps '(".*")))
2220 (special-display-frame-alist gdb-frame-parameters))
2221 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
2222 \f
2223
2224 ;; Locals buffer.
2225 ;;
2226 (gdb-set-buffer-rules 'gdb-locals-buffer
2227 'gdb-locals-buffer-name
2228 'gdb-locals-mode)
2229
2230 (def-gdb-auto-update-trigger gdb-invalidate-locals
2231 (gdb-get-buffer 'gdb-locals-buffer)
2232 "server info locals\n"
2233 gdb-info-locals-handler)
2234
2235 (defvar gdb-locals-watch-keymap
2236 (let ((map (make-sparse-keymap)))
2237 (define-key map "\r" '(lambda () (interactive)
2238 (beginning-of-line)
2239 (gud-watch)))
2240 (define-key map [mouse-2] '(lambda (event) (interactive "e")
2241 (mouse-set-point event)
2242 (beginning-of-line)
2243 (gud-watch)))
2244 map)
2245 "Keymap to create watch expression of a complex data type local variable.")
2246
2247 (defconst gdb-struct-string
2248 (concat (propertize "[struct/union];"
2249 'mouse-face 'highlight
2250 'help-echo "mouse-2: create watch expression"
2251 'local-map gdb-locals-watch-keymap) "\n"))
2252
2253 (defconst gdb-array-string
2254 (concat " " (propertize "[array];"
2255 'mouse-face 'highlight
2256 'help-echo "mouse-2: create watch expression"
2257 'local-map gdb-locals-watch-keymap) "\n"))
2258
2259 ;; Abbreviate for arrays and structures.
2260 ;; These can be expanded using gud-display.
2261 (defun gdb-info-locals-handler ()
2262 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2263 gdb-pending-triggers))
2264 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2265 (with-current-buffer buf
2266 (goto-char (point-min))
2267 (while (re-search-forward "^[ }].*\n" nil t)
2268 (replace-match "" nil nil))
2269 (goto-char (point-min))
2270 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2271 (replace-match gdb-struct-string nil nil))
2272 (goto-char (point-min))
2273 (while (re-search-forward "\\s-*{.*\n" nil t)
2274 (replace-match gdb-array-string nil nil))))
2275 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2276 (and buf
2277 (with-current-buffer buf
2278 (let* ((window (get-buffer-window buf 0))
2279 (p (window-point window))
2280 (buffer-read-only nil))
2281 (erase-buffer)
2282 (insert-buffer-substring (gdb-get-create-buffer
2283 'gdb-partial-output-buffer))
2284 (set-window-point window p)))))
2285 (run-hooks 'gdb-info-locals-hook))
2286
2287 (defvar gdb-locals-mode-map
2288 (let ((map (make-sparse-keymap)))
2289 (suppress-keymap map)
2290 (define-key map "q" 'kill-this-buffer)
2291 map))
2292
2293 (defvar gdb-locals-font-lock-keywords
2294 '(
2295 ;; var = (struct struct_tag) value
2296 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
2297 (1 font-lock-variable-name-face)
2298 (3 font-lock-keyword-face)
2299 (4 font-lock-type-face))
2300 ;; var = (type) value
2301 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
2302 (1 font-lock-variable-name-face)
2303 (3 font-lock-type-face))
2304 ;; var = val
2305 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
2306 (1 font-lock-variable-name-face))
2307 )
2308 "Font lock keywords used in `gdb-local-mode'.")
2309
2310 (defun gdb-locals-mode ()
2311 "Major mode for gdb locals.
2312
2313 \\{gdb-locals-mode-map}"
2314 (kill-all-local-variables)
2315 (setq major-mode 'gdb-locals-mode)
2316 (setq mode-name (concat "Locals:" gdb-selected-frame))
2317 (setq buffer-read-only t)
2318 (use-local-map gdb-locals-mode-map)
2319 (set (make-local-variable 'font-lock-defaults)
2320 '(gdb-locals-font-lock-keywords))
2321 (run-mode-hooks 'gdb-locals-mode-hook)
2322 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2323 'gdb-invalidate-locals
2324 'gdbmi-invalidate-locals))
2325
2326 (defun gdb-locals-buffer-name ()
2327 (with-current-buffer gud-comint-buffer
2328 (concat "*locals of " (gdb-get-target-string) "*")))
2329
2330 (defun gdb-display-locals-buffer ()
2331 "Display local variables of current stack and their values."
2332 (interactive)
2333 (gdb-display-buffer
2334 (gdb-get-create-buffer 'gdb-locals-buffer)))
2335
2336 (defun gdb-frame-locals-buffer ()
2337 "Display local variables of current stack and their values in a new frame."
2338 (interactive)
2339 (let ((special-display-regexps (append special-display-regexps '(".*")))
2340 (special-display-frame-alist gdb-frame-parameters))
2341 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
2342 \f
2343
2344 ;;;; Window management
2345 (defun gdb-display-buffer (buf &optional size)
2346 (let ((answer (get-buffer-window buf 0))
2347 (must-split nil))
2348 (if answer
2349 (display-buffer buf nil 0) ;Raise the frame if necessary.
2350 ;; The buffer is not yet displayed.
2351 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
2352 (let ((window (get-lru-window)))
2353 (if (and window
2354 (not (eq window (get-buffer-window gud-comint-buffer))))
2355 (progn
2356 (set-window-buffer window buf)
2357 (setq answer window))
2358 (setq must-split t)))
2359 (if must-split
2360 (let* ((largest (get-largest-window))
2361 (cur-size (window-height largest))
2362 (new-size (and size (< size cur-size) (- cur-size size))))
2363 (setq answer (split-window largest new-size))
2364 (set-window-buffer answer buf)
2365 (set-window-dedicated-p answer t)))
2366 answer)))
2367
2368 \f
2369 ;;; Shared keymap initialization:
2370
2371 (let ((menu (make-sparse-keymap "GDB-Windows")))
2372 (define-key gud-menu-map [displays]
2373 `(menu-item "GDB-Windows" ,menu
2374 :visible (memq gud-minor-mode '(gdbmi gdba))))
2375 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2376 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2377 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2378 (define-key menu [disassembly]
2379 '("Disassembly" . gdb-display-assembler-buffer))
2380 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2381 (define-key menu [inferior]
2382 '(menu-item "Inferior IO" gdb-display-inferior-io-buffer
2383 :enable gdb-use-inferior-io-buffer))
2384 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2385 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2386 (define-key menu [breakpoints]
2387 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2388
2389 (let ((menu (make-sparse-keymap "GDB-Frames")))
2390 (define-key gud-menu-map [frames]
2391 `(menu-item "GDB-Frames" ,menu
2392 :visible (memq gud-minor-mode '(gdbmi gdba))))
2393 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2394 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2395 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2396 (define-key menu [disassembly] '("Disassembiy" . gdb-frame-assembler-buffer))
2397 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2398 (define-key menu [inferior]
2399 '(menu-item "Inferior IO" gdb-frame-inferior-io-buffer
2400 :enable gdb-use-inferior-io-buffer))
2401 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2402 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2403 (define-key menu [breakpoints]
2404 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2405
2406 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
2407 (define-key gud-menu-map [ui]
2408 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
2409 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
2410 (define-key menu [gdb-use-inferior-io]
2411 '(menu-item "Separate inferior IO" gdb-use-inferior-io-buffer
2412 :visible (eq gud-minor-mode 'gdba)
2413 :help "Toggle separate IO for inferior."
2414 :button (:toggle . gdb-use-inferior-io-buffer)))
2415 (define-key menu [gdb-many-windows]
2416 '(menu-item "Display Other Windows" gdb-many-windows
2417 :help "Toggle display of locals, stack and breakpoint information"
2418 :button (:toggle . gdb-many-windows)))
2419 (define-key menu [gdb-restore-windows]
2420 '(menu-item "Restore Window Layout" gdb-restore-windows
2421 :help "Restore standard layout for debug session.")))
2422
2423 (defun gdb-frame-gdb-buffer ()
2424 "Display GUD buffer in a new frame."
2425 (interactive)
2426 (let ((special-display-regexps (append special-display-regexps '(".*")))
2427 (special-display-frame-alist gdb-frame-parameters)
2428 (same-window-regexps nil))
2429 (display-buffer gud-comint-buffer)))
2430
2431 (defun gdb-display-gdb-buffer ()
2432 "Display GUD buffer."
2433 (interactive)
2434 (let ((same-window-regexps nil))
2435 (pop-to-buffer gud-comint-buffer)))
2436
2437 (defun gdb-set-window-buffer (name)
2438 (set-window-buffer (selected-window) (get-buffer name))
2439 (set-window-dedicated-p (selected-window) t))
2440
2441 (defun gdb-setup-windows ()
2442 "Layout the window pattern for `gdb-many-windows'."
2443 (gdb-display-locals-buffer)
2444 (gdb-display-stack-buffer)
2445 (delete-other-windows)
2446 (gdb-display-breakpoints-buffer)
2447 (delete-other-windows)
2448 ; Don't dedicate.
2449 (pop-to-buffer gud-comint-buffer)
2450 (split-window nil ( / ( * (window-height) 3) 4))
2451 (split-window nil ( / (window-height) 3))
2452 (split-window-horizontally)
2453 (other-window 1)
2454 (gdb-set-window-buffer (gdb-locals-buffer-name))
2455 (other-window 1)
2456 (switch-to-buffer
2457 (if gud-last-last-frame
2458 (gud-find-file (car gud-last-last-frame))
2459 (gud-find-file gdb-main-file)))
2460 (when gdb-use-inferior-io-buffer
2461 (split-window-horizontally)
2462 (other-window 1)
2463 (gdb-set-window-buffer
2464 (gdb-get-create-buffer 'gdb-inferior-io)))
2465 (other-window 1)
2466 (gdb-set-window-buffer (gdb-stack-buffer-name))
2467 (split-window-horizontally)
2468 (other-window 1)
2469 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2470 (other-window 1))
2471
2472 (defcustom gdb-many-windows nil
2473 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2474 In this case it starts with two windows: one displaying the GUD
2475 buffer and the other with the source file with the main routine
2476 of the inferior. Non-nil means display the layout shown for
2477 `gdba'."
2478 :type 'boolean
2479 :group 'gud
2480 :version "22.1")
2481
2482 (defun gdb-many-windows (arg)
2483 "Toggle the number of windows in the basic arrangement.
2484 With arg, display additional buffers iff arg is positive."
2485 (interactive "P")
2486 (setq gdb-many-windows
2487 (if (null arg)
2488 (not gdb-many-windows)
2489 (> (prefix-numeric-value arg) 0)))
2490 (if (and gud-comint-buffer
2491 (buffer-name gud-comint-buffer))
2492 (condition-case nil
2493 (gdb-restore-windows)
2494 (error nil))))
2495
2496 (defun gdb-restore-windows ()
2497 "Restore the basic arrangement of windows used by gdba.
2498 This arrangement depends on the value of `gdb-many-windows'."
2499 (interactive)
2500 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2501 (delete-other-windows)
2502 (if gdb-many-windows
2503 (gdb-setup-windows)
2504 (when (or gud-last-last-frame gdb-show-main)
2505 (split-window)
2506 (other-window 1)
2507 (switch-to-buffer
2508 (if gud-last-last-frame
2509 (gud-find-file (car gud-last-last-frame))
2510 (gud-find-file gdb-main-file)))
2511 (other-window 1))))
2512
2513 (defun gdb-reset ()
2514 "Exit a debugging session cleanly.
2515 Kills the gdb buffers and resets the source buffers."
2516 (dolist (buffer (buffer-list))
2517 (unless (eq buffer gud-comint-buffer)
2518 (with-current-buffer buffer
2519 (if (memq gud-minor-mode '(gdbmi gdba))
2520 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2521 (kill-buffer nil)
2522 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2523 (setq gud-minor-mode nil)
2524 (kill-local-variable 'tool-bar-map)
2525 (kill-local-variable 'gdb-define-alist))))))
2526 (when (markerp gdb-overlay-arrow-position)
2527 (move-marker gdb-overlay-arrow-position nil)
2528 (setq gdb-overlay-arrow-position nil))
2529 (setq overlay-arrow-variable-list
2530 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
2531 (setq gud-running nil)
2532 (setq gdb-active-process nil)
2533 (setq gdb-var-list nil)
2534 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
2535
2536 (defun gdb-source-info ()
2537 "Find the source file where the program starts and displays it with related
2538 buffers."
2539 (goto-char (point-min))
2540 (if (and (search-forward "Located in " nil t)
2541 (looking-at "\\S-+"))
2542 (setq gdb-main-file (match-string 0)))
2543 (goto-char (point-min))
2544 (if (search-forward "Includes preprocessor macro info." nil t)
2545 (setq gdb-macro-info t))
2546 (if gdb-many-windows
2547 (gdb-setup-windows)
2548 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2549 (if gdb-show-main
2550 (let ((pop-up-windows t))
2551 (display-buffer (gud-find-file gdb-main-file))))))
2552
2553 (defun gdb-get-location (bptno line flag)
2554 "Find the directory containing the relevant source file.
2555 Put in buffer and place breakpoint icon."
2556 (goto-char (point-min))
2557 (catch 'file-not-found
2558 (if (search-forward "Located in " nil t)
2559 (when (looking-at "\\S-+")
2560 (delete (cons bptno "File not found") gdb-location-alist)
2561 (push (cons bptno (match-string 0)) gdb-location-alist))
2562 (gdb-resync)
2563 (unless (assoc bptno gdb-location-alist)
2564 (push (cons bptno "File not found") gdb-location-alist)
2565 (message-box "Cannot find source file for breakpoint location.\n\
2566 Add directory to search path for source files using the GDB command, dir."))
2567 (throw 'file-not-found nil))
2568 (with-current-buffer
2569 (find-file-noselect (match-string 0))
2570 (save-current-buffer
2571 (set (make-local-variable 'gud-minor-mode) 'gdba)
2572 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2573 ;; only want one breakpoint icon at each location
2574 (save-excursion
2575 (goto-line (string-to-number line))
2576 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2577
2578 (add-hook 'find-file-hook 'gdb-find-file-hook)
2579
2580 (defun gdb-find-file-hook ()
2581 "Set up buffer for debugging if file is part of the source code
2582 of the current session."
2583 (if (and (not gdb-find-file-unhook)
2584 ;; in case gud or gdb-ui is just loaded
2585 gud-comint-buffer
2586 (buffer-name gud-comint-buffer)
2587 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2588 'gdba))
2589 (condition-case nil
2590 (gdb-enqueue-input
2591 (list (concat gdb-server-prefix "list "
2592 (file-name-nondirectory buffer-file-name)
2593 ":1\n")
2594 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2595 (error (setq gdb-find-file-unhook t)))))
2596
2597 ;;from put-image
2598 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
2599 "Put string PUTSTRING in front of POS in the current buffer.
2600 PUTSTRING is displayed by putting an overlay into the current buffer with a
2601 `before-string' string that has a `display' property whose value is
2602 PUTSTRING."
2603 (let ((string (make-string 1 ?x))
2604 (buffer (current-buffer)))
2605 (setq putstring (copy-sequence putstring))
2606 (let ((overlay (make-overlay pos pos buffer))
2607 (prop (or dprop
2608 (list (list 'margin 'left-margin) putstring))))
2609 (put-text-property 0 1 'display prop string)
2610 (if sprops
2611 (add-text-properties 0 1 sprops string))
2612 (overlay-put overlay 'put-break t)
2613 (overlay-put overlay 'before-string string))))
2614
2615 ;;from remove-images
2616 (defun gdb-remove-strings (start end &optional buffer)
2617 "Remove strings between START and END in BUFFER.
2618 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2619 BUFFER nil or omitted means use the current buffer."
2620 (unless buffer
2621 (setq buffer (current-buffer)))
2622 (dolist (overlay (overlays-in start end))
2623 (when (overlay-get overlay 'put-break)
2624 (delete-overlay overlay))))
2625
2626 (defun gdb-put-breakpoint-icon (enabled bptno)
2627 (let ((start (- (line-beginning-position) 1))
2628 (end (+ (line-end-position) 1))
2629 (putstring (if enabled "B" "b"))
2630 (source-window (get-buffer-window (current-buffer) 0)))
2631 (add-text-properties
2632 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
2633 putstring)
2634 (if enabled
2635 (add-text-properties
2636 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2637 (add-text-properties
2638 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2639 (gdb-remove-breakpoint-icons start end)
2640 (if (display-images-p)
2641 (if (>= (or left-fringe-width
2642 (if source-window (car (window-fringes source-window)))
2643 gdb-buffer-fringe-width) 8)
2644 (gdb-put-string
2645 nil (1+ start)
2646 `(left-fringe breakpoint
2647 ,(if enabled
2648 'breakpoint-enabled
2649 'breakpoint-disabled))
2650 'gdb-bptno bptno
2651 'gdb-enabled enabled)
2652 (when (< left-margin-width 2)
2653 (save-current-buffer
2654 (setq left-margin-width 2)
2655 (if source-window
2656 (set-window-margins
2657 source-window
2658 left-margin-width right-margin-width))))
2659 (put-image
2660 (if enabled
2661 (or breakpoint-enabled-icon
2662 (setq breakpoint-enabled-icon
2663 (find-image `((:type xpm :data
2664 ,breakpoint-xpm-data
2665 :ascent 100 :pointer hand)
2666 (:type pbm :data
2667 ,breakpoint-enabled-pbm-data
2668 :ascent 100 :pointer hand)))))
2669 (or breakpoint-disabled-icon
2670 (setq breakpoint-disabled-icon
2671 (find-image `((:type xpm :data
2672 ,breakpoint-xpm-data
2673 :conversion disabled
2674 :ascent 100 :pointer hand)
2675 (:type pbm :data
2676 ,breakpoint-disabled-pbm-data
2677 :ascent 100 :pointer hand))))))
2678 (+ start 1)
2679 putstring
2680 'left-margin))
2681 (when (< left-margin-width 2)
2682 (save-current-buffer
2683 (setq left-margin-width 2)
2684 (let ((window (get-buffer-window (current-buffer) 0)))
2685 (if window
2686 (set-window-margins
2687 window left-margin-width right-margin-width)))))
2688 (gdb-put-string
2689 (propertize putstring
2690 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
2691 (1+ start)))))
2692
2693 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2694 (gdb-remove-strings start end)
2695 (if (display-images-p)
2696 (remove-images start end))
2697 (when remove-margin
2698 (setq left-margin-width 0)
2699 (let ((window (get-buffer-window (current-buffer) 0)))
2700 (if window
2701 (set-window-margins
2702 window left-margin-width right-margin-width)))))
2703
2704 \f
2705 ;;
2706 ;; Assembler buffer.
2707 ;;
2708 (gdb-set-buffer-rules 'gdb-assembler-buffer
2709 'gdb-assembler-buffer-name
2710 'gdb-assembler-mode)
2711
2712 (def-gdb-auto-update-handler gdb-assembler-handler
2713 gdb-invalidate-assembler
2714 gdb-assembler-buffer
2715 gdb-assembler-custom)
2716
2717 (defun gdb-assembler-custom ()
2718 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2719 (pos 1) (address) (flag) (bptno))
2720 (with-current-buffer buffer
2721 (save-excursion
2722 (if (not (equal gdb-frame-address "main"))
2723 (progn
2724 (goto-char (point-min))
2725 (if (and gdb-frame-address
2726 (re-search-forward gdb-frame-address nil t))
2727 (progn
2728 (setq pos (point))
2729 (beginning-of-line)
2730 (or gdb-overlay-arrow-position
2731 (setq gdb-overlay-arrow-position (make-marker)))
2732 (set-marker gdb-overlay-arrow-position
2733 (point) (current-buffer))))))
2734 ;; remove all breakpoint-icons in assembler buffer before updating.
2735 (gdb-remove-breakpoint-icons (point-min) (point-max))))
2736 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2737 (goto-char (point-min))
2738 (while (< (point) (- (point-max) 1))
2739 (forward-line 1)
2740 (if (looking-at "[^\t].*?breakpoint")
2741 (progn
2742 (looking-at
2743 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
2744 (setq bptno (match-string 1))
2745 (setq flag (char-after (match-beginning 2)))
2746 (setq address (match-string 3))
2747 (with-current-buffer buffer
2748 (save-excursion
2749 (goto-char (point-min))
2750 (if (re-search-forward address nil t)
2751 (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
2752 (if (not (equal gdb-frame-address "main"))
2753 (with-current-buffer buffer
2754 (set-window-point (get-buffer-window buffer 0) pos)))))
2755
2756 (defvar gdb-assembler-mode-map
2757 (let ((map (make-sparse-keymap)))
2758 (suppress-keymap map)
2759 (define-key map "q" 'kill-this-buffer)
2760 map))
2761
2762 (defvar gdb-assembler-font-lock-keywords
2763 '(;; <__function.name+n>
2764 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2765 (1 font-lock-function-name-face))
2766 ;; 0xNNNNNNNN <__function.name+n>: opcode
2767 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2768 (4 font-lock-keyword-face))
2769 ;; %register(at least i386)
2770 ("%\\sw+" . font-lock-variable-name-face)
2771 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2772 (1 font-lock-comment-face)
2773 (2 font-lock-function-name-face))
2774 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2775 "Font lock keywords used in `gdb-assembler-mode'.")
2776
2777 (defun gdb-assembler-mode ()
2778 "Major mode for viewing code assembler.
2779
2780 \\{gdb-assembler-mode-map}"
2781 (kill-all-local-variables)
2782 (setq major-mode 'gdb-assembler-mode)
2783 (setq mode-name (concat "Machine:" gdb-selected-frame))
2784 (setq gdb-overlay-arrow-position nil)
2785 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2786 (setq fringes-outside-margins t)
2787 (setq buffer-read-only t)
2788 (use-local-map gdb-assembler-mode-map)
2789 (gdb-invalidate-assembler)
2790 (set (make-local-variable 'font-lock-defaults)
2791 '(gdb-assembler-font-lock-keywords))
2792 (run-mode-hooks 'gdb-assembler-mode-hook)
2793 'gdb-invalidate-assembler)
2794
2795 (defun gdb-assembler-buffer-name ()
2796 (with-current-buffer gud-comint-buffer
2797 (concat "*disassembly of " (gdb-get-target-string) "*")))
2798
2799 (defun gdb-display-assembler-buffer ()
2800 "Display disassembly view."
2801 (interactive)
2802 (setq gdb-previous-frame nil)
2803 (gdb-display-buffer
2804 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2805
2806 (defun gdb-frame-assembler-buffer ()
2807 "Display disassembly view in a new frame."
2808 (interactive)
2809 (setq gdb-previous-frame nil)
2810 (let ((special-display-regexps (append special-display-regexps '(".*")))
2811 (special-display-frame-alist gdb-frame-parameters))
2812 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2813
2814 ;; modified because if gdb-frame-address has changed value a new command
2815 ;; must be enqueued to update the buffer with the new output
2816 (defun gdb-invalidate-assembler (&optional ignored)
2817 (if (gdb-get-buffer 'gdb-assembler-buffer)
2818 (progn
2819 (unless (and gdb-selected-frame
2820 (string-equal gdb-selected-frame gdb-previous-frame))
2821 (if (or (not (member 'gdb-invalidate-assembler
2822 gdb-pending-triggers))
2823 (not (string-equal gdb-frame-address
2824 gdb-previous-frame-address)))
2825 (progn
2826 ;; take previous disassemble command, if any, off the queue
2827 (with-current-buffer gud-comint-buffer
2828 (let ((queue gdb-input-queue))
2829 (dolist (item queue)
2830 (if (equal (cdr item) '(gdb-assembler-handler))
2831 (setq gdb-input-queue
2832 (delete item gdb-input-queue))))))
2833 (gdb-enqueue-input
2834 (list
2835 (concat gdb-server-prefix "disassemble "
2836 (if (member gdb-frame-address '(nil "main")) nil "0x")
2837 gdb-frame-address "\n")
2838 'gdb-assembler-handler))
2839 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2840 (setq gdb-previous-frame-address gdb-frame-address)
2841 (setq gdb-previous-frame gdb-selected-frame)))))))
2842
2843 (defun gdb-get-selected-frame ()
2844 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2845 (progn
2846 (gdb-enqueue-input
2847 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2848 (push 'gdb-get-selected-frame
2849 gdb-pending-triggers))))
2850
2851 (defun gdb-frame-handler ()
2852 (setq gdb-pending-triggers
2853 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2854 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2855 (goto-char (point-min))
2856 (if (re-search-forward "Stack level \\([0-9]+\\)" nil t)
2857 (setq gdb-frame-number (match-string 1)))
2858 (goto-char (point-min))
2859 (if (re-search-forward
2860 ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? " nil t)
2861 (progn
2862 (setq gdb-selected-frame (match-string 2))
2863 (if (gdb-get-buffer 'gdb-locals-buffer)
2864 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2865 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2866 (if (gdb-get-buffer 'gdb-assembler-buffer)
2867 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
2868 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2869 (setq gdb-frame-address (match-string 1))))
2870 (goto-char (point-min))
2871 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2872 (setq gdb-current-language (match-string 1))))
2873 (gdb-invalidate-assembler))
2874
2875 (provide 'gdb-ui)
2876
2877 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2878 ;;; gdb-ui.el ends here