Reputation: 12559
I wrote a C program on linux to process large amount of data. It seemed working OK most of the time, but I met a segmentation fault error when doing a job. Because the program works OK with other data so I don't know how to deal with this problem. And by the way how to retrieve variable value when segfault occurred?
here is the gdb output:
Program received signal SIGSEGV, Segmentation fault.
tyn_p4d_encode32 (in=0x10000000c01, cnt_in=118248, out=0x10000000101 <Address 0x10000000101 out of bounds>, add_termination=1) at tyn_coder.c:645
645 length_stat[count_bits32(*(in + i)) - 1]++;
Missing separate debuginfos, use: debuginfo-install glibc-2.14.90-24.fc16.6.x86_64 zlib-1.2.5-5.fc16.x86_64
(gdb) bt
#0 tyn_p4d_encode32 (in=0x10000000c01, cnt_in=118248, out=0x10000000101 <Address 0x10000000101 out of bounds>, add_termination=1) at tyn_coder.c:645
#1 0x0000000000404582 in nodes_term32_flush (array=<optimized out>, size=<optimized out>, nodes_context=0x2ded020, is_last=0) at tyn_indexer.c:116
#2 0x0000000000407b78 in tyn_exsorter_sort (exsorter=0x64c4a0, context=0x2ded020, nodes_flush=0x404320 <nodes_term32_flush>, progress_callback=0x404190 <progress_callback>) at tyn_exsorter.c:131
#3 0x0000000000406ddf in tyn_build_index (tyn_config=0x61a060, index_name=0x4138d1 "mysql_index") at tyn_indexer.c:731
#4 0x0000000000403850 in main (argc=<optimized out>, argv=<optimized out>) at tyn_indexer.c:943
Upvotes: 1
Views: 522
Reputation: 581
You can use the coredump in this case. First of all enable coredumps ulimit -c unlimited
...the use gdb like this gdb <path to executable> <path to coredump>
...this coredump at the time of the segfault will contain the values of the variables and frames etc intact....so u can use this information for debugging purposes.
Upvotes: 1
Reputation: 24574
You need to compile and link with -g
flag to be able to use debugger; but you seem already to be doing that. print
(abbreviated p
) prints variable value; bt
, up
, down
, frame
are other useful commands. Otherwise, help
within gdb or info gdb
.
Upvotes: 1