How can I set a breakpoint in C or C++ code programatically that will work for gdb on Linux?
I.e.:
int main(int argc, char** argv)
{
/* set breakpoint here! */
int a = 3;
a++; /* In gdb> print a; expect result to be 3 */
return 0;
}
int main
rather thanvoid main
. - Stuart Golodetzreturn 0
is not necessary, though, and is just noise! - Lightness Races in Orbitreturn 0;
is 100% necessary. Besides the warning your compiler should throw at you, this can corrupt the stack on older/embedded systems, and as such should ALWAYS be done out of habit and correctness. Forget a return in other places in your code and you're guaranteed to pay for it on modern desktop systems, too. - Jimmio92