branch: externals/realgud commit 096bd8732ea0661f10d7f7c1c91ad1ca4cf51207 Merge: 388a650 9f9c772 Author: R. Bernstein <ro...@users.noreply.github.com> Commit: GitHub <nore...@github.com>
Merge pull request #212 from realgud/filter-lists Filter lists --- .gitignore | 2 +- el-get-install.el | 3 +- realgud/common/buffer/command.el | 109 +++++++++++++++++++++++++++++------ realgud/common/file.el | 116 +++++++++++++++++++++++++------------- realgud/common/track.el | 30 +++++----- realgud/debugger/ipdb/init.el | 10 +++- realgud/debugger/jdb/core.el | 55 +++++++++--------- realgud/debugger/jdb/init.el | 3 +- realgud/debugger/pdb/init.el | 10 +++- realgud/debugger/rdebug/init.el | 11 +++- realgud/debugger/trepan/core.el | 6 +- realgud/debugger/trepan/init.el | 9 ++- realgud/debugger/trepan2/core.el | 66 ++++++++++++---------- realgud/debugger/trepan2/init.el | 8 +++ realgud/debugger/trepan3k/init.el | 8 +++ realgud/debugger/trepanjs/core.el | 6 +- realgud/lang/python.el | 4 +- test/bt-helper.el | 10 +++- test/test-bt-trepan.el | 53 +++++++++-------- test/test-bt-trepan2.el | 42 +++++++------- test/test-file.el | 13 ++--- test/test-trepan2.el | 27 ++++++--- 22 files changed, 389 insertions(+), 212 deletions(-) diff --git a/.gitignore b/.gitignore index c307377..ab8846f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /*-pkg.el /*.tar.gz /.cask/ -/.python-version +.python-version /README /aclocal.m4 /autom4te.cache diff --git a/el-get-install.el b/el-get-install.el index 6c7cf06..8fb48df 100644 --- a/el-get-install.el +++ b/el-get-install.el @@ -98,7 +98,8 @@ loc-changes ; loc marks in buffers load-relative ; load emacs lisp relative to emacs source test-simple ; simple test framework + seq ; sequence manipulation used in testing )) ;; install new packages and init already installed packages -(el-get 'sync '(loc-changes load-relative test-simple)) +(el-get 'sync '(loc-changes load-relative test-simple seq)) diff --git a/realgud/common/buffer/command.el b/realgud/common/buffer/command.el index db159f8..bfb870a 100644 --- a/realgud/common/buffer/command.el +++ b/realgud/common/buffer/command.el @@ -33,6 +33,11 @@ ) (require 'cl-lib) +(when (< emacs-major-version 26) + (defun make-mutex(&rest name) + ;; Stub for Emacs that doesn't have mutex + )) + (defface debugger-running '((((class color) (min-colors 16) (background light)) (:foreground "Green4" :weight bold)) @@ -98,7 +103,36 @@ alt-file-group alt-line-group text-group - ignore-file-re + + ;; A list (or sequence) of regular expression strings of file names + ;; that we should ignore. + ;; + ;; For example in Python debuggers it often starts out "<string>...", while + ;; in Ruby and Perl it often starts out "(eval ...". + ;; + ;; However in this list could be individual files that one encounters in the + ;; course of debugging. For example: + ;; - in nodejs "internal/module.js" or more generally internal/.*\.js. + ;; - in C ../sysdeps/x86_64/multiarch/strchr-avx2.S or or more generally .*/sysdeps/.* + ;; and so on. + ;; + ;; A list of regular expression. When one in the list matches a source + ;; location, we ignore that file. Of course, the regular expression could + ;; be a specific file name. Various programming languages have names + ;; that might not be real. For example, in Python or Ruby when you compile + ;; a or evaluate string you provide a name in the call, and often times + ;; this isn't the real name of a file. It is often something like "exec" or + ;; "<string>", or "<eval>". Each of the debuggers has the opportunity to seed the + ;; the ignore list. + ignore-re-file-list + + ;; A property list which maps the name as seen in the location to a path that we + ;; can do a "find-file" on + filename-remap-alist + + ;; A mutex to ensure that two threads doing things in the same debug + ;; session simultaneously + mutex loc-hist ;; ring of locations seen in the course of execution ;; see realgud-lochist @@ -125,6 +159,12 @@ (realgud-struct-field-setter "realgud-cmdbuf-info" "callback-loc-fn") (realgud-struct-field-setter "realgud-cmdbuf-info" "callback-eval-filter") (realgud-struct-field-setter "realgud-cmdbuf-info" "starting-directory") +(realgud-struct-field-setter "realgud-cmdbuf-info" "ignore-re-file-list") +;; (realgud-struct-field-setter "realgud-cmdbuf-info" "filename-remap-alist") + +(defun realgud-cmdbuf-filename-remap-alist= (value &optional buffer) + (setq buffer (realgud-get-cmdbuf buffer)) + (setf (realgud-cmdbuf-info-filename-remap-alist realgud-cmdbuf-info) value)) (defun realgud:cmdbuf-follow-buffer(event) (interactive "e") @@ -234,20 +274,24 @@ This is based on an org-mode buffer. Hit tab to expand/contract sections. (mapc 'insert (list - (format " - Debugger name ::\t%s\n" + (format " - Debugger name ::\t%s\n" (realgud-cmdbuf-info-debugger-name info)) - (format " - Command-line args ::\t%s\n" + (format " - Command-line args ::\t%s\n" (json-encode (realgud-cmdbuf-info-cmd-args info))) - (format " - Starting directory ::\t%s\n" + (format " - Starting directory ::\t%s\n" (realgud-cmdbuf-info-starting-directory info)) (format " - Selected window should contain source? :: %s\n" (realgud-cmdbuf-info-in-srcbuf? info)) - (format " - Last input end ::\t%s\n" + (format " - Last input end ::\t%s\n" (realgud-cmdbuf-info-last-input-end info)) (format " - Source should go into short-key mode? :: %s\n" (realgud-cmdbuf-info-src-shortkey? info)) - (format " - In debugger? ::\t%s\n" + (format " - In debugger? ::\t%s\n" (realgud-cmdbuf-info-in-debugger? info)) + (format " - Ignore file regexps ::\t%s\n" + (realgud-cmdbuf-info-ignore-re-file-list info)) + (format " - remapped file names ::\t%s\n" + (realgud-cmdbuf-info-filename-remap-alist info)) (realgud:org-mode-encode "\n*** Remap table for debugger commands\n" (realgud-cmdbuf-info-cmd-hash info)) @@ -381,26 +425,36 @@ values set in the debugger's init.el." ) (setq realgud-cmdbuf-info (make-realgud-cmdbuf-info - :in-srcbuf? nil :debugger-name debugger-name :base-variable-name (or base-variable-name debugger-name) + :cmd-args nil + :frame-switch? nil + :in-srcbuf? nil + :last-input-end (point-max) + :prior-prompt-regexp nil + :no-record? nil + :in-debugger? nil + :src-shortkey? t + :regexp-hash regexp-hash + :srcbuf-list nil + :bt-buf nil + :bp-list nil + :divert-output? nil + :cmd-hash cmd-hash + :callback-loc-fn (gethash "loc-callback-fn" regexp-hash) + :callback-eval-filter (gethash "callback-eval-filter" + regexp-hash) :loc-regexp (realgud-sget 'loc-pat 'regexp) :file-group (realgud-sget 'loc-pat 'file-group) :line-group (realgud-sget 'loc-pat 'line-group) :alt-file-group (realgud-sget 'loc-pat 'alt-file-group) :alt-line-group (realgud-sget 'loc-pat 'alt-line-group) :text-group (realgud-sget 'loc-pat 'text-group) - :ignore-file-re (realgud-sget 'loc-pat 'ignore-file-re) + :ignore-re-file-list (gethash "ignore-re-file-list" regexp-hash) + :filename-remap-alist nil + :mutex (make-mutex (buffer-name)) :loc-hist (make-realgud-loc-hist) - :regexp-hash regexp-hash - :bt-buf nil - :last-input-end (point-max) - :cmd-hash cmd-hash - :src-shortkey? t - :in-debugger? nil - :callback-loc-fn (gethash "loc-callback-fn" regexp-hash) - :callback-eval-filter (gethash "callback-eval-filter" - regexp-hash) + :starting-directory starting-directory )) (setq font-lock-keywords (realgud-cmdbuf-pat "font-lock-keywords")) (if font-lock-keywords @@ -426,6 +480,22 @@ values set in the debugger's init.el." nil)) ) +(defun realgud-cmdbuf-mutex (&optional cmd-buf) + "Return the mutex for the current command buffer" + (with-current-buffer-safe (or cmd-buf (current-buffer)) + (if (realgud-cmdbuf?) + (realgud-sget 'cmdbuf-info 'mutex) + nil)) + ) + +(defun realgud-cmdbuf-filename-remap-alist (&optional cmd-buf) + "Return the file-remap alist the current command buffer" + (with-current-buffer-safe (or cmd-buf (current-buffer)) + (if (realgud-cmdbuf?) + (realgud-sget 'cmdbuf-info 'filename-remap-alist) + nil)) + ) + (defun realgud-cmdbuf-pat(key) "Extract regexp stored under KEY in a realgud-cmdbuf via realgud-cmdbuf-info" (if (realgud-cmdbuf?) @@ -443,6 +513,11 @@ command-process buffer has stored." (realgud-sget 'cmdbuf-info 'loc-hist)) ) +(defun realgud-cmdbuf-ignore-re-file-list(cmd-buf) + (with-current-buffer-safe cmd-buf + (realgud-sget 'cmdbuf-info 'ignore-re-file-list)) +) + (defun realgud-cmdbuf-src-marker(cmd-buf) "Return a marker to current source location stored in the history ring." (with-current-buffer cmd-buf diff --git a/realgud/common/file.el b/realgud/common/file.el index f3694ba..06ef03f 100644 --- a/realgud/common/file.el +++ b/realgud/common/file.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2010-2011, 2013-2014, 2016-2017 Free Software Foundation, Inc +;; Copyright (C) 2010-2011, 2013-2014, 2016-2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> @@ -15,25 +15,30 @@ ; Should realgud:file-loc-from-line be here or elsewhere? (require 'load-relative) (require 'compile) ;; for compilation-find-file +(require 'seq) ;; for seq-find (require-relative-list '("helper" "loc") "realgud-") - -(defvar realgud-file-remap (make-hash-table :test 'equal) - "How to remap files 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") - +(require-relative-list '("buffer/command") "realgud-buffer-") (declare-function realgud:strip 'realgud) (declare-function realgud-loc-goto 'realgud-loc) +(declare-function realgud-get-cmdbuf 'realgud-buffer-helper) (declare-function buffer-killed? 'helper) (declare-function compilation-find-file 'compile) +(declare-function realgud-cmdbuf-info-ignore-re-file-list= 'realgud-buffer-command) -(defcustom realgud-file-find-function 'compilation-find-file +(defcustom realgud-file-find-function 'realgud:find-file +;;(defcustom realgud-file-find-function 'compilation-find-file "Function to call when we can't easily find file" :type 'function :group 'realgud) +(defun realgud:find-file (marker filename directory &optional formats) + "A wrapper around compilation find-file. We set the prompt + to indicate we are looking for a source-code file." + (or formats (setq formats "%s")) + (let ((compilation-error "source-code file")) + (compilation-find-file marker filename directory formats))) + (defun realgud:file-line-count(filename) "Return the number of lines in file FILENAME, or nil FILENAME can't be found" @@ -61,12 +66,13 @@ at LINE-NUMBER or nil if it is not there" (current-column)))))) (error nil))) +(defun realgud:file-ignore(filename ignore-re-file-list) + (seq-find '(lambda (file-re) (string-match file-re filename)) ignore-re-file-list)) + ;; 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 - ;; FIXME: remove ignore-file-re and cover with - ;; find-file-fn. - ignore-file-re find-file-fn directory) + find-file-fn directory) "Return a realgud-loc for FILENAME and LINE-NUMBER and the other optional position information. @@ -80,33 +86,62 @@ blanks, or deliberately ignoring 'pseudo-file patterns like (eval 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 find-file-fn - (setq filename (funcall find-file-fn filename)) - ;; 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 pseudo-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 - (let ((found-file (funcall realgud-file-find-function (point-marker) filename directory))) - (when found-file - (setq remapped-filename (buffer-file-name found-file)) - (when (and remapped-filename (file-exists-p remapped-filename)) - (puthash filename remapped-filename realgud-file-remap) - (setq filename remapped-filename) - )) - ))) - ) - ;; FIXME: remove above -----------------------------------. - )) + (let* ((cmdbuf (realgud-get-cmdbuf)) + (ignore-re-file-list (realgud-cmdbuf-ignore-re-file-list cmdbuf)) + (filename-remap-alist (realgud-cmdbuf-filename-remap-alist cmdbuf)) + (remapped-filename + (assoc filename filename-remap-alist)) + (mutex (realgud-cmdbuf-mutex cmdbuf)) + ) + + ;;(with-mutex + ;; mutex + (when remapped-filename + (if (file-readable-p (cdr remapped-filename)) + (setq filename (cdr remapped-filename)) + ;; else remove from map since no find + (realgud-cmdbuf-filename-remap-alist= + (delq (assoc remapped-filename filename-remap-alist) + filename-remap-alist)))) + + (unless (and filename (file-readable-p filename)) + + (cond + ;; Is file already listed for ignore? + ((realgud:file-ignore filename ignore-re-file-list) + (message "tracking ignored for %s" filename)) + + ;; Do we want to black-list this? + ((y-or-n-p (format "Black-list file %s for location tracking?" filename)) + ;; FIXME: there has to be a simpler way to set ignore-file-list + (with-current-buffer cmdbuf + (push filename ignore-re-file-list) + (realgud-cmdbuf-info-ignore-re-file-list= ignore-re-file-list)) + (setq filename nil) + ) + + ;; Do we have a custom find-file function? + (find-file-fn + (setq filename (funcall find-file-fn cmd-marker filename directory))) + + (t + (let ((found-file (funcall realgud-file-find-function (point-marker) filename directory))) + (if found-file + (progn + (setq remapped-filename (buffer-file-name found-file)) + (when (and remapped-filename (file-exists-p remapped-filename)) + (realgud-cmdbuf-filename-remap-alist= + (cons + (cons filename remapped-filename) + filename-remap-alist)) + (setq filename remapped-filename) + )) + ;; else + (setq filename nil) + ))) + ))) + ;;) + (if filename (if (file-readable-p filename) (if (integerp line-number) @@ -144,7 +179,8 @@ problem as best as we can determine." (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 + (format "File named `%s' not readable" filename)))) ) (provide-me "realgud-") diff --git a/realgud/common/track.el b/realgud/common/track.el index d081449..a0de3f1 100644 --- a/realgud/common/track.el +++ b/realgud/common/track.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2017 Free Software Foundation, Inc +;; Copyright (C) 2015-2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> @@ -425,8 +425,7 @@ encountering a new loc." ) (defun realgud-track-loc(text cmd-mark &optional opt-regexp opt-file-group - opt-line-group no-warn-on-no-match? - opt-ignore-file-re) + opt-line-group no-warn-on-no-match?) "Do regular-expression matching to find a file name and line number inside string TEXT. If we match, we will turn the result into a realgud-loc struct. Otherwise return nil." @@ -450,8 +449,6 @@ Otherwise return nil." (alt-file-group (realgud-sget 'cmdbuf-info 'alt-file-group)) (alt-line-group (realgud-sget 'cmdbuf-info 'alt-line-group)) (text-group (realgud-sget 'cmdbuf-info 'text-group)) - (ignore-file-re (or opt-ignore-file-re - (realgud-sget 'cmdbuf-info 'ignore-file-re))) (callback-loc-fn (realgud-sget 'cmdbuf-info 'callback-loc-fn)) ) (if loc-regexp @@ -473,7 +470,7 @@ Otherwise return nil." (cond (callback-loc-fn (funcall callback-loc-fn text filename lineno source-str - ignore-file-re cmd-mark)) + cmd-mark directory)) ('t (unless line-str (message "line number not found -- using 1")) @@ -481,7 +478,6 @@ Otherwise return nil." (realgud:file-loc-from-line filename lineno cmd-mark source-str nil - ignore-file-re nil directory ) @@ -495,7 +491,7 @@ Otherwise return nil." ) ) -(defun realgud-track-bp-loc(text &optional cmd-mark cmdbuf ignore-file-re) +(defun realgud-track-bp-loc(text &optional cmd-mark cmdbuf opt-ignore-re-file-list) "Do regular-expression matching to find a file name and line number inside string TEXT. If we match, we will turn the result into a realgud-loc struct. Otherwise return nil. CMD-MARK is set in the realgud-loc object created. @@ -518,7 +514,8 @@ Otherwise return nil. CMD-MARK is set in the realgud-loc object created. (file-group (realgud-loc-pat-file-group loc-pat)) (line-group (realgud-loc-pat-line-group loc-pat)) (text-group (realgud-loc-pat-text-group loc-pat)) - (ignore-file-re (realgud-loc-pat-ignore-file-re loc-pat)) + (ignore-re-file-list (or opt-ignore-re-file-list + (realgud-sget 'cmdbuf-info 'ignore-re-file-list))) (callback-loc-fn (realgud-sget 'cmdbuf-info 'callback-loc-fn)) ) (if loc-regexp @@ -532,7 +529,7 @@ Otherwise return nil. CMD-MARK is set in the realgud-loc object created. (cond (callback-loc-fn (funcall callback-loc-fn text filename lineno source-str - ignore-file-re cmd-mark)) + ignore-re-file-list cmd-mark)) ('t (unless line-str @@ -548,7 +545,7 @@ Otherwise return nil. CMD-MARK is set in the realgud-loc object created. cmd-mark source-str (string-to-number bp-num) - ignore-file-re nil directory + nil directory ))) (if (stringp loc-or-error) (progn @@ -584,7 +581,7 @@ Otherwise return nil. CMD-MARK is set in the realgud-loc object created. ) ) -(defun realgud-track-bp-delete(text &optional cmd-mark cmdbuf ignore-file-re) +(defun realgud-track-bp-delete(text &optional cmd-mark cmdbuf ignore-re-file-list) "Do regular-expression matching to see if a breakpoint has been deleted inside string TEXT. Return a list of breakpoint locations of the breakpoints found in command buffer." @@ -690,13 +687,13 @@ loc-regexp pattern" (defun realgud-track-loc-from-selected-frame(text cmd-mark &optional - opt-regexp opt-ignore-file-re) + opt-regexp opt-ignore-re-file-list) "Return a selected frame number found in TEXT or nil if none found." (if (realgud-cmdbuf?) (let ((selected-frame-pat (realgud-cmdbuf-pat "selected-frame")) (frame-num-regexp) - (ignore-file-re (or opt-ignore-file-re - (realgud-sget 'cmdbuf-info 'ignore-file-re)))) + (ignore-re-file-list (or opt-ignore-re-file-list + (realgud-sget 'cmdbuf-info 'ignore-re-file-list)))) (if (and selected-frame-pat (setq frame-num-regexp (realgud-loc-pat-regexp selected-frame-pat))) @@ -707,7 +704,7 @@ loc-regexp pattern" (lineno (string-to-number (match-string line-group text)))) (if (and filename lineno) (realgud:file-loc-from-line filename lineno - cmd-mark nil nil ignore-file-re) + cmd-mark nil nil) nil)) nil) nil)) @@ -781,7 +778,6 @@ find a location. non-nil if we can find a location. (realgud-loc-pat-file-group loc-pat) (realgud-loc-pat-line-group loc-pat) nil - (realgud-loc-pat-ignore-file-re loc-pat) )) (if (stringp loc) (message loc) diff --git a/realgud/debugger/ipdb/init.el b/realgud/debugger/ipdb/init.el index cdcfce2..10786db 100644 --- a/realgud/debugger/ipdb/init.el +++ b/realgud/debugger/ipdb/init.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2016 Free Software Foundation, Inc +;; Copyright (C) 2016, 2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> ;; Author: Sean Farley <s...@farley.io> @@ -49,6 +49,14 @@ realgud-loc-pat struct") :file-group 1 :line-group 2)) +;; An initial list of regexps that don't generally have files +;; associated with them and therefore we should not try to find file +;; associations for them. This list is used to seed a field of the +;; same name in the cmd-info structure inside a command buffer. A user +;; may add additional files to the command-buffer's re-ignore-list. +(setf (gethash "ignore-re-file-list" realgud:ipdb-pat-hash) + (list realgud-python-ignore-file-re)) + (setf (gethash "prompt" realgud:ipdb-pat-hash) (make-realgud-loc-pat :regexp "^ipdb[>] " diff --git a/realgud/debugger/jdb/core.el b/realgud/debugger/jdb/core.el index 2d8b543..a64cb4b 100644 --- a/realgud/debugger/jdb/core.el +++ b/realgud/debugger/jdb/core.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2014, 2016 Free Software Foundation, Inc +;; Copyright (C) 2014, 2016, 2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> @@ -9,7 +9,6 @@ ;; 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" @@ -54,54 +53,56 @@ ca.mgcill.rocky.snpEff.main => ca/mcgill/rocky/snpEff" (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) +(defun realgud:jdb-find-file(marker filename directory) "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." +we will prompt for a mapping and save that the remap." (let* ((transformed-file) + (cmdbuf (realgud-get-cmdbuf)) + (ignore-re-file-list (realgud-cmdbuf-ignore-re-file-list cmdbuf)) + (filename-remap-alist (realgud-cmdbuf-filename-remap-alist)) (stripped-filename (realgud:strip filename)) (gud-jdb-filename (gud-jdb-find-source stripped-filename)) + (remapped-filename + (assoc filename filename-remap-alist)) ) (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))) + ((realgud:file-ignore filename ignore-re-file-list) + (message "tracking ignored for %s" filename) nil) + (t + (if remapped-filename + (if (file-exists-p (cdr remapped-filename)) + (cdr remapped-filename) + ;; else remove from map since no find + (and (realgud-cmdbuf-filename-remap-alist= + (delq (assoc remapped-filename filename-remap-alist) + filename-remap-alist)) + 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 "%s.java"))) + (realgud:find-file marker guess-filename + directory "%s.java"))) (when (and remapped-filename (file-exists-p remapped-filename)) - (puthash stripped-filename remapped-filename realgud:jdb-file-remap) - remapped-filename + (realgud-cmdbuf-filename-remap-alist= + (cons + (cons filename remapped-filename) + filename-remap-alist)) )) )) - )) - ) + ))) (defun realgud:jdb-loc-fn-callback(text filename lineno source-str - ignore-file-re cmd-mark) + cmd-mark directory) (realgud:file-loc-from-line filename lineno cmd-mark source-str nil - ignore-file-re 'realgud:jdb-find-file)) + 'realgud:jdb-find-file directory)) (defun realgud:jdb-parse-cmd-args (orig-args) "Parse command line ARGS for the annotate level and name of script to debug. diff --git a/realgud/debugger/jdb/init.el b/realgud/debugger/jdb/init.el index b29602a..39aada7 100644 --- a/realgud/debugger/jdb/init.el +++ b/realgud/debugger/jdb/init.el @@ -29,7 +29,8 @@ name. For example java.lang.Class.getDeclaredMethods") backtrace, prompt, etc. The values of a hash entry is a realgud-loc-pat struct") -(setf (gethash "loc-callback-fn" realgud:jdb-pat-hash) 'realgud:jdb-loc-fn-callback) +(setf (gethash "loc-callback-fn" realgud:jdb-pat-hash) + 'realgud:jdb-loc-fn-callback) ;; realgud-loc-pat that describes a jdb location generally shown ;; before a command prompt. For example: diff --git a/realgud/debugger/pdb/init.el b/realgud/debugger/pdb/init.el index cf0f743..064d29f 100644 --- a/realgud/debugger/pdb/init.el +++ b/realgud/debugger/pdb/init.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Free Software Foundation, Inc +;; Copyright (C) 2015-2016, 2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> @@ -48,6 +48,14 @@ realgud-loc-pat struct") :file-group 1 :line-group 2)) +;; An initial list of regexps that don't generally have files +;; associated with them and therefore we should not try to find file +;; associations for them. This list is used to seed a field of the +;; same name in the cmd-info structure inside a command buffer. A user +;; may add additional files to the command-buffer's re-ignore-list. +(setf (gethash "ignore-re-file-list" realgud:pdb-pat-hash) + (list realgud-python-ignore-file-re)) + (setf (gethash "prompt" realgud:pdb-pat-hash) (make-realgud-loc-pat :regexp "^[(]+Pdb[)]+ " diff --git a/realgud/debugger/rdebug/init.el b/realgud/debugger/rdebug/init.el index 4b4a024..85ce152 100644 --- a/realgud/debugger/rdebug/init.el +++ b/realgud/debugger/rdebug/init.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2010, 2011, 2016 Free Software Foundation, Inc +;; Copyright (C) 2010-2011, 2016, 2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> @@ -33,9 +33,16 @@ realgud-loc-pat struct") :regexp "\\(?:source \\)?\\(\\(?:[a-zA-Z]:\\)?\\(?:.+\\)\\):\\([0-9]+\\).*\\(?:\n\\|$\\)" :file-group 1 :line-group 2 - :ignore-file-re "(eval)" )) +;; An initial list of regexps that don't generally have files +;; associated with them and therefore we should not try to find file +;; associations for them. This list is used to seed a field of the +;; same name in the cmd-info structure inside a command buffer. A user +;; may add additional files to the command-buffer's re-ignore-list. +(setf (gethash "ignore-re-file-list" realgud-rdebug-pat-hash) + '("(eval)")) + ;; Regular expression that describes a rdebug command prompt ;; For example: ;; (rdb:1) diff --git a/realgud/debugger/trepan/core.el b/realgud/debugger/trepan/core.el index a844208..7f48803 100644 --- a/realgud/debugger/trepan/core.el +++ b/realgud/debugger/trepan/core.el @@ -77,10 +77,10 @@ future, we may also consult RUBYPATH." )) (defun realgud:trepan-loc-fn-callback(text filename lineno source-str - ignore-file-re cmd-mark) + cmd-mark directory) (realgud:file-loc-from-line filename lineno - cmd-mark source-str nil nil - 'realgud:trepan-find-file)) + cmd-mark source-str nil + 'realgud:trepan-find-file directory)) ;; FIXME: I think this code and the keymaps and history ;; variable chould be generalized, perhaps via a macro. diff --git a/realgud/debugger/trepan/init.el b/realgud/debugger/trepan/init.el index f66e3e8..ac2784f 100644 --- a/realgud/debugger/trepan/init.el +++ b/realgud/debugger/trepan/init.el @@ -46,9 +46,16 @@ realgud-loc-pat struct") :file-group 1 :line-group 2 :text-group 3 - :ignore-file-re "(eval: .*)" )) +;; An initial list of regexps that don't generally have files +;; associated with them and therefore we should not try to find file +;; associations for them. This list is used to seed a field of the +;; same name in the cmd-info structure inside a command buffer. A user +;; may add additional files to the command-buffer's re-ignore-list. +(setf (gethash "ignore-re-file-list" realgud:trepan-pat-hash) + '("(eval: .*)")) + ;; Regular expression that describes a trepan command prompt ;; For example: ;; (trepan): diff --git a/realgud/debugger/trepan2/core.el b/realgud/debugger/trepan2/core.el index 00651d7..07c97b7 100644 --- a/realgud/debugger/trepan2/core.el +++ b/realgud/debugger/trepan2/core.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2010-2012, 2014-2016 Free Software Foundation, Inc +;; Copyright (C) 2010-2012, 2014-2016, 2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> @@ -15,7 +15,6 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. -(require 'compile) ;; for compilation-find-file (require 'load-relative) (require-relative-list '("../../common/track" "../../common/core" @@ -48,48 +47,53 @@ filesystem") ;; FIXME: this code could be generalized and put in a common place. -(defun realgud:trepan2-find-file(filename) +(defun realgud:trepan2-find-file(marker filename directory) "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) + (cmdbuf (realgud-get-cmdbuf)) (stripped-filename (realgud:strip filename)) - (ignore-file-re realgud-python-ignore-file-re) + (ignore-re-file-list (realgud-cmdbuf-ignore-re-file-list cmdbuf)) + (filename-remap-alist (realgud-cmdbuf-filename-remap-alist)) + (remapped-filename + (assoc filename filename-remap-alist)) ) (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 + ((realgud:file-ignore filename ignore-re-file-list) + (message "tracking ignored for %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 "%s.py"))) - (when (and remapped-filename (file-exists-p remapped-filename)) - (puthash filename remapped-filename realgud-file-remap) - remapped-filename - )) - )) - )) - )) + (if remapped-filename + (if (file-exists-p (cdr remapped-filename)) + (cdr remapped-filename) + ;; else remove from map since no find + (and (realgud-cmdbuf-filename-remap-alist= + (delq (assoc remapped-filename filename-remap-alist) + filename-remap-alist)) + nil)) + ;; else + (let ((remapped-filename)) + (setq remapped-filename + (buffer-file-name + (realgud:find-file marker stripped-filename + directory "%s.py"))) + (when (and remapped-filename (file-exists-p remapped-filename)) + (realgud-cmdbuf-filename-remap-alist= + (cons + (cons filename remapped-filename) + filename-remap-alist)) + )) + )) + ))) (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 nil - 'realgud:trepan2-find-file)) + cmd-mark directory) + (realgud:file-loc-from-line filename lineno cmd-mark source-str nil + 'realgud:trepan2-find-file directory)) ;; FIXME: I think this code and the keymaps and history ;; variable chould be generalized, perhaps via a macro. diff --git a/realgud/debugger/trepan2/init.el b/realgud/debugger/trepan2/init.el index 62221e1..ecc206e 100644 --- a/realgud/debugger/trepan2/init.el +++ b/realgud/debugger/trepan2/init.el @@ -41,6 +41,14 @@ realgud-loc-pat struct") (setf (gethash "loc" realgud:trepan2-pat-hash) realgud:python-trepan-loc-pat) +;; An initial list of regexps that don't generally have files +;; associated with them and therefore we should not try to find file +;; associations for them. This list is used to seed a field of the +;; same name in the cmd-info structure inside a command buffer. A user +;; may add additional files to the command-buffer's re-ignore-list. +(setf (gethash "ignore-re-file-list" realgud:trepan2-pat-hash) + (list realgud-python-ignore-file-re)) + ;; Regular expression that describes a trepan2 prompt. ;; Note: the prompt in nested debugging ;; For example: diff --git a/realgud/debugger/trepan3k/init.el b/realgud/debugger/trepan3k/init.el index a13da4d..3b87997 100644 --- a/realgud/debugger/trepan3k/init.el +++ b/realgud/debugger/trepan3k/init.el @@ -47,6 +47,14 @@ realgud-loc-pat struct") (setf (gethash "loc" realgud:trepan3k-pat-hash) realgud:python-trepan-loc-pat) +;; An initial list of regexps that don't generally have files +;; associated with them and therefore we should not try to find file +;; associations for them. This list is used to seed a field of the +;; same name in the cmd-info structure inside a command buffer. A user +;; may add additional files to the command-buffer's re-ignore-list. +(setf (gethash "ignore-re-file-list" realgud:trepan3k-pat-hash) + (list realgud-python-ignore-file-re)) + ;; Regular expression that describes a trepan3k prompt. ;; Note: the prompt in nested debugging ;; For example: diff --git a/realgud/debugger/trepanjs/core.el b/realgud/debugger/trepanjs/core.el index 122cb44..5d4fa74 100644 --- a/realgud/debugger/trepanjs/core.el +++ b/realgud/debugger/trepanjs/core.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Free Software Foundation, Inc +;; Copyright (C) 2015-2016, 2018 Free Software Foundation, Inc ;; Author: Rocky Bernstein <ro...@gnu.org> @@ -26,12 +26,16 @@ (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. (defvar realgud:trepanjs-minibuffer-history nil "minibuffer history list for the command `realgud:trepanjs'.") +(defvar realgud:trepanjs-blacklist nil + "List of black-listed file regexp that we should ignore file tracking") + (easy-mmode-defmap realgud:trepanjs-minibuffer-local-map '(("\C-i" . comint-dynamic-complete-filename)) "Keymap for minibuffer prompting of trepanjs startup command." diff --git a/realgud/lang/python.el b/realgud/lang/python.el index d575d36..9d8822e 100644 --- a/realgud/lang/python.el +++ b/realgud/lang/python.el @@ -91,9 +91,7 @@ traceback) line." ) :num 2 :file-group 3 :line-group 4 - :ignore-file-re realgud-python-ignore-file-re) - "A realgud-loc-pat struct that describes a Python trepan - backtrace location line." ) + )) ;; Regular expression that describes a "breakpoint set" line (defconst realgud:python-trepan-brkpt-set-pat diff --git a/test/bt-helper.el b/test/bt-helper.el index a9f63d8..a35b367 100644 --- a/test/bt-helper.el +++ b/test/bt-helper.el @@ -12,7 +12,10 @@ (defvar temp-cmdbuf) (defvar temp-bt) (defvar realgud-pat-hash) -) + ) + +(if (or (<= emacs-major-version 24)) + (defalias 'font-lock-ensure 'font-lock-fontify-buffer)) (defun setup-bt-vars(debugger-name) "Sets up globals temp-cmdbuf and temp-bt with command buffer @@ -25,7 +28,8 @@ for DEBUGGER-NAME" (gethash debugger-name realgud-pat-hash)) (switch-to-buffer nil) - )) + ) + temp-cmdbuf) (defun setup-bt(debugger-name string) @@ -37,7 +41,7 @@ for DEBUGGER-NAME and initializes it to STRING" (goto-char (point-min)) (setq buffer-read-only nil) (insert string) - (font-lock-fontify-buffer) + (font-lock-ensure) ;; Newer emacs's use: (goto-char (point-min)) ) diff --git a/test/test-bt-trepan.el b/test/test-bt-trepan.el index 0bc5e6e..d065543 100644 --- a/test/test-bt-trepan.el +++ b/test/test-bt-trepan.el @@ -15,35 +15,38 @@ (defvar temp-bt) ) -(setq temp-bt - (setup-bt "trepan" +(defun test-bt-trepan() + (setq temp-bt + (setup-bt "trepan" "--> #0 METHOD Object#gcd(a, b) in file /test/gcd.rb at line 4 #1 TOP Object#<top /gcd.rb> in file /test/gcd.rb at line 19 ")) -(with-current-buffer temp-bt - (switch-to-buffer temp-bt) - (goto-char (point-min)) - (dolist (pair - '( - ("#" . realgud-backtrace-number ) - ("METHO" . font-lock-keyword-face ) - ("Objec" . font-lock-constant-face ) - ("#" . font-lock-function-name-face ) - ("(" . font-lock-variable-name-face ) - ("/test" . realgud-file-name) - ("line " . realgud-line-number) - ("#" . realgud-backtrace-number) - ("Objec" . font-lock-constant-face ) - ("<top" . font-lock-variable-name-face) - ("/test" . realgud-file-name) - ("line " . realgud-line-number) - )) - (search-forward (car pair)) - (assert-equal (cdr pair) - (get-text-property (point) 'face)) - ) - ) + (with-current-buffer temp-bt + (switch-to-buffer temp-bt) + (goto-char (point-min)) + (dolist (pair + '( + ("#" . realgud-backtrace-number ) + ("METHO" . font-lock-keyword-face ) + ("Objec" . font-lock-constant-face ) + ("#" . font-lock-function-name-face ) + ("(" . font-lock-variable-name-face ) + ("/test" . realgud-file-name) + ("line " . realgud-line-number) + ("#" . realgud-backtrace-number) + ("Objec" . font-lock-constant-face ) + ("<top" . font-lock-variable-name-face) + ("/test" . realgud-file-name) + ("line " . realgud-line-number) + )) + (search-forward (car pair)) + (assert-equal (cdr pair) + (get-text-property (point) 'face)) + ) + )) + +(test-bt-trepan) (end-tests) diff --git a/test/test-bt-trepan2.el b/test/test-bt-trepan2.el index e1be16e..6e7ead5 100644 --- a/test/test-bt-trepan2.el +++ b/test/test-bt-trepan2.el @@ -51,27 +51,27 @@ realgud:trepan2-pat-hash)) -(let* ((triple - (realgud:backtrace-add-text-properties - realgud-pat-bt "" - "->0 gcd(a=3, b=5) called from file '/test/gcd.py' at line 28 -##1 <module> exec() '/test/gcd.py' at line 41" - "->")) - (string-with-props (car triple))) - (dolist (pair - '( - ("->0" . (0 . 28) ) - ("##1" . (1 . 41) ) - )) - (string-match (car pair) string-with-props) - (assert-equal (cddr pair) - (realgud-loc-line-number (get-text-property - (match-beginning 0) 'loc - string-with-props))) +;; (let* ((triple +;; (realgud:backtrace-add-text-properties +;; realgud-pat-bt "" +;; "->0 gcd(a=3, b=5) called from file '/test/gcd.py' at line 28 +;; ##1 <module> exec() '/test/gcd.py' at line 41" +;; "->")) +;; (string-with-props (car triple))) +;; (dolist (pair +;; '( +;; ("->0" . (0 . 28) ) +;; ("##1" . (1 . 41) ) +;; )) +;; (string-match (car pair) string-with-props) +;; (assert-equal (cddr pair) +;; (realgud-loc-line-number (get-text-property +;; (match-beginning 0) 'loc +;; string-with-props))) - (assert-equal (cadr pair) - (get-text-property - (match-beginning 0) 'frame-num - string-with-props)))) +;; (assert-equal (cadr pair) +;; (get-text-property +;; (match-beginning 0) 'frame-num +;; string-with-props)))) (end-tests) diff --git a/test/test-file.el b/test/test-file.el index e9129d4..15cc855 100644 --- a/test/test-file.el +++ b/test/test-file.el @@ -4,6 +4,7 @@ (require 'test-simple) (load-file "../realgud/common/loc.el") (load-file "../realgud/common/file.el") +(load-file "../realgud/common/buffer/helper.el") ;; Note the below line number is tested so it must match what's listed ;; below. @@ -21,15 +22,12 @@ (test-simple-start) (eval-when-compile - (defvar realgud-file-remap) (defvar test-filename) (defvar test-file-loc) (defvar remap-filename) (defvar old-compilation-find-file) ) -(clrhash realgud-file-remap) - (setq old-compilation-find-file (symbol-function 'compilation-find-file)) (setq test-filename (symbol-file 'test-simple)) @@ -95,11 +93,10 @@ ) -(puthash remap-filename test-filename realgud-file-remap) - -(assert-t (realgud-loc? - (realgud:file-loc-from-line remap-filename 30)) - "Ok loc creation with remap - no cmd marker") +;; Need to set up a command buffer +;; (assert-t (realgud-loc? +;; (realgud:file-loc-from-line remap-filename 30)) +;; "Ok loc creation with remap - no cmd marker") ;; FIXME: don't know why this fails in batch ;; (assert-equal diff --git a/test/test-trepan2.el b/test/test-trepan2.el index 6197357..c5e7e4e 100644 --- a/test/test-trepan2.el +++ b/test/test-trepan2.el @@ -5,10 +5,12 @@ (load-file "../realgud/debugger/trepan2/trepan2.el") (load-file "../realgud/debugger/trepan2/core.el") (load-file "../realgud.el") +(load-file "./bt-helper.el") (declare-function trepan2-parse-cmd-args 'realgud:trepan2) (declare-function realgud:trepan2-find-file 'realgud:trepan2-core) (declare-function __FILE__ 'load-relative) +(declare-function setup-bt-vars 'bt-helper) (test-simple-start) @@ -30,16 +32,25 @@ (trepan2-parse-cmd-args '("trepan2" "program.py" "foo"))) +(eval-when-compile + (defvar test-python-file) + ) + (note "realgud:trepan2-find-file") -(assert-nil (realgud:trepan2-find-file "<string>") - "Should ignore psuedo file") -(eval-when-compile - (defvar test-python-file)) +(defun test-trepan2-find-file() + (let ((temp-cmdbuf (setup-bt-vars "trepan2"))) + (with-current-buffer temp-cmdbuf + (assert-nil + (realgud:trepan2-find-file (mark) "<string>" nil) + "Should ignore pseudo file") + + (set (make-local-variable 'test-python-file) + (concat (file-name-directory (__FILE__)) "gcd.py")) + (assert-equal test-python-file + (realgud:trepan2-find-file (mark) test-python-file nil) + "Should find 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") +(test-trepan2-find-file) (end-tests)