The most common cause for an application crash is when a program tries to read or write memory that is not allocated for reading or writing by the application – a general protection fault. Some other causes are listed below:
- Attempting to execute privileged or invalid instructions
- Unforeseen circumstances or poor code writing that results in the program executing an endless loop
- Attempting to perform I/O operations on hardware devices to which it does not have permission to access
- Passing invalid arguments to system calls
- Attempting to access other system resources to which the application does not have permission to access
At this point, let’s digress a little bit and introduce a couple of quirky terms that we use to discuss “bugs”.
Heisenbug: The Heisenbug takes its name from the Heisenberg Uncertainty Principle. A Heisenbug is a bug that disappears or alters its characteristics when it is observed. The most common example of a Heisenbug is being unable to reproduce a problem when running a program in debug mode. In debug mode, memory is often cleaned before the program starts. Variables may be forced onto stack locations as opposed to being kept in registers. Another reason that you may see a Heisenbug in debug mode is that debuggers commonly provide watches or other user interfaces that cause code (such as property accessors) to be executed, which in turn may alter the state of the program.