Can't breakpoint the last statement of a code block in Eclipse

时间秒杀一切 提交于 2019-11-29 03:56:32

To set a breakpoint at the end of an arbitrary block is not possible (without byte-code hacking).

If it is a method body, then it is possible: you can set a Method breakpoint. Do this by double-clicking on the method definition line:

(notice the little arrow?) and then in the breakpoints view, select the breakpoint to see both an Entry and an Exit option tick-box in the displayed properties:

The little arrow indicates that, by default, we have set a breakpoint on entry to the method.

Now select Exit (and deselect Entry) and you will see this in the breakpoints view:

(There is a different little arrow, indicating an exit breakpoint.)

Now run the debugger on this little breaker ('Debug As a Java Application') and it will stop on the exit brace of the method:

and the local variables (only a in this case) are now visible (with the correct values) in the Variables view:

It is worth noticing that this type of breakpoint traps method exit however this happens -- even, for example, if we exit by throwing an exception.

You can highlight the expression on the right hand side of the assignment and press Ctrl+Shift+I (for 'inspect' I think). It will evaluate the expression and give you the result. That way you can know the value of b without needing a breakpoint after the assignment.

Duckies

I'm honestly not sure what's going on in your Eclipse installation. I'm working in Java and just tried everything I can think of. I checked a static method for breakpoint on the last line that is not a } and it works just fine. I checked the same for a non-static method.

It breaks down this way: you can't breakpoint on a curly brace end, but it will default to whatever is under the curly brace, line-wise. So if you have a nested function:

public int DoesStuff(int x, int y) {
    if(x > y) {
        DoThing;
    }
    else {
        DoOtherThing;
    }
}

Then the last two braces cannot be break-pointed, but DoThing and DoOtherThing can. Make sense?

Aman

If ending statement is assignment and it is on local variable why do you want to see its value because it will not be in scope anymore and can't effect.

If it's setting same class attribute then you can see it when you return from this call and you have the object on which this method operated.

Although this doesn't answer the question but I am trying to understand the use-case of your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!