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

Conditional breakpoints #303

Merged
merged 1 commit into from Mar 3, 2016

Conversation

Projects
None yet
3 participants
@grammati
Contributor

grammati commented Feb 26, 2016

Not entirely ready, but I would like to get some more eyes on this and see whether others agree with the approach.

The feature is conditional breakpoints - that is, breakpoints that will only enter the debugger when an expression is truthy.

Conditions are attached to forms as :break/when metadata. Example:

(for [i (range 3)]
  #dbg ^{:break/when (odd? i)
  (inc i))

Evaluating this, you will stop in the debugger only once, when i is 1.

However, the primary use case (at least for me) is likely to be instrumenting a function with a conditional breakpoint. I have implemented this in cider as C-u C-u C-M-x, which prompts for an expression. This can be an expression of the function arguments. The form is then sent to cider-nrepl with #dbg ^{:break/when (the expression)} prefixed.

Making this work required a slightly hairy special-case that moves :break/when metadata down from the defn form and onto the forms inside the body of the macroexpanded function.

To get some confidence that I have the slightest idea what I'm doing, I wrote a bunch of new tests, in a new test namespace. These interact with cider-nrepl only by sending and receiving nrepl messages, just as a client (i.e. emacs) would.

Thanks everyone, please let me know what you think.

@Malabarba

This comment has been minimized.

Show comment
Hide comment
@Malabarba

Malabarba Feb 26, 2016

Member

Wow. First of all, thanks a ton! :-)
This is a feature that's been requested several times already, so it's very welcome.
Also, thanks so much for writing so many tests! :-)

I'll make some comments directly in the code, but overall I like how you've implemented it.

Member

Malabarba commented Feb 26, 2016

Wow. First of all, thanks a ton! :-)
This is a feature that's been requested several times already, so it's very welcome.
Also, thanks so much for writing so many tests! :-)

I'll make some comments directly in the code, but overall I like how you've implemented it.

Show outdated Hide outdated project.clj

@grammati grammati referenced this pull request Feb 26, 2016

Closed

Conditional break #1591

@grammati

This comment has been minimized.

Show comment
Hide comment
@grammati

grammati Feb 26, 2016

Contributor

I pushed a PR for a rudimentary version of the front-end portion, here: clojure-emacs/cider#1591

Contributor

grammati commented Feb 26, 2016

I pushed a PR for a rudimentary version of the front-end portion, here: clojure-emacs/cider#1591

@grammati

This comment has been minimized.

Show comment
Hide comment
@grammati

grammati Feb 28, 2016

Contributor

@Malabarba, I pushed a commit that addresses all your comments, I think.

I pared back the functionality to be just the basic conditional break. I removed the special-casing of defns that moved the condition down into the body of the fn. I can re-introduce that in another PR, where we can discuss the best interface.

I also added a few more tests, including one (unrelated to conditional breakpoints) that I think should pass but does not. Can you have a look at call-instrumented-fn-when-stepping-out? Perhaps my expectations of how the debugger should behave are just wrong.

Thanks!

Contributor

grammati commented Feb 28, 2016

@Malabarba, I pushed a commit that addresses all your comments, I think.

I pared back the functionality to be just the basic conditional break. I removed the special-casing of defns that moved the condition down into the body of the fn. I can re-introduce that in another PR, where we can discuss the best interface.

I also added a few more tests, including one (unrelated to conditional breakpoints) that I think should pass but does not. Can you have a look at call-instrumented-fn-when-stepping-out? Perhaps my expectations of how the debugger should behave are just wrong.

Thanks!

@Malabarba

This comment has been minimized.

Show comment
Hide comment
@Malabarba

Malabarba Feb 29, 2016

Member

Ok, thanks! I'll have a look at the tests when I get a chance. 👍

Member

Malabarba commented Feb 29, 2016

Ok, thanks! I'll have a look at the tests when I get a chance. 👍

Add support for conditional breakpoints
Also some new, high-level tests for the debugger.
@grammati

This comment has been minimized.

Show comment
Hide comment
@grammati

grammati Mar 3, 2016

Contributor

I rebased this onto master and pushed again

Contributor

grammati commented Mar 3, 2016

I rebased this onto master and pushed again

@Malabarba

This comment has been minimized.

Show comment
Hide comment
@Malabarba

Malabarba Mar 3, 2016

Member

Ok. Looks like your tests are good. The only 2 failures are the cljs tests which are also failing on master. I've also tested your code locally and it seems to work well.
I'm going to give this a final read and merge. 👍

Member

Malabarba commented Mar 3, 2016

Ok. Looks like your tests are good. The only 2 failures are the cljs tests which are also failing on master. I've also tested your code locally and it seems to work well.
I'm going to give this a final read and merge. 👍

Malabarba added a commit that referenced this pull request Mar 3, 2016

@Malabarba Malabarba merged commit 97a0113 into clojure-emacs:master Mar 3, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
@Malabarba

This comment has been minimized.

Show comment
Hide comment
@Malabarba

Malabarba Mar 3, 2016

Member

Ok. This should now be on clojar.
Thanks again for the feature and specially for the tests. :-)

Member

Malabarba commented Mar 3, 2016

Ok. This should now be on clojar.
Thanks again for the feature and specially for the tests. :-)

@grammati grammati deleted the grammati:conditional-break-squashed branch Apr 22, 2017

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