I get a segmentation fault when I cancel my program. I am using gdb for debugging, the problem is that when I press Ctrl-C while I am debugging gdb does not cancel the program and do what it is supposed to do that is stop it.
What I want is do the Ctrl-C and do not allow gdb to stop it. Is there any way to do this? Any other recommendations for debugging? I cannot use printf because sincerely I have not a clear idea where the problem comes from.
In practice, segfaults are almost always due to trying to read or write a non-existent array element, not properly defining a pointer before using it, or (in C programs) accidentally using a variable's value as an address (see the scanf example below).
It can be resolved by having a base condition to return from the recursive function. A pointer must point to valid memory before accessing it.
A common run-time error for C programs by beginners is a "segmentation violation" or "segmentation fault." When you run your program and the system reports a "segmentation violation," it means your program has attempted to access an area of memory that it is not allowed to access.
gdb is intercepting the signal. When you press CTRL-C, you're actually causing the terminal driver to generate a SIGINT.
What you need to do is have GDB generate the SIGINT using the signal command. the syntax is
signal num
and man signal will tell you the signal number (in this case, SIGINT is signal 2, so signal 2
will do it.)
Sure enough, you can use the symbolic name. info signal
will tell you all the names etc.
Oh, by the way, odds are that you have a signal handler installed for SIGINT and the arguments aren't right somehow.
An alternative is to stop gdb from catching the SIGINT by typing handle SIGINT noprint pass
at the gdb prompt before running the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With