Mercurial > emacs
comparison lisp/gdb-ui.el @ 48884:f774c94b3b5e
(gdba-marker-filter, gdb-output-burst): Merge and
rename gud-gdba-marker-filter.
(gdb-append-to-inferior-io): Only pop up IO buffer if there is
output.
(gdb-make-instance): Remove (put into gdba).
Use gdb-instance-enqueue-input instead of
gdb-instance-enqueue-idle-input for user functions.
(gdb-instance-target-string): Simplify.
(in-gdb-instance-context): Remove.
Expand Commentary.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Tue, 17 Dec 2002 23:40:06 +0000 |
parents | dc51e4b2d5c1 |
children | 3aa5ba679145 |
comparison
equal
deleted
inserted
replaced
48883:2bce492766d6 | 48884:f774c94b3b5e |
---|---|
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 ;; Extension of gdba.el written by Jim Kingdon from gdb 5.0 | 28 ;; This file is based on gdba.el written by Jim Kingdon from GDB 5.0 and uses |
29 ;; GDB's annotation interface. You don't need to know about annotations but | |
30 ;; If you are interested developing this mode see the Annotations section in | |
31 ;; the GDB info manual). | |
32 ;; | |
33 ;; It has been extended to use features of Emacs 21 such as the display | |
34 ;; margin for breakpoints and the toolbar. It also has new buffers and lots | |
35 ;; of other new features such as formatted auto-display of arrays and | |
36 ;; structures (see the GDB-UI in the Emacs info manual). | |
29 | 37 |
30 ;;; Code: | 38 ;;; Code: |
31 | 39 |
32 (require 'gud) | 40 (require 'gud) |
33 | 41 |
92 | 100 |
93 ;; Let's start with a basic gud-gdb buffer and then modify it a bit. | 101 ;; Let's start with a basic gud-gdb buffer and then modify it a bit. |
94 (gdb command-line) | 102 (gdb command-line) |
95 | 103 |
96 (set (make-local-variable 'gud-minor-mode) 'gdba) | 104 (set (make-local-variable 'gud-minor-mode) 'gdba) |
97 (set (make-local-variable 'gud-marker-filter) 'gdba-marker-filter) | 105 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter) |
98 | 106 |
99 (gud-def gud-break (if (not (string-equal mode-name "Assembler")) | 107 (gud-def gud-break (if (not (string-equal mode-name "Assembler")) |
100 (gud-call "break %f:%l" arg) | 108 (gud-call "break %f:%l" arg) |
101 (save-excursion | 109 (save-excursion |
102 (beginning-of-line) | 110 (beginning-of-line) |
118 (setq gdb-main-or-pc "main") | 126 (setq gdb-main-or-pc "main") |
119 (setq gdb-current-address nil) | 127 (setq gdb-current-address nil) |
120 (setq gdb-display-in-progress nil) | 128 (setq gdb-display-in-progress nil) |
121 (setq gdb-dive nil) | 129 (setq gdb-dive nil) |
122 | 130 |
123 (gdb-make-instance) | 131 (mapc 'make-local-variable gdb-instance-variables) |
132 (setq gdb-buffer-type 'gdba) | |
133 | |
124 (gdb-clear-inferior-io) | 134 (gdb-clear-inferior-io) |
125 | 135 |
126 ;; find source file and compilation directory here | 136 ;; find source file and compilation directory here |
127 (gdb-instance-enqueue-idle-input (list "server list\n" 'ignore)) | 137 (gdb-instance-enqueue-input (list "server list\n" 'ignore)) |
128 (gdb-instance-enqueue-idle-input (list "server info source\n" | 138 (gdb-instance-enqueue-input (list "server info source\n" |
129 'gdb-source-info)) | 139 'gdb-source-info)) |
130 | 140 |
131 (run-hooks 'gdba-mode-hook)) | 141 (run-hooks 'gdba-mode-hook)) |
132 | 142 |
133 (defun gud-display () | 143 (defun gud-display () |
134 "Display (possibly dereferenced) C expression at point." | 144 "Display (possibly dereferenced) C expression at point." |
135 (interactive) | 145 (interactive) |
136 (save-excursion | 146 (save-excursion |
137 (let ((expr (gud-find-c-expr))) | 147 (let ((expr (gud-find-c-expr))) |
138 (gdb-instance-enqueue-idle-input | 148 (gdb-instance-enqueue-input |
139 (list (concat "server whatis " expr "\n") | 149 (list (concat "server whatis " expr "\n") |
140 `(lambda () (gud-display1 ,expr))))))) | 150 `(lambda () (gud-display1 ,expr))))))) |
141 | 151 |
142 (defun gud-display1 (expr) | 152 (defun gud-display1 (expr) |
143 (goto-char (point-min)) | 153 (goto-char (point-min)) |
144 (if (re-search-forward "\*" nil t) | 154 (if (re-search-forward "\*" nil t) |
145 (gdb-instance-enqueue-idle-input | 155 (gdb-instance-enqueue-input |
146 (list (concat "server display* " expr "\n") 'ignore)) | 156 (list (concat "server display* " expr "\n") 'ignore)) |
147 (gdb-instance-enqueue-idle-input | 157 (gdb-instance-enqueue-input |
148 (list (concat "server display " expr "\n") 'ignore)))) | 158 (list (concat "server display " expr "\n") 'ignore)))) |
149 | 159 |
150 | 160 |
151 ;; The completion process filter is installed temporarily to slurp the | 161 ;; The completion process filter is installed temporarily to slurp the |
152 ;; output of GDB up to the next prompt and build the completion list. | 162 ;; output of GDB up to the next prompt and build the completion list. |
226 | 236 |
227 (def-gdb-var pending-triggers '() | 237 (def-gdb-var pending-triggers '() |
228 "A list of trigger functions that have run later than their output | 238 "A list of trigger functions that have run later than their output |
229 handlers.") | 239 handlers.") |
230 | 240 |
231 (defun in-gdb-instance-context (form) | 241 ;; end of instance vars |
232 "Funcall FORM in the GUD buffer." | 242 |
243 (defun gdb-instance-target-string () | |
233 (with-current-buffer gud-comint-buffer | 244 (with-current-buffer gud-comint-buffer |
234 (funcall form))) | 245 gud-target-name)) |
235 | |
236 ;; end of instance vars | |
237 | |
238 (defun gdb-make-instance () | |
239 "Create a gdb instance object from the current buffer." | |
240 (mapc 'make-local-variable gdb-instance-variables) | |
241 (setq gdb-buffer-type 'gdba)) | |
242 | |
243 (defun gdb-instance-target-string () | |
244 "The apparent name of the program being debugged by a gdb instance. | |
245 For sure this the root string used in smashing together the gdb | |
246 buffer's name, even if that doesn't happen to be the name of a | |
247 program." | |
248 (in-gdb-instance-context (lambda () gud-target-name))) | |
249 | 246 |
250 | 247 |
251 ;; | 248 ;; |
252 ;; Instance Buffers. | 249 ;; Instance Buffers. |
253 ;; | 250 ;; |
499 | 496 |
500 (defcustom gud-gdba-command-name "gdb -annotate=2" | 497 (defcustom gud-gdba-command-name "gdb -annotate=2" |
501 "Default command to execute an executable under the GDB-UI debugger." | 498 "Default command to execute an executable under the GDB-UI debugger." |
502 :type 'string | 499 :type 'string |
503 :group 'gud) | 500 :group 'gud) |
504 | |
505 (defun gdba-marker-filter (string) | |
506 "A gud marker filter for gdb." | |
507 (gdb-output-burst string)) | |
508 | 501 |
509 (defvar gdb-annotation-rules | 502 (defvar gdb-annotation-rules |
510 '(("frames-invalid" gdb-invalidate-frame-and-assembler) | 503 '(("frames-invalid" gdb-invalidate-frame-and-assembler) |
511 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler) | 504 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler) |
512 ("pre-prompt" gdb-pre-prompt) | 505 ("pre-prompt" gdb-pre-prompt) |
801 'action (lambda (button) (gdb-display-go-back))) | 794 'action (lambda (button) (gdb-display-go-back))) |
802 | 795 |
803 (defun gdb-display-go-back () | 796 (defun gdb-display-go-back () |
804 ;; delete display so they don't accumulate and delete buffer | 797 ;; delete display so they don't accumulate and delete buffer |
805 (let ((number gdb-display-number)) | 798 (let ((number gdb-display-number)) |
806 (gdb-instance-enqueue-idle-input | 799 (gdb-instance-enqueue-input |
807 (list (concat "server delete display " number "\n") 'ignore)) | 800 (list (concat "server delete display " number "\n") 'ignore)) |
808 (switch-to-buffer (concat "*display " gdb-dive-display-number "*")) | 801 (switch-to-buffer (concat "*display " gdb-dive-display-number "*")) |
809 (kill-buffer (get-buffer (concat "*display " number "*"))))) | 802 (kill-buffer (get-buffer (concat "*display " number "*"))))) |
810 | 803 |
811 ;; prefix annotations with ## and process whole output in one chunk | 804 ;; prefix annotations with ## and process whole output in one chunk |
909 ;; * not needed for components of a pointer to a structure in gdb | 902 ;; * not needed for components of a pointer to a structure in gdb |
910 (if (string-equal "*" (substring gdb-full-expression 0 1)) | 903 (if (string-equal "*" (substring gdb-full-expression 0 1)) |
911 (setq gdb-full-expression (substring gdb-full-expression 1 nil))) | 904 (setq gdb-full-expression (substring gdb-full-expression 1 nil))) |
912 (setq gdb-full-expression | 905 (setq gdb-full-expression |
913 (concat gdb-full-expression gdb-part-expression "." gdb-last-field)) | 906 (concat gdb-full-expression gdb-part-expression "." gdb-last-field)) |
914 (gdb-instance-enqueue-idle-input | 907 (gdb-instance-enqueue-input |
915 (list (concat "server display" gdb-display-char | 908 (list (concat "server display" gdb-display-char |
916 " " gdb-full-expression "\n") | 909 " " gdb-full-expression "\n") |
917 'ignore))))) | 910 'ignore))))) |
918 | 911 |
919 (defun gdb-insert-field () | 912 (defun gdb-insert-field () |
1061 (setq num (+ num 1))) | 1054 (setq num (+ num 1))) |
1062 (insert | 1055 (insert |
1063 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n")))) | 1056 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n")))) |
1064 (setq buffer-read-only t)) | 1057 (setq buffer-read-only t)) |
1065 | 1058 |
1066 ;; Handle a burst of output from a gdb instance. | 1059 (defun gud-gdba-marker-filter (string) |
1067 ;; This function is (indirectly) used as a gud-marker-filter. | 1060 "A gud marker filter for gdb. Handle a burst of output from a gdb instance. |
1068 ;; It must return output (if any) to be inserted in the gdb | 1061 It must return output (if any) to be insterted in the gdb buffer." |
1069 ;; buffer. | |
1070 | |
1071 (defun gdb-output-burst (string) | |
1072 "Handle a burst of output from a gdb instance. | |
1073 This function is (indirectly) used as a gud-marker-filter. | |
1074 It must return output (if any) to be insterted in the gdb | |
1075 buffer." | |
1076 (save-match-data | 1062 (save-match-data |
1077 (let ( | 1063 (let ( |
1078 ;; Recall the left over burst from last time | 1064 ;; Recall the left over burst from last time |
1079 (burst (concat (gdb-instance-burst) string)) | 1065 (burst (concat (gdb-instance-burst) string)) |
1080 ;; Start accumulating output for the GUD buffer | 1066 ;; Start accumulating output for the GUD buffer |
1162 (save-excursion | 1148 (save-excursion |
1163 (set-buffer | 1149 (set-buffer |
1164 (gdb-get-create-instance-buffer 'gdb-inferior-io)) | 1150 (gdb-get-create-instance-buffer 'gdb-inferior-io)) |
1165 (goto-char (point-max)) | 1151 (goto-char (point-max)) |
1166 (insert-before-markers string)) | 1152 (insert-before-markers string)) |
1167 (gdb-display-buffer | 1153 (if (not (string-equal string "")) |
1168 (gdb-get-create-instance-buffer 'gdb-inferior-io))) | 1154 (gdb-display-buffer |
1155 (gdb-get-create-instance-buffer 'gdb-inferior-io)))) | |
1169 | 1156 |
1170 (defun gdb-clear-inferior-io () | 1157 (defun gdb-clear-inferior-io () |
1171 (save-excursion | 1158 (save-excursion |
1172 (set-buffer | 1159 (set-buffer |
1173 (gdb-get-create-instance-buffer 'gdb-inferior-io)) | 1160 (gdb-get-create-instance-buffer 'gdb-inferior-io)) |
1389 (interactive) | 1376 (interactive) |
1390 (save-excursion | 1377 (save-excursion |
1391 (beginning-of-line 1) | 1378 (beginning-of-line 1) |
1392 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | 1379 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) |
1393 (error "Not recognized as break/watchpoint line") | 1380 (error "Not recognized as break/watchpoint line") |
1394 (gdb-instance-enqueue-idle-input | 1381 (gdb-instance-enqueue-input |
1395 (list | 1382 (list |
1396 (concat | 1383 (concat |
1397 (if (eq ?y (char-after (match-beginning 2))) | 1384 (if (eq ?y (char-after (match-beginning 2))) |
1398 "server disable " | 1385 "server disable " |
1399 "server enable ") | 1386 "server enable ") |
1405 "Delete the breakpoint of the current line." | 1392 "Delete the breakpoint of the current line." |
1406 (interactive) | 1393 (interactive) |
1407 (beginning-of-line 1) | 1394 (beginning-of-line 1) |
1408 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | 1395 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) |
1409 (error "Not recognized as break/watchpoint line") | 1396 (error "Not recognized as break/watchpoint line") |
1410 (gdb-instance-enqueue-idle-input | 1397 (gdb-instance-enqueue-input |
1411 (list | 1398 (list (concat "server delete " (match-string 1) "\n") 'ignore)))) |
1412 (concat | |
1413 "server delete " | |
1414 (match-string 1) | |
1415 "\n") | |
1416 'ignore)))) | |
1417 | 1399 |
1418 (defvar gdb-source-window nil) | 1400 (defvar gdb-source-window nil) |
1419 | 1401 |
1420 (defun gdb-goto-bp-this-line () | 1402 (defun gdb-goto-bp-this-line () |
1421 "Display the file in the source buffer at the specified breakpoint." | 1403 "Display the file in the source buffer at the specified breakpoint." |
1513 (goto-char (posn-point (event-end e))) | 1495 (goto-char (posn-point (event-end e))) |
1514 (setq selection (gdb-get-frame-number)))) | 1496 (setq selection (gdb-get-frame-number)))) |
1515 (select-window (posn-window (event-end e))) | 1497 (select-window (posn-window (event-end e))) |
1516 (save-excursion | 1498 (save-excursion |
1517 (set-buffer gud-comint-buffer) | 1499 (set-buffer gud-comint-buffer) |
1518 (gdb-instance-enqueue-idle-input | 1500 (gdb-instance-enqueue-input |
1519 (list (gud-format-command "server frame %p\n" selection) | 1501 (list (gud-format-command "server frame %p\n" selection) |
1520 'ignore)) | 1502 'ignore)) |
1521 (gud-display-frame)))) | 1503 (gud-display-frame)))) |
1522 | 1504 |
1523 | 1505 |
1700 (interactive) | 1682 (interactive) |
1701 (save-excursion | 1683 (save-excursion |
1702 (beginning-of-line 1) | 1684 (beginning-of-line 1) |
1703 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) | 1685 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) |
1704 (error "No expression on this line") | 1686 (error "No expression on this line") |
1705 (gdb-instance-enqueue-idle-input | 1687 (gdb-instance-enqueue-input |
1706 (list | 1688 (list |
1707 (concat | 1689 (concat |
1708 (if (eq ?y (char-after (match-beginning 2))) | 1690 (if (eq ?y (char-after (match-beginning 2))) |
1709 "server disable display " | 1691 "server disable display " |
1710 "server enable display ") | 1692 "server enable display ") |
1720 (gdb-get-instance-buffer 'gdb-display-buffer)) | 1702 (gdb-get-instance-buffer 'gdb-display-buffer)) |
1721 (beginning-of-line 1) | 1703 (beginning-of-line 1) |
1722 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) | 1704 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) |
1723 (error "No expression on this line") | 1705 (error "No expression on this line") |
1724 (let ((number (match-string 1))) | 1706 (let ((number (match-string 1))) |
1725 (gdb-instance-enqueue-idle-input | 1707 (gdb-instance-enqueue-input |
1726 (list (concat "server delete display " number "\n") | 1708 (list (concat "server delete display " number "\n") |
1727 'ignore)) | 1709 'ignore)) |
1728 (if (not (display-graphic-p)) | 1710 (if (not (display-graphic-p)) |
1729 (kill-buffer (get-buffer (concat "*display " number "*"))) | 1711 (kill-buffer (get-buffer (concat "*display " number "*"))) |
1730 (catch 'frame-found | 1712 (catch 'frame-found |
2097 " 1 -T X")))))) | 2079 " 1 -T X")))))) |
2098 | 2080 |
2099 (defun gdb-delete-display () | 2081 (defun gdb-delete-display () |
2100 "Delete displayed expression and its frame." | 2082 "Delete displayed expression and its frame." |
2101 (interactive) | 2083 (interactive) |
2102 (gdb-instance-enqueue-idle-input | 2084 (gdb-instance-enqueue-input |
2103 (list (concat "server delete display " gdb-display-number "\n") | 2085 (list (concat "server delete display " gdb-display-number "\n") |
2104 'ignore)) | 2086 'ignore)) |
2105 (kill-buffer nil) | 2087 (kill-buffer nil) |
2106 (delete-frame)) | 2088 (delete-frame)) |
2107 | 2089 |