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