Skip to content

Improve support for method breakpoints #426

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

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

gayanper
Copy link
Contributor

@gayanper gayanper commented Jul 9, 2022

Now method breakpoints can added by adding a line breakpoint at method
header.

@gayanper
Copy link
Contributor Author

gayanper commented Jul 9, 2022

@testforstephen Please review this and let me know what you think ?

@testforstephen testforstephen self-requested a review July 11, 2022 13:11
@testforstephen
Copy link
Contributor

Had a try and found two issues:

  • If I add a breakpoint to method header first and then add an usual line breakpoint to the method body, all breakpoints are skipped during debugging.
    image
  • Add a breakpoint to the method header, I see it applies to all overloaded methods and they all might be hit on method entry.
    image

I'm thinking a different approach to support the breakpoint added through method header. I think it might be easier to handle it as a line breakpoint instead of method breakpoint.

  1. Reuse JdtSourceLookUpProvider.getFullyQualifiedName(...) to return FQN#methodSignature if the line points to method header.
  2. In the line breakpoint class Breakpoint.collectLocations(...), we can find the JDI method using method signature first and then get the target breakpoint location using com.sun.jdi.Method#location().

@gayanper
Copy link
Contributor Author

Had a try and found two issues:

  • If I add a breakpoint to method header first and then add an usual line breakpoint to the method body, all breakpoints are skipped during debugging.
    image
  • Add a breakpoint to the method header, I see it applies to all overloaded methods and they all might be hit on method entry.
    image

I'm thinking a different approach to support the breakpoint added through method header. I think it might be easier to handle it as a line breakpoint instead of method breakpoint.

  1. Reuse JdtSourceLookUpProvider.getFullyQualifiedName(...) to return FQN#methodSignature if the line points to method header.
  2. In the line breakpoint class Breakpoint.collectLocations(...), we can find the JDI method using method signature first and then get the target breakpoint location using com.sun.jdi.Method#location().

Yes it might be more simpler and efficient than the method entry request. But will it work for decompiled classes since there is no source location available ? And i wonder if we could use the same for lambda and BreakpointLocations implementation so that it will be more user friendly to add breakpoint to step into just selected method invocation in a expression with many method invocations. WDYT ?

@gayanper
Copy link
Contributor Author

@testforstephen I will try to change the fix with your suggestion, I think we can support method breakpoints better with your suggestion, specially overcoming the overloaded problem with less effort. About lambda I think we might be able to do the same if we find the correct method invocation signature as the FQN. Thanks for the suggestion, it makes the solution more extendable.

@testforstephen
Copy link
Contributor

But will it work for decompiled classes since there is no source location available ?

If the classfile doesn't include the source location info, current breakpoint policy cannot work.

And i wonder if we could use the same for lambda and BreakpointLocations implementation so that it will be more user friendly to add breakpoint to step into just selected method invocation in a expression with many method invocations.

VS Code 1.69 added a new capability to step into targets, we can adopt it in the scenario of multiple chain calls in the same line.

@gayanper
Copy link
Contributor Author

@testforstephen I have reworked the solution, please check and let me know.

@gayanper
Copy link
Contributor Author

@testforstephen Do you think if we need to comparison of generic method signature ?

Copy link
Contributor

@testforstephen testforstephen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit works pretty well.

Another improvement we can optimize is the breakpoint event reason. Currently the method header breakpoint stops with the reason "Paused on Breakpoint", it would be better if it can displayed as "Paused on Function Breakpoint". One approach we can use is to store some additional property via BreakpointRequest#putProperty(), and use that to distinguish the BreakpointEvent reason.

@gayanper
Copy link
Contributor Author

Will improve this on Monday

@testforstephen
Copy link
Contributor

@testforstephen Do you think if we need to comparison of generic method signature ?

I think checking the method signature is enough. I see current implementation is reusing binding#getKey(), which considers both generic signature and signature. if it works, that's ok.

@gayanper
Copy link
Contributor Author

@testforstephen Do you think if we need to comparison of generic method signature ?

I think checking the method signature is enough. I see current implementation is reusing binding#getKey(), which considers both generic signature and signature. if it works, that's ok.

Then let’s improve this once we have the JDT API i tagged you in.

@gayanper gayanper force-pushed the line-to-method branch 2 times, most recently from 79cb06b to b8ef001 Compare July 18, 2022 12:39
Now method breakpoints can added by adding a line breakpoint at method
header.
Copy link
Contributor

@testforstephen testforstephen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gayanper It works well for me. Thanks for contribution.

@testforstephen testforstephen merged commit 1fcbe70 into microsoft:main Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants