Eclipse: Hitting A Breakpoint After The Fact
- Stop at a breakpoint
- Realize that you want to step through a method called a few lines back
- Put a breakpoint in that method
- Highlight an expression that uses the method in the java editor and from the context menu select Inspect
That should do it! Before you see the value in the inspection pop-up, your debugger should hit the breakpoint that you just created. Very cool.
From http://greensopinion.blogspot.com/
David Green is a software developer at MAKE Technologies creating developer tools based on Java and the Eclipse platform. He is primarily interested in MDD and MDE development techniques and how they can be effectively applied to the legacy modernization problem. David is a DZone MVB and is not an employee of DZone and has posted 18 posts at DZone. You can read more from them at their website.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
James Sugrue replied on Mon, 2009/02/02 - 6:43am
dmissoh replied on Mon, 2009/02/02 - 2:24pm
Hi David,
that's a nice one. Thanks for your usefull tip!
Steven replied on Mon, 2009/02/02 - 4:53pm
good one, thanks.
i used to just trigger a partial compile with some meaningless temporary code change which re-runs the method (thus hitting the breakpoint again)
Steven replied on Mon, 2009/02/02 - 4:53pm
good one, thanks.
i used to just trigger a partial compile with some meaningless temporary code change which re-runs the method (thus hitting the breakpoint again)
David Karr replied on Mon, 2009/02/02 - 7:34pm
You may be missing the most powerful way to do this. If your method has any side effects, or depends on any side effects, calling the method again the way you describe may not be sufficient. You often need to just "back up" to before the method was called, set the breakpoint, and start stepping again.
This can be done with the "drop to frame" feature, which was recently blogged about at http://www.javalobby.org/forums/thread.jspa?threadID=15271&tstart=0 (why don't I get the option to insert a link here?).
You simply right-click on the entry at the top of the stack, select "drop to frame", and the step cursor is at the top of the method again, rewinding history.
David Green replied on Tue, 2009/02/10 - 6:42pm
@David Karr, "drop to frame" does indeed look powerful. I'm using the trick described here in a lot of cases because a) "drop to frame" is often disabled in the Eclipse UI, and b) often I don't want to re-run the whole method.