Use gdb to debug a segmentation fault
Posted: Thu Feb 26, 2015 4:27 pm
Compile the source with -g -O0 so that you can use gdb.
Using a makefile, it's something like:
Next, use gdb to get a stack trace:
bash$ gdb spaceshuttle.exe
gdb> run arguments
(cc1 will stop at the segmentation fault)
gdb> where
gdb> list
Using a makefile, it's something like:
Code: Select all
# enalbe GDB on for debugging
GDB = -g -O0
all: spaceshuttle.c
gcc $(GDB) -Wall -o spaceshuttle.exe functions.c encryptionlib.c -lspacelib -lpthread
clean:
$(RM) spaceshuttle.exe
Next, use gdb to get a stack trace:
bash$ gdb spaceshuttle.exe
gdb> run arguments
(cc1 will stop at the segmentation fault)
gdb> where
gdb> list