Since kernel 2.6.19, Linux supports an alternate syntax for the /proc/sys/kernel/core_pattern file. If the first character of this file is a pipe symbol (|), then the remainder of the line is interpreted as the command-line for a user-space program (or script) that is to be executed. Instead of being written to a disk file, the core dump is given as standard input to the program.
GNU gdb (GDB) 8.1 Copyright (C) 2018 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-pc-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 /home/yzy/Repos/naive-pascal-compiler/cmake-build-debug/npc...done. [New LWP 16042] Core was generated by `./npc'. Program terminated with signal SIGABRT, Aborted. #0 0x00007f8df8f4986b in raise () from /usr/lib/libc.so.6 (gdb)
打印了如上信息并且进入了 gdb 的 REPL。
使用 backtrace 命令查看事故现场的调用栈:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
(gdb) bt #0 0x00007f8df8f4986b in raise () from /usr/lib/libc.so.6 #1 0x00007f8df8f3440e in abort () from /usr/lib/libc.so.6 #2 0x00007f8df8f342e0 in __assert_fail_base.cold.0 () from /usr/lib/libc.so.6 #3 0x00007f8df8f42112 in __assert_fail () from /usr/lib/libc.so.6 #4 0x0000563a871686f3 in npc::cast_node<npc::ExprNode> (node=std::shared_ptr<npc::AbstractNode> (use count 3, weak count 1) = {...}) at /home/yzy/repos/naive-pascal-compiler/src/utils/../ast/../utils/ast_utils.hpp:37 #5 0x0000563a87166c3c in npc::BinopExprNode::BinopExprNode (this=0x563a87be6a80, _Op=npc::BinopExprNode::OP::ge, _lhs=std::shared_ptr<npc::AbstractNode> (use count 3, weak count 1) = {...}, _rhs=std::shared_ptr<npc::AbstractNode> (use count 2, weak count 1) = {...}) at /home/yzy/repos/naive-pascal-compiler/src/utils/../ast/type_nodes.hpp:65 #6 0x0000563a8716afe3 in npc::make_node<npc::BinopExprNode, npc::BinopExprNode::OP, std::shared_ptr<npc::AbstractNode>&, std::shared_ptr<npc::AbstractNode>&> ( args#0=@0x7fff62efc900: npc::BinopExprNode::OP::ge, args#1=std::shared_ptr<npc::AbstractNode> (use count 3, weak count 1) = {...}, args#2=std::shared_ptr<npc::AbstractNode> (use count 2, weak count 1) = {...}) at /home/yzy/repos/naive-pascal-compiler/src/utils/../ast/../utils/ast_utils.hpp:44 #7 0x0000563a8716582b in yyparse () at src/parse.y:271 #8 0x0000563a8715e499 in main (argc=1, argv=0x7fff62efd888) at /home/yzy/repos/naive-pascal-compiler/src/main.cpp:20