You know the scene – you have a loop that iterates through loads of records but something strange happens when Widget.Property = “Banana” or somesuch. “What the devil is going on?” you mutter to yourself, and you set a conditional breakpoint on an appropriate line to see what is happening when the property is set in this way.
Breakpoint set, condition set, and off you go.
However, now, something really strange starts. Object properties are changing when you least expect it and you start to doubt the very fabric of the universe (or at least the .NET Framework runtime). Widget.Property equalled “Apple” a minute ago, and now it equals “Banana” for no apparent reason and you really can’t get your head around it. A PC reboot, and a quick Google-ing doesn’t help. Your mind wanders further.. maybe a virus? A problem with the PC’s memory? Surely not. Everything else seems to be fine.
In desperation you remove the breakpoint and.. lo and behold.. the problem goes away. Or, at least, the original problem comes back. What the hell?
The problem lies in the condition on the conditional breakpoint. I had set my condition to Widget.Property = “Banana” - note that I had accidentally used one “=” , not two. The upshot of this is quite logical once you sit back and think about it – just prior to the line with the breakpoint on it being executed, the condition is executed and the boolean result determined. If the boolean result is true, the breakpoint stops execution, if not, it continues.
So rather than checking if Widget.Property equalled “Banana” I was in fact setting Widget.Property to “Banana” on every iteration round the loop.. and this is why I couldn’t work out what the hell was going on.
And note that this condition is executed when the line with the breakpoint on it gets the “focus”. So you haven’t even stepped past the point where the breakpoint is set when the weird things happen. I wasted an hour on this today…
Run the program and you get a list of people and ages.
Now set a breakpoint on the line indicated, and set it to break when iPerson.Name = “Mr B” (with 1 “=” sign)
Run the program again and note that, first of all the breakpoint is never trigged, and second of all you just get a list of Mr.B’s but all with different ages.
So.. beware this one, fellow developers. It may just catch you out one day…
This entry was posted on Friday, October 15th, 2010 at 10:17 pm and is filed under comment, computer, development. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Conditional Breakpoints – A Cautionary Tale
You know the scene – you have a loop that iterates through loads of records but something strange happens when Widget.Property = “Banana” or somesuch. “What the devil is going on?” you mutter to yourself, and you set a conditional breakpoint on an appropriate line to see what is happening when the property is set in this way.
Breakpoint set, condition set, and off you go.
However, now, something really strange starts. Object properties are changing when you least expect it and you start to doubt the very fabric of the universe (or at least the .NET Framework runtime). Widget.Property equalled “Apple” a minute ago, and now it equals “Banana” for no apparent reason and you really can’t get your head around it. A PC reboot, and a quick Google-ing doesn’t help. Your mind wanders further.. maybe a virus? A problem with the PC’s memory? Surely not. Everything else seems to be fine.
In desperation you remove the breakpoint and.. lo and behold.. the problem goes away. Or, at least, the original problem comes back. What the hell?
The problem lies in the condition on the conditional breakpoint. I had set my condition to Widget.Property = “Banana” - note that I had accidentally used one “=” , not two. The upshot of this is quite logical once you sit back and think about it – just prior to the line with the breakpoint on it being executed, the condition is executed and the boolean result determined. If the boolean result is true, the breakpoint stops execution, if not, it continues.
So rather than checking if Widget.Property equalled “Banana” I was in fact setting Widget.Property to “Banana” on every iteration round the loop.. and this is why I couldn’t work out what the hell was going on.
And note that this condition is executed when the line with the breakpoint on it gets the “focus”. So you haven’t even stepped past the point where the breakpoint is set when the weird things happen. I wasted an hour on this today…
An example, below:
Run the program and you get a list of people and ages.
Now set a breakpoint on the line indicated, and set it to break when iPerson.Name = “Mr B” (with 1 “=” sign)
Run the program again and note that, first of all the breakpoint is never trigged, and second of all you just get a list of Mr.B’s but all with different ages.
So.. beware this one, fellow developers. It may just catch you out one day…
Like this:
This entry was posted on Friday, October 15th, 2010 at 10:17 pm and is filed under comment, computer, development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.