(require 'gud)
(defcustom gud-bashdb-command-name "bashdb"
"File name for executing Bashdb."
:type 'string
:group 'gud)
(defvar gud-bashdb-history nil)
(defun gud-bashdb-massage-args (file args)
(if xemacsp
(cons (file-name-nondirectory file) args)
args))
(if xemacsp
(defvar gud-bashdb-marker-acc ""))
(defun gud-bashdb-marker-acc ()
(if xemacsp
gud-bashdb-marker-acc
gud-marker-acc))
(defun gud-bashdb-marker-acc-quote ()
(if xemacsp
'gud-bashdb-marker-acc
'gud-marker-acc))
(defun gud-bashdb-marker-filter (string)
(save-match-data
(set (gud-bashdb-marker-acc-quote)
(concat (gud-bashdb-marker-acc) string))
(let ((output ""))
(while (string-match "^\\([^:\n]+\\):\\([0-9]+\\)[ *]*>.*\n"
(gud-bashdb-marker-acc))
(setq
gud-last-frame (cons
(substring (gud-bashdb-marker-acc)
(match-beginning 1)
(match-end 1))
(string-to-int
(substring (gud-bashdb-marker-acc)
(match-beginning 2)
(match-end 2))))
output (concat output
(substring (gud-bashdb-marker-acc) 0 (match-beginning 0))))
(set
(gud-bashdb-marker-acc-quote) (substring
(gud-bashdb-marker-acc) (match-end 0))))
(if (string-match "^\\([^:\n]+\\):\\([0-9]+\\)[ *]*>" (gud-bashdb-marker-acc))
(progn
(setq output (concat output (substring (gud-bashdb-marker-acc)
0 (match-beginning 0))))
(set (gud-bashdb-marker-acc-quote)
(substring (gud-bashdb-marker-acc) (match-beginning 0))))
(setq output (concat output (gud-bashdb-marker-acc)))
(set (gud-bashdb-marker-acc-quote) ""))
output)))
(defun gud-bashdb-find-file (f)
(find-file-noselect f))
(defun bashdb (command-line)
"Run bashdb on program FILE in buffer *gud-FILE*.
The directory containing FILE becomes the initial working directory
and source-file directory for your debugger."
(interactive
(if xemacsp
(list (read-from-minibuffer "Run bashdb (like this): "
(if (consp gud-bashdb-history)
(car gud-bashdb-history)
(format "%s " gud-bashdb-command-name))
nil nil
'(gud-bashdb-history . 1)))
(list (gud-query-cmdline 'bashdb))
))
(if xemacsp
(progn
(gud-overload-functions '((gud-massage-args . gud-bashdb-massage-args)
(gud-marker-filter . gud-bashdb-marker-filter)
(gud-find-file . gud-bashdb-find-file)))
(gud-common-init command-line gud-bashdb-command-name))
(gud-common-init command-line 'gud-bashdb-massage-args
'gud-bashdb-marker-filter 'gud-bashdb-find-file)
(set (make-local-variable 'gud-minor-mode) 'bashdb))
(gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.")
(gud-def gud-list-break "break" "b" "List breakpoints & break condition.")
(gud-def gud-remove "delete %l" "\C-d" "Remove breakpoint at current line")
(gud-def gud-remove-all "delete" "d" "Clear all breakpoints")
(gud-def gud-cont "continue" "\C-r" "Continue with display.")
(gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
(gud-def gud-print "print %e" "\C-p" "Evaluate bash expression at point.")
(gud-def gud-help "help" "h" "Show all commands.")
(gud-def gud-trace "trace" "t" "Toggle execution trace on/off")
(setq comint-prompt-regexp "^bashdb> ")
(setq paragraph-start comint-prompt-regexp)
(run-hooks 'bashdb-mode-hook))
(provide 'bashdb)