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