How can program C issue a main dump without stopping?

I want C to dump the kernel under certain circumstances. This is a program that runs in a production environment and does not easily stop and restart to configure other types of debugging code. Also, since it's in a production environment, I don't want to call abort (). The issues under investigation are not easily replicated in a non-production environment. I want the program, when it detects certain problems, to itself create a core dump, preferably with enough information to rename the file, and then continue.

+26
c debugging coredump
Sep 25 '08 at 4:11
source share
5 answers
void create_dump(void) { if(!fork()) { // Crash the app in your favorite way here abort() || (*((void*)0) = 42); } } 

Complete the process and then the child crashes - he will give you a snapshot whenever you want

+52
Sep 25 '08 at 4:56
source share

Another way could be to use the Google Coredumper library. This creates a similar result for fork + abort technology, but works better with multi-threaded applications (it pauses all threads for some time before forking so that they do not mess in the child).

Example:

     #include <google / coredumper.h>
     ...
     WriteCoreDump ('core.myprogram');
     / * Keep going, we generated a core file,
      * but we didn't crash.
      * /
+4
Jul 10 '14 at 9:21
source share

Sun describes how to get the main file in Solaris, HP-UX, Redhat, and Windows here .

Solaris has a gcore program. HP-UX may have this. Otherwise, use gdb and its gcore commmand. Windows has win-dbg-root \ tlist.exe and win-dbg-root \ adplus.vbs

+3
Sep 25 '08 at 4:30
source share

Do you really want a kernel or just a stack? If all you need is a stacktrace, you can take a look at openource here and try to integrate the code from there or just call it from the command line enough.

I believe that some code in the gdb project may also be useful.

Another thing you might want to do is use gdb to join the running process.

 $ gdb /path/to/exec 1234 # 1234 is the pid of the running process 
+3
Sep 25 '08 at 4:33
source share

The source code for creating a core dump is in 'gcore', which is part of the gdb package.

In addition, the Sun has gcore .

In addition, you must have a separate process executing a core dump, as the current process must be paused. You will find the details in the gcore source, or you can simply launch your gcore platform with your process as a target.

+1
Sep 25 '08 at 4:21
source share



All Articles