RFC: internal_error() change + abort()

Andrew Cagney ac131313@cygnus.com
Mon Jul 24 17:58:00 GMT 2000


Michael Snyder wrote:
> 
> Andrew Cagney wrote:
> >
> > Michael Snyder wrote:
> >
> > > How do you decide when it's safe to NOT abort?
> > > Eg. if a malloc call fails, you're probably completely
> > > out of virtual memory.  Are you sure printf will work
> > > under such a circumstance?
> >
> > Internal error asks for permission to abort.  If the user really does
> > want to continue they can (but they have been warned :-).
> > internal_error() its self keeps an eye out for a re-entrant call (say
> > the printf failed) and will do a write() abort() in that case.
> >
> > Of course, a lack of stack space is always fatal :-)
> 
> What I meant was, how do you know if internal_error can
> call printf, or prompt the user to decide whether to
> continue, if there is no virtual memory or heap space left?

You don't know. internal_verror() eventually calls asprintf() (via
vfprintf_unfiltered()).  That calls malloc().  If that malloc() call
fails, it will re-call internal_verror().  The rentrant call should
trigger a failsafe abort:

  static int dejavu = 0;
  ...
  /* don't allow infinite error recursion. */
  switch (dejavu)
    {
    case 0:
      dejavu = 1;
      break;
    case 1:
      dejavu = 2;
      fputs_unfiltered (msg, gdb_stderr);
      abort ();
    default:
      dejavu = 3;
      write (STDERR_FILENO, msg, sizeof (msg));
      exit (1);
    }
  ...
  vfprintf_unfiltered (gdb_stderr, fmt, ap);
  ...
  dejavu = 0;
  return_to_top_level (RETURN_ERROR);

	Andrew


More information about the Gdb-patches mailing list