You can enable
and disable
breakpoints, and these commands will accept a range. Use these commands, with a range, at strategic points during the execution of the program.
I assume that when you mention breakpoint #2 you're referring to the gdb numbering of breakpoints. Here is a simple example gdb session:
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x00001ddb in main at example.c:34
2 breakpoint keep y 0x00001e00 in main at example.c:39
3 breakpoint keep y 0x00001e15 in main at example.c:40
(gdb) disable 1-3
(gdb) enable 2
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep n 0x00001ddb in main at example.c:34
2 breakpoint keep y 0x00001e00 in main at example.c:39
3 breakpoint keep n 0x00001e15 in main at example.c:40
(gdb)
Now only breakpoint #2 is enabled. Run the program and when execution breaks at #2, re-enable all of your desired breakpoints with a range:
(gdb) enable 1-3
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x00001ddb in main at example.c:34
2 breakpoint keep y 0x00001e00 in main at example.c:39
3 breakpoint keep y 0x00001e15 in main at example.c:40
You can also mix breakpoint numbers and ranges:
(gdb) disable 1 4 6-7
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep n 0x00001ddb in main at example.c:34
2 breakpoint keep y 0x00001e00 in main at example.c:39
3 breakpoint keep y 0x00001e15 in main at example.c:40
4 breakpoint keep n 0x00001e4f in main at example.c:43
5 breakpoint keep y 0x00001e4f in main at example.c:44
6 breakpoint keep n 0x00001e5e in main at example.c:45
7 breakpoint keep n 0x00001e5e in main at example.c:46