]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/gdb-ui.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / progmodes / gdb-ui.el
index 7bc904f83192ed27bb01886da59bb913587b3c98..45843ec696f90145a911498bd6a5715594f3d9b6 100644 (file)
@@ -4,14 +4,14 @@
 ;; Maintainer: FSF
 ;; Keywords: unix, tools
 
-;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
 ;; Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -34,8 +34,7 @@
 ;; Emacs 21 such as the fringe/display margin for breakpoints, and the toolbar
 ;; (see the GDB Graphical Interface section in the Emacs info manual).
 
-;; By default, M-x gdb will start the debugger. However, if you have customised
-;; gud-gdb-command-name, then start it with M-x gdba.
+;; By default, M-x gdb will start the debugger.
 
 ;; This file has evolved from gdba.el that was included with GDB 5.0 and
 ;; written by Tom Lord and Jim Kingdon.  It uses GDB's annotation interface.
 ;; section in the GDB info manual.
 
 ;; GDB developers plan to make the annotation interface obsolete.  A new
-;; interface called GDB/MI (machine interface) has been designed to replace
-;; it.  Some GDB/MI commands are used in this file through the CLI command
-;; 'interpreter mi <mi-command>'.  A file called gdb-mi.el is included with
-;; GDB (6.2 onwards) that uses GDB/MI as the primary interface to GDB.  It is
-;; still under development and is part of a process to migrate Emacs from
-;; annotations to GDB/MI.
+;; interface called GDB/MI (machine interface) has been designed to replace it.
+;; Some GDB/MI commands are used in this file through the CLI command
+;; 'interpreter mi <mi-command>'.  To help with the process of fully migrating
+;; Emacs from annotations to GDB/MI, there is an experimental package called
+;; gdb-mi in the Emacs Lisp Package Archive ("http://tromey.com/elpa/").  It
+;; comprises of modified gud.el and a file called gdb-mi.el which replaces
+;; gdb-ui.el.  When installed, this overrides the current files and invoking
+;; M-x gdb will use GDB/MI directly (starts with "gdb -i=mi").  When deleted
+;; ('d' followed by 'x' in Package Menu mode), the files are deleted and old
+;; functionality restored.  This provides a convenient way to review the
+;; current status/contribute to its improvement.  For someone who just wants to
+;; use GDB, however, the current mode in Emacs 22 is a much better option.
+;; There is also a file, also called gdb-mi.el, a version of which is included
+;; the GDB distribution.  This will probably only work with versions
+;; distributed with GDB 6.5 or later.  Unlike the version in ELPA it works on
+;; top of gdb-ui.el and you can only start it with M-x gdbmi.
 
 ;; This mode SHOULD WORK WITH GDB 5.0 or later but you will NEED AT LEAST
 ;; GDB 6.0 to use watch expressions.  It works best with GDB 6.4 or later
 
 ;; and compiling with -DUNBUFFERED while debugging.
 
+;; If you are using Cygwin GDB and find that the source is not being displayed
+;; in Emacs when you step through it, possible solutions are to:
+
+;;   1) Use Cygwin X Windows and Cygwin Emacs.
+;;        (Since 22.1 Emacs builds under Cygwin.)
+;;   2) Use MinGW GDB instead.
+;;   3) Use cygwin-mount.el
+
 ;;; Known Bugs:
 
-;; 1) Strings that are watched don't update in the speedbar when their
-;;    contents change unless the first character changes.
-;; 2) Cannot handle multiple debug sessions.
-;; 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
+;; 1) Cannot handle multiple debug sessions.
+;; 2) 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.
-;; 6) After detaching from a process, clicking on the "GO" icon on toolbar
+;; 3) After detaching from a process, clicking on the "GO" icon on toolbar
 ;;    (gud-go) sends "continue" to GDB (should be "run").
 
-;;; Problems with watch expressions, GDB/MI:
-
-;; 1) They go out of scope when the inferior is re-run.
-;; 2) -stack-list-locals has a type field but also prints type in values field.
-;; 3) VARNUM increments even when variable object is not created
-;;    (maybe trivial).
-
 ;;; TODO:
 
 ;; 1) Use MI command -data-read-memory for memory window.
-;; 2) Use tree-widget.el instead of the speedbar for watch-expressions?
+;; 2) Use tree-buffer.el (from ECB) instead of the speedbar for
+;;    watch-expressions?  Handling of watch-expressions needs to be
+;;    overhauled to work for large arrays/structures by creating variable
+;;    objects for visible watch-expressions only.
 ;; 3) Mark breakpoint locations on scroll-bar of source buffer?
 
 ;;; Code:
 (defvar speedbar-initial-expansion-list-name)
 
 (defvar gdb-pc-address nil "Initialization for Assembler buffer.
-Set to \"main\" at start if gdb-show-main is t.")
+Set to \"main\" at start if `gdb-show-main' is t.")
 (defvar gdb-frame-address nil "Identity of frame for watch expression.")
-(defvar gdb-previous-frame-address nil)
+(defvar gdb-previous-frame-pc-address nil)
 (defvar gdb-memory-address "main")
 (defvar gdb-previous-frame nil)
 (defvar gdb-selected-frame nil)
 (defvar gdb-frame-number nil)
 (defvar gdb-current-language nil)
 (defvar gdb-var-list nil
- "List of variables in watch window.
 "List of variables in watch window.
 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-thread-indicator nil)
 (defvar gdb-overlay-arrow-position nil)
 (defvar gdb-stack-position nil)
 (defvar gdb-server-prefix nil)
@@ -139,6 +148,10 @@ Emacs can't find.")
 (defvar gdb-frame-begin nil
   "Non-nil when GDB generates frame-begin annotation.")
 (defvar gdb-printing t)
+(defvar gdb-parent-bptno-enabled nil)
+(defvar gdb-ready nil)
+(defvar gdb-stack-update nil)
+(defvar gdb-early-user-input nil)
 
 (defvar gdb-buffer-type nil
   "One of the symbols bound in `gdb-buffer-rules'.")
@@ -150,7 +163,7 @@ Emacs can't find.")
 (defvar gdb-prompting nil
   "True when gdb is idle with no pending input.")
 
-(defvar gdb-output-sink 'user
+(defvar gdb-output-sink nil
   "The disposition of the output of the current gdb command.
 Possible values are these symbols:
 
@@ -176,19 +189,17 @@ gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
   "The most recent command item sent to gdb.")
 
 (defvar gdb-pending-triggers '()
-  "A list of trigger functions that have run later than their output
-handlers.")
+  "A list of trigger functions that have run later than their output handlers.")
 
 (defvar gdb-first-post-prompt nil)
 (defvar gdb-version nil)
 (defvar gdb-locals-font-lock-keywords nil)
 (defvar gdb-source-file-list nil
-  "List of source files for the current executable")
+  "List of source files for the current executable.")
 (defconst gdb-error-regexp "\\^error,msg=\"\\(.+\\)\"")
 
 (defvar gdb-locals-font-lock-keywords-1
-  '(
-    ;; var = (struct struct_tag) value
+  '(;; var = (struct struct_tag) value
     ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +(\\(struct\\) \\(\\(\\sw\\|[_.]\\)+\\)"
       (1 font-lock-variable-name-face)
       (3 font-lock-keyword-face)
@@ -199,17 +210,14 @@ handlers.")
       (3 font-lock-type-face))
     ;; var = val
     ( "\\(^\\(\\sw\\|[_.]\\)+\\) += +[^(]"
-      (1 font-lock-variable-name-face))
-    )
+      (1 font-lock-variable-name-face)))
   "Font lock keywords used in `gdb-local-mode'.")
 
 (defvar gdb-locals-font-lock-keywords-2
-  '(
-    ;; var = type value
+  '(;; var = type value
     ( "\\(^\\(\\sw\\|[_.]\\)+\\)\t+\\(\\(\\sw\\|[_.]\\)+\\)"
       (1 font-lock-variable-name-face)
-      (3 font-lock-type-face))
-    )
+      (3 font-lock-type-face)))
   "Font lock keywords used in `gdb-local-mode'.")
 
 ;; Variables for GDB 6.4+
@@ -218,10 +226,10 @@ handlers.")
   "List of changed register numbers (strings).")
 
 ;;;###autoload
-(defun gdba (command-line)
+(defun gdb (command-line)
   "Run gdb on program FILE in buffer *gud-FILE*.
-The directory containing FILE becomes the initial working directory
-and source-file directory for your debugger.
+The directory containing FILE becomes the initial working
+directory and source-file directory for your debugger.
 
 If `gdb-many-windows' is nil (the default value) then gdb just
 pops up the GUD buffer unless `gdb-show-main' is t.  In this case
@@ -244,79 +252,129 @@ The following commands help control operation :
 See Info node `(emacs)GDB Graphical Interface' for a more
 detailed description of this mode.
 
-
 +----------------------------------------------------------------------+
 |                               GDB Toolbar                            |
 +-----------------------------------+----------------------------------+
-| GUD buffer (I/O of GDB)           | Locals buffer                    |
-|                                   |                                  |
+|  GUD buffer (I/O of GDB)          |  Locals buffer                   |
+|-----------------------------------+----------------------------------+
 |                                   |                                  |
+|  Source buffer                    |  I/O buffer for debugged program |
 |                                   |                                  |
+|-----------------------------------+----------------------------------+
+|  Stack buffer                     |  Breakpoints/threads buffer      |
 +-----------------------------------+----------------------------------+
-| Source buffer                     | I/O buffer (of debugged program) |
-|                                   | (comint-mode)                    |
-|                                   |                                  |
-|                                   |                                  |
-|                                   |                                  |
-|                                   |                                  |
-|                                   |                                  |
-|                                   |                                  |
-+-----------------------------------+----------------------------------+
-| Stack buffer                      | Breakpoints buffer               |
-| RET      gdb-frames-select        | SPC    gdb-toggle-breakpoint     |
-|                                   | RET    gdb-goto-breakpoint       |
-|                                   | D      gdb-delete-breakpoint     |
-+-----------------------------------+----------------------------------+"
-  ;;
-  (interactive (list (gud-query-cmdline 'gdba)))
-  ;;
-  ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
-  (gdb command-line)
-  (gdb-init-1))
+
+To run GDB in text command mode, replace the GDB \"--annotate=3\"
+option with \"--fullname\" either in the minibuffer for the
+current Emacs session, or the custom variable
+`gud-gdb-command-name' for all future sessions.  You need to use
+text command mode to debug multiple programs within one Emacs
+session."
+  (interactive (list (gud-query-cmdline 'gdb)))
+
+  (when (and gud-comint-buffer
+          (buffer-name gud-comint-buffer)
+          (get-buffer-process gud-comint-buffer)
+          (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)))
+       (gdb-restore-windows)
+       (error
+        "Multiple debugging requires restarting in text command mode"))
+
+  (gud-common-init command-line nil 'gud-gdba-marker-filter)
+  (set (make-local-variable 'gud-minor-mode) 'gdba)
+  (setq comint-input-sender 'gdb-send)
+
+  (gud-def gud-break  "break %f:%l"  "\C-b" "Set breakpoint at current line.")
+  (gud-def gud-tbreak "tbreak %f:%l" "\C-t"
+          "Set temporary breakpoint at current line.")
+  (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line.")
+  (gud-def gud-step   "step %p"     "\C-s" "Step one source line with display.")
+  (gud-def gud-stepi  "stepi %p"    "\C-i" "Step one instruction with display.")
+  (gud-def gud-next   "next %p"     "\C-n" "Step one line (skip functions).")
+  (gud-def gud-nexti  "nexti %p" nil   "Step one instruction (skip functions).")
+  (gud-def gud-cont   "cont"     "\C-r" "Continue with display.")
+  (gud-def gud-finish "finish"   "\C-f" "Finish executing current function.")
+  (gud-def gud-jump
+          (progn (gud-call "tbreak %f:%l") (gud-call "jump %f:%l"))
+          "\C-j" "Set execution address to current line.")
+
+  (gud-def gud-up     "up %p"     "<" "Up N stack frames (numeric arg).")
+  (gud-def gud-down   "down %p"   ">" "Down N stack frames (numeric arg).")
+  (gud-def gud-print  "print %e"  "\C-p" "Evaluate C expression at point.")
+  (gud-def gud-pstar  "print* %e" nil
+          "Evaluate C dereferenced pointer expression at point.")
+
+  ;; For debugging Emacs only.
+  (gud-def gud-pv "pv1 %e"      "\C-v" "Print the value of the lisp variable.")
+
+  (gud-def gud-until  "until %l" "\C-u" "Continue to current line.")
+  (gud-def gud-run    "run"     nil    "Run the program.")
+
+  (local-set-key "\C-i" 'gud-gdb-complete-command)
+  (setq comint-prompt-regexp "^(.*gdb[+]?) *")
+  (setq paragraph-start comint-prompt-regexp)
+  (setq gdb-output-sink 'user)
+  (setq gdb-first-prompt t)
+  (setq gud-running nil)
+  (setq gdb-ready nil)
+  (setq gdb-stack-update nil)
+  (setq gdb-flush-pending-output nil)
+  (setq gdb-early-user-input nil)
+  (setq gud-filter-pending-text nil)
+  (gdb-thread-identification)
+  (run-hooks 'gdb-mode-hook))
+
+;; Keep as an alias for compatibility with Emacs 22.1.
+;;;###autoload
+(defalias 'gdba 'gdb)
+
+(defgroup gdb nil
+  "Gdb Graphical Mode options specifically for running Gdb in Emacs."
+  :group 'processes
+  :group 'tools)
 
 (defcustom gdb-debug-log-max 128
   "Maximum size of `gdb-debug-log'.  If nil, size is unlimited."
-  :group 'gud
+  :group 'gdb
   :type '(choice (integer :tag "Number of elements")
                 (const   :tag "Unlimited" nil))
   :version "22.1")
 
 (defvar gdb-debug-log nil
-  "List of commands sent to and replies received from GDB.  Most
-recent commands are listed first.  This list stores only the last
-'gdb-debug-log-max' values.  This variable is used to debug
-GDB-UI.")
+  "List of commands sent to and replies received from GDB.
+Most recent commands are listed first.  This list stores only the last
+`gdb-debug-log-max' values.  This variable is used to debug GDB-UI.")
 
 ;;;###autoload
 (defcustom gdb-enable-debug nil
   "Non-nil means record the process input and output in `gdb-debug-log'."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-cpp-define-alist-program "gcc -E -dM -"
   "Shell command for generating a list of defined macros in a source file.
 This list is used to display the #define directive associated
 with an identifier as a tooltip.  It works in a debug session with
-GDB, when gud-tooltip-mode is t.
+GDB, when `gud-tooltip-mode' is t.
 
 Set `gdb-cpp-define-alist-flags' for any include paths or
 predefined macros."
   :type 'string
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-cpp-define-alist-flags ""
   "Preprocessor flags for `gdb-cpp-define-alist-program'."
   :type 'string
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-show-main nil
   "Non-nil means display source file containing the main routine at startup.
 Also display the main routine in the disassembly buffer if present."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-many-windows nil
@@ -326,13 +384,13 @@ buffer and the other with the source file with the main routine
 of the debugged program.  Non-nil means display the layout shown
 for `gdba'."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-use-separate-io-buffer nil
   "Non-nil means display output from the debugged program in a separate buffer."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defun gdb-force-mode-line-update (status)
@@ -347,7 +405,8 @@ for `gdba'."
 
 (defun gdb-many-windows (arg)
   "Toggle the number of windows in the basic arrangement.
-With arg, display additional buffers iff arg is positive."
+With prefix argument ARG, display additional buffers if ARG is positive,
+otherwise use a single window."
   (interactive "P")
   (setq gdb-many-windows
        (if (null arg)
@@ -363,7 +422,8 @@ With arg, display additional buffers iff arg is positive."
 
 (defun gdb-use-separate-io-buffer (arg)
   "Toggle separate IO for debugged program.
-With arg, use separate IO iff arg is positive."
+With prefix argument ARG, use separate IO if ARG is positive,
+otherwise do not."
   (interactive "P")
   (setq gdb-use-separate-io-buffer
        (if (null arg)
@@ -387,11 +447,11 @@ With arg, use separate IO iff arg is positive."
         (output
          (with-output-to-string
            (with-current-buffer standard-output
-             (call-process shell-file-name
-                           (if (file-exists-p file) file nil)
+             (and file (file-exists-p file)
+             (call-process shell-file-name file
                            (list t nil) nil "-c"
                            (concat gdb-cpp-define-alist-program " "
-                                   gdb-cpp-define-alist-flags)))))
+                                   gdb-cpp-define-alist-flags))))))
        (define-list (split-string output "\n" t)) (name))
     (setq gdb-define-alist nil)
     (dolist (define define-list)
@@ -424,6 +484,15 @@ With arg, use separate IO iff arg is positive."
 
 (defconst gdb-source-file-regexp "\\(.+?\\), \\|\\([^, \n].*$\\)")
 
+(defun gdb-init-buffer ()
+  (set (make-local-variable 'gud-minor-mode)
+       (buffer-local-value 'gud-minor-mode gud-comint-buffer))
+  (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
+  (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)))
+
 (defun gdb-set-gud-minor-mode-existing-buffers ()
   "Create list of source files for current GDB session."
   (goto-char (point-min))
@@ -436,12 +505,7 @@ With arg, use separate IO iff arg is positive."
        (when (and buffer-file-name
                   (member (file-name-nondirectory buffer-file-name)
                           gdb-source-file-list))
-         (set (make-local-variable 'gud-minor-mode) 'gdba)
-         (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
-         (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))))))
+         (gdb-init-buffer)))))
   (gdb-force-mode-line-update
    (propertize "ready" 'face font-lock-variable-name-face)))
 
@@ -463,9 +527,6 @@ With arg, use separate IO iff arg is positive."
       expr)))
 
 (defun gdb-init-1 ()
-  (set (make-local-variable 'gud-minor-mode) 'gdba)
-  (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
-  ;;
   (gud-def gud-break (if (not (string-match "Machine" mode-name))
                         (gud-call "break %f:%l" arg)
                       (save-excursion
@@ -500,7 +561,7 @@ With arg, use separate IO iff arg is positive."
             "pp1 " (if (eq (buffer-local-value
                             'major-mode (window-buffer)) 'speedbar-mode)
                        (gdb-find-watch-expression) "%e")) arg)
-          nil   "Print the emacs s-expression.")
+          nil   "Print the Emacs s-expression.")
 
   (define-key gud-minor-mode-map [left-margin mouse-1]
     'gdb-mouse-set-clear-breakpoint)
@@ -529,11 +590,9 @@ With arg, use separate IO iff arg is positive."
   (define-key gud-minor-mode-map [left-margin C-mouse-3]
     'gdb-mouse-jump)
 
-  (setq comint-input-sender 'gdb-send)
-
   ;; (re-)initialize
   (setq gdb-pc-address (if gdb-show-main "main" nil))
-  (setq gdb-previous-frame-address nil
+  (setq gdb-previous-frame-pc-address nil
        gdb-memory-address "main"
        gdb-previous-frame nil
        gdb-selected-frame nil
@@ -548,7 +607,6 @@ With arg, use separate IO iff arg is positive."
        gdb-pending-triggers nil
        gdb-output-sink 'user
        gdb-server-prefix "server "
-       gdb-flush-pending-output nil
        gdb-location-alist nil
        gdb-source-file-list nil
        gdb-error nil
@@ -562,7 +620,8 @@ With arg, use separate IO iff arg is positive."
        gdb-look-up-stack nil
         gdb-frame-begin nil
        gdb-printing t
-       gud-old-arrow nil)
+       gud-old-arrow nil
+       gdb-thread-indicator nil)
 
   (setq gdb-buffer-type 'gdba)
 
@@ -597,7 +656,7 @@ With arg, use separate IO iff arg is positive."
   (gdb-enqueue-input (list "server list\n" 'ignore))
   (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
 
-  (run-hooks 'gdba-mode-hook))
+  (run-hooks 'gdb-mode-hook))
 
 (defun gdb-get-version ()
   (goto-char (point-min))
@@ -637,7 +696,7 @@ with mouse-1 (default bindings)."
   "Set execution address/line.
 The destination source line can be selected either by clicking with C-mouse-3
 on the fringe/margin or dragging the arrow with C-mouse-1 (default bindings).
-Unlike gdb-mouse-until the destination address can be before the current
+Unlike `gdb-mouse-until' the destination address can be before the current
 line, and no execution takes place."
   (interactive "e")
   (let ((start (event-start event))
@@ -659,12 +718,13 @@ line, and no execution takes place."
   "If non-nil raise speedbar every time display of watch expressions is\
  updated."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defun gdb-speedbar-auto-raise (arg)
   "Toggle automatic raising of the speedbar for watch expressions.
-With arg, automatically raise speedbar iff arg is positive."
+With prefix argument ARG, automatically raise speedbar if ARG is
+positive, otherwise don't automatically raise it."
   (interactive "P")
   (setq gdb-speedbar-auto-raise
        (if (null arg)
@@ -676,7 +736,7 @@ With arg, automatically raise speedbar iff arg is positive."
 (defcustom gdb-use-colon-colon-notation nil
   "If non-nil use FUN::VAR format to display variables in the speedbar."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch)
@@ -698,16 +758,16 @@ With arg, enter name of variable to be watched in the minibuffer."
                                        'gud-gdb-complete-command)
                     (if (and transient-mark-mode mark-active)
                         (buffer-substring (region-beginning) (region-end))
-                      (tooltip-identifier-from-point (point))))))
-             (speedbar 1)
-               (set-text-properties 0 (length expr) nil expr)
-               (gdb-enqueue-input
-                (list
-                 (if (eq minor-mode 'gdba)
-                     (concat
-                      "server interpreter mi \"-var-create - * "  expr "\"\n")
-                   (concat"-var-create - * "  expr "\n"))
-                 `(lambda () (gdb-var-create-handler ,expr)))))))
+                      (concat (if (eq major-mode 'gdb-registers-mode) "$")
+                              (tooltip-identifier-from-point (point)))))))
+             (set-text-properties 0 (length expr) nil expr)
+             (gdb-enqueue-input
+              (list
+               (if (eq minor-mode 'gdba)
+                   (concat
+                    "server interpreter mi \"-var-create - * "  expr "\"\n")
+                 (concat"-var-create - * "  expr "\n"))
+               `(lambda () (gdb-var-create-handler ,expr)))))))
       (message "gud-watch is a no-op in this mode."))))
 
 (defconst gdb-var-create-regexp
@@ -727,6 +787,7 @@ With arg, enter name of variable to be watched in the minibuffer."
                  (if (match-string 3) (read (match-string 3)))
                  nil gdb-frame-address)))
        (push var gdb-var-list)
+       (speedbar 1)
        (unless (string-equal
                 speedbar-initial-expansion-list-name "GUD")
          (speedbar-change-initial-expansion-list "GUD"))
@@ -753,6 +814,8 @@ With arg, enter name of variable to be watched in the minibuffer."
     (push 'gdb-speedbar-timer gdb-pending-triggers)))
 
 (defun gdb-speedbar-timer-fn ()
+  (if gdb-speedbar-auto-raise
+      (raise-frame speedbar-frame))
   (setq gdb-pending-triggers
        (delq 'gdb-speedbar-timer gdb-pending-triggers))
   (speedbar-timer-fn))
@@ -774,7 +837,7 @@ With arg, enter name of variable to be watched in the minibuffer."
         `(lambda () (gdb-var-list-children-handler ,varnum)))))
 
 (defconst gdb-var-list-children-regexp
- "child={.*?name=\"\\(.*?\\)\",.*?exp=\"\\(.*?\\)\",.*?\
 "child={.*?name=\"\\(.*?\\)\",.*?exp=\"\\(.*?\\)\",.*?\
 numchild=\"\\(.*?\\)\"\\(}\\|,.*?\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
 
 (defun gdb-var-list-children-handler (varnum)
@@ -835,11 +898,32 @@ type_changed=\".*?\".*?}")
   (setq gdb-pending-triggers
        (delq 'gdb-var-update gdb-pending-triggers)))
 
+(defun gdb-var-set-format (format)
+  "Set the output format for a variable displayed in the speedbar."
+  (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
+        (varnum (car var)))
+    (gdb-enqueue-input
+     (list
+      (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
+         (concat "server interpreter mi \"-var-set-format "
+                 varnum " " format "\"\n")
+       (concat "-var-set-format " varnum " " format "\n"))
+          `(lambda () (gdb-var-set-format-handler ,varnum))))))
+
+(defconst gdb-var-set-format-regexp
+  "format=\"\\(.*?\\)\",.*value=\"\\(.*?\\)\"")
+
+(defun gdb-var-set-format-handler (varnum)
+  (goto-char (point-min))
+  (if (re-search-forward gdb-var-set-format-regexp nil t)
+      (let ((var (assoc varnum gdb-var-list)))
+       (setcar (nthcdr 4 var) (match-string 2))
+       (gdb-var-update-1))))
+
 (defun gdb-var-delete-1 (varnum)
   (gdb-enqueue-input
    (list
-    (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
-           'gdba)
+    (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
        (concat "server interpreter mi \"-var-delete " varnum "\"\n")
       (concat "-var-delete " varnum "\n"))
     'ignore))
@@ -890,15 +974,21 @@ type_changed=\".*?\".*?}")
 Out of scope variables are suppressed with `shadow' face.
 Changed values are highlighted with the face `font-lock-warning-face'."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-max-children 40
   "Maximum number of children before expansion requires confirmation."
   :type 'integer
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
+(defcustom gdb-delete-out-of-scope t
+  "If non-nil delete watch expressions automatically when they go out of scope."
+  :type 'boolean
+  :group 'gdb
+  :version "22.2")
+
 (defun gdb-speedbar-expand-node (text token indent)
   "Expand the node the user clicked on.
 TEXT is the text of the button we clicked on, a + or - item.
@@ -955,7 +1045,7 @@ The key should be one of the cars in `gdb-buffer-rules-assoc'."
     (gdb-look-for-tagged-buffer key (buffer-list))))
 
 (defun gdb-get-buffer-create (key)
-  "Create a new gdb  buffer of the type specified by 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)
       (let* ((rules (assoc key gdb-buffer-rules-assoc))
@@ -1121,20 +1211,24 @@ The key should be one of the cars in `gdb-buffer-rules-assoc'."
 (defun gdb-send (proc string)
   "A comint send filter for gdb.
 This filter may simply queue input for a later time."
-  (with-current-buffer gud-comint-buffer
-    (let ((inhibit-read-only t))
-      (remove-text-properties (point-min) (point-max) '(face))))
-    (if gud-running
-       (progn
-         (let ((item (concat string "\n")))
-           (if gdb-enable-debug (push (cons 'send item) gdb-debug-log))
-           (process-send-string proc item)))
-      (if (and (string-match "\\\\$" string)
-              (not comint-input-sender-no-newline)) ;;Try to catch C-d.
-         (setq gdb-continuation (concat gdb-continuation string "\n"))
-       (let ((item (concat gdb-continuation string "\n")))
-         (gdb-enqueue-input item)
-         (setq gdb-continuation nil)))))
+  (if gdb-ready
+      (progn
+       (with-current-buffer gud-comint-buffer
+         (let ((inhibit-read-only t))
+           (remove-text-properties (point-min) (point-max) '(face))))
+       (if gud-running
+           (progn
+             (let ((item (concat string "\n")))
+               (if gdb-enable-debug (push (cons 'send item) gdb-debug-log))
+               (process-send-string proc item)))
+         (if (string-match "\\\\\\'" string)
+             (setq gdb-continuation (concat gdb-continuation string "\n"))
+           (let ((item (concat
+                        gdb-continuation string
+                        (if (not comint-input-sender-no-newline) "\n"))))
+             (gdb-enqueue-input item)
+             (setq gdb-continuation nil)))))
+    (push (concat string "\n")  gdb-early-user-input)))
 
 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
 ;; is a query, or other non-top-level prompt.
@@ -1149,10 +1243,12 @@ This filter may simply queue input for a later time."
 
 (defun gdb-dequeue-input ()
   (let ((queue gdb-input-queue))
-    (and queue
-        (let ((last (car (last queue))))
-          (unless (nbutlast queue) (setq gdb-input-queue '()))
-          last))))
+    (if queue
+       (let ((last (car (last queue))))
+         (unless (nbutlast queue) (setq gdb-input-queue '()))
+         last)
+      ;; This should be nil here anyway but set it just to make sure.
+      (setq gdb-pending-triggers nil))))
 
 (defun gdb-send-item (item)
   (setq gdb-flush-pending-output nil)
@@ -1190,8 +1286,10 @@ This filter may simply queue input for a later time."
 ;; any newlines.
 ;;
 
-(defcustom gud-gdba-command-name "gdb -annotate=3"
-  "Default command to execute an executable under the GDB-UI debugger."
+(defcustom gud-gdb-command-name "gdb --annotate=3"
+  "Default command to execute an executable under the GDB debugger.
+The option \"--annotate=3\" must be included in this value if you
+want the GDB Graphical Interface."
   :type 'string
   :group 'gud
   :version "22.1")
@@ -1217,13 +1315,14 @@ This filter may simply queue input for a later time."
     ("stopped" gdb-stopped)
     ("error-begin" gdb-error)
     ("error" gdb-error)
-    ) "An assoc mapping annotation tags to functions which process them.")
+    ("new-thread" (lambda (ignored) (gdb-get-buffer-create 'gdb-threads-buffer))))
+  "An assoc mapping annotation tags to functions which process them.")
 
 (defun gdb-resync()
   (setq gdb-flush-pending-output t)
   (setq gud-running nil)
   (gdb-force-mode-line-update
-   (propertize "stopped"'face font-lock-warning-face))
+   (propertize "stopped" 'face font-lock-warning-face))
   (setq gdb-output-sink 'user)
   (setq gdb-input-queue nil)
   (setq gdb-pending-triggers nil)
@@ -1263,7 +1362,7 @@ 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 
+    (gdb-force-mode-line-update
      (propertize "initializing..." 'face font-lock-variable-name-face))
     (gdb-init-1)
     (setq gdb-first-prompt nil))
@@ -1284,7 +1383,11 @@ This sends the next command (if any) to gdb."
        (gdb-send-item input)
       (progn
        (setq gdb-prompting t)
-       (gud-display-frame)))))
+       (gud-display-frame)
+       (setq gdb-early-user-input (nreverse gdb-early-user-input))
+       (while gdb-early-user-input
+           (gdb-enqueue-input (car gdb-early-user-input))
+           (setq gdb-early-user-input (cdr gdb-early-user-input)))))))
 
 (defun gdb-subprompt (ignored)
   "An annotation handler for non-top-level prompts."
@@ -1301,6 +1404,10 @@ not GDB."
      ((eq sink 'user)
       (progn
        (setq gud-running t)
+       (setq gdb-stack-update t)
+       ;; Temporarily set gud-running to nil to force "info stack" onto queue.
+       (let ((gud-running nil))
+         (gdb-invalidate-frames))
        (setq gdb-inferior-status "running")
        (setq gdb-signalled nil)
        (gdb-force-mode-line-update
@@ -1367,21 +1474,25 @@ directives."
       (gdb-resync)
       (error "Unexpected frame-begin annotation (%S)" sink)))))
 
-(defcustom gdb-same-frame focus-follows-mouse
+(defcustom gdb-same-frame (not focus-follows-mouse)
   "Non-nil means pop up GUD buffer in same frame."
-  :group 'gud
+  :group 'gdb
   :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
+  :group 'gdb
   :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."
+  "Toggle looking for a source frame further up call stack.
+The code associated with current (innermost) frame may not have
+been compiled with debug information, e.g., C library routine.
+With prefix argument ARG, look for a source frame further up
+stack to display in the source buffer if ARG is positive,
+otherwise don't look further up."
   (interactive "P")
   (setq gdb-find-source-frame
        (if (null arg)
@@ -1457,7 +1568,8 @@ happens to be appropriate."
       (gdb-invalidate-locals-1))
 
     (gdb-invalidate-threads)
-    (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
+    (unless (or (null gdb-var-list)
+            (eq system-type 'darwin)) ;Breaks on Darwin's GDB-5.3.
       ;; FIXME: with GDB-6 on Darwin, this might very well work.
       ;; Only needed/used with speedbar/watch expressions.
       (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
@@ -1502,6 +1614,10 @@ happens to be appropriate."
       (set-window-buffer source-window buffer))
     source-window))
 
+;; Derived from gud-gdb-marker-regexp
+(defvar gdb-fullname-regexp
+  (concat "\\(.:?[^" ":" "\n]*\\)" ":" "\\([0-9]*\\)" ":" ".*"))
+
 (defun gud-gdba-marker-filter (string)
   "A gud marker filter for gdb.  Handle a burst of output from GDB."
   (if gdb-flush-pending-output
@@ -1518,34 +1634,50 @@ happens to be appropriate."
       ;;
       ;; Process all the complete markers in this chunk.
       (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
-       (let ((annotation (match-string 1 gud-marker-acc)))
-         ;;
-         ;; Stuff prior to the match is just ordinary output.
-         ;; It is either concatenated to OUTPUT or directed
-         ;; elsewhere.
-         (setq output
-               (gdb-concat-output
-                output
-                (substring gud-marker-acc 0 (match-beginning 0))))
-         ;;
-         ;; Take that stuff off the gud-marker-acc.
-         (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
+       (let ((annotation (match-string 1 gud-marker-acc))
+             (before (substring gud-marker-acc 0 (match-beginning 0)))
+             (after (substring gud-marker-acc (match-end 0))))
          ;;
          ;; Parse the tag from the annotation, and maybe its arguments.
          (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
          (let* ((annotation-type (match-string 1 annotation))
                 (annotation-arguments (match-string 2 annotation))
                 (annotation-rule (assoc annotation-type
-                                        gdb-annotation-rules)))
+                                        gdb-annotation-rules))
+                (fullname (string-match gdb-fullname-regexp annotation-type)))
+
+           ;; Stuff prior to the match is just ordinary output.
+           ;; It is either concatenated to OUTPUT or directed
+           ;; elsewhere.
+           (setq output
+                 (gdb-concat-output output
+                                    (concat before (if fullname "\n"))))
+
+           ;; Take that stuff off the gud-marker-acc.
+           (setq gud-marker-acc after)
+
            ;; Call the handler for this annotation.
            (if annotation-rule
                (funcall (car (cdr annotation-rule))
                         annotation-arguments)
-             ;; Else the annotation is not recognized.  Ignore it silently,
-             ;; so that GDB can add new annotations without causing
-             ;; us to blow up.
-             ))))
-      ;;
+
+             ;; Switch to gud-gdb-marker-filter if appropriate.
+             (when fullname
+
+               ;; Extract the frame position from the marker.
+               (setq gud-last-frame (cons (match-string 1 annotation)
+                                          (string-to-number
+                                           (match-string 2 annotation))))
+
+               (set (make-local-variable 'gud-minor-mode) 'gdb)
+               (set (make-local-variable 'gud-marker-filter)
+                    'gud-gdb-marker-filter)))
+
+           ;; Else the annotation is not recognized.  Ignore it silently,
+           ;; so that GDB can add new annotations without causing
+           ;; us to blow up.
+           )))
+
       ;; Does the remaining text end in a partial line?
       ;; If it does, then keep part of the gud-marker-acc until we get more.
       (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
@@ -1768,7 +1900,7 @@ static char *magick[] = {
      :foreground "red1"
      :weight bold))
   "Face for enabled breakpoint icon in fringe."
-  :group 'gud)
+  :group 'gdb)
 
 (defface breakpoint-disabled
   '((((class color) (min-colors 88)) :foreground "grey70")
@@ -1781,10 +1913,10 @@ static char *magick[] = {
      :inverse-video t)
     (t :background "gray"))
   "Face for disabled breakpoint icon in fringe."
-  :group 'gud)
+  :group 'gdb)
 
 (defconst gdb-breakpoint-regexp
-  "\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\s-+\\(.\\)\\s-+")
+  "\\(?:\\([0-9]+\\).*?\\(?:point\\|catch\\s-+\\S-+\\)\\s-+\\S-+\\|\\([0-9]+\\.[0-9]+\\)\\)\\s-+\\(.\\)\\s-+")
 
 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
 (defun gdb-info-breakpoints-custom ()
@@ -1798,41 +1930,40 @@ static char *magick[] = {
     (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 gdb-breakpoint-regexp)
-             (progn
-               (setq bptno (match-string 1))
-               (setq flag (char-after (match-beginning 2)))
-               (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]+\\)")
+         (goto-char (point-min))
+         (while (< (point) (- (point-max) 1))
+           (forward-line 1)
+           (if (looking-at gdb-breakpoint-regexp)
+               (progn
+                 (setq bptno (or (match-string 1) (match-string 2)))
+                 (setq flag (char-after (match-beginning 3)))
+                 (if (match-string 1)
+                     (setq gdb-parent-bptno-enabled (eq flag ?y)))
+                 (add-text-properties
+                  (match-beginning 3) (match-end 3)
+                  (if (eq flag ?y)
+                      '(face font-lock-warning-face)
+                    '(face font-lock-type-face)))
+                 (let ((bl (point))
+                       (el (line-end-position)))
+                   (when (re-search-forward " in \\(.*\\) at" el t)
+                     (add-text-properties
+                      (match-beginning 1) (match-end 1)
+                      '(face font-lock-function-name-face)))
+                   (if (re-search-forward
+                        ".*\\s-+\\(\\S-+\\):\\([0-9]+\\)$" nil t)
                        (let ((line (match-string 2))
                              (file (match-string 1)))
                          (add-text-properties bl el
-                          '(mouse-face highlight
-                            help-echo "mouse-2, RET: visit breakpoint"))
+                              '(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)
+                               (gdb-init-buffer)
                                ;; Only want one breakpoint icon at each
                                ;; location.
                                (save-excursion
@@ -1846,36 +1977,48 @@ static char *magick[] = {
                            (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)
+                                               ,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-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)))
+                        '(face font-lock-variable-name-face)))))))
+           (end-of-line))))))
+  (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom))
+
+  ;; Breakpoints buffer is always present.  Hack to just update
+  ;; current frame if there's been no execution.
+  (if gdb-stack-update
+      (setq gdb-stack-update nil)
+    (if (gdb-get-buffer 'gdb-stack-buffer) (gdb-info-stack-custom))))
+
+(declare-function gud-remove "gdb-ui" t t) ; gud-def
+(declare-function gud-break  "gdb-ui" t t) ; gud-def
 
 (defun gdb-mouse-set-clear-breakpoint (event)
-  "Set/clear breakpoint in left fringe/margin with mouse click."
+  "Set/clear breakpoint in left fringe/margin at mouse click.
+If not in a source or disassembly buffer just set point."
   (interactive "e")
   (mouse-minibuffer-check event)
   (let ((posn (event-end event)))
-    (if (numberp (posn-point posn))
-       (with-selected-window (posn-window posn)
-         (save-excursion
-           (goto-char (posn-point posn))
-           (if (or (posn-object posn)
-                   (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
-                       'breakpoint))
-               (gud-remove nil)
-             (gud-break nil)))))))
+    (with-selected-window (posn-window posn)
+      (if (or (buffer-file-name) (eq major-mode 'gdb-assembler-mode))
+         (if (numberp (posn-point posn))
+             (save-excursion
+               (goto-char (posn-point posn))
+               (if (or (posn-object posn)
+                       (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
+                           'breakpoint))
+                   (gud-remove nil)
+                 (gud-break nil)))))
+      (posn-set-point posn))))
 
 (defun gdb-mouse-toggle-breakpoint-margin (event)
   "Enable/disable breakpoint in left margin with mouse click."
@@ -1887,17 +2030,18 @@ static char *magick[] = {
          (save-excursion
            (goto-char (posn-point posn))
            (if (posn-object posn)
-               (gdb-enqueue-input
-                (list
-                 (let ((bptno (get-text-property
-                               0 'gdb-bptno (car (posn-string posn)))))
+               (let* ((bptno (get-text-property
+                              0 'gdb-bptno (car (posn-string posn)))))
+                 (string-match "\\([0-9+]\\)*" bptno)
+                 (gdb-enqueue-input
+                  (list
                    (concat gdb-server-prefix
                            (if (get-text-property
                                 0 'gdb-enabled (car (posn-string posn)))
                                "disable "
                              "enable ")
-                           bptno "\n"))
-                 'ignore))))))))
+                           (match-string 1 bptno) "\n")
+                  'ignore)))))))))
 
 (defun gdb-mouse-toggle-breakpoint-fringe (event)
   "Enable/disable breakpoint in left fringe with mouse click."
@@ -1915,14 +2059,16 @@ static char *magick[] = {
            (when (overlay-get overlay 'put-break)
              (setq obj (overlay-get overlay 'before-string))))
          (when (stringp obj)
-           (gdb-enqueue-input
-            (list
-             (concat gdb-server-prefix
-              (if (get-text-property 0 'gdb-enabled obj)
-                  "disable "
-                "enable ")
-              (get-text-property 0 'gdb-bptno obj) "\n")
-             'ignore))))))))
+           (let* ((bptno (get-text-property 0 'gdb-bptno obj)))
+             (string-match "\\([0-9+]\\)*" bptno)
+             (gdb-enqueue-input
+              (list
+               (concat gdb-server-prefix
+                       (if (get-text-property 0 'gdb-enabled obj)
+                           "disable "
+                         "enable ")
+                       (match-string 1 bptno) "\n")
+               'ignore)))))))))
 
 (defun gdb-breakpoints-buffer-name ()
   (with-current-buffer gud-comint-buffer
@@ -1965,6 +2111,47 @@ static char *magick[] = {
   (if (one-window-p) (delete-frame)
     (delete-window)))
 
+;;from make-mode-line-mouse-map
+(defun gdb-make-header-line-mouse-map (mouse function) "\
+Return a keymap with single entry for mouse key MOUSE on the header line.
+MOUSE is defined to run function FUNCTION with no args in the buffer
+corresponding to the mode line clicked."
+  (let ((map (make-sparse-keymap)))
+    (define-key map (vector 'header-line mouse) function)
+    (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
+    map))
+
+(defvar gdb-breakpoints-header
+ `(,(propertize "Breakpoints"
+               'help-echo "mouse-1: select"
+               'mouse-face 'mode-line-highlight
+               'face 'mode-line
+               'local-map
+               (gdb-make-header-line-mouse-map
+                'mouse-1
+                (lambda (event) (interactive "e")
+                  (save-selected-window
+                    (select-window (posn-window (event-start event)))
+                    (set-window-dedicated-p (selected-window) nil)
+                    (switch-to-buffer
+                     (gdb-get-buffer-create 'gdb-breakpoints-buffer))
+                    (set-window-dedicated-p (selected-window) t)))))
+   " "
+   ,(propertize "Threads"
+               'help-echo "mouse-1: select"
+               'mouse-face 'mode-line-highlight
+               'face 'mode-line
+               'local-map
+               (gdb-make-header-line-mouse-map
+                'mouse-1
+                (lambda (event) (interactive "e")
+                  (save-selected-window
+                    (select-window (posn-window (event-start event)))
+                    (set-window-dedicated-p (selected-window) nil)
+                    (switch-to-buffer
+                     (gdb-get-buffer-create 'gdb-threads-buffer))
+                    (set-window-dedicated-p (selected-window) t)))))))
+
 (defun gdb-breakpoints-mode ()
   "Major mode for gdb breakpoints.
 
@@ -1974,6 +2161,8 @@ static char *magick[] = {
   (setq mode-name "Breakpoints")
   (use-local-map gdb-breakpoints-mode-map)
   (setq buffer-read-only t)
+  (buffer-disable-undo)
+  (setq header-line-format gdb-breakpoints-header)
   (run-mode-hooks 'gdb-breakpoints-mode-hook)
   (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
       'gdb-invalidate-breakpoints
@@ -1988,21 +2177,25 @@ static char *magick[] = {
        (gdb-enqueue-input
         (list
          (concat gdb-server-prefix
-                 (if (eq ?y (char-after (match-beginning 2)))
+                 (if (eq ?y (char-after (match-beginning 3)))
                      "disable "
                    "enable ")
-                 (match-string 1) "\n") 'ignore))
+                 (or (match-string 1) (match-string 2)) "\n") 'ignore))
       (error "Not recognized as break/watchpoint line"))))
 
 (defun gdb-delete-breakpoint ()
   "Delete the breakpoint at current line."
   (interactive)
-  (beginning-of-line 1)
-  (if (looking-at gdb-breakpoint-regexp)
-      (gdb-enqueue-input
-       (list
-       (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
-    (error "Not recognized as break/watchpoint line")))
+  (save-excursion
+    (beginning-of-line 1)
+    (if (looking-at gdb-breakpoint-regexp)
+       (if (match-string 1)
+           (gdb-enqueue-input
+            (list
+             (concat gdb-server-prefix "delete " (match-string 1) "\n")
+             'ignore))
+         (message-box "This breakpoint cannot be deleted on its own."))
+      (error "Not recognized as break/watchpoint line"))))
 
 (defun gdb-goto-breakpoint (&optional event)
   "Display the breakpoint location specified at current line."
@@ -2010,7 +2203,7 @@ static char *magick[] = {
   (if event (posn-set-point (event-end event)))
   (save-excursion
     (beginning-of-line 1)
-    (if (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
+    (if (looking-at "\\([0-9]+\\.?[0-9]*\\) .*\\s-+\\(\\S-+\\):\\([0-9]+\\)$")
        (let ((bptno (match-string 1))
              (file  (match-string 2))
              (line  (match-string 3)))
@@ -2027,7 +2220,7 @@ static char *magick[] = {
       (error "No location specified."))))
 \f
 
-;; Frames buffer.  This displays a perpetually correct bactracktrace
+;; Frames buffer.  This displays a perpetually correct backtrace
 ;; (from the command `where').
 ;;
 ;; Alas, if your stack is deep, it is costly.
@@ -2035,7 +2228,7 @@ static char *magick[] = {
 (defcustom gdb-max-frames 40
   "Maximum number of frames displayed in call stack."
   :type 'integer
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (gdb-set-buffer-rules 'gdb-stack-buffer
@@ -2048,64 +2241,80 @@ static char *magick[] = {
   gdb-info-stack-handler
   gdb-info-stack-custom)
 
+;; This may be more important for embedded targets where unwinding the
+;; stack may take a long time.
+(defadvice gdb-invalidate-frames (around gdb-invalidate-frames-advice
+                                        (&optional ignored) activate compile)
+  "Only queue \"info stack\" if execution has occurred."
+  (if gdb-stack-update ad-do-it))
+
 (defun gdb-info-stack-custom ()
   (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
-    (save-excursion
-      (unless (eq gdb-look-up-stack 'delete)
-       (let ((buffer-read-only nil)
-             bl el)
-         (goto-char (point-min))
-         (while (< (point) (point-max))
-           (setq bl (line-beginning-position)
-                 el (line-end-position))
-           (when (looking-at "#")
-             (add-text-properties bl el
-                                  '(mouse-face highlight
-                                    help-echo "mouse-2, RET: Select frame")))
-           (goto-char bl)
-           (when (looking-at "^#\\([0-9]+\\)")
-             (when (string-equal (match-string 1) gdb-frame-number)
-               (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 ")
-                     "\\([^ ]+\\) (") el t)
-               (put-text-property (match-beginning 1) (match-end 1)
-                                  'face font-lock-function-name-face)
-               (setq bl (match-end 0))
-               (while (re-search-forward "<\\([^>]+\\)>" el t)
-                 (put-text-property (match-beginning 1) (match-end 1)
-                                    'face font-lock-function-name-face))
-               (goto-char bl)
-               (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
-                 (put-text-property (match-beginning 1) (match-end 1)
-                                    'face font-lock-variable-name-face))))
-           (forward-line 1))
-         (forward-line -1)
-         (when (looking-at "(More stack frames follow...)")
-           (add-text-properties (match-beginning 0) (match-end 0)
-            '(mouse-face highlight
-              gdb-max-frames t
-              help-echo
-               "mouse-2, RET: customize gdb-max-frames to see more frames")))))
-      (when gdb-look-up-stack
+    (let (move-to)
+      (save-excursion
+       (unless (eq gdb-look-up-stack 'delete)
+         (let ((buffer-read-only nil)
+               bl el)
            (goto-char (point-min))
-           (when (re-search-forward "\\(\\S-+?\\):\\([0-9]+\\)" nil t)
-             (let ((start (line-beginning-position))
-                   (file (match-string 1))
-                   (line (match-string 2)))
-               (re-search-backward "^#*\\([0-9]+\\)" start t)
-               (gdb-enqueue-input
-                (list (concat gdb-server-prefix "frame "
-                              (match-string 1) "\n") 'gdb-set-hollow))
-               (gdb-enqueue-input
-                (list (concat gdb-server-prefix "frame 0\n") 'ignore)))))))
+           (while (< (point) (point-max))
+             (setq bl (line-beginning-position)
+                   el (line-end-position))
+             (when (looking-at "#")
+               (add-text-properties bl el
+                   '(mouse-face highlight
+                                help-echo "mouse-2, RET: Select frame")))
+             (goto-char bl)
+             (when (looking-at "^#\\([0-9]+\\)")
+               (when (string-equal (match-string 1) gdb-frame-number)
+                 (if (gud-tool-bar-item-visible-no-fringe)
+                     (progn
+                       (put-text-property bl (+ bl 4)
+                                          'face '(:inverse-video t))
+                       (setq move-to bl))
+                   (or gdb-stack-position
+                       (setq gdb-stack-position (make-marker)))
+                   (set-marker gdb-stack-position (point))
+                   (setq move-to gdb-stack-position)))
+               (when (re-search-forward "\\([^ ]+\\) (" el t)
+                 (put-text-property (match-beginning 1) (match-end 1)
+                                    'face font-lock-function-name-face)
+                 (setq bl (match-end 0))
+                 (while (re-search-forward "<\\([^>]+\\)>" el t)
+                   (put-text-property (match-beginning 1) (match-end 1)
+                                      'face font-lock-function-name-face))
+                 (goto-char bl)
+                 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
+                   (put-text-property (match-beginning 1) (match-end 1)
+                                      'face font-lock-variable-name-face))))
+             (forward-line 1))
+           (forward-line -1)
+           (when (looking-at "(More stack frames follow...)")
+             (add-text-properties
+              (match-beginning 0) (match-end 0)
+              '(mouse-face highlight
+                gdb-max-frames t
+                help-echo
+                  "mouse-2, RET: customize gdb-max-frames to see more frames"
+                )))))
+       (when gdb-look-up-stack
+         (goto-char (point-min))
+         (when (re-search-forward "\\(\\S-+?\\):\\([0-9]+\\)" nil t)
+           (let ((start (line-beginning-position))
+                 (file (match-string 1))
+                 (line (match-string 2)))
+             (re-search-backward "^#*\\([0-9]+\\)" start t)
+             (gdb-enqueue-input
+              (list (concat gdb-server-prefix "frame "
+                            (match-string 1) "\n") 'gdb-set-hollow))
+             (gdb-enqueue-input
+              (list (concat gdb-server-prefix "frame 0\n") 'ignore))))))
+      (when move-to
+       (let ((window (get-buffer-window (current-buffer) 0)))
+         (when window
+           (with-selected-window window
+             (goto-char move-to)
+             (unless (pos-visible-in-window-p)
+               (recenter '(center)))))))))
   (if (eq gdb-look-up-stack 'delete)
       (kill-buffer (gdb-get-buffer 'gdb-stack-buffer)))
   (setq gdb-look-up-stack nil))
@@ -2138,10 +2347,24 @@ static char *magick[] = {
     (suppress-keymap map)
     (define-key map "q" 'kill-this-buffer)
     (define-key map "\r" 'gdb-frames-select)
+    (define-key map "F" 'gdb-frames-force-update)
     (define-key map [mouse-2] 'gdb-frames-select)
     (define-key map [follow-link] 'mouse-face)
     map))
 
+(declare-function gdbmi-invalidate-frames "ext:gdb-mi" nil t)
+
+(defun gdb-frames-force-update ()
+  "Force update of call stack.
+Use when the displayed call stack gets out of sync with the
+actual one, e.g after using the Gdb command \"return\" or setting
+$pc directly from the GUD buffer.  This command isn't normally needed."
+  (interactive)
+  (setq gdb-stack-update t)
+  (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
+      (gdb-invalidate-frames)
+    (gdbmi-invalidate-frames)))
+
 (defun gdb-frames-mode ()
   "Major mode for gdb call stack.
 
@@ -2149,12 +2372,15 @@ static char *magick[] = {
   (kill-all-local-variables)
   (setq major-mode 'gdb-frames-mode)
   (setq mode-name "Frames")
-  (setq gdb-stack-position nil) 
+  (setq gdb-stack-position nil)
   (add-to-list 'overlay-arrow-variable-list 'gdb-stack-position)
   (setq truncate-lines t)  ;; Make it easier to see overlay arrow.
   (setq buffer-read-only t)
+  (buffer-disable-undo)
+  (gdb-thread-identification)
   (use-local-map gdb-frames-mode-map)
   (run-mode-hooks 'gdb-frames-mode-hook)
+  (setq gdb-stack-update t)
   (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
       'gdb-invalidate-frames
     'gdbmi-invalidate-frames))
@@ -2198,6 +2424,12 @@ another GDB command e.g pwd, to see new frames")
     (let ((buffer-read-only nil))
       (save-excursion
        (goto-char (point-min))
+       (if (re-search-forward "\\* \\([0-9]+\\)" nil t)
+           (setq gdb-thread-indicator
+                 (propertize (concat " [" (match-string 1) "]")
+                             ; FIXME: this help-echo doesn't work
+                             'help-echo "thread id")))
+       (goto-char (point-min))
        (while (< (point) (point-max))
          (unless (looking-at "No ")
            (add-text-properties (line-beginning-position) (line-end-position)
@@ -2245,11 +2477,14 @@ another GDB command e.g pwd, to see new frames")
   (setq major-mode 'gdb-threads-mode)
   (setq mode-name "Threads")
   (setq buffer-read-only t)
+  (buffer-disable-undo)
+  (setq header-line-format gdb-breakpoints-header)
   (use-local-map gdb-threads-mode-map)
   (set (make-local-variable 'font-lock-defaults)
        '(gdb-threads-font-lock-keywords))
   (run-mode-hooks 'gdb-threads-mode-hook)
-  'gdb-invalidate-threads)
+  ;; Force "info threads" onto queue.
+  (lambda () (let ((gud-running nil)) (gdb-invalidate-threads))))
 
 (defun gdb-get-thread-number ()
   (save-excursion
@@ -2264,14 +2499,18 @@ another GDB command e.g pwd, to see new frames")
    (list (concat gdb-server-prefix "thread "
                 (gdb-get-thread-number) "\n") 'ignore))
   (gud-display-frame))
-\f
 
+(defun gdb-thread-identification ()
+  (setq mode-line-buffer-identification
+       (list (car mode-line-buffer-identification)
+             '(gdb-thread-indicator gdb-thread-indicator))))
+\f
 ;; Registers buffer.
 ;;
 (defcustom gdb-all-registers nil
   "Non-nil means include floating-point registers."
   :type 'boolean
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (gdb-set-buffer-rules 'gdb-registers-buffer
@@ -2323,6 +2562,37 @@ another GDB command e.g pwd, to see new frames")
     (define-key map "q" 'kill-this-buffer)
      map))
 
+(defvar gdb-locals-header
+ `(,(propertize "Locals"
+               'help-echo "mouse-1: select"
+               'mouse-face 'mode-line-highlight
+               'face 'mode-line
+               'local-map
+               (gdb-make-header-line-mouse-map
+                'mouse-1
+                (lambda (event) (interactive "e")
+                  (save-selected-window
+                    (select-window (posn-window (event-start event)))
+                    (set-window-dedicated-p (selected-window) nil)
+                    (switch-to-buffer
+                     (gdb-get-buffer-create 'gdb-locals-buffer))
+                    (set-window-dedicated-p (selected-window) t)))))
+   " "
+   ,(propertize "Registers"
+               'help-echo "mouse-1: select"
+               'mouse-face 'mode-line-highlight
+               'face 'mode-line
+               'local-map
+               (gdb-make-header-line-mouse-map
+                'mouse-1
+                (lambda (event) (interactive "e")
+                  (save-selected-window
+                    (select-window (posn-window (event-start event)))
+                    (set-window-dedicated-p (selected-window) nil)
+                    (switch-to-buffer
+                     (gdb-get-buffer-create 'gdb-registers-buffer))
+                    (set-window-dedicated-p (selected-window) t)))))))
+
 (defun gdb-registers-mode ()
   "Major mode for gdb registers.
 
@@ -2330,7 +2600,10 @@ another GDB command e.g pwd, to see new frames")
   (kill-all-local-variables)
   (setq major-mode 'gdb-registers-mode)
   (setq mode-name "Registers")
+  (setq header-line-format gdb-locals-header)
   (setq buffer-read-only t)
+  (buffer-disable-undo)
+  (gdb-thread-identification)
   (use-local-map gdb-registers-mode-map)
   (run-mode-hooks 'gdb-registers-mode-hook)
   (if (string-equal gdb-version "pre-6.4")
@@ -2378,7 +2651,7 @@ another GDB command e.g pwd, to see new frames")
 (defcustom gdb-memory-repeat-count 32
   "Number of data items in memory window."
   :type 'integer
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-memory-format "x"
@@ -2388,7 +2661,7 @@ another GDB command e.g pwd, to see new frames")
                 (const :tag "Unsigned decimal" "u")
                 (const :tag "Octal" "o")
                 (const :tag "Binary" "t"))
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (defcustom gdb-memory-unit "w"
@@ -2397,7 +2670,7 @@ another GDB command e.g pwd, to see new frames")
                 (const :tag "Halfword" "h")
                 (const :tag "Word" "w")
                 (const :tag "Giant word" "g"))
-  :group 'gud
+  :group 'gdb
   :version "22.1")
 
 (gdb-set-buffer-rules 'gdb-memory-buffer
@@ -2478,10 +2751,10 @@ another GDB command e.g pwd, to see new frames")
   (let ((map (make-sparse-keymap)))
     (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
     map)
- "Keymap to select format in the header line.")
 "Keymap to select format in the header line.")
 
 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
- "Menu of display formats in the header line.")
 "Menu of display formats in the header line.")
 
 (define-key gdb-memory-format-menu [binary]
   '(menu-item "Binary" gdb-memory-format-binary
@@ -2540,10 +2813,10 @@ another GDB command e.g pwd, to see new frames")
   (let ((map (make-sparse-keymap)))
     (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
     map)
- "Keymap to select units in the header line.")
 "Keymap to select units in the header line.")
 
 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
- "Menu of units in the header line.")
 "Menu of units in the header line.")
 
 (define-key gdb-memory-unit-menu [giantwords]
   '(menu-item "Giant words" gdb-memory-unit-giant
@@ -2571,16 +2844,6 @@ another GDB command e.g pwd, to see new frames")
                                               (vector (car selection))))))
       (if binding (call-interactively binding)))))
 
-;;from make-mode-line-mouse-map
-(defun gdb-make-header-line-mouse-map (mouse function) "\
-Return a keymap with single entry for mouse key MOUSE on the header line.
-MOUSE is defined to run function FUNCTION with no args in the buffer
-corresponding to the mode line clicked."
-  (let ((map (make-sparse-keymap)))
-    (define-key map (vector 'header-line mouse) function)
-    (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
-    map))
-
 (defvar gdb-memory-font-lock-keywords
   '(;; <__function.name+n>
     ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
@@ -2595,6 +2858,7 @@ corresponding to the mode line clicked."
   (setq major-mode 'gdb-memory-mode)
   (setq mode-name "Memory")
   (setq buffer-read-only t)
+  (buffer-disable-undo)
   (use-local-map gdb-memory-mode-map)
   (setq header-line-format
        '(:eval
@@ -2706,7 +2970,7 @@ corresponding to the mode line clicked."
                                (beginning-of-line)
                                (gud-watch)))
     map)
- "Keymap to create watch expression of a complex data type local variable.")
 "Keymap to create watch expression of a complex data type local variable.")
 
 (defconst gdb-struct-string
   (concat (propertize "[struct/union]"
@@ -2728,13 +2992,14 @@ corresponding to the mode line clicked."
   (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
     (with-current-buffer buf
       (goto-char (point-min))
+      ;; Need this in case "set print pretty" is on.
       (while (re-search-forward "^[ }].*\n" nil t)
        (replace-match "" nil nil))
       (goto-char (point-min))
       (while (re-search-forward "{\\(.*=.*\n\\|\n\\)" nil t)
        (replace-match gdb-struct-string nil nil))
       (goto-char (point-min))
-      (while (re-search-forward "\\s-*{.*\n" nil t)
+      (while (re-search-forward "\\s-*{[^.].*\n" nil t)
        (replace-match gdb-array-string nil nil))))
   (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
     (and buf
@@ -2747,8 +3012,7 @@ corresponding to the mode line clicked."
                 (insert-buffer-substring (gdb-get-buffer-create
                                           'gdb-partial-output-buffer))
                (set-window-start window start)
-               (set-window-point window p))
-)))
+               (set-window-point window p)))))
   (run-hooks 'gdb-info-locals-hook))
 
 (defvar gdb-locals-mode-map
@@ -2764,8 +3028,11 @@ corresponding to the mode line clicked."
   (kill-all-local-variables)
   (setq major-mode 'gdb-locals-mode)
   (setq mode-name (concat "Locals:" gdb-selected-frame))
-  (setq buffer-read-only t)
   (use-local-map gdb-locals-mode-map)
+  (setq buffer-read-only t)
+  (buffer-disable-undo)
+  (setq header-line-format gdb-locals-header)
+  (gdb-thread-identification)
   (set (make-local-variable 'font-lock-defaults)
        '(gdb-locals-font-lock-keywords))
   (run-mode-hooks 'gdb-locals-mode-hook)
@@ -2793,28 +3060,16 @@ corresponding to the mode line clicked."
 \f
 
 ;;;; Window management
-(defun gdb-display-buffer (buf dedicated &optional size)
-  (let ((answer (get-buffer-window buf 0))
-       (must-split nil))
+(defun gdb-display-buffer (buf dedicated &optional frame)
+  (let ((answer (get-buffer-window buf (or frame 0))))
     (if answer
-       (display-buffer buf nil 0)      ;Raise the frame if necessary.
-      ;; The buffer is not yet displayed.
-      (pop-to-buffer gud-comint-buffer)        ;Select the right frame.
+       (display-buffer buf nil (or frame 0)) ;Deiconify the frame if necessary.
       (let ((window (get-lru-window)))
-       (if (and window
-                (not (memq window `(,(get-buffer-window gud-comint-buffer)
-                                    ,gdb-source-window))))
-           (progn
-             (set-window-buffer window buf)
-             (setq answer window))
-         (setq must-split t)))
-      (if must-split
-         (let* ((largest (get-largest-window))
-                (cur-size (window-height largest))
-                (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 dedicated)))
+       (let* ((largest (get-largest-window))
+              (cur-size (window-height largest)))
+         (setq answer (split-window largest))
+         (set-window-buffer answer buf)
+         (set-window-dedicated-p answer dedicated)))
       answer)))
 
 \f
@@ -2823,6 +3078,7 @@ corresponding to the mode line clicked."
 (let ((menu (make-sparse-keymap "GDB-Windows")))
   (define-key gud-menu-map [displays]
     `(menu-item "GDB-Windows" ,menu
+               :help "Open a GDB-UI buffer in a new window."
                :visible (memq gud-minor-mode '(gdbmi gdba))))
   (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
   (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
@@ -2841,6 +3097,7 @@ corresponding to the mode line clicked."
 (let ((menu (make-sparse-keymap "GDB-Frames")))
   (define-key gud-menu-map [frames]
     `(menu-item "GDB-Frames" ,menu
+               :help "Open a GDB-UI buffer in a new frame."
                :visible (memq gud-minor-mode '(gdbmi gdba))))
   (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
   (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
@@ -2859,10 +3116,13 @@ 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-customize]
+  '(menu-item "Customize" (lambda () (interactive) (customize-group 'gdb))
+             :help "Customize Gdb Graphical Mode options."))
   (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."
+             :help "Toggle looking for source frame further up call stack."
              :button (:toggle . gdb-find-source-frame)))
   (define-key menu [gdb-use-separate-io]
   '(menu-item "Separate IO" gdb-use-separate-io-buffer
@@ -2891,7 +3151,7 @@ corresponding to the mode line clicked."
   "Display GUD buffer."
   (interactive)
   (let ((same-window-regexps nil))
-    (pop-to-buffer gud-comint-buffer)))
+    (select-window (display-buffer gud-comint-buffer nil 0))))
 
 (defun gdb-set-window-buffer (name)
   (set-window-buffer (selected-window) (get-buffer name))
@@ -2987,12 +3247,13 @@ buffers."
   (goto-char (point-min))
   (if (search-forward "Includes preprocessor macro info." nil t)
       (setq gdb-macro-info t))
- (if gdb-many-windows
 (if gdb-many-windows
       (gdb-setup-windows)
    (gdb-get-buffer-create 'gdb-breakpoints-buffer)
    (if gdb-show-main
        (let ((pop-up-windows t))
-        (display-buffer (gud-find-file gdb-main-file))))))
+        (display-buffer (gud-find-file gdb-main-file)))))
+ (setq gdb-ready t))
 
 (defun gdb-get-location (bptno line flag)
   "Find the directory containing the relevant source file.
@@ -3011,9 +3272,7 @@ Add directory to search path for source files using the GDB command, dir."))
       (throw 'file-not-found nil))
     (with-current-buffer
        (find-file-noselect (match-string 0))
-      (save-current-buffer
-       (set (make-local-variable 'gud-minor-mode) 'gdba)
-       (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
+      (gdb-init-buffer)
       ;; only want one breakpoint icon at each location
       (save-excursion
        (goto-line (string-to-number line))
@@ -3035,9 +3294,7 @@ of the current session."
                    buffer-file-name)
                  gdb-source-file-list)
          (with-current-buffer (find-buffer-visiting buffer-file-name)
-           (set (make-local-variable 'gud-minor-mode)
-                (buffer-local-value 'gud-minor-mode gud-comint-buffer))
-           (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)))))
+           (gdb-init-buffer)))))
 
 ;;from put-image
 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
@@ -3069,6 +3326,8 @@ BUFFER nil or omitted means use the current buffer."
          (delete-overlay overlay))))
 
 (defun gdb-put-breakpoint-icon (enabled bptno)
+  (if (string-match "[0-9+]+\\." bptno)
+      (setq enabled gdb-parent-bptno-enabled))
   (let ((start (- (line-beginning-position) 1))
        (end (+ (line-end-position) 1))
        (putstring (if enabled "B" "b"))
@@ -3128,8 +3387,8 @@ BUFFER nil or omitted means use the current buffer."
          (setq left-margin-width 2)
          (let ((window (get-buffer-window (current-buffer) 0)))
            (if window
-             (set-window-margins
-              window left-margin-width right-margin-width)))))
+               (set-window-margins
+                window left-margin-width right-margin-width)))))
       (gdb-put-string
        (propertize putstring
                   'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
@@ -3199,18 +3458,16 @@ BUFFER nil or omitted means use the current buffer."
       (goto-char (point-min))
       (while (< (point) (- (point-max) 1))
        (forward-line 1)
-       (if (looking-at "[^\t].*?breakpoint")
-           (progn
-             (looking-at
-           "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
-             (setq bptno (match-string 1))
-             (setq flag (char-after (match-beginning 2)))
-             (setq address (match-string 3))
-             (with-current-buffer buffer
-               (save-excursion
-                 (goto-char (point-min))
-                 (if (search-forward address nil t)
-                     (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
+       (when (looking-at
+              "\\([0-9]+\\.?[0-9]*\\).*?\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
+         (setq bptno (match-string 1))
+         (setq flag (char-after (match-beginning 2)))
+         (setq address (match-string 3))
+         (with-current-buffer buffer
+           (save-excursion
+             (goto-char (point-min))
+             (if (re-search-forward (concat "^0x0*" address) nil t)
+                 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))))
     (if (not (equal gdb-pc-address "main"))
        (with-current-buffer buffer
          (set-window-point (get-buffer-window buffer 0) pos)))))
@@ -3247,6 +3504,8 @@ BUFFER nil or omitted means use the current buffer."
   (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
   (setq fringes-outside-margins t)
   (setq buffer-read-only t)
+  (buffer-disable-undo)
+  (gdb-thread-identification)
   (use-local-map gdb-assembler-mode-map)
   (gdb-invalidate-assembler)
   (set (make-local-variable 'font-lock-defaults)
@@ -3282,8 +3541,9 @@ BUFFER nil or omitted means use the current buffer."
                     (string-equal gdb-selected-frame gdb-previous-frame))
          (if (or (not (member 'gdb-invalidate-assembler
                               gdb-pending-triggers))
-                 (not (string-equal gdb-pc-address
-                                    gdb-previous-frame-address)))
+                 (not (equal (string-to-number gdb-pc-address)
+                             (string-to-number
+                              gdb-previous-frame-pc-address))))
          (progn
            ;; take previous disassemble command, if any, off the queue
            (with-current-buffer gud-comint-buffer
@@ -3294,21 +3554,23 @@ BUFFER nil or omitted means use the current buffer."
                            (delete item gdb-input-queue))))))
            (gdb-enqueue-input
             (list
-             (concat gdb-server-prefix "disassemble "
-                     (if (member gdb-pc-address '(nil "main")) nil "0x")
-                          gdb-pc-address "\n")
+             (concat gdb-server-prefix "disassemble " gdb-pc-address "\n")
                   'gdb-assembler-handler))
            (push 'gdb-invalidate-assembler gdb-pending-triggers)
-           (setq gdb-previous-frame-address gdb-pc-address)
+           (setq gdb-previous-frame-pc-address gdb-pc-address)
            (setq gdb-previous-frame gdb-selected-frame)))))))
 
 (defun gdb-get-selected-frame ()
   (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
       (progn
-       (gdb-enqueue-input
-        (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
-       (push 'gdb-get-selected-frame
-              gdb-pending-triggers))))
+       (if (string-equal gdb-version "pre-6.4")
+           (gdb-enqueue-input
+            (list (concat gdb-server-prefix "info frame\n")
+                  'gdb-frame-handler))
+         (gdb-enqueue-input
+           (list "server interpreter mi -stack-info-frame\n"
+                 'gdb-frame-handler-1)))
+       (push 'gdb-get-selected-frame gdb-pending-triggers))))
 
 (defun gdb-frame-handler ()
   (setq gdb-pending-triggers
@@ -3319,7 +3581,7 @@ 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-+\\(.*?\\)\
+  (when (re-search-forward ".*=\\s-+\\(\\S-*\\)\\s-+in\\s-+\\(.*?\\)\
 \\(?: (\\(\\S-+?\\):[0-9]+?)\\)*; "
      nil t)
     (setq gdb-selected-frame (match-string 2))
@@ -3334,7 +3596,8 @@ BUFFER nil or omitted means use the current buffer."
       (let ((buffer (marker-buffer gud-overlay-arrow-position))
            (position (marker-position gud-overlay-arrow-position)))
        (when (and buffer
-                  (string-equal (buffer-name buffer)
+                  (string-equal (file-name-nondirectory
+                                 (buffer-file-name buffer))
                                 (file-name-nondirectory (match-string 3))))
          (with-current-buffer buffer
            (setq fringe-indicator-alist
@@ -3353,7 +3616,7 @@ BUFFER nil or omitted means use the current buffer."
 
 (defun gdb-set-gud-minor-mode-existing-buffers-1 ()
   "Create list of source files for current GDB session.
-If buffers already exist for any of these files, gud-minor-mode
+If buffers already exist for any of these files, `gud-minor-mode'
 is set in them."
   (goto-char (point-min))
   (while (re-search-forward gdb-source-file-regexp-1 nil t)
@@ -3361,24 +3624,53 @@ is set in them."
   (dolist (buffer (buffer-list))
     (with-current-buffer buffer
       (when (member buffer-file-name gdb-source-file-list)
-       (set (make-local-variable 'gud-minor-mode)
-            (buffer-local-value 'gud-minor-mode gud-comint-buffer))
-       (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
-       (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)))))
+       (gdb-init-buffer))))
   (gdb-force-mode-line-update
    (propertize "ready" 'face font-lock-variable-name-face)))
 
-; Uses "-var-list-children --all-values".  Needs GDB 6.1 onwards.
+;; Used for -stack-info-frame but could be used for -stack-list-frames too.
+(defconst gdb-stack-list-frames-regexp
+".*?level=\"\\(.*?\\)\",.*?addr=\"\\(.*?\\)\",.*?func=\"\\(.*?\\)\",\
+\\(?:.*?file=\".*?\",.*?fullname=\"\\(.*?\\)\",.*?line=\"\\(.*?\\)\".*?}\\|\
+from=\"\\(.*?\\)\"\\)")
+
+(defun gdb-frame-handler-1 ()
+  (setq gdb-pending-triggers
+       (delq 'gdb-get-selected-frame gdb-pending-triggers))
+  (goto-char (point-min))
+    (when (re-search-forward gdb-stack-list-frames-regexp nil t)
+      (setq gdb-frame-number (match-string 1))
+      (setq gdb-pc-address (match-string 2))
+      (setq gdb-selected-frame (match-string 3))
+      (if (gdb-get-buffer 'gdb-locals-buffer)
+         (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
+           (setq mode-name (concat "Locals:" gdb-selected-frame))))
+      (if (gdb-get-buffer 'gdb-assembler-buffer)
+         (with-current-buffer (gdb-get-buffer 'gdb-assembler-buffer)
+           (setq mode-name (concat "Machine:" gdb-selected-frame)))))
+    (if (and (match-string 4) (match-string 5) gud-overlay-arrow-position)
+       (let ((buffer (marker-buffer gud-overlay-arrow-position))
+             (position (marker-position gud-overlay-arrow-position)))
+         (when (and buffer
+                    (string-equal (file-name-nondirectory
+                                   (buffer-file-name buffer))
+                                  (file-name-nondirectory (match-string 4))))
+           (with-current-buffer buffer
+             (setq fringe-indicator-alist
+                   (if (string-equal gdb-frame-number "0")
+                       nil
+                     '((overlay-arrow . hollow-right-triangle))))
+             (set-marker gud-overlay-arrow-position position)))))
+  (gdb-invalidate-assembler))
+
+; Uses "-var-list-children --all-values".  Needs GDB 6.4 onwards.
 (defun gdb-var-list-children-1 (varnum)
   (gdb-enqueue-input
    (list
     (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
-       (concat "server interpreter mi \"-var-list-children --all-values "
-               varnum "\"\n")
-      (concat "-var-list-children --all-values " varnum "\n"))
+       (concat "server interpreter mi \"-var-list-children --all-values \\\""
+               varnum "\\\"\"\n")
+      (concat "-var-list-children --all-values \"" varnum "\"\n"))
     `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
 
 (defconst gdb-var-list-children-regexp-1
@@ -3434,7 +3726,9 @@ in_scope=\"\\(.*?\\)\".*?}")
       (when var
        (let ((match (match-string 3)))
          (cond ((string-equal match "false")
-                (setcar (nthcdr 5 var) 'out-of-scope))
+                (if gdb-delete-out-of-scope
+                    (gdb-var-delete-1 varnum)
+                  (setcar (nthcdr 5 var) 'out-of-scope)))
                ((string-equal match "true")
                 (setcar (nthcdr 5 var) 'changed)
                 (setcar (nthcdr 4 var)
@@ -3562,7 +3856,7 @@ in_scope=\"\\(.*?\\)\".*?}")
     (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.")
 "Keymap to create watch expression of a complex data type local variable.")
 
 (defvar gdb-edit-locals-map-1
   (let ((map (make-sparse-keymap)))
@@ -3570,7 +3864,7 @@ in_scope=\"\\(.*?\\)\".*?}")
     (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.")
 "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."