Force a core dump?

Force a core dump?

Post by Eric M. Bo » Tue, 18 Mar 1997 04:00:00



Is it possible to force a core dump in a program, and still have the program
continue running?  Forcing a core dump is easy with something like:

{
  char *dump=0;
  sprintf(dump, "This will segfault");

Quote:}

The best idea I've had is something like:

void
dump_core()
{
  switch(fork()) {
    case -1:
      exit(errno);
      break;
    case 0:
      {
        char *dump=0;
        sprintf(dump, "This will segfault");
        break;
      }
    default:
       return;
  }

Quote:}

This will cause the program to fork, and the child can then dump core.  The
parent is then allowed to continue running.  Is there a better way to do this?

Breif rational for trying this:
I want to write a sighandler that catches Seg-faults, bus errors, etc. and dumps
core so I can debug the program and find the error.  But I want the program to
re-exec itself also to attempt some sort of recovery from the error.

Eric

--------------------------------+----------------------------------------------
Eric Boyd (TSMA)                |       "It's easier to ask for
InterDimensions Corp.           |        forgiveness than for permission."
25 Ellery St.                   |
Cambridge Ma, 02138             |       "640K ought to be enough for anybody."
617-661-4200                    |               -- Bill Gates, 1981
                                |

 
 
 

Force a core dump?

Post by Boyd Rober » Wed, 19 Mar 1997 04:00:00



Quote:

>Is it possible to force a core dump in a program, and still have the program
>continue running?  Forcing a core dump is easy with something like:

You're better off calling abort(3) rather than relying on address space trickery.

--

``Not only is UNIX dead, but it's starting to smell really bad.''  -- rob

 
 
 

Force a core dump?

Post by Andrew Giert » Wed, 19 Mar 1997 04:00:00


 Eric> Is it possible to force a core dump in a program, and still
 Eric> have the program continue running?  Forcing a core dump is easy
 Eric> with something like:

 Eric> {
 Eric>   char *dump=0;
 Eric>   sprintf(dump, "This will segfault");
 Eric> }

Yuk!

 [code using fork() elided]

 Eric> This will cause the program to fork, and the child can then
 Eric> dump core.  The parent is then allowed to continue running.  Is
 Eric> there a better way to do this?

 Eric> Breif rational for trying this: I want to write a sighandler
 Eric> that catches Seg-faults, bus errors, etc. and dumps core so I
 Eric> can debug the program and find the error.  But I want the
 Eric> program to re-exec itself also to attempt some sort of recovery
 Eric> from the error.

I'd do it like this:

void dump_core()
{
    if (fork() == 0)
        raise(SIGABRT);

Quote:}

(The lack of an error check is deliberate.)

Your method would not work well if called from a handler for SIGSEGV,
unless that handler had been installed with "oldstyle" semantics.
Remember: use sigaction(), *NEVER* use signal(), even though on some
systems signal() gives you the behaviour you want. On a BSD system,
if you cause a segfault within a signal handler for SIGSEGV, the
probable result is an infinite loop trying to retry the faulting
instruction.

--
Andrew.

 
 
 

Force a core dump?

Post by Fletcher.Gl.. » Wed, 19 Mar 1997 04:00:00


If you want to continue running try:

char buf[32];

sprintf(buf, "gcore %d", getpid());
system(buf);

The above code will show the top of stack in system(), but
everything below will be your original context.



>Is it possible to force a core dump in a program, and still have the program
>continue running?  Forcing a core dump is easy with something like:

>{
>  char *dump=0;
>  sprintf(dump, "This will segfault");
>}

>The best idea I've had is something like:

>void
>dump_core()
>{
>  switch(fork()) {
>    case -1:
>      exit(errno);
>      break;
>    case 0:
>      {
>        char *dump=0;
>        sprintf(dump, "This will segfault");
>        break;
>      }
>    default:
>       return;
>  }
>}

>This will cause the program to fork, and the child can then dump core.  The
>parent is then allowed to continue running.  Is there a better way to do this?

>Breif rational for trying this:
>I want to write a sighandler that catches Seg-faults, bus errors, etc. and dumps
>core so I can debug the program and find the error.  But I want the program to
>re-exec itself also to attempt some sort of recovery from the error.

>Eric

>--------------------------------+----------------------------------------------
>Eric Boyd (TSMA)                |       "It's easier to ask for
>InterDimensions Corp.           |        forgiveness than for permission."
>25 Ellery St.                   |
>Cambridge Ma, 02138             |       "640K ought to be enough for anybody."
>617-661-4200                    |               -- Bill Gates, 1981
>                                |


 
 
 

Force a core dump?

Post by Shawn Baye » Wed, 19 Mar 1997 04:00:00




Quote:>Breif rational for trying this:
>I want to write a sighandler that catches Seg-faults, bus errors, etc. and dumps
>core so I can debug the program and find the error.  But I want the program to
>re-exec itself also to attempt some sort of recovery from the error.

You may wish to look into sigaction().

Shawn

 
 
 

Force a core dump?

Post by Andy Knigh » Thu, 20 Mar 1997 04:00:00


Isn't gcore peculiar to Solaris?

--
Andy Knight



Quote:> If you want to continue running try:

> char buf[32];

> sprintf(buf, "gcore %d", getpid());
> system(buf);

> The above code will show the top of stack in system(), but
> everything below will be your original context.

 
 
 

Force a core dump?

Post by Fletcher.Gl.. » Thu, 20 Mar 1997 04:00:00


It may be peculiar to Sun - it is present in both SunOS 4.x and Solaris.



>Isn't gcore peculiar to Solaris?

>--
>Andy Knight



>> If you want to continue running try:

>> char buf[32];

>> sprintf(buf, "gcore %d", getpid());
>> system(buf);

>> The above code will show the top of stack in system(), but
>> everything below will be your original context.

 
 
 

1. dump core or not dump core

Howdy,

Some of my programs dump core, others don't. I tried
it on RedHat 6.1 and Mandrake 7.0 with kernels 2.2.14
and 2.2.15. I tried tcsh and bash with coredumpsize
set to 1GB. It seems to be application specific.

Is there any other criteria when suppressing apart from
the type of signal and the size limitation?
The application that doesn't dump core contains signal
handlers for some signals, but not for SEGV or ABRT.

Ruppert

 -----------------------------------------------------------------

 Dept of Elec. & Comp. Engr.    http://alpha.ece.ucsb.edu/~ruppert
 University of California       Phone: (805) 893-7788
 Santa Barbara, CA 93106        Fax:   (805) 893-3262
 -----------------------------------------------------------------

2. kernel BUG at drivers/scsi/scsi_lib.c:819 with 2.5.44-ac5

3. core dumps core dumps everywhere...

4. I would like to thank you

5. How do I force a core dump

6. White block mouse in X-Window

7. "ps -u" forces core dump

8. ADSM server process growing too much

9. Forcing a Core Dump

10. How to force a core dump

11. how to force a core file dump ?

12. forcing a core dump

13. Forcing a core dump