October 21, 2010

Conditional breakpoints can cause side-effects.

Posted in Debugging tagged , , , at 8:11 am by davy803

I had the strangest bug the other day.  One part of code just suddenly stopped working, a variable was being set to the wrong value somehow but I could not find where it was being set.  I reverted back to a working copy from source control, chalking it up to one of those random mysteries.  Still not working.  Rebooted, did a clean checkout.  Still nothing.  At this point I was very frustrated.  I removed a breakpoint and it suddenly started working again.  It was the strangest thing.

Then I realized what happened.  I had set a conditional breakpoint, but instead of setting to condition to “foo == bar” I had set it to “foo = bar” so it was assigning the value.  Doh!

Advertisement

1 Comment »

  1. Ouch.

    Had one recently where, after looking at an object in the debugger, the object’s internal state became whacky.

    Took me a while to figure out that the author of the object had a property getter that actually set the value of some other property, e.g. the getter for Foo was setting Bar then returning Foo.

    Side-effects inside property getters = pure evil.


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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.