Andrey said:
Not really.
exit != enter debugger
Ah, that makes things clearer. There's no "standard" way whatsoever
to call a debugger from compiled C code, but provided your program
runs under control of a debugger (or at least a monitor that talks
to a debugger), and you want the program control transferred to the
debugger at specific points, you can do this:
#ifdef CHECKPOINTS
static void checkpoint (void) { /* empty */ }
#define CHECKPT do { checkpoint (); } while (0);
#else
#define CHECKPT /* empty */
#endif
You should put this in a header file (say, "checkpt.h") and #include
it in all C modules where you want to apply checkpoints (of course,
you'll later have to recompile them with "-DCHECKPOINTS").
Then, insert "CHECKPT"s in your C code wherever you deem them right,
and set an actual breakpoint from within the debugger to "checkpoint"
(usually before you start the program). If your program hits such a
CHECKPT, the debugger will re-gain control, and you will have to use
its "one frame up"-command to set the context to the causing CHECKPT.
With gdb, you can easily automate this by attaching an "up" command
to the "checkpoint" breakpoint from within a command file (.gdbinit).
Since breakpoints (and breakpoint handling) depend on so many things
(monitor, debugger, target architecture, target OS, memory type and
memory protection, a.s.o.), I think this approach is the closest you
can get to "independent breakpoints". I'd really appreciate it if
someone could prove me wrong on this, but I doubt this will actually
happen... ;-)
Cheers,
mike