Skip to content

add support for lambda breakpoints #1160

Closed

Description

@gayanper
Environment
  • Operating System: Any
  • JDK version: Java8+
  • Visual Studio Code version: 1.66.2
  • Java extension version: v1.5.0
  • Java Debugger extension version: v0.40.1
Steps To Reproduce
  1. Try to place a breakpoint into a lambda expression similar to typescript
Current Result

Cannot place the beak-point.

Expected Result

Should be able to place breakpoints like in typescript code.

Additional Informations

It seems methods entry breakpoints are not supported as well. And both these type of breakpoints are not support with upstream jdt debug project.

Activity

  1. testforstephen commented on May 6, 2022

    @testforstephen
    Contributor

    method entry breakpoints are not supported in VS Code Java Debugger yet.

    Gayan Perera (@gayanper) Are you talking about lambda entry breakpoint like this https://bugs.eclipse.org/bugs/show_bug.cgi?id=579100? Right?

  2. rgrunber commented on May 6, 2022

    @rgrunber

    Is this the regression in eclipse-jdt/eclipse.jdt.debug#33 ? Should be fixed for 4.24 M3.

  3. gayanper commented on May 7, 2022

    @gayanper
    ContributorAuthor

    I was trying to add a lambda breakpoint like what is available in eclipse 2020-03. But in vscode I couldn’t find a way to add the breakpoint into a specific lambda expression in stream expression for example.

  4. testforstephen commented on May 7, 2022

    @testforstephen
    Contributor

    image

    I see Eclipse has separate menus to toggle Lambda Entry Breakpoint and Function Breakpoint, we don't have similar capabilities in VS Code yet. Currently only line breakpoints are supported, where you can set a breakpoint inside a lambda body.

    Is this the regression in eclipse-jdt/eclipse.jdt.debug#33 ? Should be fixed for 4.24 M3.

    Yes, we also find in some cases the line breakpoints inside lambda body are not working. For example, breakpoints under stream().forEach() can be hit, but breakpoints under stream().map() will be skipped.

    		List<String> users = Arrays.asList("Lambda");
    
    		users.stream().forEach(u -> {
    			System.out.println("user name: " + u); // Breakpoint at this line can be hit
    		});
    
    		users.stream().map(u -> {
    			return u;  // breakpoint at this line will be skipped.
    		});
  5. gayanper commented on May 7, 2022

    @gayanper
    ContributorAuthor

    Jinbo Wang (@testforstephen) I cannot remember top of my head we added the lambda breakpoint toggle as a public API or not. But if we do in jdt debug, could we make use of vscode support for adding breakpoints in lambda starting point. I see that it is available for javascript and typescript at least.

  6. gayanper commented on May 8, 2022

    @gayanper
    ContributorAuthor

    The correct vscode term is the inline breakpoints, which can be added today even thought they are treated as normal line breakpoints. I will check more and see if we can provide some support in jdt debug for this.
    The reason i'm more focused on this feature is that to add support for java on cloud ready IDEs such as eclipse che for example.

  7. gayanper commented on May 8, 2022

    @gayanper
    ContributorAuthor

    Further looking at i found the vscode send us the column number we added the inline breakpoint. But since our java types doesn't have that we don't receive at SetBreakpointRequest handler. What remaining is that we should be able to look at the AST from jdtls at that location and see if we have a lambda expression (not a lambda block). From that we should be able to resolve the lambda method name by doing a org.eclipse.jdt.core.ICodeAssist.codeSelect(int, int) and create an entry breakpoint.

  8. snjeza commented on May 8, 2022

    @snjeza

    The correct vscode term is the inline breakpoints, which can be added today even thought they are treated as normal line breakpoints.

    It works in VS Code Java.

    lambda

    I have used:
    VS Code 1.67
    VS Code Java: 1.6.0
    Java: embedded (17.0.2)
    Fedora 35 Xorg

  9. snjeza commented on May 8, 2022

    @snjeza

    Yes, we also find in some cases the line breakpoints inside lambda body are not working. For example, breakpoints under stream().forEach() can be hit, but breakpoints under stream().map() will be skipped.

    This is an Eclipse upstream issue. I can reproduce it in Eclipse I20220507-1800 and master.

  10. testforstephen commented on May 9, 2022

    @testforstephen
    Contributor

    The correct vscode term is the inline breakpoints, which can be added today even thought they are treated as normal line breakpoints.

    It works in VS Code Java.

    lambda

    I have used: VS Code 1.67 VS Code Java: 1.6.0 Java: embedded (17.0.2) Fedora 35 Xorg

    Interesting. When setting inline breakpoints in VS Code, Java Debugger only respects line numbers but ignores the column numbers, they will actually be taken as line breakpoints. It seems registering line breakpoints on the same line twice can handle the case of having inline lambda body in one line well.

    But the approach Gayan Perera (@gayanper) mentioned above should be a better approach to handle inline breakpoints systematically.

  11. gayanper commented on May 9, 2022

    @gayanper
    ContributorAuthor

    Jinbo Wang (@testforstephen) i think setting a line breakpoint in java debugger stops on all locations in that line. When you have in-line lambda, the location includes the entry point of that lambda method as well. It works in other Eclipse the same way without any special treatment.

  12. testforstephen commented on May 9, 2022

    @testforstephen
    Contributor

    Jinbo Wang (@testforstephen) i think setting a line breakpoint in java debugger stops on all locations in that line.

    Have a look again, VS Code Java Debugger provides the same behavior. When setting a breakpoint in a line, VS Code Java Debugger actually will register BreakpointRequests at all valid locations in that line. The valid locations are fetched from the JDI API ReferenceType#locationsOfLine(int lineNumber), which returns all statement locations in that line, but not the entry point of a lambda expression.

  13. testforstephen commented on Feb 10, 2023

    @testforstephen
    Contributor

    Closing it since this has been supported in latest debugger version.

  14. dmarrazzo commented on Dec 5, 2024

    @dmarrazzo

    I'm using this version:

    Version: 1.95.3
    Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
    Date: 2024-11-13T14:50:04.152Z
    OS: Linux x64 6.11.10-300.fc41.x86_64
    

    along with Language Support for Java(TM) by Red Hat
    v1.38.2024120508 (pre-release)

    I can set the in-line breakpoint, but as I start the program in debug mode they appear disabled and don't work (the red bullet becomes grayed out).

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions