在 gdb 中,我设置了一个断点,让 gdb 在满足第一个if条件时停止。但是 gdb 停在另一行并且if不满足条件。我读过gdb breakpoint does not get hit,但它仍然没有解决。我认为 gdb 仅在if (a == 1)遇到并在第 3282 行时停止。我错了吗?
#pragma GCC push_options
#pragma GCC optimize("O0")
static void __attribute__ ((noinline)) search(int a, int b)
{
// other code here
if (a == 1) {
printf("condition1\n");
printf("condition1\n"); // line 3282, breakpoint is set here
}
if (b == 1) { // line 3284, in fact, gdb stops in this line
printf("condition2\n");
printf("condition2\n");
}
}
#pragma GCC pop_options
Run Code Online (Sandbox Code Playgroud)
使用命令在第 3282 行设置断点 b file.c:3282
0x40da02 处的断点 1:文件 file.c,第 3282 行。
info breakpoint 显示:
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000040da02 in search at file.c:3282
breakpoint already hit 1 time
但是gdb停在3284行,而不是3282行,a不等于1
【切换到线程0x7ffff75b8700 (LWP 3631)】
断点1,在file.c:3284
3284处搜索if (b == 1) {
gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
我更改gcc -g -O2为gcc -g -O0,然后一切顺利。以下是关于-O2gcc 命令选项的文档。
-O2 优化更多。GCC 执行几乎所有不涉及空间速度权衡的受支持优化。与 -O 相比,此选项会增加编译时间和生成代码的性能。
| 归档时间: |
|
| 查看次数: |
3417 次 |
| 最近记录: |