源代码行的错觉

源代码行的错觉

Content #

为下面的程序在main的入口设置断点,GDB为什么会把断点放在第4行,而不是 1,2,3行?

1 int main(void)
2 {
3   int i;
4   i=3;
5
6   return 0;
7 }

GDB实际是以机器指令工作的,但是有了增强的符号表后,它表现出了使用源代码行的错觉。第3行确实会生成机器指令,但这种代码对调试没有用处,因此,当要求GDB在main()的开头中断时,它就在第4行设置了一个断点。

A symbolic debugger such as GDB can run your program, just like you can. However, with the magic of including debugging symbols in the executable, the debugger gives the illusion of executing the program line by line of source code, instead of instruction by instruction of compiled machine code.

From #