Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger incorrectly steps through conditional forms #437

Open
vspinu opened this issue Aug 20, 2017 · 6 comments
Open

Debugger incorrectly steps through conditional forms #437

vspinu opened this issue Aug 20, 2017 · 6 comments
Assignees

Comments

@vspinu
Copy link
Contributor

vspinu commented Aug 20, 2017

Once #435 is in, try

#dbg
(defn tt [a]
  (let [b (+ a 1)]
    #?(:clj (do
              (loop [b b]
                (if (pos? b)
                  (recur (- b 1))
                  (println "clj"))))
       :cljs (println "cljs"))))

(tt 2)

The debugger within :clj form breaks almost immediately.

@bbatsov
Copy link
Member

bbatsov commented Feb 7, 2020

@FiV0 You might consider taking a stab at this one as well.

@FiV0
Copy link
Contributor

FiV0 commented Feb 7, 2020

@bbatsov Had seen it. You can assign it to me if you want.

@FiV0
Copy link
Contributor

FiV0 commented Feb 8, 2020

@bbatsov @vspinu For this one I need some pointers/help. Consider the following code

#dbg
#?(:cljs (+ 1 2) :clj (inc (inc 1)))

In the maybe-debug function

(defn- maybe-debug
"Return msg, prepared for debugging if code contains debugging macros."
[{:keys [code ns] :as msg}]
;; The best way of checking if there's a #break reader-macro in
;; `code` is by reading it, in which case it toggles `has-debug?`.
(let [has-debug? (atom false)

the code is still in string form, so something like "#dbg\n#?(....)". Once the evaluation gets to instrument-and-eval
(defn instrument-and-eval [form]
(let [form1 (ins/instrument-tagged-code form)]
;; (ins/print-form form1 true false)
(try

the code has been "read" as clojure data and the form is just (inc (inc 1)), so somewhere in between some reading seems to happen. I am assuming this happens in some lower handler in the nrepl. Is that correct? Essentially when reading such a form we need to do something like (read-string {:read-cond :preserve} "#dbg\n#?(....)") as otherwise the bookkeeping of where stuff is located fails.
Maybe it's this line?
https://github.com/nrepl/nrepl/blob/1cc9baae631703c184894559a2232275dc50dff6/src/clojure/nrepl/middleware/interruptible_eval.clj#L110-L111

@bbatsov
Copy link
Member

bbatsov commented Feb 9, 2020

Yeah, I think that's the line. nREPL basically just delegates to Clojure's own REPL, so it wouldn't have to reimplement its functionality.

@FiV0
Copy link
Contributor

FiV0 commented Feb 9, 2020

@bbatsov You think it would be ok to add an option to nrepl so that code is read with :preserve. We could then do a first read via nrepl, locate stuff corretly in cider-nrepl, do a second read also in cider-nrepl and then do stuff as usual. I don't see how to solve this one otherwise.

@bbatsov
Copy link
Member

bbatsov commented Feb 9, 2020

Probably that'd be fine. What exactly does :preserve do? If it doesn't affect the evaluation then we can safely enable it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants