Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard methods of debugging

What's your standard way of debugging a problem? This might seem like a pretty broad question with some of you replying 'It depends on the problem' but I think a lot of us debug by instinct and haven't actually tried wording our process. That's why we say 'it depends'.

I was sort of forced to word my process recently because a few developers and I were working an the same problem and we were debugging it in totally different ways. I wanted them to understand what I was trying to do and vice versa.

After some reflection I realized that my way of debugging is actually quite monotonous. I'll first try to be able to reliably replicate the problem (especially on my local machine). Then through a series of elimination (and this is where I think it's problem dependent) try to identify the problem.

The other guys were trying to do it in a totally different way.

So, just wondering what has been working for you guys out there? And what would you say your process is for debugging if you had to formalize it in words?

BTW, we still haven't found out our problem =)

like image 334
Fung Avatar asked Apr 08 '09 03:04

Fung


People also ask

What are the 4 debugging steps?

Isolate the source of the bug. Identify the cause of the bug. Determine a fix for the bug. Apply the fix and test it.


3 Answers

My approach varies based on my familiarity with the system at hand. Typically I do something like:

  1. Replicate the failure, if at all possible.
  2. Examine the fail state to determine the immediate cause of the failure.
  3. If I'm familiar with the system, I may have a good guess about to root cause. If not, I start to mechanically trace the data back through the software while challenging basic assumptions made by the software.
  4. If the problem seems to have a consistent trigger, I may manually walk forward through the code with a debugger while challenging implicit assumptions that the code makes.

Tracing the root cause is, of course, where things can get hairy. This is where having a dump (or better, a live, broken process) can be truly invaluable.

I think that the key point in my debugging process is challenging pre-conceptions and assumptions. The number of times I've found a bug in that component that I or a colleague would swear is working fine is massive.

I've been told by my more intuitive friends and colleagues that I'm quite pedantic when they watch me debug or ask me to help them figure something out. :)

like image 64
Greg D Avatar answered Sep 29 '22 13:09

Greg D


Consider getting hold of the book "Debugging" by David J Agans. The subtitle is "The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems". His list of debugging rules — available in a poster form at the web site (and there's a link for the book, too) is:

  • Understand the system
  • Make it fail
  • Quit thinking and look
  • Divide and conquer
  • Change one thing at a time
  • Keep an audit trail
  • Check the plug
  • Get a fresh view
  • If you didn't fix it, it ain't fixed

The last point is particularly relevant in the software industry.

like image 31
Jonathan Leffler Avatar answered Sep 29 '22 12:09

Jonathan Leffler


When I'm up against a bug that I can't get seem to figure out, I like to make a model of the problem. Make a copy of the section of problem code, and start removing features from it, one at a time. Run a unit test against the code after every removal. Through this process your will either remove the feature with the bug (and hence, locate the bug), or you will have isolated the bug down to a core piece of code that contains the essence of the problem. And once you figure out the essence of the problem, its a lot easier to fix.

like image 27
Spike Williams Avatar answered Sep 29 '22 11:09

Spike Williams