Ignoring caught exceptions in the debugger

0

The debugger in Firefox has long had the option to pause the execution of a script when an exception is thrown. However, the problem with this ‘pause on exceptions’ option is that it always pauses on *all* exceptions.  Most of the time when debugging a script, we are only interested in pausing on exceptions that are not going to be caught.

To make the ‘pause on exceptions’ option more useful, I’ve added an option to ‘ignore caught exceptions’. When an exception is thrown with this option turned on (the default), the debugger first walks up the JavaScript call stack, and checks the return address for each frame. If one of these return addresses is in the scope of a catch block, the exception is ignored. You can find the bug page for this feature here.

To figure out whether a given bytecode address is in the scope of a catch block, I’ve used the set of try notes that SpiderMonkey generates for each script. These are used internally to implement stack unwinding when an exception is thrown, and completely describe the scope of each catch block. In other words: they are exactly what we need.

The above approach is straightforward, and works great 80% of the time. There are a couple of caveats that you should be aware of, however. Most importantly, if an exception will be caught by C++ code, there’s no way for us to tell up front, so the exception won’t be ignored in that case. This is not a problem for any web based code, but it might be a problem when debugging chrome code.

Since perfect detection is impossible, the best we can do is an approximation that doesn’t give us any false positives. Unfortunately, we currently cannot distinguish conditional catch blocks (which are a SpiderMonkey feature) from unconditional ones, so we do get such false positives if the condition evaluates to false (we will still ignore the exception in this case). This is a problem we can fix, however (conditional catch blocks have a well defined bytecode sequence that we can detect), and in any case, it’s not a problem for any web based code, since conditional catch blocks are only implemented in Firefox.

I’ve just landed the final patch on mozilla-inbound, so you should be able to start playing with this new feature soon. You can turn ignoring caught exceptions on or off in the debugger menu. Note that the option is turned on by default, so you might notice some change in the debugger’s default behavior:

Categories: Uncategorized

No responses {+}

Post Your Comment