Use gdb to debug a segmentation fault

admin
Site Admin
Posts: 12
Joined: Thu Oct 03, 2013 5:49 pm

Use gdb to debug a segmentation fault

Postby admin » 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:

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

Return to “C/C++ development”

Who is online

Users browsing this forum: No registered users and 1 guest