changeset 69180:9c5c44399069

(gdb-source-window): New variable. Re-introduce the concept of a source window. (gdb-get-buffer-create): Rename from gdb-get-create-buffer for consistency with get-buffer-create. (def-gdb-auto-update-handler, gdb-info-locals-handler) (gdb-data-list-register-values-handler) (gdb-stack-list-locals-handler): Try to preserve window-start as well as window-point. (gdb-display-source-buffer): New function (old concept). (gdb-goto-breakpoint): Use it.
author Nick Roberts <nickrob@snap.net.nz>
date Mon, 27 Feb 2006 09:14:59 +0000
parents 1a8aba2b127b
children c4332666a388
files lisp/progmodes/gdb-ui.el
diffstat 1 files changed, 69 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/gdb-ui.el	Mon Feb 27 09:12:51 2006 +0000
+++ b/lisp/progmodes/gdb-ui.el	Mon Feb 27 09:14:59 2006 +0000
@@ -124,6 +124,7 @@
   "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
 (defvar gdb-buffer-fringe-width nil)
 (defvar gdb-signalled nil)
+(defvar gdb-source-window nil)
 
 (defvar gdb-buffer-type nil
   "One of the symbols bound in `gdb-buffer-rules'.")
@@ -489,7 +490,8 @@
 	gdb-macro-info nil
 	gdb-buffer-fringe-width (car (window-fringes))
 	gdb-debug-ring nil
-	gdb-signalled nil)
+	gdb-signalled nil
+	gdb-source-window nil)
 
   (setq gdb-buffer-type 'gdba)
 
@@ -835,7 +837,7 @@
 ;; The usual gdb interaction buffer is given the type `gdba' and
 ;; is constructed specially.
 ;;
-;; Others are constructed by gdb-get-create-buffer and
+;; Others are constructed by gdb-get-buffer-create and
 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
 
 (defvar gdb-buffer-rules-assoc '())
@@ -846,7 +848,7 @@
   (save-excursion
     (gdb-look-for-tagged-buffer key (buffer-list))))
 
-(defun gdb-get-create-buffer (key)
+(defun gdb-get-buffer-create (key)
   "Create a new gdb  buffer of the type specified by KEY.
 The key should be one of the cars in `gdb-buffer-rules-assoc'."
   (or (gdb-get-buffer key)
@@ -924,7 +926,7 @@
   (interactive)
   (if gdb-use-separate-io-buffer
       (gdb-display-buffer
-       (gdb-get-create-buffer 'gdb-inferior-io))))
+       (gdb-get-buffer-create 'gdb-inferior-io))))
 
 (defconst gdb-frame-parameters
   '((height . 14) (width . 80)
@@ -939,7 +941,7 @@
   (if gdb-use-separate-io-buffer
       (let ((special-display-regexps (append special-display-regexps '(".*")))
 	    (special-display-frame-alist gdb-frame-parameters))
-	(display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))))
+	(display-buffer (gdb-get-buffer-create 'gdb-inferior-io)))))
 
 (defvar gdb-inferior-io-mode-map
   (let ((map (make-sparse-keymap)))
@@ -1156,7 +1158,7 @@
       (setq gdb-output-sink 'user)
       (let ((handler
 	     (car (cdr gdb-current-item))))
-	(with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
+	(with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
 	  (funcall handler))))
      (t
       (gdb-resync)
@@ -1253,7 +1255,7 @@
     (gdb-get-selected-frame)
     (gdb-invalidate-frames)
     ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
-    (gdb-get-create-buffer 'gdb-breakpoints-buffer)
+    (gdb-get-buffer-create 'gdb-breakpoints-buffer)
     (gdb-invalidate-breakpoints)
     ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
     ;; so gdb-frame-address is updated.
@@ -1288,6 +1290,22 @@
       (gdb-resync)
       (error "Phase error in gdb-post-prompt (got %s)" sink)))))
 
+;; GUD displays the selected GDB frame.  This might might not be the current
+;; GDB frame (after up, down etc).  If no GDB frame is visible but the last
+;; visited breakpoint is, use that window.
+(defun gdb-display-source-buffer (buffer)
+  (let* ((last-window (if gud-last-last-frame
+			 (get-buffer-window
+			  (gud-find-file (car gud-last-last-frame)))))
+	 (source-window (or last-window
+			    (if (and gdb-source-window
+				     (window-live-p gdb-source-window))
+				gdb-source-window))))
+    (when source-window
+      (setq gdb-source-window source-window)
+      (set-window-buffer source-window buffer))
+    source-window))
+
 (defun gud-gdba-marker-filter (string)
   "A gud marker filter for gdb.  Handle a burst of output from GDB."
   (if gdb-flush-pending-output
@@ -1370,23 +1388,23 @@
       (error "Bogon output sink %S" sink)))))
 
 (defun gdb-append-to-partial-output (string)
-  (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
+  (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
     (goto-char (point-max))
     (insert string)))
 
 (defun gdb-clear-partial-output ()
-  (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
+  (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
     (erase-buffer)))
 
 (defun gdb-append-to-inferior-io (string)
-  (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
+  (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
     (goto-char (point-max))
     (insert-before-markers string))
   (if (not (string-equal string ""))
-      (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
+      (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io))))
 
 (defun gdb-clear-inferior-io ()
-  (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
+  (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
     (erase-buffer)))
 
 
@@ -1434,11 +1452,13 @@
        (and buf
 	    (with-current-buffer buf
 	      (let* ((window (get-buffer-window buf 0))
+		     (start (window-start window))
 		     (p (window-point window))
 		    (buffer-read-only nil))
 		(erase-buffer)
-		(insert-buffer-substring (gdb-get-create-buffer
+		(insert-buffer-substring (gdb-get-buffer-create
 					  'gdb-partial-output-buffer))
+		(set-window-start window start)
 		(set-window-point window p)))))
      ;; put customisation here
      (,custom-defun)))
@@ -1688,14 +1708,14 @@
   "Display status of user-settable breakpoints."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
+   (gdb-get-buffer-create 'gdb-breakpoints-buffer)))
 
 (defun gdb-frame-breakpoints-buffer ()
   "Display status of user-settable breakpoints in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
 	(special-display-frame-alist gdb-frame-parameters))
-    (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
+    (display-buffer (gdb-get-buffer-create 'gdb-breakpoints-buffer))))
 
 (defvar gdb-breakpoints-mode-map
   (let ((map (make-sparse-keymap))
@@ -1767,9 +1787,6 @@
   "Display the breakpoint location specified at current line."
   (interactive (list last-input-event))
   (if event (posn-set-point (event-end event)))
-  ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
-  (let ((window (get-buffer-window gud-comint-buffer)))
-    (if window (save-selected-window  (select-window window))))
   (save-excursion
     (beginning-of-line 1)
     (if (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
@@ -1777,11 +1794,13 @@
 	      (file  (match-string 2))
 	      (line  (match-string 3)))
 	  (save-selected-window
-	    (let* ((buf (find-file-noselect
+	    (let* ((buffer (find-file-noselect
 			 (if (file-exists-p file) file
 			   (cdr (assoc bptno gdb-location-alist)))))
-		   (window (display-buffer buf)))
-	      (with-current-buffer buf
+		   (window (unless (gdb-display-source-buffer buffer)
+			       (display-buffer buffer))))
+	      (setq gdb-source-window window)
+	      (with-current-buffer buffer
 		(goto-line (string-to-number line))
 		(set-window-point window (point))))))
       (error "No location specified."))))
@@ -1844,14 +1863,14 @@
   "Display backtrace of current stack."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-create-buffer 'gdb-stack-buffer)))
+   (gdb-get-buffer-create 'gdb-stack-buffer)))
 
 (defun gdb-frame-stack-buffer ()
   "Display backtrace of current stack in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
 	(special-display-frame-alist gdb-frame-parameters))
-    (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
+    (display-buffer (gdb-get-buffer-create 'gdb-stack-buffer))))
 
 (defvar gdb-frames-mode-map
   (let ((map (make-sparse-keymap)))
@@ -1925,14 +1944,14 @@
   "Display IDs of currently known threads."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-create-buffer 'gdb-threads-buffer)))
+   (gdb-get-buffer-create 'gdb-threads-buffer)))
 
 (defun gdb-frame-threads-buffer ()
   "Display IDs of currently known threads in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
 	(special-display-frame-alist gdb-frame-parameters))
-    (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
+    (display-buffer (gdb-get-buffer-create 'gdb-threads-buffer))))
 
 (defvar gdb-threads-mode-map
   (let ((map (make-sparse-keymap)))
@@ -2061,14 +2080,14 @@
   "Display integer register contents."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-create-buffer 'gdb-registers-buffer)))
+   (gdb-get-buffer-create 'gdb-registers-buffer)))
 
 (defun gdb-frame-registers-buffer ()
   "Display integer register contents in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
 	(special-display-frame-alist gdb-frame-parameters))
-    (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
+    (display-buffer (gdb-get-buffer-create 'gdb-registers-buffer))))
 
 (defun gdb-all-registers ()
   "Toggle the display of floating-point registers (pre GDB 6.4 only)."
@@ -2077,10 +2096,10 @@
     (if gdb-all-registers
 	(progn
 	  (setq gdb-all-registers nil)
-	  (with-current-buffer (gdb-get-create-buffer 'gdb-registers-buffer)
+	  (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
 	    (setq mode-name "Registers")))
       (setq gdb-all-registers t)
-      (with-current-buffer (gdb-get-create-buffer 'gdb-registers-buffer)
+      (with-current-buffer (gdb-get-buffer-create 'gdb-registers-buffer)
 	(setq mode-name "Registers:All")))
     (message (format "Display of floating-point registers %sabled"
 		     (if gdb-all-registers "en" "dis")))
@@ -2385,14 +2404,14 @@
   "Display memory contents."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-create-buffer 'gdb-memory-buffer)))
+   (gdb-get-buffer-create 'gdb-memory-buffer)))
 
 (defun gdb-frame-memory-buffer ()
   "Display memory contents in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
 	(special-display-frame-alist gdb-frame-parameters))
-    (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
+    (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
 
 
 ;; Locals buffer.
@@ -2450,12 +2469,15 @@
     (and buf
 	 (with-current-buffer buf
 	      (let* ((window (get-buffer-window buf 0))
+		     (start (window-start window))
 		     (p (window-point window))
 		     (buffer-read-only nil))
 		 (erase-buffer)
-		 (insert-buffer-substring (gdb-get-create-buffer
+		 (insert-buffer-substring (gdb-get-buffer-create
 					   'gdb-partial-output-buffer))
-		(set-window-point window p)))))
+		(set-window-start window start)
+		(set-window-point window p))
+)))
   (run-hooks 'gdb-info-locals-hook))
 
 (defvar gdb-locals-mode-map
@@ -2489,14 +2511,14 @@
   "Display local variables of current stack and their values."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-create-buffer 'gdb-locals-buffer)))
+   (gdb-get-buffer-create 'gdb-locals-buffer)))
 
 (defun gdb-frame-locals-buffer ()
   "Display local variables of current stack and their values in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
 	(special-display-frame-alist gdb-frame-parameters))
-    (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
+    (display-buffer (gdb-get-buffer-create 'gdb-locals-buffer))))
 
 
 ;;;; Window management
@@ -2619,7 +2641,7 @@
     (split-window-horizontally)
     (other-window 1)
     (gdb-set-window-buffer
-     (gdb-get-create-buffer 'gdb-inferior-io)))
+     (gdb-get-buffer-create 'gdb-inferior-io)))
   (other-window 1)
   (gdb-set-window-buffer (gdb-stack-buffer-name))
   (split-window-horizontally)
@@ -2707,7 +2729,7 @@
       (setq gdb-macro-info t))
  (if gdb-many-windows
       (gdb-setup-windows)
-   (gdb-get-create-buffer 'gdb-breakpoints-buffer)
+   (gdb-get-buffer-create 'gdb-breakpoints-buffer)
    (if gdb-show-main
        (let ((pop-up-windows t))
 	 (display-buffer (gud-find-file gdb-main-file))))))
@@ -2960,7 +2982,7 @@
   (interactive)
   (setq gdb-previous-frame nil)
   (gdb-display-buffer
-   (gdb-get-create-buffer 'gdb-assembler-buffer)))
+   (gdb-get-buffer-create 'gdb-assembler-buffer)))
 
 (defun gdb-frame-assembler-buffer ()
   "Display disassembly view in a new frame."
@@ -2968,7 +2990,7 @@
   (setq gdb-previous-frame nil)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
 	(special-display-frame-alist gdb-frame-parameters))
-    (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
+    (display-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))))
 
 ;; modified because if gdb-frame-address has changed value a new command
 ;; must be enqueued to update the buffer with the new output
@@ -3166,11 +3188,14 @@
 	      (concat register-values register-string)))
       (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
 	(with-current-buffer buf
-	  (let ((p (window-point (get-buffer-window buf 0)))
-		(buffer-read-only nil))
+	  (let* ((window (get-buffer-window buf 0))
+		 (start (window-start window))
+		 (p (window-point window))
+		 (buffer-read-only nil))
 	    (erase-buffer)
 	    (insert register-values)
-	    (set-window-point (get-buffer-window buf 0) p))))))
+	    (set-window-start window start)
+	    (set-window-point window p))))))
   (gdb-data-list-register-values-custom))
 
 (defun gdb-data-list-register-values-custom ()
@@ -3255,6 +3280,7 @@
     (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
       (and buf (with-current-buffer buf
 		 (let* ((window (get-buffer-window buf 0))
+			(start (window-start window))
 			(p (window-point window))
 			(buffer-read-only nil))
 		   (erase-buffer)
@@ -3270,6 +3296,7 @@
 		       (insert 
 			(concat name "\t" (nth 1 local)
 				"\t" (nth 2 local) "\n")))
+		   (set-window-start window start)
 		   (set-window-point window p)))))))
 
 (defun gdb-get-register-names ()