      (get-buffer-create (format "*rdebug-variables-%s*" script-name)))
     (other-window 1)
     (switch-to-buffer
-     (if gud-last-last-frame
-	 (gud-find-file (car gud-last-last-frame))
-       ;; Put buffer list in window if we
-       ;; can't find a source file.
-       ;;
-       ;; Note: The frame-specific buffer list (used when
-       ;; `Buffer-menu-use-frame-buffer-list' is non-nil), can contain
-       ;; killed buffers, which `list-buffers-noselect' crashes on.
-       (let ((Buffer-menu-use-frame-buffer-list nil))
-         (list-buffers-noselect))))
+     (cond (gud-last-last-frame
+            (gud-find-file (car gud-last-last-frame)))
+           (gud-target-name
+            (gud-find-file gud-target-name))
+           (t
+            ;; Put buffer list in window if we
+            ;; can't find a source file.
+            ;;
+            ;; Note: The frame-specific buffer list (used when
+            ;; `Buffer-menu-use-frame-buffer-list' is non-nil), can contain
+            ;; killed buffers, which `list-buffers-noselect' crashes on.
+            (let ((Buffer-menu-use-frame-buffer-list nil))
+              (list-buffers-noselect)))))
     (other-window 1)
     (set-window-buffer 
      (selected-window) 

    (define-key menu [quit] '("Quit"   . rdebug-delete-frame-or-window))
    (define-key menu [goto] '("Goto"   . rdebug-goto-breakpoint))
    (define-key menu [delete] '("Delete" . rdebug-delete-breakpoint))
    ; (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
    (define-key map [mouse-2] 'rdebug-goto-breakpoint-mouse)
    ; (define-key map [? ] 'rdebug-toggle-breakpoint)
    (define-key map [(control m)] 'rdebug-goto-breakpoint)
    (define-key map [?d] 'rdebug-delete-breakpoint)
    map)

	  (gud-call (format "p %s=%s" var value)))
      (message "No variable found"))))

;; -- display (a.k.a watch window)

;; TODO: Add display, delete display.

(defvar rdebug-display-mode-map
  (let ((map (make-sparse-keymap)))
    (suppress-keymap map)
    map))

(defun rdebug-display-mode ()
  "Major mode for rdebug display (watch) window.

\\{rdebug-display-mode}"
  (interactive)
  (kill-all-local-variables)
  (setq major-mode 'rdebug-display-mode)
  (setq mode-name "RDEBUG Display")
  (setq buffer-read-only t)
  (use-local-map rdebug-display-mode-map)
  (run-mode-hooks 'rdebug-display-mode-hook))

(defun rdebug--setup-display-buffer (buf)
  (rdebug-debug-enter "rdebug--setup-display-buffer"
    (with-current-buffer buf (rdebug-display-mode))))

;; -- Reset support

(defadvice gud-reset (before rdebug-reset)
  "rdebug cleanup - remove debugger's internal buffers (frame, breakpoints, 
etc.)."
