comparison lisp/gdb-ui.el @ 49000:f3c5848184cb

(gdb-delete-display): Rename (gdb-delete-expression). (gdb-goto-bp-this-line): Rename (gdb-goto-breakpoint). (gdb-toggle-bp-this-line): Rename (gdb-toggle-breakpoint). (gdb-delete-bp-this-line): Rename (gdb-delete-breakpoint). (gdb-toggle-disp-this-line): Rename (gdb-toggle-display). (gdb-delete-disp-this-line): Rename (gdb-delete-display). (gud-gdba-marker-filter): Remove unnecessary save-match-data. (gdb-mouse-goto-breakpoint, gdb-frames-select): New functions. (gdb-frames-mouse-select): Simplify. Make keybindings (gdb-goto-breakpoint, gdb-frames-select, etc) consistent with other modes in emacs. (gdb-display-source-buffer): Return window of source buffer for (gud-display-line).
author Nick Roberts <nickrob@snap.net.nz>
date Sun, 29 Dec 2002 20:46:41 +0000
parents 1bb53161a4b9
children 6c5f45b01d2e
comparison
equal deleted inserted replaced
48999:a39c6bb2d692 49000:f3c5848184cb
45 45
46 (defvar gdb-main-or-pc nil "Initialisation for Assembler buffer.") 46 (defvar gdb-main-or-pc nil "Initialisation for Assembler buffer.")
47 (defvar gdb-current-address nil) 47 (defvar gdb-current-address nil)
48 (defvar gdb-display-in-progress nil) 48 (defvar gdb-display-in-progress nil)
49 (defvar gdb-dive nil) 49 (defvar gdb-dive nil)
50 (defvar gdb-buffer-type nil)
51 (defvar gdb-variables '()
52 "A list of variables that are local to the GUD buffer.")
53
50 54
51 ;;;###autoload 55 ;;;###autoload
52 (defun gdba (command-line) 56 (defun gdba (command-line)
53 "Run gdb on program FILE in buffer *gud-FILE*. 57 "Run gdb on program FILE in buffer *gud-FILE*.
54 The directory containing FILE becomes the initial working directory 58 The directory containing FILE becomes the initial working directory
74 | 78 |
75 | 79 |
76 | 80 |
77 --------------------------------------------------------------------- 81 ---------------------------------------------------------------------
78 Stack buffer | Breakpoints buffer 82 Stack buffer | Breakpoints buffer
79 \[mouse-2\] gdb-frames-mouse-select | SPC gdb-toggle-bp-this-line 83 RET gdb-frames-select | SPC gdb-toggle-breakpoint
80 | g gdb-goto-bp-this-line 84 | RET gdb-goto-breakpoint
81 | d gdb-delete-bp-this-line 85 | d gdb-delete-breakpoint
82 --------------------------------------------------------------------- 86 ---------------------------------------------------------------------
83 87
84 All the buffers share the toolbar and source should always display in the same 88 All the buffers share the toolbar and source should always display in the same
85 window e.g after typing g on a breakpoint in the breakpoints buffer. Breakpoint 89 window e.g after typing g on a breakpoint in the breakpoints buffer. Breakpoint
86 icons are displayed both by setting a break with gud-break and by typing break 90 icons are displayed both by setting a break with gud-break and by typing break
171 ;; 175 ;;
172 ;; In this world, there are gdb variables (of unspecified 176 ;; In this world, there are gdb variables (of unspecified
173 ;; representation) and buffers associated with those objects. 177 ;; representation) and buffers associated with those objects.
174 ;; The list of variables is built up by the expansions of 178 ;; The list of variables is built up by the expansions of
175 ;; def-gdb-variable 179 ;; def-gdb-variable
176
177 (defvar gdb-variables '()
178 "A list of variables that are local to the GUD buffer.")
179 180
180 (defmacro def-gdb-var (root-symbol &optional default doc) 181 (defmacro def-gdb-var (root-symbol &optional default doc)
181 (let* ((root (symbol-name root-symbol)) 182 (let* ((root (symbol-name root-symbol))
182 (accessor (intern (concat "gdb-get-" root))) 183 (accessor (intern (concat "gdb-get-" root)))
183 (setter (intern (concat "gdb-set-" root))) 184 (setter (intern (concat "gdb-set-" root)))
1041 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n")))) 1042 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n"))))
1042 (setq buffer-read-only t)) 1043 (setq buffer-read-only t))
1043 1044
1044 (defun gud-gdba-marker-filter (string) 1045 (defun gud-gdba-marker-filter (string)
1045 "A gud marker filter for gdb. Handle a burst of output from GDB." 1046 "A gud marker filter for gdb. Handle a burst of output from GDB."
1046 (save-match-data 1047 (let (
1047 (let ( 1048 ;; Recall the left over burst from last time
1048 ;; Recall the left over burst from last time 1049 (burst (concat (gdb-get-burst) string))
1049 (burst (concat (gdb-get-burst) string)) 1050 ;; Start accumulating output for the GUD buffer
1050 ;; Start accumulating output for the GUD buffer 1051 (output ""))
1051 (output "")) 1052 ;;
1053 ;; Process all the complete markers in this chunk.
1054 (while (string-match "\n\032\032\\(.*\\)\n" burst)
1055 (let ((annotation (match-string 1 burst)))
1056 ;;
1057 ;; Stuff prior to the match is just ordinary output.
1058 ;; It is either concatenated to OUTPUT or directed
1059 ;; elsewhere.
1060 (setq output
1061 (gdb-concat-output
1062 output
1063 (substring burst 0 (match-beginning 0))))
1064
1065 ;; Take that stuff off the burst.
1066 (setq burst (substring burst (match-end 0)))
1067
1068 ;; Parse the tag from the annotation, and maybe its arguments.
1069 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1070 (let* ((annotation-type (match-string 1 annotation))
1071 (annotation-arguments (match-string 2 annotation))
1072 (annotation-rule (assoc annotation-type
1073 gdb-annotation-rules)))
1074 ;; Call the handler for this annotation.
1075 (if annotation-rule
1076 (funcall (car (cdr annotation-rule))
1077 annotation-arguments)
1078 ;; Else the annotation is not recognized. Ignore it silently,
1079 ;; so that GDB can add new annotations without causing
1080 ;; us to blow up.
1081 ))))
1082 ;;
1083 ;; Does the remaining text end in a partial line?
1084 ;; If it does, then keep part of the burst until we get more.
1085 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1086 burst)
1087 (progn
1088 ;; Everything before the potential marker start can be output.
1089 (setq output
1090 (gdb-concat-output output
1091 (substring burst 0 (match-beginning 0))))
1092 ;;
1093 ;; Everything after, we save, to combine with later input.
1094 (setq burst (substring burst (match-beginning 0))))
1052 ;; 1095 ;;
1053 ;; Process all the complete markers in this chunk. 1096 ;; In case we know the burst contains no partial annotations:
1054 (while (string-match "\n\032\032\\(.*\\)\n" burst) 1097 (progn
1055 (let ((annotation (match-string 1 burst))) 1098 (setq output (gdb-concat-output output burst))
1056 ;; 1099 (setq burst "")))
1057 ;; Stuff prior to the match is just ordinary output. 1100 ;;
1058 ;; It is either concatenated to OUTPUT or directed 1101 ;; Save the remaining burst for the next call to this function.
1059 ;; elsewhere. 1102 (gdb-set-burst burst)
1060 (setq output 1103 output))
1061 (gdb-concat-output
1062 output
1063 (substring burst 0 (match-beginning 0))))
1064
1065 ;; Take that stuff off the burst.
1066 (setq burst (substring burst (match-end 0)))
1067
1068 ;; Parse the tag from the annotation, and maybe its arguments.
1069 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
1070 (let* ((annotation-type (match-string 1 annotation))
1071 (annotation-arguments (match-string 2 annotation))
1072 (annotation-rule (assoc annotation-type
1073 gdb-annotation-rules)))
1074 ;; Call the handler for this annotation.
1075 (if annotation-rule
1076 (funcall (car (cdr annotation-rule))
1077 annotation-arguments)
1078 ;; Else the annotation is not recognized. Ignore it silently,
1079 ;; so that GDB can add new annotations without causing
1080 ;; us to blow up.
1081 ))))
1082 ;;
1083 ;; Does the remaining text end in a partial line?
1084 ;; If it does, then keep part of the burst until we get more.
1085 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
1086 burst)
1087 (progn
1088 ;; Everything before the potential marker start can be output.
1089 (setq output
1090 (gdb-concat-output output
1091 (substring burst 0 (match-beginning 0))))
1092 ;;
1093 ;; Everything after, we save, to combine with later input.
1094 (setq burst (substring burst (match-beginning 0))))
1095 ;;
1096 ;; In case we know the burst contains no partial annotations:
1097 (progn
1098 (setq output (gdb-concat-output output burst))
1099 (setq burst "")))
1100 ;;
1101 ;; Save the remaining burst for the next call to this function.
1102 (gdb-set-burst burst)
1103 output)))
1104 1104
1105 (defun gdb-concat-output (so-far new) 1105 (defun gdb-concat-output (so-far new)
1106 (let ((sink (gdb-get-output-sink ))) 1106 (let ((sink (gdb-get-output-sink )))
1107 (cond 1107 (cond
1108 ((eq sink 'user) (concat so-far new)) 1108 ((eq sink 'user) (concat so-far new))
1325 (gdb-get-create-buffer 'gdb-breakpoints-buffer))) 1325 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1326 1326
1327 (defvar gdb-breakpoints-mode-map 1327 (defvar gdb-breakpoints-mode-map
1328 (let ((map (make-sparse-keymap)) 1328 (let ((map (make-sparse-keymap))
1329 (menu (make-sparse-keymap "Breakpoints"))) 1329 (menu (make-sparse-keymap "Breakpoints")))
1330 (define-key menu [toggle] '("Toggle" . gdb-toggle-bp-this-line)) 1330 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1331 (define-key menu [delete] '("Delete" . gdb-delete-bp-this-line)) 1331 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1332 (define-key menu [goto] '("Goto" . gdb-goto-bp-this-line)) 1332 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1333 1333
1334 (suppress-keymap map) 1334 (suppress-keymap map)
1335 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu)) 1335 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1336 (define-key map " " 'gdb-toggle-bp-this-line) 1336 (define-key map " " 'gdb-toggle-breakpoint)
1337 (define-key map "d" 'gdb-delete-bp-this-line) 1337 (define-key map "d" 'gdb-delete-breakpoint)
1338 (define-key map "g" 'gdb-goto-bp-this-line) 1338 (define-key map "\r" 'gdb-goto-breakpoint)
1339 (define-key map [mouse-2] 'gdb-mouse-goto-breakpoint)
1339 map)) 1340 map))
1340 1341
1341 (defun gdb-breakpoints-mode () 1342 (defun gdb-breakpoints-mode ()
1342 "Major mode for gdb breakpoints. 1343 "Major mode for gdb breakpoints.
1343 1344
1346 (setq mode-name "Breakpoints") 1347 (setq mode-name "Breakpoints")
1347 (use-local-map gdb-breakpoints-mode-map) 1348 (use-local-map gdb-breakpoints-mode-map)
1348 (setq buffer-read-only t) 1349 (setq buffer-read-only t)
1349 (gdb-invalidate-breakpoints)) 1350 (gdb-invalidate-breakpoints))
1350 1351
1351 (defun gdb-toggle-bp-this-line () 1352 (defun gdb-toggle-breakpoint ()
1352 "Enable/disable the breakpoint of the current line." 1353 "Enable/disable the breakpoint at current line."
1353 (interactive) 1354 (interactive)
1354 (save-excursion 1355 (save-excursion
1355 (beginning-of-line 1) 1356 (beginning-of-line 1)
1356 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) 1357 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1357 (error "Not recognized as break/watchpoint line") 1358 (error "Not recognized as break/watchpoint line")
1362 "server disable " 1363 "server disable "
1363 "server enable ") 1364 "server enable ")
1364 (match-string 1) "\n") 1365 (match-string 1) "\n")
1365 'ignore))))) 1366 'ignore)))))
1366 1367
1367 (defun gdb-delete-bp-this-line () 1368 (defun gdb-delete-breakpoint ()
1368 "Delete the breakpoint of the current line." 1369 "Delete the breakpoint at current line."
1369 (interactive) 1370 (interactive)
1370 (beginning-of-line 1) 1371 (beginning-of-line 1)
1371 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) 1372 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1372 (error "Not recognized as break/watchpoint line") 1373 (error "Not recognized as break/watchpoint line")
1373 (gdb-enqueue-input 1374 (gdb-enqueue-input
1374 (list (concat "server delete " (match-string 1) "\n") 'ignore)))) 1375 (list (concat "server delete " (match-string 1) "\n") 'ignore))))
1375 1376
1376 (defvar gdb-source-window nil) 1377 (defvar gdb-source-window nil)
1377 1378
1378 (defun gdb-goto-bp-this-line () 1379 (defun gdb-goto-breakpoint ()
1379 "Display the file in the source buffer at the specified breakpoint." 1380 "Display the file in the source buffer at the breakpoint specified on the
1381 current line."
1380 (interactive) 1382 (interactive)
1381 (save-excursion 1383 (save-excursion
1382 (beginning-of-line 1) 1384 (beginning-of-line 1)
1383 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t) 1385 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t)
1384 (looking-at "\\(\\S-*\\):\\([0-9]+\\)")) 1386 (looking-at "\\(\\S-*\\):\\([0-9]+\\)"))
1390 (switch-to-buffer (find-file-noselect 1392 (switch-to-buffer (find-file-noselect
1391 (if (file-exists-p file) 1393 (if (file-exists-p file)
1392 file 1394 file
1393 (expand-file-name file gdb-cdir)))) 1395 (expand-file-name file gdb-cdir))))
1394 (goto-line (string-to-number line)))))) 1396 (goto-line (string-to-number line))))))
1397
1398 (defun gdb-mouse-goto-breakpoint (event)
1399 "Display the file in the source buffer at the selected breakpoint."
1400 (interactive "e")
1401 (mouse-set-point event)
1402 (gdb-goto-breakpoint))
1395 1403
1396 ;; 1404 ;;
1397 ;; Frames buffer. This displays a perpetually correct bactracktrace 1405 ;; Frames buffer. This displays a perpetually correct bactracktrace
1398 ;; (from the command `where'). 1406 ;; (from the command `where').
1399 ;; 1407 ;;
1435 (gdb-get-create-buffer 'gdb-stack-buffer))) 1443 (gdb-get-create-buffer 'gdb-stack-buffer)))
1436 1444
1437 (defvar gdb-frames-mode-map 1445 (defvar gdb-frames-mode-map
1438 (let ((map (make-sparse-keymap))) 1446 (let ((map (make-sparse-keymap)))
1439 (suppress-keymap map) 1447 (suppress-keymap map)
1448 (define-key map "\r" 'gdb-frames-select)
1440 (define-key map [mouse-2] 'gdb-frames-mouse-select) 1449 (define-key map [mouse-2] 'gdb-frames-mouse-select)
1441 map)) 1450 map))
1442 1451
1443 (defun gdb-frames-mode () 1452 (defun gdb-frames-mode ()
1444 "Major mode for gdb frames. 1453 "Major mode for gdb frames.
1451 (gdb-invalidate-frames)) 1460 (gdb-invalidate-frames))
1452 1461
1453 (defun gdb-get-frame-number () 1462 (defun gdb-get-frame-number ()
1454 (save-excursion 1463 (save-excursion
1455 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t)) 1464 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t))
1456 (n (or (and pos (string-to-int (match-string 1))) 0))) 1465 (n (or (and pos (match-string-no-properties 1)) "0")))
1457 n))) 1466 n)))
1458 1467
1459 (defun gdb-frames-mouse-select (e) 1468 (defun gdb-frames-select ()
1460 "Make the selected frame become the current frame and 1469 "Make the frame on the current line become the current frame and display the
1461 display the source in the source buffer." 1470 source in the source buffer."
1471 (interactive)
1472 (gdb-enqueue-input
1473 (list (concat "server frame " (gdb-get-frame-number) "\n") 'ignore))
1474 (gud-display-frame))
1475
1476 (defun gdb-frames-mouse-select (event)
1477 "Make the selected frame become the current frame and display the source in
1478 the source buffer."
1462 (interactive "e") 1479 (interactive "e")
1463 (let (selection) 1480 (mouse-set-point event)
1464 (save-excursion 1481 (gdb-frames-select))
1465 (set-buffer (window-buffer (posn-window (event-end e))))
1466 (save-excursion
1467 (goto-char (posn-point (event-end e)))
1468 (setq selection (gdb-get-frame-number))))
1469 (select-window (posn-window (event-end e)))
1470 (save-excursion
1471 (set-buffer gud-comint-buffer)
1472 (gdb-enqueue-input
1473 (list (gud-format-command "server frame %p\n" selection) 'ignore))
1474 (gud-display-frame))))
1475
1476 1482
1477 ;; 1483 ;;
1478 ;; Registers buffer. 1484 ;; Registers buffer.
1479 ;; 1485 ;;
1480 (gdb-set-buffer-rules 'gdb-registers-buffer 1486 (gdb-set-buffer-rules 'gdb-registers-buffer
1637 (delete-frame frame))))))))))) 1643 (delete-frame frame)))))))))))
1638 1644
1639 (defvar gdb-display-mode-map 1645 (defvar gdb-display-mode-map
1640 (let ((map (make-sparse-keymap)) 1646 (let ((map (make-sparse-keymap))
1641 (menu (make-sparse-keymap "Display"))) 1647 (menu (make-sparse-keymap "Display")))
1642 (define-key menu [toggle] '("Toggle" . gdb-toggle-disp-this-line)) 1648 (define-key menu [toggle] '("Toggle" . gdb-toggle-display))
1643 (define-key menu [delete] '("Delete" . gdb-delete-disp-this-line)) 1649 (define-key menu [delete] '("Delete" . gdb-delete-display))
1644 1650
1645 (suppress-keymap map) 1651 (suppress-keymap map)
1646 (define-key map [menu-bar display] (cons "Display" menu)) 1652 (define-key map [menu-bar display] (cons "Display" menu))
1647 (define-key map " " 'gdb-toggle-disp-this-line) 1653 (define-key map " " 'gdb-toggle-display)
1648 (define-key map "d" 'gdb-delete-disp-this-line) 1654 (define-key map "d" 'gdb-delete-display)
1649 map)) 1655 map))
1650 1656
1651 (defun gdb-display-mode () 1657 (defun gdb-display-mode ()
1652 "Major mode for gdb display. 1658 "Major mode for gdb display.
1653 1659
1670 (defun gdb-frame-display-buffer () 1676 (defun gdb-frame-display-buffer ()
1671 (interactive) 1677 (interactive)
1672 (switch-to-buffer-other-frame 1678 (switch-to-buffer-other-frame
1673 (gdb-get-create-buffer 'gdb-display-buffer))) 1679 (gdb-get-create-buffer 'gdb-display-buffer)))
1674 1680
1675 (defun gdb-toggle-disp-this-line () 1681 (defun gdb-toggle-display ()
1676 "Enable/disable the displayed expression of the current line." 1682 "Enable/disable the displayed expression at current line."
1677 (interactive) 1683 (interactive)
1678 (save-excursion 1684 (save-excursion
1679 (beginning-of-line 1) 1685 (beginning-of-line 1)
1680 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) 1686 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)"))
1681 (error "No expression on this line") 1687 (error "No expression on this line")
1686 "server disable display " 1692 "server disable display "
1687 "server enable display ") 1693 "server enable display ")
1688 (match-string 1) "\n") 1694 (match-string 1) "\n")
1689 'ignore))))) 1695 'ignore)))))
1690 1696
1691 (defun gdb-delete-disp-this-line () 1697 (defun gdb-delete-display ()
1692 "Delete the displayed expression of the current line." 1698 "Delete the displayed expression at current line."
1693 (interactive) 1699 (interactive)
1694 (save-excursion 1700 (save-excursion
1695 (set-buffer 1701 (set-buffer
1696 (gdb-get-buffer 'gdb-display-buffer)) 1702 (gdb-get-buffer 'gdb-display-buffer))
1697 (beginning-of-line 1) 1703 (beginning-of-line 1)
1711 1717
1712 (defvar gdb-expressions-mode-menu 1718 (defvar gdb-expressions-mode-menu
1713 '("GDB Expressions Commands" 1719 '("GDB Expressions Commands"
1714 "----" 1720 "----"
1715 ["Visualise" gdb-array-visualise t] 1721 ["Visualise" gdb-array-visualise t]
1716 ["Delete" gdb-delete-display t]) 1722 ["Delete" gdb-delete-expression t])
1717 "Menu for `gdb-expressions-mode'.") 1723 "Menu for `gdb-expressions-mode'.")
1718 1724
1719 (defun gdb-expressions-popup-menu (event) 1725 (defun gdb-expressions-popup-menu (event)
1720 "Explicit Popup menu as this buffer doesn't have a menubar." 1726 "Explicit Popup menu as this buffer doesn't have a menubar."
1721 (interactive "@e") 1727 (interactive "@e")
1784 (setq answer (split-window largest new-size)) 1790 (setq answer (split-window largest new-size))
1785 (set-window-buffer answer buf))) 1791 (set-window-buffer answer buf)))
1786 answer)) 1792 answer))
1787 1793
1788 (defun gdb-display-source-buffer (buffer) 1794 (defun gdb-display-source-buffer (buffer)
1789 (set-window-buffer gdb-source-window buffer)) 1795 (set-window-buffer gdb-source-window buffer)
1796 gdb-source-window)
1790 1797
1791 1798
1792 ;;; Shared keymap initialization: 1799 ;;; Shared keymap initialization:
1793 1800
1794 (defun gdb-display-gdb-buffer () 1801 (defun gdb-display-gdb-buffer ()
2057 (int-to-string (aref gdb-array-start n)) 2064 (int-to-string (aref gdb-array-start n))
2058 " " 2065 " "
2059 (int-to-string (aref gdb-array-stop n)) 2066 (int-to-string (aref gdb-array-stop n))
2060 " 1 -T X")))))) 2067 " 1 -T X"))))))
2061 2068
2062 (defun gdb-delete-display () 2069 (defun gdb-delete-expression ()
2063 "Delete displayed expression and its frame." 2070 "Delete displayed expression and its frame."
2064 (interactive) 2071 (interactive)
2065 (gdb-enqueue-input 2072 (gdb-enqueue-input
2066 (list (concat "server delete display " gdb-display-number "\n") 2073 (list (concat "server delete display " gdb-display-number "\n")
2067 'ignore))) 2074 'ignore)))