comparison lisp/gdb-ui.el @ 49039:6c5f45b01d2e

Acknowledge Tom Lord as author of gdba.el. Use let construction to bind buffer-read-only to nil. (gdba): 'set height 0' in GDB. (gdb-display-end, gdb-frame-handler): Corrections to forming full expression name for header-line in display frame. (gdb-info-breakpoints-custom): Highlight breakpoints since they may be clicked on with mouse-2. (gdb-quit): Delete frames of displayed expressions when quitting. (gdb-delete-frames): New function. (gdb-source-info): Don't create stack buffer automatically.
author Nick Roberts <nickrob@snap.net.nz>
date Sat, 04 Jan 2003 22:45:39 +0000
parents f3c5848184cb
children 8a40184e2f0e
comparison
equal deleted inserted replaced
49038:e1f3921c6689 49039:6c5f45b01d2e
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA. 24 ;; Boston, MA 02111-1307, USA.
25 25
26 ;;; Commentary: 26 ;;; Commentary:
27 27
28 ;; This file is based on gdba.el from GDB 5.0 written by Jim Kingdon and uses 28 ;; This file is based on gdba.el from GDB 5.0 written by Tom Lord and Jim
29 ;; GDB's annotation interface. It has been extended to use features of Emacs 29 ;; Kingdon and uses GDB's annotation interface. It has been extended to use
30 ;; 21 such as the display margin for breakpoints and the toolbar. It also has 30 ;; features of Emacs 21 such as the display margin for breakpoints and the
31 ;; new buffers and lots of other new features such as formatted auto-display 31 ;; toolbar. It also has new buffers and lots of other new features such as
32 ;; of arrays and structures (see the GDB-UI section in the Emacs info 32 ;; formatted auto-display of arrays and structures (see the GDB-UI section in
33 ;; manual). 33 ;; the Emacs info manual). Start the debugger with M-x gdba.
34 34
35 ;; You don't need to know about annotations to use this mode as a graphical 35 ;; You don't need to know about annotations to use this mode as a graphical
36 ;; user interface to GDB. However, if you are interested developing the mode 36 ;; user interface to GDB. However, if you are interested developing the mode
37 ;; itself see the Annotations section in the GDB info manual. 37 ;; itself see the Annotations section in the GDB info manual.
38 ;; 38 ;;
139 (mapc 'make-local-variable gdb-variables) 139 (mapc 'make-local-variable gdb-variables)
140 (setq gdb-buffer-type 'gdba) 140 (setq gdb-buffer-type 'gdba)
141 ;; 141 ;;
142 (gdb-clear-inferior-io) 142 (gdb-clear-inferior-io)
143 ;; 143 ;;
144 (gdb-enqueue-input (list "set height 0\n" 'ignore))
144 ;; find source file and compilation directory here 145 ;; find source file and compilation directory here
145 (gdb-enqueue-input (list "server list\n" 'ignore)) 146 (gdb-enqueue-input (list "server list\n" 'ignore))
146 (gdb-enqueue-input (list "server info source\n" 147 (gdb-enqueue-input (list "server info source\n"
147 'gdb-source-info)) 148 'gdb-source-info))
148 ;; 149 ;;
149 (run-hooks 'gdba-mode-hook)) 150 (run-hooks 'gdba-mode-hook))
150 151
151 (defun gud-display () 152 (defun gud-display ()
152 "Display (possibly dereferenced) C expression at point." 153 "Auto-display (possibly dereferenced) C expression at point."
153 (interactive) 154 (interactive)
154 (save-excursion 155 (save-excursion
155 (let ((expr (gud-find-c-expr))) 156 (let ((expr (gud-find-c-expr)))
156 (gdb-enqueue-input 157 (gdb-enqueue-input
157 (list (concat "server whatis " expr "\n") 158 (list (concat "server whatis " expr "\n")
163 (gdb-enqueue-input 164 (gdb-enqueue-input
164 (list (concat "server display* " expr "\n") 'ignore)) 165 (list (concat "server display* " expr "\n") 'ignore))
165 (gdb-enqueue-input 166 (gdb-enqueue-input
166 (list (concat "server display " expr "\n") 'ignore)))) 167 (list (concat "server display " expr "\n") 'ignore))))
167 168
169 ; this would messy because these bindings don't work with M-x gdb
170 ; (define-key global-map "\C-x\C-a\C-a" 'gud-display)
171 ; (define-key gud-minor-mode-map "\C-c\C-a" 'gud-display)
168 172
169 ;; The completion process filter is installed temporarily to slurp the 173 ;; The completion process filter is installed temporarily to slurp the
170 ;; output of GDB up to the next prompt and build the completion list. 174 ;; output of GDB up to the next prompt and build the completion list.
171 ;; It must also handle annotations. 175 ;; It must also handle annotations.
172 176
724 (if (not (string-match "::" gdb-expression)) 728 (if (not (string-match "::" gdb-expression))
725 (setq gdb-expression (concat char gdb-current-frame 729 (setq gdb-expression (concat char gdb-current-frame
726 "::" gdb-expression)) 730 "::" gdb-expression))
727 ;;else put * back on if necessary 731 ;;else put * back on if necessary
728 (setq gdb-expression (concat char gdb-expression))) 732 (setq gdb-expression (concat char gdb-expression)))
729 (setq header-line-format (concat "-- " gdb-expression " %-")))) 733 (if (not header-line-format)
734 (setq header-line-format (concat "-- " gdb-expression " %-")))))
730 ;; 735 ;;
731 ;;-if scalar/string 736 ;;-if scalar/string
732 (if (not (re-search-forward "##" nil t)) 737 (if (not (re-search-forward "##" nil t))
733 (progn 738 (progn
734 (save-excursion 739 (save-excursion
735 (set-buffer gdb-expression-buffer-name) 740 (set-buffer gdb-expression-buffer-name)
736 (setq buffer-read-only nil) 741 (let ((buffer-read-only nil))
737 (delete-region (point-min) (point-max)) 742 (delete-region (point-min) (point-max))
738 (insert-buffer-substring 743 (insert-buffer-substring
739 (gdb-get-buffer 'gdb-partial-output-buffer)) 744 (gdb-get-buffer 'gdb-partial-output-buffer)))))
740 (setq buffer-read-only t)))
741 ;; display expression name... 745 ;; display expression name...
742 (goto-char (point-min)) 746 (goto-char (point-min))
743 (let ((start (progn (point))) 747 (let ((start (progn (point)))
744 (end (progn (end-of-line) (point)))) 748 (end (progn (end-of-line) (point))))
745 (save-excursion 749 (save-excursion
764 (gdb-field-format-begin)))) 768 (gdb-field-format-begin))))
765 (save-excursion 769 (save-excursion
766 (set-buffer gdb-expression-buffer-name) 770 (set-buffer gdb-expression-buffer-name)
767 (if gdb-dive-display-number 771 (if gdb-dive-display-number
768 (progn 772 (progn
769 (setq buffer-read-only nil) 773 (let ((buffer-read-only nil))
770 (goto-char (point-max)) 774 (goto-char (point-max))
771 (insert "\n") 775 (insert "\n")
772 (insert-text-button "[back]" 'type 'gdb-display-back) 776 (insert-text-button "[back]" 'type 'gdb-display-back)))))
773 (setq buffer-read-only t))))
774 (gdb-clear-partial-output) 777 (gdb-clear-partial-output)
775 (gdb-set-output-sink 'user) 778 (gdb-set-output-sink 'user)
776 (setq gdb-display-in-progress nil)) 779 (setq gdb-display-in-progress nil))
777 780
778 (define-button-type 'gdb-display-back 781 (define-button-type 'gdb-display-back
899 (let ((start (progn (point))) 902 (let ((start (progn (point)))
900 (end (progn (next-line) (point))) 903 (end (progn (next-line) (point)))
901 (num 0)) 904 (num 0))
902 (save-excursion 905 (save-excursion
903 (set-buffer gdb-expression-buffer-name) 906 (set-buffer gdb-expression-buffer-name)
904 (setq buffer-read-only nil) 907 (let ((buffer-read-only nil))
905 (if (string-equal gdb-annotation-arg "\*") (insert "\*")) 908 (if (string-equal gdb-annotation-arg "\*") (insert "\*"))
906 (while (<= num gdb-nesting-level) 909 (while (<= num gdb-nesting-level)
907 (insert "\t") 910 (insert "\t")
908 (setq num (+ num 1))) 911 (setq num (+ num 1)))
909 (insert-buffer-substring (gdb-get-buffer 912 (insert-buffer-substring (gdb-get-buffer
910 'gdb-partial-output-buffer) 913 'gdb-partial-output-buffer)
911 start end) 914 start end)
912 (put-text-property (- (point) (- end start)) (- (point) 1) 915 (put-text-property (- (point) (- end start)) (- (point) 1)
913 'mouse-face 'highlight) 916 'mouse-face 'highlight)
914 (put-text-property (- (point) (- end start)) (- (point) 1) 917 (put-text-property (- (point) (- end start)) (- (point) 1)
915 'local-map gdb-dive-map) 918 'local-map gdb-dive-map)))
916 (setq buffer-read-only t))
917 (delete-region start end))) 919 (delete-region start end)))
918 920
919 (defvar gdb-values) 921 (defvar gdb-values)
920 922
921 (defun gdb-array-format () 923 (defun gdb-array-format ()
969 (defvar gdb-display-string) 971 (defvar gdb-display-string)
970 (defvar gdb-array-size) 972 (defvar gdb-array-size)
971 973
972 (defun gdb-array-format1 () 974 (defun gdb-array-format1 ()
973 (setq gdb-display-string "") 975 (setq gdb-display-string "")
974 (setq buffer-read-only nil) 976 (let ((buffer-read-only nil))
975 (delete-region (point-min) (point-max)) 977 (delete-region (point-min) (point-max))
976 (let ((gdb-value-list (split-string gdb-values ", "))) 978 (let ((gdb-value-list (split-string gdb-values ", ")))
977 (string-match "\\({+\\)" (car gdb-value-list)) 979 (string-match "\\({+\\)" (car gdb-value-list))
978 (let* ((depth (- (match-end 1) (match-beginning 1))) 980 (let* ((depth (- (match-end 1) (match-beginning 1)))
979 (indices (make-vector depth '0)) 981 (indices (make-vector depth '0))
980 (index 0) (num 0) (array-start "") 982 (index 0) (num 0) (array-start "")
981 (array-stop "") (array-slice "") (array-range nil) 983 (array-stop "") (array-slice "") (array-range nil)
982 (flag t) (indices-string "")) 984 (flag t) (indices-string ""))
983 (dolist (gdb-value gdb-value-list) 985 (dolist (gdb-value gdb-value-list)
984 (string-match "{*\\([^}]*\\)\\(}*\\)" gdb-value) 986 (string-match "{*\\([^}]*\\)\\(}*\\)" gdb-value)
987 (setq num 0)
988 (while (< num depth)
989 (setq indices-string
990 (concat indices-string
991 "[" (int-to-string (aref indices num)) "]"))
992 (if (not (= (aref gdb-array-start num) -1))
993 (if (or (< (aref indices num) (aref gdb-array-start num))
994 (> (aref indices num) (aref gdb-array-stop num)))
995 (setq flag nil))
996 (aset gdb-array-size num (aref indices num)))
997 (setq num (+ num 1)))
998 (if flag
999 (let ((gdb-display-value (match-string 1 gdb-value)))
1000 (setq gdb-display-string (concat gdb-display-string " "
1001 gdb-display-value))
1002 (insert
1003 (concat indices-string "\t" gdb-display-value "\n"))))
1004 (setq indices-string "")
1005 (setq flag t)
1006 ;; 0<= index < depth, start at right : (- depth 1)
1007 (setq index (- (- depth 1)
1008 (- (match-end 2) (match-beginning 2))))
1009 ;;don't set for very last brackets
1010 (when (>= index 0)
1011 (aset indices index (+ 1 (aref indices index)))
1012 (setq num (+ 1 index))
1013 (while (< num depth)
1014 (aset indices num 0)
1015 (setq num (+ num 1)))))
985 (setq num 0) 1016 (setq num 0)
986 (while (< num depth) 1017 (while (< num depth)
987 (setq indices-string 1018 (if (= (aref gdb-array-start num) -1)
988 (concat indices-string 1019 (progn
989 "[" (int-to-string (aref indices num)) "]")) 1020 (aset gdb-array-start num 0)
990 (if (not (= (aref gdb-array-start num) -1)) 1021 (aset gdb-array-stop num (aref indices num))))
991 (if (or (< (aref indices num) (aref gdb-array-start num)) 1022 (setq array-start (int-to-string (aref gdb-array-start num)))
992 (> (aref indices num) (aref gdb-array-stop num))) 1023 (setq array-stop (int-to-string (aref gdb-array-stop num)))
993 (setq flag nil)) 1024 (setq array-range (concat "[" array-start
994 (aset gdb-array-size num (aref indices num))) 1025 ":" array-stop "]"))
1026 (put-text-property 1 (+ (length array-start)
1027 (length array-stop) 2)
1028 'mouse-face 'highlight array-range)
1029 (put-text-property 1 (+ (length array-start)
1030 (length array-stop) 2)
1031 'local-map gdb-array-slice-map array-range)
1032 (goto-char (point-min))
1033 (setq array-slice (concat array-slice array-range))
995 (setq num (+ num 1))) 1034 (setq num (+ num 1)))
996 (if flag
997 (let ((gdb-display-value (match-string 1 gdb-value)))
998 (setq gdb-display-string (concat gdb-display-string " "
999 gdb-display-value))
1000 (insert
1001 (concat indices-string "\t" gdb-display-value "\n"))))
1002 (setq indices-string "")
1003 (setq flag t)
1004 ;; 0<= index < depth, start at right : (- depth 1)
1005 (setq index (- (- depth 1)
1006 (- (match-end 2) (match-beginning 2))))
1007 ;;don't set for very last brackets
1008 (when (>= index 0)
1009 (aset indices index (+ 1 (aref indices index)))
1010 (setq num (+ 1 index))
1011 (while (< num depth)
1012 (aset indices num 0)
1013 (setq num (+ num 1)))))
1014 (setq num 0)
1015 (while (< num depth)
1016 (if (= (aref gdb-array-start num) -1)
1017 (progn
1018 (aset gdb-array-start num 0)
1019 (aset gdb-array-stop num (aref indices num))))
1020 (setq array-start (int-to-string (aref gdb-array-start num)))
1021 (setq array-stop (int-to-string (aref gdb-array-stop num)))
1022 (setq array-range (concat "[" array-start
1023 ":" array-stop "]"))
1024 (put-text-property 1 (+ (length array-start)
1025 (length array-stop) 2)
1026 'mouse-face 'highlight array-range)
1027 (put-text-property 1 (+ (length array-start)
1028 (length array-stop) 2)
1029 'local-map gdb-array-slice-map array-range)
1030 (goto-char (point-min)) 1035 (goto-char (point-min))
1031 (setq array-slice (concat array-slice array-range)) 1036 (insert "Array Size : ")
1032 (setq num (+ num 1))) 1037 (setq num 0)
1033 (goto-char (point-min)) 1038 (while (< num depth)
1034 (insert "Array Size : ") 1039 (insert
1035 (setq num 0) 1040 (concat "["
1036 (while (< num depth) 1041 (int-to-string (+ (aref gdb-array-size num) 1)) "]"))
1042 (setq num (+ num 1)))
1037 (insert 1043 (insert
1038 (concat "[" 1044 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n"))))))
1039 (int-to-string (+ (aref gdb-array-size num) 1)) "]"))
1040 (setq num (+ num 1)))
1041 (insert
1042 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n"))))
1043 (setq buffer-read-only t))
1044 1045
1045 (defun gud-gdba-marker-filter (string) 1046 (defun gud-gdba-marker-filter (string)
1046 "A gud marker filter for gdb. Handle a burst of output from GDB." 1047 "A gud marker filter for gdb. Handle a burst of output from GDB."
1047 (let ( 1048 (let (
1048 ;; Recall the left over burst from last time 1049 ;; Recall the left over burst from last time
1266 (setq flag (char-after (match-beginning 2))) 1267 (setq flag (char-after (match-beginning 2)))
1267 (beginning-of-line) 1268 (beginning-of-line)
1268 (if (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t) 1269 (if (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t)
1269 (progn 1270 (progn
1270 (looking-at "\\(\\S-*\\):\\([0-9]+\\)") 1271 (looking-at "\\(\\S-*\\):\\([0-9]+\\)")
1271 (let ((line (match-string 2)) 1272 (let ((line (match-string 2)) (buffer-read-only nil)
1272 (file (match-string 1))) 1273 (file (match-string 1)))
1274 (put-text-property (progn (beginning-of-line) (point))
1275 (progn (end-of-line) (point))
1276 'mouse-face 'highlight)
1273 (save-excursion 1277 (save-excursion
1274 (set-buffer 1278 (set-buffer
1275 (find-file-noselect 1279 (find-file-noselect
1276 (if (file-exists-p file) file 1280 (if (file-exists-p file) file
1277 (expand-file-name file gdb-cdir)))) 1281 (expand-file-name file gdb-cdir))))
1630 (let ((number 1634 (let ((number
1631 (match-string 1 (buffer-name buffer)))) 1635 (match-string 1 (buffer-name buffer))))
1632 (if (not (memq (string-to-int number) display-list)) 1636 (if (not (memq (string-to-int number) display-list))
1633 (kill-buffer 1637 (kill-buffer
1634 (get-buffer (concat "*display " number "*"))))))))) 1638 (get-buffer (concat "*display " number "*")))))))))
1635 (dolist (frame (frame-list)) 1639 (gdb-delete-frames display-list))))
1636 (let ((frame-name (frame-parameter frame 'name))) 1640
1637 (if (string-match "\\*display \\([0-9]+\\)\\*" frame-name) 1641 (defun gdb-delete-frames (display-list)
1638 (progn 1642 (dolist (frame (frame-list))
1639 (let ((number (match-string 1 frame-name))) 1643 (let ((frame-name (frame-parameter frame 'name)))
1640 (if (not (memq (string-to-int number) display-list)) 1644 (if (string-match "\\*display \\([0-9]+\\)\\*" frame-name)
1641 (progn (kill-buffer 1645 (progn
1642 (get-buffer (concat "*display " number "*"))) 1646 (let ((number (match-string 1 frame-name)))
1643 (delete-frame frame))))))))))) 1647 (if (not (memq (string-to-int number) display-list))
1648 (progn (kill-buffer
1649 (get-buffer (concat "*display " number "*")))
1650 (delete-frame frame)))))))))
1644 1651
1645 (defvar gdb-display-mode-map 1652 (defvar gdb-display-mode-map
1646 (let ((map (make-sparse-keymap)) 1653 (let ((map (make-sparse-keymap))
1647 (menu (make-sparse-keymap "Display"))) 1654 (menu (make-sparse-keymap "Display")))
1648 (define-key menu [toggle] '("Toggle" . gdb-toggle-display)) 1655 (define-key menu [toggle] '("Toggle" . gdb-toggle-display))
1919 (defun gdb-quit () 1926 (defun gdb-quit ()
1920 "Kill the GUD interaction and gdb buffers and reset variables. 1927 "Kill the GUD interaction and gdb buffers and reset variables.
1921 Use this command to exit a debugging session cleanly and reset 1928 Use this command to exit a debugging session cleanly and reset
1922 things like the toolbar and margin in the source buffers." 1929 things like the toolbar and margin in the source buffers."
1923 (interactive) 1930 (interactive)
1931 (gdb-delete-frames '())
1924 (dolist (buffer (buffer-list)) 1932 (dolist (buffer (buffer-list))
1925 (save-excursion 1933 (save-excursion
1926 (set-buffer buffer) 1934 (set-buffer buffer)
1927 (if (eq gud-minor-mode 'gdba) 1935 (if (eq gud-minor-mode 'gdba)
1928 (if (string-match "^\*" (buffer-name)) 1936 (if (string-match "^\*" (buffer-name))
1959 (other-window 1)) 1967 (other-window 1))
1960 (delete-other-windows) 1968 (delete-other-windows)
1961 (if gdb-many-windows 1969 (if gdb-many-windows
1962 (gdb-setup-windows) 1970 (gdb-setup-windows)
1963 (gdb-display-breakpoints-buffer) 1971 (gdb-display-breakpoints-buffer)
1964 (gdb-display-stack-buffer)
1965 (gdb-display-display-buffer) 1972 (gdb-display-display-buffer)
1966 (delete-other-windows) 1973 (delete-other-windows)
1967 (split-window) 1974 (split-window)
1968 (other-window 1) 1975 (other-window 1)
1969 (switch-to-buffer (gud-find-file gdb-main-file)) 1976 (switch-to-buffer (gud-find-file gdb-main-file))
2219 (gdb-set-pending-triggers 2226 (gdb-set-pending-triggers
2220 (delq 'gdb-get-current-frame (gdb-get-pending-triggers))) 2227 (delq 'gdb-get-current-frame (gdb-get-pending-triggers)))
2221 (save-excursion 2228 (save-excursion
2222 (set-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)) 2229 (set-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer))
2223 (goto-char (point-min)) 2230 (goto-char (point-min))
2224 (if (looking-at "^#[0-9]*\\s-*\\(\\S-*\\)") 2231 (if (looking-at "^#[0-9]*\\s-*0x\\S-* in \\(\\S-*\\)")
2225 (setq gdb-current-frame (match-string 1))))) 2232 (setq gdb-current-frame (match-string 1))
2233 (if (looking-at "^#[0-9]*\\s-*\\(\\S-*\\)")
2234 (setq gdb-current-frame (match-string 1))))))
2226 2235
2227 (provide 'gdb-ui) 2236 (provide 'gdb-ui)
2228 2237
2229 ;;; gdb-ui.el ends here 2238 ;;; gdb-ui.el ends here