Debuggeration

Not surprisingly there is a bug in my code. The segfault was a hint. So, like you do I sprayed printf()s all over the place and found a likely bit of code causing the trouble. I was trying to dereference a NULL pointer, so added a bit of code that said “if (!whatever) return”.

Which then shifted the crash up a level, so I attached a debugger and began stepping through the code, jumping over the error several times before remembering what I was doing. Debuggers really need an “undo” or “rewind” option for when you accidentally jump over the line of code causing the crash.

And now I know exactly where my code crashes and why. It crashes on the line where I attempt to call an object’s member function, except the object is really a NULL pointer.

The pointer should be NULL, the problem is the code shouldn’t even be running at this moment in time.

I hate recursive programming, it always bites me somewhere unexpected. Unfortunately it makes sense to parse a recursive data structure using a recursive function.

And I won’t ask why I can’t compare two std::string objects using ==, but .compare() works fine.

This entry was posted in Programming and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">