Bug 414135 - Add support for suspending on exceptions in user code only
Summary: Add support for suspending on exceptions in user code only
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-31 09:37 EDT by Marcin Wisnicki CLA
Modified: 2016-05-09 05:49 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcin Wisnicki CLA 2013-07-31 09:37:19 EDT
Please add ability to debug only user code similar to Visual Studio.

This means that any exceptions that are not caused by user code are ignored.

So for example I can put a break on all thrown Throwables but won't be bothered by any internal errors of sun.misc.Launcher while it loads my code.

I think it is enough to ignore exceptions that do not contain user code anywhere in the stack trace except maybe for threads whose creation was triggered by user code.
Comment 1 Michael Rennie CLA 2013-07-31 13:30:57 EDT
You can do this now with step filters and customizing exception breakpoints.

See the step filtering preference page: Java > Debug > Step Filtering

See the breakpoint properties for an exception breakpoint (either in the properties dialog Filtering page or in the detail pane).

Is that what you were looking for?
Comment 2 Marcin Wisnicki CLA 2013-07-31 14:03:07 EDT
Breakpoint properties only allow filtering based on origin of exception (place where it was thrown), not by presence of certain class/package in the stack trace.

For example, assume my code (com.example.Main) calls java.lang.ClassLoader.loadClass("invalid") which throws ClassNotFoundException.

That same exception is thrown multiple times during normal application startup somewhere in sun.misc.Launcher and other places.

If I create inclusion breakpoint filter on "com.example.*" then eclipse will not suspend when ClassLoader raises exception while being called by Main.

If I create exclusion filter on ClassLoader.loadClass to avoid Launcher errors then I will also miss errors from Main.
Comment 3 Marcin Wisnicki CLA 2013-08-01 04:48:57 EDT
I'll also add that step filters have similar weakness when it comes to stepping through code, i.e. even when I enable filter "sun.*" I will step into methods called by "sun.*". Whereas a useful behaviour would be to skip anything called by sun.* unless it belongs to user code.
Comment 4 Michael Rennie CLA 2013-08-01 11:39:58 EDT
I like this idea, I think as first step we could provide this support as an option for exception breakpoints; i.e. like the option we have to suspend on sub-classes of exceptions, we could add another to only suspend in user-code (or similar).
Comment 5 Marcin Wisnicki CLA 2013-09-10 18:13:42 EDT
I've managed to implement it as a plugin with breakpoint listener (http://goo.gl/2GUftb).

It's on https://github.com/mwisnicki/eclipse.justmycode .

Unfortunately this approach is quite slow but I'm not sure if it can be accelerated without help from JVM (except maybe by implementing it as a native JVMTI agent).
Comment 6 Michael Rennie CLA 2013-09-11 09:45:15 EDT
(In reply to Marcin Wisnicki from comment #5)
> I've managed to implement it as a plugin with breakpoint listener
> (http://goo.gl/2GUftb).
> 
> It's on https://github.com/mwisnicki/eclipse.justmycode .
> 
> Unfortunately this approach is quite slow but I'm not sure if it can be
> accelerated without help from JVM (except maybe by implementing it as a
> native JVMTI agent).

Very cool! We could probably quite easily add code like that to our normal exception breakpoint and just add a "just my code" option.

Also note that you could get to the resource via the breakpoint object as well rather than using 

'Object sourceElement = sourceLocator.getSourceElement(frame);' 

because using the source locator:
1. can cause a prompt dialog to show when user interaction is needed for location resolution.
2. is slow (as you noted)

There are also a bunch of utilities in org.eclipse.jdt.internal.debug.ui.BreakpointUtils that can help.

If you are interested in providing a patch for Eclipse the first place to start would be org.eclipse.jdt.internal.debug.core.breakpoints.JavaExceptionBreakpoint. You would also have to sign the CLA.