A commonly used approach is to use a dummy function with a non-obvious name. Then you can increase your .gdbinit or use any other technique to always break that name.
Trivial dummy function:
void my_dummy_breakpoint_loc(void) {}
Checked code (may be an assert type macro):
if (rare_condition) my_dummy_breakpoint_loc();
gdb session (obviously eh?):
b my_dummy_breakpoint_loc
It is important to make sure that "my_dummy_breakpoint_loc" is not optimized by the compiler for this technique to work.
In the most severe cases, the actual assembler instruction that calls my_dummy_breakpoint_loc can be replaced with "nops" and included on the site by site using a slight modification of the code at runtime. This method is used by Linux kernel development tools to name one example.
source share