How can a debugger "fix" errors in a program?

In a recent interview, I was asked the following question:

You have an error in your program, after trying to debug it by inserting expressions such as printf, console.log, System.out.println, echo, etc., the error will disappear. How can this happen?

I answered the following answers:

  • You have something with side effects in your print instruction, for example: System.out.println(foo.somethingWithSideEffects())
  • Adding printf changes the memory layout of the program, so it can span neighboring memory and prevent crashes
  • Undefined Behavior in native code (e.g. uninitialized values, buffer overflows, sequence points, etc.)

The interviewer said that this is not the only way this can happen, and I could not think of any other ways to just add printf, etc., to “fix” the error in the program.

What else could lead to this?

+4
source share
2 answers

The biggest thing that comes to mind is that entering the debug code can change the code time, which can make a difference if there is a race condition in the debug code. It can be very frustrating to try to debug race conditions that disappear when checked.

+5
source

- . , , , ,

0

All Articles