Add arch taglines
[bpt/emacs.git] / lisp / gdb-ui.el
1 ;;; gdb-ui.el --- User Interface for running GDB
2
3 ;; Author: Nick Roberts <nick@nick.uklinux.net>
4 ;; Maintainer: FSF
5 ;; Keywords: unix, tools
6
7 ;; Copyright (C) 2002 Free Software Foundation, Inc.
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; This mode acts as a graphical user interface to GDB. You can interact with
29 ;; GDB through the GUD buffer in the usual way, but there are also further
30 ;; buffers which control the execution and describe the state of your program.
31 ;; It separates the input/output of your program from that of GDB and displays
32 ;; expressions and their current values in their own buffers. It also uses
33 ;; features of Emacs 21 such as the display margin for breakpoints, and the
34 ;; toolbar (see the GDB Graphical Interface section in the Emacs info manual).
35
36 ;; Start the debugger with M-x gdba.
37
38 ;; This file is based on gdba.el from GDB 5.0 written by Tom Lord and Jim
39 ;; Kingdon and uses GDB's annotation interface. You don't need to know about
40 ;; annotations to use this mode as a debugger, but if you are interested
41 ;; developing the mode itself, then see the Annotations section in the GDB
42 ;; info manual.
43 ;;
44 ;; Known Bugs:
45 ;; Does not auto-display arrays of structures or structures containing arrays.
46 ;; On MS Windows, Gdb 5.1.1 from MinGW 2.0 does not flush the output from the
47 ;; inferior.
48
49 ;;; Code:
50
51 (require 'gud)
52
53 (defcustom gdb-window-height 20
54 "Number of lines in a frame for a displayed expression in GDB-UI."
55 :type 'integer
56 :group 'gud)
57
58 (defcustom gdb-window-width 30
59 "Width of a frame for a displayed expression in GDB-UI."
60 :type 'integer
61 :group 'gud)
62
63 (defvar gdb-current-address "main" "Initialisation for Assembler buffer.")
64 (defvar gdb-previous-address nil)
65 (defvar gdb-previous-frame nil)
66 (defvar gdb-current-frame "main")
67 (defvar gdb-display-in-progress nil)
68 (defvar gdb-dive nil)
69 (defvar gdb-view-source t "Non-nil means that source code can be viewed")
70 (defvar gdb-selected-view 'source "Code type that user wishes to view")
71 (defvar gdb-buffer-type nil)
72 (defvar gdb-variables '()
73 "A list of variables that are local to the GUD buffer.")
74
75
76 ;;;###autoload
77 (defun gdba (command-line)
78 "Run gdb on program FILE in buffer *gud-FILE*.
79 The directory containing FILE becomes the initial working directory
80 and source-file directory for your debugger.
81
82 If `gdb-many-windows' is nil (the default value) then gdb starts with
83 just two windows : the GUD and the source buffer. If it is t the
84 following layout will appear (keybindings given in relevant buffer) :
85
86 ---------------------------------------------------------------------
87 GDB Toolbar
88 ---------------------------------------------------------------------
89 GUD buffer (I/O of GDB) | Locals buffer
90 |
91 |
92 |
93 ---------------------------------------------------------------------
94 Source buffer | Input/Output (of debuggee) buffer
95 | (comint-mode)
96 |
97 |
98 |
99 |
100 |
101 |
102 ---------------------------------------------------------------------
103 Stack buffer | Breakpoints buffer
104 RET gdb-frames-select | SPC gdb-toggle-breakpoint
105 | RET gdb-goto-breakpoint
106 | d gdb-delete-breakpoint
107 ---------------------------------------------------------------------
108
109 All the buffers share the toolbar and source should always display in the same
110 window e.g after typing g on a breakpoint in the breakpoints buffer. Breakpoint
111 icons are displayed both by setting a break with gud-break and by typing break
112 in the GUD buffer.
113
114 This works best (depending on the size of your monitor) using most of the
115 screen.
116
117 Displayed expressions appear in separate frames. Arrays may be displayed
118 as slices and visualised using the graph program from plotutils if installed.
119 Pointers in structures may be followed in a tree-like fashion.
120
121 The following interactive lisp functions help control operation :
122
123 `gdb-many-windows' - Toggle the number of windows gdb uses.
124 `gdb-restore-windows' - To restore the window layout."
125 ;;
126 (interactive (list (gud-query-cmdline 'gdba)))
127 ;;
128 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
129 (gdb command-line)
130 ;;
131 (set (make-local-variable 'gud-minor-mode) 'gdba)
132 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
133 ;;
134 (gud-def gud-break (if (not (string-equal mode-name "Assembler"))
135 (gud-call "break %f:%l" arg)
136 (save-excursion
137 (beginning-of-line)
138 (forward-char 2)
139 (gud-call "break *%a" arg)))
140 "\C-b" "Set breakpoint at current line or address.")
141 ;;
142 (gud-def gud-remove (if (not (string-equal mode-name "Assembler"))
143 (gud-call "clear %f:%l" arg)
144 (save-excursion
145 (beginning-of-line)
146 (forward-char 2)
147 (gud-call "clear *%a" arg)))
148 "\C-d" "Remove breakpoint at current line or address.")
149 ;;
150 (gud-def gud-until (if (not (string-equal mode-name "Assembler"))
151 (gud-call "until %f:%l" arg)
152 (save-excursion
153 (beginning-of-line)
154 (forward-char 2)
155 (gud-call "until *%a" arg)))
156 "\C-u" "Continue to current line or address.")
157
158 (setq comint-input-sender 'gdb-send)
159 ;;
160 ;; (re-)initialise
161 (setq gdb-current-address "main")
162 (setq gdb-previous-address nil)
163 (setq gdb-previous-frame nil)
164 (setq gdb-current-frame "main")
165 (setq gdb-display-in-progress nil)
166 (setq gdb-dive nil)
167 (setq gdb-view-source t)
168 (setq gdb-selected-view 'source)
169 ;;
170 (mapc 'make-local-variable gdb-variables)
171 (setq gdb-buffer-type 'gdba)
172 ;;
173 (gdb-clear-inferior-io)
174 ;;
175 (if (eq window-system 'w32)
176 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
177 (gdb-enqueue-input (list "set height 0\n" 'ignore))
178 ;; find source file and compilation directory here
179 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
180 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
181 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
182 ;;
183 (run-hooks 'gdba-mode-hook))
184
185 (defun gud-display ()
186 "Auto-display (possibly dereferenced) C expression at point."
187 (interactive)
188 (save-excursion
189 (let ((expr (gud-find-c-expr)))
190 (gdb-enqueue-input
191 (list (concat "server ptype " expr "\n")
192 `(lambda () (gud-display1 ,expr)))))))
193
194 (defun gud-display1 (expr)
195 (goto-char (point-min))
196 (if (looking-at "No symbol")
197 (progn
198 (gdb-set-output-sink 'user)
199 (gud-call (concat "server ptype " expr)))
200 (goto-char (- (point-max) 1))
201 (if (equal (char-before) (string-to-char "\*"))
202 (gdb-enqueue-input
203 (list (concat "display* " expr "\n") 'ignore))
204 (gdb-enqueue-input
205 (list (concat "display " expr "\n") 'ignore)))))
206
207 ; this would messy because these bindings don't work with M-x gdb
208 ; (define-key global-map "\C-x\C-a\C-a" 'gud-display)
209 ; (define-key gud-minor-mode-map "\C-c\C-a" 'gud-display)
210
211
212 \f
213 ;; ======================================================================
214 ;;
215 ;; In this world, there are gdb variables (of unspecified
216 ;; representation) and buffers associated with those objects.
217 ;; The list of variables is built up by the expansions of
218 ;; def-gdb-variable
219
220 (defmacro def-gdb-var (root-symbol &optional default doc)
221 (let* ((root (symbol-name root-symbol))
222 (accessor (intern (concat "gdb-get-" root)))
223 (setter (intern (concat "gdb-set-" root)))
224 (name (intern (concat "gdb-" root))))
225 `(progn
226 (defvar ,name ,default ,doc)
227 (if (not (memq ',name gdb-variables))
228 (push ',name gdb-variables))
229 (defun ,accessor ()
230 (buffer-local-value ',name gud-comint-buffer))
231 (defun ,setter (val)
232 (with-current-buffer gud-comint-buffer
233 (setq ,name val))))))
234
235 (def-gdb-var buffer-type nil
236 "One of the symbols bound in gdb-buffer-rules")
237
238 (def-gdb-var burst ""
239 "A string of characters from gdb that have not yet been processed.")
240
241 (def-gdb-var input-queue ()
242 "A list of high priority gdb command objects.")
243
244 (def-gdb-var idle-input-queue ()
245 "A list of low priority gdb command objects.")
246
247 (def-gdb-var prompting nil
248 "True when gdb is idle with no pending input.")
249
250 (def-gdb-var output-sink 'user
251 "The disposition of the output of the current gdb command.
252 Possible values are these symbols:
253
254 user -- gdb output should be copied to the GUD buffer
255 for the user to see.
256
257 inferior -- gdb output should be copied to the inferior-io buffer
258
259 pre-emacs -- output should be ignored util the post-prompt
260 annotation is received. Then the output-sink
261 becomes:...
262 emacs -- output should be collected in the partial-output-buffer
263 for subsequent processing by a command. This is the
264 disposition of output generated by commands that
265 gdb mode sends to gdb on its own behalf.
266 post-emacs -- ignore input until the prompt annotation is
267 received, then go to USER disposition.
268 ")
269
270 (def-gdb-var current-item nil
271 "The most recent command item sent to gdb.")
272
273 (def-gdb-var pending-triggers '()
274 "A list of trigger functions that have run later than their output
275 handlers.")
276
277 ;; end of gdb variables
278
279 (defun gdb-get-target-string ()
280 (with-current-buffer gud-comint-buffer
281 gud-target-name))
282 \f
283
284 ;;
285 ;; gdb buffers.
286 ;;
287 ;; Each buffer has a TYPE -- a symbol that identifies the function
288 ;; of that particular buffer.
289 ;;
290 ;; The usual gdb interaction buffer is given the type `gdba' and
291 ;; is constructed specially.
292 ;;
293 ;; Others are constructed by gdb-get-create-buffer and
294 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
295
296 (defvar gdb-buffer-rules-assoc '())
297
298 (defun gdb-get-buffer (key)
299 "Return the gdb buffer tagged with type KEY.
300 The key should be one of the cars in `gdb-buffer-rules-assoc'."
301 (save-excursion
302 (gdb-look-for-tagged-buffer key (buffer-list))))
303
304 (defun gdb-get-create-buffer (key)
305 "Create a new gdb buffer of the type specified by KEY.
306 The key should be one of the cars in `gdb-buffer-rules-assoc'."
307 (or (gdb-get-buffer key)
308 (let* ((rules (assoc key gdb-buffer-rules-assoc))
309 (name (funcall (gdb-rules-name-maker rules)))
310 (new (get-buffer-create name)))
311 (with-current-buffer new
312 ;; FIXME: This should be set after calling the function, since the
313 ;; function should run kill-all-local-variables.
314 (set (make-local-variable 'gdb-buffer-type) key)
315 (if (cdr (cdr rules))
316 (funcall (car (cdr (cdr rules)))))
317 (set (make-local-variable 'gud-comint-buffer) gud-comint-buffer)
318 (set (make-local-variable 'gud-minor-mode) 'gdba)
319 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
320 new))))
321
322 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
323
324 (defun gdb-look-for-tagged-buffer (key bufs)
325 (let ((retval nil))
326 (while (and (not retval) bufs)
327 (set-buffer (car bufs))
328 (if (eq gdb-buffer-type key)
329 (setq retval (car bufs)))
330 (setq bufs (cdr bufs)))
331 retval))
332
333 ;;
334 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
335 ;; at least one and possible more functions. The functions have these
336 ;; roles in defining a buffer type:
337 ;;
338 ;; NAME - Return a name for this buffer type.
339 ;;
340 ;; The remaining function(s) are optional:
341 ;;
342 ;; MODE - called in a new buffer with no arguments, should establish
343 ;; the proper mode for the buffer.
344 ;;
345
346 (defun gdb-set-buffer-rules (buffer-type &rest rules)
347 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
348 (if binding
349 (setcdr binding rules)
350 (push (cons buffer-type rules)
351 gdb-buffer-rules-assoc))))
352
353 ;; GUD buffers are an exception to the rules
354 (gdb-set-buffer-rules 'gdba 'error)
355
356 ;;
357 ;; Partial-output buffer : This accumulates output from a command executed on
358 ;; behalf of emacs (rather than the user).
359 ;;
360 (gdb-set-buffer-rules 'gdb-partial-output-buffer
361 'gdb-partial-output-name)
362
363 (defun gdb-partial-output-name ()
364 (concat "*partial-output-"
365 (gdb-get-target-string)
366 "*"))
367
368 \f
369 (gdb-set-buffer-rules 'gdb-inferior-io
370 'gdb-inferior-io-name
371 'gdb-inferior-io-mode)
372
373 (defun gdb-inferior-io-name ()
374 (concat "*input/output of "
375 (gdb-get-target-string)
376 "*"))
377
378 (defvar gdb-inferior-io-mode-map
379 (let ((map (make-sparse-keymap)))
380 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
381 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
382 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
383 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
384 map))
385
386 (define-derived-mode gdb-inferior-io-mode comint-mode "Debuggee I/O"
387 "Major mode for gdb inferior-io."
388 :syntax-table nil :abbrev-table nil
389 ;; We want to use comint because it has various nifty and familiar
390 ;; features. We don't need a process, but comint wants one, so create
391 ;; a dummy one.
392 (make-comint-in-buffer
393 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
394 (current-buffer) "hexl")
395 (setq comint-input-sender 'gdb-inferior-io-sender))
396
397 (defun gdb-inferior-io-sender (proc string)
398 ;; PROC is the pseudo-process created to satisfy comint.
399 (with-current-buffer (process-buffer proc)
400 (setq proc (get-buffer-process gud-comint-buffer))
401 (process-send-string proc string)
402 (process-send-string proc "\n")))
403
404 (defun gdb-inferior-io-interrupt ()
405 "Interrupt the program being debugged."
406 (interactive)
407 (interrupt-process
408 (get-buffer-process gud-comint-buffer) comint-ptyp))
409
410 (defun gdb-inferior-io-quit ()
411 "Send quit signal to the program being debugged."
412 (interactive)
413 (quit-process
414 (get-buffer-process gud-comint-buffer) comint-ptyp))
415
416 (defun gdb-inferior-io-stop ()
417 "Stop the program being debugged."
418 (interactive)
419 (stop-process
420 (get-buffer-process gud-comint-buffer) comint-ptyp))
421
422 (defun gdb-inferior-io-eof ()
423 "Send end-of-file to the program being debugged."
424 (interactive)
425 (process-send-eof
426 (get-buffer-process gud-comint-buffer)))
427 \f
428
429 ;;
430 ;; gdb communications
431 ;;
432
433 ;; INPUT: things sent to gdb
434 ;;
435 ;; There is a high and low priority input queue. Low priority input is sent
436 ;; only when the high priority queue is idle.
437 ;;
438 ;; The queues are lists. Each element is either a string (indicating user or
439 ;; user-like input) or a list of the form:
440 ;;
441 ;; (INPUT-STRING HANDLER-FN)
442 ;;
443 ;; The handler function will be called from the partial-output buffer when the
444 ;; command completes. This is the way to write commands which invoke gdb
445 ;; commands autonomously.
446 ;;
447 ;; These lists are consumed tail first.
448 ;;
449
450 (defun gdb-send (proc string)
451 "A comint send filter for gdb.
452 This filter may simply queue output for a later time."
453 (gdb-enqueue-input (concat string "\n")))
454
455 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
456 ;; is a query, or other non-top-level prompt. To guarantee stuff will get
457 ;; sent to the top-level prompt, currently it must be put in the idle queue.
458 ;; ^^^^^^^^^
459 ;; [This should encourage gdb extensions that invoke gdb commands to let
460 ;; the user go first; it is not a bug. -t]
461 ;;
462
463 (defun gdb-enqueue-input (item)
464 (if (gdb-get-prompting)
465 (progn
466 (gdb-send-item item)
467 (gdb-set-prompting nil))
468 (gdb-set-input-queue
469 (cons item (gdb-get-input-queue)))))
470
471 (defun gdb-dequeue-input ()
472 (let ((queue (gdb-get-input-queue)))
473 (and queue
474 (if (not (cdr queue))
475 (let ((answer (car queue)))
476 (gdb-set-input-queue '())
477 answer)
478 (gdb-take-last-elt queue)))))
479
480 (defun gdb-enqueue-idle-input (item)
481 (if (and (gdb-get-prompting)
482 (not (gdb-get-input-queue)))
483 (progn
484 (gdb-send-item item)
485 (gdb-set-prompting nil))
486 (gdb-set-idle-input-queue
487 (cons item (gdb-get-idle-input-queue)))))
488
489 (defun gdb-dequeue-idle-input ()
490 (let ((queue (gdb-get-idle-input-queue)))
491 (and queue
492 (if (not (cdr queue))
493 (let ((answer (car queue)))
494 (gdb-set-idle-input-queue '())
495 answer)
496 (gdb-take-last-elt queue)))))
497
498 ;; Don't use this in general.
499 (defun gdb-take-last-elt (l)
500 (if (cdr (cdr l))
501 (gdb-take-last-elt (cdr l))
502 (let ((answer (car (cdr l))))
503 (setcdr l '())
504 answer)))
505
506 \f
507 ;;
508 ;; output -- things gdb prints to emacs
509 ;;
510 ;; GDB output is a stream interrupted by annotations.
511 ;; Annotations can be recognized by their beginning
512 ;; with \C-j\C-z\C-z<tag><opt>\C-j
513 ;;
514 ;; The tag is a string obeying symbol syntax.
515 ;;
516 ;; The optional part `<opt>' can be either the empty string
517 ;; or a space followed by more data relating to the annotation.
518 ;; For example, the SOURCE annotation is followed by a filename,
519 ;; line number and various useless goo. This data must not include
520 ;; any newlines.
521 ;;
522
523 (defcustom gud-gdba-command-name "gdb -annotate=2 -noasync"
524 "Default command to execute an executable under the GDB-UI debugger."
525 :type 'string
526 :group 'gud)
527
528 (defvar gdb-annotation-rules
529 '(("pre-prompt" gdb-pre-prompt)
530 ("prompt" gdb-prompt)
531 ("commands" gdb-subprompt)
532 ("overload-choice" gdb-subprompt)
533 ("query" gdb-subprompt)
534 ("prompt-for-continue" gdb-subprompt)
535 ("post-prompt" gdb-post-prompt)
536 ("source" gdb-source)
537 ("starting" gdb-starting)
538 ("exited" gdb-stopping)
539 ("signalled" gdb-stopping)
540 ("signal" gdb-stopping)
541 ("breakpoint" gdb-stopping)
542 ("watchpoint" gdb-stopping)
543 ("frame-begin" gdb-frame-begin)
544 ("stopped" gdb-stopped)
545 ("display-begin" gdb-display-begin)
546 ("display-end" gdb-display-end)
547 ; GDB commands info stack, info locals and frame generate an error-begin
548 ; annotation at start when there is no stack but this is a quirk/bug in
549 ; annotations.
550 ; ("error-begin" gdb-error-begin)
551 ("display-number-end" gdb-display-number-end)
552 ("array-section-begin" gdb-array-section-begin)
553 ("array-section-end" gdb-array-section-end)
554 ;; ("elt" gdb-elt)
555 ("field-begin" gdb-field-begin)
556 ("field-end" gdb-field-end)
557 ) "An assoc mapping annotation tags to functions which process them.")
558
559 (defconst gdb-source-spec-regexp
560 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:\\(0x[a-f0-9]*\\)")
561
562 ;; Do not use this except as an annotation handler.
563 (defun gdb-source (args)
564 (string-match gdb-source-spec-regexp args)
565 ;; Extract the frame position from the marker.
566 (setq gud-last-frame
567 (cons
568 (match-string 1 args)
569 (string-to-int (match-string 2 args))))
570 (setq gdb-current-address (match-string 3 args))
571 (setq gdb-view-source t))
572
573 (defun gdb-send-item (item)
574 (gdb-set-current-item item)
575 (if (stringp item)
576 (progn
577 (gdb-set-output-sink 'user)
578 (process-send-string (get-buffer-process gud-comint-buffer) item))
579 (progn
580 (gdb-clear-partial-output)
581 (gdb-set-output-sink 'pre-emacs)
582 (process-send-string (get-buffer-process gud-comint-buffer)
583 (car item)))))
584
585 (defun gdb-pre-prompt (ignored)
586 "An annotation handler for `pre-prompt'. This terminates the collection of
587 output from a previous command if that happens to be in effect."
588 (let ((sink (gdb-get-output-sink)))
589 (cond
590 ((eq sink 'user) t)
591 ((eq sink 'emacs)
592 (gdb-set-output-sink 'post-emacs)
593 (let ((handler
594 (car (cdr (gdb-get-current-item)))))
595 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
596 (funcall handler))))
597 (t
598 (gdb-set-output-sink 'user)
599 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
600
601 (defun gdb-prompt (ignored)
602 "An annotation handler for `prompt'.
603 This sends the next command (if any) to gdb."
604 (let ((sink (gdb-get-output-sink)))
605 (cond
606 ((eq sink 'user) t)
607 ((eq sink 'post-emacs)
608 (gdb-set-output-sink 'user))
609 (t
610 (gdb-set-output-sink 'user)
611 (error "Phase error in gdb-prompt (got %s)" sink))))
612 (let ((highest (gdb-dequeue-input)))
613 (if highest
614 (gdb-send-item highest)
615 (let ((lowest (gdb-dequeue-idle-input)))
616 (if lowest
617 (gdb-send-item lowest)
618 (progn
619 (gdb-set-prompting t)
620 (gud-display-frame)))))))
621
622 (defun gdb-subprompt (ignored)
623 "An annotation handler for non-top-level prompts."
624 (let ((highest (gdb-dequeue-input)))
625 (if highest
626 (gdb-send-item highest)
627 (gdb-set-prompting t))))
628
629 (defun gdb-starting (ignored)
630 "An annotation handler for `starting'. This says that I/O for the
631 subprocess is now the program being debugged, not GDB."
632 (let ((sink (gdb-get-output-sink)))
633 (cond
634 ((eq sink 'user)
635 (progn
636 (setq gud-running t)
637 (gdb-set-output-sink 'inferior)))
638 (t (error "Unexpected `starting' annotation")))))
639
640 (defun gdb-stopping (ignored)
641 "An annotation handler for `exited' and other annotations which say that I/O
642 for the subprocess is now GDB, not the program being debugged."
643 (let ((sink (gdb-get-output-sink)))
644 (cond
645 ((eq sink 'inferior)
646 (gdb-set-output-sink 'user))
647 (t (error "Unexpected stopping annotation")))))
648
649 (defun gdb-frame-begin (ignored)
650 (let ((sink (gdb-get-output-sink)))
651 (cond
652 ((eq sink 'inferior)
653 (gdb-set-output-sink 'user))
654 ((eq sink 'user) t)
655 ((eq sink 'emacs) t)
656 (t (error "Unexpected frame-begin annotation (%S)" sink)))))
657
658 (defun gdb-stopped (ignored)
659 "An annotation handler for `stopped'. It is just like gdb-stopping, except
660 that if we already set the output sink to 'user in gdb-stopping, that is fine."
661 (setq gud-running nil)
662 (let ((sink (gdb-get-output-sink)))
663 (cond
664 ((eq sink 'inferior)
665 (gdb-set-output-sink 'user))
666 ((eq sink 'user) t)
667 (t (error "Unexpected stopped annotation")))))
668
669 (defun gdb-post-prompt (ignored)
670 "An annotation handler for `post-prompt'. This begins the collection of
671 output from the current command if that happens to be appropriate."
672 (if (not (gdb-get-pending-triggers))
673 (progn
674 (gdb-get-current-frame)
675 (gdb-invalidate-frames)
676 (gdb-invalidate-breakpoints)
677 (gdb-invalidate-assembler)
678 (gdb-invalidate-registers)
679 (gdb-invalidate-locals)
680 (gdb-invalidate-display)
681 (gdb-invalidate-threads)))
682 (let ((sink (gdb-get-output-sink)))
683 (cond
684 ((eq sink 'user) t)
685 ((eq sink 'pre-emacs)
686 (gdb-set-output-sink 'emacs))
687 (t
688 (gdb-set-output-sink 'user)
689 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
690
691 ;; If we get an error whilst evaluating one of the expressions
692 ;; we won't get the display-end annotation. Set the sink back to
693 ;; user to make sure that the error message is seen.
694 ;; NOT USED: see annotation-rules for reason.
695 ;(defun gdb-error-begin (ignored)
696 ; (gdb-set-output-sink 'user))
697
698 (defun gdb-display-begin (ignored)
699 (gdb-set-output-sink 'emacs)
700 (gdb-clear-partial-output)
701 (setq gdb-display-in-progress t))
702
703 (defvar gdb-expression-buffer-name nil)
704 (defvar gdb-display-number nil)
705 (defvar gdb-dive-display-number nil)
706
707 (defun gdb-display-number-end (ignored)
708 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
709 (setq gdb-display-number (buffer-string))
710 (setq gdb-expression-buffer-name
711 (concat "*display " gdb-display-number "*"))
712 (save-excursion
713 (if (progn
714 (set-buffer (window-buffer))
715 gdb-dive)
716 (progn
717 (let ((number gdb-display-number))
718 (switch-to-buffer
719 (set-buffer (get-buffer-create gdb-expression-buffer-name)))
720 (gdb-expressions-mode)
721 (setq gdb-dive-display-number number)))
722 (set-buffer (get-buffer-create gdb-expression-buffer-name))
723 (if (display-graphic-p)
724 (catch 'frame-exists
725 (dolist (frame (frame-list))
726 (if (string-equal (frame-parameter frame 'name)
727 gdb-expression-buffer-name)
728 (throw 'frame-exists nil)))
729 (gdb-expressions-mode)
730 (make-frame `((height . ,gdb-window-height)
731 (width . ,gdb-window-width)
732 (tool-bar-lines . nil)
733 (menu-bar-lines . nil)
734 (minibuffer . nil))))
735 (gdb-expressions-mode)
736 (gdb-display-buffer (get-buffer gdb-expression-buffer-name)))))
737 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
738 (setq gdb-dive nil))
739
740 (defvar gdb-nesting-level nil)
741 (defvar gdb-expression nil)
742 (defvar gdb-point nil)
743 (defvar gdb-annotation-arg nil)
744
745 (defun gdb-delete-line ()
746 "Delete the current line."
747 (delete-region (line-beginning-position) (line-beginning-position 2)))
748
749 (defun gdb-display-end (ignored)
750 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
751 (goto-char (point-min))
752 (search-forward ": ")
753 (looking-at "\\(.*?\\) =")
754 (let ((char "")
755 (gdb-temp-value (match-string 1)))
756 ;;move * to front of expression if necessary
757 (if (looking-at ".*\\*")
758 (progn
759 (setq char "*")
760 (setq gdb-temp-value (substring gdb-temp-value 1 nil))))
761 (with-current-buffer gdb-expression-buffer-name
762 (setq gdb-expression gdb-temp-value)
763 (if (not (string-match "::" gdb-expression))
764 (setq gdb-expression (concat char gdb-current-frame
765 "::" gdb-expression))
766 ;;else put * back on if necessary
767 (setq gdb-expression (concat char gdb-expression)))
768 (if (not header-line-format)
769 (setq header-line-format (concat "-- " gdb-expression " %-")))))
770 ;;
771 ;;-if scalar/string
772 (if (not (re-search-forward "##" nil t))
773 (progn
774 (with-current-buffer gdb-expression-buffer-name
775 (let ((buffer-read-only nil))
776 (delete-region (point-min) (point-max))
777 (insert-buffer-substring
778 (gdb-get-buffer 'gdb-partial-output-buffer)))))
779 ;; display expression name...
780 (goto-char (point-min))
781 (let ((start (progn (point)))
782 (end (progn (end-of-line) (point))))
783 (with-current-buffer gdb-expression-buffer-name
784 (let ((buffer-read-only nil))
785 (delete-region (point-min) (point-max))
786 (insert-buffer-substring (gdb-get-buffer
787 'gdb-partial-output-buffer)
788 start end)
789 (insert "\n"))))
790 (goto-char (point-min))
791 (re-search-forward "##" nil t)
792 (setq gdb-nesting-level 0)
793 (if (looking-at "array-section-begin")
794 (progn
795 (gdb-delete-line)
796 (setq gdb-point (point))
797 (gdb-array-format)))
798 (if (looking-at "field-begin \\(.\\)")
799 (progn
800 (setq gdb-annotation-arg (match-string 1))
801 (gdb-field-format-begin))))
802 (with-current-buffer gdb-expression-buffer-name
803 (if gdb-dive-display-number
804 (progn
805 (let ((buffer-read-only nil))
806 (goto-char (point-max))
807 (insert "\n")
808 (insert-text-button "[back]" 'type 'gdb-display-back)))))
809 (gdb-clear-partial-output)
810 (gdb-set-output-sink 'user)
811 (setq gdb-display-in-progress nil))
812
813 (define-button-type 'gdb-display-back
814 'help-echo "mouse-2, RET: go back to previous display buffer"
815 'action (lambda (button) (gdb-display-go-back)))
816
817 (defun gdb-display-go-back ()
818 ;; delete display so they don't accumulate and delete buffer
819 (let ((number gdb-display-number))
820 (gdb-enqueue-input
821 (list (concat "server delete display " number "\n") 'ignore))
822 (switch-to-buffer (concat "*display " gdb-dive-display-number "*"))
823 (kill-buffer (get-buffer (concat "*display " number "*")))))
824
825 ;; prefix annotations with ## and process whole output in one chunk
826 ;; in gdb-partial-output-buffer (to allow recursion).
827
828 ;; array-section flags are just removed again but after counting. They
829 ;; might also be useful for arrays of structures and structures with arrays.
830 (defun gdb-array-section-begin (args)
831 (if gdb-display-in-progress
832 (progn
833 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
834 (goto-char (point-max))
835 (insert (concat "\n##array-section-begin " args "\n"))))))
836
837 (defun gdb-array-section-end (ignored)
838 (if gdb-display-in-progress
839 (progn
840 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
841 (goto-char (point-max))
842 (insert "\n##array-section-end\n")))))
843
844 (defun gdb-field-begin (args)
845 (if gdb-display-in-progress
846 (progn
847 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
848 (goto-char (point-max))
849 (insert (concat "\n##field-begin " args "\n"))))))
850
851 (defun gdb-field-end (ignored)
852 (if gdb-display-in-progress
853 (progn
854 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
855 (goto-char (point-max))
856 (insert "\n##field-end\n")))))
857
858 (defun gdb-elt (ignored)
859 (if gdb-display-in-progress
860 (progn
861 (goto-char (point-max))
862 (insert "\n##elt\n"))))
863
864 (defun gdb-field-format-begin ()
865 ;; get rid of ##field-begin
866 (gdb-delete-line)
867 (gdb-insert-field)
868 (setq gdb-nesting-level (+ gdb-nesting-level 1))
869 (while (re-search-forward "##" nil t)
870 ;; keep making recursive calls...
871 (if (looking-at "field-begin \\(.\\)")
872 (progn
873 (setq gdb-annotation-arg (match-string 1))
874 (gdb-field-format-begin)))
875 ;; until field-end.
876 (if (looking-at "field-end") (gdb-field-format-end))))
877
878 (defun gdb-field-format-end ()
879 ;; get rid of ##field-end and `,' or `}'
880 (gdb-delete-line)
881 (gdb-delete-line)
882 (setq gdb-nesting-level (- gdb-nesting-level 1)))
883
884 (defvar gdb-dive-map
885 (let ((map (make-sparse-keymap)))
886 (define-key map [mouse-2] 'gdb-dive)
887 (define-key map [S-mouse-2] 'gdb-dive-new-frame)
888 map))
889
890 (defun gdb-dive (event)
891 "Dive into structure."
892 (interactive "e")
893 (setq gdb-dive t)
894 (gdb-dive-new-frame event))
895
896 (defun gdb-dive-new-frame (event)
897 "Dive into structure and display in a new frame."
898 (interactive "e")
899 (save-excursion
900 (mouse-set-point event)
901 (let ((point (point)) (gdb-full-expression gdb-expression)
902 (end (progn (end-of-line) (point)))
903 (gdb-part-expression "") (gdb-last-field nil) (gdb-display-char nil))
904 (beginning-of-line)
905 (if (looking-at "\*") (setq gdb-display-char "*"))
906 (re-search-forward "\\(\\S-+\\) = " end t)
907 (setq gdb-last-field (match-string-no-properties 1))
908 (goto-char (match-beginning 1))
909 (let ((last-column (current-column)))
910 (while (re-search-backward "\\s-\\(\\S-+\\) = {" nil t)
911 (goto-char (match-beginning 1))
912 (if (and (< (current-column) last-column)
913 (> (count-lines 1 (point)) 1))
914 (progn
915 (setq gdb-part-expression
916 (concat "." (match-string-no-properties 1)
917 gdb-part-expression))
918 (setq last-column (current-column))))))
919 ;; * not needed for components of a pointer to a structure in gdb
920 (if (string-equal "*" (substring gdb-full-expression 0 1))
921 (setq gdb-full-expression (substring gdb-full-expression 1 nil)))
922 (setq gdb-full-expression
923 (concat gdb-full-expression gdb-part-expression "." gdb-last-field))
924 (gdb-enqueue-input
925 (list (concat "server display" gdb-display-char
926 " " gdb-full-expression "\n")
927 'ignore)))))
928
929 (defun gdb-insert-field ()
930 (let ((start (progn (point)))
931 (end (progn (next-line) (point)))
932 (num 0))
933 (with-current-buffer gdb-expression-buffer-name
934 (let ((buffer-read-only nil))
935 (if (string-equal gdb-annotation-arg "\*") (insert "\*"))
936 (while (<= num gdb-nesting-level)
937 (insert "\t")
938 (setq num (+ num 1)))
939 (insert-buffer-substring (gdb-get-buffer
940 'gdb-partial-output-buffer)
941 start end)
942 (add-text-properties
943 (- (point) (- end start)) (- (point) 1)
944 `(mouse-face highlight
945 local-map ,gdb-dive-map
946 help-echo "mouse-2: dive, S-mouse-2: dive in a new frame"))))
947 (delete-region start end)))
948
949 (defvar gdb-values nil)
950
951 (defun gdb-array-format ()
952 (while (re-search-forward "##" nil t)
953 ;; keep making recursive calls...
954 (if (looking-at "array-section-begin")
955 (progn
956 ;;get rid of ##array-section-begin
957 (gdb-delete-line)
958 (setq gdb-nesting-level (+ gdb-nesting-level 1))
959 (gdb-array-format)))
960 ;;until *matching* array-section-end is found
961 (if (looking-at "array-section-end")
962 (if (eq gdb-nesting-level 0)
963 (progn
964 (let ((values (buffer-substring gdb-point (- (point) 2))))
965 (with-current-buffer gdb-expression-buffer-name
966 (setq gdb-values
967 (concat "{" (replace-regexp-in-string "\n" "" values)
968 "}"))
969 (gdb-array-format1))))
970 ;;else get rid of ##array-section-end etc
971 (gdb-delete-line)
972 (setq gdb-nesting-level (- gdb-nesting-level 1))
973 (gdb-array-format)))))
974
975 (defvar gdb-array-start nil)
976 (defvar gdb-array-stop nil)
977
978 (defvar gdb-array-slice-map
979 (let ((map (make-sparse-keymap)))
980 (define-key map "\r" 'gdb-array-slice)
981 (define-key map [mouse-2] 'gdb-mouse-array-slice)
982 map))
983
984 (defun gdb-mouse-array-slice (event)
985 "Select an array slice to display."
986 (interactive "e")
987 (mouse-set-point event)
988 (gdb-array-slice))
989
990 (defun gdb-array-slice ()
991 (interactive)
992 (save-excursion
993 (let ((n -1) (stop 0) (start 0) (point (point)))
994 (beginning-of-line)
995 (while (search-forward "[" point t)
996 (setq n (+ n 1)))
997 (setq start (string-to-int (read-string "Start index: ")))
998 (aset gdb-array-start n start)
999 (setq stop (string-to-int (read-string "Stop index: ")))
1000 (aset gdb-array-stop n stop)))
1001 (gdb-array-format1))
1002
1003 (defvar gdb-display-string nil)
1004 (defvar gdb-array-size nil)
1005
1006 (defun gdb-array-format1 ()
1007 (setq gdb-display-string "")
1008 (let ((buffer-read-only nil))
1009 (delete-region (point-min) (point-max))
1010 (let ((gdb-value-list (split-string gdb-values ", ")))
1011 (string-match "\\({+\\)" (car gdb-value-list))
1012 (let* ((depth (- (match-end 1) (match-beginning 1)))
1013 (indices (make-vector depth '0))
1014 (index 0) (num 0) (array-start "")
1015 (array-stop "") (array-slice "") (array-range nil)
1016 (flag t) (indices-string ""))
1017 (dolist (gdb-value gdb-value-list)
1018 (string-match "{*\\([^}]*\\)\\(}*\\)" gdb-value)
1019 (setq num 0)
1020 (while (< num depth)
1021 (setq indices-string
1022 (concat indices-string
1023 "[" (int-to-string (aref indices num)) "]"))
1024 (if (not (= (aref gdb-array-start num) -1))
1025 (if (or (< (aref indices num) (aref gdb-array-start num))
1026 (> (aref indices num) (aref gdb-array-stop num)))
1027 (setq flag nil))
1028 (aset gdb-array-size num (aref indices num)))
1029 (setq num (+ num 1)))
1030 (if flag
1031 (let ((gdb-display-value (match-string 1 gdb-value)))
1032 (setq gdb-display-string (concat gdb-display-string " "
1033 gdb-display-value))
1034 (insert
1035 (concat indices-string "\t" gdb-display-value "\n"))))
1036 (setq indices-string "")
1037 (setq flag t)
1038 ;; 0<= index < depth, start at right : (- depth 1)
1039 (setq index (- (- depth 1)
1040 (- (match-end 2) (match-beginning 2))))
1041 ;;don't set for very last brackets
1042 (when (>= index 0)
1043 (aset indices index (+ 1 (aref indices index)))
1044 (setq num (+ 1 index))
1045 (while (< num depth)
1046 (aset indices num 0)
1047 (setq num (+ num 1)))))
1048 (setq num 0)
1049 (while (< num depth)
1050 (if (= (aref gdb-array-start num) -1)
1051 (progn
1052 (aset gdb-array-start num 0)
1053 (aset gdb-array-stop num (aref indices num))))
1054 (setq array-start (int-to-string (aref gdb-array-start num)))
1055 (setq array-stop (int-to-string (aref gdb-array-stop num)))
1056 (setq array-range (concat "[" array-start
1057 ":" array-stop "]"))
1058 (add-text-properties
1059 1 (+ (length array-start) (length array-stop) 2)
1060 `(mouse-face highlight
1061 local-map ,gdb-array-slice-map
1062 help-echo "mouse-2, RET: select slice for this index") array-range)
1063 (goto-char (point-min))
1064 (setq array-slice (concat array-slice array-range))
1065 (setq num (+ num 1)))
1066 (goto-char (point-min))
1067 (insert "Array Size : ")
1068 (setq num 0)
1069 (while (< num depth)
1070 (insert
1071 (concat "["
1072 (int-to-string (+ (aref gdb-array-size num) 1)) "]"))
1073 (setq num (+ num 1)))
1074 (insert
1075 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n"))))))
1076
1077 (defun gud-gdba-marker-filter (string)
1078 "A gud marker filter for gdb. Handle a burst of output from GDB."
1079 (let (
1080 ;; Recall the left over burst from last time
1081 (burst (concat (gdb-get-burst) string))
1082 ;; Start accumulating output for the GUD buffer
1083 (output ""))
1084 ;;
1085 ;; Process all the complete markers in this chunk.
1086 (while (string-match "\n\032\032\\(.*\\)\n" burst)
1087 (let ((annotation (match-string 1 burst)))
1088 ;;
1089 ;; Stuff prior to the match is just ordinary output.
1090 ;; It is either concatenated to OUTPUT or directed
1091 ;; elsewhere.
1092 (setq output
1093 (gdb-concat-output
1094 output
1095 (substring burst 0 (match-beginning 0))))
1096
1097 ;; Take that stuff off the burst.
1098 (setq burst (substring burst (match-end 0)))
1099
1100 ;; Parse the tag from the annotation, and maybe its arguments.
1101 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1102 (let* ((annotation-type (match-string 1 annotation))
1103 (annotation-arguments (match-string 2 annotation))
1104 (annotation-rule (assoc annotation-type
1105 gdb-annotation-rules)))
1106 ;; Call the handler for this annotation.
1107 (if annotation-rule
1108 (funcall (car (cdr annotation-rule))
1109 annotation-arguments)
1110 ;; Else the annotation is not recognized. Ignore it silently,
1111 ;; so that GDB can add new annotations without causing
1112 ;; us to blow up.
1113 ))))
1114 ;;
1115 ;; Does the remaining text end in a partial line?
1116 ;; If it does, then keep part of the burst until we get more.
1117 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1118 burst)
1119 (progn
1120 ;; Everything before the potential marker start can be output.
1121 (setq output
1122 (gdb-concat-output output
1123 (substring burst 0 (match-beginning 0))))
1124 ;;
1125 ;; Everything after, we save, to combine with later input.
1126 (setq burst (substring burst (match-beginning 0))))
1127 ;;
1128 ;; In case we know the burst contains no partial annotations:
1129 (progn
1130 (setq output (gdb-concat-output output burst))
1131 (setq burst "")))
1132 ;;
1133 ;; Save the remaining burst for the next call to this function.
1134 (gdb-set-burst burst)
1135 output))
1136
1137 (defun gdb-concat-output (so-far new)
1138 (let ((sink (gdb-get-output-sink )))
1139 (cond
1140 ((eq sink 'user) (concat so-far new))
1141 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1142 ((eq sink 'emacs)
1143 (gdb-append-to-partial-output new)
1144 so-far)
1145 ((eq sink 'inferior)
1146 (gdb-append-to-inferior-io new)
1147 so-far)
1148 (t (error "Bogon output sink %S" sink)))))
1149
1150 (defun gdb-append-to-partial-output (string)
1151 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1152 (goto-char (point-max))
1153 (insert string)))
1154
1155 (defun gdb-clear-partial-output ()
1156 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
1157 (delete-region (point-min) (point-max))))
1158
1159 (defun gdb-append-to-inferior-io (string)
1160 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1161 (goto-char (point-max))
1162 (insert-before-markers string))
1163 (if (not (string-equal string ""))
1164 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1165
1166 (defun gdb-clear-inferior-io ()
1167 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1168 (delete-region (point-min) (point-max))))
1169 \f
1170
1171 ;; One trick is to have a command who's output is always available in a buffer
1172 ;; of it's own, and is always up to date. We build several buffers of this
1173 ;; type.
1174 ;;
1175 ;; There are two aspects to this: gdb has to tell us when the output for that
1176 ;; command might have changed, and we have to be able to run the command
1177 ;; behind the user's back.
1178 ;;
1179 ;; The idle input queue and the output phasing associated with the variable
1180 ;; gdb-output-sink help us to run commands behind the user's back.
1181 ;;
1182 ;; Below is the code for specificly managing buffers of output from one
1183 ;; command.
1184 ;;
1185
1186 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1187 ;; It adds an idle input for the command we are tracking. It should be the
1188 ;; annotation rule binding of whatever gdb sends to tell us this command
1189 ;; might have changed it's output.
1190 ;;
1191 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1192 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1193 ;; input in the input queue (see comment about ``gdb communications'' above).
1194
1195 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1196 output-handler)
1197 `(defun ,name (&optional ignored)
1198 (if (and (,demand-predicate)
1199 (not (member ',name
1200 (gdb-get-pending-triggers))))
1201 (progn
1202 (gdb-enqueue-idle-input
1203 (list ,gdb-command ',output-handler))
1204 (gdb-set-pending-triggers
1205 (cons ',name
1206 (gdb-get-pending-triggers)))))))
1207
1208 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1209 `(defun ,name ()
1210 (gdb-set-pending-triggers
1211 (delq ',trigger
1212 (gdb-get-pending-triggers)))
1213 (let ((buf (gdb-get-buffer ',buf-key)))
1214 (and buf
1215 (with-current-buffer buf
1216 (let ((p (point))
1217 (buffer-read-only nil))
1218 (delete-region (point-min) (point-max))
1219 (insert-buffer-substring (gdb-get-create-buffer
1220 'gdb-partial-output-buffer))
1221 (goto-char p)))))
1222 ;; put customisation here
1223 (,custom-defun)))
1224
1225 (defmacro def-gdb-auto-updated-buffer (buffer-key trigger-name gdb-command
1226 output-handler-name custom-defun)
1227 `(progn
1228 (def-gdb-auto-update-trigger ,trigger-name
1229 ;; The demand predicate:
1230 (lambda () (gdb-get-buffer ',buffer-key))
1231 ,gdb-command
1232 ,output-handler-name)
1233 (def-gdb-auto-update-handler ,output-handler-name
1234 ,trigger-name ,buffer-key ,custom-defun)))
1235
1236 \f
1237 ;;
1238 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1239 ;;
1240 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1241 'gdb-breakpoints-buffer-name
1242 'gdb-breakpoints-mode)
1243
1244 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1245 ;; This defines the auto update rule for buffers of type
1246 ;; `gdb-breakpoints-buffer'.
1247 ;;
1248 ;; It defines a function to serve as the annotation handler that
1249 ;; handles the `foo-invalidated' message. That function is called:
1250 gdb-invalidate-breakpoints
1251 ;;
1252 ;; To update the buffer, this command is sent to gdb.
1253 "server info breakpoints\n"
1254 ;;
1255 ;; This also defines a function to be the handler for the output
1256 ;; from the command above. That function will copy the output into
1257 ;; the appropriately typed buffer. That function will be called:
1258 gdb-info-breakpoints-handler
1259 ;; buffer specific functions
1260 gdb-info-breakpoints-custom)
1261
1262 (defvar gdb-cdir nil "Compilation directory.")
1263
1264 (defconst breakpoint-xpm-data "/* XPM */
1265 static char *magick[] = {
1266 /* columns rows colors chars-per-pixel */
1267 \"12 12 2 1\",
1268 \" c red\",
1269 \"+ c None\",
1270 /* pixels */
1271 \"++++++++++++\",
1272 \"+++ +++\",
1273 \"++ ++\",
1274 \"+ +\",
1275 \"+ +\",
1276 \"+ +\",
1277 \"+ +\",
1278 \"+ +\",
1279 \"+ +\",
1280 \"++ ++\",
1281 \"+++ +++\",
1282 \"++++++++++++\"
1283 };"
1284 "XPM data used for breakpoint icon.")
1285
1286 (defconst breakpoint-enabled-pbm-data
1287 "P1
1288 12 12\",
1289 0 0 0 0 0 0 0 0 0 0 0 0
1290 0 0 0 1 1 1 1 1 1 0 0 0
1291 0 0 1 1 1 1 1 1 1 1 0 0
1292 0 1 1 1 1 1 1 1 1 1 1 0
1293 0 1 1 1 1 1 1 1 1 1 1 0
1294 0 1 1 1 1 1 1 1 1 1 1 0
1295 0 1 1 1 1 1 1 1 1 1 1 0
1296 0 1 1 1 1 1 1 1 1 1 1 0
1297 0 1 1 1 1 1 1 1 1 1 1 0
1298 0 0 1 1 1 1 1 1 1 1 0 0
1299 0 0 0 1 1 1 1 1 1 0 0 0
1300 0 0 0 0 0 0 0 0 0 0 0 0"
1301 "PBM data used for enabled breakpoint icon.")
1302
1303 (defconst breakpoint-disabled-pbm-data
1304 "P1
1305 12 12\",
1306 0 0 0 0 0 0 0 0 0 0 0 0
1307 0 0 0 1 0 1 0 1 0 0 0 0
1308 0 0 1 0 1 0 1 0 1 0 0 0
1309 0 1 0 1 0 1 0 1 0 1 0 0
1310 0 0 1 0 1 0 1 0 1 0 1 0
1311 0 1 0 1 0 1 0 1 0 1 0 0
1312 0 0 1 0 1 0 1 0 1 0 1 0
1313 0 1 0 1 0 1 0 1 0 1 0 0
1314 0 0 1 0 1 0 1 0 1 0 1 0
1315 0 0 0 1 0 1 0 1 0 1 0 0
1316 0 0 0 0 1 0 1 0 1 0 0 0
1317 0 0 0 0 0 0 0 0 0 0 0 0"
1318 "PBM data used for disabled breakpoint icon.")
1319
1320 (defvar breakpoint-enabled-icon
1321 (find-image `((:type xpm :data ,breakpoint-xpm-data)
1322 (:type pbm :data ,breakpoint-enabled-pbm-data)))
1323 "Icon for enabled breakpoint in display margin")
1324
1325 (defvar breakpoint-disabled-icon
1326 (find-image `((:type xpm :data ,breakpoint-xpm-data :conversion disabled)
1327 (:type pbm :data ,breakpoint-disabled-pbm-data)))
1328 "Icon for disabled breakpoint in display margin")
1329
1330 ;;-put breakpoint icons in relevant margins (even those set in the GUD buffer)
1331 (defun gdb-info-breakpoints-custom ()
1332 (let ((flag)(address))
1333 ;;
1334 ;; remove all breakpoint-icons in source buffers but not assembler buffer
1335 (dolist (buffer (buffer-list))
1336 (with-current-buffer buffer
1337 (if (and (eq gud-minor-mode 'gdba)
1338 (not (string-match "^\*" (buffer-name))))
1339 (if (display-images-p)
1340 (remove-images (point-min) (point-max))
1341 (gdb-remove-strings (point-min) (point-max))))))
1342 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1343 (save-excursion
1344 (goto-char (point-min))
1345 (while (< (point) (- (point-max) 1))
1346 (forward-line 1)
1347 (if (looking-at "[^\t].*breakpoint")
1348 (progn
1349 (looking-at "[0-9]*\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)")
1350 (setq flag (char-after (match-beginning 1)))
1351 (beginning-of-line)
1352 (if (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t)
1353 (progn
1354 (looking-at "\\(\\S-*\\):\\([0-9]+\\)")
1355 (let ((line (match-string 2)) (buffer-read-only nil)
1356 (file (match-string 1)))
1357 (add-text-properties (point-at-bol) (point-at-eol)
1358 '(mouse-face highlight
1359 help-echo "mouse-2, RET: visit breakpoint"))
1360 (with-current-buffer
1361 (find-file-noselect
1362 (if (file-exists-p file) file
1363 (expand-file-name file gdb-cdir)))
1364 (save-current-buffer
1365 (set (make-local-variable 'gud-minor-mode) 'gdba)
1366 (set (make-local-variable 'tool-bar-map)
1367 gud-tool-bar-map)
1368 (setq left-margin-width 2)
1369 (if (get-buffer-window (current-buffer))
1370 (set-window-margins (get-buffer-window
1371 (current-buffer))
1372 left-margin-width
1373 right-margin-width)))
1374 ;; only want one breakpoint icon at each location
1375 (save-excursion
1376 (goto-line (string-to-number line))
1377 (let ((start (progn (beginning-of-line)
1378 (- (point) 1)))
1379 (end (progn (end-of-line) (+ (point) 1))))
1380 (if (display-images-p)
1381 (progn
1382 (remove-images start end)
1383 (if (eq ?y flag)
1384 (put-image breakpoint-enabled-icon
1385 (+ start 1)
1386 "breakpoint icon enabled"
1387 'left-margin)
1388 (put-image breakpoint-disabled-icon
1389 (+ start 1)
1390 "breakpoint icon disabled"
1391 'left-margin)))
1392 (gdb-remove-strings start end)
1393 (if (eq ?y flag)
1394 (gdb-put-string "B" (+ start 1))
1395 (gdb-put-string "b" (+ start 1))))))))))))
1396 (end-of-line)))))
1397 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1398
1399 (defun gdb-breakpoints-buffer-name ()
1400 (with-current-buffer gud-comint-buffer
1401 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1402
1403 (defun gdb-display-breakpoints-buffer ()
1404 (interactive)
1405 (gdb-display-buffer
1406 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1407
1408 (defun gdb-frame-breakpoints-buffer ()
1409 (interactive)
1410 (switch-to-buffer-other-frame
1411 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1412
1413 (defvar gdb-breakpoints-mode-map
1414 (let ((map (make-sparse-keymap))
1415 (menu (make-sparse-keymap "Breakpoints")))
1416 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1417 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1418 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1419
1420 (suppress-keymap map)
1421 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1422 (define-key map " " 'gdb-toggle-breakpoint)
1423 (define-key map "d" 'gdb-delete-breakpoint)
1424 (define-key map "\r" 'gdb-goto-breakpoint)
1425 (define-key map [mouse-2] 'gdb-mouse-goto-breakpoint)
1426 map))
1427
1428 (defun gdb-breakpoints-mode ()
1429 "Major mode for gdb breakpoints.
1430
1431 \\{gdb-breakpoints-mode-map}"
1432 (setq major-mode 'gdb-breakpoints-mode)
1433 (setq mode-name "Breakpoints")
1434 (use-local-map gdb-breakpoints-mode-map)
1435 (setq buffer-read-only t)
1436 (gdb-invalidate-breakpoints))
1437
1438 (defun gdb-toggle-breakpoint ()
1439 "Enable/disable the breakpoint at current line."
1440 (interactive)
1441 (save-excursion
1442 (beginning-of-line 1)
1443 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1444 (error "Not recognized as break/watchpoint line")
1445 (gdb-enqueue-input
1446 (list
1447 (concat
1448 (if (eq ?y (char-after (match-beginning 2)))
1449 "server disable "
1450 "server enable ")
1451 (match-string 1) "\n")
1452 'ignore)))))
1453
1454 (defun gdb-delete-breakpoint ()
1455 "Delete the breakpoint at current line."
1456 (interactive)
1457 (beginning-of-line 1)
1458 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1459 (error "Not recognized as break/watchpoint line")
1460 (gdb-enqueue-input
1461 (list (concat "server delete " (match-string 1) "\n") 'ignore))))
1462
1463 (defvar gdb-source-window nil)
1464
1465 (defun gdb-goto-breakpoint ()
1466 "Display the file in the source buffer at the breakpoint specified on the
1467 current line."
1468 (interactive)
1469 (save-excursion
1470 (beginning-of-line 1)
1471 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t)
1472 (looking-at "\\(\\S-*\\):\\([0-9]+\\)"))
1473 (if (match-string 2)
1474 (let ((line (match-string 2))
1475 (file (match-string 1)))
1476 (save-selected-window
1477 (select-window gdb-source-window)
1478 (switch-to-buffer (find-file-noselect
1479 (if (file-exists-p file)
1480 file
1481 (expand-file-name file gdb-cdir))))
1482 (goto-line (string-to-number line))))))
1483
1484 (defun gdb-mouse-goto-breakpoint (event)
1485 "Display the file in the source buffer at the selected breakpoint."
1486 (interactive "e")
1487 (mouse-set-point event)
1488 (gdb-goto-breakpoint))
1489 \f
1490 ;;
1491 ;; Frames buffer. This displays a perpetually correct bactracktrace
1492 ;; (from the command `where').
1493 ;;
1494 ;; Alas, if your stack is deep, it is costly.
1495 ;;
1496 (gdb-set-buffer-rules 'gdb-stack-buffer
1497 'gdb-stack-buffer-name
1498 'gdb-frames-mode)
1499
1500 (def-gdb-auto-updated-buffer gdb-stack-buffer
1501 gdb-invalidate-frames
1502 "server where\n"
1503 gdb-info-frames-handler
1504 gdb-info-frames-custom)
1505
1506 (defun gdb-info-frames-custom ()
1507 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1508 (save-excursion
1509 (let ((buffer-read-only nil))
1510 (goto-char (point-min))
1511 (while (< (point) (point-max))
1512 (add-text-properties (point-at-bol) (point-at-eol)
1513 '(mouse-face highlight
1514 help-echo "mouse-2, RET: Select frame"))
1515 (beginning-of-line)
1516 (if (or (looking-at "^#[0-9]*\\s-*\\S-* in \\(\\S-*\\)")
1517 (looking-at "^#[0-9]*\\s-*\\(\\S-*\\)"))
1518 (if (equal (match-string 1) gdb-current-frame)
1519 (put-text-property (point-at-bol) (point-at-eol)
1520 'face
1521 `(:background ,(face-attribute 'default :foreground)
1522 :foreground ,(face-attribute 'default :background)))))
1523 (forward-line 1))))))
1524
1525 (defun gdb-stack-buffer-name ()
1526 (with-current-buffer gud-comint-buffer
1527 (concat "*stack frames of " (gdb-get-target-string) "*")))
1528
1529 (defun gdb-display-stack-buffer ()
1530 (interactive)
1531 (gdb-display-buffer
1532 (gdb-get-create-buffer 'gdb-stack-buffer)))
1533
1534 (defun gdb-frame-stack-buffer ()
1535 (interactive)
1536 (switch-to-buffer-other-frame
1537 (gdb-get-create-buffer 'gdb-stack-buffer)))
1538
1539 (defvar gdb-frames-mode-map
1540 (let ((map (make-sparse-keymap)))
1541 (suppress-keymap map)
1542 (define-key map "\r" 'gdb-frames-select)
1543 (define-key map [mouse-2] 'gdb-frames-mouse-select)
1544 map))
1545
1546 (defun gdb-frames-mode ()
1547 "Major mode for gdb frames.
1548
1549 \\{gdb-frames-mode-map}"
1550 (setq major-mode 'gdb-frames-mode)
1551 (setq mode-name "Frames")
1552 (setq buffer-read-only t)
1553 (use-local-map gdb-frames-mode-map)
1554 (font-lock-mode -1)
1555 (gdb-invalidate-frames))
1556
1557 (defun gdb-get-frame-number ()
1558 (save-excursion
1559 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t))
1560 (n (or (and pos (match-string-no-properties 1)) "0")))
1561 n)))
1562
1563 (defun gdb-frames-select ()
1564 "Make the frame on the current line become the current frame and display the
1565 source in the source buffer."
1566 (interactive)
1567 (gdb-enqueue-input
1568 (list (concat "server frame " (gdb-get-frame-number) "\n") 'ignore))
1569 (gud-display-frame))
1570
1571 (defun gdb-frames-mouse-select (event)
1572 "Make the selected frame become the current frame and display the source in
1573 the source buffer."
1574 (interactive "e")
1575 (mouse-set-point event)
1576 (gdb-frames-select))
1577 \f
1578 ;;
1579 ;; Threads buffer. This displays a selectable thread list.
1580 ;;
1581 (gdb-set-buffer-rules 'gdb-threads-buffer
1582 'gdb-threads-buffer-name
1583 'gdb-threads-mode)
1584
1585 (def-gdb-auto-updated-buffer gdb-threads-buffer
1586 gdb-invalidate-threads
1587 "info threads\n"
1588 gdb-info-threads-handler
1589 gdb-info-threads-custom)
1590
1591 (defun gdb-info-threads-custom ()
1592 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1593 (let ((buffer-read-only nil))
1594 (goto-char (point-min))
1595 (while (< (point) (point-max))
1596 (add-text-properties (point-at-bol) (point-at-eol)
1597 '(mouse-face highlight
1598 help-echo "mouse-2, RET: select thread"))
1599 (forward-line 1)))))
1600
1601 (defun gdb-threads-buffer-name ()
1602 (with-current-buffer gud-comint-buffer
1603 (concat "*threads of " (gdb-get-target-string) "*")))
1604
1605 (defun gdb-display-threads-buffer ()
1606 (interactive)
1607 (gdb-display-buffer
1608 (gdb-get-create-buffer 'gdb-threads-buffer)))
1609
1610 (defun gdb-frame-threads-buffer ()
1611 (interactive)
1612 (switch-to-buffer-other-frame
1613 (gdb-get-create-buffer 'gdb-threads-buffer)))
1614
1615 (defvar gdb-threads-mode-map
1616 (let ((map (make-sparse-keymap)))
1617 (suppress-keymap map)
1618 (define-key map "\r" 'gdb-threads-select)
1619 (define-key map [mouse-2] 'gdb-threads-mouse-select)
1620 map))
1621
1622 (defun gdb-threads-mode ()
1623 "Major mode for gdb frames.
1624
1625 \\{gdb-frames-mode-map}"
1626 (setq major-mode 'gdb-threads-mode)
1627 (setq mode-name "Threads")
1628 (setq buffer-read-only t)
1629 (use-local-map gdb-threads-mode-map)
1630 (gdb-invalidate-threads))
1631
1632 (defun gdb-get-thread-number ()
1633 (save-excursion
1634 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1635 (match-string-no-properties 1)))
1636
1637
1638 (defun gdb-threads-select ()
1639 "Make the thread on the current line become the current thread and display the
1640 source in the source buffer."
1641 (interactive)
1642 (gdb-enqueue-input
1643 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1644 (gud-display-frame))
1645
1646 (defun gdb-threads-mouse-select (event)
1647 "Make the selected frame become the current frame and display the source in
1648 the source buffer."
1649 (interactive "e")
1650 (mouse-set-point event)
1651 (gdb-threads-select))
1652 \f
1653 ;;
1654 ;; Registers buffer.
1655 ;;
1656 (gdb-set-buffer-rules 'gdb-registers-buffer
1657 'gdb-registers-buffer-name
1658 'gdb-registers-mode)
1659
1660 (def-gdb-auto-updated-buffer gdb-registers-buffer
1661 gdb-invalidate-registers
1662 "server info registers\n"
1663 gdb-info-registers-handler
1664 gdb-info-registers-custom)
1665
1666 (defun gdb-info-registers-custom ())
1667
1668 (defvar gdb-registers-mode-map
1669 (let ((map (make-sparse-keymap)))
1670 (suppress-keymap map)
1671 map))
1672
1673 (defun gdb-registers-mode ()
1674 "Major mode for gdb registers.
1675
1676 \\{gdb-registers-mode-map}"
1677 (setq major-mode 'gdb-registers-mode)
1678 (setq mode-name "Registers")
1679 (setq buffer-read-only t)
1680 (use-local-map gdb-registers-mode-map)
1681 (gdb-invalidate-registers))
1682
1683 (defun gdb-registers-buffer-name ()
1684 (with-current-buffer gud-comint-buffer
1685 (concat "*registers of " (gdb-get-target-string) "*")))
1686
1687 (defun gdb-display-registers-buffer ()
1688 (interactive)
1689 (gdb-display-buffer
1690 (gdb-get-create-buffer 'gdb-registers-buffer)))
1691
1692 (defun gdb-frame-registers-buffer ()
1693 (interactive)
1694 (switch-to-buffer-other-frame
1695 (gdb-get-create-buffer 'gdb-registers-buffer)))
1696 \f
1697 ;;
1698 ;; Locals buffer.
1699 ;;
1700 (gdb-set-buffer-rules 'gdb-locals-buffer
1701 'gdb-locals-buffer-name
1702 'gdb-locals-mode)
1703
1704 (def-gdb-auto-updated-buffer gdb-locals-buffer
1705 gdb-invalidate-locals
1706 "server info locals\n"
1707 gdb-info-locals-handler
1708 gdb-info-locals-custom)
1709
1710 ;; Abbreviate for arrays and structures.
1711 ;; These can be expanded using gud-display.
1712 (defun gdb-info-locals-handler nil
1713 (gdb-set-pending-triggers (delq 'gdb-invalidate-locals
1714 (gdb-get-pending-triggers)))
1715 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
1716 (with-current-buffer buf
1717 (goto-char (point-min))
1718 (while (re-search-forward "^ .*\n" nil t)
1719 (replace-match "" nil nil))
1720 (goto-char (point-min))
1721 (while (re-search-forward "{[-0-9, {}\]*\n" nil t)
1722 (replace-match "(array);\n" nil nil))
1723 (goto-char (point-min))
1724 (while (re-search-forward "{.*=.*\n" nil t)
1725 (replace-match "(structure);\n" nil nil))))
1726 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
1727 (and buf (with-current-buffer buf
1728 (let ((p (point))
1729 (buffer-read-only nil))
1730 (delete-region (point-min) (point-max))
1731 (insert-buffer-substring (gdb-get-create-buffer
1732 'gdb-partial-output-buffer))
1733 (goto-char p)))))
1734 (run-hooks 'gdb-info-locals-hook))
1735
1736 (defun gdb-info-locals-custom ()
1737 nil)
1738
1739 (defvar gdb-locals-mode-map
1740 (let ((map (make-sparse-keymap)))
1741 (suppress-keymap map)
1742 map))
1743
1744 (defun gdb-locals-mode ()
1745 "Major mode for gdb locals.
1746
1747 \\{gdb-locals-mode-map}"
1748 (setq major-mode 'gdb-locals-mode)
1749 (setq mode-name "Locals")
1750 (setq buffer-read-only t)
1751 (use-local-map gdb-locals-mode-map)
1752 (gdb-invalidate-locals))
1753
1754 (defun gdb-locals-buffer-name ()
1755 (with-current-buffer gud-comint-buffer
1756 (concat "*locals of " (gdb-get-target-string) "*")))
1757
1758 (defun gdb-display-locals-buffer ()
1759 (interactive)
1760 (gdb-display-buffer
1761 (gdb-get-create-buffer 'gdb-locals-buffer)))
1762
1763 (defun gdb-frame-locals-buffer ()
1764 (interactive)
1765 (switch-to-buffer-other-frame
1766 (gdb-get-create-buffer 'gdb-locals-buffer)))
1767 \f
1768 ;;
1769 ;; Display expression buffer.
1770 ;;
1771 (gdb-set-buffer-rules 'gdb-display-buffer
1772 'gdb-display-buffer-name
1773 'gdb-display-mode)
1774
1775 (def-gdb-auto-updated-buffer gdb-display-buffer
1776 ;; `gdb-display-buffer'.
1777 gdb-invalidate-display
1778 "server info display\n"
1779 gdb-info-display-handler
1780 gdb-info-display-custom)
1781
1782 (defun gdb-info-display-custom ()
1783 (let ((display-list nil))
1784 (with-current-buffer (gdb-get-buffer 'gdb-display-buffer)
1785 (goto-char (point-min))
1786 (while (< (point) (- (point-max) 1))
1787 (forward-line 1)
1788 (if (looking-at "\\([0-9]+\\): \\([ny]\\)")
1789 (setq display-list
1790 (cons (string-to-int (match-string 1)) display-list)))
1791 (end-of-line)))
1792 (if (not (display-graphic-p))
1793 (progn
1794 (dolist (buffer (buffer-list))
1795 (if (string-match "\\*display \\([0-9]+\\)\\*" (buffer-name buffer))
1796 (progn
1797 (let ((number
1798 (match-string 1 (buffer-name buffer))))
1799 (if (not (memq (string-to-int number) display-list))
1800 (kill-buffer
1801 (get-buffer (concat "*display " number "*")))))))))
1802 (gdb-delete-frames display-list))))
1803
1804 (defun gdb-delete-frames (display-list)
1805 (dolist (frame (frame-list))
1806 (let ((frame-name (frame-parameter frame 'name)))
1807 (if (string-match "\\*display \\([0-9]+\\)\\*" frame-name)
1808 (progn
1809 (let ((number (match-string 1 frame-name)))
1810 (if (not (memq (string-to-int number) display-list))
1811 (progn (kill-buffer
1812 (get-buffer (concat "*display " number "*")))
1813 (delete-frame frame)))))))))
1814
1815 (defvar gdb-display-mode-map
1816 (let ((map (make-sparse-keymap))
1817 (menu (make-sparse-keymap "Display")))
1818 (define-key menu [toggle] '("Toggle" . gdb-toggle-display))
1819 (define-key menu [delete] '("Delete" . gdb-delete-display))
1820
1821 (suppress-keymap map)
1822 (define-key map [menu-bar display] (cons "Display" menu))
1823 (define-key map " " 'gdb-toggle-display)
1824 (define-key map "d" 'gdb-delete-display)
1825 map))
1826
1827 (defun gdb-display-mode ()
1828 "Major mode for gdb display.
1829
1830 \\{gdb-display-mode-map}"
1831 (setq major-mode 'gdb-display-mode)
1832 (setq mode-name "Display")
1833 (setq buffer-read-only t)
1834 (use-local-map gdb-display-mode-map)
1835 (gdb-invalidate-display))
1836
1837 (defun gdb-display-buffer-name ()
1838 (with-current-buffer gud-comint-buffer
1839 (concat "*Displayed expressions of " (gdb-get-target-string) "*")))
1840
1841 (defun gdb-display-display-buffer ()
1842 (interactive)
1843 (gdb-display-buffer
1844 (gdb-get-create-buffer 'gdb-display-buffer)))
1845
1846 (defun gdb-frame-display-buffer ()
1847 (interactive)
1848 (switch-to-buffer-other-frame
1849 (gdb-get-create-buffer 'gdb-display-buffer)))
1850
1851 (defun gdb-toggle-display ()
1852 "Enable/disable the displayed expression at current line."
1853 (interactive)
1854 (save-excursion
1855 (beginning-of-line 1)
1856 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)"))
1857 (error "No expression on this line")
1858 (gdb-enqueue-input
1859 (list
1860 (concat
1861 (if (eq ?y (char-after (match-beginning 2)))
1862 "server disable display "
1863 "server enable display ")
1864 (match-string 1) "\n")
1865 'ignore)))))
1866
1867 (defun gdb-delete-display ()
1868 "Delete the displayed expression at current line."
1869 (interactive)
1870 (with-current-buffer (gdb-get-buffer 'gdb-display-buffer)
1871 (beginning-of-line 1)
1872 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)"))
1873 (error "No expression on this line")
1874 (let ((number (match-string 1)))
1875 (gdb-enqueue-input
1876 (list (concat "server delete display " number "\n") 'ignore))))))
1877
1878 (defvar gdb-expressions-mode-map
1879 (let ((map (make-sparse-keymap)))
1880 (suppress-keymap map)
1881 (define-key map "v" 'gdb-array-visualise)
1882 (define-key map "q" 'gdb-delete-expression)
1883 (define-key map [mouse-3] 'gdb-expressions-popup-menu)
1884 map))
1885
1886 (defvar gdb-expressions-mode-menu
1887 '("GDB Expressions Commands"
1888 "----"
1889 ["Visualise" gdb-array-visualise t]
1890 ["Delete" gdb-delete-expression t])
1891 "Menu for `gdb-expressions-mode'.")
1892
1893 (defun gdb-expressions-popup-menu (event)
1894 "Explicit Popup menu as this buffer doesn't have a menubar."
1895 (interactive "@e")
1896 (mouse-set-point event)
1897 (popup-menu gdb-expressions-mode-menu))
1898
1899 (defun gdb-expressions-mode ()
1900 "Major mode for display expressions.
1901
1902 \\{gdb-expressions-mode-map}"
1903 (setq major-mode 'gdb-expressions-mode)
1904 (setq mode-name "Expressions")
1905 (use-local-map gdb-expressions-mode-map)
1906 (make-local-variable 'gdb-display-number)
1907 (make-local-variable 'gdb-values)
1908 (make-local-variable 'gdb-expression)
1909 (set (make-local-variable 'gdb-display-string) nil)
1910 (set (make-local-variable 'gdb-dive-display-number) nil)
1911 (set (make-local-variable 'gud-minor-mode) 'gdba)
1912 (set (make-local-variable 'gdb-array-start) (make-vector 16 '-1))
1913 (set (make-local-variable 'gdb-array-stop) (make-vector 16 '-1))
1914 (set (make-local-variable 'gdb-array-size) (make-vector 16 '-1))
1915 (setq buffer-read-only t))
1916 \f
1917
1918 ;;;; Window management
1919
1920 ;;; The way we abuse the dedicated-p flag is pretty gross, but seems
1921 ;;; to do the right thing. Seeing as there is no way for Lisp code to
1922 ;;; get at the use_time field of a window, I'm not sure there exists a
1923 ;;; more elegant solution without writing C code.
1924
1925 (defun gdb-display-buffer (buf &optional size)
1926 (let ((must-split nil)
1927 (answer nil))
1928 (unwind-protect
1929 (progn
1930 (walk-windows
1931 #'(lambda (win)
1932 (if (or (eq gud-comint-buffer (window-buffer win))
1933 (eq gdb-source-window win))
1934 (set-window-dedicated-p win t))))
1935 (setq answer (get-buffer-window buf))
1936 (if (not answer)
1937 (let ((window (get-lru-window)))
1938 (if window
1939 (progn
1940 (set-window-buffer window buf)
1941 (setq answer window))
1942 (setq must-split t)))))
1943 (walk-windows
1944 #'(lambda (win)
1945 (if (or (eq gud-comint-buffer (window-buffer win))
1946 (eq gdb-source-window win))
1947 (set-window-dedicated-p win nil)))))
1948 (if must-split
1949 (let* ((largest (get-largest-window))
1950 (cur-size (window-height largest))
1951 (new-size (and size (< size cur-size) (- cur-size size))))
1952 (setq answer (split-window largest new-size))
1953 (set-window-buffer answer buf)))
1954 answer))
1955
1956 (defun gdb-display-source-buffer (buffer)
1957 (if (eq gdb-selected-view 'source)
1958 (progn
1959 (if (window-live-p gdb-source-window)
1960 (set-window-buffer gdb-source-window buffer)
1961 (gdb-display-buffer buffer)
1962 (setq gdb-source-window (get-buffer-window buffer)))
1963 gdb-source-window)
1964 (if (window-live-p gdb-source-window)
1965 (set-window-buffer gdb-source-window
1966 (gdb-get-buffer 'gdb-assembler-buffer))
1967 (let ((buf (gdb-get-buffer 'gdb-assembler-buffer)))
1968 (gdb-display-buffer buf)
1969 (setq gdb-source-window (get-buffer-window buf))))
1970 nil))
1971
1972 \f
1973 ;;; Shared keymap initialization:
1974
1975 (let ((menu (make-sparse-keymap "GDB-Frames")))
1976 (define-key gud-menu-map [frames]
1977 `(menu-item "GDB-Frames" ,menu :visible (eq gud-minor-mode 'gdba)))
1978 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
1979 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
1980 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
1981 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
1982 (define-key menu [breakpoints] '("Breakpoints" . gdb-frame-breakpoints-buffer))
1983 (define-key menu [display] '("Display" . gdb-frame-display-buffer))
1984 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
1985 ; (define-key menu [assembler] '("Assembler" . gdb-frame-assembler-buffer))
1986 )
1987
1988 (let ((menu (make-sparse-keymap "GDB-Windows")))
1989 (define-key gud-menu-map [displays]
1990 `(menu-item "GDB-Windows" ,menu :visible (eq gud-minor-mode 'gdba)))
1991 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
1992 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
1993 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
1994 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
1995 (define-key menu [breakpoints] '("Breakpoints" . gdb-display-breakpoints-buffer))
1996 (define-key menu [display] '("Display" . gdb-display-display-buffer))
1997 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
1998 ; (define-key menu [assembler] '("Assembler" . gdb-display-assembler-buffer))
1999 )
2000
2001 (let ((menu (make-sparse-keymap "View")))
2002 (define-key gud-menu-map [view]
2003 `(menu-item "View" ,menu :visible (eq gud-minor-mode 'gdba)))
2004 ; (define-key menu [both] '(menu-item "Both" gdb-view-both
2005 ; :help "Display both source and assembler"
2006 ; :button (:radio . (eq gdb-selected-view 'both))))
2007 (define-key menu [assembler] '(menu-item "Assembler" gdb-view-assembler
2008 :help "Display assembler only"
2009 :button (:radio . (eq gdb-selected-view 'assembler))))
2010 (define-key menu [source] '(menu-item "Source" gdb-view-source-function
2011 :help "Display source only"
2012 :button (:radio . (eq gdb-selected-view 'source)))))
2013
2014 (let ((menu (make-sparse-keymap "GDB-UI")))
2015 (define-key gud-menu-map [ui]
2016 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
2017 (define-key menu [gdb-restore-windows]
2018 '("Restore window layout" . gdb-restore-windows))
2019 (define-key menu [gdb-many-windows]
2020 (menu-bar-make-toggle gdb-many-windows gdb-many-windows
2021 "Display other windows" "Many Windows %s"
2022 "Display locals, stack and breakpoint information")))
2023
2024 (defun gdb-frame-gdb-buffer ()
2025 (interactive)
2026 (switch-to-buffer-other-frame
2027 (gdb-get-create-buffer 'gdba)))
2028
2029 (defun gdb-display-gdb-buffer ()
2030 (interactive)
2031 (gdb-display-buffer
2032 (gdb-get-create-buffer 'gdba)))
2033
2034 (defvar gdb-main-file nil "Source file from which program execution begins.")
2035
2036 (defun gdb-view-source-function ()
2037 (interactive)
2038 (if gdb-view-source
2039 (if gud-last-last-frame
2040 (set-window-buffer gdb-source-window
2041 (gud-find-file (car gud-last-last-frame)))
2042 (set-window-buffer gdb-source-window (gud-find-file gdb-main-file))))
2043 (setq gdb-selected-view 'source))
2044
2045 (defun gdb-view-assembler()
2046 (interactive)
2047 (set-window-buffer gdb-source-window
2048 (gdb-get-create-buffer 'gdb-assembler-buffer))
2049 (setq gdb-selected-view 'assembler))
2050
2051 ;(defun gdb-view-both()
2052 ;(interactive)
2053 ;(setq gdb-selected-view 'both))
2054
2055 ;; layout for all the windows
2056 (defun gdb-setup-windows ()
2057 (gdb-display-locals-buffer)
2058 (gdb-display-stack-buffer)
2059 (delete-other-windows)
2060 (gdb-display-breakpoints-buffer)
2061 (gdb-display-display-buffer)
2062 (delete-other-windows)
2063 (switch-to-buffer gud-comint-buffer)
2064 (split-window nil ( / ( * (window-height) 3) 4))
2065 (split-window nil ( / (window-height) 3))
2066 (split-window-horizontally)
2067 (other-window 1)
2068 (switch-to-buffer (gdb-locals-buffer-name))
2069 (other-window 1)
2070 (if (and gdb-view-source
2071 (eq gdb-selected-view 'source))
2072 (switch-to-buffer
2073 (if gud-last-last-frame
2074 (gud-find-file (car gud-last-last-frame))
2075 (gud-find-file gdb-main-file)))
2076 (switch-to-buffer (gdb-get-create-buffer 'gdb-assembler-buffer)))
2077 (setq gdb-source-window (get-buffer-window (current-buffer)))
2078 (split-window-horizontally)
2079 (other-window 1)
2080 (switch-to-buffer (gdb-inferior-io-name))
2081 (other-window 1)
2082 (switch-to-buffer (gdb-stack-buffer-name))
2083 (split-window-horizontally)
2084 (other-window 1)
2085 (switch-to-buffer (gdb-breakpoints-buffer-name))
2086 (other-window 1))
2087
2088 (defcustom gdb-many-windows nil
2089 "Nil means that gdb starts with just two windows : the GUD and
2090 the source buffer."
2091 :type 'boolean
2092 :group 'gud)
2093
2094 (defun gdb-many-windows (arg)
2095 "Toggle the number of windows in the basic arrangement."
2096 (interactive "P")
2097 (setq gdb-many-windows
2098 (if (null arg)
2099 (not gdb-many-windows)
2100 (> (prefix-numeric-value arg) 0)))
2101 (gdb-restore-windows))
2102
2103 (defun gdb-restore-windows ()
2104 "Restore the basic arrangement of windows used by gdba.
2105 This arrangement depends on the value of `gdb-many-windows'."
2106 (interactive)
2107 (if gdb-many-windows
2108 (progn
2109 (switch-to-buffer gud-comint-buffer)
2110 (delete-other-windows)
2111 (gdb-setup-windows))
2112 (switch-to-buffer gud-comint-buffer)
2113 (delete-other-windows)
2114 (split-window)
2115 (other-window 1)
2116 (if (and gdb-view-source
2117 (eq gdb-selected-view 'source))
2118 (switch-to-buffer
2119 (if gud-last-last-frame
2120 (gud-find-file (car gud-last-last-frame))
2121 (gud-find-file gdb-main-file)))
2122 (switch-to-buffer (gdb-get-create-buffer 'gdb-assembler-buffer)))
2123 (setq gdb-source-window (get-buffer-window (current-buffer)))
2124 (other-window 1)))
2125
2126 (defun gdb-reset ()
2127 "Exit a debugging session cleanly by killing the gdb buffers and resetting
2128 the source buffers."
2129 (gdb-delete-frames '())
2130 (dolist (buffer (buffer-list))
2131 (if (not (eq buffer gud-comint-buffer))
2132 (with-current-buffer buffer
2133 (if (eq gud-minor-mode 'gdba)
2134 (if (string-match "^\*.+*$" (buffer-name))
2135 (kill-buffer nil)
2136 (if (display-images-p)
2137 (remove-images (point-min) (point-max))
2138 (gdb-remove-strings (point-min) (point-max)))
2139 (setq left-margin-width 0)
2140 (setq gud-minor-mode nil)
2141 (kill-local-variable 'tool-bar-map)
2142 (setq gud-running nil)
2143 (if (get-buffer-window (current-buffer))
2144 (set-window-margins (get-buffer-window
2145 (current-buffer))
2146 left-margin-width
2147 right-margin-width))))))))
2148
2149 (defun gdb-source-info ()
2150 "Find the source file where the program starts and displays it with related
2151 buffers."
2152 (goto-char (point-min))
2153 (if (search-forward "directory is " nil t)
2154 (progn
2155 (if (looking-at "\\S-*:\\(\\S-*\\)")
2156 (setq gdb-cdir (match-string 1))
2157 (looking-at "\\S-*")
2158 (setq gdb-cdir (match-string 0)))
2159 (search-forward "Located in ")
2160 (looking-at "\\S-*")
2161 (setq gdb-main-file (match-string 0)))
2162 (setq gdb-view-source nil))
2163 (delete-other-windows)
2164 (switch-to-buffer gud-comint-buffer)
2165 (if gdb-many-windows
2166 (gdb-setup-windows)
2167 (gdb-display-breakpoints-buffer)
2168 (gdb-display-display-buffer)
2169 (delete-other-windows)
2170 (split-window)
2171 (other-window 1)
2172 (if gdb-view-source
2173 (switch-to-buffer
2174 (if gud-last-last-frame
2175 (gud-find-file (car gud-last-last-frame))
2176 (gud-find-file gdb-main-file)))
2177 (switch-to-buffer (gdb-get-create-buffer 'gdb-assembler-buffer)))
2178 (setq gdb-source-window (get-buffer-window (current-buffer)))
2179 (other-window 1)))
2180
2181 ;;from put-image
2182 (defun gdb-put-string (putstring pos)
2183 "Put string PUTSTRING in front of POS in the current buffer.
2184 PUTSTRING is displayed by putting an overlay into the current buffer with a
2185 `before-string' STRING that has a `display' property whose value is
2186 PUTSTRING."
2187 (let ((gdb-string "x")
2188 (buffer (current-buffer)))
2189 (let ((overlay (make-overlay pos pos buffer))
2190 (prop (list (list 'margin 'left-margin) putstring)))
2191 (put-text-property 0 (length gdb-string) 'display prop gdb-string)
2192 (overlay-put overlay 'put-break t)
2193 (overlay-put overlay 'before-string gdb-string))))
2194
2195 ;;from remove-images
2196 (defun gdb-remove-strings (start end &optional buffer)
2197 "Remove strings between START and END in BUFFER.
2198 Remove only strings that were put in BUFFER with calls to `put-string'.
2199 BUFFER nil or omitted means use the current buffer."
2200 (unless buffer
2201 (setq buffer (current-buffer)))
2202 (let ((overlays (overlays-in start end)))
2203 (while overlays
2204 (let ((overlay (car overlays)))
2205 (when (overlay-get overlay 'put-break)
2206 (delete-overlay overlay)))
2207 (setq overlays (cdr overlays)))))
2208
2209 (defun gdb-put-arrow (putstring pos)
2210 "Put arrow string PUTSTRING in the left margin in front of POS
2211 in the current buffer. PUTSTRING is displayed by putting an
2212 overlay into the current buffer with a `before-string'
2213 \"gdb-arrow\" that has a `display' property whose value is
2214 PUTSTRING. POS may be an integer or marker."
2215 (let ((gdb-string "gdb-arrow")
2216 (buffer (current-buffer)))
2217 (let ((overlay (make-overlay pos pos buffer))
2218 (prop (list (list 'margin 'left-margin) putstring)))
2219 (put-text-property 0 (length gdb-string) 'display prop gdb-string)
2220 (overlay-put overlay 'put-arrow t)
2221 (overlay-put overlay 'before-string gdb-string))))
2222
2223 (defun gdb-remove-arrow (&optional buffer)
2224 "Remove arrow in BUFFER.
2225 Remove only images that were put in BUFFER with calls to `put-arrow'.
2226 BUFFER nil or omitted means use the current buffer."
2227 (unless buffer
2228 (setq buffer (current-buffer)))
2229 (let ((overlays (overlays-in (point-min) (point-max))))
2230 (while overlays
2231 (let ((overlay (car overlays)))
2232 (when (overlay-get overlay 'put-arrow)
2233 (delete-overlay overlay)))
2234 (setq overlays (cdr overlays)))))
2235
2236 (defun gdb-array-visualise ()
2237 "Visualise arrays and slices using graph program from plotutils."
2238 (interactive)
2239 (when (and (display-graphic-p) gdb-display-string)
2240 (let ((n 0) m)
2241 (catch 'multi-dimensional
2242 (while (eq (aref gdb-array-start n) (aref gdb-array-stop n))
2243 (setq n (+ n 1)))
2244 (setq m (+ n 1))
2245 (while (< m (length gdb-array-start))
2246 (if (not (eq (aref gdb-array-start m) (aref gdb-array-stop m)))
2247 (progn
2248 (x-popup-dialog
2249 t `(,(concat "Only one dimensional data can be visualised.\n"
2250 "Use an array slice to reduce the number of\n"
2251 "dimensions") ("OK" t)))
2252 (throw 'multi-dimensional nil))
2253 (setq m (+ m 1))))
2254 (shell-command (concat "echo" gdb-display-string " | graph -a 1 "
2255 (int-to-string (aref gdb-array-start n))
2256 " -x "
2257 (int-to-string (aref gdb-array-start n))
2258 " "
2259 (int-to-string (aref gdb-array-stop n))
2260 " 1 -T X"))))))
2261
2262 (defun gdb-delete-expression ()
2263 "Delete displayed expression and its frame."
2264 (interactive)
2265 (gdb-enqueue-input
2266 (list (concat "server delete display " gdb-display-number "\n")
2267 'ignore)))
2268 \f
2269 ;;
2270 ;; Assembler buffer.
2271 ;;
2272 (gdb-set-buffer-rules 'gdb-assembler-buffer
2273 'gdb-assembler-buffer-name
2274 'gdb-assembler-mode)
2275
2276 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2277 gdb-invalidate-assembler
2278 (concat "server disassemble " gdb-current-address "\n")
2279 gdb-assembler-handler
2280 gdb-assembler-custom)
2281
2282 (defun gdb-assembler-custom ()
2283 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2284 (gdb-arrow-position 1) (address) (flag))
2285 (with-current-buffer buffer
2286 (if (not (equal gdb-current-address "main"))
2287 (progn
2288 (gdb-remove-arrow)
2289 (goto-char (point-min))
2290 (if (re-search-forward gdb-current-address nil t)
2291 (progn
2292 (setq gdb-arrow-position (point))
2293 (gdb-put-arrow "=>" (point))))))
2294 ;; remove all breakpoint-icons in assembler buffer before updating.
2295 (if (display-images-p)
2296 (remove-images (point-min) (point-max))
2297 (gdb-remove-strings (point-min) (point-max))))
2298 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2299 (goto-char (point-min))
2300 (while (< (point) (- (point-max) 1))
2301 (forward-line 1)
2302 (if (looking-at "[^\t].*breakpoint")
2303 (progn
2304 (looking-at
2305 "[0-9]*\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)\\s-*0x\\(\\S-*\\)")
2306 (setq flag (char-after (match-beginning 1)))
2307 (setq address (match-string 2))
2308 ;; remove leading 0s from output of info break.
2309 (if (string-match "^0+\\(.*\\)" address)
2310 (setq address (match-string 1 address)))
2311 (with-current-buffer buffer
2312 (goto-char (point-min))
2313 (if (re-search-forward address nil t)
2314 (let ((start (progn (beginning-of-line) (- (point) 1)))
2315 (end (progn (end-of-line) (+ (point) 1))))
2316 (if (display-images-p)
2317 (progn
2318 (remove-images start end)
2319 (if (eq ?y flag)
2320 (put-image breakpoint-enabled-icon
2321 (+ start 1)
2322 "breakpoint icon enabled"
2323 'left-margin)
2324 (put-image breakpoint-disabled-icon
2325 (+ start 1)
2326 "breakpoint icon disabled"
2327 'left-margin)))
2328 (gdb-remove-strings start end)
2329 (if (eq ?y flag)
2330 (gdb-put-string "B" (+ start 1))
2331 (gdb-put-string "b" (+ start 1)))))))))))
2332 (if (not (equal gdb-current-address "main"))
2333 (set-window-point (get-buffer-window buffer) gdb-arrow-position))))
2334
2335 (defvar gdb-assembler-mode-map
2336 (let ((map (make-sparse-keymap)))
2337 (suppress-keymap map)
2338 map))
2339
2340 (defun gdb-assembler-mode ()
2341 "Major mode for viewing code assembler.
2342
2343 \\{gdb-assembler-mode-map}"
2344 (setq major-mode 'gdb-assembler-mode)
2345 (setq mode-name "Assembler")
2346 (setq left-margin-width 2)
2347 (setq fringes-outside-margins t)
2348 (setq buffer-read-only t)
2349 (use-local-map gdb-assembler-mode-map)
2350 (gdb-invalidate-assembler))
2351
2352 (defun gdb-assembler-buffer-name ()
2353 (with-current-buffer gud-comint-buffer
2354 (concat "*Machine Code " (gdb-get-target-string) "*")))
2355
2356 (defun gdb-display-assembler-buffer ()
2357 (interactive)
2358 (gdb-display-buffer
2359 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2360
2361 (defun gdb-frame-assembler-buffer ()
2362 (interactive)
2363 (switch-to-buffer-other-frame
2364 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2365
2366 ;; modified because if gdb-current-address has changed value a new command
2367 ;; must be enqueued to update the buffer with the new output
2368 (defun gdb-invalidate-assembler (&optional ignored)
2369 (if (gdb-get-buffer 'gdb-assembler-buffer)
2370 (progn
2371 (unless (string-equal gdb-current-frame gdb-previous-frame)
2372 (if (or (not (member 'gdb-invalidate-assembler
2373 (gdb-get-pending-triggers)))
2374 (not (string-equal gdb-current-address
2375 gdb-previous-address)))
2376 (progn
2377 ;; take previous disassemble command off the queue
2378 (with-current-buffer gud-comint-buffer
2379 (let ((queue (gdb-get-idle-input-queue)) (item))
2380 (dolist (item queue)
2381 (if (equal (cdr item) '(gdb-assembler-handler))
2382 (gdb-set-idle-input-queue
2383 (delete item (gdb-get-idle-input-queue)))))))
2384 (gdb-enqueue-idle-input
2385 (list (concat "server disassemble " gdb-current-address "\n")
2386 'gdb-assembler-handler))
2387 (gdb-set-pending-triggers
2388 (cons 'gdb-invalidate-assembler
2389 (gdb-get-pending-triggers)))
2390 (setq gdb-previous-address gdb-current-address)
2391 (setq gdb-previous-frame gdb-current-frame)))))))
2392
2393 (defun gdb-get-current-frame ()
2394 (if (not (member 'gdb-get-current-frame (gdb-get-pending-triggers)))
2395 (progn
2396 (gdb-enqueue-idle-input
2397 (list (concat "server info frame\n") 'gdb-frame-handler))
2398 (gdb-set-pending-triggers
2399 (cons 'gdb-get-current-frame
2400 (gdb-get-pending-triggers))))))
2401
2402 (defun gdb-frame-handler ()
2403 (gdb-set-pending-triggers
2404 (delq 'gdb-get-current-frame (gdb-get-pending-triggers)))
2405 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2406 (goto-char (point-min))
2407 (forward-line)
2408 (if (looking-at ".*= 0x\\(\\S-*\\) in \\(\\S-*\\)")
2409 (progn
2410 (setq gdb-current-frame (match-string 2))
2411 (let ((address (match-string 1)))
2412 ;; remove leading 0s from output of info frame command.
2413 (if (string-match "^0+\\(.*\\)" address)
2414 (setq gdb-current-address
2415 (concat "0x" (match-string 1 address)))
2416 (setq gdb-current-address (concat "0x" address))))
2417 (if (or (if (not (looking-at ".*(\\S-*:[0-9]*)"))
2418 (progn (setq gdb-view-source nil) t))
2419 (eq gdb-selected-view 'assembler))
2420 (progn
2421 (set-window-buffer
2422 gdb-source-window
2423 (gdb-get-create-buffer 'gdb-assembler-buffer))
2424 ;;update with new frame for machine code if necessary
2425 (gdb-invalidate-assembler)))))))
2426
2427 (provide 'gdb-ui)
2428
2429 ;;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2430 ;;; gdb-ui.el ends here