How to programmatically cause a core dump in C/C++

后端 未结 10 1201
悲&欢浪女
悲&欢浪女 2020-11-28 01:24

I would like to force a core dump at a specific location in my C++ application.

I know I can do it by doing something like:

int * crash = NULL;
*cras         


        
10条回答
  •  迷失自我
    2020-11-28 02:01

    A few years ago, Google released the coredumper library.

    Overview

    The coredumper library can be compiled into applications to create core dumps of the running program -- without terminating. It supports both single- and multi-threaded core dumps, even if the kernel does not natively support multi-threaded core files.

    Coredumper is distributed under the terms of the BSD License.

    Example

    This is by no means a complete example; it simply gives you a feel for what the coredumper API looks like.

    #include 
    ...
    WriteCoreDump('core.myprogram');
    /* Keep going, we generated a core file,
     * but we didn't crash.
     */
    

    It's not what you were asking for, but maybe it's even better :)

提交回复
热议问题