]> code.delx.au - gnu-emacs/blob - lisp/progmodes/gdb-ui.el
(gdb-info-stack-custom): Use
[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, 2006, 2007, 2008
8 ;; Free Software Foundation, Inc.
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; This mode acts as a graphical user interface to GDB. You can interact with
30 ;; GDB through the GUD buffer in the usual way, but there are also further
31 ;; buffers which control the execution and describe the state of your program.
32 ;; It separates the input/output of your program from that of GDB, if
33 ;; required, and watches expressions in the speedbar. It also uses features of
34 ;; Emacs 21 such as the fringe/display margin for breakpoints, and the toolbar
35 ;; (see the GDB Graphical Interface section in the Emacs info manual).
36
37 ;; By default, M-x gdb will start the debugger.
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, see the Annotations
43 ;; 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 it.
47 ;; Some GDB/MI commands are used in this file through the CLI command
48 ;; 'interpreter mi <mi-command>'. To help with the process of fully migrating
49 ;; Emacs from annotations to GDB/MI, there is an experimental package called
50 ;; gdb-mi in the Emacs Lisp Package Archive ("http://tromey.com/elpa/"). It
51 ;; comprises of modified gud.el and a file called gdb-mi.el which replaces
52 ;; gdb-ui.el. When installed, this overrides the current files and invoking
53 ;; M-x gdb will use GDB/MI directly (starts with "gdb -i=mi"). When deleted
54 ;; ('d' followed by 'x' in Package Menu mode), the files are deleted and old
55 ;; functionality restored. This provides a convenient way to review the
56 ;; current status/contribute to its improvement. For someone who just wants to
57 ;; use GDB, however, the current mode in Emacs 22 is a much better option.
58 ;; There is also a file, also called gdb-mi.el, a version of which is included
59 ;; the GDB distribution. This will probably only work with versions
60 ;; distributed with GDB 6.5 or later. Unlike the version in ELPA it works on
61 ;; top of gdb-ui.el and you can only start it with M-x gdbmi.
62
63 ;; This mode SHOULD WORK WITH GDB 5.0 or later but you will NEED AT LEAST
64 ;; GDB 6.0 to use watch expressions. It works best with GDB 6.4 or later
65 ;; where watch expressions will update more quickly.
66
67 ;;; Windows Platforms:
68
69 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
70 ;; explicitly in your program if you want timely display of I/O in Emacs.
71 ;; Alternatively you can make the output stream unbuffered, for example, by
72 ;; using a macro:
73
74 ;; #ifdef UNBUFFERED
75 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
76 ;; #endif
77
78 ;; and compiling with -DUNBUFFERED while debugging.
79
80 ;; If you are using Cygwin GDB and find that the source is not being displayed
81 ;; in Emacs when you step through it, possible solutions are to:
82
83 ;; 1) Use Cygwin X Windows and Cygwin Emacs.
84 ;; (Since 22.1 Emacs builds under Cygwin.)
85 ;; 2) Use MinGW GDB instead.
86 ;; 3) Use cygwin-mount.el
87
88 ;;; Known Bugs:
89
90 ;; 1) Cannot handle multiple debug sessions.
91 ;; 2) If you wish to call procedures from your program in GDB
92 ;; e.g "call myproc ()", "p mysquare (5)" then use level 2 annotations
93 ;; "gdb --annotate=2 myprog" to keep source buffer/selected frame fixed.
94 ;; 3) After detaching from a process, clicking on the "GO" icon on toolbar
95 ;; (gud-go) sends "continue" to GDB (should be "run").
96
97 ;;; TODO:
98
99 ;; 1) Use MI command -data-read-memory for memory window.
100 ;; 2) Use tree-buffer.el (from ECB) instead of the speedbar for
101 ;; watch-expressions? Handling of watch-expressions needs to be
102 ;; overhauled to work for large arrays/structures by creating variable
103 ;; objects for visible watch-expressions only.
104 ;; 3) Mark breakpoint locations on scroll-bar of source buffer?
105
106 ;;; Code:
107
108 (require 'gud)
109
110 (defvar tool-bar-map)
111 (defvar speedbar-initial-expansion-list-name)
112
113 (defvar gdb-pc-address nil "Initialization for Assembler buffer.
114 Set to \"main\" at start if `gdb-show-main' is t.")
115 (defvar gdb-frame-address nil "Identity of frame for watch expression.")
116 (defvar gdb-previous-frame-pc-address nil)
117 (defvar gdb-memory-address "main")
118 (defvar gdb-previous-frame nil)
119 (defvar gdb-selected-frame nil)
120 (defvar gdb-frame-number nil)
121 (defvar gdb-current-language nil)
122 (defvar gdb-var-list nil
123 "List of variables in watch window.
124 Each element has the form (VARNUM EXPRESSION NUMCHILD TYPE VALUE STATUS FP)
125 where STATUS is nil (`unchanged'), `changed' or `out-of-scope', FP the frame
126 address for root variables.")
127 (defvar gdb-main-file nil "Source file from which program execution begins.")
128 (defvar gud-old-arrow nil)
129 (defvar gdb-thread-indicator nil)
130 (defvar gdb-overlay-arrow-position nil)
131 (defvar gdb-stack-position nil)
132 (defvar gdb-server-prefix nil)
133 (defvar gdb-flush-pending-output nil)
134 (defvar gdb-location-alist nil
135 "Alist of breakpoint numbers and full filenames. Only used for files that
136 Emacs can't find.")
137 (defvar gdb-active-process nil
138 "GUD tooltips display variable values when t, and macro definitions otherwise.")
139 (defvar gdb-error "Non-nil when GDB is reporting an error.")
140 (defvar gdb-macro-info nil
141 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
142 (defvar gdb-buffer-fringe-width nil)
143 (defvar gdb-signalled nil)
144 (defvar gdb-source-window nil)
145 (defvar gdb-inferior-status nil)
146 (defvar gdb-continuation nil)
147 (defvar gdb-look-up-stack nil)
148 (defvar gdb-frame-begin nil
149 "Non-nil when GDB generates frame-begin annotation.")
150 (defvar gdb-printing t)
151 (defvar gdb-parent-bptno-enabled nil)
152 (defvar gdb-ready nil)
153 (defvar gdb-stack-update nil)
154 (defvar gdb-early-user-input nil)
155
156 (defvar gdb-buffer-type nil
157 "One of the symbols bound in `gdb-buffer-rules'.")
158 (make-variable-buffer-local 'gdb-buffer-type)
159
160 (defvar gdb-input-queue ()
161 "A list of gdb command objects.")
162
163 (defvar gdb-prompting nil
164 "True when gdb is idle with no pending input.")
165
166 (defvar gdb-output-sink nil
167 "The disposition of the output of the current gdb command.
168 Possible values are these symbols:
169
170 `user' -- gdb output should be copied to the GUD buffer
171 for the user to see.
172
173 `inferior' -- gdb output should be copied to the inferior-io buffer.
174
175 `pre-emacs' -- output should be ignored util the post-prompt
176 annotation is received. Then the output-sink
177 becomes:...
178 `emacs' -- output should be collected in the partial-output-buffer
179 for subsequent processing by a command. This is the
180 disposition of output generated by commands that
181 gdb mode sends to gdb on its own behalf.
182 `post-emacs' -- ignore output until the prompt annotation is
183 received, then go to USER disposition.
184
185 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
186 \(`user' and `emacs').")
187
188 (defvar gdb-current-item nil
189 "The most recent command item sent to gdb.")
190
191 (defvar gdb-pending-triggers '()
192 "A list of trigger functions that have run later than their output handlers.")
193
194 (defvar gdb-first-post-prompt nil)
195 (defvar gdb-version nil)
196 (defvar gdb-locals-font-lock-keywords nil)
197 (defvar gdb-source-file-list nil
198 "List of source files for the current executable.")
199 (defconst gdb-error-regexp "\\^error,msg=\"\\(.+\\)\"")
200
201 (defvar gdb-locals-font-lock-keywords-1
202 '(;; var = (struct struct_tag) value
203 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
204 (1 font-lock-variable-name-face)
205 (3 font-lock-keyword-face)
206 (4 font-lock-type-face))
207 ;; var = (type) value
208 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(\\(\\sw\\|[_.]\\)+\\)"
209 (1 font-lock-variable-name-face)
210 (3 font-lock-type-face))
211 ;; var = val
212 ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
213 (1 font-lock-variable-name-face)))
214 "Font lock keywords used in `gdb-local-mode'.")
215
216 (defvar gdb-locals-font-lock-keywords-2
217 '(;; var = type value
218 ( "\\(^\\(\\sw\\|[_.]\\)+\\)\t+\\(\\(\\sw\\|[_.]\\)+\\)"
219 (1 font-lock-variable-name-face)
220 (3 font-lock-type-face)))
221 "Font lock keywords used in `gdb-local-mode'.")
222
223 ;; Variables for GDB 6.4+
224 (defvar gdb-register-names nil "List of register names.")
225 (defvar gdb-changed-registers nil
226 "List of changed register numbers (strings).")
227
228 ;;;###autoload
229 (defun gdb (command-line)
230 "Run gdb on program FILE in buffer *gud-FILE*.
231 The directory containing FILE becomes the initial working
232 directory and source-file directory for your debugger.
233
234 If `gdb-many-windows' is nil (the default value) then gdb just
235 pops up the GUD buffer unless `gdb-show-main' is t. In this case
236 it starts with two windows: one displaying the GUD buffer and the
237 other with the source file with the main routine of the inferior.
238
239 If `gdb-many-windows' is t, regardless of the value of
240 `gdb-show-main', the layout below will appear unless
241 `gdb-use-separate-io-buffer' is nil when the source buffer
242 occupies the full width of the frame. Keybindings are shown in
243 some of the buffers.
244
245 Watch expressions appear in the speedbar/slowbar.
246
247 The following commands help control operation :
248
249 `gdb-many-windows' - Toggle the number of windows gdb uses.
250 `gdb-restore-windows' - To restore the window layout.
251
252 See Info node `(emacs)GDB Graphical Interface' for a more
253 detailed description of this mode.
254
255 +----------------------------------------------------------------------+
256 | GDB Toolbar |
257 +-----------------------------------+----------------------------------+
258 | GUD buffer (I/O of GDB) | Locals buffer |
259 |-----------------------------------+----------------------------------+
260 | | |
261 | Source buffer | I/O buffer for debugged program |
262 | | |
263 |-----------------------------------+----------------------------------+
264 | Stack buffer | Breakpoints/threads buffer |
265 +-----------------------------------+----------------------------------+
266
267 To run GDB in text command mode, replace the GDB \"--annotate=3\"
268 option with \"--fullname\" either in the minibuffer for the
269 current Emacs session, or the custom variable
270 `gud-gdb-command-name' for all future sessions. You need to use
271 text command mode to debug multiple programs within one Emacs
272 session."
273 (interactive (list (gud-query-cmdline 'gdb)))
274
275 (when (and gud-comint-buffer
276 (buffer-name gud-comint-buffer)
277 (get-buffer-process gud-comint-buffer)
278 (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)))
279 (gdb-restore-windows)
280 (error
281 "Multiple debugging requires restarting in text command mode"))
282
283 (gud-common-init command-line nil 'gud-gdba-marker-filter)
284 (set (make-local-variable 'gud-minor-mode) 'gdba)
285 (setq comint-input-sender 'gdb-send)
286
287 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
288 (gud-def gud-tbreak "tbreak %f:%l" "\C-t"
289 "Set temporary breakpoint at current line.")
290 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line.")
291 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.")
292 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
293 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
294 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).")
295 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
296 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
297 (gud-def gud-jump
298 (progn (gud-call "tbreak %f:%l") (gud-call "jump %f:%l"))
299 "\C-j" "Set execution address to current line.")
300
301 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
302 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
303 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
304 (gud-def gud-pstar "print* %e" nil
305 "Evaluate C dereferenced pointer expression at point.")
306
307 ;; For debugging Emacs only.
308 (gud-def gud-pv "pv1 %e" "\C-v" "Print the value of the lisp variable.")
309
310 (gud-def gud-until "until %l" "\C-u" "Continue to current line.")
311 (gud-def gud-run "run" nil "Run the program.")
312
313 (local-set-key "\C-i" 'gud-gdb-complete-command)
314 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
315 (setq paragraph-start comint-prompt-regexp)
316 (setq gdb-output-sink 'user)
317 (setq gdb-first-prompt t)
318 (setq gud-running nil)
319 (setq gdb-ready nil)
320 (setq gdb-stack-update nil)
321 (setq gdb-flush-pending-output nil)
322 (setq gdb-early-user-input nil)
323 (setq gud-filter-pending-text nil)
324 (gdb-thread-identification)
325 (run-hooks 'gdb-mode-hook))
326
327 ;; Keep as an alias for compatibility with Emacs 22.1.
328 ;;;###autoload
329 (defalias 'gdba 'gdb)
330
331 (defgroup gdb nil
332 "Gdb Graphical Mode options specifically for running Gdb in Emacs."
333 :group 'processes
334 :group 'tools)
335
336 (defcustom gdb-debug-log-max 128
337 "Maximum size of `gdb-debug-log'. If nil, size is unlimited."
338 :group 'gdb
339 :type '(choice (integer :tag "Number of elements")
340 (const :tag "Unlimited" nil))
341 :version "22.1")
342
343 (defvar gdb-debug-log nil
344 "List of commands sent to and replies received from GDB.
345 Most recent commands are listed first. This list stores only the last
346 `gdb-debug-log-max' values. This variable is used to debug GDB-UI.")
347
348 ;;;###autoload
349 (defcustom gdb-enable-debug nil
350 "Non-nil means record the process input and output in `gdb-debug-log'."
351 :type 'boolean
352 :group 'gdb
353 :version "22.1")
354
355 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
356 "Shell command for generating a list of defined macros in a source file.
357 This list is used to display the #define directive associated
358 with an identifier as a tooltip. It works in a debug session with
359 GDB, when `gud-tooltip-mode' is t.
360
361 Set `gdb-cpp-define-alist-flags' for any include paths or
362 predefined macros."
363 :type 'string
364 :group 'gdb
365 :version "22.1")
366
367 (defcustom gdb-cpp-define-alist-flags ""
368 "Preprocessor flags for `gdb-cpp-define-alist-program'."
369 :type 'string
370 :group 'gdb
371 :version "22.1")
372
373 (defcustom gdb-show-main nil
374 "Non-nil means display source file containing the main routine at startup.
375 Also display the main routine in the disassembly buffer if present."
376 :type 'boolean
377 :group 'gdb
378 :version "22.1")
379
380 (defcustom gdb-many-windows nil
381 "If nil, just pop up the GUD buffer unless `gdb-show-main' is t.
382 In this case start with two windows: one displaying the GUD
383 buffer and the other with the source file with the main routine
384 of the debugged program. Non-nil means display the layout shown
385 for `gdba'."
386 :type 'boolean
387 :group 'gdb
388 :version "22.1")
389
390 (defcustom gdb-use-separate-io-buffer nil
391 "Non-nil means display output from the debugged program in a separate buffer."
392 :type 'boolean
393 :group 'gdb
394 :version "22.1")
395
396 (defun gdb-force-mode-line-update (status)
397 (let ((buffer gud-comint-buffer))
398 (if (and buffer (buffer-name buffer))
399 (with-current-buffer buffer
400 (setq mode-line-process
401 (format ":%s [%s]"
402 (process-status (get-buffer-process buffer)) status))
403 ;; Force mode line redisplay soon.
404 (force-mode-line-update)))))
405
406 (defun gdb-many-windows (arg)
407 "Toggle the number of windows in the basic arrangement.
408 With prefix argument ARG, display additional buffers if ARG is positive,
409 otherwise use a single window."
410 (interactive "P")
411 (setq gdb-many-windows
412 (if (null arg)
413 (not gdb-many-windows)
414 (> (prefix-numeric-value arg) 0)))
415 (message (format "Display of other windows %sabled"
416 (if gdb-many-windows "en" "dis")))
417 (if (and gud-comint-buffer
418 (buffer-name gud-comint-buffer))
419 (condition-case nil
420 (gdb-restore-windows)
421 (error nil))))
422
423 (defun gdb-use-separate-io-buffer (arg)
424 "Toggle separate IO for debugged program.
425 With prefix argument ARG, use separate IO if ARG is positive,
426 otherwise do not."
427 (interactive "P")
428 (setq gdb-use-separate-io-buffer
429 (if (null arg)
430 (not gdb-use-separate-io-buffer)
431 (> (prefix-numeric-value arg) 0)))
432 (message (format "Separate IO %sabled"
433 (if gdb-use-separate-io-buffer "en" "dis")))
434 (if (and gud-comint-buffer
435 (buffer-name gud-comint-buffer))
436 (condition-case nil
437 (if gdb-use-separate-io-buffer
438 (if gdb-many-windows (gdb-restore-windows))
439 (kill-buffer (gdb-inferior-io-name)))
440 (error nil))))
441
442 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
443
444 (defun gdb-create-define-alist ()
445 "Create an alist of #define directives for GUD tooltips."
446 (let* ((file (buffer-file-name))
447 (output
448 (with-output-to-string
449 (with-current-buffer standard-output
450 (and file (file-exists-p file)
451 (call-process shell-file-name file
452 (list t nil) nil "-c"
453 (concat gdb-cpp-define-alist-program " "
454 gdb-cpp-define-alist-flags))))))
455 (define-list (split-string output "\n" t)) (name))
456 (setq gdb-define-alist nil)
457 (dolist (define define-list)
458 (setq name (nth 1 (split-string define "[( ]")))
459 (push (cons name define) gdb-define-alist))))
460
461 (defun gdb-tooltip-print (expr)
462 (tooltip-show
463 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
464 (goto-char (point-min))
465 (let ((string
466 (if (search-forward "=" nil t)
467 (concat expr (buffer-substring (- (point) 2) (point-max)))
468 (buffer-string))))
469 ;; remove newline for gud-tooltip-echo-area
470 (substring string 0 (- (length string) 1))))
471 (or gud-tooltip-echo-area tooltip-use-echo-area)))
472
473 ;; If expr is a macro for a function don't print because of possible dangerous
474 ;; side-effects. Also printing a function within a tooltip generates an
475 ;; unexpected starting annotation (phase error).
476 (defun gdb-tooltip-print-1 (expr)
477 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
478 (goto-char (point-min))
479 (if (search-forward "expands to: " nil t)
480 (unless (looking-at "\\S-+.*(.*).*")
481 (gdb-enqueue-input
482 (list (concat gdb-server-prefix "print " expr "\n")
483 `(lambda () (gdb-tooltip-print ,expr))))))))
484
485 (defconst gdb-source-file-regexp "\\(.+?\\), \\|\\([^, \n].*$\\)")
486
487 (defun gdb-init-buffer ()
488 (set (make-local-variable 'gud-minor-mode)
489 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
490 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
491 (when gud-tooltip-mode
492 (make-local-variable 'gdb-define-alist)
493 (gdb-create-define-alist)
494 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))
495
496 (defun gdb-set-gud-minor-mode-existing-buffers ()
497 "Create list of source files for current GDB session."
498 (goto-char (point-min))
499 (when (search-forward "read in on demand:" nil t)
500 (while (re-search-forward gdb-source-file-regexp nil t)
501 (push (file-name-nondirectory (or (match-string 1) (match-string 2)))
502 gdb-source-file-list))
503 (dolist (buffer (buffer-list))
504 (with-current-buffer buffer
505 (when (and buffer-file-name
506 (member (file-name-nondirectory buffer-file-name)
507 gdb-source-file-list))
508 (gdb-init-buffer)))))
509 (gdb-force-mode-line-update
510 (propertize "ready" 'face font-lock-variable-name-face)))
511
512 (defun gdb-find-watch-expression ()
513 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
514 (varnum (car var)) expr array)
515 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varnum)
516 (let ((var1 (assoc (match-string 1 varnum) gdb-var-list)) var2 varnumlet
517 (component-list (split-string (match-string 2 varnum) "\\." t)))
518 (setq expr (nth 1 var1))
519 (setq varnumlet (car var1))
520 (dolist (component component-list)
521 (setq var2 (assoc varnumlet gdb-var-list))
522 (setq expr (concat expr
523 (if (string-match ".*\\[[0-9]+\\]$" (nth 3 var2))
524 (concat "[" component "]")
525 (concat "." component))))
526 (setq varnumlet (concat varnumlet "." component)))
527 expr)))
528
529 (defun gdb-init-1 ()
530 (gud-def gud-break (if (not (string-match "Machine" mode-name))
531 (gud-call "break %f:%l" arg)
532 (save-excursion
533 (beginning-of-line)
534 (forward-char 2)
535 (gud-call "break *%a" arg)))
536 "\C-b" "Set breakpoint at current line or address.")
537 ;;
538 (gud-def gud-remove (if (not (string-match "Machine" mode-name))
539 (gud-call "clear %f:%l" arg)
540 (save-excursion
541 (beginning-of-line)
542 (forward-char 2)
543 (gud-call "clear *%a" arg)))
544 "\C-d" "Remove breakpoint at current line or address.")
545 ;;
546 (gud-def gud-until (if (not (string-match "Machine" mode-name))
547 (gud-call "until %f:%l" arg)
548 (save-excursion
549 (beginning-of-line)
550 (forward-char 2)
551 (gud-call "until *%a" arg)))
552 "\C-u" "Continue to current line or address.")
553 ;;
554 (gud-def gud-go (gud-call (if gdb-active-process "continue" "run") arg)
555 nil "Start or continue execution.")
556
557 ;; For debugging Emacs only.
558 (gud-def gud-pp
559 (gud-call
560 (concat
561 "pp1 " (if (eq (buffer-local-value
562 'major-mode (window-buffer)) 'speedbar-mode)
563 (gdb-find-watch-expression) "%e")) arg)
564 nil "Print the Emacs s-expression.")
565
566 (define-key gud-minor-mode-map [left-margin mouse-1]
567 'gdb-mouse-set-clear-breakpoint)
568 (define-key gud-minor-mode-map [left-fringe mouse-1]
569 'gdb-mouse-set-clear-breakpoint)
570 (define-key gud-minor-mode-map [left-margin C-mouse-1]
571 'gdb-mouse-toggle-breakpoint-margin)
572 (define-key gud-minor-mode-map [left-fringe C-mouse-1]
573 'gdb-mouse-toggle-breakpoint-fringe)
574
575 (define-key gud-minor-mode-map [left-margin drag-mouse-1]
576 'gdb-mouse-until)
577 (define-key gud-minor-mode-map [left-fringe drag-mouse-1]
578 'gdb-mouse-until)
579 (define-key gud-minor-mode-map [left-margin mouse-3]
580 'gdb-mouse-until)
581 (define-key gud-minor-mode-map [left-fringe mouse-3]
582 'gdb-mouse-until)
583
584 (define-key gud-minor-mode-map [left-margin C-drag-mouse-1]
585 'gdb-mouse-jump)
586 (define-key gud-minor-mode-map [left-fringe C-drag-mouse-1]
587 'gdb-mouse-jump)
588 (define-key gud-minor-mode-map [left-fringe C-mouse-3]
589 'gdb-mouse-jump)
590 (define-key gud-minor-mode-map [left-margin C-mouse-3]
591 'gdb-mouse-jump)
592
593 ;; (re-)initialize
594 (setq gdb-pc-address (if gdb-show-main "main" nil))
595 (setq gdb-previous-frame-pc-address nil
596 gdb-memory-address "main"
597 gdb-previous-frame nil
598 gdb-selected-frame nil
599 gdb-current-language nil
600 gdb-frame-number nil
601 gdb-var-list nil
602 gdb-main-file nil
603 gdb-first-post-prompt t
604 gdb-prompting nil
605 gdb-input-queue nil
606 gdb-current-item nil
607 gdb-pending-triggers nil
608 gdb-output-sink 'user
609 gdb-server-prefix "server "
610 gdb-location-alist nil
611 gdb-source-file-list nil
612 gdb-error nil
613 gdb-macro-info nil
614 gdb-buffer-fringe-width (car (window-fringes))
615 gdb-debug-log nil
616 gdb-signalled nil
617 gdb-source-window nil
618 gdb-inferior-status nil
619 gdb-continuation nil
620 gdb-look-up-stack nil
621 gdb-frame-begin nil
622 gdb-printing t
623 gud-old-arrow nil
624 gdb-thread-indicator nil)
625
626 (setq gdb-buffer-type 'gdba)
627
628 (if gdb-use-separate-io-buffer (gdb-clear-inferior-io))
629
630 ;; Hack to see test for GDB 6.4+ (-stack-info-frame was implemented in 6.4)
631 (gdb-enqueue-input (list "server interpreter mi -stack-info-frame\n"
632 'gdb-get-version)))
633
634 (defun gdb-init-2 ()
635 (if (eq window-system 'w32)
636 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
637 (gdb-enqueue-input (list "set height 0\n" 'ignore))
638 (gdb-enqueue-input (list "set width 0\n" 'ignore))
639
640 (if (string-equal gdb-version "pre-6.4")
641 (progn
642 (gdb-enqueue-input (list (concat gdb-server-prefix "info sources\n")
643 'gdb-set-gud-minor-mode-existing-buffers))
644 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-1))
645 (gdb-enqueue-input
646 (list "server interpreter mi -data-list-register-names\n"
647 'gdb-get-register-names))
648 ; Needs GDB 6.2 onwards.
649 (gdb-enqueue-input
650 (list "server interpreter mi \"-file-list-exec-source-files\"\n"
651 'gdb-set-gud-minor-mode-existing-buffers-1))
652 (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-2))
653
654 ;; Find source file and compilation directory here.
655 ;; Works for C, C++, Fortran and Ada but not Java (GDB 6.4)
656 (gdb-enqueue-input (list "server list\n" 'ignore))
657 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
658
659 (run-hooks 'gdb-mode-hook))
660
661 (defun gdb-get-version ()
662 (goto-char (point-min))
663 (if (re-search-forward "Undefined\\( mi\\)* command:" nil t)
664 (setq gdb-version "pre-6.4")
665 (setq gdb-version "6.4+"))
666 (gdb-init-2))
667
668 (defmacro gdb-if-arrow (arrow-position &rest body)
669 `(if ,arrow-position
670 (let ((buffer (marker-buffer ,arrow-position)) (line))
671 (if (equal buffer (window-buffer (posn-window end)))
672 (with-current-buffer buffer
673 (when (or (equal start end)
674 (equal (posn-point start)
675 (marker-position ,arrow-position)))
676 ,@body))))))
677
678 (defun gdb-mouse-until (event)
679 "Continue running until a source line past the current line.
680 The destination source line can be selected either by clicking
681 with mouse-3 on the fringe/margin or dragging the arrow
682 with mouse-1 (default bindings)."
683 (interactive "e")
684 (let ((start (event-start event))
685 (end (event-end event)))
686 (gdb-if-arrow gud-overlay-arrow-position
687 (setq line (line-number-at-pos (posn-point end)))
688 (gud-call (concat "until " (number-to-string line))))
689 (gdb-if-arrow gdb-overlay-arrow-position
690 (save-excursion
691 (goto-line (line-number-at-pos (posn-point end)))
692 (forward-char 2)
693 (gud-call (concat "until *%a"))))))
694
695 (defun gdb-mouse-jump (event)
696 "Set execution address/line.
697 The destination source line can be selected either by clicking with C-mouse-3
698 on the fringe/margin or dragging the arrow with C-mouse-1 (default bindings).
699 Unlike `gdb-mouse-until' the destination address can be before the current
700 line, and no execution takes place."
701 (interactive "e")
702 (let ((start (event-start event))
703 (end (event-end event)))
704 (gdb-if-arrow gud-overlay-arrow-position
705 (setq line (line-number-at-pos (posn-point end)))
706 (progn
707 (gud-call (concat "tbreak " (number-to-string line)))
708 (gud-call (concat "jump " (number-to-string line)))))
709 (gdb-if-arrow gdb-overlay-arrow-position
710 (save-excursion
711 (goto-line (line-number-at-pos (posn-point end)))
712 (forward-char 2)
713 (progn
714 (gud-call (concat "tbreak *%a"))
715 (gud-call (concat "jump *%a")))))))
716
717 (defcustom gdb-speedbar-auto-raise nil
718 "If non-nil raise speedbar every time display of watch expressions is\
719 updated."
720 :type 'boolean
721 :group 'gdb
722 :version "22.1")
723
724 (defun gdb-speedbar-auto-raise (arg)
725 "Toggle automatic raising of the speedbar for watch expressions.
726 With prefix argument ARG, automatically raise speedbar if ARG is
727 positive, otherwise don't automatically raise it."
728 (interactive "P")
729 (setq gdb-speedbar-auto-raise
730 (if (null arg)
731 (not gdb-speedbar-auto-raise)
732 (> (prefix-numeric-value arg) 0)))
733 (message (format "Auto raising %sabled"
734 (if gdb-speedbar-auto-raise "en" "dis"))))
735
736 (defcustom gdb-use-colon-colon-notation nil
737 "If non-nil use FUN::VAR format to display variables in the speedbar."
738 :type 'boolean
739 :group 'gdb
740 :version "22.1")
741
742 (define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch)
743 (define-key global-map (concat gud-key-prefix "\C-w") 'gud-watch)
744
745 (defun gud-watch (&optional arg event)
746 "Watch expression at point.
747 With arg, enter name of variable to be watched in the minibuffer."
748 (interactive (list current-prefix-arg last-input-event))
749 (let ((minor-mode (buffer-local-value 'gud-minor-mode gud-comint-buffer)))
750 (if (memq minor-mode '(gdbmi gdba))
751 (progn
752 (if event (posn-set-point (event-end event)))
753 (require 'tooltip)
754 (save-selected-window
755 (let ((expr
756 (if arg
757 (completing-read "Name of variable: "
758 'gud-gdb-complete-command)
759 (if (and transient-mark-mode mark-active)
760 (buffer-substring (region-beginning) (region-end))
761 (concat (if (eq major-mode 'gdb-registers-mode) "$")
762 (tooltip-identifier-from-point (point)))))))
763 (set-text-properties 0 (length expr) nil expr)
764 (gdb-enqueue-input
765 (list
766 (if (eq minor-mode 'gdba)
767 (concat
768 "server interpreter mi \"-var-create - * " expr "\"\n")
769 (concat"-var-create - * " expr "\n"))
770 `(lambda () (gdb-var-create-handler ,expr)))))))
771 (message "gud-watch is a no-op in this mode."))))
772
773 (defconst gdb-var-create-regexp
774 "name=\"\\(.*?\\)\",.*numchild=\"\\(.*?\\)\",\\(?:.*value=\\(\".*\"\\),\\)?.*type=\"\\(.*?\\)\"")
775
776 (defun gdb-var-create-handler (expr)
777 (goto-char (point-min))
778 (if (re-search-forward gdb-var-create-regexp nil t)
779 (let ((var (list
780 (match-string 1)
781 (if (and (string-equal gdb-current-language "c")
782 gdb-use-colon-colon-notation gdb-selected-frame)
783 (setq expr (concat gdb-selected-frame "::" expr))
784 expr)
785 (match-string 2)
786 (match-string 4)
787 (if (match-string 3) (read (match-string 3)))
788 nil gdb-frame-address)))
789 (push var gdb-var-list)
790 (speedbar 1)
791 (unless (string-equal
792 speedbar-initial-expansion-list-name "GUD")
793 (speedbar-change-initial-expansion-list "GUD"))
794 (unless (nth 4 var)
795 (gdb-enqueue-input
796 (list
797 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
798 'gdba)
799 (concat "server interpreter mi \"0-var-evaluate-expression "
800 (car var) "\"\n")
801 (concat "0-var-evaluate-expression " (car var) "\n"))
802 `(lambda () (gdb-var-evaluate-expression-handler
803 ,(car var) nil))))))
804 (if (search-forward "Undefined command" nil t)
805 (message-box "Watching expressions requires GDB 6.0 onwards")
806 (message-box "No symbol \"%s\" in current context." expr))))
807
808 (defun gdb-speedbar-update ()
809 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame)
810 (not (member 'gdb-speedbar-timer gdb-pending-triggers)))
811 ;; Dummy command to update speedbar even when idle.
812 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
813 ;; Keep gdb-pending-triggers non-nil till end.
814 (push 'gdb-speedbar-timer gdb-pending-triggers)))
815
816 (defun gdb-speedbar-timer-fn ()
817 (setq gdb-pending-triggers
818 (delq 'gdb-speedbar-timer gdb-pending-triggers))
819 (speedbar-timer-fn))
820
821 (defun gdb-var-evaluate-expression-handler (varnum changed)
822 (goto-char (point-min))
823 (re-search-forward "\\(.+\\)\\^done,value=\\(\".*\"\\)" nil t)
824 (setq gdb-pending-triggers
825 (delq (string-to-number (match-string 1)) gdb-pending-triggers))
826 (let ((var (assoc varnum gdb-var-list)))
827 (when var
828 (if changed (setcar (nthcdr 5 var) 'changed))
829 (setcar (nthcdr 4 var) (read (match-string 2)))))
830 (gdb-speedbar-update))
831
832 (defun gdb-var-list-children (varnum)
833 (gdb-enqueue-input
834 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
835 `(lambda () (gdb-var-list-children-handler ,varnum)))))
836
837 (defconst gdb-var-list-children-regexp
838 "child={.*?name=\"\\(.*?\\)\",.*?exp=\"\\(.*?\\)\",.*?\
839 numchild=\"\\(.*?\\)\"\\(}\\|,.*?\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
840
841 (defun gdb-var-list-children-handler (varnum)
842 (goto-char (point-min))
843 (let ((var-list nil))
844 (catch 'child-already-watched
845 (dolist (var gdb-var-list)
846 (if (string-equal varnum (car var))
847 (progn
848 (push var var-list)
849 (while (re-search-forward gdb-var-list-children-regexp nil t)
850 (let ((varchild (list (match-string 1)
851 (match-string 2)
852 (match-string 3)
853 (match-string 6)
854 nil nil)))
855 (if (assoc (car varchild) gdb-var-list)
856 (throw 'child-already-watched nil))
857 (push varchild var-list)
858 (gdb-enqueue-input
859 (list
860 (concat
861 "server interpreter mi \"0-var-evaluate-expression "
862 (car varchild) "\"\n")
863 `(lambda () (gdb-var-evaluate-expression-handler
864 ,(car varchild) nil)))))))
865 (push var var-list)))
866 (setq gdb-var-list (nreverse var-list)))))
867
868 (defun gdb-var-update ()
869 (when (not (member 'gdb-var-update gdb-pending-triggers))
870 (gdb-enqueue-input
871 (list "server interpreter mi \"-var-update *\"\n"
872 'gdb-var-update-handler))
873 (push 'gdb-var-update gdb-pending-triggers)))
874
875 (defconst gdb-var-update-regexp
876 "{.*?name=\"\\(.*?\\)\",.*?in_scope=\"\\(.*?\\)\",.*?\
877 type_changed=\".*?\".*?}")
878
879 (defun gdb-var-update-handler ()
880 (dolist (var gdb-var-list)
881 (setcar (nthcdr 5 var) nil))
882 (goto-char (point-min))
883 (let ((n 0))
884 (while (re-search-forward gdb-var-update-regexp nil t)
885 (let ((varnum (match-string 1)))
886 (if (string-equal (match-string 2) "false")
887 (let ((var (assoc varnum gdb-var-list)))
888 (if var (setcar (nthcdr 5 var) 'out-of-scope)))
889 (setq n (1+ n))
890 (push n gdb-pending-triggers)
891 (gdb-enqueue-input
892 (list
893 (concat "server interpreter mi \"" (number-to-string n)
894 "-var-evaluate-expression " varnum "\"\n")
895 `(lambda () (gdb-var-evaluate-expression-handler ,varnum t))))))))
896 (setq gdb-pending-triggers
897 (delq 'gdb-var-update gdb-pending-triggers)))
898
899 (defun gdb-var-set-format (format)
900 "Set the output format for a variable displayed in the speedbar."
901 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
902 (varnum (car var)))
903 (gdb-enqueue-input
904 (list
905 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
906 (concat "server interpreter mi \"-var-set-format "
907 varnum " " format "\"\n")
908 (concat "-var-set-format " varnum " " format "\n"))
909 `(lambda () (gdb-var-set-format-handler ,varnum))))))
910
911 (defconst gdb-var-set-format-regexp
912 "format=\"\\(.*?\\)\",.*value=\"\\(.*?\\)\"")
913
914 (defun gdb-var-set-format-handler (varnum)
915 (goto-char (point-min))
916 (if (re-search-forward gdb-var-set-format-regexp nil t)
917 (let ((var (assoc varnum gdb-var-list)))
918 (setcar (nthcdr 4 var) (match-string 2))
919 (gdb-var-update-1))))
920
921 (defun gdb-var-delete-1 (varnum)
922 (gdb-enqueue-input
923 (list
924 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
925 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
926 (concat "-var-delete " varnum "\n"))
927 'ignore))
928 (setq gdb-var-list (delq var gdb-var-list))
929 (dolist (varchild gdb-var-list)
930 (if (string-match (concat (car var) "\\.") (car varchild))
931 (setq gdb-var-list (delq varchild gdb-var-list)))))
932
933 (defun gdb-var-delete ()
934 "Delete watch expression at point from the speedbar."
935 (interactive)
936 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
937 '(gdbmi gdba))
938 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
939 (varnum (car var)))
940 (if (string-match "\\." (car var))
941 (message-box "Can only delete a root expression")
942 (gdb-var-delete-1 varnum)))))
943
944 (defun gdb-var-delete-children (varnum)
945 "Delete children of variable object at point from the speedbar."
946 (gdb-enqueue-input
947 (list
948 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
949 (concat "server interpreter mi \"-var-delete -c " varnum "\"\n")
950 (concat "-var-delete -c " varnum "\n")) 'ignore)))
951
952 (defun gdb-edit-value (text token indent)
953 "Assign a value to a variable displayed in the speedbar."
954 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
955 (varnum (car var)) (value))
956 (setq value (read-string "New value: "))
957 (gdb-enqueue-input
958 (list
959 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
960 (concat "server interpreter mi \"-var-assign "
961 varnum " " value "\"\n")
962 (concat "-var-assign " varnum " " value "\n"))
963 `(lambda () (gdb-edit-value-handler ,value))))))
964
965 (defun gdb-edit-value-handler (value)
966 (goto-char (point-min))
967 (if (re-search-forward gdb-error-regexp nil t)
968 (message-box "Invalid number or expression (%s)" value)))
969
970 (defcustom gdb-show-changed-values t
971 "If non-nil change the face of out of scope variables and changed values.
972 Out of scope variables are suppressed with `shadow' face.
973 Changed values are highlighted with the face `font-lock-warning-face'."
974 :type 'boolean
975 :group 'gdb
976 :version "22.1")
977
978 (defcustom gdb-max-children 40
979 "Maximum number of children before expansion requires confirmation."
980 :type 'integer
981 :group 'gdb
982 :version "22.1")
983
984 (defcustom gdb-delete-out-of-scope t
985 "If non-nil delete watch expressions automatically when they go out of scope."
986 :type 'boolean
987 :group 'gdb
988 :version "22.2")
989
990 (defun gdb-speedbar-expand-node (text token indent)
991 "Expand the node the user clicked on.
992 TEXT is the text of the button we clicked on, a + or - item.
993 TOKEN is data related to this node.
994 INDENT is the current indentation depth."
995 (if (and gud-comint-buffer (buffer-name gud-comint-buffer))
996 (progn
997 (cond ((string-match "+" text) ;expand this node
998 (let* ((var (assoc token gdb-var-list))
999 (expr (nth 1 var)) (children (nth 2 var)))
1000 (if (or (<= (string-to-number children) gdb-max-children)
1001 (y-or-n-p
1002 (format
1003 "%s has %s children. Continue? " expr children)))
1004 (if (and (eq (buffer-local-value
1005 'gud-minor-mode gud-comint-buffer) 'gdba)
1006 (string-equal gdb-version "pre-6.4"))
1007 (gdb-var-list-children token)
1008 (gdb-var-list-children-1 token)))))
1009 ((string-match "-" text) ;contract this node
1010 (dolist (var gdb-var-list)
1011 (if (string-match (concat token "\\.") (car var))
1012 (setq gdb-var-list (delq var gdb-var-list))))
1013 (gdb-var-delete-children token)
1014 (speedbar-change-expand-button-char ?+)
1015 (speedbar-delete-subblock indent))
1016 (t (error "Ooops... not sure what to do")))
1017 (speedbar-center-buffer-smartly))
1018 (message-box "GUD session has been killed")))
1019
1020 (defun gdb-get-target-string ()
1021 (with-current-buffer gud-comint-buffer
1022 gud-target-name))
1023 \f
1024
1025 ;;
1026 ;; gdb buffers.
1027 ;;
1028 ;; Each buffer has a TYPE -- a symbol that identifies the function
1029 ;; of that particular buffer.
1030 ;;
1031 ;; The usual gdb interaction buffer is given the type `gdba' and
1032 ;; is constructed specially.
1033 ;;
1034 ;; Others are constructed by gdb-get-buffer-create and
1035 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
1036
1037 (defvar gdb-buffer-rules-assoc '())
1038
1039 (defun gdb-get-buffer (key)
1040 "Return the gdb buffer tagged with type KEY.
1041 The key should be one of the cars in `gdb-buffer-rules-assoc'."
1042 (save-excursion
1043 (gdb-look-for-tagged-buffer key (buffer-list))))
1044
1045 (defun gdb-get-buffer-create (key)
1046 "Create a new gdb buffer of the type specified by KEY.
1047 The key should be one of the cars in `gdb-buffer-rules-assoc'."
1048 (or (gdb-get-buffer key)
1049 (let* ((rules (assoc key gdb-buffer-rules-assoc))
1050 (name (funcall (gdb-rules-name-maker rules)))
1051 (new (get-buffer-create name)))
1052 (with-current-buffer new
1053 (let ((trigger))
1054 (if (cdr (cdr rules))
1055 (setq trigger (funcall (car (cdr (cdr rules))))))
1056 (setq gdb-buffer-type key)
1057 (set (make-local-variable 'gud-minor-mode)
1058 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
1059 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
1060 (if trigger (funcall trigger)))
1061 new))))
1062
1063 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
1064
1065 (defun gdb-look-for-tagged-buffer (key bufs)
1066 (let ((retval nil))
1067 (while (and (not retval) bufs)
1068 (set-buffer (car bufs))
1069 (if (eq gdb-buffer-type key)
1070 (setq retval (car bufs)))
1071 (setq bufs (cdr bufs)))
1072 retval))
1073
1074 ;;
1075 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
1076 ;; at least one and possible more functions. The functions have these
1077 ;; roles in defining a buffer type:
1078 ;;
1079 ;; NAME - Return a name for this buffer type.
1080 ;;
1081 ;; The remaining function(s) are optional:
1082 ;;
1083 ;; MODE - called in a new buffer with no arguments, should establish
1084 ;; the proper mode for the buffer.
1085 ;;
1086
1087 (defun gdb-set-buffer-rules (buffer-type &rest rules)
1088 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
1089 (if binding
1090 (setcdr binding rules)
1091 (push (cons buffer-type rules)
1092 gdb-buffer-rules-assoc))))
1093
1094 ;; GUD buffers are an exception to the rules
1095 (gdb-set-buffer-rules 'gdba 'error)
1096
1097 ;; Partial-output buffer : This accumulates output from a command executed on
1098 ;; behalf of emacs (rather than the user).
1099 ;;
1100 (gdb-set-buffer-rules 'gdb-partial-output-buffer
1101 'gdb-partial-output-name)
1102
1103 (defun gdb-partial-output-name ()
1104 (concat " *partial-output-"
1105 (gdb-get-target-string)
1106 "*"))
1107
1108 \f
1109 (gdb-set-buffer-rules 'gdb-inferior-io
1110 'gdb-inferior-io-name
1111 'gdb-inferior-io-mode)
1112
1113 (defun gdb-inferior-io-name ()
1114 (concat "*input/output of "
1115 (gdb-get-target-string)
1116 "*"))
1117
1118 (defun gdb-display-separate-io-buffer ()
1119 "Display IO of debugged program in a separate window."
1120 (interactive)
1121 (if gdb-use-separate-io-buffer
1122 (gdb-display-buffer
1123 (gdb-get-buffer-create 'gdb-inferior-io) t)))
1124
1125 (defconst gdb-frame-parameters
1126 '((height . 14) (width . 80)
1127 (unsplittable . t)
1128 (tool-bar-lines . nil)
1129 (menu-bar-lines . nil)
1130 (minibuffer . nil)))
1131
1132 (defun gdb-frame-separate-io-buffer ()
1133 "Display IO of debugged program in a new frame."
1134 (interactive)
1135 (if gdb-use-separate-io-buffer
1136 (let ((special-display-regexps (append special-display-regexps '(".*")))
1137 (special-display-frame-alist gdb-frame-parameters))
1138 (display-buffer (gdb-get-buffer-create 'gdb-inferior-io)))))
1139
1140 (defvar gdb-inferior-io-mode-map
1141 (let ((map (make-sparse-keymap)))
1142 (define-key map "\C-c\C-c" 'gdb-separate-io-interrupt)
1143 (define-key map "\C-c\C-z" 'gdb-separate-io-stop)
1144 (define-key map "\C-c\C-\\" 'gdb-separate-io-quit)
1145 (define-key map "\C-c\C-d" 'gdb-separate-io-eof)
1146 (define-key map "\C-d" 'gdb-separate-io-eof)
1147 map))
1148
1149 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
1150 "Major mode for gdb inferior-io."
1151 :syntax-table nil :abbrev-table nil
1152 ;; We want to use comint because it has various nifty and familiar
1153 ;; features. We don't need a process, but comint wants one, so create
1154 ;; a dummy one.
1155 (make-comint-in-buffer
1156 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
1157 (current-buffer) "hexl")
1158 (setq comint-input-sender 'gdb-inferior-io-sender))
1159
1160 (defun gdb-inferior-io-sender (proc string)
1161 ;; PROC is the pseudo-process created to satisfy comint.
1162 (with-current-buffer (process-buffer proc)
1163 (setq proc (get-buffer-process gud-comint-buffer))
1164 (process-send-string proc string)
1165 (process-send-string proc "\n")))
1166
1167 (defun gdb-separate-io-interrupt ()
1168 "Interrupt the program being debugged."
1169 (interactive)
1170 (interrupt-process
1171 (get-buffer-process gud-comint-buffer) comint-ptyp))
1172
1173 (defun gdb-separate-io-quit ()
1174 "Send quit signal to the program being debugged."
1175 (interactive)
1176 (quit-process
1177 (get-buffer-process gud-comint-buffer) comint-ptyp))
1178
1179 (defun gdb-separate-io-stop ()
1180 "Stop the program being debugged."
1181 (interactive)
1182 (stop-process
1183 (get-buffer-process gud-comint-buffer) comint-ptyp))
1184
1185 (defun gdb-separate-io-eof ()
1186 "Send end-of-file to the program being debugged."
1187 (interactive)
1188 (process-send-eof
1189 (get-buffer-process gud-comint-buffer)))
1190 \f
1191
1192 ;; gdb communications
1193 ;;
1194
1195 ;; INPUT: things sent to gdb
1196 ;;
1197 ;; The queues are lists. Each element is either a string (indicating user or
1198 ;; user-like input) or a list of the form:
1199 ;;
1200 ;; (INPUT-STRING HANDLER-FN)
1201 ;;
1202 ;; The handler function will be called from the partial-output buffer when the
1203 ;; command completes. This is the way to write commands which invoke gdb
1204 ;; commands autonomously.
1205 ;;
1206 ;; These lists are consumed tail first.
1207 ;;
1208
1209 (defun gdb-send (proc string)
1210 "A comint send filter for gdb.
1211 This filter may simply queue input for a later time."
1212 (if gdb-ready
1213 (progn
1214 (with-current-buffer gud-comint-buffer
1215 (let ((inhibit-read-only t))
1216 (remove-text-properties (point-min) (point-max) '(face))))
1217 (if gud-running
1218 (progn
1219 (let ((item (concat string "\n")))
1220 (if gdb-enable-debug (push (cons 'send item) gdb-debug-log))
1221 (process-send-string proc item)))
1222 (if (string-match "\\\\\\'" string)
1223 (setq gdb-continuation (concat gdb-continuation string "\n"))
1224 (let ((item (concat
1225 gdb-continuation string
1226 (if (not comint-input-sender-no-newline) "\n"))))
1227 (gdb-enqueue-input item)
1228 (setq gdb-continuation nil)))))
1229 (push (concat string "\n") gdb-early-user-input)))
1230
1231 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
1232 ;; is a query, or other non-top-level prompt.
1233
1234 (defun gdb-enqueue-input (item)
1235 (if (not gud-running)
1236 (if gdb-prompting
1237 (progn
1238 (gdb-send-item item)
1239 (setq gdb-prompting nil))
1240 (push item gdb-input-queue))))
1241
1242 (defun gdb-dequeue-input ()
1243 (let ((queue gdb-input-queue))
1244 (if queue
1245 (let ((last (car (last queue))))
1246 (unless (nbutlast queue) (setq gdb-input-queue '()))
1247 last)
1248 ;; This should be nil here anyway but set it just to make sure.
1249 (setq gdb-pending-triggers nil))))
1250
1251 (defun gdb-send-item (item)
1252 (setq gdb-flush-pending-output nil)
1253 (if gdb-enable-debug (push (cons 'send-item item) gdb-debug-log))
1254 (setq gdb-current-item item)
1255 (let ((process (get-buffer-process gud-comint-buffer)))
1256 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
1257 (if (stringp item)
1258 (progn
1259 (setq gdb-output-sink 'user)
1260 (process-send-string process item))
1261 (progn
1262 (gdb-clear-partial-output)
1263 (setq gdb-output-sink 'pre-emacs)
1264 (process-send-string process
1265 (car item))))
1266 ;; case: eq gud-minor-mode 'gdbmi
1267 (gdb-clear-partial-output)
1268 (setq gdb-output-sink 'emacs)
1269 (process-send-string process (car item)))))
1270 \f
1271 ;;
1272 ;; output -- things gdb prints to emacs
1273 ;;
1274 ;; GDB output is a stream interrupted by annotations.
1275 ;; Annotations can be recognized by their beginning
1276 ;; with \C-j\C-z\C-z<tag><opt>\C-j
1277 ;;
1278 ;; The tag is a string obeying symbol syntax.
1279 ;;
1280 ;; The optional part `<opt>' can be either the empty string
1281 ;; or a space followed by more data relating to the annotation.
1282 ;; For example, the SOURCE annotation is followed by a filename,
1283 ;; line number and various useless goo. This data must not include
1284 ;; any newlines.
1285 ;;
1286
1287 (defcustom gud-gdb-command-name "gdb --annotate=3"
1288 "Default command to execute an executable under the GDB debugger.
1289 The option \"--annotate=3\" must be included in this value if you
1290 want the GDB Graphical Interface."
1291 :type 'string
1292 :group 'gud
1293 :version "22.1")
1294
1295 (defvar gdb-annotation-rules
1296 '(("pre-prompt" gdb-pre-prompt)
1297 ("prompt" gdb-prompt)
1298 ("commands" gdb-subprompt)
1299 ("overload-choice" gdb-subprompt)
1300 ("query" gdb-subprompt)
1301 ;; Need this prompt for GDB 6.1
1302 ("nquery" gdb-subprompt)
1303 ("prompt-for-continue" gdb-subprompt)
1304 ("post-prompt" gdb-post-prompt)
1305 ("source" gdb-source)
1306 ("starting" gdb-starting)
1307 ("exited" gdb-exited)
1308 ("signalled" gdb-signalled)
1309 ("signal" gdb-signal)
1310 ("breakpoint" gdb-stopping)
1311 ("watchpoint" gdb-stopping)
1312 ("frame-begin" gdb-frame-begin)
1313 ("stopped" gdb-stopped)
1314 ("error-begin" gdb-error)
1315 ("error" gdb-error)
1316 ("new-thread" (lambda (ignored) (gdb-get-buffer-create 'gdb-threads-buffer))))
1317 "An assoc mapping annotation tags to functions which process them.")
1318
1319 (defun gdb-resync()
1320 (setq gdb-flush-pending-output t)
1321 (setq gud-running nil)
1322 (gdb-force-mode-line-update
1323 (propertize "stopped" 'face font-lock-warning-face))
1324 (setq gdb-output-sink 'user)
1325 (setq gdb-input-queue nil)
1326 (setq gdb-pending-triggers nil)
1327 (setq gdb-prompting t))
1328
1329 (defconst gdb-source-spec-regexp
1330 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:0x0*\\([a-f0-9]*\\)")
1331
1332 ;; Do not use this except as an annotation handler.
1333 (defun gdb-source (args)
1334 (string-match gdb-source-spec-regexp args)
1335 ;; Extract the frame position from the marker.
1336 (setq gud-last-frame
1337 (cons
1338 (match-string 1 args)
1339 (string-to-number (match-string 2 args))))
1340 (setq gdb-pc-address (match-string 3 args))
1341 ;; cover for auto-display output which comes *before*
1342 ;; stopped annotation
1343 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
1344
1345 (defun gdb-pre-prompt (ignored)
1346 "An annotation handler for `pre-prompt'.
1347 This terminates the collection of output from a previous command if that
1348 happens to be in effect."
1349 (setq gdb-error nil)
1350 (let ((sink gdb-output-sink))
1351 (cond
1352 ((eq sink 'user) t)
1353 ((eq sink 'emacs)
1354 (setq gdb-output-sink 'post-emacs))
1355 (t
1356 (gdb-resync)
1357 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
1358
1359 (defun gdb-prompt (ignored)
1360 "An annotation handler for `prompt'.
1361 This sends the next command (if any) to gdb."
1362 (when gdb-first-prompt
1363 (gdb-force-mode-line-update
1364 (propertize "initializing..." 'face font-lock-variable-name-face))
1365 (gdb-init-1)
1366 (setq gdb-first-prompt nil))
1367 (let ((sink gdb-output-sink))
1368 (cond
1369 ((eq sink 'user) t)
1370 ((eq sink 'post-emacs)
1371 (setq gdb-output-sink 'user)
1372 (let ((handler
1373 (car (cdr gdb-current-item))))
1374 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1375 (funcall handler))))
1376 (t
1377 (gdb-resync)
1378 (error "Phase error in gdb-prompt (got %s)" sink))))
1379 (let ((input (gdb-dequeue-input)))
1380 (if input
1381 (gdb-send-item input)
1382 (progn
1383 (setq gdb-prompting t)
1384 (gud-display-frame)
1385 (setq gdb-early-user-input (nreverse gdb-early-user-input))
1386 (while gdb-early-user-input
1387 (gdb-enqueue-input (car gdb-early-user-input))
1388 (setq gdb-early-user-input (cdr gdb-early-user-input)))))))
1389
1390 (defun gdb-subprompt (ignored)
1391 "An annotation handler for non-top-level prompts."
1392 (setq gdb-prompting t))
1393
1394 (defun gdb-starting (ignored)
1395 "An annotation handler for `starting'.
1396 This says that I/O for the subprocess is now the program being debugged,
1397 not GDB."
1398 (setq gdb-active-process t)
1399 (setq gdb-printing t)
1400 (let ((sink gdb-output-sink))
1401 (cond
1402 ((eq sink 'user)
1403 (progn
1404 (setq gud-running t)
1405 (setq gdb-stack-update t)
1406 ;; Temporarily set gud-running to nil to force "info stack" onto queue.
1407 (let ((gud-running nil))
1408 (gdb-invalidate-frames))
1409 (setq gdb-inferior-status "running")
1410 (setq gdb-signalled nil)
1411 (gdb-force-mode-line-update
1412 (propertize gdb-inferior-status 'face font-lock-type-face))
1413 (gdb-remove-text-properties)
1414 (setq gud-old-arrow gud-overlay-arrow-position)
1415 (setq gud-overlay-arrow-position nil)
1416 (setq gdb-overlay-arrow-position nil)
1417 (setq gdb-stack-position nil)
1418 (if gdb-use-separate-io-buffer
1419 (setq gdb-output-sink 'inferior))))
1420 (t
1421 (gdb-resync)
1422 (error "Unexpected `starting' annotation")))))
1423
1424 (defun gdb-signal (ignored)
1425 (setq gdb-inferior-status "signal")
1426 (gdb-force-mode-line-update
1427 (propertize gdb-inferior-status 'face font-lock-warning-face))
1428 (gdb-stopping ignored))
1429
1430 (defun gdb-stopping (ignored)
1431 "An annotation handler for `breakpoint' and other annotations.
1432 They say that I/O for the subprocess is now GDB, not the program
1433 being debugged."
1434 (if gdb-use-separate-io-buffer
1435 (let ((sink gdb-output-sink))
1436 (cond
1437 ((eq sink 'inferior)
1438 (setq gdb-output-sink 'user))
1439 (t
1440 (gdb-resync)
1441 (error "Unexpected stopping annotation"))))))
1442
1443 (defun gdb-exited (ignored)
1444 "An annotation handler for `exited' and `signalled'.
1445 They say that I/O for the subprocess is now GDB, not the program
1446 being debugged and that the program is no longer running. This
1447 function is used to change the focus of GUD tooltips to #define
1448 directives."
1449 (setq gdb-active-process nil)
1450 (setq gud-overlay-arrow-position nil)
1451 (setq gdb-overlay-arrow-position nil)
1452 (setq gdb-stack-position nil)
1453 (setq gud-old-arrow nil)
1454 (setq gdb-inferior-status "exited")
1455 (gdb-force-mode-line-update
1456 (propertize gdb-inferior-status 'face font-lock-warning-face))
1457 (gdb-stopping ignored))
1458
1459 (defun gdb-signalled (ignored)
1460 (setq gdb-signalled t))
1461
1462 (defun gdb-frame-begin (ignored)
1463 (setq gdb-frame-begin t)
1464 (setq gdb-printing nil)
1465 (let ((sink gdb-output-sink))
1466 (cond
1467 ((eq sink 'inferior)
1468 (setq gdb-output-sink 'user))
1469 ((eq sink 'user) t)
1470 ((eq sink 'emacs) t)
1471 (t
1472 (gdb-resync)
1473 (error "Unexpected frame-begin annotation (%S)" sink)))))
1474
1475 (defcustom gdb-same-frame focus-follows-mouse
1476 "Non-nil means pop up GUD buffer in same frame."
1477 :group 'gdb
1478 :type 'boolean
1479 :version "22.1")
1480
1481 (defcustom gdb-find-source-frame nil
1482 "Non-nil means try to find a source frame further up stack e.g after signal."
1483 :group 'gdb
1484 :type 'boolean
1485 :version "22.1")
1486
1487 (defun gdb-find-source-frame (arg)
1488 "Toggle looking for a source frame further up call stack.
1489 The code associated with current (innermost) frame may not have
1490 been compiled with debug information, e.g., C library routine.
1491 With prefix argument ARG, look for a source frame further up
1492 stack to display in the source buffer if ARG is positive,
1493 otherwise don't look further up."
1494 (interactive "P")
1495 (setq gdb-find-source-frame
1496 (if (null arg)
1497 (not gdb-find-source-frame)
1498 (> (prefix-numeric-value arg) 0)))
1499 (message (format "Looking for source frame %sabled"
1500 (if gdb-find-source-frame "en" "dis"))))
1501
1502 (defun gdb-stopped (ignored)
1503 "An annotation handler for `stopped'.
1504 It is just like `gdb-stopping', except that if we already set the output
1505 sink to `user' in `gdb-stopping', that is fine."
1506 (setq gud-running nil)
1507 (unless (or gud-overlay-arrow-position gud-last-frame)
1508 (if (and gdb-frame-begin gdb-printing)
1509 (setq gud-overlay-arrow-position gud-old-arrow)
1510 ;;Pop up GUD buffer to display current frame when it doesn't have source
1511 ;;information i.e if not compiled with -g as with libc routines generally.
1512 (if gdb-same-frame
1513 (gdb-display-gdb-buffer)
1514 (gdb-frame-gdb-buffer))
1515 (if gdb-find-source-frame
1516 ;;Try to find source further up stack e.g after signal.
1517 (setq gdb-look-up-stack
1518 (if (gdb-get-buffer 'gdb-stack-buffer)
1519 'keep
1520 (progn
1521 (gdb-get-buffer-create 'gdb-stack-buffer)
1522 (gdb-invalidate-frames)
1523 'delete))))))
1524 (unless (member gdb-inferior-status '("exited" "signal"))
1525 (setq gdb-active-process t) ;Just for attaching case.
1526 (setq gdb-inferior-status "stopped")
1527 (gdb-force-mode-line-update
1528 (propertize gdb-inferior-status 'face font-lock-warning-face)))
1529 (let ((sink gdb-output-sink))
1530 (cond
1531 ((eq sink 'inferior)
1532 (setq gdb-output-sink 'user))
1533 ((eq sink 'user) t)
1534 (t
1535 (gdb-resync)
1536 (error "Unexpected stopped annotation"))))
1537 (if gdb-signalled (gdb-exited ignored)))
1538
1539 (defun gdb-error (ignored)
1540 (setq gdb-error (not gdb-error)))
1541
1542 (defun gdb-post-prompt (ignored)
1543 "An annotation handler for `post-prompt'.
1544 This begins the collection of output from the current command if that
1545 happens to be appropriate."
1546 ;; Don't add to queue if there outstanding items or gdb-version is not known
1547 ;; yet.
1548 (unless (or gdb-pending-triggers gdb-first-post-prompt)
1549 (gdb-get-selected-frame)
1550 (gdb-invalidate-frames)
1551 ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
1552 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
1553 (gdb-invalidate-breakpoints)
1554 ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
1555 ;; so gdb-pc-address is updated.
1556 ;; (gdb-invalidate-assembler)
1557
1558 (if (string-equal gdb-version "pre-6.4")
1559 (gdb-invalidate-registers)
1560 (gdb-get-changed-registers)
1561 (gdb-invalidate-registers-1))
1562
1563 (gdb-invalidate-memory)
1564 (if (string-equal gdb-version "pre-6.4")
1565 (gdb-invalidate-locals)
1566 (gdb-invalidate-locals-1))
1567
1568 (gdb-invalidate-threads)
1569 (unless (or (null gdb-var-list)
1570 (eq system-type 'darwin)) ;Breaks on Darwin's GDB-5.3.
1571 ;; FIXME: with GDB-6 on Darwin, this might very well work.
1572 ;; Only needed/used with speedbar/watch expressions.
1573 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
1574 (if (string-equal gdb-version "pre-6.4")
1575 (gdb-var-update)
1576 (gdb-var-update-1)))))
1577 (setq gdb-first-post-prompt nil)
1578 (let ((sink gdb-output-sink))
1579 (cond
1580 ((eq sink 'user) t)
1581 ((eq sink 'pre-emacs)
1582 (setq gdb-output-sink 'emacs))
1583 (t
1584 (gdb-resync)
1585 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
1586
1587 (defconst gdb-buffer-list
1588 '(gdb-stack-buffer gdb-locals-buffer gdb-registers-buffer gdb-threads-buffer))
1589
1590 (defun gdb-remove-text-properties ()
1591 (dolist (buffertype gdb-buffer-list)
1592 (let ((buffer (gdb-get-buffer buffertype)))
1593 (if buffer
1594 (with-current-buffer buffer
1595 (let ((inhibit-read-only t))
1596 (remove-text-properties
1597 (point-min) (point-max) '(mouse-face nil help-echo nil))))))))
1598
1599 ;; GUD displays the selected GDB frame. This might might not be the current
1600 ;; GDB frame (after up, down etc). If no GDB frame is visible but the last
1601 ;; visited breakpoint is, use that window.
1602 (defun gdb-display-source-buffer (buffer)
1603 (let* ((last-window (if gud-last-last-frame
1604 (get-buffer-window
1605 (gud-find-file (car gud-last-last-frame)))))
1606 (source-window (or last-window
1607 (if (and gdb-source-window
1608 (window-live-p gdb-source-window))
1609 gdb-source-window))))
1610 (when source-window
1611 (setq gdb-source-window source-window)
1612 (set-window-buffer source-window buffer))
1613 source-window))
1614
1615 ;; Derived from gud-gdb-marker-regexp
1616 (defvar gdb-fullname-regexp
1617 (concat "\\(.:?[^" ":" "\n]*\\)" ":" "\\([0-9]*\\)" ":" ".*"))
1618
1619 (defun gud-gdba-marker-filter (string)
1620 "A gud marker filter for gdb. Handle a burst of output from GDB."
1621 (if gdb-flush-pending-output
1622 nil
1623 (when gdb-enable-debug
1624 (push (cons 'recv string) gdb-debug-log)
1625 (if (and gdb-debug-log-max
1626 (> (length gdb-debug-log) gdb-debug-log-max))
1627 (setcdr (nthcdr (1- gdb-debug-log-max) gdb-debug-log) nil)))
1628 ;; Recall the left over gud-marker-acc from last time.
1629 (setq gud-marker-acc (concat gud-marker-acc string))
1630 ;; Start accumulating output for the GUD buffer.
1631 (let ((output ""))
1632 ;;
1633 ;; Process all the complete markers in this chunk.
1634 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
1635 (let ((annotation (match-string 1 gud-marker-acc))
1636 (before (substring gud-marker-acc 0 (match-beginning 0)))
1637 (after (substring gud-marker-acc (match-end 0))))
1638 ;;
1639 ;; Parse the tag from the annotation, and maybe its arguments.
1640 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1641 (let* ((annotation-type (match-string 1 annotation))
1642 (annotation-arguments (match-string 2 annotation))
1643 (annotation-rule (assoc annotation-type
1644 gdb-annotation-rules))
1645 (fullname (string-match gdb-fullname-regexp annotation-type)))
1646
1647 ;; Stuff prior to the match is just ordinary output.
1648 ;; It is either concatenated to OUTPUT or directed
1649 ;; elsewhere.
1650 (setq output
1651 (gdb-concat-output output
1652 (concat before (if fullname "\n"))))
1653
1654 ;; Take that stuff off the gud-marker-acc.
1655 (setq gud-marker-acc after)
1656
1657 ;; Call the handler for this annotation.
1658 (if annotation-rule
1659 (funcall (car (cdr annotation-rule))
1660 annotation-arguments)
1661
1662 ;; Switch to gud-gdb-marker-filter if appropriate.
1663 (when fullname
1664
1665 ;; Extract the frame position from the marker.
1666 (setq gud-last-frame (cons (match-string 1 annotation)
1667 (string-to-number
1668 (match-string 2 annotation))))
1669
1670 (set (make-local-variable 'gud-minor-mode) 'gdb)
1671 (set (make-local-variable 'gud-marker-filter)
1672 'gud-gdb-marker-filter)))
1673
1674 ;; Else the annotation is not recognized. Ignore it silently,
1675 ;; so that GDB can add new annotations without causing
1676 ;; us to blow up.
1677 )))
1678
1679 ;; Does the remaining text end in a partial line?
1680 ;; If it does, then keep part of the gud-marker-acc until we get more.
1681 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1682 gud-marker-acc)
1683 (progn
1684 ;; Everything before the potential marker start can be output.
1685 (setq output
1686 (gdb-concat-output output
1687 (substring gud-marker-acc 0
1688 (match-beginning 0))))
1689 ;;
1690 ;; Everything after, we save, to combine with later input.
1691 (setq gud-marker-acc (substring gud-marker-acc
1692 (match-beginning 0))))
1693 ;;
1694 ;; In case we know the gud-marker-acc contains no partial annotations:
1695 (progn
1696 (setq output (gdb-concat-output output gud-marker-acc))
1697 (setq gud-marker-acc "")))
1698 output)))
1699
1700 (defun gdb-concat-output (so-far new)
1701 (if gdb-error
1702 (put-text-property 0 (length new) 'face font-lock-warning-face new))
1703 (let ((sink gdb-output-sink))
1704 (cond
1705 ((eq sink 'user) (concat so-far new))
1706 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1707 ((eq sink 'emacs)
1708 (gdb-append-to-partial-output new)
1709 so-far)
1710 ((eq sink 'inferior)
1711 (gdb-append-to-inferior-io new)
1712 so-far)
1713 (t
1714 (gdb-resync)
1715 (error "Bogon output sink %S" sink)))))
1716
1717 (defun gdb-append-to-partial-output (string)
1718 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1719 (goto-char (point-max))
1720 (insert string)))
1721
1722 (defun gdb-clear-partial-output ()
1723 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1724 (erase-buffer)))
1725
1726 (defun gdb-append-to-inferior-io (string)
1727 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1728 (goto-char (point-max))
1729 (insert-before-markers string))
1730 (if (not (string-equal string ""))
1731 (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io) t)))
1732
1733 (defun gdb-clear-inferior-io ()
1734 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
1735 (erase-buffer)))
1736 \f
1737
1738 ;; One trick is to have a command who's output is always available in a buffer
1739 ;; of it's own, and is always up to date. We build several buffers of this
1740 ;; type.
1741 ;;
1742 ;; There are two aspects to this: gdb has to tell us when the output for that
1743 ;; command might have changed, and we have to be able to run the command
1744 ;; behind the user's back.
1745 ;;
1746 ;; The output phasing associated with the variable gdb-output-sink
1747 ;; help us to run commands behind the user's back.
1748 ;;
1749 ;; Below is the code for specificly managing buffers of output from one
1750 ;; command.
1751 ;;
1752
1753 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1754 ;; It adds an input for the command we are tracking. It should be the
1755 ;; annotation rule binding of whatever gdb sends to tell us this command
1756 ;; might have changed it's output.
1757 ;;
1758 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1759 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1760 ;; input in the input queue (see comment about ``gdb communications'' above).
1761
1762 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1763 output-handler)
1764 `(defun ,name (&optional ignored)
1765 (if (and ,demand-predicate
1766 (not (member ',name
1767 gdb-pending-triggers)))
1768 (progn
1769 (gdb-enqueue-input
1770 (list ,gdb-command ',output-handler))
1771 (push ',name gdb-pending-triggers)))))
1772
1773 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1774 `(defun ,name ()
1775 (setq gdb-pending-triggers
1776 (delq ',trigger
1777 gdb-pending-triggers))
1778 (let ((buf (gdb-get-buffer ',buf-key)))
1779 (and buf
1780 (with-current-buffer buf
1781 (let* ((window (get-buffer-window buf 0))
1782 (start (window-start window))
1783 (p (window-point window))
1784 (buffer-read-only nil))
1785 (erase-buffer)
1786 (insert-buffer-substring (gdb-get-buffer-create
1787 'gdb-partial-output-buffer))
1788 (set-window-start window start)
1789 (set-window-point window p)))))
1790 ;; put customisation here
1791 (,custom-defun)))
1792
1793 (defmacro def-gdb-auto-updated-buffer (buffer-key
1794 trigger-name gdb-command
1795 output-handler-name custom-defun)
1796 `(progn
1797 (def-gdb-auto-update-trigger ,trigger-name
1798 ;; The demand predicate:
1799 (gdb-get-buffer ',buffer-key)
1800 ,gdb-command
1801 ,output-handler-name)
1802 (def-gdb-auto-update-handler ,output-handler-name
1803 ,trigger-name ,buffer-key ,custom-defun)))
1804
1805 \f
1806 ;;
1807 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1808 ;;
1809 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1810 'gdb-breakpoints-buffer-name
1811 'gdb-breakpoints-mode)
1812
1813 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1814 ;; This defines the auto update rule for buffers of type
1815 ;; `gdb-breakpoints-buffer'.
1816 ;;
1817 ;; It defines a function to serve as the annotation handler that
1818 ;; handles the `foo-invalidated' message. That function is called:
1819 gdb-invalidate-breakpoints
1820 ;;
1821 ;; To update the buffer, this command is sent to gdb.
1822 "server info breakpoints\n"
1823 ;;
1824 ;; This also defines a function to be the handler for the output
1825 ;; from the command above. That function will copy the output into
1826 ;; the appropriately typed buffer. That function will be called:
1827 gdb-info-breakpoints-handler
1828 ;; buffer specific functions
1829 gdb-info-breakpoints-custom)
1830
1831 (defconst breakpoint-xpm-data
1832 "/* XPM */
1833 static char *magick[] = {
1834 /* columns rows colors chars-per-pixel */
1835 \"10 10 2 1\",
1836 \" c red\",
1837 \"+ c None\",
1838 /* pixels */
1839 \"+++ +++\",
1840 \"++ ++\",
1841 \"+ +\",
1842 \" \",
1843 \" \",
1844 \" \",
1845 \" \",
1846 \"+ +\",
1847 \"++ ++\",
1848 \"+++ +++\",
1849 };"
1850 "XPM data used for breakpoint icon.")
1851
1852 (defconst breakpoint-enabled-pbm-data
1853 "P1
1854 10 10\",
1855 0 0 0 0 1 1 1 1 0 0 0 0
1856 0 0 0 1 1 1 1 1 1 0 0 0
1857 0 0 1 1 1 1 1 1 1 1 0 0
1858 0 1 1 1 1 1 1 1 1 1 1 0
1859 0 1 1 1 1 1 1 1 1 1 1 0
1860 0 1 1 1 1 1 1 1 1 1 1 0
1861 0 1 1 1 1 1 1 1 1 1 1 0
1862 0 0 1 1 1 1 1 1 1 1 0 0
1863 0 0 0 1 1 1 1 1 1 0 0 0
1864 0 0 0 0 1 1 1 1 0 0 0 0"
1865 "PBM data used for enabled breakpoint icon.")
1866
1867 (defconst breakpoint-disabled-pbm-data
1868 "P1
1869 10 10\",
1870 0 0 1 0 1 0 1 0 0 0
1871 0 1 0 1 0 1 0 1 0 0
1872 1 0 1 0 1 0 1 0 1 0
1873 0 1 0 1 0 1 0 1 0 1
1874 1 0 1 0 1 0 1 0 1 0
1875 0 1 0 1 0 1 0 1 0 1
1876 1 0 1 0 1 0 1 0 1 0
1877 0 1 0 1 0 1 0 1 0 1
1878 0 0 1 0 1 0 1 0 1 0
1879 0 0 0 1 0 1 0 1 0 0"
1880 "PBM data used for disabled breakpoint icon.")
1881
1882 (defvar breakpoint-enabled-icon nil
1883 "Icon for enabled breakpoint in display margin.")
1884
1885 (defvar breakpoint-disabled-icon nil
1886 "Icon for disabled breakpoint in display margin.")
1887
1888 (and (display-images-p)
1889 ;; Bitmap for breakpoint in fringe
1890 (define-fringe-bitmap 'breakpoint
1891 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c")
1892 ;; Bitmap for gud-overlay-arrow in fringe
1893 (define-fringe-bitmap 'hollow-right-triangle
1894 "\xe0\x90\x88\x84\x84\x88\x90\xe0"))
1895
1896 (defface breakpoint-enabled
1897 '((t
1898 :foreground "red1"
1899 :weight bold))
1900 "Face for enabled breakpoint icon in fringe."
1901 :group 'gdb)
1902
1903 (defface breakpoint-disabled
1904 '((((class color) (min-colors 88)) :foreground "grey70")
1905 ;; Ensure that on low-color displays that we end up something visible.
1906 (((class color) (min-colors 8) (background light))
1907 :foreground "black")
1908 (((class color) (min-colors 8) (background dark))
1909 :foreground "white")
1910 (((type tty) (class mono))
1911 :inverse-video t)
1912 (t :background "gray"))
1913 "Face for disabled breakpoint icon in fringe."
1914 :group 'gdb)
1915
1916 (defconst gdb-breakpoint-regexp
1917 "\\(?:\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\|\\([0-9]+\\.[0-9]+\\)\\)\\s-+\\(.\\)\\s-+")
1918
1919 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1920 (defun gdb-info-breakpoints-custom ()
1921 (let ((flag) (bptno))
1922 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1923 (dolist (buffer (buffer-list))
1924 (with-current-buffer buffer
1925 (if (and (memq gud-minor-mode '(gdba gdbmi))
1926 (not (string-match "\\` ?\\*.+\\*\\'" (buffer-name))))
1927 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1928 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1929 (save-excursion
1930 (let ((buffer-read-only nil))
1931 (goto-char (point-min))
1932 (while (< (point) (- (point-max) 1))
1933 (forward-line 1)
1934 (if (looking-at gdb-breakpoint-regexp)
1935 (progn
1936 (setq bptno (or (match-string 1) (match-string 2)))
1937 (setq flag (char-after (match-beginning 3)))
1938 (if (match-string 1)
1939 (setq gdb-parent-bptno-enabled (eq flag ?y)))
1940 (add-text-properties
1941 (match-beginning 3) (match-end 3)
1942 (if (eq flag ?y)
1943 '(face font-lock-warning-face)
1944 '(face font-lock-type-face)))
1945 (let ((bl (point))
1946 (el (line-end-position)))
1947 (if (re-search-forward " in \\(.*\\) at\\s-+" el t)
1948 (progn
1949 (add-text-properties
1950 (match-beginning 1) (match-end 1)
1951 '(face font-lock-function-name-face))
1952 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1953 (let ((line (match-string 2))
1954 (file (match-string 1)))
1955 (add-text-properties bl el
1956 '(mouse-face highlight
1957 help-echo "mouse-2, RET: visit breakpoint"))
1958 (unless (file-exists-p file)
1959 (setq file (cdr (assoc bptno gdb-location-alist))))
1960 (if (and file
1961 (not (string-equal file "File not found")))
1962 (with-current-buffer
1963 (find-file-noselect file 'nowarn)
1964 (gdb-init-buffer)
1965 ;; Only want one breakpoint icon at each
1966 ;; location.
1967 (save-excursion
1968 (goto-line (string-to-number line))
1969 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1970 (gdb-enqueue-input
1971 (list
1972 (concat gdb-server-prefix "list "
1973 (match-string-no-properties 1) ":1\n")
1974 'ignore))
1975 (gdb-enqueue-input
1976 (list (concat gdb-server-prefix "info source\n")
1977 `(lambda () (gdb-get-location
1978 ,bptno ,line ,flag)))))))
1979 (if (re-search-forward
1980 "<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
1981 el t)
1982 (add-text-properties
1983 (match-beginning 1) (match-end 1)
1984 '(face font-lock-function-name-face))
1985 (end-of-line)
1986 (re-search-backward "\\s-\\(\\S-*\\)"
1987 bl t)
1988 (add-text-properties
1989 (match-beginning 1) (match-end 1)
1990 '(face font-lock-variable-name-face)))))))
1991 (end-of-line))))))
1992 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom))
1993
1994 ;; Breakpoints buffer is always present. Hack to just update
1995 ;; current frame if there's been no execution.
1996 (if gdb-stack-update
1997 (setq gdb-stack-update nil)
1998 (if (gdb-get-buffer 'gdb-stack-buffer) (gdb-info-stack-custom))))
1999
2000 (declare-function gud-remove "gdb-ui" t t) ; gud-def
2001 (declare-function gud-break "gdb-ui" t t) ; gud-def
2002
2003 (defun gdb-mouse-set-clear-breakpoint (event)
2004 "Set/clear breakpoint in left fringe/margin at mouse click.
2005 If not in a source or disassembly buffer just set point."
2006 (interactive "e")
2007 (mouse-minibuffer-check event)
2008 (let ((posn (event-end event)))
2009 (with-selected-window (posn-window posn)
2010 (if (or (buffer-file-name) (eq major-mode 'gdb-assembler-mode))
2011 (if (numberp (posn-point posn))
2012 (save-excursion
2013 (goto-char (posn-point posn))
2014 (if (or (posn-object posn)
2015 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
2016 'breakpoint))
2017 (gud-remove nil)
2018 (gud-break nil)))))
2019 (posn-set-point posn))))
2020
2021 (defun gdb-mouse-toggle-breakpoint-margin (event)
2022 "Enable/disable breakpoint in left margin with mouse click."
2023 (interactive "e")
2024 (mouse-minibuffer-check event)
2025 (let ((posn (event-end event)))
2026 (if (numberp (posn-point posn))
2027 (with-selected-window (posn-window posn)
2028 (save-excursion
2029 (goto-char (posn-point posn))
2030 (if (posn-object posn)
2031 (let* ((bptno (get-text-property
2032 0 'gdb-bptno (car (posn-string posn)))))
2033 (string-match "\\([0-9+]\\)*" bptno)
2034 (gdb-enqueue-input
2035 (list
2036 (concat gdb-server-prefix
2037 (if (get-text-property
2038 0 'gdb-enabled (car (posn-string posn)))
2039 "disable "
2040 "enable ")
2041 (match-string 1 bptno) "\n")
2042 'ignore)))))))))
2043
2044 (defun gdb-mouse-toggle-breakpoint-fringe (event)
2045 "Enable/disable breakpoint in left fringe with mouse click."
2046 (interactive "e")
2047 (mouse-minibuffer-check event)
2048 (let* ((posn (event-end event))
2049 (pos (posn-point posn))
2050 obj)
2051 (when (numberp pos)
2052 (with-selected-window (posn-window posn)
2053 (save-excursion
2054 (set-buffer (window-buffer (selected-window)))
2055 (goto-char pos)
2056 (dolist (overlay (overlays-in pos pos))
2057 (when (overlay-get overlay 'put-break)
2058 (setq obj (overlay-get overlay 'before-string))))
2059 (when (stringp obj)
2060 (let* ((bptno (get-text-property 0 'gdb-bptno obj)))
2061 (string-match "\\([0-9+]\\)*" bptno)
2062 (gdb-enqueue-input
2063 (list
2064 (concat gdb-server-prefix
2065 (if (get-text-property 0 'gdb-enabled obj)
2066 "disable "
2067 "enable ")
2068 (match-string 1 bptno) "\n")
2069 'ignore)))))))))
2070
2071 (defun gdb-breakpoints-buffer-name ()
2072 (with-current-buffer gud-comint-buffer
2073 (concat "*breakpoints of " (gdb-get-target-string) "*")))
2074
2075 (defun gdb-display-breakpoints-buffer ()
2076 "Display status of user-settable breakpoints."
2077 (interactive)
2078 (gdb-display-buffer
2079 (gdb-get-buffer-create 'gdb-breakpoints-buffer) t))
2080
2081 (defun gdb-frame-breakpoints-buffer ()
2082 "Display status of user-settable breakpoints in a new frame."
2083 (interactive)
2084 (let ((special-display-regexps (append special-display-regexps '(".*")))
2085 (special-display-frame-alist gdb-frame-parameters))
2086 (display-buffer (gdb-get-buffer-create 'gdb-breakpoints-buffer))))
2087
2088 (defvar gdb-breakpoints-mode-map
2089 (let ((map (make-sparse-keymap))
2090 (menu (make-sparse-keymap "Breakpoints")))
2091 (define-key menu [quit] '("Quit" . gdb-delete-frame-or-window))
2092 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
2093 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
2094 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
2095 (suppress-keymap map)
2096 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
2097 (define-key map " " 'gdb-toggle-breakpoint)
2098 (define-key map "D" 'gdb-delete-breakpoint)
2099 ;; Don't bind "q" to kill-this-buffer as we need it for breakpoint icons.
2100 (define-key map "q" 'gdb-delete-frame-or-window)
2101 (define-key map "\r" 'gdb-goto-breakpoint)
2102 (define-key map [mouse-2] 'gdb-goto-breakpoint)
2103 (define-key map [follow-link] 'mouse-face)
2104 map))
2105
2106 (defun gdb-delete-frame-or-window ()
2107 "Delete frame if there is only one window. Otherwise delete the window."
2108 (interactive)
2109 (if (one-window-p) (delete-frame)
2110 (delete-window)))
2111
2112 ;;from make-mode-line-mouse-map
2113 (defun gdb-make-header-line-mouse-map (mouse function) "\
2114 Return a keymap with single entry for mouse key MOUSE on the header line.
2115 MOUSE is defined to run function FUNCTION with no args in the buffer
2116 corresponding to the mode line clicked."
2117 (let ((map (make-sparse-keymap)))
2118 (define-key map (vector 'header-line mouse) function)
2119 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2120 map))
2121
2122 (defvar gdb-breakpoints-header
2123 `(,(propertize "Breakpoints"
2124 'help-echo "mouse-1: select"
2125 'mouse-face 'mode-line-highlight
2126 'face 'mode-line
2127 'local-map
2128 (gdb-make-header-line-mouse-map
2129 'mouse-1
2130 (lambda (event) (interactive "e")
2131 (save-selected-window
2132 (select-window (posn-window (event-start event)))
2133 (set-window-dedicated-p (selected-window) nil)
2134 (switch-to-buffer
2135 (gdb-get-buffer-create 'gdb-breakpoints-buffer))
2136 (set-window-dedicated-p (selected-window) t)))))
2137 " "
2138 ,(propertize "Threads"
2139 'help-echo "mouse-1: select"
2140 'mouse-face 'mode-line-highlight
2141 'face 'mode-line
2142 'local-map
2143 (gdb-make-header-line-mouse-map
2144 'mouse-1
2145 (lambda (event) (interactive "e")
2146 (save-selected-window
2147 (select-window (posn-window (event-start event)))
2148 (set-window-dedicated-p (selected-window) nil)
2149 (switch-to-buffer
2150 (gdb-get-buffer-create 'gdb-threads-buffer))
2151 (set-window-dedicated-p (selected-window) t)))))))
2152
2153 (defun gdb-breakpoints-mode ()
2154 "Major mode for gdb breakpoints.
2155
2156 \\{gdb-breakpoints-mode-map}"
2157 (kill-all-local-variables)
2158 (setq major-mode 'gdb-breakpoints-mode)
2159 (setq mode-name "Breakpoints")
2160 (use-local-map gdb-breakpoints-mode-map)
2161 (setq buffer-read-only t)
2162 (buffer-disable-undo)
2163 (setq header-line-format gdb-breakpoints-header)
2164 (run-mode-hooks 'gdb-breakpoints-mode-hook)
2165 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2166 'gdb-invalidate-breakpoints
2167 'gdbmi-invalidate-breakpoints))
2168
2169 (defun gdb-toggle-breakpoint ()
2170 "Enable/disable breakpoint at current line."
2171 (interactive)
2172 (save-excursion
2173 (beginning-of-line 1)
2174 (if (looking-at gdb-breakpoint-regexp)
2175 (gdb-enqueue-input
2176 (list
2177 (concat gdb-server-prefix
2178 (if (eq ?y (char-after (match-beginning 3)))
2179 "disable "
2180 "enable ")
2181 (or (match-string 1) (match-string 2)) "\n") 'ignore))
2182 (error "Not recognized as break/watchpoint line"))))
2183
2184 (defun gdb-delete-breakpoint ()
2185 "Delete the breakpoint at current line."
2186 (interactive)
2187 (save-excursion
2188 (beginning-of-line 1)
2189 (if (looking-at gdb-breakpoint-regexp)
2190 (if (match-string 1)
2191 (gdb-enqueue-input
2192 (list
2193 (concat gdb-server-prefix "delete " (match-string 1) "\n")
2194 'ignore))
2195 (message-box "This breakpoint cannot be deleted on its own."))
2196 (error "Not recognized as break/watchpoint line"))))
2197
2198 (defun gdb-goto-breakpoint (&optional event)
2199 "Display the breakpoint location specified at current line."
2200 (interactive (list last-input-event))
2201 (if event (posn-set-point (event-end event)))
2202 (save-excursion
2203 (beginning-of-line 1)
2204 (if (looking-at "\\([0-9]+\\.?[0-9]*\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
2205 (let ((bptno (match-string 1))
2206 (file (match-string 2))
2207 (line (match-string 3)))
2208 (save-selected-window
2209 (let* ((buffer (find-file-noselect
2210 (if (file-exists-p file) file
2211 (cdr (assoc bptno gdb-location-alist)))))
2212 (window (or (gdb-display-source-buffer buffer)
2213 (display-buffer buffer))))
2214 (setq gdb-source-window window)
2215 (with-current-buffer buffer
2216 (goto-line (string-to-number line))
2217 (set-window-point window (point))))))
2218 (error "No location specified."))))
2219 \f
2220
2221 ;; Frames buffer. This displays a perpetually correct bactracktrace
2222 ;; (from the command `where').
2223 ;;
2224 ;; Alas, if your stack is deep, it is costly.
2225 ;;
2226 (defcustom gdb-max-frames 40
2227 "Maximum number of frames displayed in call stack."
2228 :type 'integer
2229 :group 'gdb
2230 :version "22.1")
2231
2232 (gdb-set-buffer-rules 'gdb-stack-buffer
2233 'gdb-stack-buffer-name
2234 'gdb-frames-mode)
2235
2236 (def-gdb-auto-updated-buffer gdb-stack-buffer
2237 gdb-invalidate-frames
2238 (concat "server info stack " (number-to-string gdb-max-frames) "\n")
2239 gdb-info-stack-handler
2240 gdb-info-stack-custom)
2241
2242 ;; This may be more important for embedded targets where unwinding the
2243 ;; stack may take a long time.
2244 (defadvice gdb-invalidate-frames (around gdb-invalidate-frames-advice
2245 (&optional ignored) activate compile)
2246 "Only queue \"info stack\" if execution has occurred."
2247 (if gdb-stack-update ad-do-it))
2248
2249 (defun gdb-info-stack-custom ()
2250 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
2251 (let (move-to)
2252 (save-excursion
2253 (unless (eq gdb-look-up-stack 'delete)
2254 (let ((buffer-read-only nil)
2255 bl el)
2256 (goto-char (point-min))
2257 (while (< (point) (point-max))
2258 (setq bl (line-beginning-position)
2259 el (line-end-position))
2260 (when (looking-at "#")
2261 (add-text-properties bl el
2262 '(mouse-face highlight
2263 help-echo "mouse-2, RET: Select frame")))
2264 (goto-char bl)
2265 (when (looking-at "^#\\([0-9]+\\)")
2266 (when (string-equal (match-string 1) gdb-frame-number)
2267 (if (gud-tool-bar-item-visible-no-fringe)
2268 (progn
2269 (put-text-property bl (+ bl 4)
2270 'face '(:inverse-video t))
2271 (setq move-to bl))
2272 (or gdb-stack-position
2273 (setq gdb-stack-position (make-marker)))
2274 (set-marker gdb-stack-position (point))
2275 (setq move-to gdb-stack-position)))
2276 (when (re-search-forward "\\([^ ]+\\) (" el t)
2277 (put-text-property (match-beginning 1) (match-end 1)
2278 'face font-lock-function-name-face)
2279 (setq bl (match-end 0))
2280 (while (re-search-forward "<\\([^>]+\\)>" el t)
2281 (put-text-property (match-beginning 1) (match-end 1)
2282 'face font-lock-function-name-face))
2283 (goto-char bl)
2284 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
2285 (put-text-property (match-beginning 1) (match-end 1)
2286 'face font-lock-variable-name-face))))
2287 (forward-line 1))
2288 (forward-line -1)
2289 (when (looking-at "(More stack frames follow...)")
2290 (add-text-properties (match-beginning 0) (match-end 0)
2291 '(mouse-face highlight
2292 gdb-max-frames t
2293 help-echo
2294 "mouse-2, RET: customize gdb-max-frames to see more frames")))))
2295 (when gdb-look-up-stack
2296 (goto-char (point-min))
2297 (when (re-search-forward "\\(\\S-+?\\):\\([0-9]+\\)" nil t)
2298 (let ((start (line-beginning-position))
2299 (file (match-string 1))
2300 (line (match-string 2)))
2301 (re-search-backward "^#*\\([0-9]+\\)" start t)
2302 (gdb-enqueue-input
2303 (list (concat gdb-server-prefix "frame "
2304 (match-string 1) "\n") 'gdb-set-hollow))
2305 (gdb-enqueue-input
2306 (list (concat gdb-server-prefix "frame 0\n") 'ignore))))))
2307 (when move-to
2308 (let ((window (get-buffer-window (current-buffer) 0)))
2309 (when window
2310 (with-selected-window window
2311 (goto-char move-to)
2312 (unless (pos-visible-in-window-p)
2313 (recenter '(center)))))))))
2314 (if (eq gdb-look-up-stack 'delete)
2315 (kill-buffer (gdb-get-buffer 'gdb-stack-buffer)))
2316 (setq gdb-look-up-stack nil))
2317
2318 (defun gdb-set-hollow ()
2319 (if gud-last-last-frame
2320 (with-current-buffer (gud-find-file (car gud-last-last-frame))
2321 (setq fringe-indicator-alist
2322 '((overlay-arrow . hollow-right-triangle))))))
2323
2324 (defun gdb-stack-buffer-name ()
2325 (with-current-buffer gud-comint-buffer
2326 (concat "*stack frames of " (gdb-get-target-string) "*")))
2327
2328 (defun gdb-display-stack-buffer ()
2329 "Display backtrace of current stack."
2330 (interactive)
2331 (gdb-display-buffer
2332 (gdb-get-buffer-create 'gdb-stack-buffer) t))
2333
2334 (defun gdb-frame-stack-buffer ()
2335 "Display backtrace of current stack in a new frame."
2336 (interactive)
2337 (let ((special-display-regexps (append special-display-regexps '(".*")))
2338 (special-display-frame-alist gdb-frame-parameters))
2339 (display-buffer (gdb-get-buffer-create 'gdb-stack-buffer))))
2340
2341 (defvar gdb-frames-mode-map
2342 (let ((map (make-sparse-keymap)))
2343 (suppress-keymap map)
2344 (define-key map "q" 'kill-this-buffer)
2345 (define-key map "\r" 'gdb-frames-select)
2346 (define-key map "F" 'gdb-frames-force-update)
2347 (define-key map [mouse-2] 'gdb-frames-select)
2348 (define-key map [follow-link] 'mouse-face)
2349 map))
2350
2351 (declare-function gdbmi-invalidate-frames "ext:gdb-mi" nil t)
2352
2353 (defun gdb-frames-force-update ()
2354 "Force update of call stack.
2355 Use when the displayed call stack gets out of sync with the
2356 actual one, e.g after using the Gdb command \"return\" or setting
2357 $pc directly from the GUD buffer. This command isn't normally needed."
2358 (interactive)
2359 (setq gdb-stack-update t)
2360 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2361 (gdb-invalidate-frames)
2362 (gdbmi-invalidate-frames)))
2363
2364 (defun gdb-frames-mode ()
2365 "Major mode for gdb call stack.
2366
2367 \\{gdb-frames-mode-map}"
2368 (kill-all-local-variables)
2369 (setq major-mode 'gdb-frames-mode)
2370 (setq mode-name "Frames")
2371 (setq gdb-stack-position nil)
2372 (add-to-list 'overlay-arrow-variable-list 'gdb-stack-position)
2373 (setq truncate-lines t) ;; Make it easier to see overlay arrow.
2374 (setq buffer-read-only t)
2375 (buffer-disable-undo)
2376 (gdb-thread-identification)
2377 (use-local-map gdb-frames-mode-map)
2378 (run-mode-hooks 'gdb-frames-mode-hook)
2379 (setq gdb-stack-update t)
2380 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
2381 'gdb-invalidate-frames
2382 'gdbmi-invalidate-frames))
2383
2384 (defun gdb-get-frame-number ()
2385 (save-excursion
2386 (end-of-line)
2387 (let* ((start (line-beginning-position))
2388 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
2389 (n (or (and pos (match-string 1)) "0")))
2390 n)))
2391
2392 (defun gdb-frames-select (&optional event)
2393 "Select the frame and display the relevant source."
2394 (interactive (list last-input-event))
2395 (if event (posn-set-point (event-end event)))
2396 (if (get-text-property (point) 'gdb-max-frames)
2397 (progn
2398 (message-box "After setting gdb-max-frames, you need to enter\n\
2399 another GDB command e.g pwd, to see new frames")
2400 (customize-variable-other-window 'gdb-max-frames))
2401 (gdb-enqueue-input
2402 (list (concat gdb-server-prefix "frame "
2403 (gdb-get-frame-number) "\n") 'ignore))))
2404 \f
2405
2406 ;; Threads buffer. This displays a selectable thread list.
2407 ;;
2408 (gdb-set-buffer-rules 'gdb-threads-buffer
2409 'gdb-threads-buffer-name
2410 'gdb-threads-mode)
2411
2412 (def-gdb-auto-updated-buffer gdb-threads-buffer
2413 gdb-invalidate-threads
2414 (concat gdb-server-prefix "info threads\n")
2415 gdb-info-threads-handler
2416 gdb-info-threads-custom)
2417
2418 (defun gdb-info-threads-custom ()
2419 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
2420 (let ((buffer-read-only nil))
2421 (save-excursion
2422 (goto-char (point-min))
2423 (if (re-search-forward "\\* \\([0-9]+\\)" nil t)
2424 (setq gdb-thread-indicator
2425 (propertize (concat " [" (match-string 1) "]")
2426 ; FIXME: this help-echo doesn't work
2427 'help-echo "thread id")))
2428 (goto-char (point-min))
2429 (while (< (point) (point-max))
2430 (unless (looking-at "No ")
2431 (add-text-properties (line-beginning-position) (line-end-position)
2432 '(mouse-face highlight
2433 help-echo "mouse-2, RET: select thread")))
2434 (forward-line 1))))))
2435
2436 (defun gdb-threads-buffer-name ()
2437 (with-current-buffer gud-comint-buffer
2438 (concat "*threads of " (gdb-get-target-string) "*")))
2439
2440 (defun gdb-display-threads-buffer ()
2441 "Display IDs of currently known threads."
2442 (interactive)
2443 (gdb-display-buffer
2444 (gdb-get-buffer-create 'gdb-threads-buffer) t))
2445
2446 (defun gdb-frame-threads-buffer ()
2447 "Display IDs of currently known threads in a new frame."
2448 (interactive)
2449 (let ((special-display-regexps (append special-display-regexps '(".*")))
2450 (special-display-frame-alist gdb-frame-parameters))
2451 (display-buffer (gdb-get-buffer-create 'gdb-threads-buffer))))
2452
2453 (defvar gdb-threads-mode-map
2454 (let ((map (make-sparse-keymap)))
2455 (suppress-keymap map)
2456 (define-key map "q" 'kill-this-buffer)
2457 (define-key map "\r" 'gdb-threads-select)
2458 (define-key map [mouse-2] 'gdb-threads-select)
2459 (define-key map [follow-link] 'mouse-face)
2460 map))
2461
2462 (defvar gdb-threads-font-lock-keywords
2463 '((") +\\([^ ]+\\) (" (1 font-lock-function-name-face))
2464 ("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
2465 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face)))
2466 "Font lock keywords used in `gdb-threads-mode'.")
2467
2468 (defun gdb-threads-mode ()
2469 "Major mode for gdb threads.
2470
2471 \\{gdb-threads-mode-map}"
2472 (kill-all-local-variables)
2473 (setq major-mode 'gdb-threads-mode)
2474 (setq mode-name "Threads")
2475 (setq buffer-read-only t)
2476 (buffer-disable-undo)
2477 (setq header-line-format gdb-breakpoints-header)
2478 (use-local-map gdb-threads-mode-map)
2479 (set (make-local-variable 'font-lock-defaults)
2480 '(gdb-threads-font-lock-keywords))
2481 (run-mode-hooks 'gdb-threads-mode-hook)
2482 ;; Force "info threads" onto queue.
2483 (lambda () (let ((gud-running nil)) (gdb-invalidate-threads))))
2484
2485 (defun gdb-get-thread-number ()
2486 (save-excursion
2487 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
2488 (match-string-no-properties 1)))
2489
2490 (defun gdb-threads-select (&optional event)
2491 "Select the thread and display the relevant source."
2492 (interactive (list last-input-event))
2493 (if event (posn-set-point (event-end event)))
2494 (gdb-enqueue-input
2495 (list (concat gdb-server-prefix "thread "
2496 (gdb-get-thread-number) "\n") 'ignore))
2497 (gud-display-frame))
2498
2499 (defun gdb-thread-identification ()
2500 (setq mode-line-buffer-identification
2501 (list (car mode-line-buffer-identification)
2502 '(gdb-thread-indicator gdb-thread-indicator))))
2503 \f
2504 ;; Registers buffer.
2505 ;;
2506 (defcustom gdb-all-registers nil
2507 "Non-nil means include floating-point registers."
2508 :type 'boolean
2509 :group 'gdb
2510 :version "22.1")
2511
2512 (gdb-set-buffer-rules 'gdb-registers-buffer
2513 'gdb-registers-buffer-name
2514 'gdb-registers-mode)
2515
2516 (def-gdb-auto-updated-buffer gdb-registers-buffer
2517 gdb-invalidate-registers
2518 (concat
2519 gdb-server-prefix "info " (if gdb-all-registers "all-") "registers\n")
2520 gdb-info-registers-handler
2521 gdb-info-registers-custom)
2522
2523 (defun gdb-info-registers-custom ()
2524 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2525 (save-excursion
2526 (let ((buffer-read-only nil)
2527 start end)
2528 (goto-char (point-min))
2529 (while (< (point) (point-max))
2530 (setq start (line-beginning-position))
2531 (setq end (line-end-position))
2532 (when (looking-at "^[^ ]+")
2533 (unless (string-equal (match-string 0) "The")
2534 (put-text-property start (match-end 0)
2535 'face font-lock-variable-name-face)
2536 (add-text-properties start end
2537 '(help-echo "mouse-2: edit value"
2538 mouse-face highlight))))
2539 (forward-line 1))))))
2540
2541 (defun gdb-edit-register-value (&optional event)
2542 (interactive (list last-input-event))
2543 (save-excursion
2544 (if event (posn-set-point (event-end event)))
2545 (beginning-of-line)
2546 (let* ((register (current-word))
2547 (value (read-string (format "New value (%s): " register))))
2548 (gdb-enqueue-input
2549 (list (concat gdb-server-prefix "set $" register "=" value "\n")
2550 'ignore)))))
2551
2552 (defvar gdb-registers-mode-map
2553 (let ((map (make-sparse-keymap)))
2554 (suppress-keymap map)
2555 (define-key map "\r" 'gdb-edit-register-value)
2556 (define-key map [mouse-2] 'gdb-edit-register-value)
2557 (define-key map " " 'gdb-all-registers)
2558 (define-key map "q" 'kill-this-buffer)
2559 map))
2560
2561 (defvar gdb-locals-header
2562 `(,(propertize "Locals"
2563 'help-echo "mouse-1: select"
2564 'mouse-face 'mode-line-highlight
2565 'face 'mode-line
2566 'local-map
2567 (gdb-make-header-line-mouse-map
2568 'mouse-1
2569 (lambda (event) (interactive "e")
2570 (save-selected-window
2571 (select-window (posn-window (event-start event)))
2572 (set-window-dedicated-p (selected-window) nil)
2573 (switch-to-buffer
2574 (gdb-get-buffer-create 'gdb-locals-buffer))
2575 (set-window-dedicated-p (selected-window) t)))))
2576 " "
2577 ,(propertize "Registers"
2578 'help-echo "mouse-1: select"
2579 'mouse-face 'mode-line-highlight
2580 'face 'mode-line
2581 'local-map
2582 (gdb-make-header-line-mouse-map
2583 'mouse-1
2584 (lambda (event) (interactive "e")
2585 (save-selected-window
2586 (select-window (posn-window (event-start event)))
2587 (set-window-dedicated-p (selected-window) nil)
2588 (switch-to-buffer
2589 (gdb-get-buffer-create 'gdb-registers-buffer))
2590 (set-window-dedicated-p (selected-window) t)))))))
2591
2592 (defun gdb-registers-mode ()
2593 "Major mode for gdb registers.
2594
2595 \\{gdb-registers-mode-map}"
2596 (kill-all-local-variables)
2597 (setq major-mode 'gdb-registers-mode)
2598 (setq mode-name "Registers")
2599 (setq header-line-format gdb-locals-header)
2600 (setq buffer-read-only t)
2601 (buffer-disable-undo)
2602 (gdb-thread-identification)
2603 (use-local-map gdb-registers-mode-map)
2604 (run-mode-hooks 'gdb-registers-mode-hook)
2605 (if (string-equal gdb-version "pre-6.4")
2606 (progn
2607 (if gdb-all-registers (setq mode-name "Registers:All"))
2608 'gdb-invalidate-registers)
2609 'gdb-invalidate-registers-1))
2610
2611 (defun gdb-registers-buffer-name ()
2612 (with-current-buffer gud-comint-buffer
2613 (concat "*registers of " (gdb-get-target-string) "*")))
2614
2615 (defun gdb-display-registers-buffer ()
2616 "Display integer register contents."
2617 (interactive)
2618 (gdb-display-buffer
2619 (gdb-get-buffer-create 'gdb-registers-buffer) t))
2620
2621 (defun gdb-frame-registers-buffer ()
2622 "Display integer register contents in a new frame."
2623 (interactive)
2624 (let ((special-display-regexps (append special-display-regexps '(".*")))
2625 (special-display-frame-alist gdb-frame-parameters))
2626 (display-buffer (gdb-get-buffer-create 'gdb-registers-buffer))))
2627
2628 (defun gdb-all-registers ()
2629 "Toggle the display of floating-point registers (pre GDB 6.4 only)."
2630 (interactive)
2631 (when (string-equal gdb-version "pre-6.4")
2632 (if gdb-all-registers
2633 (progn
2634 (setq gdb-all-registers nil)
2635 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2636 (setq mode-name "Registers")))
2637 (setq gdb-all-registers t)
2638 (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
2639 (setq mode-name "Registers:All")))
2640 (message (format "Display of floating-point registers %sabled"
2641 (if gdb-all-registers "en" "dis")))
2642 (gdb-invalidate-registers)))
2643 \f
2644
2645 ;; Memory buffer.
2646 ;;
2647 (defcustom gdb-memory-repeat-count 32
2648 "Number of data items in memory window."
2649 :type 'integer
2650 :group 'gdb
2651 :version "22.1")
2652
2653 (defcustom gdb-memory-format "x"
2654 "Display format of data items in memory window."
2655 :type '(choice (const :tag "Hexadecimal" "x")
2656 (const :tag "Signed decimal" "d")
2657 (const :tag "Unsigned decimal" "u")
2658 (const :tag "Octal" "o")
2659 (const :tag "Binary" "t"))
2660 :group 'gdb
2661 :version "22.1")
2662
2663 (defcustom gdb-memory-unit "w"
2664 "Unit size of data items in memory window."
2665 :type '(choice (const :tag "Byte" "b")
2666 (const :tag "Halfword" "h")
2667 (const :tag "Word" "w")
2668 (const :tag "Giant word" "g"))
2669 :group 'gdb
2670 :version "22.1")
2671
2672 (gdb-set-buffer-rules 'gdb-memory-buffer
2673 'gdb-memory-buffer-name
2674 'gdb-memory-mode)
2675
2676 (def-gdb-auto-updated-buffer gdb-memory-buffer
2677 gdb-invalidate-memory
2678 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
2679 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
2680 gdb-read-memory-handler
2681 gdb-read-memory-custom)
2682
2683 (defun gdb-read-memory-custom ()
2684 (save-excursion
2685 (goto-char (point-min))
2686 (if (looking-at "0x[[:xdigit:]]+")
2687 (setq gdb-memory-address (match-string 0)))))
2688
2689 (defvar gdb-memory-mode-map
2690 (let ((map (make-sparse-keymap)))
2691 (suppress-keymap map)
2692 (define-key map "q" 'kill-this-buffer)
2693 map))
2694
2695 (defun gdb-memory-set-address (event)
2696 "Set the start memory address."
2697 (interactive "e")
2698 (save-selected-window
2699 (select-window (posn-window (event-start event)))
2700 (let ((arg (read-from-minibuffer "Memory address: ")))
2701 (setq gdb-memory-address arg))
2702 (gdb-invalidate-memory)))
2703
2704 (defun gdb-memory-set-repeat-count (event)
2705 "Set the number of data items in memory window."
2706 (interactive "e")
2707 (save-selected-window
2708 (select-window (posn-window (event-start event)))
2709 (let* ((arg (read-from-minibuffer "Repeat count: "))
2710 (count (string-to-number arg)))
2711 (if (<= count 0)
2712 (error "Positive numbers only")
2713 (customize-set-variable 'gdb-memory-repeat-count count)
2714 (gdb-invalidate-memory)))))
2715
2716 (defun gdb-memory-format-binary ()
2717 "Set the display format to binary."
2718 (interactive)
2719 (customize-set-variable 'gdb-memory-format "t")
2720 (gdb-invalidate-memory))
2721
2722 (defun gdb-memory-format-octal ()
2723 "Set the display format to octal."
2724 (interactive)
2725 (customize-set-variable 'gdb-memory-format "o")
2726 (gdb-invalidate-memory))
2727
2728 (defun gdb-memory-format-unsigned ()
2729 "Set the display format to unsigned decimal."
2730 (interactive)
2731 (customize-set-variable 'gdb-memory-format "u")
2732 (gdb-invalidate-memory))
2733
2734 (defun gdb-memory-format-signed ()
2735 "Set the display format to decimal."
2736 (interactive)
2737 (customize-set-variable 'gdb-memory-format "d")
2738 (gdb-invalidate-memory))
2739
2740 (defun gdb-memory-format-hexadecimal ()
2741 "Set the display format to hexadecimal."
2742 (interactive)
2743 (customize-set-variable 'gdb-memory-format "x")
2744 (gdb-invalidate-memory))
2745
2746 (defvar gdb-memory-format-map
2747 (let ((map (make-sparse-keymap)))
2748 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2749 map)
2750 "Keymap to select format in the header line.")
2751
2752 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2753 "Menu of display formats in the header line.")
2754
2755 (define-key gdb-memory-format-menu [binary]
2756 '(menu-item "Binary" gdb-memory-format-binary
2757 :button (:radio . (equal gdb-memory-format "t"))))
2758 (define-key gdb-memory-format-menu [octal]
2759 '(menu-item "Octal" gdb-memory-format-octal
2760 :button (:radio . (equal gdb-memory-format "o"))))
2761 (define-key gdb-memory-format-menu [unsigned]
2762 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2763 :button (:radio . (equal gdb-memory-format "u"))))
2764 (define-key gdb-memory-format-menu [signed]
2765 '(menu-item "Signed Decimal" gdb-memory-format-signed
2766 :button (:radio . (equal gdb-memory-format "d"))))
2767 (define-key gdb-memory-format-menu [hexadecimal]
2768 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2769 :button (:radio . (equal gdb-memory-format "x"))))
2770
2771 (defun gdb-memory-format-menu (event)
2772 (interactive "@e")
2773 (x-popup-menu event gdb-memory-format-menu))
2774
2775 (defun gdb-memory-format-menu-1 (event)
2776 (interactive "e")
2777 (save-selected-window
2778 (select-window (posn-window (event-start event)))
2779 (let* ((selection (gdb-memory-format-menu event))
2780 (binding (and selection (lookup-key gdb-memory-format-menu
2781 (vector (car selection))))))
2782 (if binding (call-interactively binding)))))
2783
2784 (defun gdb-memory-unit-giant ()
2785 "Set the unit size to giant words (eight bytes)."
2786 (interactive)
2787 (customize-set-variable 'gdb-memory-unit "g")
2788 (gdb-invalidate-memory))
2789
2790 (defun gdb-memory-unit-word ()
2791 "Set the unit size to words (four bytes)."
2792 (interactive)
2793 (customize-set-variable 'gdb-memory-unit "w")
2794 (gdb-invalidate-memory))
2795
2796 (defun gdb-memory-unit-halfword ()
2797 "Set the unit size to halfwords (two bytes)."
2798 (interactive)
2799 (customize-set-variable 'gdb-memory-unit "h")
2800 (gdb-invalidate-memory))
2801
2802 (defun gdb-memory-unit-byte ()
2803 "Set the unit size to bytes."
2804 (interactive)
2805 (customize-set-variable 'gdb-memory-unit "b")
2806 (gdb-invalidate-memory))
2807
2808 (defvar gdb-memory-unit-map
2809 (let ((map (make-sparse-keymap)))
2810 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2811 map)
2812 "Keymap to select units in the header line.")
2813
2814 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2815 "Menu of units in the header line.")
2816
2817 (define-key gdb-memory-unit-menu [giantwords]
2818 '(menu-item "Giant words" gdb-memory-unit-giant
2819 :button (:radio . (equal gdb-memory-unit "g"))))
2820 (define-key gdb-memory-unit-menu [words]
2821 '(menu-item "Words" gdb-memory-unit-word
2822 :button (:radio . (equal gdb-memory-unit "w"))))
2823 (define-key gdb-memory-unit-menu [halfwords]
2824 '(menu-item "Halfwords" gdb-memory-unit-halfword
2825 :button (:radio . (equal gdb-memory-unit "h"))))
2826 (define-key gdb-memory-unit-menu [bytes]
2827 '(menu-item "Bytes" gdb-memory-unit-byte
2828 :button (:radio . (equal gdb-memory-unit "b"))))
2829
2830 (defun gdb-memory-unit-menu (event)
2831 (interactive "@e")
2832 (x-popup-menu event gdb-memory-unit-menu))
2833
2834 (defun gdb-memory-unit-menu-1 (event)
2835 (interactive "e")
2836 (save-selected-window
2837 (select-window (posn-window (event-start event)))
2838 (let* ((selection (gdb-memory-unit-menu event))
2839 (binding (and selection (lookup-key gdb-memory-unit-menu
2840 (vector (car selection))))))
2841 (if binding (call-interactively binding)))))
2842
2843 (defvar gdb-memory-font-lock-keywords
2844 '(;; <__function.name+n>
2845 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2846 )
2847 "Font lock keywords used in `gdb-memory-mode'.")
2848
2849 (defun gdb-memory-mode ()
2850 "Major mode for examining memory.
2851
2852 \\{gdb-memory-mode-map}"
2853 (kill-all-local-variables)
2854 (setq major-mode 'gdb-memory-mode)
2855 (setq mode-name "Memory")
2856 (setq buffer-read-only t)
2857 (buffer-disable-undo)
2858 (use-local-map gdb-memory-mode-map)
2859 (setq header-line-format
2860 '(:eval
2861 (concat
2862 "Read address["
2863 (propertize
2864 "-"
2865 'face font-lock-warning-face
2866 'help-echo "mouse-1: decrement address"
2867 'mouse-face 'mode-line-highlight
2868 'local-map
2869 (gdb-make-header-line-mouse-map
2870 'mouse-1
2871 (lambda () (interactive)
2872 (let ((gdb-memory-address
2873 ;; Let GDB do the arithmetic.
2874 (concat
2875 gdb-memory-address " - "
2876 (number-to-string
2877 (* gdb-memory-repeat-count
2878 (cond ((string= gdb-memory-unit "b") 1)
2879 ((string= gdb-memory-unit "h") 2)
2880 ((string= gdb-memory-unit "w") 4)
2881 ((string= gdb-memory-unit "g") 8)))))))
2882 (gdb-invalidate-memory)))))
2883 "|"
2884 (propertize "+"
2885 'face font-lock-warning-face
2886 'help-echo "mouse-1: increment address"
2887 'mouse-face 'mode-line-highlight
2888 'local-map (gdb-make-header-line-mouse-map
2889 'mouse-1
2890 (lambda () (interactive)
2891 (let ((gdb-memory-address nil))
2892 (gdb-invalidate-memory)))))
2893 "]: "
2894 (propertize gdb-memory-address
2895 'face font-lock-warning-face
2896 'help-echo "mouse-1: set memory address"
2897 'mouse-face 'mode-line-highlight
2898 'local-map (gdb-make-header-line-mouse-map
2899 'mouse-1
2900 #'gdb-memory-set-address))
2901 " Repeat Count: "
2902 (propertize (number-to-string gdb-memory-repeat-count)
2903 'face font-lock-warning-face
2904 'help-echo "mouse-1: set repeat count"
2905 'mouse-face 'mode-line-highlight
2906 'local-map (gdb-make-header-line-mouse-map
2907 'mouse-1
2908 #'gdb-memory-set-repeat-count))
2909 " Display Format: "
2910 (propertize gdb-memory-format
2911 'face font-lock-warning-face
2912 'help-echo "mouse-3: select display format"
2913 'mouse-face 'mode-line-highlight
2914 'local-map gdb-memory-format-map)
2915 " Unit Size: "
2916 (propertize gdb-memory-unit
2917 'face font-lock-warning-face
2918 'help-echo "mouse-3: select unit size"
2919 'mouse-face 'mode-line-highlight
2920 'local-map gdb-memory-unit-map))))
2921 (set (make-local-variable 'font-lock-defaults)
2922 '(gdb-memory-font-lock-keywords))
2923 (run-mode-hooks 'gdb-memory-mode-hook)
2924 'gdb-invalidate-memory)
2925
2926 (defun gdb-memory-buffer-name ()
2927 (with-current-buffer gud-comint-buffer
2928 (concat "*memory of " (gdb-get-target-string) "*")))
2929
2930 (defun gdb-display-memory-buffer ()
2931 "Display memory contents."
2932 (interactive)
2933 (gdb-display-buffer
2934 (gdb-get-buffer-create 'gdb-memory-buffer) t))
2935
2936 (defun gdb-frame-memory-buffer ()
2937 "Display memory contents in a new frame."
2938 (interactive)
2939 (let* ((special-display-regexps (append special-display-regexps '(".*")))
2940 (special-display-frame-alist
2941 (cons '(left-fringe . 0)
2942 (cons '(right-fringe . 0)
2943 (cons '(width . 83) gdb-frame-parameters)))))
2944 (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
2945 \f
2946
2947 ;; Locals buffer.
2948 ;;
2949 (gdb-set-buffer-rules 'gdb-locals-buffer
2950 'gdb-locals-buffer-name
2951 'gdb-locals-mode)
2952
2953 (def-gdb-auto-update-trigger gdb-invalidate-locals
2954 (gdb-get-buffer 'gdb-locals-buffer)
2955 "server info locals\n"
2956 gdb-info-locals-handler)
2957
2958 (defvar gdb-locals-watch-map
2959 (let ((map (make-sparse-keymap)))
2960 (suppress-keymap map)
2961 (define-key map "\r" (lambda () (interactive)
2962 (beginning-of-line)
2963 (gud-watch)))
2964 (define-key map [mouse-2] (lambda (event) (interactive "e")
2965 (mouse-set-point event)
2966 (beginning-of-line)
2967 (gud-watch)))
2968 map)
2969 "Keymap to create watch expression of a complex data type local variable.")
2970
2971 (defconst gdb-struct-string
2972 (concat (propertize "[struct/union]"
2973 'mouse-face 'highlight
2974 'help-echo "mouse-2: create watch expression"
2975 'local-map gdb-locals-watch-map) "\n"))
2976
2977 (defconst gdb-array-string
2978 (concat " " (propertize "[array]"
2979 'mouse-face 'highlight
2980 'help-echo "mouse-2: create watch expression"
2981 'local-map gdb-locals-watch-map) "\n"))
2982
2983 ;; Abbreviate for arrays and structures.
2984 ;; These can be expanded using gud-display.
2985 (defun gdb-info-locals-handler ()
2986 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2987 gdb-pending-triggers))
2988 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
2989 (with-current-buffer buf
2990 (goto-char (point-min))
2991 ;; Need this in case "set print pretty" is on.
2992 (while (re-search-forward "^[ }].*\n" nil t)
2993 (replace-match "" nil nil))
2994 (goto-char (point-min))
2995 (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
2996 (replace-match gdb-struct-string nil nil))
2997 (goto-char (point-min))
2998 (while (re-search-forward "\\s-*{[^.].*\n" nil t)
2999 (replace-match gdb-array-string nil nil))))
3000 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
3001 (and buf
3002 (with-current-buffer buf
3003 (let* ((window (get-buffer-window buf 0))
3004 (start (window-start window))
3005 (p (window-point window))
3006 (buffer-read-only nil))
3007 (erase-buffer)
3008 (insert-buffer-substring (gdb-get-buffer-create
3009 'gdb-partial-output-buffer))
3010 (set-window-start window start)
3011 (set-window-point window p)))))
3012 (run-hooks 'gdb-info-locals-hook))
3013
3014 (defvar gdb-locals-mode-map
3015 (let ((map (make-sparse-keymap)))
3016 (suppress-keymap map)
3017 (define-key map "q" 'kill-this-buffer)
3018 map))
3019
3020 (defun gdb-locals-mode ()
3021 "Major mode for gdb locals.
3022
3023 \\{gdb-locals-mode-map}"
3024 (kill-all-local-variables)
3025 (setq major-mode 'gdb-locals-mode)
3026 (setq mode-name (concat "Locals:" gdb-selected-frame))
3027 (use-local-map gdb-locals-mode-map)
3028 (setq buffer-read-only t)
3029 (buffer-disable-undo)
3030 (setq header-line-format gdb-locals-header)
3031 (gdb-thread-identification)
3032 (set (make-local-variable 'font-lock-defaults)
3033 '(gdb-locals-font-lock-keywords))
3034 (run-mode-hooks 'gdb-locals-mode-hook)
3035 (if (and (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3036 (string-equal gdb-version "pre-6.4"))
3037 'gdb-invalidate-locals
3038 'gdb-invalidate-locals-1))
3039
3040 (defun gdb-locals-buffer-name ()
3041 (with-current-buffer gud-comint-buffer
3042 (concat "*locals of " (gdb-get-target-string) "*")))
3043
3044 (defun gdb-display-locals-buffer ()
3045 "Display local variables of current stack and their values."
3046 (interactive)
3047 (gdb-display-buffer
3048 (gdb-get-buffer-create 'gdb-locals-buffer) t))
3049
3050 (defun gdb-frame-locals-buffer ()
3051 "Display local variables of current stack and their values in a new frame."
3052 (interactive)
3053 (let ((special-display-regexps (append special-display-regexps '(".*")))
3054 (special-display-frame-alist gdb-frame-parameters))
3055 (display-buffer (gdb-get-buffer-create 'gdb-locals-buffer))))
3056 \f
3057
3058 ;;;; Window management
3059 (defun gdb-display-buffer (buf dedicated &optional frame)
3060 (let ((answer (get-buffer-window buf (or frame 0)))
3061 (must-split nil))
3062 (if answer
3063 (display-buffer buf nil (or frame 0)) ;Deiconify the frame if necessary.
3064 (if (get-buffer-window gud-comint-buffer)
3065 (select-window (get-buffer-window gud-comint-buffer))
3066 ;; If the buffer is not yet displayed, select the right frame.
3067 (pop-to-buffer gud-comint-buffer))
3068 (let ((window (get-lru-window)))
3069 (if (and window
3070 (not (memq window `(,(get-buffer-window gud-comint-buffer)
3071 ,gdb-source-window))))
3072 (progn
3073 (set-window-buffer window buf)
3074 (setq answer window))
3075 (setq must-split t)))
3076 (if must-split
3077 (let* ((largest (get-largest-window))
3078 (cur-size (window-height largest)))
3079 (setq answer (split-window largest))
3080 (set-window-buffer answer buf)
3081 (set-window-dedicated-p answer dedicated)))
3082 answer)))
3083
3084 \f
3085 ;;; Shared keymap initialization:
3086
3087 (let ((menu (make-sparse-keymap "GDB-Windows")))
3088 (define-key gud-menu-map [displays]
3089 `(menu-item "GDB-Windows" ,menu
3090 :help "Open a GDB-UI buffer in a new window."
3091 :visible (memq gud-minor-mode '(gdbmi gdba))))
3092 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
3093 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
3094 (define-key menu [inferior]
3095 '(menu-item "Separate IO" gdb-display-separate-io-buffer
3096 :enable gdb-use-separate-io-buffer))
3097 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
3098 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
3099 (define-key menu [disassembly]
3100 '("Disassembly" . gdb-display-assembler-buffer))
3101 (define-key menu [breakpoints]
3102 '("Breakpoints" . gdb-display-breakpoints-buffer))
3103 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
3104 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)))
3105
3106 (let ((menu (make-sparse-keymap "GDB-Frames")))
3107 (define-key gud-menu-map [frames]
3108 `(menu-item "GDB-Frames" ,menu
3109 :help "Open a GDB-UI buffer in a new frame."
3110 :visible (memq gud-minor-mode '(gdbmi gdba))))
3111 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
3112 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
3113 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
3114 (define-key menu [inferior]
3115 '(menu-item "Separate IO" gdb-frame-separate-io-buffer
3116 :enable gdb-use-separate-io-buffer))
3117 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
3118 (define-key menu [disassembly] '("Disassembly" . gdb-frame-assembler-buffer))
3119 (define-key menu [breakpoints]
3120 '("Breakpoints" . gdb-frame-breakpoints-buffer))
3121 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
3122 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)))
3123
3124 (let ((menu (make-sparse-keymap "GDB-UI/MI")))
3125 (define-key gud-menu-map [ui]
3126 `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
3127 ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
3128 (define-key menu [gdb-customize]
3129 '(menu-item "Customize" (lambda () (interactive) (customize-group 'gdb))
3130 :help "Customize Gdb Graphical Mode options."))
3131 (define-key menu [gdb-find-source-frame]
3132 '(menu-item "Look For Source Frame" gdb-find-source-frame
3133 :visible (eq gud-minor-mode 'gdba)
3134 :help "Toggle looking for source frame further up call stack."
3135 :button (:toggle . gdb-find-source-frame)))
3136 (define-key menu [gdb-use-separate-io]
3137 '(menu-item "Separate IO" gdb-use-separate-io-buffer
3138 :visible (eq gud-minor-mode 'gdba)
3139 :help "Toggle separate IO for debugged program."
3140 :button (:toggle . gdb-use-separate-io-buffer)))
3141 (define-key menu [gdb-many-windows]
3142 '(menu-item "Display Other Windows" gdb-many-windows
3143 :help "Toggle display of locals, stack and breakpoint information"
3144 :button (:toggle . gdb-many-windows)))
3145 (define-key menu [gdb-restore-windows]
3146 '(menu-item "Restore Window Layout" gdb-restore-windows
3147 :help "Restore standard layout for debug session.")))
3148
3149 (defun gdb-frame-gdb-buffer ()
3150 "Display GUD buffer in a new frame."
3151 (interactive)
3152 (let ((special-display-regexps (append special-display-regexps '(".*")))
3153 (special-display-frame-alist
3154 (remove '(menu-bar-lines) (remove '(tool-bar-lines)
3155 gdb-frame-parameters)))
3156 (same-window-regexps nil))
3157 (display-buffer gud-comint-buffer)))
3158
3159 (defun gdb-display-gdb-buffer ()
3160 "Display GUD buffer."
3161 (interactive)
3162 (let ((same-window-regexps nil))
3163 (pop-to-buffer gud-comint-buffer)))
3164
3165 (defun gdb-set-window-buffer (name)
3166 (set-window-buffer (selected-window) (get-buffer name))
3167 (set-window-dedicated-p (selected-window) t))
3168
3169 (defun gdb-setup-windows ()
3170 "Layout the window pattern for `gdb-many-windows'."
3171 (gdb-display-locals-buffer)
3172 (gdb-display-stack-buffer)
3173 (delete-other-windows)
3174 (gdb-display-breakpoints-buffer)
3175 (delete-other-windows)
3176 ; Don't dedicate.
3177 (pop-to-buffer gud-comint-buffer)
3178 (split-window nil ( / ( * (window-height) 3) 4))
3179 (split-window nil ( / (window-height) 3))
3180 (split-window-horizontally)
3181 (other-window 1)
3182 (gdb-set-window-buffer (gdb-locals-buffer-name))
3183 (other-window 1)
3184 (switch-to-buffer
3185 (if gud-last-last-frame
3186 (gud-find-file (car gud-last-last-frame))
3187 (if gdb-main-file
3188 (gud-find-file gdb-main-file)
3189 ;; Put buffer list in window if we
3190 ;; can't find a source file.
3191 (list-buffers-noselect))))
3192 (setq gdb-source-window (selected-window))
3193 (when gdb-use-separate-io-buffer
3194 (split-window-horizontally)
3195 (other-window 1)
3196 (gdb-set-window-buffer
3197 (gdb-get-buffer-create 'gdb-inferior-io)))
3198 (other-window 1)
3199 (gdb-set-window-buffer (gdb-stack-buffer-name))
3200 (split-window-horizontally)
3201 (other-window 1)
3202 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
3203 (other-window 1))
3204
3205 (defun gdb-restore-windows ()
3206 "Restore the basic arrangement of windows used by gdba.
3207 This arrangement depends on the value of `gdb-many-windows'."
3208 (interactive)
3209 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
3210 (delete-other-windows)
3211 (if gdb-many-windows
3212 (gdb-setup-windows)
3213 (when (or gud-last-last-frame gdb-show-main)
3214 (split-window)
3215 (other-window 1)
3216 (switch-to-buffer
3217 (if gud-last-last-frame
3218 (gud-find-file (car gud-last-last-frame))
3219 (gud-find-file gdb-main-file)))
3220 (setq gdb-source-window (selected-window))
3221 (other-window 1))))
3222
3223 (defun gdb-reset ()
3224 "Exit a debugging session cleanly.
3225 Kills the gdb buffers, and resets variables and the source buffers."
3226 (dolist (buffer (buffer-list))
3227 (unless (eq buffer gud-comint-buffer)
3228 (with-current-buffer buffer
3229 (if (memq gud-minor-mode '(gdbmi gdba))
3230 (if (string-match "\\` ?\\*.+\\*\\'" (buffer-name))
3231 (kill-buffer nil)
3232 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
3233 (setq gud-minor-mode nil)
3234 (kill-local-variable 'tool-bar-map)
3235 (kill-local-variable 'gdb-define-alist))))))
3236 (setq gdb-overlay-arrow-position nil)
3237 (setq overlay-arrow-variable-list
3238 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
3239 (setq fringe-indicator-alist '((overlay-arrow . right-triangle)))
3240 (setq gdb-stack-position nil)
3241 (setq overlay-arrow-variable-list
3242 (delq 'gdb-stack-position overlay-arrow-variable-list))
3243 (if (boundp 'speedbar-frame) (speedbar-timer-fn))
3244 (setq gud-running nil)
3245 (setq gdb-active-process nil)
3246 (setq gdb-var-list nil)
3247 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
3248
3249 (defun gdb-source-info ()
3250 "Find the source file where the program starts and displays it with related
3251 buffers."
3252 (goto-char (point-min))
3253 (if (and (search-forward "Located in " nil t)
3254 (looking-at "\\S-+"))
3255 (setq gdb-main-file (match-string 0)))
3256 (goto-char (point-min))
3257 (if (search-forward "Includes preprocessor macro info." nil t)
3258 (setq gdb-macro-info t))
3259 (if gdb-many-windows
3260 (gdb-setup-windows)
3261 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
3262 (if gdb-show-main
3263 (let ((pop-up-windows t))
3264 (display-buffer (gud-find-file gdb-main-file)))))
3265 (setq gdb-ready t))
3266
3267 (defun gdb-get-location (bptno line flag)
3268 "Find the directory containing the relevant source file.
3269 Put in buffer and place breakpoint icon."
3270 (goto-char (point-min))
3271 (catch 'file-not-found
3272 (if (search-forward "Located in " nil t)
3273 (when (looking-at "\\S-+")
3274 (delete (cons bptno "File not found") gdb-location-alist)
3275 (push (cons bptno (match-string 0)) gdb-location-alist))
3276 (gdb-resync)
3277 (unless (assoc bptno gdb-location-alist)
3278 (push (cons bptno "File not found") gdb-location-alist)
3279 (message-box "Cannot find source file for breakpoint location.\n\
3280 Add directory to search path for source files using the GDB command, dir."))
3281 (throw 'file-not-found nil))
3282 (with-current-buffer
3283 (find-file-noselect (match-string 0))
3284 (gdb-init-buffer)
3285 ;; only want one breakpoint icon at each location
3286 (save-excursion
3287 (goto-line (string-to-number line))
3288 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
3289
3290 (add-hook 'find-file-hook 'gdb-find-file-hook)
3291
3292 (defun gdb-find-file-hook ()
3293 "Set up buffer for debugging if file is part of the source code
3294 of the current session."
3295 (if (and (buffer-name gud-comint-buffer)
3296 ;; in case gud or gdb-ui is just loaded
3297 gud-comint-buffer
3298 (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
3299 '(gdba gdbmi)))
3300 ;;Pre GDB 6.3 "info sources" doesn't give absolute file name.
3301 (if (member (if (string-equal gdb-version "pre-6.4")
3302 (file-name-nondirectory buffer-file-name)
3303 buffer-file-name)
3304 gdb-source-file-list)
3305 (with-current-buffer (find-buffer-visiting buffer-file-name)
3306 (gdb-init-buffer)))))
3307
3308 ;;from put-image
3309 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
3310 "Put string PUTSTRING in front of POS in the current buffer.
3311 PUTSTRING is displayed by putting an overlay into the current buffer with a
3312 `before-string' string that has a `display' property whose value is
3313 PUTSTRING."
3314 (let ((string (make-string 1 ?x))
3315 (buffer (current-buffer)))
3316 (setq putstring (copy-sequence putstring))
3317 (let ((overlay (make-overlay pos pos buffer))
3318 (prop (or dprop
3319 (list (list 'margin 'left-margin) putstring))))
3320 (put-text-property 0 1 'display prop string)
3321 (if sprops
3322 (add-text-properties 0 1 sprops string))
3323 (overlay-put overlay 'put-break t)
3324 (overlay-put overlay 'before-string string))))
3325
3326 ;;from remove-images
3327 (defun gdb-remove-strings (start end &optional buffer)
3328 "Remove strings between START and END in BUFFER.
3329 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
3330 BUFFER nil or omitted means use the current buffer."
3331 (unless buffer
3332 (setq buffer (current-buffer)))
3333 (dolist (overlay (overlays-in start end))
3334 (when (overlay-get overlay 'put-break)
3335 (delete-overlay overlay))))
3336
3337 (defun gdb-put-breakpoint-icon (enabled bptno)
3338 (if (string-match "[0-9+]+\\." bptno)
3339 (setq enabled gdb-parent-bptno-enabled))
3340 (let ((start (- (line-beginning-position) 1))
3341 (end (+ (line-end-position) 1))
3342 (putstring (if enabled "B" "b"))
3343 (source-window (get-buffer-window (current-buffer) 0)))
3344 (add-text-properties
3345 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
3346 putstring)
3347 (if enabled
3348 (add-text-properties
3349 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
3350 (add-text-properties
3351 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
3352 (gdb-remove-breakpoint-icons start end)
3353 (if (display-images-p)
3354 (if (>= (or left-fringe-width
3355 (if source-window (car (window-fringes source-window)))
3356 gdb-buffer-fringe-width) 8)
3357 (gdb-put-string
3358 nil (1+ start)
3359 `(left-fringe breakpoint
3360 ,(if enabled
3361 'breakpoint-enabled
3362 'breakpoint-disabled))
3363 'gdb-bptno bptno
3364 'gdb-enabled enabled)
3365 (when (< left-margin-width 2)
3366 (save-current-buffer
3367 (setq left-margin-width 2)
3368 (if source-window
3369 (set-window-margins
3370 source-window
3371 left-margin-width right-margin-width))))
3372 (put-image
3373 (if enabled
3374 (or breakpoint-enabled-icon
3375 (setq breakpoint-enabled-icon
3376 (find-image `((:type xpm :data
3377 ,breakpoint-xpm-data
3378 :ascent 100 :pointer hand)
3379 (:type pbm :data
3380 ,breakpoint-enabled-pbm-data
3381 :ascent 100 :pointer hand)))))
3382 (or breakpoint-disabled-icon
3383 (setq breakpoint-disabled-icon
3384 (find-image `((:type xpm :data
3385 ,breakpoint-xpm-data
3386 :conversion disabled
3387 :ascent 100 :pointer hand)
3388 (:type pbm :data
3389 ,breakpoint-disabled-pbm-data
3390 :ascent 100 :pointer hand))))))
3391 (+ start 1)
3392 putstring
3393 'left-margin))
3394 (when (< left-margin-width 2)
3395 (save-current-buffer
3396 (setq left-margin-width 2)
3397 (let ((window (get-buffer-window (current-buffer) 0)))
3398 (if window
3399 (set-window-margins
3400 window left-margin-width right-margin-width)))))
3401 (gdb-put-string
3402 (propertize putstring
3403 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
3404 (1+ start)))))
3405
3406 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
3407 (gdb-remove-strings start end)
3408 (if (display-images-p)
3409 (remove-images start end))
3410 (when remove-margin
3411 (setq left-margin-width 0)
3412 (let ((window (get-buffer-window (current-buffer) 0)))
3413 (if window
3414 (set-window-margins
3415 window left-margin-width right-margin-width)))))
3416
3417 \f
3418 ;;
3419 ;; Assembler buffer.
3420 ;;
3421 (gdb-set-buffer-rules 'gdb-assembler-buffer
3422 'gdb-assembler-buffer-name
3423 'gdb-assembler-mode)
3424
3425 ;; We can't use def-gdb-auto-update-handler because we don't want to use
3426 ;; window-start but keep the overlay arrow/current line visible.
3427 (defun gdb-assembler-handler ()
3428 (setq gdb-pending-triggers
3429 (delq 'gdb-invalidate-assembler
3430 gdb-pending-triggers))
3431 (let ((buf (gdb-get-buffer 'gdb-assembler-buffer)))
3432 (and buf
3433 (with-current-buffer buf
3434 (let* ((window (get-buffer-window buf 0))
3435 (p (window-point window))
3436 (buffer-read-only nil))
3437 (erase-buffer)
3438 (insert-buffer-substring (gdb-get-buffer-create
3439 'gdb-partial-output-buffer))
3440 (set-window-point window p)))))
3441 ;; put customisation here
3442 (gdb-assembler-custom))
3443
3444 (defun gdb-assembler-custom ()
3445 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
3446 (pos 1) (address) (flag) (bptno))
3447 (with-current-buffer buffer
3448 (save-excursion
3449 (if (not (equal gdb-pc-address "main"))
3450 (progn
3451 (goto-char (point-min))
3452 (if (and gdb-pc-address
3453 (search-forward gdb-pc-address nil t))
3454 (progn
3455 (setq pos (point))
3456 (beginning-of-line)
3457 (setq fringe-indicator-alist
3458 (if (string-equal gdb-frame-number "0")
3459 nil
3460 '((overlay-arrow . hollow-right-triangle))))
3461 (or gdb-overlay-arrow-position
3462 (setq gdb-overlay-arrow-position (make-marker)))
3463 (set-marker gdb-overlay-arrow-position (point))))))
3464 ;; remove all breakpoint-icons in assembler buffer before updating.
3465 (gdb-remove-breakpoint-icons (point-min) (point-max))))
3466 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
3467 (goto-char (point-min))
3468 (while (< (point) (- (point-max) 1))
3469 (forward-line 1)
3470 (when (looking-at
3471 "\\([0-9]+\\.?[0-9]*\\).*?\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
3472 (setq bptno (match-string 1))
3473 (setq flag (char-after (match-beginning 2)))
3474 (setq address (match-string 3))
3475 (with-current-buffer buffer
3476 (save-excursion
3477 (goto-char (point-min))
3478 (if (search-forward address nil t)
3479 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))))
3480 (if (not (equal gdb-pc-address "main"))
3481 (with-current-buffer buffer
3482 (set-window-point (get-buffer-window buffer 0) pos)))))
3483
3484 (defvar gdb-assembler-mode-map
3485 (let ((map (make-sparse-keymap)))
3486 (suppress-keymap map)
3487 (define-key map "q" 'kill-this-buffer)
3488 map))
3489
3490 (defvar gdb-assembler-font-lock-keywords
3491 '(;; <__function.name+n>
3492 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
3493 (1 font-lock-function-name-face))
3494 ;; 0xNNNNNNNN <__function.name+n>: opcode
3495 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
3496 (4 font-lock-keyword-face))
3497 ;; %register(at least i386)
3498 ("%\\sw+" . font-lock-variable-name-face)
3499 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
3500 (1 font-lock-comment-face)
3501 (2 font-lock-function-name-face))
3502 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
3503 "Font lock keywords used in `gdb-assembler-mode'.")
3504
3505 (defun gdb-assembler-mode ()
3506 "Major mode for viewing code assembler.
3507
3508 \\{gdb-assembler-mode-map}"
3509 (kill-all-local-variables)
3510 (setq major-mode 'gdb-assembler-mode)
3511 (setq mode-name (concat "Machine:" gdb-selected-frame))
3512 (setq gdb-overlay-arrow-position nil)
3513 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
3514 (setq fringes-outside-margins t)
3515 (setq buffer-read-only t)
3516 (buffer-disable-undo)
3517 (gdb-thread-identification)
3518 (use-local-map gdb-assembler-mode-map)
3519 (gdb-invalidate-assembler)
3520 (set (make-local-variable 'font-lock-defaults)
3521 '(gdb-assembler-font-lock-keywords))
3522 (run-mode-hooks 'gdb-assembler-mode-hook)
3523 'gdb-invalidate-assembler)
3524
3525 (defun gdb-assembler-buffer-name ()
3526 (with-current-buffer gud-comint-buffer
3527 (concat "*disassembly of " (gdb-get-target-string) "*")))
3528
3529 (defun gdb-display-assembler-buffer ()
3530 "Display disassembly view."
3531 (interactive)
3532 (setq gdb-previous-frame nil)
3533 (gdb-display-buffer
3534 (gdb-get-buffer-create 'gdb-assembler-buffer) t))
3535
3536 (defun gdb-frame-assembler-buffer ()
3537 "Display disassembly view in a new frame."
3538 (interactive)
3539 (setq gdb-previous-frame nil)
3540 (let ((special-display-regexps (append special-display-regexps '(".*")))
3541 (special-display-frame-alist gdb-frame-parameters))
3542 (display-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))))
3543
3544 ;; modified because if gdb-pc-address has changed value a new command
3545 ;; must be enqueued to update the buffer with the new output
3546 (defun gdb-invalidate-assembler (&optional ignored)
3547 (if (gdb-get-buffer 'gdb-assembler-buffer)
3548 (progn
3549 (unless (and gdb-selected-frame
3550 (string-equal gdb-selected-frame gdb-previous-frame))
3551 (if (or (not (member 'gdb-invalidate-assembler
3552 gdb-pending-triggers))
3553 (not (equal (string-to-number gdb-pc-address)
3554 (string-to-number
3555 gdb-previous-frame-pc-address))))
3556 (progn
3557 ;; take previous disassemble command, if any, off the queue
3558 (with-current-buffer gud-comint-buffer
3559 (let ((queue gdb-input-queue))
3560 (dolist (item queue)
3561 (if (equal (cdr item) '(gdb-assembler-handler))
3562 (setq gdb-input-queue
3563 (delete item gdb-input-queue))))))
3564 (gdb-enqueue-input
3565 (list
3566 (concat gdb-server-prefix "disassemble " gdb-pc-address "\n")
3567 'gdb-assembler-handler))
3568 (push 'gdb-invalidate-assembler gdb-pending-triggers)
3569 (setq gdb-previous-frame-pc-address gdb-pc-address)
3570 (setq gdb-previous-frame gdb-selected-frame)))))))
3571
3572 (defun gdb-get-selected-frame ()
3573 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
3574 (progn
3575 (if (string-equal gdb-version "pre-6.4")
3576 (gdb-enqueue-input
3577 (list (concat gdb-server-prefix "info frame\n")
3578 'gdb-frame-handler))
3579 (gdb-enqueue-input
3580 (list "server interpreter mi -stack-info-frame\n"
3581 'gdb-frame-handler-1)))
3582 (push 'gdb-get-selected-frame gdb-pending-triggers))))
3583
3584 (defun gdb-frame-handler ()
3585 (setq gdb-pending-triggers
3586 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3587 (goto-char (point-min))
3588 (when (re-search-forward
3589 "Stack level \\([0-9]+\\), frame at \\(0x[[:xdigit:]]+\\)" nil t)
3590 (setq gdb-frame-number (match-string 1))
3591 (setq gdb-frame-address (match-string 2)))
3592 (goto-char (point-min))
3593 (when (re-search-forward ".*=\\s-+\\(\\S-*\\)\\s-+in\\s-+\\(.*?\\)\
3594 \\(?: (\\(\\S-+?\\):[0-9]+?)\\)*; "
3595 nil t)
3596 (setq gdb-selected-frame (match-string 2))
3597 (if (gdb-get-buffer 'gdb-locals-buffer)
3598 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3599 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3600 (if (gdb-get-buffer 'gdb-assembler-buffer)
3601 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3602 (setq mode-name (concat "Machine:" gdb-selected-frame))))
3603 (setq gdb-pc-address (match-string 1))
3604 (if (and (match-string 3) gud-overlay-arrow-position)
3605 (let ((buffer (marker-buffer gud-overlay-arrow-position))
3606 (position (marker-position gud-overlay-arrow-position)))
3607 (when (and buffer
3608 (string-equal (file-name-nondirectory
3609 (buffer-file-name buffer))
3610 (file-name-nondirectory (match-string 3))))
3611 (with-current-buffer buffer
3612 (setq fringe-indicator-alist
3613 (if (string-equal gdb-frame-number "0")
3614 nil
3615 '((overlay-arrow . hollow-right-triangle))))
3616 (set-marker gud-overlay-arrow-position position))))))
3617 (goto-char (point-min))
3618 (if (re-search-forward " source language \\(\\S-+\\)\." nil t)
3619 (setq gdb-current-language (match-string 1)))
3620 (gdb-invalidate-assembler))
3621
3622 \f
3623 ;; Code specific to GDB 6.4
3624 (defconst gdb-source-file-regexp-1 "fullname=\"\\(.*?\\)\"")
3625
3626 (defun gdb-set-gud-minor-mode-existing-buffers-1 ()
3627 "Create list of source files for current GDB session.
3628 If buffers already exist for any of these files, `gud-minor-mode'
3629 is set in them."
3630 (goto-char (point-min))
3631 (while (re-search-forward gdb-source-file-regexp-1 nil t)
3632 (push (match-string 1) gdb-source-file-list))
3633 (dolist (buffer (buffer-list))
3634 (with-current-buffer buffer
3635 (when (member buffer-file-name gdb-source-file-list)
3636 (gdb-init-buffer))))
3637 (gdb-force-mode-line-update
3638 (propertize "ready" 'face font-lock-variable-name-face)))
3639
3640 ;; Used for -stack-info-frame but could be used for -stack-list-frames too.
3641 (defconst gdb-stack-list-frames-regexp
3642 ".*?level=\"\\(.*?\\)\",.*?addr=\"\\(.*?\\)\",.*?func=\"\\(.*?\\)\",\
3643 \\(?:.*?file=\".*?\",.*?fullname=\"\\(.*?\\)\",.*?line=\"\\(.*?\\)\".*?}\\|\
3644 from=\"\\(.*?\\)\"\\)")
3645
3646 (defun gdb-frame-handler-1 ()
3647 (setq gdb-pending-triggers
3648 (delq 'gdb-get-selected-frame gdb-pending-triggers))
3649 (goto-char (point-min))
3650 (when (re-search-forward gdb-stack-list-frames-regexp nil t)
3651 (setq gdb-frame-number (match-string 1))
3652 (setq gdb-pc-address (match-string 2))
3653 (setq gdb-selected-frame (match-string 3))
3654 (if (gdb-get-buffer 'gdb-locals-buffer)
3655 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3656 (setq mode-name (concat "Locals:" gdb-selected-frame))))
3657 (if (gdb-get-buffer 'gdb-assembler-buffer)
3658 (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
3659 (setq mode-name (concat "Machine:" gdb-selected-frame)))))
3660 (gdb-invalidate-assembler))
3661
3662 ; Uses "-var-list-children --all-values". Needs GDB 6.4 onwards.
3663 (defun gdb-var-list-children-1 (varnum)
3664 (gdb-enqueue-input
3665 (list
3666 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3667 (concat "server interpreter mi \"-var-list-children --all-values \\\""
3668 varnum "\\\"\"\n")
3669 (concat "-var-list-children --all-values \"" varnum "\"\n"))
3670 `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
3671
3672 (defconst gdb-var-list-children-regexp-1
3673 "child={.*?name=\"\\(.+?\\)\",.*?exp=\"\\(.+?\\)\",.*?\
3674 numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\)\
3675 \\(}\\|,.*?\\(type=\"\\(.+?\\)\"\\)?.*?}\\)")
3676
3677 (defun gdb-var-list-children-handler-1 (varnum)
3678 (goto-char (point-min))
3679 (let ((var-list nil))
3680 (catch 'child-already-watched
3681 (dolist (var gdb-var-list)
3682 (if (string-equal varnum (car var))
3683 (progn
3684 (push var var-list)
3685 (while (re-search-forward gdb-var-list-children-regexp-1 nil t)
3686 (let ((varchild (list (match-string 1)
3687 (match-string 2)
3688 (match-string 3)
3689 (match-string 7)
3690 (read (match-string 4))
3691 nil)))
3692 (if (assoc (car varchild) gdb-var-list)
3693 (throw 'child-already-watched nil))
3694 (push varchild var-list))))
3695 (push var var-list)))
3696 (setq gdb-var-list (nreverse var-list))))
3697 (gdb-speedbar-update))
3698
3699 ; Uses "-var-update --all-values". Needs GDB 6.4 onwards.
3700 (defun gdb-var-update-1 ()
3701 (if (not (member 'gdb-var-update gdb-pending-triggers))
3702 (progn
3703 (gdb-enqueue-input
3704 (list
3705 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3706 "server interpreter mi \"-var-update --all-values *\"\n"
3707 "-var-update --all-values *\n")
3708 'gdb-var-update-handler-1))
3709 (push 'gdb-var-update gdb-pending-triggers))))
3710
3711 (defconst gdb-var-update-regexp-1
3712 "{.*?name=\"\\(.*?\\)\",.*?\\(?:value=\\(\".*?\"\\),\\)?.*?\
3713 in_scope=\"\\(.*?\\)\".*?}")
3714
3715 (defun gdb-var-update-handler-1 ()
3716 (dolist (var gdb-var-list)
3717 (setcar (nthcdr 5 var) nil))
3718 (goto-char (point-min))
3719 (while (re-search-forward gdb-var-update-regexp-1 nil t)
3720 (let* ((varnum (match-string 1))
3721 (var (assoc varnum gdb-var-list)))
3722 (when var
3723 (let ((match (match-string 3)))
3724 (cond ((string-equal match "false")
3725 (if gdb-delete-out-of-scope
3726 (gdb-var-delete-1 varnum)
3727 (setcar (nthcdr 5 var) 'out-of-scope)))
3728 ((string-equal match "true")
3729 (setcar (nthcdr 5 var) 'changed)
3730 (setcar (nthcdr 4 var)
3731 (read (match-string 2))))
3732 ((string-equal match "invalid")
3733 (gdb-var-delete-1 varnum)))))))
3734 (setq gdb-pending-triggers
3735 (delq 'gdb-var-update gdb-pending-triggers))
3736 (gdb-speedbar-update))
3737
3738 ;; Registers buffer.
3739 ;;
3740 (gdb-set-buffer-rules 'gdb-registers-buffer
3741 'gdb-registers-buffer-name
3742 'gdb-registers-mode)
3743
3744 (def-gdb-auto-update-trigger gdb-invalidate-registers-1
3745 (gdb-get-buffer 'gdb-registers-buffer)
3746 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3747 "server interpreter mi \"-data-list-register-values x\"\n"
3748 "-data-list-register-values x\n")
3749 gdb-data-list-register-values-handler)
3750
3751 (defconst gdb-data-list-register-values-regexp
3752 "{.*?number=\"\\(.*?\\)\",.*?value=\"\\(.*?\\)\".*?}")
3753
3754 (defun gdb-data-list-register-values-handler ()
3755 (setq gdb-pending-triggers (delq 'gdb-invalidate-registers-1
3756 gdb-pending-triggers))
3757 (goto-char (point-min))
3758 (if (re-search-forward gdb-error-regexp nil t)
3759 (let ((err (match-string 1)))
3760 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3761 (let ((buffer-read-only nil))
3762 (erase-buffer)
3763 (put-text-property 0 (length err) 'face font-lock-warning-face err)
3764 (insert err)
3765 (goto-char (point-min)))))
3766 (let ((register-list (reverse gdb-register-names))
3767 (register nil) (register-string nil) (register-values nil))
3768 (goto-char (point-min))
3769 (while (re-search-forward gdb-data-list-register-values-regexp nil t)
3770 (setq register (pop register-list))
3771 (setq register-string (concat register "\t" (match-string 2) "\n"))
3772 (if (member (match-string 1) gdb-changed-registers)
3773 (put-text-property 0 (length register-string)
3774 'face 'font-lock-warning-face
3775 register-string))
3776 (setq register-values
3777 (concat register-values register-string)))
3778 (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
3779 (with-current-buffer buf
3780 (let* ((window (get-buffer-window buf 0))
3781 (start (window-start window))
3782 (p (window-point window))
3783 (buffer-read-only nil))
3784 (erase-buffer)
3785 (insert register-values)
3786 (set-window-start window start)
3787 (set-window-point window p))))))
3788 (gdb-data-list-register-values-custom))
3789
3790 (defun gdb-data-list-register-values-custom ()
3791 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
3792 (save-excursion
3793 (let ((buffer-read-only nil)
3794 start end)
3795 (goto-char (point-min))
3796 (while (< (point) (point-max))
3797 (setq start (line-beginning-position))
3798 (setq end (line-end-position))
3799 (when (looking-at "^[^\t]+")
3800 (unless (string-equal (match-string 0) "No registers.")
3801 (put-text-property start (match-end 0)
3802 'face font-lock-variable-name-face)
3803 (add-text-properties start end
3804 '(help-echo "mouse-2: edit value"
3805 mouse-face highlight))))
3806 (forward-line 1))))))
3807
3808 ;; Needs GDB 6.4 onwards (used to fail with no stack).
3809 (defun gdb-get-changed-registers ()
3810 (if (and (gdb-get-buffer 'gdb-registers-buffer)
3811 (not (member 'gdb-get-changed-registers gdb-pending-triggers)))
3812 (progn
3813 (gdb-enqueue-input
3814 (list
3815 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3816 "server interpreter mi -data-list-changed-registers\n"
3817 "-data-list-changed-registers\n")
3818 'gdb-get-changed-registers-handler))
3819 (push 'gdb-get-changed-registers gdb-pending-triggers))))
3820
3821 (defconst gdb-data-list-register-names-regexp "\"\\(.*?\\)\"")
3822
3823 (defun gdb-get-changed-registers-handler ()
3824 (setq gdb-pending-triggers
3825 (delq 'gdb-get-changed-registers gdb-pending-triggers))
3826 (setq gdb-changed-registers nil)
3827 (goto-char (point-min))
3828 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3829 (push (match-string 1) gdb-changed-registers)))
3830 \f
3831
3832 ;; Locals buffer.
3833 ;;
3834 ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards.
3835 (gdb-set-buffer-rules 'gdb-locals-buffer
3836 'gdb-locals-buffer-name
3837 'gdb-locals-mode)
3838
3839 (def-gdb-auto-update-trigger gdb-invalidate-locals-1
3840 (gdb-get-buffer 'gdb-locals-buffer)
3841 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
3842 "server interpreter mi -\"stack-list-locals --simple-values\"\n"
3843 "-stack-list-locals --simple-values\n")
3844 gdb-stack-list-locals-handler)
3845
3846 (defconst gdb-stack-list-locals-regexp
3847 "{.*?name=\"\\(.*?\\)\",.*?type=\"\\(.*?\\)\"")
3848
3849 (defvar gdb-locals-watch-map-1
3850 (let ((map (make-sparse-keymap)))
3851 (suppress-keymap map)
3852 (define-key map "\r" 'gud-watch)
3853 (define-key map [mouse-2] 'gud-watch)
3854 map)
3855 "Keymap to create watch expression of a complex data type local variable.")
3856
3857 (defvar gdb-edit-locals-map-1
3858 (let ((map (make-sparse-keymap)))
3859 (suppress-keymap map)
3860 (define-key map "\r" 'gdb-edit-locals-value)
3861 (define-key map [mouse-2] 'gdb-edit-locals-value)
3862 map)
3863 "Keymap to edit value of a simple data type local variable.")
3864
3865 (defun gdb-edit-locals-value (&optional event)
3866 "Assign a value to a variable displayed in the locals buffer."
3867 (interactive (list last-input-event))
3868 (save-excursion
3869 (if event (posn-set-point (event-end event)))
3870 (beginning-of-line)
3871 (let* ((var (current-word))
3872 (value (read-string (format "New value (%s): " var))))
3873 (gdb-enqueue-input
3874 (list (concat gdb-server-prefix"set variable " var " = " value "\n")
3875 'ignore)))))
3876
3877 ;; Dont display values of arrays or structures.
3878 ;; These can be expanded using gud-watch.
3879 (defun gdb-stack-list-locals-handler ()
3880 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals-1
3881 gdb-pending-triggers))
3882 (goto-char (point-min))
3883 (if (re-search-forward gdb-error-regexp nil t)
3884 (let ((err (match-string 1)))
3885 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
3886 (let ((buffer-read-only nil))
3887 (erase-buffer)
3888 (insert err)
3889 (goto-char (point-min)))))
3890 (let (local locals-list)
3891 (goto-char (point-min))
3892 (while (re-search-forward gdb-stack-list-locals-regexp nil t)
3893 (let ((local (list (match-string 1)
3894 (match-string 2)
3895 nil)))
3896 (if (looking-at ",value=\\(\".*\"\\).*?}")
3897 (setcar (nthcdr 2 local) (read (match-string 1))))
3898 (push local locals-list)))
3899 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
3900 (and buf (with-current-buffer buf
3901 (let* ((window (get-buffer-window buf 0))
3902 (start (window-start window))
3903 (p (window-point window))
3904 (buffer-read-only nil) (name) (value))
3905 (erase-buffer)
3906 (dolist (local locals-list)
3907 (setq name (car local))
3908 (setq value (nth 2 local))
3909 (if (or (not value)
3910 (string-match "^\\0x" value))
3911 (add-text-properties 0 (length name)
3912 `(mouse-face highlight
3913 help-echo "mouse-2: create watch expression"
3914 local-map ,gdb-locals-watch-map-1)
3915 name)
3916 (add-text-properties 0 (length value)
3917 `(mouse-face highlight
3918 help-echo "mouse-2: edit value"
3919 local-map ,gdb-edit-locals-map-1)
3920 value))
3921 (insert
3922 (concat name "\t" (nth 1 local)
3923 "\t" value "\n")))
3924 (set-window-start window start)
3925 (set-window-point window p))))))))
3926
3927 (defun gdb-get-register-names ()
3928 "Create a list of register names."
3929 (goto-char (point-min))
3930 (setq gdb-register-names nil)
3931 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
3932 (push (match-string 1) gdb-register-names)))
3933
3934 (provide 'gdb-ui)
3935
3936 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
3937 ;;; gdb-ui.el ends here