Flex code injection using conditional breakpoints

20 01 2011

So while it’s not new news, something I saw in a video from MAX 2009 on Flash Builder 4 last year really stuck with me. And, it’s been saving me day after day on this massive project.

It has to do with conditional breakpoints in FB4. On top of the normal, if x == true conditions, you can use a sneaky comma trick to inject code.

It’s simple, you enter true (1) or false (0) in the box (depending on whether you want the breakpoint to pause execution) and then add any expression(s) you want, separated by commas. The beauty is that these expression(s) is/are evaluated regardless of whether the breakpoint is executed or not. That means you can inject code into a running debug session without stopping to compile and rerun.

There are two main usages I’ve found for this feature:

Inserting Traces

I regularly find myself tracing through asynchronous operations, trying to figure out the order of events and properties at the time. Sometimes (and this evokes one very painful memory) I’m tracking multiple timers and I can’t learn anything from breakpoints, as I need to get an idea of the order of the ticks (and the corresponding events that are firing).

These scenarios make them a perfect candidate for the injected trace. Try this:

 

FB4 Conditional Breakpoint Dialog: Tracing

FB4 Conditional Breakpoint Dialog: Tracing

 

Modifying Properties

The other main use-case is the all-too-common scenario when you want to change a property mid-execution. We’ve all been there – myself just today.

FB4 Conditional Breakpoint Dialog: Property Setting

FB4 Conditional Breakpoint Dialog: Property Setting

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: