Why is GDB automatically continuing!?
Is your gdb automatically continuing once it hits a break point?
The Short Answer (and Solution)
It’s because you are putting blank lines in the GDB terminal after you type
continue
.
Do not type stuff into the GDB terminal (including blank lines) while your program is running. Only type stuff into the GDB terminal when you see the gdb prompt. Read on for clarifications.
The Long Answer
Here is your typical gdb workflow:
- start gdb
- attach it to a process
- set a break point
- type
continue
to resume program execution
Remember, continue
is the last thing you wrote before program execution resumed.
So, now your program is running, and you go to the gdb terminal and type a couple of enter
s to create some empty space in the terminal window:
The terminal “records” the fact that you typed enter
a few times.
When your program hits a breakpoint, its execution is halted and the gdb prompt is shown for a split second, but since your terminal “recorded” that you pressed enter
, it will automatically send enter
to the gdb promp. Sending just enter
(aka a blank input) to the gdb prompt tells gdb to repeat the last command, which was continue
. So essentially, you have told gdb to immediately continue upon hitting a breakpoint!
To prevent this:
Do not type anything in the gdb terminal while your program is running. Only type when you see the gdb prompt!