A Cure For The Dreaded Heisenbug

A Heisenbug is a particularly nasty type of software problem named after renowned German theoretical physicist Werner Heisenberg.  A pioneer in the field of quantum mechanics, Heisenberg proposed in 1927 that the more precisely you measure the location of a particle, the less you can know about its momentum (mass times velocity).  The same proposition is true for the opposite measurement.  His idea is expressed in a simple mathematical inequality known as Heisenberg’s uncertainty principle.

Although the term Heisenbug, coined in the 1980s, is certainly a clever pun and certainly involves uncertainty, a Heisenbug is actually an example of a different physical phenomenon called the observer effect.  Simply put, the act of observing or measuring a system can change the object being observed.

An example of the observer effect is what happens when using a glass mercury thermometer.  A thermometer must absorb or give up some thermal energy in order to measure a temperature, therefore it actually changes the temperature of the body during measurement.  Analogously, a Heisenbug is a software problem whose symptoms change or disappear while it is being investigated.  This is certainly no fun for the programmer.

What causes Heisenbugs?  There are several simple causes such as uninitialized variables or runaway pointers, however the most serious cases involve nuances in timing.  In multiprocessing applications, timing dependencies often exist among the individual processes and threads that comprise the application. Using a debugger can drastically alter the timing sequence of asynchronous events, thus resulting in completely different or even random application behavior and results.

To defeat a Heisenbug you need advanced, non-impact debugging tools. Ordinary debuggers, such as GDB, interrupt the normal execution of a process by taking control when evaluating variables, breakpoint conditions or delivering signals to the process.

On the other hand, non-impact debuggers, such as Concurrent’s NightStar, operate with minimal intrusion and are specifically designed to avoid Heisenbug conditions.  With these debuggers, conditional expressions and ignore counts in breakpoints and user-defined source code patches are inserted directly into the process and thus execute at application speed.  The debugger takes control only when the specific condition you’re looking for occurs, so your application behaves during debugging just as it would in normal execution.  The Heisenbug cannot hide from detection.

Non-impact debuggers can also non-intrusively record and timestamp the running values of any variable on an executing process without any coding changes to the program. They do this by mapping directly into a process’s address space.

So, if you’ve been made ill by a nagging, elusive problem, a non-impact debugging tool like NightStar may be the cure.

Get Started with Real-Time