]> code.delx.au - gnu-emacs-elpa/commitdiff
{trepan2,jdb}/{core,init}.el: Start adding debugger-specific find-file routines....
authorrocky <rocky@gnu.org>
Sun, 16 Nov 2014 03:11:17 +0000 (22:11 -0500)
committerrocky <rocky@gnu.org>
Sun, 16 Nov 2014 03:11:17 +0000 (22:11 -0500)
test/*.el: reduce warnings.

13 files changed:
realgud.el
realgud/common/file.el
realgud/debugger/jdb/core.el
realgud/debugger/trepan2/core.el
realgud/debugger/trepan2/init.el
test/test-bt-trepanx.el
test/test-bt-zshdb.el
test/test-jdb.el
test/test-loc-regexp-gub.el
test/test-loc-regexp-trepan.el
test/test-loc-regexp-trepanx.el
test/test-regexp-gub.el
test/test-trepan2.el

index ebac77bc94e21b2b8b5d8ab28f1640eac65b274d..1735f9d2370200d67b38a4524f1b09e2a7079ebf 100644 (file)
                    ,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))
index bf013cae2c36285277700e333a9a67b925508bc8..fc10f16cee65fe0d661038fb88f3633d8e4222b7 100644 (file)
@@ -43,69 +43,80 @@ at LINE-NUMBER or nil if it is not there"
 
 ;; 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-")
index 5e4c52f44b9df247ba2ca8fbbc017ac101ec5e0b..4d4afc98f84448de23e159fb5944e7cbee3a705e 100644 (file)
@@ -3,17 +3,19 @@
 
 ;; 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.
@@ -55,7 +106,7 @@ ORIG-ARGS should contain a tokenized list of the command line to run.
 
 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
 
index aca75dc148edd8ced65929ba48af9a0d916433f0..5334c4ff0e03a84c7ea7c506adceac05edb60e49 100644 (file)
@@ -1,17 +1,21 @@
 ;;; 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)
index 9322bb901903a79572bcac1c4e1d5b26229efe90..318a89c672110be23ed0eb429c1cb513670cd97f 100644 (file)
@@ -18,7 +18,7 @@
 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.
index 217da4246fd09b403fcc5bc64bff4492941ee62a..eff0deca56c3542d05bed2886271afaff0649f9b 100644 (file)
@@ -1,3 +1,4 @@
+(require 'test-simple)
 (load-file "./bt-helper.el")
 (load-file "../realgud/debugger/trepanx/init.el")
 
index f91f80250d676698011c1f8a107373f8257213ac..bb4b36aaa8018acfbfddcb0a08736558cfecc77d 100644 (file)
@@ -1,3 +1,4 @@
+(require 'test-simple)
 (load-file "./bt-helper.el")
 (load-file "../realgud/debugger/zshdb/init.el")
 
index ca89cfd3b79b5ee80ea2abffa70d8e9342593305..1df94c12083705957f88993ef1da5910d0e1e98c 100644 (file)
@@ -4,7 +4,11 @@
 
 (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)
index f278ff89cf315fb936afb6a30e9cc1dab188a2e9..49c01656b8c46d483415ebd0cf4d17359112e7b6 100644 (file)
@@ -1,3 +1,4 @@
+(require 'test-simple)
 (load-file "./regexp-helper.el")
 (load-file "../realgud/common/regexp.el")
 (load-file "../realgud/debugger/gub/init.el")
index c19c51d9623960f6989a2363784c4f2467948255..daf34580c927974118f6a14806f8b221171a2584 100644 (file)
@@ -1,3 +1,4 @@
+(require 'test-simple)
 (load-file "./regexp-helper.el")
 (load-file "../realgud/common/regexp.el")
 (load-file "../realgud/debugger/trepan/init.el")
index 4abe0fcec2d6cbeeb2efecd7ecb22a76073449cc..6da52f2a195ca1166d62f74408b1efb3ffa2f690 100644 (file)
@@ -1,3 +1,4 @@
+(require 'test-simple)
 (load-file "./regexp-helper.el")
 (load-file "../realgud/common/regexp.el")
 (load-file "../realgud/debugger/trepanx/init.el")
index ef90112fcf36618a2f7d8eec7f0c25f73f8a6b3d..7d33b0d647d29812a2b6bf16c1a38fe5dbc38637 100644 (file)
@@ -9,7 +9,7 @@
   (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)
@@ -28,7 +28,7 @@
 (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)
index 569e3347fbdd611c2a6ca35d154a7ab5b781d66b..2e9910ab2d5a8a7dab75c73f4444a0d0214d04e3 100644 (file)
@@ -1,7 +1,11 @@
 (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)