The problem is not simple at all. It looks like there is no any practical alternative to debugging, but we have some remote and limited hope for something better.
Let's say we need some definitive automated diagnostics of the infinite loop problem. It can be embedded in the program in question or based on static code analysis, no matter compiled or source code.
Strictly speaking, this is totally impossible. This is proven mathematically and is known in computability theory
as the "halting problem
". With any kind of code analysis, it is theoretically impossible
to predict if some program will ever terminate or not. Please see:http://en.wikipedia.org/wiki/Computability_theory_%28computer_science%29
So, the most general problem formulated as "give me the way to predict if some program can get in an infinite loop or not" is the ill-posed problem and cannot be solved
. Nevertheless, there is some hope. If you look at the proof of the theorem, you will see that the idea is this: suppose the algorithm for solving of the halting problem exist; let's name it A. We can design such a program P using A that works the way A fails. So the hopeful question is: can we formulate some very wide practically significant subclass of programs which behavior could be predicted. (Of course you can find many trivial subclasses of programs, for example, programs with no forks, or not loops, etc. Such finding would not have any practically important sense.)
Several years ago I saw just one article telling us that Microsoft started some research in this direction. I never heard about any results so far. So, right now debugging and just using human brain is the only option. —SA