To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it. Examining data When your program is stopped you can examine or set the value of any variable.
Just press c. It will continue execution until the next breakpoint.
GDB normally ignores breakpoints when it resumes execution, until at least one instruction has been executed. If it did not do this, you would be unable to proceed past a breakpoint without first disabling the breakpoint. This rule applies whether or not the breakpoint already existed when your program stopped.
An assertion failure occurs when the database server cannot continue normal processing and must shut down. You can correct some of the problems that cause assertion failures, such as disk issues.
Setting a breakpoint on abort()
seems to be the best answer.
break abort
in gdb's CLI.
No break
is needed on Linux, just type bt
on the prompt
abort()
causes the SIGABRT
signal to be raised in Linux, and GDB already breaks on signals by default. E.g.:
a.c
#include <assert.h>
void g(int i) {
assert(0);
}
void f(int i) {
g(i);
}
int main(void) {
f(1);
}
Then:
gcc -std=c99 -O0 -ggdb3 -o a a.c
gdb -ex run ./a
Then just type bt
in the shell:
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:58
#1 0x00007ffff7a483ea in __GI_abort () at abort.c:89
#2 0x00007ffff7a3ebb7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x555555554788 "0", file=file@entry=0x555555554784 "a.c", line=line@entry=4,
function=function@entry=0x55555555478a <__PRETTY_FUNCTION__.1772> "g") at assert.c:92
#3 0x00007ffff7a3ec62 in __GI___assert_fail (assertion=0x555555554788 "0", file=0x555555554784 "a.c", line=4, function=0x55555555478a <__PRETTY_FUNCTION__.1772> "g")
at assert.c:101
#4 0x00005555555546ca in g (i=1) at a.c:4
#5 0x00005555555546df in f (i=1) at a.c:8
#6 0x00005555555546f0 in main () at a.c:12
Which already shows the function values (f (i=1)
).
And you can also do as usual:
(gdb) f 4
#4 0x00005555555546ca in g (i=1) at a.c:4
4 assert(0);
(gdb) p i
$1 = 1
The setting that controls if GDB breaks on signals by default or not is: handle all nostop
as shown at: How to handle all signals in GDB
Tested in Ubuntu 16.10, gdb 7.11.
If suggested above answers doesn't work for you, you may try to break on __assert_fail function.
break __assert_fail
Name is most probably implementation - dependent, but it's easy to find if you look at definition of assert macro on your platform. This will allow you to break before SIGABRT.
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