c++debugginggdbinterpreter

Why are debuggers much more specific when an error occurs as compared to compilers?


From Thinking in C++ - Vol. 1:

Interpreters have many advantages. The transition from writing code to executing code is almost immediate, and the source code is always available so the interpreter can be much more specific when an error occurs.

Interpreter always works directly on the source code (after translating it line by line into machine code) so that may be the reason that it can be much more specific when an error occurs.

From: What does it mean to say that the source code is always available to interpreters?

speed is one criteria to use interpreter. and yes, it can directly refer to source code when error occurs. but when run-time runs compiled code, it can't refer to exact line where error occured.

Now, what about the debuggers?
GDB works on the output produced by the compiler, so here GCC and GDB have same files to work on.

Why is GDB able to show the exact error on the exact line (during run time) then as compared to the compiler?


Solution

  • Why is GDB able to show the exact error on the exact line (during run time) then as compared to the compiler?

    These are two different softwares with different purposes. First you should understand this.

    so here GCC and GDB have same files to work on

    Not exactly, Debugger needs some more files generated during compilation. (called symbols). These symbols are bridge between compiled code and source code.

    I'm not much sure of GCC but it should have debug and release build options. When you compile in debug mode, by default symbols are generated that help GDB to debug. but in release mode, be default symbols are not generated and GDB can't debug a release build.