comparison lisp/progmodes/gdb-ui.el @ 75354:6e5bbaf920de

(gdb-var-create-regexp) (gdb-var-create-handler): Handle value field in GDB output of -var-create. (gdb-max-frames): New variable. (gdb-stack-buffer, gdb-frames-select): Use it. (gdb-info-stack-custom): Help user customize gdb-max-frames, if necessary. (gdb-get-frame-number): Simplify.
author Nick Roberts <nickrob@snap.net.nz>
date Sun, 21 Jan 2007 10:49:42 +0000
parents e3694f1cb928
children bab23bcfde6e
comparison
equal deleted inserted replaced
75353:b476eafb60d0 75354:6e5bbaf920de
121 (defvar gdb-overlay-arrow-position nil) 121 (defvar gdb-overlay-arrow-position nil)
122 (defvar gdb-stack-position nil) 122 (defvar gdb-stack-position nil)
123 (defvar gdb-server-prefix nil) 123 (defvar gdb-server-prefix nil)
124 (defvar gdb-flush-pending-output nil) 124 (defvar gdb-flush-pending-output nil)
125 (defvar gdb-location-alist nil 125 (defvar gdb-location-alist nil
126 "Alist of breakpoint numbers and full filenames.") 126 "Alist of breakpoint numbers and full filenames. Only used for files that
127 (defvar gdb-active-process nil "GUD tooltips display variable values when t, \ 127 Emacs can't find.")
128 and #define directives otherwise.") 128 (defvar gdb-active-process nil
129 "GUD tooltips display variable values when t, and macro definitions otherwise.")
129 (defvar gdb-error "Non-nil when GDB is reporting an error.") 130 (defvar gdb-error "Non-nil when GDB is reporting an error.")
130 (defvar gdb-macro-info nil 131 (defvar gdb-macro-info nil
131 "Non-nil if GDB knows that the inferior includes preprocessor macro info.") 132 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
132 (defvar gdb-buffer-fringe-width nil) 133 (defvar gdb-buffer-fringe-width nil)
133 (defvar gdb-signalled nil) 134 (defvar gdb-signalled nil)
278 :group 'gud 279 :group 'gud
279 :type 'integer 280 :type 'integer
280 :version "22.1") 281 :version "22.1")
281 282
282 (defvar gdb-debug-ring nil 283 (defvar gdb-debug-ring nil
283 "List of commands, most recent first, sent to and replies received from GDB. 284 "List of commands sent to and replies received from GDB. Most recent
284 This variable is used to debug GDB-UI.") 285 commands are listed first. This variable is used to debug GDB-UI.")
285 286
286 ;;;###autoload 287 ;;;###autoload
287 (defcustom gdb-enable-debug nil 288 (defcustom gdb-enable-debug nil
288 "Non-nil means record the process input and output in `gdb-debug-ring'." 289 "Non-nil means record the process input and output in `gdb-debug-ring'."
289 :type 'boolean 290 :type 'boolean
719 (concat"-var-create - * " expr "\n")) 720 (concat"-var-create - * " expr "\n"))
720 `(lambda () (gdb-var-create-handler ,expr))))))) 721 `(lambda () (gdb-var-create-handler ,expr)))))))
721 (message "gud-watch is a no-op in this mode.")))) 722 (message "gud-watch is a no-op in this mode."))))
722 723
723 (defconst gdb-var-create-regexp 724 (defconst gdb-var-create-regexp
724 "name=\"\\(.*?\\)\",.*numchild=\"\\(.*?\\)\",.*type=\"\\(.*?\\)\"") 725 "name=\"\\(.*?\\)\",.*numchild=\"\\(.*?\\)\",\\(?:.*value=\\(\".*\"\\),\\)?.*type=\"\\(.*?\\)\"")
725 726
726 (defun gdb-var-create-handler (expr) 727 (defun gdb-var-create-handler (expr)
727 (goto-char (point-min)) 728 (goto-char (point-min))
728 (if (re-search-forward gdb-var-create-regexp nil t) 729 (if (re-search-forward gdb-var-create-regexp nil t)
729 (let ((var (list 730 (let ((var (list
731 (if (and (string-equal gdb-current-language "c") 732 (if (and (string-equal gdb-current-language "c")
732 gdb-use-colon-colon-notation gdb-selected-frame) 733 gdb-use-colon-colon-notation gdb-selected-frame)
733 (setq expr (concat gdb-selected-frame "::" expr)) 734 (setq expr (concat gdb-selected-frame "::" expr))
734 expr) 735 expr)
735 (match-string 2) 736 (match-string 2)
736 (match-string 3) 737 (match-string 4)
737 nil nil gdb-frame-address))) 738 (if (match-string 3) (read (match-string 3)))
739 nil gdb-frame-address)))
738 (push var gdb-var-list) 740 (push var gdb-var-list)
739 (unless (string-equal 741 (unless (string-equal
740 speedbar-initial-expansion-list-name "GUD") 742 speedbar-initial-expansion-list-name "GUD")
741 (speedbar-change-initial-expansion-list "GUD")) 743 (speedbar-change-initial-expansion-list "GUD"))
742 (gdb-enqueue-input 744 (unless (nth 4 var)
743 (list 745 (gdb-enqueue-input
744 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba) 746 (list
745 (concat "server interpreter mi \"0-var-evaluate-expression " 747 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
746 (car var) "\"\n") 748 'gdba)
747 (concat "0-var-evaluate-expression " (car var) "\n")) 749 (concat "server interpreter mi \"0-var-evaluate-expression "
748 `(lambda () (gdb-var-evaluate-expression-handler 750 (car var) "\"\n")
749 ,(car var) nil))))) 751 (concat "0-var-evaluate-expression " (car var) "\n"))
752 `(lambda () (gdb-var-evaluate-expression-handler
753 ,(car var) nil))))))
750 (if (search-forward "Undefined command" nil t) 754 (if (search-forward "Undefined command" nil t)
751 (message-box "Watching expressions requires GDB 6.0 onwards") 755 (message-box "Watching expressions requires GDB 6.0 onwards")
752 (message-box "No symbol \"%s\" in current context." expr)))) 756 (message-box "No symbol \"%s\" in current context." expr))))
753 757
754 (defun gdb-speedbar-update () 758 (defun gdb-speedbar-update ()
895 :type 'boolean 899 :type 'boolean
896 :group 'gud 900 :group 'gud
897 :version "22.1") 901 :version "22.1")
898 902
899 (defcustom gdb-max-children 40 903 (defcustom gdb-max-children 40
900 "Maximum number of children allowed before Emacs asks" 904 "Maximum number of children before expansion requires confirmation."
901 :type 'integer 905 :type 'integer
902 :group 'gud 906 :group 'gud
903 :version "22.1") 907 :version "22.1")
904 908
905 (defun gdb-speedbar-expand-node (text token indent) 909 (defun gdb-speedbar-expand-node (text token indent)
2027 ;; Frames buffer. This displays a perpetually correct bactracktrace 2031 ;; Frames buffer. This displays a perpetually correct bactracktrace
2028 ;; (from the command `where'). 2032 ;; (from the command `where').
2029 ;; 2033 ;;
2030 ;; Alas, if your stack is deep, it is costly. 2034 ;; Alas, if your stack is deep, it is costly.
2031 ;; 2035 ;;
2036 (defcustom gdb-max-frames 40
2037 "Maximum number of frames displayed in call stack."
2038 :type 'integer
2039 :group 'gud
2040 :version "22.1")
2041
2032 (gdb-set-buffer-rules 'gdb-stack-buffer 2042 (gdb-set-buffer-rules 'gdb-stack-buffer
2033 'gdb-stack-buffer-name 2043 'gdb-stack-buffer-name
2034 'gdb-frames-mode) 2044 'gdb-frames-mode)
2035 2045
2036 (def-gdb-auto-updated-buffer gdb-stack-buffer 2046 (def-gdb-auto-updated-buffer gdb-stack-buffer
2037 gdb-invalidate-frames 2047 gdb-invalidate-frames
2038 "server info stack\n" 2048 (concat "server info stack " (number-to-string gdb-max-frames) "\n")
2039 gdb-info-stack-handler 2049 gdb-info-stack-handler
2040 gdb-info-stack-custom) 2050 gdb-info-stack-custom)
2041 2051
2042 (defun gdb-info-stack-custom () 2052 (defun gdb-info-stack-custom ()
2043 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer) 2053 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
2075 'face font-lock-function-name-face)) 2085 'face font-lock-function-name-face))
2076 (goto-char bl) 2086 (goto-char bl)
2077 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t) 2087 (while (re-search-forward "\\(\\(\\sw\\|[_.]\\)+\\)=" el t)
2078 (put-text-property (match-beginning 1) (match-end 1) 2088 (put-text-property (match-beginning 1) (match-end 1)
2079 'face font-lock-variable-name-face)))) 2089 'face font-lock-variable-name-face))))
2080 (forward-line 1)))) 2090 (forward-line 1))
2091 (forward-line -1)
2092 (when (looking-at "(More stack frames follow...)")
2093 (add-text-properties (match-beginning 0) (match-end 0)
2094 '(mouse-face highlight
2095 gdb-max-frames t
2096 help-echo
2097 "mouse-2, RET: customize gdb-max-frames to see more frames")))))
2081 (when gdb-look-up-stack 2098 (when gdb-look-up-stack
2082 (goto-char (point-min)) 2099 (goto-char (point-min))
2083 (when (re-search-forward "\\(\\S-+?\\):\\([0-9]+\\)" nil t) 2100 (when (re-search-forward "\\(\\S-+?\\):\\([0-9]+\\)" nil t)
2084 (let ((start (line-beginning-position)) 2101 (let ((start (line-beginning-position))
2085 (file (match-string 1)) 2102 (file (match-string 1))
2145 (defun gdb-get-frame-number () 2162 (defun gdb-get-frame-number ()
2146 (save-excursion 2163 (save-excursion
2147 (end-of-line) 2164 (end-of-line)
2148 (let* ((start (line-beginning-position)) 2165 (let* ((start (line-beginning-position))
2149 (pos (re-search-backward "^#*\\([0-9]+\\)" start t)) 2166 (pos (re-search-backward "^#*\\([0-9]+\\)" start t))
2150 (n (or (and pos (match-string-no-properties 1)) "0"))) 2167 (n (or (and pos (match-string 1)) "0")))
2151 n))) 2168 n)))
2152 2169
2153 (defun gdb-frames-select (&optional event) 2170 (defun gdb-frames-select (&optional event)
2154 "Select the frame and display the relevant source." 2171 "Select the frame and display the relevant source."
2155 (interactive (list last-input-event)) 2172 (interactive (list last-input-event))
2156 (if event (posn-set-point (event-end event))) 2173 (if event (posn-set-point (event-end event)))
2157 (gdb-enqueue-input 2174 (if (get-text-property (point) 'gdb-max-frames)
2158 (list (concat gdb-server-prefix "frame " 2175 (progn
2159 (gdb-get-frame-number) "\n") 'ignore))) 2176 (message-box "After setting gdb-max-frames, you need to enter\n\
2177 another GDB command e.g pwd, to see new frames")
2178 (customize-variable-other-window 'gdb-max-frames))
2179 (gdb-enqueue-input
2180 (list (concat gdb-server-prefix "frame "
2181 (gdb-get-frame-number) "\n") 'ignore))))
2160 2182
2161 2183
2162 ;; Threads buffer. This displays a selectable thread list. 2184 ;; Threads buffer. This displays a selectable thread list.
2163 ;; 2185 ;;
2164 (gdb-set-buffer-rules 'gdb-threads-buffer 2186 (gdb-set-buffer-rules 'gdb-threads-buffer
2579 (concat 2601 (concat
2580 "Read address[" 2602 "Read address["
2581 (propertize 2603 (propertize
2582 "-" 2604 "-"
2583 'face font-lock-warning-face 2605 'face font-lock-warning-face
2584 'help-echo "mouse-1: Decrement address" 2606 'help-echo "mouse-1: decrement address"
2585 'mouse-face 'mode-line-highlight 2607 'mouse-face 'mode-line-highlight
2586 'local-map 2608 'local-map
2587 (gdb-make-header-line-mouse-map 2609 (gdb-make-header-line-mouse-map
2588 'mouse-1 2610 'mouse-1
2589 (lambda () (interactive) 2611 (lambda () (interactive)
2599 ((string= gdb-memory-unit "g") 8))))))) 2621 ((string= gdb-memory-unit "g") 8)))))))
2600 (gdb-invalidate-memory))))) 2622 (gdb-invalidate-memory)))))
2601 "|" 2623 "|"
2602 (propertize "+" 2624 (propertize "+"
2603 'face font-lock-warning-face 2625 'face font-lock-warning-face
2604 'help-echo "mouse-1: Increment address" 2626 'help-echo "mouse-1: increment address"
2605 'mouse-face 'mode-line-highlight 2627 'mouse-face 'mode-line-highlight
2606 'local-map (gdb-make-header-line-mouse-map 2628 'local-map (gdb-make-header-line-mouse-map
2607 'mouse-1 2629 'mouse-1
2608 (lambda () (interactive) 2630 (lambda () (interactive)
2609 (let ((gdb-memory-address nil)) 2631 (let ((gdb-memory-address nil))
2610 (gdb-invalidate-memory))))) 2632 (gdb-invalidate-memory)))))
2611 "]: " 2633 "]: "
2612 (propertize gdb-memory-address 2634 (propertize gdb-memory-address
2613 'face font-lock-warning-face 2635 'face font-lock-warning-face
2614 'help-echo "mouse-1: Set memory address" 2636 'help-echo "mouse-1: set memory address"
2615 'mouse-face 'mode-line-highlight 2637 'mouse-face 'mode-line-highlight
2616 'local-map (gdb-make-header-line-mouse-map 2638 'local-map (gdb-make-header-line-mouse-map
2617 'mouse-1 2639 'mouse-1
2618 #'gdb-memory-set-address)) 2640 #'gdb-memory-set-address))
2619 " Repeat Count: " 2641 " Repeat Count: "
2620 (propertize (number-to-string gdb-memory-repeat-count) 2642 (propertize (number-to-string gdb-memory-repeat-count)
2621 'face font-lock-warning-face 2643 'face font-lock-warning-face
2622 'help-echo "mouse-1: Set repeat count" 2644 'help-echo "mouse-1: set repeat count"
2623 'mouse-face 'mode-line-highlight 2645 'mouse-face 'mode-line-highlight
2624 'local-map (gdb-make-header-line-mouse-map 2646 'local-map (gdb-make-header-line-mouse-map
2625 'mouse-1 2647 'mouse-1
2626 #'gdb-memory-set-repeat-count)) 2648 #'gdb-memory-set-repeat-count))
2627 " Display Format: " 2649 " Display Format: "
2628 (propertize gdb-memory-format 2650 (propertize gdb-memory-format
2629 'face font-lock-warning-face 2651 'face font-lock-warning-face
2630 'help-echo "mouse-3: Select display format" 2652 'help-echo "mouse-3: select display format"
2631 'mouse-face 'mode-line-highlight 2653 'mouse-face 'mode-line-highlight
2632 'local-map gdb-memory-format-map) 2654 'local-map gdb-memory-format-map)
2633 " Unit Size: " 2655 " Unit Size: "
2634 (propertize gdb-memory-unit 2656 (propertize gdb-memory-unit
2635 'face font-lock-warning-face 2657 'face font-lock-warning-face
2636 'help-echo "mouse-3: Select unit size" 2658 'help-echo "mouse-3: select unit size"
2637 'mouse-face 'mode-line-highlight 2659 'mouse-face 'mode-line-highlight
2638 'local-map gdb-memory-unit-map)))) 2660 'local-map gdb-memory-unit-map))))
2639 (set (make-local-variable 'font-lock-defaults) 2661 (set (make-local-variable 'font-lock-defaults)
2640 '(gdb-memory-font-lock-keywords)) 2662 '(gdb-memory-font-lock-keywords))
2641 (run-mode-hooks 'gdb-memory-mode-hook) 2663 (run-mode-hooks 'gdb-memory-mode-hook)
3009 '(gdba gdbmi))) 3031 '(gdba gdbmi)))
3010 ;;Pre GDB 6.3 "info sources" doesn't give absolute file name. 3032 ;;Pre GDB 6.3 "info sources" doesn't give absolute file name.
3011 (if (member (if (string-equal gdb-version "pre-6.4") 3033 (if (member (if (string-equal gdb-version "pre-6.4")
3012 (file-name-nondirectory buffer-file-name) 3034 (file-name-nondirectory buffer-file-name)
3013 buffer-file-name) 3035 buffer-file-name)
3014 gdb-source-file-list) 3036 gdb-source-file-list)
3015 (with-current-buffer (find-buffer-visiting buffer-file-name) 3037 (with-current-buffer (find-buffer-visiting buffer-file-name)
3016 (set (make-local-variable 'gud-minor-mode) 3038 (set (make-local-variable 'gud-minor-mode)
3017 (buffer-local-value 'gud-minor-mode gud-comint-buffer)) 3039 (buffer-local-value 'gud-minor-mode gud-comint-buffer))
3018 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))))) 3040 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)))))
3019 3041