I wanted to tell you all about some of the exciting debugger features we’ve been working on, which will be in Flex Builder 4, including several of the most common requests. All of the features listed below are in the preview release of Flex Builder that we gave out at MAX, with the, um, exception of exception breakpoints, which are not yet in the product. If you were at MAX, give these features a try, and let us know your feedback! If you weren’t able to make it to MAX, don’t worry, this stuff will eventually show up in a beta on Adobe Labs, and then of course in the final product as well.
Suppose you have set a breakpoint, but that line of code is reached hundreds of times, and you only care about the case where a variable ‘x’ is unexpectedly equal to null. Just right-click on the breakpoint, go to its properties, and add the condition:
For some extra breakpointy goodness, you can also set a hit count on any breakpoint — e.g. a hit count of 5 means, don’t halt until the fifth time that line of code is reached.
Going along with conditional breakpoints is a vastly improved expression evaluator. It is used when evaluating conditional breakpoints, in the Expressions view, and in debugger tooltips.
For one thing, you can now make function calls directly from the Expressions view (as well as from conditional breakpoints):
Also, regular expressions and E4X expressions can be quite tricky to debug;
with the new expression evaluator, you can just type them into the Expressions
view and immediately see the value. (The one exception is you can’t use E4X
filter expressions such as
myxmlvar.(@id=='3').) For example, suppose
“customers” is an XML object — you can do expressions like these in the
myCustomersXML.customer.@name myCustomersXML..zipCode myCustomersXML.customer.@name
Here is a regular-expression example that you could put in the Expressions view or a breakpoint condition:
mystr.match( /[0-9]+/ig )
You can use the ternary ( ?: ) operator:
mystr.length>=3 ? mystr.charAt(2) : "too short"
You can use the “is” operator (this is especially useful in conditional breakpoints):
obj is String
The possibilities are limitless.
!==, string concatenation, etc.
— almost any other ActionScript expression you can think of, you can put
it in the Expressions view or a breakpoint condition.
Watchpoints tell the debugger to immediately halt when the value of a particular variable changes. Suppose you have a variable whose value keeps changing out from under you, and you can’t figure out who is changing it. With a watchpoint, it’s trivial — just set the watchpoint and run your code. (Flex Builder watchpoints are set on a particular instance of a variable. For example, you set a watchpoint on the _width field of a button “myButton”, not on the _width field of all Buttons.)
The debugger always halts immediately whenever there is an uncaught exception.
But sometimes, you want the debugger to halt even on an exception that
is going to be caught by a
try/catch block in your code.
That’s what exception breakpoints will let you do. You will be able to say,
for example, “Always halt in the debugger whenever a
TypeError is thrown,
even if it is going to be caught.”
A minor feature but still quite nice to have: Run to Line (Cmd+R on Mac, Ctrl+R on Windows) is a quick way to set a temporary breakpoint on the current line, then run until you get there, and then automatically clear the temporary breakpoint.
A major addition, this allows you to easily see the network traffic that is going back and forth between your app’s front end and its back end.