I am reading the book – “C Interfaces and Implementations” by David Hanson. This exercise questions seems interesting and am unable to find a solution:
On some systems, a program can invoke a debugger on itself when it has
detected an error. This facility is particularly useful during
development, when assertion failures may be common.
Can you provide a short example on how to invoke a debugger.
void handle_seg_fault(int arg)
{
/* how to invoke debugger from within here */
}
int main()
{
int *ptr = NULL;
signal(SIGSEGV, handle_seg_fault);
/* generate segmentation fault */
*ptr = 1;
}
Elaborating on Christian.K’s comment,
fork()ing a debugger in the face of something like a SIGFPE or SIGSEGV might not be the best of ideas, because…fork()unsafe;A coredump that I can copy to a testbed beats a debugger instance at my customer’s workplace any time of the day. A debugger interface makes for a lousy end-user error message.