]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/gdb-ui.el
(c-defun-name): Make it work for "struct foo bar [] = { ...".
[gnu-emacs] / lisp / progmodes / gdb-ui.el
index 45843ec696f90145a911498bd6a5715594f3d9b6..d704e6a5b06c750d19865488d947cb8f928c35f7 100644 (file)
@@ -9,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; 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., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -264,10 +262,8 @@ detailed description of this mode.
 |  Stack buffer                     |  Breakpoints/threads buffer      |
 +-----------------------------------+----------------------------------+
 
-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
+The option \"--annotate=3\" must be included in this value.  To
+run GDB in text command mode, use `gud-gdb'.  You need to use
 text command mode to debug multiple programs within one Emacs
 session."
   (interactive (list (gud-query-cmdline 'gdb)))
@@ -370,6 +366,18 @@ predefined macros."
   :group 'gdb
   :version "22.1")
 
+(defcustom gdb-create-source-file-list t
+  "Non-nil means create a list of files from which the executable was built.
+Set this to nil if the GUD buffer displays \"initializing...\" in the mode
+line for a long time when starting, possibly because your executable was
+built from a large number of files.  This allows quicker initialization
+but means that these files are not automatically enabled for debugging,
+e.g., you won't be able to click in the fringe to set a breakpoint until
+execution has already stopped there."
+  :type 'boolean
+  :group 'gdb
+  :version "23.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."
@@ -403,6 +411,21 @@ for `gdba'."
          ;; Force mode line redisplay soon.
          (force-mode-line-update)))))
 
+(defun gdb-enable-debug (arg)
+  "Toggle logging of transaction between Emacs and Gdb.
+The log is stored in `gdb-debug-log' as an alist with elements
+whose cons is send, send-item or recv and whose cdr is the string
+being transferred.  This list may grow up to a size of
+`gdb-debug-log-max' after which the oldest element (at the end of
+the list) is deleted every time a new one is added (at the front)."
+  (interactive "P")
+  (setq gdb-enable-debug
+       (if (null arg)
+           (not gdb-enable-debug)
+         (> (prefix-numeric-value arg) 0)))
+  (message (format "Logging of transaction %sabled"
+                  (if gdb-enable-debug "en" "dis"))))
+
 (defun gdb-many-windows (arg)
   "Toggle the number of windows in the basic arrangement.
 With prefix argument ARG, display additional buffers if ARG is positive,
@@ -447,17 +470,23 @@ otherwise do not."
         (output
          (with-output-to-string
            (with-current-buffer standard-output
-             (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))))))
+             (and file
+                  (file-exists-p file)
+                  ;; call-process doesn't work with remote file names.
+                  (not (file-remote-p default-directory))
+                  (call-process shell-file-name file
+                                (list t nil) nil "-c"
+                                (concat gdb-cpp-define-alist-program " "
+                                        gdb-cpp-define-alist-flags))))))
        (define-list (split-string output "\n" t)) (name))
     (setq gdb-define-alist nil)
     (dolist (define define-list)
       (setq name (nth 1 (split-string define "[( ]")))
       (push (cons name define) gdb-define-alist))))
 
+(declare-function tooltip-show "tooltip" (text &optional use-echo-area))
+(defvar tooltip-use-echo-area)
+
 (defun gdb-tooltip-print (expr)
   (tooltip-show
    (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
@@ -638,7 +667,7 @@ otherwise do not."
   (gdb-enqueue-input (list "set width 0\n" 'ignore))
 
   (if (string-equal gdb-version "pre-6.4")
-      (progn
+      (if gdb-create-source-file-list
        (gdb-enqueue-input (list (concat gdb-server-prefix "info sources\n")
                                 'gdb-set-gud-minor-mode-existing-buffers))
        (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-1))
@@ -646,17 +675,16 @@ otherwise do not."
      (list "server interpreter mi -data-list-register-names\n"
         'gdb-get-register-names))
     ; Needs GDB 6.2 onwards.
-    (gdb-enqueue-input
-     (list "server interpreter mi \"-file-list-exec-source-files\"\n"
-          'gdb-set-gud-minor-mode-existing-buffers-1))
+    (if gdb-create-source-file-list
+       (gdb-enqueue-input
+        (list "server interpreter mi \"-file-list-exec-source-files\"\n"
+              'gdb-set-gud-minor-mode-existing-buffers-1)))
     (setq gdb-locals-font-lock-keywords gdb-locals-font-lock-keywords-2))
 
   ;; Find source file and compilation directory here.
   ;; Works for C, C++, Fortran and Ada but not Java (GDB 6.4)
   (gdb-enqueue-input (list "server list\n" 'ignore))
-  (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
-
-  (run-hooks 'gdb-mode-hook))
+  (gdb-enqueue-input (list "server info source\n" 'gdb-source-info)))
 
 (defun gdb-get-version ()
   (goto-char (point-min))
@@ -742,6 +770,8 @@ positive, otherwise don't automatically raise it."
 (define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch)
 (define-key global-map (concat gud-key-prefix "\C-w") 'gud-watch)
 
+(declare-function tooltip-identifier-from-point "tooltip" (point))
+
 (defun gud-watch (&optional arg event)
   "Watch expression at point.
 With arg, enter name of variable to be watched in the minibuffer."
@@ -837,8 +867,8 @@ 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=\"\\(.*?\\)\",.*?\
-numchild=\"\\(.*?\\)\"\\(}\\|,.*?\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
+  "child={.*?name=\"\\(.*?\\)\".*?,exp=\"\\(.*?\\)\".*?,\
+numchild=\"\\(.*?\\)\"\\(}\\|.*?,\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
 
 (defun gdb-var-list-children-handler (varnum)
   (goto-char (point-min))
@@ -875,7 +905,7 @@ numchild=\"\\(.*?\\)\"\\(}\\|,.*?\\(type=\"\\(.*?\\)\"\\)?.*?}\\)")
     (push 'gdb-var-update gdb-pending-triggers)))
 
 (defconst gdb-var-update-regexp
-  "{.*?name=\"\\(.*?\\)\",.*?in_scope=\"\\(.*?\\)\",.*?\
+  "{.*?name=\"\\(.*?\\)\".*?,in_scope=\"\\(.*?\\)\".*?,\
 type_changed=\".*?\".*?}")
 
 (defun gdb-var-update-handler ()
@@ -1315,7 +1345,9 @@ want the GDB Graphical Interface."
     ("stopped" gdb-stopped)
     ("error-begin" gdb-error)
     ("error" gdb-error)
-    ("new-thread" (lambda (ignored) (gdb-get-buffer-create 'gdb-threads-buffer))))
+    ("new-thread" (lambda (ignored)
+                   (gdb-get-buffer-create 'gdb-threads-buffer)))
+    ("thread-changed" gdb-thread-changed))
   "An assoc mapping annotation tags to functions which process them.")
 
 (defun gdb-resync()
@@ -1541,6 +1573,9 @@ sink to `user' in `gdb-stopping', that is fine."
 (defun gdb-error (ignored)
   (setq gdb-error (not gdb-error)))
 
+(defun gdb-thread-changed (ignored)
+  (gdb-frames-force-update))
+
 (defun gdb-post-prompt (ignored)
   "An annotation handler for `post-prompt'.
 This begins the collection of output from the current command if that
@@ -1643,15 +1678,12 @@ happens to be appropriate."
          (let* ((annotation-type (match-string 1 annotation))
                 (annotation-arguments (match-string 2 annotation))
                 (annotation-rule (assoc annotation-type
-                                        gdb-annotation-rules))
-                (fullname (string-match gdb-fullname-regexp annotation-type)))
+                                        gdb-annotation-rules)))
 
            ;; 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"))))
+           (setq output (gdb-concat-output output before))
 
            ;; Take that stuff off the gud-marker-acc.
            (setq gud-marker-acc after)
@@ -1659,19 +1691,7 @@ happens to be appropriate."
            ;; Call the handler for this annotation.
            (if annotation-rule
                (funcall (car (cdr annotation-rule))
-                        annotation-arguments)
-
-             ;; 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)))
+                        annotation-arguments))
 
            ;; Else the annotation is not recognized.  Ignore it silently,
            ;; so that GDB can add new annotations without causing
@@ -1887,6 +1907,9 @@ static char *magick[] = {
 (defvar breakpoint-disabled-icon nil
   "Icon for disabled breakpoint in display margin.")
 
+(declare-function define-fringe-bitmap "fringe.c"
+                 (bitmap bits &optional height width align))
+
 (and (display-images-p)
      ;; Bitmap for breakpoint in fringe
      (define-fringe-bitmap 'breakpoint
@@ -1951,7 +1974,7 @@ static char *magick[] = {
                       (match-beginning 1) (match-end 1)
                       '(face font-lock-function-name-face)))
                    (if (re-search-forward
-                        ".*\\s-+\\(\\S-+\\):\\([0-9]+\\)$" nil t)
+                        ".*\\s-+\\(\\S-+\\):\\([0-9]+\\)$" el t)
                        (let ((line (match-string 2))
                              (file (match-string 1)))
                          (add-text-properties bl el
@@ -2001,6 +2024,7 @@ static char *magick[] = {
 
 (declare-function gud-remove "gdb-ui" t t) ; gud-def
 (declare-function gud-break  "gdb-ui" t t) ; gud-def
+(declare-function fringe-bitmaps-at-pos "fringe.c" (&optional pos window))
 
 (defun gdb-mouse-set-clear-breakpoint (event)
   "Set/clear breakpoint in left fringe/margin at mouse click.
@@ -2693,29 +2717,27 @@ another GDB command e.g pwd, to see new frames")
 (defvar gdb-memory-mode-map
   (let ((map (make-sparse-keymap)))
     (suppress-keymap map)
+    (define-key map "S" 'gdb-memory-set-address)
+    (define-key map "N" 'gdb-memory-set-repeat-count)
     (define-key map "q" 'kill-this-buffer)
      map))
 
-(defun gdb-memory-set-address (event)
+(defun gdb-memory-set-address (&optional event)
   "Set the start memory address."
-  (interactive "e")
-  (save-selected-window
-    (select-window (posn-window (event-start event)))
-    (let ((arg (read-from-minibuffer "Memory address: ")))
-      (setq gdb-memory-address arg))
-    (gdb-invalidate-memory)))
+  (interactive)
+  (let ((arg (read-from-minibuffer "Start address: ")))
+    (setq gdb-memory-address arg))
+    (gdb-invalidate-memory))
 
-(defun gdb-memory-set-repeat-count (event)
+(defun gdb-memory-set-repeat-count (&optional event)
   "Set the number of data items in memory window."
-  (interactive "e")
-  (save-selected-window
-    (select-window (posn-window (event-start event)))
-    (let* ((arg (read-from-minibuffer "Repeat count: "))
-         (count (string-to-number arg)))
-      (if (<= count 0)
-         (error "Positive numbers only")
-       (customize-set-variable 'gdb-memory-repeat-count count)
-       (gdb-invalidate-memory)))))
+  (interactive)
+  (let* ((arg (read-from-minibuffer "Repeat count: "))
+        (count (string-to-number arg)))
+    (if (<= count 0)
+       (error "Positive numbers only")
+      (customize-set-variable 'gdb-memory-repeat-count count)
+      (gdb-invalidate-memory))))
 
 (defun gdb-memory-format-binary ()
   "Set the display format to binary."
@@ -2863,7 +2885,7 @@ another GDB command e.g pwd, to see new frames")
   (setq header-line-format
        '(:eval
          (concat
-          "Read address["
+          "Start address["
           (propertize
            "-"
            'face font-lock-warning-face
@@ -2897,7 +2919,7 @@ another GDB command e.g pwd, to see new frames")
           "]: "
           (propertize gdb-memory-address
                       'face font-lock-warning-face
-                      'help-echo "mouse-1: set memory address"
+                      'help-echo "mouse-1: set start address"
                       'mouse-face 'mode-line-highlight
                       'local-map (gdb-make-header-line-mouse-map
                                   'mouse-1
@@ -3065,12 +3087,16 @@ another GDB command e.g pwd, to see new frames")
     (if answer
        (display-buffer buf nil (or frame 0)) ;Deiconify the frame if necessary.
       (let ((window (get-lru-window)))
-       (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)))
+       (if (memq (buffer-local-value 'gud-minor-mode (window-buffer window))
+                 '(gdba gdbmi))
+           (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)
+         (set-window-buffer window buf)
+         window)))))
 
 \f
 ;;; Shared keymap initialization:
@@ -3238,7 +3264,7 @@ Kills the gdb buffers, and resets variables and the source buffers."
   (remove-hook 'after-save-hook 'gdb-create-define-alist t))
 
 (defun gdb-source-info ()
-  "Find the source file where the program starts and displays it with related
+  "Find the source file where the program starts and display it with related
 buffers."
   (goto-char (point-min))
   (if (and (search-forward "Located in " nil t)
@@ -3250,7 +3276,7 @@ buffers."
   (if gdb-many-windows
       (gdb-setup-windows)
    (gdb-get-buffer-create 'gdb-breakpoints-buffer)
-   (if gdb-show-main
+   (if (and gdb-show-main gdb-main-file)
        (let ((pop-up-windows t))
         (display-buffer (gud-find-file gdb-main-file)))))
  (setq gdb-ready t))
@@ -3630,8 +3656,8 @@ is set in them."
 
 ;; 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=\"\\(.*?\\)\".*?}\\|\
+".*?level=\"\\(.*?\\)\".*?,addr=\"\\(.*?\\)\".*?,func=\"\\(.*?\\)\",\
+\\(?:.*?file=\".*?\".*?,fullname=\"\\(.*?\\)\".*?,line=\"\\(.*?\\)\".*?}\\|\
 from=\"\\(.*?\\)\"\\)")
 
 (defun gdb-frame-handler-1 ()
@@ -3674,9 +3700,9 @@ from=\"\\(.*?\\)\"\\)")
     `(lambda () (gdb-var-list-children-handler-1 ,varnum)))))
 
 (defconst gdb-var-list-children-regexp-1
-  "child={.*?name=\"\\(.+?\\)\",.*?exp=\"\\(.+?\\)\",.*?\
-numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\)\
-\\(}\\|,.*?\\(type=\"\\(.+?\\)\"\\)?.*?}\\)")
+  "child={.*?name=\"\\(.+?\\)\".*?,exp=\"\\(.+?\\)\".*?,\
+numchild=\"\\(.+?\\)\".*?,value=\\(\".*?\"\\)\
+\\(}\\|.*?,\\(type=\"\\(.+?\\)\"\\)?.*?}\\)")
 
 (defun gdb-var-list-children-handler-1 (varnum)
   (goto-char (point-min))
@@ -3713,7 +3739,7 @@ numchild=\"\\(.+?\\)\",.*?value=\\(\".*?\"\\)\
        (push 'gdb-var-update gdb-pending-triggers))))
 
 (defconst gdb-var-update-regexp-1
-  "{.*?name=\"\\(.*?\\)\",.*?\\(?:value=\\(\".*?\"\\),\\)?.*?\
+  "{.*?name=\"\\(.*?\\)\".*?,\\(?:value=\\(\".*?\"\\),\\)?.*?\
 in_scope=\"\\(.*?\\)\".*?}")
 
 (defun gdb-var-update-handler-1 ()
@@ -3753,7 +3779,7 @@ in_scope=\"\\(.*?\\)\".*?}")
     gdb-data-list-register-values-handler)
 
 (defconst gdb-data-list-register-values-regexp
-  "{.*?number=\"\\(.*?\\)\",.*?value=\"\\(.*?\\)\".*?}")
+  "{.*?number=\"\\(.*?\\)\".*?,value=\"\\(.*?\\)\".*?}")
 
 (defun gdb-data-list-register-values-handler ()
   (setq gdb-pending-triggers (delq 'gdb-invalidate-registers-1
@@ -3848,7 +3874,7 @@ in_scope=\"\\(.*?\\)\".*?}")
   gdb-stack-list-locals-handler)
 
 (defconst gdb-stack-list-locals-regexp
-  "{.*?name=\"\\(.*?\\)\",.*?type=\"\\(.*?\\)\"")
+  "{.*?name=\"\\(.*?\\)\".*?,type=\"\\(.*?\\)\"")
 
 (defvar gdb-locals-watch-map-1
   (let ((map (make-sparse-keymap)))
@@ -3875,7 +3901,7 @@ in_scope=\"\\(.*?\\)\".*?}")
     (let* ((var (current-word))
           (value (read-string (format "New value (%s): " var))))
       (gdb-enqueue-input
-       (list (concat  gdb-server-prefix"set variable " var " = " value "\n")
+       (list (concat  gdb-server-prefix "set variable " var " = " value "\n")
             'ignore)))))
 
 ;; Dont display values of arrays or structures.