add the following option to the compilation flags:
-g
then, run the command leading to a segmentation fault in gdb.
Code:
[B]seb@godzilla:~$ cat sf.c [/B] int main(){ int*i=0; *i=0; /* will generate a segmentation fault */ return 0; }
Code:
[B]seb@godzilla:~$ gcc -g sf.c -o Program[/B]
Code:
[B]seb@godzilla:~$ gdb Program [/B] GNU gdb (GDB) 7.1-ubuntu Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/seb/Program...done.
Code:
[B](gdb) run[/B] Starting program: /home/seb/Program Program received signal SIGSEGV, Segmentation fault. 0x00000000004004d4 in main () at sf.c:3 3 *i=0;
Code:
[B](gdb) bt[/B] #0 0x00000000004004d4 in main () at sf.c:3
Leave a comment: