comparison lisp/gdb-ui.el @ 48682:a74dd42cf01d

(gud-gdb-complete-string, gud-gdb-complete-break) (gud-gdb-complete-list, gud-gdb-complete-in-progress): Remove. (gdba): Call `gdb' and then make modifications. Always call gdb-clear-inferior-io rather than just "the first time". (gud-break, gud-remove): Definitions moved to inside gdba. (gdb-target-name): Remove. Use gud-target-name instead. (gdba-complete-filter, gdba-common-init): Remove. The changes were integrated into the generic code.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 05 Dec 2002 17:03:06 +0000
parents d29870d63092
children 19bf840bede8
comparison
equal deleted inserted replaced
48681:bc8dd5e93ecd 48682:a74dd42cf01d
35 (defvar gdb-current-address nil) 35 (defvar gdb-current-address nil)
36 (defvar gdb-display-in-progress nil) 36 (defvar gdb-display-in-progress nil)
37 (defvar gdb-dive nil) 37 (defvar gdb-dive nil)
38 (defvar gdb-first-time nil) 38 (defvar gdb-first-time nil)
39 (defvar gdb-proc nil "The process associated with gdb.") 39 (defvar gdb-proc nil "The process associated with gdb.")
40
41 ;; Dynamically-bound vars in gud.el
42 (defvar gud-gdb-complete-string)
43 (defvar gud-gdb-complete-break)
44 (defvar gud-gdb-complete-list)
45 (defvar gud-gdb-complete-in-progress)
46 40
47 ;;;###autoload 41 ;;;###autoload
48 (defun gdba (command-line) 42 (defun gdba (command-line)
49 "Run gdb on program FILE in buffer *gdb-FILE*. 43 "Run gdb on program FILE in buffer *gdb-FILE*.
50 The directory containing FILE becomes the initial working directory 44 The directory containing FILE becomes the initial working directory
94 `gdb-restore-windows' - to restore the layout if its lost. 88 `gdb-restore-windows' - to restore the layout if its lost.
95 `gdb-quit' - to delete (most) of the buffers used by gdb." 89 `gdb-quit' - to delete (most) of the buffers used by gdb."
96 90
97 (interactive (list (gud-query-cmdline 'gdba))) 91 (interactive (list (gud-query-cmdline 'gdba)))
98 92
99 (gdba-common-init command-line nil 'gdba-marker-filter) 93 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
94 (gdb command-line)
100 95
101 (set (make-local-variable 'gud-minor-mode) 'gdba) 96 (set (make-local-variable 'gud-minor-mode) 'gdba)
102 97 (set (make-local-variable 'gud-marker-filter) 'gdba-marker-filter)
103 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set breakpoint at current line.") 98
104 (gud-def gud-run "run" nil "Run the program.") 99 (gud-def gud-break (if (not (string-equal mode-name "Assembler"))
105 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.") 100 (gud-call "break %f:%l" arg)
106 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.") 101 (save-excursion
107 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).") 102 (beginning-of-line)
108 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.") 103 (forward-char 2)
109 (gud-def gud-cont "cont" "\C-r" "Continue with display.") 104 (gud-call "break *%a" arg)))
110 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") 105 "\C-b" "Set breakpoint at current line or address.")
111 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") 106
112 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.") 107 (gud-def gud-remove (if (not (string-equal mode-name "Assembler"))
113 (gud-def gud-goto "until %f:%l" "\C-u" "Continue up to current line.") 108 (gud-call "clear %f:%l" arg)
114 109 (save-excursion
115 (define-key gud-mode-map "\C-c\C-b" 'gud-break) 110 (beginning-of-line)
116 (define-key global-map "\C-x\C-a\C-b" 'gud-break) 111 (forward-char 2)
117 112 (gud-call "clear *%a" arg)))
118 (define-key gud-mode-map "\C-c\C-d" 'gud-remove) 113 "\C-d" "Remove breakpoint at current line or address.")
119 (define-key global-map "\C-x\C-a\C-d" 'gud-remove) 114
120
121 (local-set-key "\C-i" 'gud-gdb-complete-command)
122
123 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
124 (setq comint-input-sender 'gdb-send) 115 (setq comint-input-sender 'gdb-send)
125 116
126 ;; (re-)initialise 117 ;; (re-)initialise
127 (setq gdb-main-or-pc "main") 118 (setq gdb-main-or-pc "main")
128 (setq gdb-current-address nil) 119 (setq gdb-current-address nil)
129 (setq gdb-display-in-progress nil) 120 (setq gdb-display-in-progress nil)
130 (setq gdb-dive nil) 121 (setq gdb-dive nil)
131 (setq gud-last-last-frame nil) 122
132 (setq gud-running nil)
133
134 (run-hooks 'gdb-mode-hook)
135 (setq gdb-proc (get-buffer-process (current-buffer))) 123 (setq gdb-proc (get-buffer-process (current-buffer)))
136 (gdb-make-instance) 124 (gdb-make-instance)
137 (if gdb-first-time (gdb-clear-inferior-io)) 125 (gdb-clear-inferior-io)
138 126
139 ;; find source file and compilation directory here 127 ;; find source file and compilation directory here
140 (gdb-instance-enqueue-idle-input (list "server list\n" 'ignore)) 128 (gdb-instance-enqueue-idle-input (list "server list\n" 'ignore))
141 (gdb-instance-enqueue-idle-input (list "server info source\n" 129 (gdb-instance-enqueue-idle-input (list "server info source\n"
142 'gdb-source-info))) 130 'gdb-source-info))
143 131
144 (defun gud-break (arg) 132 (run-hooks 'gdba-mode-hook))
145 "Set breakpoint at current line or address."
146 (interactive "p")
147 (if (not (string-equal mode-name "Assembler"))
148 (gud-call "break %f:%l" arg)
149 (save-excursion
150 (beginning-of-line)
151 (forward-char 2)
152 (gud-call "break *%a" arg))))
153
154 (defun gud-remove (arg)
155 "Remove breakpoint at current line or address."
156 (interactive "p")
157 (if (not (string-equal mode-name "Assembler"))
158 (gud-call "clear %f:%l" arg)
159 (save-excursion
160 (beginning-of-line)
161 (forward-char 2)
162 (gud-call "clear *%a" arg))))
163 133
164 (defun gud-display () 134 (defun gud-display ()
165 "Display (possibly dereferenced) C expression at point." 135 "Display (possibly dereferenced) C expression at point."
166 (interactive) 136 (interactive)
167 (save-excursion 137 (save-excursion
170 (list (concat "server whatis " expr "\n") 140 (list (concat "server whatis " expr "\n")
171 `(lambda () (gud-display1 ,expr))))))) 141 `(lambda () (gud-display1 ,expr)))))))
172 142
173 (defun gud-display1 (expr) 143 (defun gud-display1 (expr)
174 (goto-char (point-min)) 144 (goto-char (point-min))
175 (if (re-search-forward "\*" nil t) 145 (if (re-search-forward "\*" nil t)
176 (gdb-instance-enqueue-idle-input
177 (list (concat "server display* " expr "\n") 'ignore))
178 (gdb-instance-enqueue-idle-input 146 (gdb-instance-enqueue-idle-input
179 (list (concat "server display " expr "\n") 'ignore)))) 147 (list (concat "server display* " expr "\n") 'ignore))
148 (gdb-instance-enqueue-idle-input
149 (list (concat "server display " expr "\n") 'ignore))))
180 150
181 151
182 ;; The completion process filter is installed temporarily to slurp the 152 ;; The completion process filter is installed temporarily to slurp the
183 ;; output of GDB up to the next prompt and build the completion list. 153 ;; output of GDB up to the next prompt and build the completion list.
184 ;; It must also handle annotations. 154 ;; It must also handle annotations.
185 (defun gdba-complete-filter (string)
186 (gdb-output-burst string)
187 (while (string-match "\n\032\032\\(.*\\)\n" string)
188 (setq string (concat (substring string 0 (match-beginning 0))
189 (substring string (match-end 0)))))
190 (setq string (concat gud-gdb-complete-string string))
191 (while (string-match "\n" string)
192 (setq gud-gdb-complete-list
193 (cons (substring string gud-gdb-complete-break (match-beginning 0))
194 gud-gdb-complete-list))
195 (setq string (substring string (match-end 0))))
196 (if (string-match comint-prompt-regexp string)
197 (progn
198 (setq gud-gdb-complete-in-progress nil)
199 string)
200 (progn
201 (setq gud-gdb-complete-string string)
202 "")))
203
204 (defvar gdb-target-name "--unknown--"
205 "The apparent name of the program being debugged in a gud buffer.")
206
207 (defun gdba-common-init (command-line massage-args marker-filter &optional find-file)
208
209 (let* ((words (split-string command-line))
210 (program (car words))
211
212 ;; Extract the file name from WORDS
213 ;; and put t in its place.
214 ;; Later on we will put the modified file name arg back there.
215 (file-word (let ((w (cdr words)))
216 (while (and w (= ?- (aref (car w) 0)))
217 (setq w (cdr w)))
218 (and w
219 (prog1 (car w)
220 (setcar w t)))))
221 (file-subst
222 (and file-word (substitute-in-file-name file-word)))
223
224 (args (cdr words))
225
226 ;; If a directory was specified, expand the file name.
227 ;; Otherwise, don't expand it, so GDB can use the PATH.
228 ;; A file name without directory is literally valid
229 ;; only if the file exists in ., and in that case,
230 ;; omitting the expansion here has no visible effect.
231 (file (and file-word
232 (if (file-name-directory file-subst)
233 (expand-file-name file-subst)
234 file-subst)))
235 (filepart (and file-word (file-name-nondirectory file)))
236 (buffer-name (concat "*gdb-" filepart "*")))
237
238 (setq gdb-first-time (not (get-buffer-process buffer-name)))
239
240 (switch-to-buffer buffer-name)
241 ;; Set default-directory to the file's directory.
242 (and file-word
243 gud-chdir-before-run
244 ;; Don't set default-directory if no directory was specified.
245 ;; In that case, either the file is found in the current directory,
246 ;; in which case this setq is a no-op,
247 ;; or it is found by searching PATH,
248 ;; in which case we don't know what directory it was found in.
249 (file-name-directory file)
250 (setq default-directory (file-name-directory file)))
251 (or (bolp) (newline))
252 (insert "Current directory is " default-directory "\n")
253 ;; Put the substituted and expanded file name back in its place.
254 (let ((w args))
255 (while (and w (not (eq (car w) t)))
256 (setq w (cdr w)))
257 (if w
258 (setcar w file)))
259 (apply 'make-comint (concat "gdb-" filepart) program nil args)
260 (gud-mode)
261 (setq gdb-target-name filepart))
262 (make-local-variable 'gud-marker-filter)
263 (setq gud-marker-filter marker-filter)
264 (if find-file (set (make-local-variable 'gud-find-file) find-file))
265
266 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
267 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
268 (gud-set-buffer))
269 155
270 156
271 ;; ====================================================================== 157 ;; ======================================================================
272 ;; 158 ;;
273 ;; In this world, there are gdb instance objects (of unspecified 159 ;; In this world, there are gdb instance objects (of unspecified
356 ;; end of instance vars 242 ;; end of instance vars
357 243
358 (defun gdb-make-instance () 244 (defun gdb-make-instance ()
359 "Create a gdb instance object from a gdb process." 245 "Create a gdb instance object from a gdb process."
360 (with-current-buffer (process-buffer gdb-proc) 246 (with-current-buffer (process-buffer gdb-proc)
361 (progn 247 (mapc 'make-local-variable gdb-instance-variables)
362 (mapc 'make-local-variable gdb-instance-variables) 248 (setq gdb-buffer-type 'gdba)))
363 (setq gdb-buffer-type 'gdba))))
364 249
365 (defun gdb-instance-target-string () 250 (defun gdb-instance-target-string ()
366 "The apparent name of the program being debugged by a gdb instance. 251 "The apparent name of the program being debugged by a gdb instance.
367 For sure this the root string used in smashing together the gdb 252 For sure this the root string used in smashing together the gdb
368 buffer's name, even if that doesn't happen to be the name of a 253 buffer's name, even if that doesn't happen to be the name of a
369 program." 254 program."
370 (in-gdb-instance-context 255 (in-gdb-instance-context (lambda () gud-target-name)))
371 (function (lambda () gdb-target-name))))
372 256
373 257
374 ;; 258 ;;
375 ;; Instance Buffers. 259 ;; Instance Buffers.
376 ;; 260 ;;
619 ;; line number and various useless goo. This data must not include 503 ;; line number and various useless goo. This data must not include
620 ;; any newlines. 504 ;; any newlines.
621 ;; 505 ;;
622 506
623 (defcustom gud-gdba-command-name "gdb -annotate=2" 507 (defcustom gud-gdba-command-name "gdb -annotate=2"
624 "Default command to execute an executable under the GDB debugger (gdb-ui.el)." 508 "Default command to execute an executable under the GDB-UI debugger."
625 :type 'string 509 :type 'string
626 :group 'gud) 510 :group 'gud)
627 511
628 (defun gdba-marker-filter (string) 512 (defun gdba-marker-filter (string)
629 "A gud marker filter for gdb." 513 "A gud marker filter for gdb."
630 ;; Bogons don't tell us the process except through scoping crud.
631 (gdb-output-burst string)) 514 (gdb-output-burst string))
632 515
633 (defvar gdb-annotation-rules 516 (defvar gdb-annotation-rules
634 '(("frames-invalid" gdb-invalidate-frame-and-assembler) 517 '(("frames-invalid" gdb-invalidate-frame-and-assembler)
635 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler) 518 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler)
1909 ;;;; Window management 1792 ;;;; Window management
1910 1793
1911 ;;; FIXME: This should only return true for buffers in the current gdb-proc 1794 ;;; FIXME: This should only return true for buffers in the current gdb-proc
1912 (defun gdb-protected-buffer-p (buffer) 1795 (defun gdb-protected-buffer-p (buffer)
1913 "Is BUFFER a buffer which we want to leave displayed?" 1796 "Is BUFFER a buffer which we want to leave displayed?"
1914 (save-excursion 1797 (with-current-buffer buffer
1915 (set-buffer buffer) 1798 (or gdb-buffer-type overlay-arrow-position)))
1916 (or gdb-buffer-type
1917 overlay-arrow-position)))
1918 1799
1919 ;;; The way we abuse the dedicated-p flag is pretty gross, but seems 1800 ;;; The way we abuse the dedicated-p flag is pretty gross, but seems
1920 ;;; to do the right thing. Seeing as there is no way for Lisp code to 1801 ;;; to do the right thing. Seeing as there is no way for Lisp code to
1921 ;;; get at the use_time field of a window, I'm not sure there exists a 1802 ;;; get at the use_time field of a window, I'm not sure there exists a
1922 ;;; more elegant solution without writing C code. 1803 ;;; more elegant solution without writing C code.
1965 (define-key gud-minor-mode-map "\C-c\M-\C-r" 'gdb-display-registers-buffer) 1846 (define-key gud-minor-mode-map "\C-c\M-\C-r" 'gdb-display-registers-buffer)
1966 (define-key gud-minor-mode-map "\C-c\M-\C-f" 'gdb-display-stack-buffer) 1847 (define-key gud-minor-mode-map "\C-c\M-\C-f" 'gdb-display-stack-buffer)
1967 (define-key gud-minor-mode-map "\C-c\M-\C-b" 'gdb-display-breakpoints-buffer) 1848 (define-key gud-minor-mode-map "\C-c\M-\C-b" 'gdb-display-breakpoints-buffer)
1968 1849
1969 (let ((menu (make-sparse-keymap "GDB-Windows"))) 1850 (let ((menu (make-sparse-keymap "GDB-Windows")))
1970 (define-key gud-minor-mode-map [menu-bar debug displays] 1851 (define-key gud-menu-map [displays]
1971 `(menu-item "GDB-Windows" ,menu :visible (memq gud-minor-mode '(gdba)))) 1852 `(menu-item "GDB-Windows" ,menu :visible (memq gud-minor-mode '(gdba))))
1972 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer)) 1853 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
1973 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer)) 1854 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
1974 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer)) 1855 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
1975 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)) 1856 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
1981 (interactive) 1862 (interactive)
1982 (switch-to-buffer-other-frame 1863 (switch-to-buffer-other-frame
1983 (gdb-get-create-instance-buffer 'gdba))) 1864 (gdb-get-create-instance-buffer 'gdba)))
1984 1865
1985 (let ((menu (make-sparse-keymap "GDB-Frames"))) 1866 (let ((menu (make-sparse-keymap "GDB-Frames")))
1986 (define-key gud-minor-mode-map [menu-bar debug frames] 1867 (define-key gud-menu-map [frames]
1987 `(menu-item "GDB-Frames" ,menu :visible (memq gud-minor-mode '(gdba)))) 1868 `(menu-item "GDB-Frames" ,menu :visible (memq gud-minor-mode '(gdba))))
1988 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer)) 1869 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
1989 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer)) 1870 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
1990 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer)) 1871 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
1991 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)) 1872 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))