$ gdb -c core core_dump_test GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2 Copyright (C) 2020 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". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from core_dump_test... [New LWP 1617] Core was generated by `./core_dump_test'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00005589d3919176 in stack_buffer_overflow () at core_dump_test.c:8 8 buffer[i] = 'O';
在gdb中,查看backtrace:
1 2 3 4
(gdb) bt #0 0x00005589d3919176 in stack_buffer_overflow () at core_dump_test.c:8 #1 0x00005589d39191a7 in main () at core_dump_test.c:12 (gdb)
For help, type "help". Type "apropos word" to search for commands related to "word"... --Type <RET> for more, q to quit, c to continue without paging--
Reading symbols from core_dump_test... [New LWP 1617] Core was generated by `./core_dump_test'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00005589d3919176 in stack_buffer_overflow () at core_dump_test.c:8 (gdb)
如果编译时没有添加-g, 调试信息和行号将无法解析:
1 2 3 4
(gdb) bt #0 0x00005589d3919176 in ?? () #1 0x00005589d39191a7 in ?? () (gdb)