]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/gdb-ui.el
(gdb-many-windows): Doc fix (Nil -> nil).
[gnu-emacs] / lisp / progmodes / gdb-ui.el
index 0f92523e30645f5714433b5ff043967f031f37f6..be2b99c897553004c34338f38b0c6040e046c654 100644 (file)
@@ -76,6 +76,9 @@
 ;; 3) M-x gdb doesn't work with "run" command in .gdbinit, use M-x gdba instead.
 ;; 4) M-x gdb doesn't work if the corefile is specified in the command in the
 ;;    minibuffer, use M-x gdba instead (or specify the core in the GUD buffer).
+;; 5) If you wish to call procedures from your program in GDB
+;;    e.g "call myproc ()", "p mysquare (5)" then use level 2 annotations
+;;    "gdb --annotate=2 myprog" to keep source buffer/selected frame fixed.
 
 ;;; Problems with watch expressions, GDB/MI:
 ;; 1) They go out of scope when the inferior is re-run.
@@ -110,7 +113,9 @@ Each element has the form (VARNUM EXPRESSION NUMCHILD TYPE VALUE STATUS FP)
 where STATUS is nil (unchanged), `changed' or `out-of-scope', FP the frame
 address for root variables.")
 (defvar gdb-main-file nil "Source file from which program execution begins.")
+(defvar gud-old-arrow nil)
 (defvar gdb-overlay-arrow-position nil)
+(defvar gdb-stack-position nil)
 (defvar gdb-server-prefix nil)
 (defvar gdb-flush-pending-output nil)
 (defvar gdb-location-alist nil
@@ -126,6 +131,9 @@ and #define directives otherwise.")
 (defvar gdb-inferior-status nil)
 (defvar gdb-continuation nil)
 (defvar gdb-look-up-stack nil)
+(defvar gdb-frame-begin nil
+  "Non-nil when GDB generates frame-begin annotation.")
+(defvar gdb-printing t)
 
 (defvar gdb-buffer-type nil
   "One of the symbols bound in `gdb-buffer-rules'.")
@@ -304,17 +312,17 @@ Also display the main routine in the disassembly buffer if present."
   :version "22.1")
 
 (defcustom gdb-many-windows nil
-  "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
+  "nil means just pop up the GUD buffer unless `gdb-show-main' is t.
 In this case it starts with two windows: one displaying the GUD
 buffer and the other with the source file with the main routine
-of the inferior.  Non-nil means display the layout shown for
+of the debugged program.  Non-nil means display the layout shown for
 `gdba'."
   :type 'boolean
   :group 'gud
   :version "22.1")
 
 (defcustom gdb-use-separate-io-buffer nil
-  "Non-nil means display output from the inferior in a separate buffer."
+  "Non-nil means display output from the debugged program in a separate buffer."
   :type 'boolean
   :group 'gud
   :version "22.1")
@@ -346,14 +354,14 @@ With arg, display additional buffers iff arg is positive."
        (error nil))))
 
 (defun gdb-use-separate-io-buffer (arg)
-  "Toggle separate IO for inferior.
+  "Toggle separate IO for debugged program.
 With arg, use separate IO iff arg is positive."
   (interactive "P")
   (setq gdb-use-separate-io-buffer
        (if (null arg)
            (not gdb-use-separate-io-buffer)
          (> (prefix-numeric-value arg) 0)))
-  (message (format "Separate inferior IO %sabled"
+  (message (format "Separate IO %sabled"
                   (if gdb-use-separate-io-buffer "en" "dis")))
   (if (and gud-comint-buffer
           (buffer-name gud-comint-buffer))
@@ -376,8 +384,7 @@ With arg, use separate IO iff arg is positive."
                            (list t nil) nil "-c"
                            (concat gdb-cpp-define-alist-program " "
                                    gdb-cpp-define-alist-flags)))))
-       (define-list (split-string output "\n" t))
-       (name))
+       (define-list (split-string output "\n" t)) (name))
     (setq gdb-define-alist nil)
     (dolist (define define-list)
       (setq name (nth 1 (split-string define "[( ]")))
@@ -426,7 +433,9 @@ With arg, use separate IO iff arg is positive."
          (when gud-tooltip-mode
            (make-local-variable 'gdb-define-alist)
            (gdb-create-define-alist)
-           (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))))
+           (add-hook 'after-save-hook 'gdb-create-define-alist nil t))))))
+  (gdb-force-mode-line-update
+   (propertize "ready" 'face font-lock-variable-name-face)))
 
 (defun gdb-find-watch-expression ()
   (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list))
@@ -542,7 +551,10 @@ With arg, use separate IO iff arg is positive."
        gdb-source-window nil
        gdb-inferior-status nil
        gdb-continuation nil
-       gdb-look-up-stack nil)
+       gdb-look-up-stack nil
+        gdb-frame-begin nil
+       gdb-printing t
+       gud-old-arrow nil)
 
   (setq gdb-buffer-type 'gdba)
 
@@ -770,7 +782,7 @@ With arg, enter name of variable to be watched in the minibuffer."
 
 (defconst gdb-var-list-children-regexp
  "child={.*?name=\"\\(.*?\\)\",.*?exp=\"\\(.*?\\)\",.*?\
-numchild=\"\\(.*?\\)\",.*?type=\"\\(.*?\\)\".*?}")
+numchild=\"\\(.*?\\)\"\\(}\\|,.*?\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
 
 (defun gdb-var-list-children-handler (varnum)
   (goto-char (point-min))
@@ -784,7 +796,7 @@ numchild=\"\\(.*?\\)\",.*?type=\"\\(.*?\\)\".*?}")
                (let ((varchild (list (match-string 1)
                                      (match-string 2)
                                      (match-string 3)
-                                     (match-string 4)
+                                     (match-string 6)
                                      nil nil)))
                  (if (assoc (car varchild) gdb-var-list)
                      (throw 'child-already-watched nil))
@@ -890,20 +902,23 @@ Changed values are highlighted with the face `font-lock-warning-face'."
 TEXT is the text of the button we clicked on, a + or - item.
 TOKEN is data related to this node.
 INDENT is the current indentation depth."
-  (cond ((string-match "+" text)        ;expand this node
-        (if (and
-             (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
-             (string-equal gdb-version "pre-6.4"))
-            (gdb-var-list-children token)
-          (gdb-var-list-children-1 token)))
-       ((string-match "-" text)        ;contract this node
-        (dolist (var gdb-var-list)
-          (if (string-match (concat token "\\.") (car var))
-              (setq gdb-var-list (delq var gdb-var-list))))
-        (speedbar-change-expand-button-char ?+)
-        (speedbar-delete-subblock indent))
-       (t (error "Ooops...  not sure what to do")))
-  (speedbar-center-buffer-smartly))
+  (if (and gud-comint-buffer (buffer-name gud-comint-buffer))
+      (progn
+       (cond ((string-match "+" text)  ;expand this node
+              (if (and (eq (buffer-local-value
+                            'gud-minor-mode gud-comint-buffer) 'gdba)
+                       (string-equal gdb-version "pre-6.4"))
+                  (gdb-var-list-children token)
+                (gdb-var-list-children-1 token)))
+             ((string-match "-" text)  ;contract this node
+              (dolist (var gdb-var-list)
+                (if (string-match (concat token "\\.") (car var))
+                    (setq gdb-var-list (delq var gdb-var-list))))
+              (speedbar-change-expand-button-char ?+)
+              (speedbar-delete-subblock indent))
+             (t (error "Ooops...  not sure what to do")))
+       (speedbar-center-buffer-smartly))
+    (message-box "GUD session has been killed")))
 
 (defun gdb-get-target-string ()
   (with-current-buffer gud-comint-buffer
@@ -1008,7 +1023,7 @@ The key should be one of the cars in `gdb-buffer-rules-assoc'."
   (interactive)
   (if gdb-use-separate-io-buffer
       (gdb-display-buffer
-       (gdb-get-buffer-create 'gdb-inferior-io))))
+       (gdb-get-buffer-create 'gdb-inferior-io) t)))
 
 (defconst gdb-frame-parameters
   '((height . 14) (width . 80)
@@ -1018,7 +1033,7 @@ The key should be one of the cars in `gdb-buffer-rules-assoc'."
     (minibuffer . nil)))
 
 (defun gdb-frame-separate-io-buffer ()
-  "Display IO of inferior in a new frame."
+  "Display IO of debugged program in a new frame."
   (interactive)
   (if gdb-use-separate-io-buffer
       (let ((special-display-regexps (append special-display-regexps '(".*")))
@@ -1120,7 +1135,7 @@ This filter may simply queue input for a later time."
       (if gdb-prompting
          (progn
            (gdb-send-item item)
-       (setq gdb-prompting nil))
+           (setq gdb-prompting nil))
        (push item gdb-input-queue))))
 
 (defun gdb-dequeue-input ()
@@ -1198,7 +1213,8 @@ This filter may simply queue input for a later time."
 (defun gdb-resync()
   (setq gdb-flush-pending-output t)
   (setq gud-running nil)
-  (gdb-force-mode-line-update "stopped")
+  (gdb-force-mode-line-update
+   (propertize "stopped"'face font-lock-warning-face))
   (setq gdb-output-sink 'user)
   (setq gdb-input-queue nil)
   (setq gdb-pending-triggers nil)
@@ -1238,6 +1254,8 @@ happens to be in effect."
   "An annotation handler for `prompt'.
 This sends the next command (if any) to gdb."
   (when gdb-first-prompt
+    (gdb-force-mode-line-update 
+     (propertize "initializing..." 'face font-lock-variable-name-face))
     (gdb-init-1)
     (setq gdb-first-prompt nil))
   (let ((sink gdb-output-sink))
@@ -1268,16 +1286,21 @@ This sends the next command (if any) to gdb."
 This says that I/O for the subprocess is now the program being debugged,
 not GDB."
   (setq gdb-active-process t)
+  (setq gdb-printing t)
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'user)
       (progn
        (setq gud-running t)
        (setq gdb-inferior-status "running")
-       (gdb-force-mode-line-update gdb-inferior-status)
+       (setq gdb-signalled nil)
+       (gdb-force-mode-line-update
+        (propertize gdb-inferior-status 'face font-lock-type-face))
        (gdb-remove-text-properties)
+       (setq gud-old-arrow gud-overlay-arrow-position)
        (setq gud-overlay-arrow-position nil)
        (setq gdb-overlay-arrow-position nil)
+       (setq gdb-stack-position nil)
        (if gdb-use-separate-io-buffer
            (setq gdb-output-sink 'inferior))))
      (t
@@ -1286,7 +1309,8 @@ not GDB."
 
 (defun gdb-signal (ignored)
   (setq gdb-inferior-status "signal")
-  (gdb-force-mode-line-update gdb-inferior-status)
+  (gdb-force-mode-line-update
+   (propertize gdb-inferior-status 'face font-lock-warning-face))
   (gdb-stopping ignored))
 
 (defun gdb-stopping (ignored)
@@ -1311,14 +1335,19 @@ directives."
   (setq gdb-active-process nil)
   (setq gud-overlay-arrow-position nil)
   (setq gdb-overlay-arrow-position nil)
+  (setq gdb-stack-position nil)
+  (setq gud-old-arrow nil)
   (setq gdb-inferior-status "exited")
-  (gdb-force-mode-line-update gdb-inferior-status)
+  (gdb-force-mode-line-update
+   (propertize gdb-inferior-status 'face font-lock-warning-face))
   (gdb-stopping ignored))
 
 (defun gdb-signalled (ignored)
   (setq gdb-signalled t))
 
 (defun gdb-frame-begin (ignored)
+  (setq gdb-frame-begin t)
+  (setq gdb-printing nil)
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'inferior)
@@ -1329,28 +1358,55 @@ directives."
       (gdb-resync)
       (error "Unexpected frame-begin annotation (%S)" sink)))))
 
+(defcustom gdb-same-frame focus-follows-mouse
+  "Non-nil means pop up GUD buffer in same frame."
+  :group 'gud
+  :type 'boolean
+  :version "22.1")
+
+(defcustom gdb-find-source-frame nil
+  "Non-nil means try to find a source frame further up stack e.g after signal."
+  :group 'gud
+  :type 'boolean
+  :version "22.1")
+
+(defun gdb-find-source-frame (arg)
+  "Toggle trying to find a source frame further up stack.
+With arg, look for a source frame further up stack iff arg is positive."
+  (interactive "P")
+  (setq gdb-find-source-frame
+       (if (null arg)
+           (not gdb-find-source-frame)
+         (> (prefix-numeric-value arg) 0)))
+  (message (format "Looking for source frame %sabled"
+                  (if gdb-find-source-frame "en" "dis"))))
+
 (defun gdb-stopped (ignored)
   "An annotation handler for `stopped'.
 It is just like `gdb-stopping', except that if we already set the output
 sink to `user' in `gdb-stopping', that is fine."
   (setq gud-running nil)
   (unless (or gud-overlay-arrow-position gud-last-frame)
+    (if (and gdb-frame-begin gdb-printing)
+       (setq gud-overlay-arrow-position gud-old-arrow)
     ;;Pop up GUD buffer to display current frame when it doesn't have source
     ;;information i.e id not compiled with -g as with libc routines generally.
-    (let ((special-display-regexps (append special-display-regexps '(".*")))
-         (special-display-frame-alist gdb-frame-parameters)
-         (same-window-regexps nil))
-      (display-buffer gud-comint-buffer))
+    (if gdb-same-frame
+       (gdb-display-gdb-buffer)
+      (gdb-frame-gdb-buffer))
+    (if gdb-find-source-frame
     ;;Try to find source further up stack e.g after signal.
-    (setq gdb-look-up-stack
-         (if (gdb-get-buffer 'gdb-stack-buffer) 'keep
-           (progn
-             (gdb-get-buffer-create 'gdb-stack-buffer)
-             (gdb-invalidate-frames)
-             'delete))))
+       (setq gdb-look-up-stack
+             (if (gdb-get-buffer 'gdb-stack-buffer)
+                 'keep
+               (progn
+                 (gdb-get-buffer-create 'gdb-stack-buffer)
+                 (gdb-invalidate-frames)
+                 'delete))))))
   (unless (member gdb-inferior-status '("exited" "signal"))
     (setq gdb-inferior-status "stopped")
-    (gdb-force-mode-line-update gdb-inferior-status))
+    (gdb-force-mode-line-update
+     (propertize gdb-inferior-status 'face font-lock-warning-face)))
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'inferior)
@@ -1531,7 +1587,7 @@ happens to be appropriate."
     (goto-char (point-max))
     (insert-before-markers string))
   (if (not (string-equal string ""))
-      (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io))))
+      (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io) t)))
 
 (defun gdb-clear-inferior-io ()
   (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
@@ -1722,52 +1778,69 @@ static char *magick[] = {
            (gdb-remove-breakpoint-icons (point-min) (point-max)))))
     (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
       (save-excursion
+       (let ((buffer-read-only nil))
        (goto-char (point-min))
        (while (< (point) (- (point-max) 1))
          (forward-line 1)
-         (if (looking-at "[^\t].*?breakpoint")
+         (if (looking-at gdb-breakpoint-regexp)
              (progn
-               (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
                (setq bptno (match-string 1))
                (setq flag (char-after (match-beginning 2)))
-               (beginning-of-line)
-               (if (re-search-forward " in \\(.*\\) at\\s-+" nil t)
-                   (progn
-                     (let ((buffer-read-only nil))
-                       (add-text-properties (match-beginning 1) (match-end 1)
-                                            '(face font-lock-function-name-face)))
-                     (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
-                     (let ((line (match-string 2)) (buffer-read-only nil)
-                           (file (match-string 1)))
-                       (add-text-properties (line-beginning-position)
-                                            (line-end-position)
-                        '(mouse-face highlight
-                          help-echo "mouse-2, RET: visit breakpoint"))
-                       (unless (file-exists-p file)
-                          (setq file (cdr (assoc bptno gdb-location-alist))))
-                       (if (and file
-                                (not (string-equal file "File not found")))
-                           (with-current-buffer
-                               (find-file-noselect file 'nowarn)
-                             (set (make-local-variable 'gud-minor-mode)
-                                  'gdba)
-                             (set (make-local-variable 'tool-bar-map)
-                                  gud-tool-bar-map)
-                             ;; Only want one breakpoint icon at each
-                             ;; location.
-                             (save-excursion
-                               (goto-line (string-to-number line))
-                               (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
-                         (gdb-enqueue-input
-                          (list
-                           (concat gdb-server-prefix "list "
-                                   (match-string-no-properties 1) ":1\n")
-                           'ignore))
-                         (gdb-enqueue-input
-                          (list (concat gdb-server-prefix "info source\n")
-                                `(lambda () (gdb-get-location
-                                             ,bptno ,line ,flag))))))))))
-         (end-of-line)))))
+               (add-text-properties
+                (match-beginning 2) (match-end 2)
+                (if (eq flag ?y)
+                    '(face font-lock-warning-face)
+                  '(face font-lock-type-face)))
+               (let ((bl (point))
+                     (el (line-end-position)))
+                 (if (re-search-forward " in \\(.*\\) at\\s-+" el t)
+                     (progn
+                       (add-text-properties
+                        (match-beginning 1) (match-end 1)
+                        '(face font-lock-function-name-face))
+                       (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
+                       (let ((line (match-string 2))
+                             (file (match-string 1)))
+                         (add-text-properties bl el
+                          '(mouse-face highlight
+                            help-echo "mouse-2, RET: visit breakpoint"))
+                         (unless (file-exists-p file)
+                           (setq file (cdr (assoc bptno gdb-location-alist))))
+                         (if (and file
+                                  (not (string-equal file "File not found")))
+                             (with-current-buffer
+                                 (find-file-noselect file 'nowarn)
+                               (set (make-local-variable 'gud-minor-mode)
+                                    'gdba)
+                               (set (make-local-variable 'tool-bar-map)
+                                    gud-tool-bar-map)
+                               ;; Only want one breakpoint icon at each
+                               ;; location.
+                               (save-excursion
+                                 (goto-line (string-to-number line))
+                                 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
+                           (gdb-enqueue-input
+                            (list
+                             (concat gdb-server-prefix "list "
+                                     (match-string-no-properties 1) ":1\n")
+                             'ignore))
+                           (gdb-enqueue-input
+                            (list (concat gdb-server-prefix "info source\n")
+                                  `(lambda () (gdb-get-location
+                                               ,bptno ,line ,flag)))))))
+                   (if (re-search-forward
+                        "<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
+                        el t)
+                       (add-text-properties
+                        (match-beginning 1) (match-end 1)
+                        '(face font-lock-function-name-face))
+                     (end-of-line)
+                     (re-search-backward "\\s-\\(\\S-*\\)"
+                                         bl t)
+                     (add-text-properties
+                      (match-beginning 1) (match-end 1)
+                      '(face font-lock-variable-name-face)))))))
+         (end-of-line))))))
   (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
 
 (defun gdb-mouse-set-clear-breakpoint (event)
@@ -1840,7 +1913,7 @@ static char *magick[] = {
   "Display status of user-settable breakpoints."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-buffer-create 'gdb-breakpoints-buffer)))
+   (gdb-get-buffer-create 'gdb-breakpoints-buffer) t))
 
 (defun gdb-frame-breakpoints-buffer ()
   "Display status of user-settable breakpoints in a new frame."
@@ -1970,8 +2043,13 @@ static char *magick[] = {
            (goto-char bl)
            (when (looking-at "^#\\([0-9]+\\)")
              (when (string-equal (match-string 1) gdb-frame-number)
-               (put-text-property bl (+ bl 4)
-                                  'face '(:inverse-video t)))
+               (if (> (car (window-fringes)) 0)
+                   (progn
+                     (or gdb-stack-position
+                         (setq gdb-stack-position (make-marker)))
+                     (set-marker gdb-stack-position (point)))
+                 (put-text-property bl (+ bl 4)
+                                    'face '(:inverse-video t))))
              (when (re-search-forward
                     (concat
                      (if (string-equal (match-string 1) "0") "" " in ")
@@ -2004,9 +2082,10 @@ static char *magick[] = {
   (setq gdb-look-up-stack nil))
 
 (defun gdb-set-hollow ()
-  (with-current-buffer (gud-find-file (car gud-last-last-frame))
-    (setq fringe-indicator-alist
-         '((overlay-arrow . hollow-right-triangle)))))
+  (if gud-last-last-frame
+      (with-current-buffer (gud-find-file (car gud-last-last-frame))
+       (setq fringe-indicator-alist
+             '((overlay-arrow . hollow-right-triangle))))))
 
 (defun gdb-stack-buffer-name ()
   (with-current-buffer gud-comint-buffer
@@ -2016,7 +2095,7 @@ static char *magick[] = {
   "Display backtrace of current stack."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-buffer-create 'gdb-stack-buffer)))
+   (gdb-get-buffer-create 'gdb-stack-buffer) t))
 
 (defun gdb-frame-stack-buffer ()
   "Display backtrace of current stack in a new frame."
@@ -2041,6 +2120,8 @@ static char *magick[] = {
   (kill-all-local-variables)
   (setq major-mode 'gdb-frames-mode)
   (setq mode-name "Frames")
+  (setq gdb-stack-position nil)
+  (add-to-list 'overlay-arrow-variable-list 'gdb-stack-position)
   (setq buffer-read-only t)
   (use-local-map gdb-frames-mode-map)
   (run-mode-hooks 'gdb-frames-mode-hook)
@@ -2097,7 +2178,7 @@ static char *magick[] = {
   "Display IDs of currently known threads."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-buffer-create 'gdb-threads-buffer)))
+   (gdb-get-buffer-create 'gdb-threads-buffer) t))
 
 (defun gdb-frame-threads-buffer ()
   "Display IDs of currently known threads in a new frame."
@@ -2231,7 +2312,7 @@ static char *magick[] = {
   "Display integer register contents."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-buffer-create 'gdb-registers-buffer)))
+   (gdb-get-buffer-create 'gdb-registers-buffer) t))
 
 (defun gdb-frame-registers-buffer ()
   "Display integer register contents in a new frame."
@@ -2492,18 +2573,18 @@ corresponding to the mode line clicked."
            'local-map
            (gdb-make-header-line-mouse-map
             'mouse-1
-            #'(lambda () (interactive)
-                (let ((gdb-memory-address
-                       ;; Let GDB do the arithmetic.
-                       (concat
-                        gdb-memory-address " - "
-                        (number-to-string
-                         (* gdb-memory-repeat-count
-                            (cond ((string= gdb-memory-unit "b") 1)
-                                  ((string= gdb-memory-unit "h") 2)
-                                  ((string= gdb-memory-unit "w") 4)
-                                  ((string= gdb-memory-unit "g") 8)))))))
-                      (gdb-invalidate-memory)))))
+            (lambda () (interactive)
+              (let ((gdb-memory-address
+                     ;; Let GDB do the arithmetic.
+                     (concat
+                      gdb-memory-address " - "
+                      (number-to-string
+                       (* gdb-memory-repeat-count
+                          (cond ((string= gdb-memory-unit "b") 1)
+                                ((string= gdb-memory-unit "h") 2)
+                                ((string= gdb-memory-unit "w") 4)
+                                ((string= gdb-memory-unit "g") 8)))))))
+                (gdb-invalidate-memory)))))
           "|"
           (propertize "+"
                       'face font-lock-warning-face
@@ -2511,9 +2592,9 @@ corresponding to the mode line clicked."
                       'mouse-face 'mode-line-highlight
                       'local-map (gdb-make-header-line-mouse-map
                                   'mouse-1
-                                  #'(lambda () (interactive)
-                                      (let ((gdb-memory-address nil))
-                                        (gdb-invalidate-memory)))))
+                                  (lambda () (interactive)
+                                    (let ((gdb-memory-address nil))
+                                      (gdb-invalidate-memory)))))
           "]: "
           (propertize gdb-memory-address
                       'face font-lock-warning-face
@@ -2555,13 +2636,16 @@ corresponding to the mode line clicked."
   "Display memory contents."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-buffer-create 'gdb-memory-buffer)))
+   (gdb-get-buffer-create 'gdb-memory-buffer) t))
 
 (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))
+  (let* ((special-display-regexps (append special-display-regexps '(".*")))
+        (special-display-frame-alist
+         (cons '(left-fringe . 0)
+               (cons '(right-fringe . 0)
+                     (cons '(width . 83) gdb-frame-parameters)))))
     (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
 \f
 
@@ -2578,13 +2662,14 @@ corresponding to the mode line clicked."
 
 (defvar gdb-locals-watch-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "\r" '(lambda () (interactive)
-                           (beginning-of-line)
-                           (gud-watch)))
-    (define-key map [mouse-2] '(lambda (event) (interactive "e")
-                                (mouse-set-point event)
-                                (beginning-of-line)
-                                (gud-watch)))
+    (suppress-keymap map)
+    (define-key map "\r" (lambda () (interactive)
+                          (beginning-of-line)
+                          (gud-watch)))
+    (define-key map [mouse-2] (lambda (event) (interactive "e")
+                               (mouse-set-point event)
+                               (beginning-of-line)
+                               (gud-watch)))
     map)
  "Keymap to create watch expression of a complex data type local variable.")
 
@@ -2662,7 +2747,7 @@ corresponding to the mode line clicked."
   "Display local variables of current stack and their values."
   (interactive)
   (gdb-display-buffer
-   (gdb-get-buffer-create 'gdb-locals-buffer)))
+   (gdb-get-buffer-create 'gdb-locals-buffer) t))
 
 (defun gdb-frame-locals-buffer ()
   "Display local variables of current stack and their values in a new frame."
@@ -2673,7 +2758,7 @@ corresponding to the mode line clicked."
 \f
 
 ;;;; Window management
-(defun gdb-display-buffer (buf &optional size)
+(defun gdb-display-buffer (buf dedicated &optional size)
   (let ((answer (get-buffer-window buf 0))
        (must-split nil))
     (if answer
@@ -2682,7 +2767,8 @@ corresponding to the mode line clicked."
       (pop-to-buffer gud-comint-buffer)        ;Select the right frame.
       (let ((window (get-lru-window)))
        (if (and window
-           (not (eq window (get-buffer-window gud-comint-buffer))))
+                (not (memq window `(,(get-buffer-window gud-comint-buffer)
+                                    ,gdb-source-window))))
            (progn
              (set-window-buffer window buf)
              (setq answer window))
@@ -2693,7 +2779,7 @@ corresponding to the mode line clicked."
                 (new-size (and size (< size cur-size) (- cur-size size))))
            (setq answer (split-window largest new-size))
            (set-window-buffer answer buf)
-           (set-window-dedicated-p answer t)))
+           (set-window-dedicated-p answer dedicated)))
       answer)))
 
 \f
@@ -2706,7 +2792,7 @@ corresponding to the mode line clicked."
   (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
   (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
   (define-key menu [inferior]
-    '(menu-item "Inferior IO" gdb-display-separate-io-buffer
+    '(menu-item "Separate IO" gdb-display-separate-io-buffer
                :enable gdb-use-separate-io-buffer))
   (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
   (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
@@ -2725,7 +2811,7 @@ corresponding to the mode line clicked."
   (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
   (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
   (define-key menu [inferior]
-    '(menu-item "Inferior IO" gdb-frame-separate-io-buffer
+    '(menu-item "Separate IO" gdb-frame-separate-io-buffer
                :enable gdb-use-separate-io-buffer))
   (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
   (define-key menu [disassembly] '("Disassembly" . gdb-frame-assembler-buffer))
@@ -2738,10 +2824,15 @@ corresponding to the mode line clicked."
   (define-key gud-menu-map [ui]
     `(menu-item (if (eq gud-minor-mode 'gdba) "GDB-UI" "GDB-MI")
                ,menu :visible (memq gud-minor-mode '(gdbmi gdba))))
+  (define-key menu [gdb-find-source-frame]
+  '(menu-item "Look For Source Frame" gdb-find-source-frame
+             :visible (eq gud-minor-mode 'gdba)
+             :help "Toggle look for source frame."
+             :button (:toggle . gdb-find-source-frame)))
   (define-key menu [gdb-use-separate-io]
-  '(menu-item "Separate inferior IO" gdb-use-separate-io-buffer
+  '(menu-item "Separate IO" gdb-use-separate-io-buffer
              :visible (eq gud-minor-mode 'gdba)
-             :help "Toggle separate IO for inferior."
+             :help "Toggle separate IO for debugged program."
              :button (:toggle . gdb-use-separate-io-buffer)))
   (define-key menu [gdb-many-windows]
   '(menu-item "Display Other Windows" gdb-many-windows
@@ -2755,7 +2846,9 @@ corresponding to the mode line clicked."
   "Display GUD buffer in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
-       (special-display-frame-alist gdb-frame-parameters)
+       (special-display-frame-alist
+        (remove '(menu-bar-lines) (remove '(tool-bar-lines)
+                                          gdb-frame-parameters)))
        (same-window-regexps nil))
     (display-buffer gud-comint-buffer)))
 
@@ -2836,12 +2929,13 @@ Kills the gdb buffers, and resets variables and the source buffers."
              (setq gud-minor-mode nil)
              (kill-local-variable 'tool-bar-map)
              (kill-local-variable 'gdb-define-alist))))))
-  (when (markerp gdb-overlay-arrow-position)
-    (move-marker gdb-overlay-arrow-position nil)
-    (setq gdb-overlay-arrow-position nil))
+  (setq gdb-overlay-arrow-position nil)
   (setq overlay-arrow-variable-list
        (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
   (setq fringe-indicator-alist '((overlay-arrow . right-triangle)))
+  (setq gdb-stack-position nil)
+  (setq overlay-arrow-variable-list
+       (delq 'gdb-stack-position overlay-arrow-variable-list))
   (if (boundp 'speedbar-frame) (speedbar-timer-fn))
   (setq gud-running nil)
   (setq gdb-active-process nil)
@@ -3063,8 +3157,7 @@ BUFFER nil or omitted means use the current buffer."
                            '((overlay-arrow . hollow-right-triangle))))
                    (or gdb-overlay-arrow-position
                        (setq gdb-overlay-arrow-position (make-marker)))
-                   (set-marker gdb-overlay-arrow-position
-                               (point) (current-buffer))))))
+                   (set-marker gdb-overlay-arrow-position (point))))))
        ;; remove all breakpoint-icons in assembler buffer before updating.
        (gdb-remove-breakpoint-icons (point-min) (point-max))))
     (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
@@ -3135,7 +3228,7 @@ BUFFER nil or omitted means use the current buffer."
   (interactive)
   (setq gdb-previous-frame nil)
   (gdb-display-buffer
-   (gdb-get-buffer-create 'gdb-assembler-buffer)))
+   (gdb-get-buffer-create 'gdb-assembler-buffer) t))
 
 (defun gdb-frame-assembler-buffer ()
   "Display disassembly view in a new frame."
@@ -3191,8 +3284,8 @@ BUFFER nil or omitted means use the current buffer."
     (setq gdb-frame-number (match-string 1))
     (setq gdb-frame-address (match-string 2)))
   (goto-char (point-min))
-  (when (re-search-forward ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-+?\\)\
-\\(?: (\\(\\S-+?\\):[0-9]+?)\\)*;? "
+  (when (re-search-forward ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(.*?\\)\
+\\(?: (\\(\\S-+?\\):[0-9]+?)\\)*; "
      nil t)
     (setq gdb-selected-frame (match-string 2))
     (if (gdb-get-buffer 'gdb-locals-buffer)
@@ -3239,7 +3332,9 @@ is set in them."
        (when gud-tooltip-mode
          (make-local-variable 'gdb-define-alist)
          (gdb-create-define-alist)
-         (add-hook 'after-save-hook 'gdb-create-define-alist nil t))))))
+         (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))))
+  (gdb-force-mode-line-update
+   (propertize "ready" 'face font-lock-variable-name-face)))
 
 ; Uses "-var-list-children --all-values".  Needs GDB 6.1 onwards.
 (defun gdb-var-list-children-1 (varnum)
@@ -3253,7 +3348,8 @@ is set in them."
 
 (defconst gdb-var-list-children-regexp-1
   "child={.*?name=\"\\(.+?\\)\",.*?exp=\"\\(.+?\\)\",.*?\
-numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\),.*?type=\"\\(.+?\\)\".*?}")
+numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\)\
+\\(}\\|,.*?\\(type=\"\\(.+?\\)\"\\)?.*?}\\)")
 
 (defun gdb-var-list-children-handler-1 (varnum)
   (goto-char (point-min))
@@ -3267,7 +3363,7 @@ numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\),.*?type=\"\\(.+?\\)\".*?}")
                (let ((varchild (list (match-string 1)
                                      (match-string 2)
                                      (match-string 3)
-                                     (match-string 5)
+                                     (match-string 7)
                                      (read (match-string 4))
                                      nil)))
                  (if (assoc (car varchild) gdb-var-list)
@@ -3423,10 +3519,32 @@ in_scope=\"\\(.*?\\)\".*?}")
 
 (defvar gdb-locals-watch-map-1
   (let ((map (make-sparse-keymap)))
+    (suppress-keymap map)
+    (define-key map "\r" 'gud-watch)
     (define-key map [mouse-2] 'gud-watch)
     map)
  "Keymap to create watch expression of a complex data type local variable.")
 
+(defvar gdb-edit-locals-map-1
+  (let ((map (make-sparse-keymap)))
+    (suppress-keymap map)
+    (define-key map "\r" 'gdb-edit-locals-value)
+    (define-key map [mouse-2] 'gdb-edit-locals-value)
+    map)
+ "Keymap to edit value of a simple data type local variable.")
+
+(defun gdb-edit-locals-value (&optional event)
+  "Assign a value to a variable displayed in the locals buffer."
+  (interactive (list last-input-event))
+  (save-excursion
+    (if event (posn-set-point (event-end event)))
+    (beginning-of-line)
+    (let* ((var (current-word))
+          (value (read-string (format "New value (%s): " var))))
+      (gdb-enqueue-input
+       (list (concat  gdb-server-prefix"set variable " var " = " value "\n")
+            'ignore)))))
+
 ;; Dont display values of arrays or structures.
 ;; These can be expanded using gud-watch.
 (defun gdb-stack-list-locals-handler ()
@@ -3454,20 +3572,26 @@ in_scope=\"\\(.*?\\)\".*?}")
                   (let* ((window (get-buffer-window buf 0))
                          (start (window-start window))
                          (p (window-point window))
-                         (buffer-read-only nil))
+                         (buffer-read-only nil) (name) (value))
                     (erase-buffer)
                     (dolist (local locals-list)
                       (setq name (car local))
-                      (if (or (not (nth 2 local))
-                              (string-match "^\\0x" (nth 2 local)))
+                      (setq value (nth 2 local))
+                      (if (or (not value)
+                              (string-match "^\\0x" value))
                           (add-text-properties 0 (length name)
                                `(mouse-face highlight
                                  help-echo "mouse-2: create watch expression"
                                  local-map ,gdb-locals-watch-map-1)
-                               name))
+                               name)
+                        (add-text-properties 0 (length value)
+                             `(mouse-face highlight
+                               help-echo "mouse-2: edit value"
+                               local-map ,gdb-edit-locals-map-1)
+                             value))
                       (insert
                        (concat name "\t" (nth 1 local)
-                               "\t" (nth 2 local) "\n")))
+                               "\t" value "\n")))
                     (set-window-start window start)
                     (set-window-point window p))))))))