我在用
p12user@ubuntu:~$ uname -a
Linux ubuntu 2.6.32-40-generic #87-Ubuntu SMP Tue Mar 6 00:56:56 UTC 2012 x86_64 GNU/Linux
p12user@ubuntu:~$ gdb -v
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
p12user@ubuntu:~/programming$ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
在 gdb 中调试此程序时,编译为gcc -g program.c
:
#include <stdio.h>
int main()
{
int condition1 = 1;
if(condition1)
{
if(!condition1)
{
printf("The control shouldn't come here.\n");
}
}
else
{
printf("in else\n");
}
return 0;
}
行为是:
Breakpoint 1, main () at program.c:4
4 int condition1 = 1;
(gdb) n
5 if(condition1)
(gdb) n
7 if(!condition1)
(gdb) n
9 printf("The control shouldn't come here.\n");
(gdb) n
16 return 0;
(gdb) n
17 }
(gdb)
第 9 行的行为在 gdb 中是意外的。但是,print 语句只显示在 gdb 中,不执行。而且,如果我将匹配的 ELSE(带有一些打印语句)与 inner-IF 一起放置,则不会发生这种情况,如果删除了与 outer-IF 匹配的 ELSE,则不会发生这种情况。我在这里错过了一些微不足道的事情吗?