]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/gdb-ui.el
(flymake-find-possible-master-files, flymake-master-file-compare,
[gnu-emacs] / lisp / progmodes / gdb-ui.el
index 54778b7b89cf3b631d7bd3b190a46672f0a1fa5f..7653ff90a2f89fc194ede7ba1d1341edba0f1191 100644 (file)
@@ -85,6 +85,7 @@
 (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.")
 
@@ -250,7 +251,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
@@ -277,7 +278,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 +360,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 +432,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)
@@ -774,6 +776,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 +864,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()
@@ -989,29 +995,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)
@@ -1083,6 +1092,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 +1172,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)))
 
@@ -1304,7 +1315,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))
@@ -1446,9 +1457,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 +1474,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 +1489,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 +1706,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
@@ -2058,12 +2071,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 ()
@@ -2172,18 +2185,18 @@ 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]
     (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.")))
 
 (defadvice toggle-gdb-use-inferior-io-buffer (after gdb-kill-io-buffer activate)
   (unless gdb-use-inferior-io-buffer
@@ -2301,7 +2314,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)
@@ -2319,7 +2332,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)
@@ -2341,6 +2354,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
@@ -2493,7 +2508,7 @@ 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")
+       (if (looking-at "[^\t].*?breakpoint")
            (progn
              (looking-at
            "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x0*\\(\\S-+\\)")
@@ -2554,12 +2569,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))))