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
A
is just never greater than 1? – StoryTeller - Unslander Monica"correct"
– StoryTeller - Unslander Monican
command. I think it's gcc optimisation. Onlya>1
can "correct" be printed. If I don't change compiling script, Can I make gdb just stop at the specific line? – user7328234