In gdb, I set a breakpoint to make gdb stop when the first if
condition is met. But gdb stops in another line and if
condition isn't met. I've read gdb breakpoint does not get hit, but it's stll not solved. I think gdb stops only when if (a == 1)
is met and just in line 3282. Am I wrong?
#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
set breakpoint in line 3282 using command b file.c:3282
Breakpoint 1 at 0x40da02: file file.c, line 3282.
info breakpoint
shows:
Num Type Disp Enb Address What
1 breakpoint keep y 0x000000000040da02 in search at file.c:3282
breakpoint already hit 1 time
But gdb stops in line 3284, instead of 3282, and a is not equal 1
[Switching to Thread 0x7ffff75b8700 (LWP 3631)]
Breakpoint 1, search at file.c:3284
3284 if (b == 1) {
gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
I change gcc -g -O2
to gcc -g -O0
, then everything goes well. Following is document about -O2
option of gcc command.
-O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O, this option increases both compilation time and the performance of the generated code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With