1 ;;; gdb-ui.el --- User Interface for running GDB
3 ;; Author: Nick Roberts <nick@nick.uklinux.net>
5 ;; Keywords: unix, tools
7 ;; Copyright (C) 2002 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
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)
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.
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.
28 ;; Extension of gdba.el written by Jim Kingdon from gdb 5.0
34 (defvar gdb-main-or-pc nil "Initialisation for Assembler buffer.")
35 (defvar gdb-current-address nil)
36 (defvar gdb-display-in-progress nil)
38 (defvar gdb-first-time nil)
39 (defvar gdb-proc nil "The process associated with gdb.")
42 (defun gdba (command-line)
43 "Run gdb on program FILE in buffer *gdb-FILE*.
44 The directory containing FILE becomes the initial working directory
45 and source-file directory for your debugger.
47 If `gdb-many-windows' is set to t this works best in X (depending on the size
48 of your monitor) using most of the screen. After a short delay the following
49 layout will appear (keybindings given in relevant buffer) :
51 ---------------------------------------------------------------------
53 ---------------------------------------------------------------------
54 GUD buffer (I/O of gdb) | Locals buffer
58 ---------------------------------------------------------------------
59 Source buffer | Input/Output (of debuggee) buffer
67 ---------------------------------------------------------------------
68 Stack buffer | Breakpoints buffer
69 \[mouse-2\] gdb-frames-select | SPC gdb-toggle-bp-this-line
70 | g gdb-goto-bp-this-line
71 | d gdb-delete-bp-this-line
72 ---------------------------------------------------------------------
74 All the buffers share the toolbar and source should always display in the same
75 window e.g after typing g on a breakpoint in the breakpoints buffer. Breakpoint
76 icons are displayed both by setting a break with gud-break and by typing break
79 Displayed expressions appear in separate frames. Arrays may be displayed
80 as slices and visualised using the graph program from plotutils if installed.
82 If `gdb-many-windows' is set to nil then gdb starts with just two windows :
83 the GUD and the source buffer.
85 The following interactive lisp functions help control operation :
87 `gdb-many-windows' - Toggle the number of windows gdb uses.
88 `gdb-restore-windows' - to restore the layout if its lost.
89 `gdb-quit' - to delete (most) of the buffers used by gdb."
91 (interactive (list (gud-query-cmdline 'gdba)))
93 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
96 (set (make-local-variable 'gud-minor-mode) 'gdba)
97 (set (make-local-variable 'gud-marker-filter) 'gdba-marker-filter)
99 (gud-def gud-break (if (not (string-equal mode-name "Assembler"))
100 (gud-call "break %f:%l" arg)
104 (gud-call "break *%a" arg)))
105 "\C-b" "Set breakpoint at current line or address.")
107 (gud-def gud-remove (if (not (string-equal mode-name "Assembler"))
108 (gud-call "clear %f:%l" arg)
112 (gud-call "clear *%a" arg)))
113 "\C-d" "Remove breakpoint at current line or address.")
115 (setq comint-input-sender 'gdb-send)
118 (setq gdb-main-or-pc "main")
119 (setq gdb-current-address nil)
120 (setq gdb-display-in-progress nil)
123 (setq gdb-proc (get-buffer-process (current-buffer)))
125 (gdb-clear-inferior-io)
127 ;; find source file and compilation directory here
128 (gdb-instance-enqueue-idle-input (list "server list\n" 'ignore))
129 (gdb-instance-enqueue-idle-input (list "server info source\n"
132 (run-hooks 'gdba-mode-hook))
134 (defun gud-display ()
135 "Display (possibly dereferenced) C expression at point."
138 (let ((expr (gud-find-c-expr)))
139 (gdb-instance-enqueue-idle-input
140 (list (concat "server whatis " expr "\n")
141 `(lambda () (gud-display1 ,expr)))))))
143 (defun gud-display1 (expr)
144 (goto-char (point-min))
145 (if (re-search-forward "\*" nil t)
146 (gdb-instance-enqueue-idle-input
147 (list (concat "server display* " expr "\n") 'ignore))
148 (gdb-instance-enqueue-idle-input
149 (list (concat "server display " expr "\n") 'ignore))))
152 ;; The completion process filter is installed temporarily to slurp the
153 ;; output of GDB up to the next prompt and build the completion list.
154 ;; It must also handle annotations.
157 ;; ======================================================================
159 ;; In this world, there are gdb instance objects (of unspecified
160 ;; representation) and buffers associated with those objects.
164 ;; gdb-instance objects
167 (defvar gdb-instance-variables '()
168 "A list of variables that are local to the GUD buffer associated
169 with a gdb instance.")
171 ;;; The list of instance variables is built up by the expansions of
175 (defmacro def-gdb-var (root-symbol &optional default doc)
176 (let* ((root (symbol-name root-symbol))
177 (accessor (intern (concat "gdb-instance-" root)))
178 (setter (intern (concat "set-gdb-instance-" root)))
179 (name (intern (concat "gdb-" root))))
181 (defvar ,name ,default ,doc)
182 (if (not (memq ',name gdb-instance-variables))
183 (push ',name gdb-instance-variables))
186 (let ((buffer (gdb-get-instance-buffer 'gdba)))
187 (and buffer (buffer-local-value ',name buffer)))))
189 `(defun ,setter (val)
190 (let ((buffer (gdb-get-instance-buffer 'gdba)))
191 (and buffer (with-current-buffer buffer
192 (setq ,name val)))))))))
194 (def-gdb-var buffer-type nil
195 "One of the symbols bound in gdb-instance-buffer-rules")
197 (def-gdb-var burst ""
198 "A string of characters from gdb that have not yet been processed.")
200 (def-gdb-var input-queue ()
201 "A list of high priority gdb command objects.")
203 (def-gdb-var idle-input-queue ()
204 "A list of low priority gdb command objects.")
206 (def-gdb-var prompting nil
207 "True when gdb is idle with no pending input.")
209 (def-gdb-var output-sink 'user
210 "The disposition of the output of the current gdb command.
211 Possible values are these symbols:
213 user -- gdb output should be copied to the GUD buffer
216 inferior -- gdb output should be copied to the inferior-io buffer
218 pre-emacs -- output should be ignored util the post-prompt
219 annotation is received. Then the output-sink
221 emacs -- output should be collected in the partial-output-buffer
222 for subsequent processing by a command. This is the
223 disposition of output generated by commands that
224 gdb mode sends to gdb on its own behalf.
225 post-emacs -- ignore input until the prompt annotation is
226 received, then go to USER disposition.
229 (def-gdb-var current-item nil
230 "The most recent command item sent to gdb.")
232 (def-gdb-var pending-triggers '()
233 "A list of trigger functions that have run later than their output
236 (defun in-gdb-instance-context (form)
237 "Funcall FORM in the GUD buffer."
239 (set-buffer (gdb-get-instance-buffer 'gdba))
242 ;; end of instance vars
244 (defun gdb-make-instance ()
245 "Create a gdb instance object from a gdb process."
246 (with-current-buffer (process-buffer gdb-proc)
247 (mapc 'make-local-variable gdb-instance-variables)
248 (setq gdb-buffer-type 'gdba)))
250 (defun gdb-instance-target-string ()
251 "The apparent name of the program being debugged by a gdb instance.
252 For sure this the root string used in smashing together the gdb
253 buffer's name, even if that doesn't happen to be the name of a
255 (in-gdb-instance-context (lambda () gud-target-name)))
262 ;; More than one buffer can be associated with a gdb instance.
264 ;; Each buffer has a TYPE -- a symbol that identifies the function
265 ;; of that particular buffer.
267 ;; The usual gdb interaction buffer is given the type `gdb' and
268 ;; is constructed specially.
270 ;; Others are constructed by gdb-get-create-instance-buffer and
271 ;; named according to the rules set forth in the gdb-instance-buffer-rules-assoc
273 (defvar gdb-instance-buffer-rules-assoc '())
275 (defun gdb-get-instance-buffer (key)
276 "Return the instance buffer tagged with type KEY.
277 The key should be one of the cars in `gdb-instance-buffer-rules-assoc'."
279 (gdb-look-for-tagged-buffer key (buffer-list))))
281 (defun gdb-get-create-instance-buffer (key)
282 "Create a new gdb instance buffer of the type specified by KEY.
283 The key should be one of the cars in `gdb-instance-buffer-rules-assoc'."
284 (or (gdb-get-instance-buffer key)
285 (let* ((rules (assoc key gdb-instance-buffer-rules-assoc))
286 (name (funcall (gdb-rules-name-maker rules)))
287 (new (get-buffer-create name)))
290 (make-variable-buffer-local 'gdb-buffer-type)
291 (setq gdb-buffer-type key)
292 (if (cdr (cdr rules))
293 (funcall (car (cdr (cdr rules)))))
296 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
298 (defun gdb-look-for-tagged-buffer (key bufs)
300 (while (and (not retval) bufs)
301 (set-buffer (car bufs))
302 (if (eq gdb-buffer-type key)
303 (setq retval (car bufs)))
304 (setq bufs (cdr bufs)))
308 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
309 ;; at least one and possible more functions. The functions have these
310 ;; roles in defining a buffer type:
312 ;; NAME - take an instance, return a name for this type buffer for that
314 ;; The remaining function(s) are optional:
316 ;; MODE - called in new new buffer with no arguments, should establish
317 ;; the proper mode for the buffer.
320 (defun gdb-set-instance-buffer-rules (buffer-type &rest rules)
321 (let ((binding (assoc buffer-type gdb-instance-buffer-rules-assoc)))
323 (setcdr binding rules)
324 (setq gdb-instance-buffer-rules-assoc
325 (cons (cons buffer-type rules)
326 gdb-instance-buffer-rules-assoc)))))
328 ;; GUD buffers are an exception to the rules
329 (gdb-set-instance-buffer-rules 'gdba 'error)
332 ;; partial-output buffers
334 ;; These accumulate output from a command executed on
335 ;; behalf of emacs (rather than the user).
338 (gdb-set-instance-buffer-rules 'gdb-partial-output-buffer
339 'gdb-partial-output-name)
341 (defun gdb-partial-output-name ()
342 (concat "*partial-output-"
343 (gdb-instance-target-string)
347 (gdb-set-instance-buffer-rules 'gdb-inferior-io
348 'gdb-inferior-io-name
349 'gdb-inferior-io-mode)
351 (defun gdb-inferior-io-name ()
352 (concat "*input/output of "
353 (gdb-instance-target-string)
356 (defvar gdb-inferior-io-mode-map
357 (let ((map (make-sparse-keymap)))
358 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
359 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
360 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
361 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
364 (define-derived-mode gdb-inferior-io-mode comint-mode "Debuggee I/O"
365 "Major mode for gdb inferior-io."
366 :syntax-table nil :abbrev-table nil
367 ;; We want to use comint because it has various nifty and familiar
368 ;; features. We don't need a process, but comint wants one, so create
370 (make-comint-in-buffer
371 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
372 (current-buffer) "/bin/cat")
373 (set (make-local-variable 'gud-minor-mode) 'gdba)
374 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
375 (setq comint-input-sender 'gdb-inferior-io-sender))
377 (defun gdb-inferior-io-sender (proc string)
379 (set-buffer (process-buffer proc))
380 (set-buffer (gdb-get-instance-buffer 'gdba))
381 (process-send-string gdb-proc string)
382 (process-send-string gdb-proc "\n")))
384 (defun gdb-inferior-io-interrupt ()
385 "Interrupt the program being debugged."
388 (get-buffer-process (gdb-get-instance-buffer 'gdba)) comint-ptyp))
390 (defun gdb-inferior-io-quit ()
391 "Send quit signal to the program being debugged."
394 (get-buffer-process (gdb-get-instance-buffer 'gdba)) comint-ptyp))
396 (defun gdb-inferior-io-stop ()
397 "Stop the program being debugged."
400 (get-buffer-process (gdb-get-instance-buffer 'gdba)) comint-ptyp))
402 (defun gdb-inferior-io-eof ()
403 "Send end-of-file to the program being debugged."
406 (get-buffer-process (gdb-get-instance-buffer 'gdba))))
410 ;; gdb communications
413 ;; INPUT: things sent to gdb
415 ;; Each instance has a high and low priority
416 ;; input queue. Low priority input is sent only
417 ;; when the high priority queue is idle.
419 ;; The queues are lists. Each element is either
420 ;; a string (indicating user or user-like input)
421 ;; or a list of the form:
423 ;; (INPUT-STRING HANDLER-FN)
426 ;; The handler function will be called from the
427 ;; partial-output buffer when the command completes.
428 ;; This is the way to write commands which
429 ;; invoke gdb commands autonomously.
431 ;; These lists are consumed tail first.
434 (defun gdb-send (proc string)
435 "A comint send filter for gdb.
436 This filter may simply queue output for a later time."
437 (gdb-instance-enqueue-input (concat string "\n")))
439 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
440 ;; is a query, or other non-top-level prompt. To guarantee stuff will get
441 ;; sent to the top-level prompt, currently it must be put in the idle queue.
443 ;; [This should encourage gdb extensions that invoke gdb commands to let
444 ;; the user go first; it is not a bug. -t]
447 (defun gdb-instance-enqueue-input (item)
448 (if (gdb-instance-prompting)
451 (set-gdb-instance-prompting nil))
452 (set-gdb-instance-input-queue
453 (cons item (gdb-instance-input-queue)))))
455 (defun gdb-instance-dequeue-input ()
456 (let ((queue (gdb-instance-input-queue)))
458 (if (not (cdr queue))
459 (let ((answer (car queue)))
460 (set-gdb-instance-input-queue '())
462 (gdb-take-last-elt queue)))))
464 (defun gdb-instance-enqueue-idle-input (item)
465 (if (and (gdb-instance-prompting)
466 (not (gdb-instance-input-queue)))
469 (set-gdb-instance-prompting nil))
470 (set-gdb-instance-idle-input-queue
471 (cons item (gdb-instance-idle-input-queue)))))
473 (defun gdb-instance-dequeue-idle-input ()
474 (let ((queue (gdb-instance-idle-input-queue)))
476 (if (not (cdr queue))
477 (let ((answer (car queue)))
478 (set-gdb-instance-idle-input-queue '())
480 (gdb-take-last-elt queue)))))
482 ;; Don't use this in general.
483 (defun gdb-take-last-elt (l)
485 (gdb-take-last-elt (cdr l))
486 (let ((answer (car (cdr l))))
492 ;; output -- things gdb prints to emacs
494 ;; GDB output is a stream interrupted by annotations.
495 ;; Annotations can be recognized by their beginning
496 ;; with \C-j\C-z\C-z<tag><opt>\C-j
498 ;; The tag is a string obeying symbol syntax.
500 ;; The optional part `<opt>' can be either the empty string
501 ;; or a space followed by more data relating to the annotation.
502 ;; For example, the SOURCE annotation is followed by a filename,
503 ;; line number and various useless goo. This data must not include
507 (defcustom gud-gdba-command-name "gdb -annotate=2"
508 "Default command to execute an executable under the GDB-UI debugger."
512 (defun gdba-marker-filter (string)
513 "A gud marker filter for gdb."
514 (gdb-output-burst string))
516 (defvar gdb-annotation-rules
517 '(("frames-invalid" gdb-invalidate-frame-and-assembler)
518 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler)
519 ("pre-prompt" gdb-pre-prompt)
520 ("prompt" gdb-prompt)
521 ("commands" gdb-subprompt)
522 ("overload-choice" gdb-subprompt)
523 ("query" gdb-subprompt)
524 ("prompt-for-continue" gdb-subprompt)
525 ("post-prompt" gdb-post-prompt)
526 ("source" gdb-source)
527 ("starting" gdb-starting)
528 ("exited" gdb-stopping)
529 ("signalled" gdb-stopping)
530 ("signal" gdb-stopping)
531 ("breakpoint" gdb-stopping)
532 ("watchpoint" gdb-stopping)
533 ("frame-begin" gdb-frame-begin)
534 ("stopped" gdb-stopped)
535 ("display-begin" gdb-display-begin)
536 ("display-end" gdb-display-end)
537 ("display-number-end" gdb-display-number-end)
538 ("array-section-begin" gdb-array-section-begin)
539 ("array-section-end" gdb-array-section-end)
541 ("field-begin" gdb-field-begin)
542 ("field-end" gdb-field-end)
543 ) "An assoc mapping annotation tags to functions which process them.")
545 (defun gdb-ignore-annotation (args)
548 (defconst gdb-source-spec-regexp
549 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:\\(0x[a-f0-9]*\\)")
551 ;; Do not use this except as an annotation handler.
552 (defun gdb-source (args)
553 (string-match gdb-source-spec-regexp args)
554 ;; Extract the frame position from the marker.
557 (match-string 1 args)
558 (string-to-int (match-string 2 args))))
559 (setq gdb-current-address (match-string 3 args))
560 (setq gdb-main-or-pc gdb-current-address)
561 ;;update with new frame for machine code if necessary
562 (gdb-invalidate-assembler))
564 (defun gdb-prompt (ignored)
565 "An annotation handler for `prompt'.
566 This sends the next command (if any) to gdb."
567 (let ((sink (gdb-instance-output-sink)))
570 ((eq sink 'post-emacs)
571 (set-gdb-instance-output-sink 'user))
573 (set-gdb-instance-output-sink 'user)
574 (error "Phase error in gdb-prompt (got %s)" sink))))
575 (let ((highest (gdb-instance-dequeue-input)))
577 (gdb-send-item highest)
578 (let ((lowest (gdb-instance-dequeue-idle-input)))
580 (gdb-send-item lowest)
582 (set-gdb-instance-prompting t)
583 (gud-display-frame)))))))
585 (defun gdb-subprompt (ignored)
586 "An annotation handler for non-top-level prompts."
587 (let ((highest (gdb-instance-dequeue-input)))
589 (gdb-send-item highest)
590 (set-gdb-instance-prompting t))))
592 (defun gdb-send-item (item)
593 (set-gdb-instance-current-item item)
596 (set-gdb-instance-output-sink 'user)
597 (process-send-string gdb-proc item))
599 (gdb-clear-partial-output)
600 (set-gdb-instance-output-sink 'pre-emacs)
601 (process-send-string gdb-proc (car item)))))
603 (defun gdb-pre-prompt (ignored)
604 "An annotation handler for `pre-prompt'. This terminates the collection of
605 output from a previous command if that happens to be in effect."
606 (let ((sink (gdb-instance-output-sink)))
610 (set-gdb-instance-output-sink 'post-emacs)
612 (car (cdr (gdb-instance-current-item)))))
614 (set-buffer (gdb-get-create-instance-buffer
615 'gdb-partial-output-buffer))
618 (set-gdb-instance-output-sink 'user)
619 (error "Output sink phase error 1")))))
621 (defun gdb-starting (ignored)
622 "An annotation handler for `starting'. This says that I/O for the
623 subprocess is now the program being debugged, not GDB."
624 (let ((sink (gdb-instance-output-sink)))
629 (set-gdb-instance-output-sink 'inferior)))
630 (t (error "Unexpected `starting' annotation")))))
632 (defun gdb-stopping (ignored)
633 "An annotation handler for `exited' and other annotations which say that I/O
634 for the subprocess is now GDB, not the program being debugged."
635 (let ((sink (gdb-instance-output-sink)))
638 (set-gdb-instance-output-sink 'user))
639 (t (error "Unexpected stopping annotation")))))
641 (defun gdb-stopped (ignored)
642 "An annotation handler for `stopped'. It is just like gdb-stopping, except
643 that if we already set the output sink to 'user in gdb-stopping, that is fine."
644 (setq gud-running nil)
645 (let ((sink (gdb-instance-output-sink)))
648 (set-gdb-instance-output-sink 'user))
650 (t (error "Unexpected stopped annotation")))))
652 (defun gdb-frame-begin (ignored)
653 (let ((sink (gdb-instance-output-sink)))
656 (set-gdb-instance-output-sink 'user))
659 (t (error "Unexpected frame-begin annotation (%S)" sink)))))
661 (defun gdb-post-prompt (ignored)
662 "An annotation handler for `post-prompt'. This begins the collection of
663 output from the current command if that happens to be appropriate."
664 (if (not (gdb-instance-pending-triggers))
666 (gdb-invalidate-registers ignored)
667 (gdb-invalidate-locals ignored)
668 (gdb-invalidate-display ignored)))
669 (let ((sink (gdb-instance-output-sink)))
672 ((eq sink 'pre-emacs)
673 (set-gdb-instance-output-sink 'emacs))
675 (set-gdb-instance-output-sink 'user)
676 (error "Output sink phase error 3")))))
678 ;; If we get an error whilst evaluating one of the expressions
679 ;; we won't get the display-end annotation. Set the sink back to
680 ;; user to make sure that the error message is seen
681 (defun gdb-error-begin (ignored)
682 (set-gdb-instance-output-sink 'user))
684 (defun gdb-display-begin (ignored)
685 (if (gdb-get-instance-buffer 'gdb-display-buffer)
687 (set-gdb-instance-output-sink 'emacs)
688 (gdb-clear-partial-output)
689 (setq gdb-display-in-progress t))
690 (set-gdb-instance-output-sink 'user)))
692 (defvar gdb-expression-buffer-name)
693 (defvar gdb-display-number)
694 (defvar gdb-dive-display-number)
696 (defun gdb-display-number-end (ignored)
697 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
698 (setq gdb-display-number (buffer-string))
699 (setq gdb-expression-buffer-name
700 (concat "*display " gdb-display-number "*"))
703 (set-buffer (window-buffer))
706 (let ((number gdb-display-number))
708 (set-buffer (get-buffer-create gdb-expression-buffer-name)))
709 (gdb-expressions-mode)
710 (setq gdb-dive-display-number number)))
711 (set-buffer (get-buffer-create gdb-expression-buffer-name))
712 (if (and (display-graphic-p) (not gdb-dive))
714 (dolist (frame (frame-list))
715 (if (string-equal (frame-parameter frame 'name)
716 gdb-expression-buffer-name)
717 (throw 'frame-exists nil)))
718 (gdb-expressions-mode)
719 (make-frame '((height . 20) (width . 40)
720 (tool-bar-lines . nil)
721 (menu-bar-lines . nil)
722 (minibuffer . nil)))))))
723 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
726 (defvar gdb-current-frame nil)
727 (defvar gdb-nesting-level)
728 (defvar gdb-expression)
730 (defvar gdb-annotation-arg)
732 (defun gdb-delete-line ()
733 "Delete the current line."
734 (delete-region (line-beginning-position) (line-beginning-position 2)))
736 (defun gdb-display-end (ignored)
737 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
738 (goto-char (point-min))
739 (search-forward ": ")
740 (looking-at "\\(.*?\\) =")
742 (gdb-temp-value (match-string 1)))
743 ;;move * to front of expression if necessary
744 (if (looking-at ".*\\*")
747 (setq gdb-temp-value (substring gdb-temp-value 1 nil))))
749 (set-buffer gdb-expression-buffer-name)
750 (setq gdb-expression gdb-temp-value)
751 (if (not (string-match "::" gdb-expression))
752 (setq gdb-expression (concat char gdb-current-frame
753 "::" gdb-expression))
754 ;;else put * back on if necessary
755 (setq gdb-expression (concat char gdb-expression)))
756 (setq header-line-format (concat "-- " gdb-expression " %-"))))
759 (if (not (re-search-forward "##" nil t))
762 (set-buffer gdb-expression-buffer-name)
763 (setq buffer-read-only nil)
764 (delete-region (point-min) (point-max))
765 (insert-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
766 (setq buffer-read-only t)))
767 ;; display expression name...
768 (goto-char (point-min))
769 (let ((start (progn (point)))
770 (end (progn (end-of-line) (point))))
772 (set-buffer gdb-expression-buffer-name)
773 (setq buffer-read-only nil)
774 (delete-region (point-min) (point-max))
775 (insert-buffer-substring (gdb-get-instance-buffer
776 'gdb-partial-output-buffer)
779 (goto-char (point-min))
780 (re-search-forward "##" nil t)
781 (setq gdb-nesting-level 0)
782 (if (looking-at "array-section-begin")
785 (setq gdb-point (point))
787 (if (looking-at "field-begin \\(.\\)")
789 (setq gdb-annotation-arg (match-string 1))
790 (gdb-field-format-begin))))
792 (set-buffer gdb-expression-buffer-name)
793 (if gdb-dive-display-number
795 (setq buffer-read-only nil)
796 (goto-char (point-max))
798 (insert-text-button "[back]" 'type 'gdb-display-back)
799 (setq buffer-read-only t))))
800 (gdb-clear-partial-output)
801 (set-gdb-instance-output-sink 'user)
802 (setq gdb-display-in-progress nil))
804 (define-button-type 'gdb-display-back
805 'help-echo (purecopy "mouse-2, RET: go back to previous display buffer")
806 'action (lambda (button) (gdb-display-go-back)))
808 (defun gdb-display-go-back ()
809 ;; delete display so they don't accumulate and delete buffer
810 (let ((number gdb-display-number))
811 (gdb-instance-enqueue-idle-input
812 (list (concat "server delete display " number "\n") 'ignore))
813 (switch-to-buffer (concat "*display " gdb-dive-display-number "*"))
814 (kill-buffer (get-buffer (concat "*display " number "*")))))
816 ;; prefix annotations with ## and process whole output in one chunk
817 ;; in gdb-partial-output-buffer (to allow recursion).
819 ;; array-section flags are just removed again but after counting. They
820 ;; might also be useful for arrays of structures and structures with arrays.
821 (defun gdb-array-section-begin (args)
822 (if gdb-display-in-progress
825 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
826 (goto-char (point-max))
827 (insert (concat "\n##array-section-begin " args "\n"))))))
829 (defun gdb-array-section-end (ignored)
830 (if gdb-display-in-progress
833 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
834 (goto-char (point-max))
835 (insert "\n##array-section-end\n")))))
837 (defun gdb-field-begin (args)
838 (if gdb-display-in-progress
841 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
842 (goto-char (point-max))
843 (insert (concat "\n##field-begin " args "\n"))))))
845 (defun gdb-field-end (ignored)
846 (if gdb-display-in-progress
849 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer))
850 (goto-char (point-max))
851 (insert "\n##field-end\n")))))
853 (defun gdb-elt (ignored)
854 (if gdb-display-in-progress
856 (goto-char (point-max))
857 (insert "\n##elt\n"))))
859 (defun gdb-field-format-begin ()
860 ;; get rid of ##field-begin
863 (setq gdb-nesting-level (+ gdb-nesting-level 1))
864 (while (re-search-forward "##" nil t)
865 ;; keep making recursive calls...
866 (if (looking-at "field-begin \\(.\\)")
868 (setq gdb-annotation-arg (match-string 1))
869 (gdb-field-format-begin)))
871 (if (looking-at "field-end") (gdb-field-format-end))))
873 (defun gdb-field-format-end ()
874 ;; get rid of ##field-end and `,' or `}'
877 (setq gdb-nesting-level (- gdb-nesting-level 1)))
880 (let ((map (make-sparse-keymap)))
881 (define-key map [mouse-2] 'gdb-dive)
882 (define-key map [S-mouse-2] 'gdb-dive-new-frame)
885 (defun gdb-dive (event)
886 "Dive into structure."
889 (gdb-dive-new-frame event))
891 (defun gdb-dive-new-frame (event)
892 "Dive into structure and display in a new frame."
895 (mouse-set-point event)
896 (let ((point (point)) (gdb-full-expression gdb-expression)
897 (end (progn (end-of-line) (point)))
898 (gdb-part-expression "") (gdb-last-field nil) (gdb-display-char nil))
900 (if (looking-at "\*") (setq gdb-display-char "*"))
901 (re-search-forward "\\(\\S-+\\) = " end t)
902 (setq gdb-last-field (match-string-no-properties 1))
903 (goto-char (match-beginning 1))
904 (let ((last-column (current-column)))
905 (while (re-search-backward "\\s-\\(\\S-+\\) = {" nil t)
906 (goto-char (match-beginning 1))
907 (if (and (< (current-column) last-column)
908 (> (count-lines 1 (point)) 1))
910 (setq gdb-part-expression
911 (concat "." (match-string-no-properties 1)
912 gdb-part-expression))
913 (setq last-column (current-column))))))
914 ;; * not needed for components of a pointer to a structure in gdb
915 (if (string-equal "*" (substring gdb-full-expression 0 1))
916 (setq gdb-full-expression (substring gdb-full-expression 1 nil)))
917 (setq gdb-full-expression
918 (concat gdb-full-expression gdb-part-expression "." gdb-last-field))
919 (gdb-instance-enqueue-idle-input
920 (list (concat "server display" gdb-display-char
921 " " gdb-full-expression "\n")
924 (defun gdb-insert-field ()
925 (let ((start (progn (point)))
926 (end (progn (next-line) (point)))
929 (set-buffer gdb-expression-buffer-name)
930 (setq buffer-read-only nil)
931 (if (string-equal gdb-annotation-arg "\*") (insert "\*"))
932 (while (<= num gdb-nesting-level)
934 (setq num (+ num 1)))
935 (insert-buffer-substring (gdb-get-instance-buffer
936 'gdb-partial-output-buffer)
938 (put-text-property (- (point) (- end start)) (- (point) 1)
939 'mouse-face 'highlight)
940 (put-text-property (- (point) (- end start)) (- (point) 1)
941 'local-map gdb-dive-map)
942 (setq buffer-read-only t))
943 (delete-region start end)))
947 (defun gdb-array-format ()
948 (while (re-search-forward "##" nil t)
949 ;; keep making recursive calls...
950 (if (looking-at "array-section-begin")
952 ;;get rid of ##array-section-begin
954 (setq gdb-nesting-level (+ gdb-nesting-level 1))
956 ;;until *matching* array-section-end is found
957 (if (looking-at "array-section-end")
958 (if (eq gdb-nesting-level 0)
960 (let ((values (buffer-substring gdb-point (- (point) 2))))
962 (set-buffer gdb-expression-buffer-name)
964 (concat "{" (replace-regexp-in-string "\n" "" values)
966 (gdb-array-format1))))
967 ;;else get rid of ##array-section-end etc
969 (setq gdb-nesting-level (- gdb-nesting-level 1))
970 (gdb-array-format)))))
972 (defvar gdb-array-start)
973 (defvar gdb-array-stop)
975 (defvar gdb-array-slice-map
976 (let ((map (make-sparse-keymap)))
977 (define-key map [mouse-2] 'gdb-array-slice)
980 (defun gdb-array-slice (event)
981 "Select an array slice to display."
983 (mouse-set-point event)
985 (let ((n -1) (stop 0) (start 0) (point (point)))
987 (while (search-forward "[" point t)
989 (setq start (string-to-int (read-string "Start index: ")))
990 (aset gdb-array-start n start)
991 (setq stop (string-to-int (read-string "Stop index: ")))
992 (aset gdb-array-stop n stop)))
995 (defvar gdb-display-string)
996 (defvar gdb-array-size)
998 (defun gdb-array-format1 ()
999 (setq gdb-display-string "")
1000 (setq buffer-read-only nil)
1001 (delete-region (point-min) (point-max))
1002 (let ((gdb-value-list (split-string gdb-values ", ")))
1003 (string-match "\\({+\\)" (car gdb-value-list))
1004 (let* ((depth (- (match-end 1) (match-beginning 1)))
1005 (indices (make-vector depth '0))
1006 (index 0) (num 0) (array-start "")
1007 (array-stop "") (array-slice "") (array-range nil)
1008 (flag t) (indices-string ""))
1009 (dolist (gdb-value gdb-value-list)
1010 (string-match "{*\\([^}]*\\)\\(}*\\)" gdb-value)
1012 (while (< num depth)
1013 (setq indices-string
1014 (concat indices-string
1015 "[" (int-to-string (aref indices num)) "]"))
1016 (if (not (= (aref gdb-array-start num) -1))
1017 (if (or (< (aref indices num) (aref gdb-array-start num))
1018 (> (aref indices num) (aref gdb-array-stop num)))
1020 (aset gdb-array-size num (aref indices num)))
1021 (setq num (+ num 1)))
1023 (let ((gdb-display-value (match-string 1 gdb-value)))
1024 (setq gdb-display-string (concat gdb-display-string " "
1027 (concat indices-string "\t" gdb-display-value "\n"))))
1028 (setq indices-string "")
1030 ;; 0<= index < depth, start at right : (- depth 1)
1031 (setq index (- (- depth 1)
1032 (- (match-end 2) (match-beginning 2))))
1033 ;;don't set for very last brackets
1035 (aset indices index (+ 1 (aref indices index)))
1036 (setq num (+ 1 index))
1037 (while (< num depth)
1038 (aset indices num 0)
1039 (setq num (+ num 1)))))
1041 (while (< num depth)
1042 (if (= (aref gdb-array-start num) -1)
1044 (aset gdb-array-start num 0)
1045 (aset gdb-array-stop num (aref indices num))))
1046 (setq array-start (int-to-string (aref gdb-array-start num)))
1047 (setq array-stop (int-to-string (aref gdb-array-stop num)))
1048 (setq array-range (concat "[" array-start
1049 ":" array-stop "]"))
1050 (put-text-property 1 (+ (length array-start)
1051 (length array-stop) 2)
1052 'mouse-face 'highlight array-range)
1053 (put-text-property 1 (+ (length array-start)
1054 (length array-stop) 2)
1055 'local-map gdb-array-slice-map array-range)
1056 (goto-char (point-min))
1057 (setq array-slice (concat array-slice array-range))
1058 (setq num (+ num 1)))
1059 (goto-char (point-min))
1060 (insert "Array Size : ")
1062 (while (< num depth)
1065 (int-to-string (+ (aref gdb-array-size num) 1)) "]"))
1066 (setq num (+ num 1)))
1068 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n"))))
1069 (setq buffer-read-only t))
1071 ;; Handle a burst of output from a gdb instance.
1072 ;; This function is (indirectly) used as a gud-marker-filter.
1073 ;; It must return output (if any) to be inserted in the gdb
1076 (defun gdb-output-burst (string)
1077 "Handle a burst of output from a gdb instance.
1078 This function is (indirectly) used as a gud-marker-filter.
1079 It must return output (if any) to be insterted in the gdb
1083 ;; Recall the left over burst from last time
1084 (burst (concat (gdb-instance-burst) string))
1085 ;; Start accumulating output for the GUD buffer
1088 ;; Process all the complete markers in this chunk.
1089 (while (string-match "\n\032\032\\(.*\\)\n" burst)
1090 (let ((annotation (match-string 1 burst)))
1092 ;; Stuff prior to the match is just ordinary output.
1093 ;; It is either concatenated to OUTPUT or directed
1098 (substring burst 0 (match-beginning 0))))
1100 ;; Take that stuff off the burst.
1101 (setq burst (substring burst (match-end 0)))
1103 ;; Parse the tag from the annotation, and maybe its arguments.
1104 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1105 (let* ((annotation-type (match-string 1 annotation))
1106 (annotation-arguments (match-string 2 annotation))
1107 (annotation-rule (assoc annotation-type
1108 gdb-annotation-rules)))
1109 ;; Call the handler for this annotation.
1111 (funcall (car (cdr annotation-rule))
1112 annotation-arguments)
1113 ;; Else the annotation is not recognized. Ignore it silently,
1114 ;; so that GDB can add new annotations without causing
1118 ;; Does the remaining text end in a partial line?
1119 ;; If it does, then keep part of the burst until we get more.
1120 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1123 ;; Everything before the potential marker start can be output.
1125 (gdb-concat-output output
1126 (substring burst 0 (match-beginning 0))))
1128 ;; Everything after, we save, to combine with later input.
1129 (setq burst (substring burst (match-beginning 0))))
1131 ;; In case we know the burst contains no partial annotations:
1133 (setq output (gdb-concat-output output burst))
1136 ;; Save the remaining burst for the next call to this function.
1137 (set-gdb-instance-burst burst)
1140 (defun gdb-concat-output (so-far new)
1141 (let ((sink (gdb-instance-output-sink )))
1143 ((eq sink 'user) (concat so-far new))
1144 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1146 (gdb-append-to-partial-output new)
1148 ((eq sink 'inferior)
1149 (gdb-append-to-inferior-io new)
1151 (t (error "Bogon output sink %S" sink)))))
1153 (defun gdb-append-to-partial-output (string)
1156 (gdb-get-create-instance-buffer 'gdb-partial-output-buffer))
1157 (goto-char (point-max))
1160 (defun gdb-clear-partial-output ()
1163 (gdb-get-create-instance-buffer 'gdb-partial-output-buffer))
1164 (delete-region (point-min) (point-max))))
1166 (defun gdb-append-to-inferior-io (string)
1169 (gdb-get-create-instance-buffer 'gdb-inferior-io))
1170 (goto-char (point-max))
1171 (insert-before-markers string))
1173 (gdb-get-create-instance-buffer 'gdb-inferior-io)))
1175 (defun gdb-clear-inferior-io ()
1178 (gdb-get-create-instance-buffer 'gdb-inferior-io))
1179 (delete-region (point-min) (point-max))))
1182 ;; One trick is to have a command who's output is always available in
1183 ;; a buffer of it's own, and is always up to date. We build several
1184 ;; buffers of this type.
1186 ;; There are two aspects to this: gdb has to tell us when the output
1187 ;; for that command might have changed, and we have to be able to run
1188 ;; the command behind the user's back.
1190 ;; The idle input queue and the output phasing associated with
1191 ;; the instance variable `(gdb-instance-output-sink)' help
1192 ;; us to run commands behind the user's back.
1194 ;; Below is the code for specificly managing buffers of output from one
1198 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1199 ;; It adds an idle input for the command we are tracking. It should be the
1200 ;; annotation rule binding of whatever gdb sends to tell us this command
1201 ;; might have changed it's output.
1203 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1204 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1205 ;; input in the input queue (see comment about ``gdb communications'' above).
1207 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1209 `(defun ,name (&optional ignored)
1210 (if (and (,demand-predicate)
1212 (gdb-instance-pending-triggers))))
1214 (gdb-instance-enqueue-idle-input
1215 (list ,gdb-command ',output-handler))
1216 (set-gdb-instance-pending-triggers
1218 (gdb-instance-pending-triggers)))))))
1220 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1222 (set-gdb-instance-pending-triggers
1224 (gdb-instance-pending-triggers)))
1225 (let ((buf (gdb-get-instance-buffer ',buf-key)))
1230 (buffer-read-only nil))
1231 (delete-region (point-min) (point-max))
1232 (insert-buffer (gdb-get-create-instance-buffer
1233 'gdb-partial-output-buffer))
1235 ;; put customisation here
1238 (defmacro def-gdb-auto-updated-buffer (buffer-key trigger-name gdb-command
1239 output-handler-name custom-defun)
1241 (def-gdb-auto-update-trigger ,trigger-name
1242 ;; The demand predicate:
1243 (lambda () (gdb-get-instance-buffer ',buffer-key))
1245 ,output-handler-name)
1246 (def-gdb-auto-update-handler ,output-handler-name
1247 ,trigger-name ,buffer-key ,custom-defun)))
1251 ;; Breakpoint buffers
1253 ;; These display the output of `info breakpoints'.
1256 (gdb-set-instance-buffer-rules 'gdb-breakpoints-buffer
1257 'gdb-breakpoints-buffer-name
1258 'gdb-breakpoints-mode)
1260 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1261 ;; This defines the auto update rule for buffers of type
1262 ;; `gdb-breakpoints-buffer'.
1264 ;; It defines a function to serve as the annotation handler that
1265 ;; handles the `foo-invalidated' message. That function is called:
1266 gdb-invalidate-breakpoints
1268 ;; To update the buffer, this command is sent to gdb.
1269 "server info breakpoints\n"
1271 ;; This also defines a function to be the handler for the output
1272 ;; from the command above. That function will copy the output into
1273 ;; the appropriately typed buffer. That function will be called:
1274 gdb-info-breakpoints-handler
1275 ;; buffer specific functions
1276 gdb-info-breakpoints-custom)
1278 (defvar gdb-cdir nil "Compilation directory.")
1279 (defvar breakpoint-enabled-icon)
1280 (defvar breakpoint-disabled-icon)
1282 ;;-put breakpoint icons in relevant margins (even those set in the GUD buffer)
1283 (defun gdb-info-breakpoints-custom ()
1284 (let ((flag)(address))
1286 ;; remove all breakpoint-icons in source buffers but not assembler buffer
1287 (let ((buffers (buffer-list)))
1290 (set-buffer (car buffers))
1291 (if (and (eq gud-minor-mode 'gdba)
1292 (not (string-match "^\*" (buffer-name))))
1293 (if (display-graphic-p)
1294 (remove-images (point-min) (point-max))
1295 (remove-strings (point-min) (point-max))))
1296 (setq buffers (cdr buffers)))))
1299 (set-buffer (gdb-get-instance-buffer 'gdb-breakpoints-buffer))
1301 (goto-char (point-min))
1302 (while (< (point) (- (point-max) 1))
1304 (if (looking-at "[^\t].*breakpoint")
1306 (looking-at "\\([0-9]*\\)\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)")
1307 (setq flag (char-after (match-beginning 2)))
1309 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+")
1310 (looking-at "\\(\\S-*\\):\\([0-9]+\\)")
1311 (let ((line (match-string 2))
1312 (file (match-string 1)))
1315 (find-file-noselect (if (file-exists-p file)
1317 (expand-file-name file gdb-cdir))))
1318 (save-current-buffer
1319 (set (make-local-variable 'gud-minor-mode) 'gdba)
1320 (set (make-local-variable 'tool-bar-map)
1322 (setq left-margin-width 2)
1323 (if (get-buffer-window (current-buffer))
1324 (set-window-margins (get-buffer-window
1327 right-margin-width)))
1328 ;; only want one breakpoint icon at each location
1330 (goto-line (string-to-number line))
1331 (let ((start (progn (beginning-of-line) (- (point) 1)))
1332 (end (progn (end-of-line) (+ (point) 1))))
1333 (if (display-graphic-p)
1335 (remove-images start end)
1337 (put-image breakpoint-enabled-icon (point)
1338 "breakpoint icon enabled"
1340 (put-image breakpoint-disabled-icon (point)
1341 "breakpoint icon disabled"
1343 (remove-strings start end)
1345 (put-string "B" (point) "enabled"
1347 (put-string "b" (point) "disabled"
1348 'left-margin)))))))))
1351 (defun gdb-breakpoints-buffer-name ()
1353 (set-buffer (process-buffer gdb-proc))
1354 (concat "*breakpoints of " (gdb-instance-target-string) "*")))
1356 (defun gdb-display-breakpoints-buffer ()
1359 (gdb-get-create-instance-buffer 'gdb-breakpoints-buffer)))
1361 (defun gdb-frame-breakpoints-buffer ()
1363 (switch-to-buffer-other-frame
1364 (gdb-get-create-instance-buffer 'gdb-breakpoints-buffer)))
1366 (defvar gdb-breakpoints-mode-map
1367 (let ((map (make-sparse-keymap))
1368 (menu (make-sparse-keymap "Breakpoints")))
1369 (define-key menu [toggle] '("Toggle" . gdb-toggle-bp-this-line))
1370 (define-key menu [delete] '("Delete" . gdb-delete-bp-this-line))
1371 (define-key menu [goto] '("Goto" . gdb-goto-bp-this-line))
1373 (suppress-keymap map)
1374 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1375 (define-key map " " 'gdb-toggle-bp-this-line)
1376 (define-key map "d" 'gdb-delete-bp-this-line)
1377 (define-key map "g" 'gdb-goto-bp-this-line)
1380 (defun gdb-breakpoints-mode ()
1381 "Major mode for gdb breakpoints.
1383 \\{gdb-breakpoints-mode-map}"
1384 (setq major-mode 'gdb-breakpoints-mode)
1385 (setq mode-name "Breakpoints")
1386 (use-local-map gdb-breakpoints-mode-map)
1387 (set (make-local-variable 'gud-minor-mode) 'gdba)
1388 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
1389 (setq buffer-read-only t)
1390 (gdb-invalidate-breakpoints))
1392 (defun gdb-toggle-bp-this-line ()
1393 "Enable/disable the breakpoint on this line."
1396 (beginning-of-line 1)
1397 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1398 (error "Not recognized as break/watchpoint line")
1399 (gdb-instance-enqueue-idle-input
1402 (if (eq ?y (char-after (match-beginning 2)))
1409 (defun gdb-delete-bp-this-line ()
1410 "Delete the breakpoint on this line."
1412 (beginning-of-line 1)
1413 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1414 (error "Not recognized as break/watchpoint line")
1415 (gdb-instance-enqueue-idle-input
1423 (defvar gdb-source-window nil)
1425 (defun gdb-goto-bp-this-line ()
1426 "Display the file at the specified breakpoint."
1429 (beginning-of-line 1)
1430 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+")
1431 (looking-at "\\(\\S-*\\):\\([0-9]+\\)"))
1432 (let ((line (match-string 2))
1433 (file (match-string 1)))
1434 (set-window-buffer gdb-source-window
1436 (if (file-exists-p file)
1438 (expand-file-name file gdb-cdir))))
1439 (goto-line (string-to-number line))))
1442 ;; Frames buffers. These display a perpetually correct bactracktrace
1443 ;; (from the command `where').
1445 ;; Alas, if your stack is deep, they are costly.
1448 (gdb-set-instance-buffer-rules 'gdb-stack-buffer
1449 'gdb-stack-buffer-name
1452 (def-gdb-auto-updated-buffer gdb-stack-buffer
1453 gdb-invalidate-frames
1455 gdb-info-frames-handler
1456 gdb-info-frames-custom)
1458 (defun gdb-info-frames-custom ()
1460 (set-buffer (gdb-get-instance-buffer 'gdb-stack-buffer))
1461 (let ((buffer-read-only nil))
1462 (goto-char (point-min))
1463 (looking-at "\\S-*\\s-*\\(\\S-*\\)")
1464 (setq gdb-current-frame (match-string 1))
1465 (while (< (point) (point-max))
1466 (put-text-property (progn (beginning-of-line) (point))
1467 (progn (end-of-line) (point))
1468 'mouse-face 'highlight)
1469 (forward-line 1)))))
1471 (defun gdb-stack-buffer-name ()
1473 (set-buffer (process-buffer gdb-proc))
1474 (concat "*stack frames of "
1475 (gdb-instance-target-string) "*")))
1477 (defun gdb-display-stack-buffer ()
1480 (gdb-get-create-instance-buffer 'gdb-stack-buffer)))
1482 (defun gdb-frame-stack-buffer ()
1484 (switch-to-buffer-other-frame
1485 (gdb-get-create-instance-buffer 'gdb-stack-buffer)))
1487 (defvar gdb-frames-mode-map
1488 (let ((map (make-sparse-keymap)))
1489 (suppress-keymap map)
1490 (define-key map [mouse-2]'gdb-frames-select-by-mouse)
1493 (defun gdb-frames-mode ()
1494 "Major mode for gdb frames.
1496 \\{gdb-frames-mode-map}"
1497 (setq major-mode 'gdb-frames-mode)
1498 (setq mode-name "Frames")
1499 (set (make-local-variable 'gud-minor-mode) 'gdba)
1500 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
1501 (setq buffer-read-only t)
1502 (use-local-map gdb-frames-mode-map)
1503 (gdb-invalidate-frames))
1505 (defun gdb-get-frame-number ()
1507 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t))
1508 (n (or (and pos (string-to-int (match-string 1))) 0)))
1511 (defun gdb-frames-select-by-mouse (e)
1512 "Display the source of the selected frame."
1516 (set-buffer (window-buffer (posn-window (event-end e))))
1518 (goto-char (posn-point (event-end e)))
1519 (setq selection (gdb-get-frame-number))))
1520 (select-window (posn-window (event-end e)))
1522 (set-buffer (gdb-get-instance-buffer 'gdba))
1523 (gdb-instance-enqueue-idle-input
1524 (list (gud-format-command "server frame %p\n" selection)
1526 (gud-display-frame))))
1530 ;; Registers buffers
1533 (def-gdb-auto-updated-buffer gdb-registers-buffer
1534 gdb-invalidate-registers
1535 "server info registers\n"
1536 gdb-info-registers-handler
1537 gdb-info-registers-custom)
1539 (defun gdb-info-registers-custom ())
1541 (gdb-set-instance-buffer-rules 'gdb-registers-buffer
1542 'gdb-registers-buffer-name
1543 'gdb-registers-mode)
1545 (defvar gdb-registers-mode-map
1546 (let ((map (make-sparse-keymap)))
1547 (suppress-keymap map)
1550 (defun gdb-registers-mode ()
1551 "Major mode for gdb registers.
1553 \\{gdb-registers-mode-map}"
1554 (setq major-mode 'gdb-registers-mode)
1555 (setq mode-name "Registers")
1556 (set (make-local-variable 'gud-minor-mode) 'gdba)
1557 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
1558 (setq buffer-read-only t)
1559 (use-local-map gdb-registers-mode-map)
1560 (gdb-invalidate-registers))
1562 (defun gdb-registers-buffer-name ()
1564 (set-buffer (process-buffer gdb-proc))
1565 (concat "*registers of " (gdb-instance-target-string) "*")))
1567 (defun gdb-display-registers-buffer ()
1570 (gdb-get-create-instance-buffer 'gdb-registers-buffer)))
1572 (defun gdb-frame-registers-buffer ()
1574 (switch-to-buffer-other-frame
1575 (gdb-get-create-instance-buffer 'gdb-registers-buffer)))
1581 (def-gdb-auto-updated-buffer gdb-locals-buffer
1582 gdb-invalidate-locals
1583 "server info locals\n"
1584 gdb-info-locals-handler
1585 gdb-info-locals-custom)
1588 ;;Abbreviate for arrays and structures. These can be expanded using gud-display
1589 (defun gdb-info-locals-handler nil
1590 (set-gdb-instance-pending-triggers (delq 'gdb-invalidate-locals
1591 (gdb-instance-pending-triggers)))
1592 (let ((buf (gdb-get-instance-buffer 'gdb-partial-output-buffer)))
1595 (goto-char (point-min))
1596 (replace-regexp "^ .*\n" "")
1597 (goto-char (point-min))
1598 (replace-regexp "{[-0-9, {}\]*\n" "(array);\n")))
1599 (goto-char (point-min))
1600 (replace-regexp "{.*=.*\n" "(structure);\n")
1601 (let ((buf (gdb-get-instance-buffer 'gdb-locals-buffer)))
1602 (and buf (save-excursion
1605 (buffer-read-only nil))
1606 (delete-region (point-min) (point-max))
1607 (insert-buffer (gdb-get-create-instance-buffer
1608 'gdb-partial-output-buffer))
1610 (run-hooks 'gdb-info-locals-hook))
1612 (defun gdb-info-locals-custom ()
1615 (gdb-set-instance-buffer-rules 'gdb-locals-buffer
1616 'gdb-locals-buffer-name
1619 (defvar gdb-locals-mode-map
1620 (let ((map (make-sparse-keymap)))
1621 (suppress-keymap map)
1624 (defun gdb-locals-mode ()
1625 "Major mode for gdb locals.
1627 \\{gdb-locals-mode-map}"
1628 (setq major-mode 'gdb-locals-mode)
1629 (setq mode-name "Locals")
1630 (set (make-local-variable 'gud-minor-mode) 'gdba)
1631 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
1632 (setq buffer-read-only t)
1633 (use-local-map gdb-locals-mode-map)
1634 (gdb-invalidate-locals))
1636 (defun gdb-locals-buffer-name ()
1638 (set-buffer (process-buffer gdb-proc))
1639 (concat "*locals of " (gdb-instance-target-string) "*")))
1641 (defun gdb-display-locals-buffer ()
1644 (gdb-get-create-instance-buffer 'gdb-locals-buffer)))
1646 (defun gdb-frame-locals-buffer ()
1648 (switch-to-buffer-other-frame
1649 (gdb-get-create-instance-buffer 'gdb-locals-buffer)))
1651 ;; Display expression buffers (just allow one to start with)
1653 (gdb-set-instance-buffer-rules 'gdb-display-buffer
1654 'gdb-display-buffer-name
1657 (def-gdb-auto-updated-buffer gdb-display-buffer
1658 ;; `gdb-display-buffer'.
1659 gdb-invalidate-display
1660 "server info display\n"
1661 gdb-info-display-handler
1662 gdb-info-display-custom)
1664 (defun gdb-info-display-custom ()
1665 ;; TODO: ensure frames of expressions that have been deleted are also deleted
1666 ;; these can be missed currently eg through GUD buffer, restarting a
1667 ;; recompiled program.
1670 (defvar gdb-display-mode-map
1671 (let ((map (make-sparse-keymap))
1672 (menu (make-sparse-keymap "Display")))
1673 (define-key menu [toggle] '("Toggle" . gdb-toggle-disp-this-line))
1674 (define-key menu [delete] '("Delete" . gdb-delete-disp-this-line))
1676 (suppress-keymap map)
1677 (define-key map [menu-bar display] (cons "Display" menu))
1678 (define-key map " " 'gdb-toggle-disp-this-line)
1679 (define-key map "d" 'gdb-delete-disp-this-line)
1682 (defun gdb-display-mode ()
1683 "Major mode for gdb display.
1685 \\{gdb-display-mode-map}"
1686 (setq major-mode 'gdb-display-mode)
1687 (setq mode-name "Display")
1688 (set (make-local-variable 'gud-minor-mode) 'gdba)
1689 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
1690 (setq buffer-read-only t)
1691 (use-local-map gdb-display-mode-map)
1692 (gdb-invalidate-display))
1694 (defun gdb-display-buffer-name ()
1696 (set-buffer (process-buffer gdb-proc))
1697 (concat "*Displayed expressions of " (gdb-instance-target-string) "*")))
1699 (defun gdb-display-display-buffer ()
1702 (gdb-get-create-instance-buffer 'gdb-display-buffer)))
1704 (defun gdb-frame-display-buffer ()
1706 (switch-to-buffer-other-frame
1707 (gdb-get-create-instance-buffer 'gdb-display-buffer)))
1709 (defun gdb-toggle-disp-this-line ()
1710 "Enable/disable the displayed expression on this line."
1713 (beginning-of-line 1)
1714 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)"))
1715 (error "No expression on this line")
1716 (gdb-instance-enqueue-idle-input
1719 (if (eq ?y (char-after (match-beginning 2)))
1720 "server disable display "
1721 "server enable display ")
1726 (defun gdb-delete-disp-this-line ()
1727 "Delete the displayed expression on this line."
1731 (gdb-get-instance-buffer 'gdb-display-buffer))
1732 (beginning-of-line 1)
1733 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)"))
1734 (error "No expression on this line")
1735 (let ((number (match-string 1)))
1736 (gdb-instance-enqueue-idle-input
1737 (list (concat "server delete display " number "\n")
1739 (if (not (display-graphic-p))
1740 (kill-buffer (get-buffer (concat "*display " number "*")))
1742 (let ((frames (frame-list)))
1744 (if (string-equal (frame-parameter (car frames) 'name)
1745 (concat "*display " number "*"))
1747 (get-buffer (concat "*display " number "*")))
1748 (delete-frame (car frames))
1749 (throw 'frame-found nil)))
1750 (setq frames (cdr frames))))))))))
1752 (defvar gdb-expressions-mode-map
1753 (let ((map (make-sparse-keymap)))
1754 (suppress-keymap map)
1755 (define-key map "v" 'gdb-array-visualise)
1756 (define-key map "q" 'gdb-delete-display)
1757 (define-key map [mouse-3] 'gdb-expressions-popup-menu)
1760 (defvar gdb-expressions-mode-menu
1761 '("GDB Expressions Commands"
1763 ["Visualise" gdb-array-visualise t]
1764 ["Delete" gdb-delete-display t])
1765 "Menu for `gdb-expressions-mode'.")
1767 (defun gdb-expressions-popup-menu (event)
1768 "Explicit Popup menu as this buffer doesn't have a menubar."
1770 (mouse-set-point event)
1771 (popup-menu gdb-expressions-mode-menu))
1773 (defun gdb-expressions-mode ()
1774 "Major mode for display expressions.
1776 \\{gdb-expressions-mode-map}"
1777 (setq major-mode 'gdb-expressions-mode)
1778 (setq mode-name "Expressions")
1779 (use-local-map gdb-expressions-mode-map)
1780 (make-local-variable 'gdb-display-number)
1781 (make-local-variable 'gdb-values)
1782 (make-local-variable 'gdb-expression)
1783 (set (make-local-variable 'gdb-display-string) nil)
1784 (set (make-local-variable 'gdb-dive-display-number) nil)
1785 (set (make-local-variable 'gud-minor-mode) 'gdba)
1786 (set (make-local-variable 'gdb-array-start) (make-vector 16 '-1))
1787 (set (make-local-variable 'gdb-array-stop) (make-vector 16 '-1))
1788 (set (make-local-variable 'gdb-array-size) (make-vector 16 '-1))
1789 (setq buffer-read-only t))
1792 ;;;; Window management
1794 ;;; FIXME: This should only return true for buffers in the current gdb-proc
1795 (defun gdb-protected-buffer-p (buffer)
1796 "Is BUFFER a buffer which we want to leave displayed?"
1797 (with-current-buffer buffer
1798 (or gdb-buffer-type overlay-arrow-position)))
1800 ;;; The way we abuse the dedicated-p flag is pretty gross, but seems
1801 ;;; to do the right thing. Seeing as there is no way for Lisp code to
1802 ;;; get at the use_time field of a window, I'm not sure there exists a
1803 ;;; more elegant solution without writing C code.
1805 (defun gdb-display-buffer (buf &optional size)
1806 (let ((must-split nil)
1812 (if (gdb-protected-buffer-p (window-buffer win))
1813 (set-window-dedicated-p win t))))
1814 (setq answer (get-buffer-window buf))
1816 (let ((window (get-lru-window)))
1819 (set-window-buffer window buf)
1820 (setq answer window))
1821 (setq must-split t)))))
1824 (if (gdb-protected-buffer-p (window-buffer win))
1825 (set-window-dedicated-p win nil)))))
1827 (let* ((largest (get-largest-window))
1828 (cur-size (window-height largest))
1829 (new-size (and size (< size cur-size) (- cur-size size))))
1830 (setq answer (split-window largest new-size))
1831 (set-window-buffer answer buf)))
1834 (defun gdb-display-source-buffer (buffer)
1835 (set-window-buffer gdb-source-window buffer))
1838 ;;; Shared keymap initialization:
1840 (defun gdb-display-gdb-buffer ()
1843 (gdb-get-create-instance-buffer 'gdba)))
1845 ;; FIXME: changing GUD's behavior: bad bad bad!!!
1846 (define-key gud-minor-mode-map "\C-c\M-\C-r" 'gdb-display-registers-buffer)
1847 (define-key gud-minor-mode-map "\C-c\M-\C-f" 'gdb-display-stack-buffer)
1848 (define-key gud-minor-mode-map "\C-c\M-\C-b" 'gdb-display-breakpoints-buffer)
1850 (let ((menu (make-sparse-keymap "GDB-Windows")))
1851 (define-key gud-menu-map [displays]
1852 `(menu-item "GDB-Windows" ,menu :visible (memq gud-minor-mode '(gdba))))
1853 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
1854 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
1855 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
1856 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
1857 (define-key menu [breakpoints] '("Breakpoints" . gdb-display-breakpoints-buffer))
1858 (define-key menu [display] '("Display" . gdb-display-display-buffer))
1859 (define-key menu [assembler] '("Assembler" . gdb-display-assembler-buffer)))
1861 (defun gdb-frame-gdb-buffer ()
1863 (switch-to-buffer-other-frame
1864 (gdb-get-create-instance-buffer 'gdba)))
1866 (let ((menu (make-sparse-keymap "GDB-Frames")))
1867 (define-key gud-menu-map [frames]
1868 `(menu-item "GDB-Frames" ,menu :visible (memq gud-minor-mode '(gdba))))
1869 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
1870 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
1871 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
1872 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
1873 (define-key menu [breakpoints] '("Breakpoints" . gdb-frame-breakpoints-buffer))
1874 (define-key menu [display] '("Display" . gdb-frame-display-buffer))
1875 (define-key menu [assembler] '("Assembler" . gdb-frame-assembler-buffer)))
1877 (defvar gdb-main-file nil "Source file from which program execution begins.")
1879 ;; layout for all the windows
1880 (defun gdb-setup-windows ()
1881 (gdb-display-locals-buffer)
1882 (gdb-display-stack-buffer)
1883 (delete-other-windows)
1884 (gdb-display-breakpoints-buffer)
1885 (gdb-display-display-buffer)
1886 (delete-other-windows)
1887 (split-window nil ( / ( * (window-height) 3) 4))
1888 (split-window nil ( / (window-height) 3))
1889 (split-window-horizontally)
1891 (switch-to-buffer (gdb-locals-buffer-name))
1894 (if gud-last-last-frame
1895 (gud-find-file (car gud-last-last-frame))
1896 (gud-find-file gdb-main-file)))
1897 (setq gdb-source-window (get-buffer-window (current-buffer)))
1898 (split-window-horizontally)
1900 (switch-to-buffer (gdb-inferior-io-name))
1902 (switch-to-buffer (gdb-stack-buffer-name))
1903 (split-window-horizontally)
1905 (switch-to-buffer (gdb-breakpoints-buffer-name))
1908 (define-minor-mode gdb-many-windows
1909 "Toggle the number of windows in the basic arrangement."
1912 (gdb-restore-windows))
1914 (defun gdb-restore-windows ()
1915 "Restore the basic arrangement of windows used by gdba.
1916 This arrangement depends on the value of `gdb-many-windows'."
1918 (if gdb-many-windows
1920 (switch-to-buffer gud-comint-buffer)
1921 (delete-other-windows)
1922 (gdb-setup-windows))
1923 (switch-to-buffer gud-comint-buffer)
1924 (delete-other-windows)
1928 (if gud-last-last-frame
1929 (gud-find-file (car gud-last-last-frame))
1930 (gud-find-file gdb-main-file)))
1933 (defconst breakpoint-xpm-data "/* XPM */
1934 static char *magick[] = {
1935 /* columns rows colors chars-per-pixel */
1953 "XPM file used for breakpoint icon.")
1955 (defvar breakpoint-enabled-icon
1956 (find-image `((:type xpm :data ,breakpoint-xpm-data)))
1957 "Icon for enabled breakpoint in display margin")
1958 (defvar breakpoint-disabled-icon
1959 (find-image `((:type xpm :data ,breakpoint-xpm-data
1960 :conversion laplace)))
1961 "Icon for disabled breakpoint in display margin")
1964 "Kill the GUD and ancillary (including source) buffers.
1965 Just the partial-output buffer is left."
1967 (let ((buffers (buffer-list)))
1970 (set-buffer (car buffers))
1971 (if (eq gud-minor-mode 'gdba)
1972 (if (string-match "^\*" (buffer-name))
1974 (if (display-graphic-p)
1975 (remove-images (point-min) (point-max))
1976 (remove-strings (point-min) (point-max)))
1977 (setq left-margin-width 0)
1978 (setq gud-minor-mode nil)
1979 (kill-local-variable 'tool-bar-map)
1980 (setq gud-running nil)
1981 (if (get-buffer-window (current-buffer))
1982 (set-window-margins (get-buffer-window
1985 right-margin-width))))
1986 (setq buffers (cdr buffers)))))
1987 (if (eq (selected-window) (minibuffer-window))
1989 (delete-other-windows))
1991 (defun gdb-source-info ()
1992 "Find the source file where the program starts and displays it with related
1994 (goto-char (point-min))
1995 (when (search-forward "directory is " nil t)
1996 (looking-at "\\S-*")
1997 (setq gdb-cdir (match-string 0))
1998 (search-forward "Located in ")
1999 (looking-at "\\S-*")
2000 (setq gdb-main-file (match-string 0))
2001 ;; Make sure we are not in the minibuffer window when we try to delete
2002 ;; all other windows.
2003 (if (window-minibuffer-p (selected-window))
2005 (delete-other-windows)
2006 (if gdb-many-windows
2008 (gdb-display-breakpoints-buffer)
2009 (gdb-display-display-buffer)
2010 (gdb-display-stack-buffer)
2011 (delete-other-windows)
2014 (switch-to-buffer (gud-find-file gdb-main-file))
2016 (setq gdb-source-window (get-buffer-window (current-buffer))))))
2019 (defun put-string (putstring pos &optional string area)
2020 "Put string PUTSTRING in front of POS in the current buffer.
2021 PUTSTRING is displayed by putting an overlay into the current buffer with a
2022 `before-string' STRING that has a `display' property whose value is
2023 PUTSTRING. STRING is defaulted if you omit it.
2024 POS may be an integer or marker.
2025 AREA is where to display the string. AREA nil or omitted means
2026 display it in the text area, a value of `left-margin' means
2027 display it in the left marginal area, a value of `right-margin'
2028 means display it in the right marginal area."
2029 (unless string (setq string "x"))
2030 (let ((buffer (current-buffer)))
2031 (unless (or (null area) (memq area '(left-margin right-margin)))
2032 (error "Invalid area %s" area))
2033 (setq string (copy-sequence string))
2034 (let ((overlay (make-overlay pos pos buffer))
2035 (prop (if (null area) putstring (list (list 'margin area) putstring))))
2036 (put-text-property 0 (length string) 'display prop string)
2037 (overlay-put overlay 'put-text t)
2038 (overlay-put overlay 'before-string string))))
2040 ;;from remove-images
2041 (defun remove-strings (start end &optional buffer)
2042 "Remove strings between START and END in BUFFER.
2043 Remove only images that were put in BUFFER with calls to `put-string'.
2044 BUFFER nil or omitted means use the current buffer."
2046 (setq buffer (current-buffer)))
2047 (let ((overlays (overlays-in start end)))
2049 (let ((overlay (car overlays)))
2050 (when (overlay-get overlay 'put-text)
2051 (delete-overlay overlay)))
2052 (setq overlays (cdr overlays)))))
2054 (defun put-arrow (putstring pos &optional string area)
2055 "Put arrow string PUTSTRING in front of POS in the current buffer.
2056 PUTSTRING is displayed by putting an overlay into the current buffer with a
2057 `before-string' \"gdb-arrow\" that has a `display' property whose value is
2058 PUTSTRING. STRING is defaulted if you omit it.
2059 POS may be an integer or marker.
2060 AREA is where to display the string. AREA nil or omitted means
2061 display it in the text area, a value of `left-margin' means
2062 display it in the left marginal area, a value of `right-margin'
2063 means display it in the right marginal area."
2064 (setq string "gdb-arrow")
2065 (let ((buffer (current-buffer)))
2066 (unless (or (null area) (memq area '(left-margin right-margin)))
2067 (error "Invalid area %s" area))
2068 (setq string (copy-sequence string))
2069 (let ((overlay (make-overlay pos pos buffer))
2070 (prop (if (null area) putstring (list (list 'margin area) putstring))))
2071 (put-text-property 0 (length string) 'display prop string)
2072 (overlay-put overlay 'put-text t)
2073 (overlay-put overlay 'before-string string))))
2075 (defun remove-arrow (&optional buffer)
2076 "Remove arrow in BUFFER.
2077 Remove only images that were put in BUFFER with calls to `put-arrow'.
2078 BUFFER nil or omitted means use the current buffer."
2080 (setq buffer (current-buffer)))
2081 (let ((overlays (overlays-in (point-min) (point-max))))
2083 (let ((overlay (car overlays)))
2084 (when (string-equal (overlay-get overlay 'before-string) "gdb-arrow")
2085 (delete-overlay overlay)))
2086 (setq overlays (cdr overlays)))))
2088 (defun gdb-array-visualise ()
2089 "Visualise arrays and slices using graph program from plotutils."
2091 (when (and (display-graphic-p) gdb-display-string)
2093 (catch 'multi-dimensional
2094 (while (eq (aref gdb-array-start n) (aref gdb-array-stop n))
2097 (while (< m (length gdb-array-start))
2098 (if (not (eq (aref gdb-array-start m) (aref gdb-array-stop m)))
2101 t `(,(concat "Only one dimensional data can be visualised.\n"
2102 "Use an array slice to reduce the number of\n"
2103 "dimensions") ("OK" t)))
2104 (throw 'multi-dimensional nil))
2106 (shell-command (concat "echo" gdb-display-string " | graph -a 1 "
2107 (int-to-string (aref gdb-array-start n))
2109 (int-to-string (aref gdb-array-start n))
2111 (int-to-string (aref gdb-array-stop n))
2114 (defun gdb-delete-display ()
2115 "Delete displayed expression and its frame."
2117 (gdb-instance-enqueue-idle-input
2118 (list (concat "server delete display " gdb-display-number "\n")
2127 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2128 gdb-invalidate-assembler
2129 (concat "server disassemble " gdb-main-or-pc "\n")
2130 gdb-assembler-handler
2131 gdb-assembler-custom)
2133 (defun gdb-assembler-custom ()
2134 (let ((buffer (gdb-get-instance-buffer 'gdb-assembler-buffer))
2135 (gdb-arrow-position) (address) (flag))
2136 (if gdb-current-address
2141 (goto-char (point-min))
2142 (re-search-forward gdb-current-address)
2143 (setq gdb-arrow-position (point))
2144 (put-arrow "=>" gdb-arrow-position nil 'left-margin))))
2146 ;; remove all breakpoint-icons in assembler buffer before updating.
2149 (if (display-graphic-p)
2150 (remove-images (point-min) (point-max))
2151 (remove-strings (point-min) (point-max))))
2153 (set-buffer (gdb-get-instance-buffer 'gdb-breakpoints-buffer))
2154 (goto-char (point-min))
2155 (while (< (point) (- (point-max) 1))
2157 (if (looking-at "[^\t].*breakpoint")
2160 "\\([0-9]*\\)\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)\\s-*0x0\\(\\S-*\\)")
2161 ;; info break gives '0x0' (8 digit) while dump gives '0x' (7 digit)
2162 (setq address (concat "0x" (match-string 3)))
2163 (setq flag (char-after (match-beginning 2)))
2166 (goto-char (point-min))
2167 (if (re-search-forward address nil t)
2168 (let ((start (progn (beginning-of-line) (- (point) 1)))
2169 (end (progn (end-of-line) (+ (point) 1))))
2170 (if (display-graphic-p)
2172 (remove-images start end)
2174 (put-image breakpoint-enabled-icon (point)
2175 "breakpoint icon enabled"
2177 (put-image breakpoint-disabled-icon (point)
2178 "breakpoint icon disabled"
2180 (remove-strings start end)
2182 (put-string "B" (point) "enabled" 'left-margin)
2183 (put-string "b" (point) "disabled"
2184 'left-margin))))))))))
2185 (if gdb-current-address
2186 (set-window-point (get-buffer-window buffer) gdb-arrow-position))))
2188 (gdb-set-instance-buffer-rules 'gdb-assembler-buffer
2189 'gdb-assembler-buffer-name
2190 'gdb-assembler-mode)
2192 (defvar gdb-assembler-mode-map
2193 (let ((map (make-sparse-keymap)))
2194 (suppress-keymap map)
2197 (defun gdb-assembler-mode ()
2198 "Major mode for viewing code assembler.
2200 \\{gdb-assembler-mode-map}"
2201 (setq major-mode 'gdb-assembler-mode)
2202 (setq mode-name "Assembler")
2203 (set (make-local-variable 'gud-minor-mode) 'gdba)
2204 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
2205 (setq left-margin-width 2)
2206 (setq buffer-read-only t)
2207 (use-local-map gdb-assembler-mode-map)
2208 (gdb-invalidate-assembler)
2209 (gdb-invalidate-breakpoints))
2211 (defun gdb-assembler-buffer-name ()
2213 (set-buffer (process-buffer gdb-proc))
2214 (concat "*Machine Code " (gdb-instance-target-string) "*")))
2216 (defun gdb-display-assembler-buffer ()
2219 (gdb-get-create-instance-buffer 'gdb-assembler-buffer)))
2221 (defun gdb-frame-assembler-buffer ()
2223 (switch-to-buffer-other-frame
2224 (gdb-get-create-instance-buffer 'gdb-assembler-buffer)))
2226 (defun gdb-invalidate-frame-and-assembler (&optional ignored)
2227 (gdb-invalidate-frames)
2228 (gdb-invalidate-assembler))
2230 (defun gdb-invalidate-breakpoints-and-assembler (&optional ignored)
2231 (gdb-invalidate-breakpoints)
2232 (gdb-invalidate-assembler))
2234 (defvar gdb-prev-main-or-pc nil)
2236 ;; modified because if gdb-main-or-pc has changed value a new command
2237 ;; must be enqueued to update the buffer with the new output
2238 (defun gdb-invalidate-assembler (&optional ignored)
2239 (if (and (gdb-get-instance-buffer 'gdb-assembler-buffer)
2240 (or (not (member 'gdb-invalidate-assembler
2241 (gdb-instance-pending-triggers)))
2242 (not (string-equal gdb-main-or-pc gdb-prev-main-or-pc))))
2245 ;; take previous disassemble command off the queue
2247 (set-buffer (gdb-get-instance-buffer 'gdba))
2248 (let ((queue gdb-idle-input-queue) (item))
2250 (setq item (car queue))
2251 (if (equal (cdr item) '(gdb-assembler-handler))
2252 (delete item gdb-idle-input-queue))
2253 (setq queue (cdr queue)))))
2255 (gdb-instance-enqueue-idle-input
2256 (list (concat "server disassemble " gdb-main-or-pc "\n")
2257 'gdb-assembler-handler))
2258 (set-gdb-instance-pending-triggers
2259 (cons 'gdb-invalidate-assembler
2260 (gdb-instance-pending-triggers)))
2261 (setq gdb-prev-main-or-pc gdb-main-or-pc))))
2265 ;;; gdb-ui.el ends here