I have definitely had bugs which I worked on for 4-5 days continuously before finding a solution. Other bugs have sat in the bug tracker for months, as I put in a few hours spread out over a long period of time. I think this sort of bug is inevitable in any complex software project.
Some stuff that works well for me:
- binary search through the program flow with logging
- use
Trace statements along with DbgView to search for bugs which show up in release mode
- find an alternate way to reproduce the bug without changing the code
- (works against logic, but...) change the code so that the bug is more easily reproducible (the failure condition is more readily achieved)
- sleep on it and try again tomorrow with a fresh pair of eyes :)
The worst sort of bug in my opinion is a concurrency bug which disappears when logging is inserted.