Geeks With Blogs
Johnny Kauffman Deriding bad software so you don't have to!

Occasionally I run into a problem difficult to reproduce in that it takes a laborious amount of tinkering.  Sometimes I’ve gone through the work of plugging away at the user interface or forcefully moving the current statement manually around if statements. In these situations,  I become very attached to my debugging session (no pun intended).

I am secure in my nerdiness enough to admit that there have been instances where I have changed code for testing purposes and forgotten to revert those changes before checkin time. Because of this I’ve developed an aversion to making such changes to the code. I recently discovered one additional tool in my arsenal to futz with the running code without changing it.

Abuse a breakpoint condition!

Breakpoint

You would usually use a condition to specify when the breakpoint should hit, but you can enter any valid code as the condition. In my case, I used this:

     (addressState = "AL") == null

The null check was just to ensure that the breakpoint would not actually break the debugger. You could use “!= null” if you still wanted the breakpoint to hit.

Ultimately this aids the same benefit you get when setting values in local or watch windows. Using this trick, you can “automate” these actions if you need to.

Posted on Monday, February 27, 2012 6:54 AM | Back to top


Comments on this post: Setting a variable when a breakpoint hits

# re: Setting a variable when a breakpoint hits
Requesting Gravatar...
Cool trick! :)
Left by Filip Skakun on Feb 27, 2012 11:36 AM

# re: Setting a variable when a breakpoint hits
Requesting Gravatar...
This is a cool trick indeed, but whenever I show it to people, they go, "huh? why would I ever want to do that?". People tend not to realize the huge power of being able to change program state directly from the debugger, for experimentation and quick-fix-checking. It's a shame, really.
Left by Omer Raviv (BugAid Software) on Feb 27, 2012 7:39 PM

# re: Setting a variable when a breakpoint hits
Requesting Gravatar...
Omer, perhaps they haven't evolved past the "int x = 0;" sprinkling stage. :)
Left by Johnny Kauffman on Feb 28, 2012 2:29 AM

Your comment:
 (will show your gravatar)


Copyright © jkauffman | Powered by: GeeksWithBlogs.net