Skip to content

Instantly share code, notes, and snippets.

@sdstrowes
Last active December 16, 2015 14:20
Show Gist options
  • Save sdstrowes/5447936 to your computer and use it in GitHub Desktop.
Save sdstrowes/5447936 to your computer and use it in GitHub Desktop.
sds@ubuntu:~/test$ cat segfault.c
#include <stdio.h>
int main(void)
{
char* foo = NULL;
printf("%c\n", *foo);
return 0;
}
sds@ubuntu:~/test$
sds@ubuntu:~/test$
sds@ubuntu:~/test$ gcc -W -Wall -Wextra -g -o segfault segfault.c
sds@ubuntu:~/test$ ./segfault
Segmentation fault (core dumped)
sds@ubuntu:~/test$
sds@ubuntu:~/test$
sds@ubuntu:~/test$ gdb ./segfault core.5656
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/sds/test/segfault...done.
[New Thread 5656]
warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib/libc.so.6...Reading symbols from /usr/lib/debug/lib/libc-2.11.1.so...done.
done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.11.1.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Core was generated by `./segfault'.
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000400538 in main () at segfault.c:6
6 printf("%c\n", *foo);
(gdb) bt
#0 0x0000000000400538 in main () at segfault.c:6
(gdb) quit
sds@ubuntu:~/test$
sds@ubuntu:~/test$
sds@ubuntu:~/test$ gdb ./segfault
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/sds/test/segfault...done.
(gdb) r
Starting program: /home/sds/test/segfault
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400538 in main () at segfault.c:6
6 printf("%c\n", *foo);
(gdb) generate-core-file
Saved corefile core.5819
(gdb) quit
A debugging session is active.
Inferior 1 [process 5819] will be killed.
Quit anyway? (y or n) y
sds@ubuntu:~/test$
sds@ubuntu:~/test$
sds@ubuntu:~/test$ gdb ./segfault core.5819
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/sds/test/segfault...done.
[New Thread 5819]
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.11.1.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Core was generated by `/home/sds/test/segfault'.
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000400538 in main () at segfault.c:6
6 printf("%c\n", *foo);
(gdb) bt
#0 0x0000000000400538 in main () at segfault.c:6
(gdb) quit
sds@ubuntu:~/test$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment