Total Pageviews

Friday, July 23, 2010

Debug Tip from "Magic's Biggest Secrets Finally Revealed on AXN" show

While ago AXN ran this series "Magic's Biggest Secrets Finally Revealed". It was kind of interesting series. Lets take example where the magician is able to move a egg or himself through a solid wall. watch this : http://www.youtube.com/watch?v=pEIFYFqEyaw

What I learnt from this is, we see what magician wants us to see. We shut our attention to see what is really happening to make that illusion possible. Now in this case if the wall is solid the only way he could move in and move out is from sides. Now what one has to look for is what can help magician move from the side.

How does this translate to debugging ?
Look Programmer and Debugger are really two different personalities although it may be done by single person, Programmer is magician and Debugger is audience. Programmer has algorithmic intent that he has captured in his program and it has failed. While debugger starts looking at it, Programmer shows only his intent but does not allow the Debugger to look at it from perspective of yes this is intent but what can break the intent. This is magic trick of the programmer on debugger where he creates the illusion of this failure is not possible.

As a smart audience, Debugger needs to think like this. Lets accept failure has happened. Lets stop denying that this failure is not possible. What one needs to think is with this given code snippet that had specific intent what can lead to the failure. It may be the fact that program was not designed for a specific input and it was given or in the course of solving main problem certain subtle language specific intent was missed.

Let me elaborate with simple System verilog constraint failure example. I had this simple constraint that sum of two integer numbers[A, B] less than third integer[C]. Third integer[C] was input and other two integers[A, B] were output of this constraint. I checked the input number it was correct but the generated integers[A, B] when I was printing as HEX was showing huge values. I thought how could this simple constraint fail. Well what was happening was int was taking negative values. I really wanted only positive numbers and declaring as int had caused it. While I stared at the simple constraint for long time assuming bug was there while it was just hiding the data type. Programmer would just show me the constraint and hide his trick with integers data type.