(scheme-mode-syntax-table): Mark ; as being also the
[bpt/emacs.git] / lisp / progmodes / gdb-ui.el
index ecb8f63..6c960c4 100644 (file)
@@ -20,8 +20,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;; still under development and is part of a process to migrate Emacs from
 ;; annotations to GDB/MI.
 ;;
+;; Windows Platforms:
+;;
+;; If you are using Emacs and GDB on Windows you will need to flush the buffer
+;; explicitly in your program if you want timely display of I/O in Emacs.
+;; Alternatively you can make the output stream unbuffered, for example, by
+;; using a macro:
+;;
+;;           #ifdef UNBUFFERED
+;;          setvbuf (stdout, (char *) NULL, _IONBF, 0);
+;;          #endif
+;;
+;; and compiling with -DUNBUFFERED while debugging.
+;;
 ;; Known Bugs:
 ;;
 ;; TODO:
@@ -66,7 +79,9 @@
 
 (require 'gud)
 
-(defvar gdb-frame-address "main" "Initialisation for Assembler buffer.")
+(defvar tool-bar-map)
+
+(defvar gdb-frame-address "main" "Initialization for Assembler buffer.")
 (defvar gdb-previous-frame-address nil)
 (defvar gdb-memory-address "main")
 (defvar gdb-previous-frame nil)
@@ -74,7 +89,7 @@
 (defvar gdb-frame-number nil)
 (defvar gdb-current-language nil)
 (defvar gdb-var-list nil "List of variables in watch window.")
-(defvar gdb-var-changed nil "Non-nil means that gdb-var-list has changed.")
+(defvar gdb-var-changed nil "Non-nil means that `gdb-var-list' has changed.")
 (defvar gdb-main-file nil "Source file from which program execution begins.")
 (defvar gdb-buffer-type nil)
 (defvar gdb-overlay-arrow-position nil)
 (defvar gdb-find-file-unhook nil)
 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
 and #define directives otherwise.")
+(defvar gdb-error "Non-nil when GDB is reporting an error.")
 (defvar gdb-macro-info nil
   "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
 
@@ -104,7 +120,7 @@ Possible values are these symbols:
     `user' -- gdb output should be copied to the GUD buffer
               for the user to see.
 
-    `inferior' -- gdb output should be copied to the inferior-io buffer
+    `inferior' -- gdb output should be copied to the inferior-io buffer.
 
     `pre-emacs' -- output should be ignored util the post-prompt
                    annotation is received.  Then the output-sink
@@ -116,7 +132,7 @@ Possible values are these symbols:
     `post-emacs' -- ignore output until the prompt annotation is
                    received, then go to USER disposition.
 
-gdba (gdb-ui.el) uses all five values,  gdbmi (gdb-mi.el) only two
+gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
 \(`user' and `emacs').")
 
 (defvar gdb-current-item nil
@@ -135,7 +151,7 @@ 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
+pops 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.
 
@@ -187,6 +203,7 @@ detailed description of this mode.
 
 (defvar gdb-debug-log nil)
 
+;;;###autoload
 (defcustom gdb-enable-debug-log nil
   "Non-nil means record the process input and output in `gdb-debug-log'."
   :type 'boolean
@@ -202,7 +219,7 @@ detailed description of this mode.
 (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
+with an identifier as a tooltip.  It works in a debug session with
 GDB, when gud-tooltip-mode is t.
 
 Set `gdb-cpp-define-alist-flags' for any include paths or
@@ -250,7 +267,7 @@ Also display the main routine in the disassembly buffer if present."
      (let ((string (buffer-string)))
        ;; remove newline for gud-tooltip-echo-area
        (substring string 0 (- (length string) 1))))
-   gud-tooltip-echo-area))
+   (or gud-tooltip-echo-area tooltip-use-echo-area)))
 
 ;; If expr is a macro for a function don't print because of possible dangerous
 ;; side-effects. Also printing a function within a tooltip generates an
@@ -265,7 +282,7 @@ Also display the main routine in the disassembly buffer if present."
                  'gdb-tooltip-print))))))
 
 (defun gdb-set-gud-minor-mode (buffer)
-  "Set gud-minor-mode from find-file if appropriate."
+  "Set `gud-minor-mode' from find-file if appropriate."
   (goto-char (point-min))
   (unless (search-forward "No source file named " nil t)
     (condition-case nil
@@ -277,7 +294,7 @@ Also display the main routine in the disassembly buffer if present."
 (defun gdb-set-gud-minor-mode-1 (buffer)
   (goto-char (point-min))
   (when (and (search-forward "Located in " nil t)
-            (looking-at "\\S-*")
+            (looking-at "\\S-+")
             (string-equal (buffer-file-name buffer)
                           (match-string 0)))
     (with-current-buffer buffer
@@ -359,6 +376,7 @@ Also display the main routine in the disassembly buffer if present."
        gdb-flush-pending-output nil
        gdb-location-alist nil
        gdb-find-file-unhook nil
+       gdb-error nil
        gdb-macro-info nil)
   ;;
   (setq gdb-buffer-type 'gdba)
@@ -430,7 +448,7 @@ Also display the main routine in the disassembly buffer if present."
            (setq gdb-var-changed t)))
       (if (re-search-forward "Undefined command" nil t)
          (message-box "Watching expressions requires gdb 6.0 onwards")
-       (message "No symbol %s in current context." expr)))))
+       (message "No symbol \"%s\" in current context." expr)))))
 
 (defun gdb-var-evaluate-expression-handler (varnum changed)
   (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
@@ -488,15 +506,11 @@ Also display the main routine in the disassembly buffer if present."
        (setq gdb-var-list (nreverse var-list))))))
 
 (defun gdb-var-update ()
-  (if (not (member 'gdb-var-update gdb-pending-triggers))
-      (progn
-       (gdb-enqueue-input
-        (list
-         (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
-             "server interpreter mi \"-var-update *\"\n"
-           "-var-update *\n")
-                                'gdb-var-update-handler))
-       (push 'gdb-var-update gdb-pending-triggers))))
+  (when (not (member 'gdb-var-update gdb-pending-triggers))
+    (gdb-enqueue-input
+     (list "server interpreter mi \"-var-update *\"\n"
+          'gdb-var-update-handler))
+    (push 'gdb-var-update gdb-pending-triggers)))
 
 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
 
@@ -507,19 +521,15 @@ Also display the main routine in the disassembly buffer if present."
        (let ((varnum (match-string 1)))
          (gdb-enqueue-input
           (list
-           (if (with-current-buffer gud-comint-buffer
-                 (eq gud-minor-mode 'gdba))
-               (concat "server interpreter mi \"-var-evaluate-expression "
-                       varnum "\"\n")
-             (concat "-var-evaluate-expression " varnum "\n"))
-                    `(lambda () (gdb-var-evaluate-expression-handler
-                                 ,varnum t)))))))
+           (concat "server interpreter mi \"-var-evaluate-expression "
+                   varnum "\"\n")
+           `(lambda () (gdb-var-evaluate-expression-handler ,varnum t)))))))
   (setq gdb-pending-triggers
    (delq 'gdb-var-update gdb-pending-triggers))
   (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
-    ;; dummy command to update speedbar at right time
+    ;; Dummy command to update speedbar at right time.
     (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
-    ;; keep gdb-pending-triggers non-nil till end
+    ;; Keep gdb-pending-triggers non-nil till end.
     (push 'gdb-speedbar-timer gdb-pending-triggers)))
 
 (defun gdb-speedbar-timer-fn ()
@@ -529,9 +539,10 @@ Also display the main routine in the disassembly buffer if present."
     (speedbar-timer-fn)))
 
 (defun gdb-var-delete ()
-  "Delete watched expression from the speedbar."
+  "Delete watch expression at point from the speedbar."
   (interactive)
-  (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
+  (if (with-current-buffer
+         gud-comint-buffer (memq gud-minor-mode '(gdbmi gdba)))
       (let ((text (speedbar-line-text)))
        (string-match "\\(\\S-+\\)" text)
        (let* ((expr (match-string 1 text))
@@ -580,7 +591,9 @@ INDENT is the current indentation depth."
   (cond ((string-match "+" text)        ;expand this node
         (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
             (gdb-var-list-children token)
-          (gdbmi-var-list-children token)))
+          (progn
+            (gdbmi-var-update)
+            (gdbmi-var-list-children token))))
        ((string-match "-" text)        ;contract this node
         (dolist (var gdb-var-list)
           (if (string-match (concat token "\\.") (nth 1 var))
@@ -693,6 +706,13 @@ The key should be one of the cars in `gdb-buffer-rules-assoc'."
       (gdb-display-buffer
        (gdb-get-create-buffer 'gdb-inferior-io))))
 
+(defconst gdb-frame-parameters
+  '((height . 14) (width . 80)
+    (unsplittable . t)
+    (tool-bar-lines . nil)
+    (menu-bar-lines . nil)
+    (minibuffer . nil)))
+
 (defun gdb-frame-inferior-io-buffer ()
   "Display IO of inferior in a new frame."
   (interactive)
@@ -774,6 +794,8 @@ 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
+    (remove-text-properties (point-min) (point-max) '(face)))
   (let ((item (concat string "\n")))
     (if gud-running
       (progn
@@ -860,6 +882,8 @@ This filter may simply queue input for a later time."
     ("watchpoint" gdb-stopping)
     ("frame-begin" gdb-frame-begin)
     ("stopped" gdb-stopped)
+    ("error-begin" gdb-error)
+    ("error" gdb-error)
     ) "An assoc mapping annotation tags to functions which process them.")
 
 (defun gdb-resync()
@@ -958,7 +982,7 @@ being debugged."
 (defun gdb-exited (ignored)
   "An annotation handler for `exited' and `signalled'.
 They say that I/O for the subprocess is now GDB, not the program
-being debugged and that the program is no longer running. This
+being debugged and that the program is no longer running.  This
 function is used to change the focus of GUD tooltips to #define
 directives."
   (setq gdb-active-process nil)
@@ -989,29 +1013,32 @@ sink to `user' in `gdb-stopping', that is fine."
       (gdb-resync)
       (error "Unexpected stopped annotation")))))
 
+(defun gdb-error (ignored)
+  (setq gdb-error (not gdb-error)))
+
 (defun gdb-post-prompt (ignored)
   "An annotation handler for `post-prompt'.
 This begins the collection of output from the current command if that
 happens to be appropriate."
   (unless gdb-pending-triggers
-       (gdb-get-selected-frame)
-       (gdb-invalidate-frames)
-       (gdb-invalidate-breakpoints)
-       ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
-       ;; so gdb-frame-address is updated.
-       ;; (gdb-invalidate-assembler)
-       (gdb-invalidate-registers)
-       (gdb-invalidate-memory)
-       (gdb-invalidate-locals)
-       (gdb-invalidate-threads)
-       (unless (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))
-           (setq gdb-var-changed t)    ; force update
-           (dolist (var gdb-var-list)
-             (setcar (nthcdr 5 var) nil))
-           (gdb-var-update))))
+    (gdb-get-selected-frame)
+    (gdb-invalidate-frames)
+    (gdb-invalidate-breakpoints)
+    ;; Do this through gdb-get-selected-frame -> gdb-frame-handler
+    ;; so gdb-frame-address is updated.
+    ;; (gdb-invalidate-assembler)
+    (gdb-invalidate-registers)
+    (gdb-invalidate-memory)
+    (gdb-invalidate-locals)
+    (gdb-invalidate-threads)
+    (unless (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))
+       (setq gdb-var-changed t)    ; force update
+       (dolist (var gdb-var-list)
+         (setcar (nthcdr 5 var) nil))
+       (gdb-var-update))))
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'user) t)
@@ -1026,9 +1053,9 @@ happens to be appropriate."
   (if gdb-flush-pending-output
       nil
     (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
-    ;; Recall the left over gud-marker-acc from last time
+    ;; Recall the left over gud-marker-acc from last time.
     (setq gud-marker-acc (concat gud-marker-acc string))
-    ;; Start accumulating output for the GUD buffer
+    ;; Start accumulating output for the GUD buffer.
     (let ((output ""))
       ;;
       ;; Process all the complete markers in this chunk.
@@ -1083,6 +1110,8 @@ happens to be appropriate."
       output)))
 
 (defun gdb-concat-output (so-far new)
+  (if gdb-error
+      (put-text-property 0 (length new) 'face font-lock-warning-face new))
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'user) (concat so-far new))
@@ -1161,12 +1190,12 @@ happens to be appropriate."
      (let ((buf (gdb-get-buffer ',buf-key)))
        (and buf
            (with-current-buffer buf
-             (let ((p (point))
+             (let ((p (window-point (get-buffer-window buf 0)))
                    (buffer-read-only nil))
                (erase-buffer)
                (insert-buffer-substring (gdb-get-create-buffer
                                          'gdb-partial-output-buffer))
-               (goto-char p)))))
+               (set-window-point (get-buffer-window buf 0) p)))))
      ;; put customisation here
      (,custom-defun)))
 
@@ -1276,7 +1305,7 @@ static char *magick[] = {
      :weight bold))
   "Face for enabled breakpoint icon in fringe."
   :group 'gud)
-;; compatibility alias for old name
+;; Compatibility alias for old name.
 (put 'breakpoint-enabled-bitmap-face 'face-alias 'breakpoint-enabled)
 
 (defface breakpoint-disabled
@@ -1287,13 +1316,11 @@ static char *magick[] = {
     (((background light)) :foreground "grey40"))
   "Face for disabled breakpoint icon in fringe."
   :group 'gud)
-;; compatibility alias for old name
-(put 'breakpoint-disabled-bitmap-face 'face-alias 'breakpoint-disabled)
 
-;;-put breakpoint icons in relevant margins (even those set in the GUD buffer)
+;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
 (defun gdb-info-breakpoints-custom ()
   (let ((flag) (bptno))
-    ;; remove all breakpoint-icons in source buffers but not assembler buffer
+    ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
     (dolist (buffer (buffer-list))
       (with-current-buffer buffer
        (if (and (eq gud-minor-mode 'gdba)
@@ -1304,7 +1331,7 @@ static char *magick[] = {
        (goto-char (point-min))
        (while (< (point) (- (point-max) 1))
          (forward-line 1)
-         (if (looking-at "[^\t].*breakpoint")
+         (if (looking-at "[^\t].*?breakpoint")
              (progn
                (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
                (setq bptno (match-string 1))
@@ -1323,13 +1350,14 @@ static char *magick[] = {
                           (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)
+                           (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
+                             ;; Only want one breakpoint icon at each
+                             ;; location.
                              (save-excursion
                                (goto-line (string-to-number line))
                                (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
@@ -1369,11 +1397,7 @@ static char *magick[] = {
        (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))
+           (if (posn-object posn)
                (gdb-enqueue-input
                 (list
                  (let ((bptno (get-text-property
@@ -1395,13 +1419,6 @@ static char *magick[] = {
   (gdb-display-buffer
    (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
 
-(defconst gdb-frame-parameters
-  '((height . 14) (width . 80)
-    (unsplittable . t)
-    (tool-bar-lines . nil)
-    (menu-bar-lines . nil)
-    (minibuffer . nil)))
-
 (defun gdb-frame-breakpoints-buffer ()
   "Display status of user-settable breakpoints in a new frame."
   (interactive)
@@ -1446,9 +1463,9 @@ static char *magick[] = {
   (save-excursion
     (beginning-of-line 1)
     (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
-           (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")
+           (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)\\s-+")
          (looking-at
-     "\\([0-9]+\\)\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)\\s-*\\S-*\\s-*\\S-*:[0-9]+"))
+     "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
        (gdb-enqueue-input
         (list
          (concat gdb-server-prefix
@@ -1463,9 +1480,9 @@ static char *magick[] = {
   (interactive)
   (beginning-of-line 1)
   (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
-         (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")
+         (looking-at "\\([0-9]+\\).*?point\\s-+\\S-+\\s-+\\(.\\)")
        (looking-at
-        "\\([0-9]+\\)\\s-*\\S-*\\s-*\\S-*\\s-*.\\s-*\\S-*\\s-*\\S-*:[0-9]+"))
+        "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\s-+\\S-+\\s-+\\S-+:[0-9]+"))
       (gdb-enqueue-input
        (list
        (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
@@ -1478,10 +1495,10 @@ static char *magick[] = {
   (save-excursion
     (beginning-of-line 1)
     (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
-           (looking-at "\\([0-9]+\\) .* in .* at\\s-+\\(\\S-*\\):\\([0-9]+\\)")
+           (looking-at "\\([0-9]+\\) .+ in .+ at\\s-+\\(\\S-+\\):\\([0-9]+\\)")
          (looking-at
-          "\\([0-9]+\\)\\s-*\\S-*\\s-*\\S-*\\s-*.\\s-*\\S-*\\s-*\
-\\(\\S-*\\):\\([0-9]+\\)"))
+          "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+.\\s-+\\S-+\\s-+\
+\\(\\S-+\\):\\([0-9]+\\)"))
        (let ((bptno (match-string 1))
              (file  (match-string 2))
              (line  (match-string 3)))
@@ -1695,7 +1712,9 @@ static char *magick[] = {
   (setq buffer-read-only t)
   (use-local-map gdb-registers-mode-map)
   (run-mode-hooks 'gdb-registers-mode-hook)
-  'gdb-invalidate-registers)
+  (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
+      'gdb-invalidate-registers
+    'gdbmi-invalidate-registers))
 
 (defun gdb-registers-buffer-name ()
   (with-current-buffer gud-comint-buffer
@@ -1766,7 +1785,11 @@ static char *magick[] = {
   gdb-read-memory-handler
   gdb-read-memory-custom)
 
-(defun gdb-read-memory-custom ())
+(defun gdb-read-memory-custom ()
+  (save-excursion
+    (goto-char (point-min))
+    (if (looking-at "0x[[:xdigit:]]+")
+       (setq gdb-memory-address (match-string 0)))))
 
 (defvar gdb-memory-mode-map
   (let ((map (make-sparse-keymap)))
@@ -1790,8 +1813,8 @@ static char *magick[] = {
     (select-window (posn-window (event-start event)))
     (let* ((arg (read-from-minibuffer "Repeat count: "))
          (count (string-to-number arg)))
-      (if (< count 0)
-         (error "Non-negative numbers only")
+      (if (<= count 0)
+         (error "Positive numbers only")
        (customize-set-variable 'gdb-memory-repeat-count count)
        (gdb-invalidate-memory)))))
 
@@ -1944,7 +1967,38 @@ corresponding to the mode line clicked."
   (setq header-line-format
        '(:eval
          (concat
-          "Read address: "
+          "Read address["
+          (propertize
+           "-"
+           'face font-lock-warning-face
+           'help-echo "mouse-1: Decrement address"
+           'mouse-face 'mode-line-highlight
+           '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)))))
+          "|"
+          (propertize "+"
+                      'face font-lock-warning-face
+                      'help-echo "mouse-1: Increment address"
+                      '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)))))
+          "]: "
           (propertize gdb-memory-address
                       'face font-lock-warning-face
                       'help-echo "mouse-1: Set memory address"
@@ -2023,12 +2077,12 @@ corresponding to the mode line clicked."
        (replace-match " (array);\n" nil nil))))
   (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
     (and buf (with-current-buffer buf
-              (let ((p (point))
+              (let ((p (window-point (get-buffer-window buf 0)))
                     (buffer-read-only nil))
-                (delete-region (point-min) (point-max))
+                (erase-buffer)
                 (insert-buffer-substring (gdb-get-create-buffer
                                           'gdb-partial-output-buffer))
-                (goto-char p)))))
+               (set-window-point (get-buffer-window buf 0) p)))))
   (run-hooks 'gdb-info-locals-hook))
 
 (defun gdb-info-locals-custom ()
@@ -2137,19 +2191,21 @@ corresponding to the mode line clicked."
 (let ((menu (make-sparse-keymap "GDB-UI")))
   (define-key gud-menu-map [ui]
     `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
-  (define-key menu [gdb-restore-windows]
-  '(menu-item "Restore Window Layout" gdb-restore-windows
-             :help "Restore standard layout for debug session."))
-  (define-key menu [gdb-many-windows]
-  '(menu-item "Display Other Windows" gdb-many-windows
-             :help "Toggle display of locals, stack and breakpoint information"
-             :button (:toggle . gdb-many-windows)))
   (define-key menu [gdb-use-inferior-io]
+    ;; See defadvice below.
     (menu-bar-make-toggle toggle-gdb-use-inferior-io-buffer
                          gdb-use-inferior-io-buffer
      "Separate inferior IO" "Use separate IO %s"
-     "Toggle separate IO for inferior.")))
+     "Toggle separate IO for inferior."))
+  (define-key menu [gdb-many-windows]
+  '(menu-item "Display Other Windows" gdb-many-windows
+             :help "Toggle display of locals, stack and breakpoint information"
+             :button (:toggle . gdb-many-windows)))
+  (define-key menu [gdb-restore-windows]
+  '(menu-item "Restore Window Layout" gdb-restore-windows
+             :help "Restore standard layout for debug session.")))
 
+;; This function is defined above through a macro.
 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
   (unless gdb-use-inferior-io-buffer
     (kill-buffer (gdb-inferior-io-name))))
@@ -2172,7 +2228,7 @@ corresponding to the mode line clicked."
   (set-window-dedicated-p (selected-window) t))
 
 (defun gdb-setup-windows ()
-  "Layout the window pattern for gdb-many-windows."
+  "Layout the window pattern for `gdb-many-windows'."
   (gdb-display-locals-buffer)
   (gdb-display-stack-buffer)
   (delete-other-windows)
@@ -2266,7 +2322,7 @@ Kills the gdb buffers and resets the source buffers."
 buffers."
   (goto-char (point-min))
   (if (and (search-forward "Located in " nil t)
-          (looking-at "\\S-*"))
+          (looking-at "\\S-+"))
       (setq gdb-main-file (match-string 0)))
   (goto-char (point-min))
   (if (search-forward "Includes preprocessor macro info." nil t)
@@ -2284,7 +2340,7 @@ Put in buffer and place breakpoint icon."
   (goto-char (point-min))
   (catch 'file-not-found
     (if (search-forward "Located in " nil t)
-       (when (looking-at "\\S-*")
+       (when (looking-at "\\S-+")
          (delete (cons bptno "File not found") gdb-location-alist)
          (push (cons bptno (match-string 0)) gdb-location-alist))
       (gdb-resync)
@@ -2306,6 +2362,8 @@ Add directory to search path for source files using the GDB command, dir."))
 (add-hook 'find-file-hook 'gdb-find-file-hook)
 
 (defun gdb-find-file-hook ()
+"Set up buffer for debugging if file is part of the source code
+of the current session."
   (if (and (not gdb-find-file-unhook)
           ;; in case gud or gdb-ui is just loaded
           gud-comint-buffer
@@ -2324,7 +2382,7 @@ Add directory to search path for source files using the GDB command, dir."))
 (defun gdb-put-string (putstring pos &optional dprop)
   "Put string PUTSTRING in front of POS in the current buffer.
 PUTSTRING is displayed by putting an overlay into the current buffer with a
-`before-string' STRING that has a `display' property whose value is
+`before-string' string that has a `display' property whose value is
 PUTSTRING."
   (let ((string (make-string 1 ?x))
        (buffer (current-buffer)))
@@ -2429,7 +2487,7 @@ BUFFER nil or omitted means use the current buffer."
 
 (def-gdb-auto-updated-buffer gdb-assembler-buffer
   gdb-invalidate-assembler
-  (concat gdb-server-prefix "disassemble " 
+  (concat gdb-server-prefix "disassemble "
          (if (member gdb-frame-address '(nil "main")) nil "0x")
          gdb-frame-address "\n")
   gdb-assembler-handler
@@ -2439,25 +2497,26 @@ BUFFER nil or omitted means use the current buffer."
   (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
        (pos 1) (address) (flag) (bptno))
     (with-current-buffer buffer
-      (if (not (equal gdb-frame-address "main"))
-         (progn
-           (goto-char (point-min))
-           (if (and gdb-frame-address
-                    (re-search-forward gdb-frame-address nil t))
-               (progn
-                 (setq pos (point))
-                 (beginning-of-line)
-                 (or gdb-overlay-arrow-position
-                     (setq gdb-overlay-arrow-position (make-marker)))
-                 (set-marker gdb-overlay-arrow-position
-                             (point) (current-buffer))))))
-      ;; remove all breakpoint-icons in assembler buffer before updating.
-      (gdb-remove-breakpoint-icons (point-min) (point-max)))
+      (save-excursion
+       (if (not (equal gdb-frame-address "main"))
+           (progn
+             (goto-char (point-min))
+             (if (and gdb-frame-address
+                      (re-search-forward gdb-frame-address nil t))
+                 (progn
+                   (setq pos (point))
+                   (beginning-of-line)
+                   (or gdb-overlay-arrow-position
+                       (setq gdb-overlay-arrow-position (make-marker)))
+                   (set-marker gdb-overlay-arrow-position
+                               (point) (current-buffer))))))
+       ;; 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)
       (goto-char (point-min))
       (while (< (point) (- (point-max) 1))
        (forward-line 1)
-       (if (looking-at "[^\t].*breakpoint")
+       (if (looking-at "[^\t].*?breakpoint")
            (progn
              (looking-at
            "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
@@ -2465,9 +2524,10 @@ BUFFER nil or omitted means use the current buffer."
              (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 address nil t)
-                     (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))))
+                     (gdb-put-breakpoint-icon (eq flag ?y) bptno))))))))
     (if (not (equal gdb-frame-address "main"))
        (set-window-point (get-buffer-window buffer 0) pos))))
 
@@ -2517,12 +2577,14 @@ BUFFER nil or omitted means use the current buffer."
 (defun gdb-display-assembler-buffer ()
   "Display disassembly view."
   (interactive)
+  (setq gdb-previous-frame nil)
   (gdb-display-buffer
    (gdb-get-create-buffer 'gdb-assembler-buffer)))
 
 (defun gdb-frame-assembler-buffer ()
   "Display disassembly view in a new frame."
   (interactive)
+  (setq gdb-previous-frame nil)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
        (special-display-frame-alist gdb-frame-parameters))
     (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))