"The most effective debugging tool is still careful thought, coupled with judiciously placed print statements." -- Brian W. Kernighan
Your question is really too broad to answer in this medium. Read a book or two.
http://cm.bell-labs.com/cm/cs/tpop/debugging.html by Kernighan & Pike would be among my reading suggestions. (Not responding right now. Here's Google's cached copy:
From Chapter 5, Debugging)