Mercurial > emacs
comparison lisp/gud.el @ 4092:e72012acb5fb
(gud-debugger-startup): Replaced with gud-massage-args.
(gud-{gdb,sdb,xdb}-debugger-startup): Replaced with gud-*-massage-args.
(gdb, sdb, xdb): Argument is command line, not args for it. Remove
debugger name from prompt and put it in the default input instead.
Overload gud-massage-args instead of gud-debugger-startup.
(gud-chop-words): New function; subr for gud-common-init.
(gud-common-init): Argument is command line, not args for it.
Rewritten to use gud-chop-words instead of temp buffer and kludge involving
read. Find the program name as the first word of the command line.
Use make-comint and gud-massage-args in place of gud-debugger-startup.
Expand the file name before passing it to gud-massage-args.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Thu, 15 Jul 1993 01:55:13 +0000 |
parents | 27d35763dda9 |
children | 2455c90e1371 |
comparison
equal
deleted
inserted
replaced
4091:51d19cce579f | 4092:e72012acb5fb |
---|---|
55 (ORIGINAL-FUNCTION-NAME OVERLOAD-FUNCTION)" | 55 (ORIGINAL-FUNCTION-NAME OVERLOAD-FUNCTION)" |
56 (mapcar | 56 (mapcar |
57 (function (lambda (p) (fset (car p) (symbol-function (cdr p))))) | 57 (function (lambda (p) (fset (car p) (symbol-function (cdr p))))) |
58 gud-overload-alist)) | 58 gud-overload-alist)) |
59 | 59 |
60 (defun gud-debugger-startup (file args) | 60 (defun gud-massage-args (file args) |
61 (error "GUD not properly entered.")) | 61 (error "GUD not properly entered.")) |
62 | 62 |
63 (defun gud-marker-filter (str) | 63 (defun gud-marker-filter (str) |
64 (error "GUD not properly entered.")) | 64 (error "GUD not properly entered.")) |
65 | 65 |
126 ;; | 126 ;; |
127 ;; Each entry must define the following at startup: | 127 ;; Each entry must define the following at startup: |
128 ;; | 128 ;; |
129 ;;<name> | 129 ;;<name> |
130 ;; comint-prompt-regexp | 130 ;; comint-prompt-regexp |
131 ;; gud-<name>-debugger-startup | 131 ;; gud-<name>-massage-args |
132 ;; gud-<name>-marker-filter | 132 ;; gud-<name>-marker-filter |
133 ;; gud-<name>-find-file | 133 ;; gud-<name>-find-file |
134 ;; | 134 ;; |
135 ;; The job of the startup-command method is to fire up a copy of the debugger, | 135 ;; The job of the massage-args method is to modify the given list of |
136 ;; given a list of debugger arguments. | 136 ;; debugger arguments before running the debugger. |
137 ;; | 137 ;; |
138 ;; The job of the marker-filter method is to detect file/line markers in | 138 ;; The job of the marker-filter method is to detect file/line markers in |
139 ;; strings and set the global gud-last-frame to indicate what display | 139 ;; strings and set the global gud-last-frame to indicate what display |
140 ;; action (if any) should be triggered by the marker. Note that only | 140 ;; action (if any) should be triggered by the marker. Note that only |
141 ;; whatever the method *returns* is displayed in the buffer; thus, you | 141 ;; whatever the method *returns* is displayed in the buffer; thus, you |
150 ;; gdb functions | 150 ;; gdb functions |
151 | 151 |
152 ;;; History of argument lists passed to gdb. | 152 ;;; History of argument lists passed to gdb. |
153 (defvar gud-gdb-history nil) | 153 (defvar gud-gdb-history nil) |
154 | 154 |
155 (defun gud-gdb-debugger-startup (file args) | 155 (defun gud-gdb-massage-args (file args) |
156 (apply 'make-comint (concat "gud-" file) "gdb" nil "-fullname" args)) | 156 (cons "-fullname" (cons file args))) |
157 | 157 |
158 (defun gud-gdb-marker-filter (string) | 158 (defun gud-gdb-marker-filter (string) |
159 (if (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n" string) | 159 (if (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n" string) |
160 (progn | 160 (progn |
161 (setq gud-last-frame | 161 (setq gud-last-frame |
173 | 173 |
174 (defun gud-gdb-find-file (f) | 174 (defun gud-gdb-find-file (f) |
175 (find-file-noselect f)) | 175 (find-file-noselect f)) |
176 | 176 |
177 ;;;###autoload | 177 ;;;###autoload |
178 (defun gdb (args) | 178 (defun gdb (command-line) |
179 "Run gdb on program FILE in buffer *gud-FILE*. | 179 "Run gdb on program FILE in buffer *gud-FILE*. |
180 The directory containing FILE becomes the initial working directory | 180 The directory containing FILE becomes the initial working directory |
181 and source-file directory for your debugger." | 181 and source-file directory for your debugger." |
182 (interactive | 182 (interactive |
183 (list (read-from-minibuffer "Run gdb (like this): gdb " | 183 (list (read-from-minibuffer "Run gdb (like this): " |
184 (if (consp gud-gdb-history) | 184 (if (consp gud-gdb-history) |
185 (car gud-gdb-history) | 185 (car gud-gdb-history) |
186 "") | 186 "gdb ") |
187 nil nil | 187 nil nil |
188 '(gud-gdb-history . 1)))) | 188 '(gud-gdb-history . 1)))) |
189 (gud-overload-functions '((gud-debugger-startup . gud-gdb-debugger-startup) | 189 (gud-overload-functions '((gud-massage-args . gud-gdb-massage-args) |
190 (gud-marker-filter . gud-gdb-marker-filter) | 190 (gud-marker-filter . gud-gdb-marker-filter) |
191 (gud-find-file . gud-gdb-find-file) | 191 (gud-find-file . gud-gdb-find-file) |
192 )) | 192 )) |
193 | 193 |
194 (gud-common-init args) | 194 (gud-common-init command-line) |
195 | 195 |
196 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.") | 196 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.") |
197 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set breakpoint at current line.") | 197 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set breakpoint at current line.") |
198 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") | 198 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") |
199 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.") | 199 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.") |
219 (defvar gud-sdb-needs-tags (not (file-exists-p "/var")) | 219 (defvar gud-sdb-needs-tags (not (file-exists-p "/var")) |
220 "If nil, we're on a System V Release 4 and don't need the tags hack.") | 220 "If nil, we're on a System V Release 4 and don't need the tags hack.") |
221 | 221 |
222 (defvar gud-sdb-lastfile nil) | 222 (defvar gud-sdb-lastfile nil) |
223 | 223 |
224 (defun gud-sdb-debugger-startup (file args) | 224 (defun gud-sdb-massage-args (file args) |
225 (apply 'make-comint (concat "gud-" file) "sdb" nil args)) | 225 (cons file args)) |
226 | 226 |
227 (defun gud-sdb-marker-filter (string) | 227 (defun gud-sdb-marker-filter (string) |
228 (cond | 228 (cond |
229 ;; System V Release 3.2 uses this format | 229 ;; System V Release 3.2 uses this format |
230 ((string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n" | 230 ((string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n" |
253 (if gud-sdb-needs-tags | 253 (if gud-sdb-needs-tags |
254 (find-tag-noselect f) | 254 (find-tag-noselect f) |
255 (find-file-noselect f))) | 255 (find-file-noselect f))) |
256 | 256 |
257 ;;;###autoload | 257 ;;;###autoload |
258 (defun sdb (args) | 258 (defun sdb (command-line) |
259 "Run sdb on program FILE in buffer *gud-FILE*. | 259 "Run sdb on program FILE in buffer *gud-FILE*. |
260 The directory containing FILE becomes the initial working directory | 260 The directory containing FILE becomes the initial working directory |
261 and source-file directory for your debugger." | 261 and source-file directory for your debugger." |
262 (interactive | 262 (interactive |
263 (list (read-from-minibuffer "Run sdb (like this): sdb " | 263 (list (read-from-minibuffer "Run sdb (like this): " |
264 (if (consp gud-sdb-history) | 264 (if (consp gud-sdb-history) |
265 (car gud-sdb-history) | 265 (car gud-sdb-history) |
266 "") | 266 "sdb ") |
267 nil nil | 267 nil nil |
268 '(gud-sdb-history . 1)))) | 268 '(gud-sdb-history . 1)))) |
269 (if (and gud-sdb-needs-tags | 269 (if (and gud-sdb-needs-tags |
270 (not (and (boundp 'tags-file-name) (file-exists-p tags-file-name)))) | 270 (not (and (boundp 'tags-file-name) (file-exists-p tags-file-name)))) |
271 (error "The sdb support requires a valid tags table to work.")) | 271 (error "The sdb support requires a valid tags table to work.")) |
272 (gud-overload-functions '((gud-debugger-startup . gud-sdb-debugger-startup) | 272 (gud-overload-functions '((gud-massage-args . gud-sdb-massage-args) |
273 (gud-marker-filter . gud-sdb-marker-filter) | 273 (gud-marker-filter . gud-sdb-marker-filter) |
274 (gud-find-file . gud-sdb-find-file) | 274 (gud-find-file . gud-sdb-find-file) |
275 )) | 275 )) |
276 | 276 |
277 (gud-common-init args) | 277 (gud-common-init command-line) |
278 | 278 |
279 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.") | 279 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.") |
280 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.") | 280 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.") |
281 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line") | 281 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line") |
282 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.") | 282 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.") |
293 ;; dbx functions | 293 ;; dbx functions |
294 | 294 |
295 ;;; History of argument lists passed to dbx. | 295 ;;; History of argument lists passed to dbx. |
296 (defvar gud-dbx-history nil) | 296 (defvar gud-dbx-history nil) |
297 | 297 |
298 (defun gud-dbx-debugger-startup (file args) | 298 (defun gud-dbx-massage-args (file args) |
299 (apply 'make-comint (concat "gud-" file) "dbx" nil args)) | 299 (cons file args)) |
300 | 300 |
301 (defun gud-dbx-marker-filter (string) | 301 (defun gud-dbx-marker-filter (string) |
302 (if (string-match | 302 (if (string-match |
303 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" string) | 303 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" string) |
304 (setq gud-last-frame | 304 (setq gud-last-frame |
310 | 310 |
311 (defun gud-dbx-find-file (f) | 311 (defun gud-dbx-find-file (f) |
312 (find-file-noselect f)) | 312 (find-file-noselect f)) |
313 | 313 |
314 ;;;###autoload | 314 ;;;###autoload |
315 (defun dbx (args) | 315 (defun dbx (command-line) |
316 "Run dbx on program FILE in buffer *gud-FILE*. | 316 "Run dbx on program FILE in buffer *gud-FILE*. |
317 The directory containing FILE becomes the initial working directory | 317 The directory containing FILE becomes the initial working directory |
318 and source-file directory for your debugger." | 318 and source-file directory for your debugger." |
319 (interactive | 319 (interactive |
320 (list (read-from-minibuffer "Run dbx (like this): dbx " | 320 (list (read-from-minibuffer "Run dbx (like this): " |
321 (if (consp gud-dbx-history) | 321 (if (consp gud-dbx-history) |
322 (car gud-dbx-history) | 322 (car gud-dbx-history) |
323 "") | 323 "dbx ") |
324 nil nil | 324 nil nil |
325 '(gud-dbx-history . 1)))) | 325 '(gud-dbx-history . 1)))) |
326 (gud-overload-functions '((gud-debugger-startup . gud-dbx-debugger-startup) | 326 (gud-overload-functions '((gud-massage-args . gud-dbx-massage-args) |
327 (gud-marker-filter . gud-dbx-marker-filter) | 327 (gud-marker-filter . gud-dbx-marker-filter) |
328 (gud-find-file . gud-dbx-find-file) | 328 (gud-find-file . gud-dbx-find-file) |
329 )) | 329 )) |
330 | 330 |
331 (gud-common-init args) | 331 (gud-common-init command-line) |
332 | 332 |
333 (gud-def gud-break "stop at \"%f\":%l" | 333 (gud-def gud-break "stop at \"%f\":%l" |
334 "\C-b" "Set breakpoint at current line.") | 334 "\C-b" "Set breakpoint at current line.") |
335 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") | 335 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") |
336 (gud-def gud-step "step %p" "\C-s" "Step one line with display.") | 336 (gud-def gud-step "step %p" "\C-s" "Step one line with display.") |
357 will be known to xdb. | 357 will be known to xdb. |
358 | 358 |
359 The file names should be absolute, or relative to the directory | 359 The file names should be absolute, or relative to the directory |
360 containing the executable being debugged.") | 360 containing the executable being debugged.") |
361 | 361 |
362 (defun gud-xdb-debugger-startup (file args) | 362 (defun gud-xdb-massage-args (file args) |
363 (apply 'make-comint (concat "gud-" file) "xdb" nil | 363 (nconc (let ((directories gud-xdb-directories) |
364 (append (let ((directories gud-xdb-directories) | 364 (result nil)) |
365 (result nil)) | 365 (while directories |
366 (while directories | 366 (setq result (cons (car directories) (cons "-d" result))) |
367 (setq result (cons (car directories) (cons "-d" result))) | 367 (setq directories (cdr directories))) |
368 (setq directories (cdr directories))) | 368 (nreverse (cons file result))) |
369 (nreverse result)) | 369 args)) |
370 args))) | |
371 | 370 |
372 (defun gud-xdb-file-name (f) | 371 (defun gud-xdb-file-name (f) |
373 "Transform a relative pathname to a full pathname in xdb mode" | 372 "Transform a relative pathname to a full pathname in xdb mode" |
374 (let ((result nil)) | 373 (let ((result nil)) |
375 (if (file-exists-p f) | 374 (if (file-exists-p f) |
408 (defun gud-xdb-find-file (f) | 407 (defun gud-xdb-find-file (f) |
409 (let ((realf (gud-xdb-file-name f))) | 408 (let ((realf (gud-xdb-file-name f))) |
410 (if realf (find-file-noselect realf)))) | 409 (if realf (find-file-noselect realf)))) |
411 | 410 |
412 ;;;###autoload | 411 ;;;###autoload |
413 (defun xdb (args) | 412 (defun xdb (command-line) |
414 "Run xdb on program FILE in buffer *gud-FILE*. | 413 "Run xdb on program FILE in buffer *gud-FILE*. |
415 The directory containing FILE becomes the initial working directory | 414 The directory containing FILE becomes the initial working directory |
416 and source-file directory for your debugger. | 415 and source-file directory for your debugger. |
417 | 416 |
418 You can set the variable 'gud-xdb-directories' to a list of program source | 417 You can set the variable 'gud-xdb-directories' to a list of program source |
419 directories if your program contains sources from more than one directory." | 418 directories if your program contains sources from more than one directory." |
420 (interactive | 419 (interactive |
421 (list (read-from-minibuffer "Run xdb (like this): xdb " | 420 (list (read-from-minibuffer "Run xdb (like this): " |
422 (if (consp gud-xdb-history) | 421 (if (consp gud-xdb-history) |
423 (car gud-xdb-history) | 422 (car gud-xdb-history) |
424 "") | 423 "xdb ") |
425 nil nil | 424 nil nil |
426 '(gud-xdb-history . 1)))) | 425 '(gud-xdb-history . 1)))) |
427 (gud-overload-functions '((gud-debugger-startup . gud-xdb-debugger-startup) | 426 (gud-overload-functions '((gud-massage-args . gud-xdb-massage-args) |
428 (gud-marker-filter . gud-xdb-marker-filter) | 427 (gud-marker-filter . gud-xdb-marker-filter) |
429 (gud-find-file . gud-xdb-find-file))) | 428 (gud-find-file . gud-xdb-find-file))) |
430 | 429 |
431 (gud-common-init args) | 430 (gud-common-init command-line) |
432 | 431 |
433 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.") | 432 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.") |
434 (gud-def gud-tbreak "b %f:%l\\t" "\C-t" | 433 (gud-def gud-tbreak "b %f:%l\\t" "\C-t" |
435 "Set temporary breakpoint at current line.") | 434 "Set temporary breakpoint at current line.") |
436 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line") | 435 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line") |
561 (run-hooks 'gud-mode-hook) | 560 (run-hooks 'gud-mode-hook) |
562 ) | 561 ) |
563 | 562 |
564 (defvar gud-comint-buffer nil) | 563 (defvar gud-comint-buffer nil) |
565 | 564 |
566 (defun gud-common-init (args) | 565 ;; Chop STRING into words separated by SPC or TAB and return a list of them. |
567 ;; Perform initializations common to all debuggers | 566 (defun gud-chop-words (string) |
568 ;; There *must* be a cleaner way to lex the arglist... | 567 (let ((i 0) (beg 0) |
569 (let (file i) | 568 (len (length string)) |
570 (if (string= args "") | 569 (words nil)) |
571 (setq args nil) | 570 (while (< i len) |
572 (save-excursion | 571 (if (memq (aref string i) '(?\t ? )) |
573 (set-buffer (get-buffer-create "*gud-scratch*")) | 572 (progn |
574 (erase-buffer) | 573 (setq words (cons (substring string beg i) words) |
575 (insert args) | 574 beg (1+ i)) |
576 (goto-char (point-max)) | 575 (while (and (< beg len) (memq (aref string beg) '(?\t ? ))) |
577 (insert "\")") | 576 (setq beg (1+ beg))) |
578 (goto-char (point-min)) | 577 (setq i (1+ beg))) |
579 (insert "(\"") | 578 (setq i (1+ i)))) |
580 (while (re-search-forward " +" nil t) | 579 (if (< beg len) |
581 (replace-match "\" \"" nil nil)) | 580 (setq words (cons (substring string beg) words))) |
582 (goto-char (point-min)) | 581 (nreverse words))) |
583 (while (re-search-forward "\"\"" nil t) | 582 |
584 (replace-match "" nil nil)) | 583 ;; Perform initializations common to all debuggers. |
585 (setq args (read (buffer-string))) | 584 (defun gud-common-init (command-line) |
586 (kill-buffer (current-buffer)))) | 585 (let* ((words (gud-chop-words command-line)) |
587 (setq i (1- (length args))) | 586 (program (car words)) |
588 (while (and (>= i 0) (not (= (aref (nth i args) 0) ?-))) | 587 (file-word (let ((w (cdr words))) |
589 (setq file (nth i args)) (setq i (1- i))) | 588 (while (and w (= ?- (aref (car w) 0))) |
590 (let* ((path (expand-file-name file)) | 589 (setq w (cdr w))) |
591 (filepart (file-name-nondirectory path))) | 590 (car w))) |
591 (args (delq file-word (cdr words))) | |
592 (file (expand-file-name file-word)) | |
593 (filepart (file-name-nondirectory file))) | |
592 (switch-to-buffer (concat "*gud-" filepart "*")) | 594 (switch-to-buffer (concat "*gud-" filepart "*")) |
593 (setq default-directory (file-name-directory path)) | 595 (setq default-directory (file-name-directory file)) |
594 (or (bolp) (newline)) | 596 (or (bolp) (newline)) |
595 (insert "Current directory is " default-directory "\n") | 597 (insert "Current directory is " default-directory "\n") |
596 (gud-debugger-startup filepart args))) | 598 (apply 'make-comint (concat "gud-" filepart) program nil |
599 (gud-massage-args file args))) | |
597 (gud-mode) | 600 (gud-mode) |
598 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter) | 601 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter) |
599 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel) | 602 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel) |
600 (gud-set-buffer) | 603 (gud-set-buffer) |
601 ) | 604 ) |