Function: gud-common-init
gud-common-init is a byte-compiled function defined in gud.el.gz.
Signature
(gud-common-init COMMAND-LINE MASSAGE-ARGS MARKER-FILTER &optional FIND-FILE)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/gud.el.gz
;; Perform initializations common to all debuggers.
;; The first arg is the specified command line,
;; which starts with the program to debug.
;; The other three args specify the values to use
;; for local variables in the debugger buffer.
(defun gud-common-init (command-line massage-args marker-filter
&optional find-file)
(let* ((words (split-string-and-unquote command-line))
(program (car words))
(dir default-directory)
;; Extract the file name from WORDS
;; and put t in its place.
;; Later on we will put the modified file name arg back there.
(file-word (let ((w (cdr words)))
(while (and w (= ?- (aref (car w) 0)))
(setq w (cdr w)))
(and w
(prog1 (car w)
(setcar w t)))))
(file-subst
(and file-word (substitute-in-file-name file-word)))
(args (cdr words))
;; If a directory was specified, expand the file name.
;; Otherwise, don't expand it, so GDB can use the PATH.
;; A file name without directory is literally valid
;; only if the file exists in ., and in that case,
;; omitting the expansion here has no visible effect.
(file (and file-word
(if (file-name-directory file-subst)
(expand-file-name file-subst)
file-subst)))
(filepart (and file-word (concat "-" (file-name-nondirectory file))))
(buffer-name (concat "*gud" filepart "*"))
(existing-buffer (get-buffer buffer-name))
error)
(when (and existing-buffer
(get-buffer-process existing-buffer))
(if (equal (buffer-local-value 'default-directory existing-buffer)
default-directory)
;; We're already debugging this executable.
(setq error t)
;; Open a new window to debug an executable with the same name.
(setq buffer-name (generate-new-buffer-name buffer-name))))
(select-window
(display-buffer
(get-buffer-create buffer-name)
'((display-buffer-reuse-window
display-buffer-in-previous-window
display-buffer-same-window display-buffer-pop-up-window))))
(when error
(error "This program is already being debugged"))
;; Set the dir, in case the buffer already existed with a different dir.
(setq default-directory dir)
;; Set default-directory to the file's directory.
(and file-word
gud-chdir-before-run
;; Don't set default-directory if no directory was specified.
;; In that case, either the file is found in the current directory,
;; in which case this setq is a no-op,
;; or it is found by searching PATH,
;; in which case we don't know what directory it was found in.
(file-name-directory file)
(setq default-directory (file-name-directory file)))
(or (bolp) (newline))
(insert "Current directory is " default-directory "\n")
;; Put the substituted and expanded file name back in its place.
(let ((w args))
(while (and w (not (eq (car w) t)))
(setq w (cdr w)))
;; Tramp has already been loaded if we are here.
(if w (setcar w (setq file (file-local-name file)))))
(apply #'make-comint-in-buffer
(concat "gud" filepart) (current-buffer)
program nil
(if massage-args
(funcall massage-args file args)
args))
;; Since comint clobbered the mode, we don't set it until now.
(gud-mode)
(setq-local gud-target-name
(and file-word (file-name-nondirectory file))))
(setq-local gud-marker-filter marker-filter)
(if find-file (setq-local gud-find-file find-file))
(setq gud-last-last-frame nil)
(set-process-filter (get-buffer-process (current-buffer)) #'gud-filter)
(set-process-sentinel (get-buffer-process (current-buffer)) #'gud-sentinel)
(gud-set-buffer))