test/*.el: reduce warnings.
,string 0 (length ,prefix))
)
+(defun realgud:strip (str)
+ "Remove leading and tailing whitespace from STR."
+ (while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'"
+ str)
+ (setq str (replace-match "" t t str)))
+ str)
+
(defun realgud-feature-starts-with(feature prefix)
"realgud-strings-starts-with on stringified FEATURE and PREFIX."
(declare (indent 1))
;; FIXME: should allow column number to be passed in.
(defun realgud-file-loc-from-line(filename line-number
- &optional cmd-marker source-text
- bp-num ignore-file-re)
+ &optional cmd-marker source-text bp-num
+ ;; FIXME: remove ignore-file-re and cover with
+ ;; find-file-fn.
+ ignore-file-re find-file-fn)
"Return a realgud-loc for FILENAME and LINE-NUMBER
-CMD-MARKER and BP-NUM get stored in the realgud-loc object. IGNORE-FILE-RE
-is a regular expression describing things that aren't expected to be
-found. For example many debuggers create a pseudo file name for eval
-expressions. For example (eval 1) of Perl <string> of Python.
+CMD-MARKER and BP-NUM get stored in the realgud-loc
+object. FIND-FILE-FN is a function which do special things to
+transform filename so it can be found. This could include
+searching classpaths (in Java), stripping leading and trailing
+blanks, or deliberately ignoring 'pseudo-file patterns like (eval
+1) of Perl and <string> of Python.
If we're unable find the source code we return a string describing the
problem as best as we can determine."
(unless (and filename (file-readable-p filename))
- (if (and ignore-file-re (string-match ignore-file-re filename))
- (message "tracking ignored for psuedo-file %s" filename)
- ; else
- (let ((remapped-filename))
- (if (gethash filename realgud-file-remap)
+ (if find-file-fn
+ (setq filename (funcall find-file-fn))
+ ;; FIXME: Remove the below by refactoring to use the above find-file-fn
+ ;; else
+ (if (and ignore-file-re (string-match ignore-file-re filename))
+ (message "tracking ignored for psuedo-file %s" filename)
+ ;; else
+ (let ((remapped-filename))
+ (if (gethash filename realgud-file-remap)
+ (progn
+ (setq remapped-filename (gethash filename realgud-file-remap))
+ (if (file-exists-p remapped-filename)
+ (setq filename remapped-filename)
+ (remhash filename realgud-file-remap)))
+ ;; else
(progn
- (setq remapped-filename (gethash filename realgud-file-remap))
- (if (file-exists-p remapped-filename)
- (setq filename remapped-filename)
- (remhash filename realgud-file-remap)))
- ;; else
- (progn
- (setq remapped-filename
- (buffer-file-name
- (compilation-find-file (point-marker) filename nil)))
- (when (and remapped-filename (file-exists-p remapped-filename))
- (puthash filename remapped-filename realgud-file-remap)
- (setq filename remapped-filename)
- )
- )))
+ (setq remapped-filename
+ (buffer-file-name
+ (compilation-find-file (point-marker) filename nil)))
+ (when (and remapped-filename (file-exists-p remapped-filename))
+ (puthash filename remapped-filename realgud-file-remap)
+ (setq filename remapped-filename)
+ )
+ )))
+ )
+ ;; FIXME: remove above -----------------------------------.
))
- (if (and filename (file-readable-p filename))
- (if (integerp line-number)
- (if (> line-number 0)
- (lexical-let ((line-count))
- (if (setq line-count (realgud:file-line-count filename))
- (if (> line-count line-number)
- (let ((column-number
- (realgud:file-column-from-string filename
- line-number
- source-text)))
- ;; And you thought we'd never get around to
- ;; doing something other than validation?
- (make-realgud-loc
- :num bp-num
- :cmd-marker cmd-marker
- :filename filename
- :line-number line-number
- :column-number column-number
- :source-text source-text
- :marker (make-marker)
- ))
- ;; else
- (format "File %s has only %d lines. (Line %d requested.)"
- filename line-count line-number))
- (format "Problem getting line count for file `%s'" filename)))
- (format "line number %s should be greater than 0" line-number))
- (format "%s is not an integer" line-number))
- ;; else
- (format "File named `%s' not readable" filename))
+ (if filename
+ (if (file-readable-p filename)
+ (if (integerp line-number)
+ (if (> line-number 0)
+ (lexical-let ((line-count))
+ (if (setq line-count (realgud:file-line-count filename))
+ (if (> line-count line-number)
+ (let ((column-number
+ (realgud:file-column-from-string filename
+ line-number
+ source-text)))
+ ;; And you thought we'd never get around to
+ ;; doing something other than validation?
+ (make-realgud-loc
+ :num bp-num
+ :cmd-marker cmd-marker
+ :filename filename
+ :line-number line-number
+ :column-number column-number
+ :source-text source-text
+ :marker (make-marker)
+ ))
+ ;; else
+ (format "File %s has only %d lines. (Line %d requested.)"
+ filename line-count line-number))
+ (format "Problem getting line count for file `%s'" filename)))
+ (format "line number %s should be greater than 0" line-number))
+ (format "%s is not an integer" line-number))
+ ;; else
+ (format "File named `%s' not readable" filename)))
)
(provide-me "realgud-")
;; We use gud to handle the classpath-to-filename mapping
(require 'gud)
+(require 'compile) ;; for compilation-find-file
(require 'load-relative)
(require-relative-list '("../../common/track"
"../../common/core"
- "../../common/lang"
- "../../common/file")
+ "../../common/file"
+ "../../common/lang")
"realgud-")
(require-relative-list '("init") "realgud:jdb-")
(declare-function gud-find-source 'gud)
+(declare-function realgud:strip 'realgud)
(declare-function realgud:expand-file-name-if-exists 'realgud-core)
(declare-function realgud-parse-command-arg 'realgud-core)
(declare-function realgud-query-cmdline 'realgud-core)
'realgud:jdb-minibuffer-history
opt-debugger))
+(defun realgud:jdb-dot-to-slash (str)
+ "Change '.' to '/' in STR but chop off from the last . to the end. For example
+ca.mgcill.rocky.snpEff.main => ca/mcgill/rocky/snpEff"
+ (setq str (replace-regexp-in-string "\\([^\\.]+\\.\\)[^\\.]+$" "\\1" str))
+ (setq str (replace-regexp-in-string "\\.$" "" str))
+ (setq str (replace-regexp-in-string "\\." "/" str))
+ str)
+
+(defvar realgud:jdb-file-remap (make-hash-table :test 'equal)
+ "How to remap Java files in jdb when we otherwise can't find in
+ the filesystem. The hash key is the file string we saw, and the
+ value is associated filesystem string presumably in the
+ filesystem")
+
+(defun realgud:jdb-find-file(filename)
+ "A find-file specific for java/jdb. We use `gdb-jdb-find-source' to map a
+name to a filename. Failing that we can add on .java to the name. Failing that
+we will prompt for a mapping and save that in `realgud:jdb-file-remap' when
+that works."
+ (let* ((transformed-file)
+ (stripped-filename (realgud:strip filename))
+ (gud-jdb-filename (gud-jdb-find-source stripped-filename))
+ )
+ (cond
+ ((and gud-jdb-filename (file-exists-p gud-jdb-filename))
+ gud-jdb-filename)
+ ((file-exists-p (setq transformed-file (concat stripped-filename ".java")))
+ transformed-file)
+ ('t
+ (if (gethash stripped-filename realgud:jdb-file-remap)
+ (let ((remapped-filename))
+ (setq remapped-filename (gethash stripped-filename realgud:jdb-file-remap))
+ (if (file-exists-p remapped-filename)
+ remapped-filename
+ ;; else
+ (and (remhash filename realgud-file-remap) nil))
+ ;; else
+ (let ((remapped-filename)
+ (guess-filename (realgud:jdb-dot-to-slash filename)))
+ (setq remapped-filename
+ (buffer-file-name
+ (compilation-find-file (point-marker) guess-filename nil)))
+ (when (and remapped-filename (file-exists-p remapped-filename))
+ (puthash stripped-filename remapped-filename realgud:jdb-file-remap)
+ remapped-filename
+ ))
+ ))
+ ))
+ ))
+
(defun realgud:jdb-loc-fn-callback(text filename lineno source-str
ignore-file-re cmd-mark)
-
- (realgud-file-loc-from-line (or (gud-jdb-find-source filename)
- (concat filename ".java"))
+ (realgud-file-loc-from-line filename lineno
+ cmd-mark source-str nil
lineno cmd-mark
source-str nil
- ignore-file-re))
+ nil 'realgud:jdb-find-file))
(defun realgud:jdb-parse-cmd-args (orig-args)
"Parse command line ARGS for the annotate level and name of script to debug.
We return the a list containing
-* the command debuger (e.g. jdb)
+* the command debugger (e.g. jdb)
* debugger command rguments if any - a list of strings
;;; Copyright (C) 2010, 2014 Rocky Bernstein <rocky@gnu.org>
(eval-when-compile (require 'cl))
+(require 'compile) ;; for compilation-find-file
(require 'load-relative)
(require-relative-list '("../../common/track"
"../../common/core"
+ "../../common/file"
"../../common/lang")
"realgud-")
(require-relative-list '("init") "realgud:trepan2-")
+(declare-function realgud:strip 'realgud)
(declare-function realgud:expand-file-name-if-exists 'realgud-core)
(declare-function realgud-parse-command-arg 'realgud-core)
(declare-function realgud-query-cmdline 'realgud-core)
(declare-function realgud-suggest-invocation 'realgud-core)
+(declare-function realgud-file-loc-from-line 'realgud-file)
;; FIXME: I think the following could be generalized and moved to
;; realgud-... probably via a macro.
"Keymap for minibuffer prompting of gud startup command."
:inherit minibuffer-local-map)
+(defvar realgud:trepan2-file-remap (make-hash-table :test 'equal)
+ "How to remap Python files in treapn2 when we otherwise can't
+ find in the filesystem. The hash key is the file string we saw,
+ and the value is associated filesystem string presumably in the
+ filesystem")
+
+;; FIXME: this code could be generalized and put in a common place.
+(defun realgud:trepan2-find-file(filename)
+ "A find-file specific for python/trepan. We strip off trailing
+blanks. Failing that we will prompt for a mapping and save that
+in variable `realgud:trepan2-file-remap' when that works. In the future,
+we may also consult PYTHONPATH."
+ (let* ((transformed-file)
+ (stripped-filename (realgud:strip filename))
+ (ignore-file-re realgud-python-ignore-file-re)
+ )
+ (cond
+ ((file-exists-p filename) filename)
+ ((file-exists-p stripped-filename) stripped-filename)
+ ((string-match ignore-file-re filename)
+ (message "tracking ignored for psuedo-file: %s" filename) nil)
+ ('t
+ ;; FIXME search PYTHONPATH if not absolute file
+ (if (gethash filename realgud-file-remap)
+ (let ((remapped-filename))
+ (setq remapped-filename (gethash filename realgud:trepan2-file-remap))
+ (if (file-exists-p remapped-filename)
+ remapped-filename
+ ;; else
+ (and (remhash filename realgud-file-remap)) nil)
+ ;; else
+ (let ((remapped-filename))
+ (setq remapped-filename
+ (buffer-file-name
+ (compilation-find-file (point-marker) stripped-filename nil)))
+ (when (and remapped-filename (file-exists-p remapped-filename))
+ (puthash filename remapped-filename realgud-file-remap)
+ remapped-filename
+ ))
+ ))
+ ))
+ ))
+
+(defun realgud:trepan2-loc-fn-callback(text filename lineno source-str
+ ignore-file-re cmd-mark)
+ (realgud-file-loc-from-line filename lineno
+ cmd-mark source-str nil
+ 'realgud:trepan2-find-file))
+
;; FIXME: I think this code and the keymaps and history
;; variable chould be generalized, perhaps via a macro.
(defun trepan2-query-cmdline (&optional opt-debugger)
backtrace, prompt, etc. The values of a hash entry is a
realgud-loc-pat struct")
-(declare-function make-realgud-loc "realgud-loc" (a b c d e f))
+(setf (gethash "loc-callback-fn" realgud:trepan2-pat-hash) 'realgud:trepan2-loc-fn-callback)
;; Regular expression that describes a trepan2 location generally shown
;; before a command prompt.
+(require 'test-simple)
(load-file "./bt-helper.el")
(load-file "../realgud/debugger/trepanx/init.el")
+(require 'test-simple)
(load-file "./bt-helper.el")
(load-file "../realgud/debugger/zshdb/init.el")
(declare-function __FILE__ 'require-relative)
(declare-function realgud:jdb-parse-cmd-args 'realgud:jdb-core)
+(declare-function realgud:jdb-dot-to-slash 'realgud:jdb-core)
(assert-equal '("jdb" nil ("./TestMe.java"))
(realgud:jdb-parse-cmd-args '("jdb" "./TestMe.java")))
+(assert-equal "mcb/pcingola/SnpEff"
+ (realgud:jdb-dot-to-slash "mcb.pcingola.SnpEff.main"))
+
(end-tests)
+(require 'test-simple)
(load-file "./regexp-helper.el")
(load-file "../realgud/common/regexp.el")
(load-file "../realgud/debugger/gub/init.el")
+(require 'test-simple)
(load-file "./regexp-helper.el")
(load-file "../realgud/common/regexp.el")
(load-file "../realgud/debugger/trepan/init.el")
+(require 'test-simple)
(load-file "./regexp-helper.el")
(load-file "../realgud/common/regexp.el")
(load-file "../realgud/debugger/trepanx/init.el")
(defvar dbg-name)
(defvar realgud:gub-pat-hash)
(defvar panic-tb)
- (defvar tb)
+ (defvar test-tb)
(defvar prompt-pat)
(defvar test-dbgr)
(defvar test-text)
(prompt-match "gub[32@5]: ")
(setup-regexp-vars realgud:gub-pat-hash)
-(set (make-local-variable 'tb)
+(set (make-local-variable 'test-tb)
(gethash "lang-backtrace" realgud:gub-pat-hash))
(note "go lang traceback")
(assert-t (numberp (tb-loc-match test-text)) "go traceback location")
(assert-equal "/usr/local/go/src/pkg/runtime/panic.c"
- (match-string (realgud-loc-pat-file-group tb)
+ (match-string (realgud-loc-pat-file-group test-tb)
test-text) "extract traceback file name")
(assert-equal "482"
- (match-string (realgud-loc-pat-line-group tb)
+ (match-string (realgud-loc-pat-line-group test-tb)
test-text) "extract traceback line number")
(note "panic traceback")
(assert-t (numberp (string-match (realgud-loc-pat-regexp panic-tb) test-text))
"go panic location")
(assert-equal "/tmp/github.com/rocky/ssa-interp/eval/selectorexpr.go"
- (match-string (realgud-loc-pat-file-group tb)
+ (match-string (realgud-loc-pat-file-group test-tb)
test-text) "extract panic traceback file name")
(assert-equal "18"
- (match-string (realgud-loc-pat-line-group tb)
+ (match-string (realgud-loc-pat-line-group test-tb)
test-text) "extract panic traceback line number")
-
-
(end-tests)
(require 'test-simple)
(load-file "../realgud/debugger/trepan2/trepan2.el")
-(declare-function trepan2-parse-cmd-args 'realgud:trepan2)
-(declare-function __FILE__ 'require-relative)
+(load-file "../realgud/debugger/trepan2/core.el")
+(load-file "../realgud.el")
+
+(declare-function trepan2-parse-cmd-args 'realgud:trepan2)
+(declare-function realgud:trepan2-find-file 'realgud:trepan2-core)
+(declare-function __FILE__ 'require-relative)
(test-simple-start)
(trepan2-parse-cmd-args
'("trepan2" "program.py" "foo")))
+(note "realgud:trepan2-find-file")
+(assert-nil (realgud:trepan2-find-file "<string>")
+ "Should ignore psuedo file")
+
+(eval-when-compile
+ (defvar test-python-file))
+
+(set (make-local-variable 'test-python-file)
+ (concat (file-name-directory (__FILE__)) "gcd.py"))
+(assert-equal test-python-file (realgud:trepan2-find-file test-python-file)
+ "Should ignore psuedo file")
+
(end-tests)