[Patch, Fortran] PR51197 - print signal number before backtrace [RFC]

Janne Blomqvist blomqvist.janne@gmail.com
Mon Jan 9 20:32:00 GMT 2012


On Mon, Jan 9, 2012 at 21:21, Tobias Burnus <burnus@net-b.de> wrote:
> Hello,
>
> in GCC 4.6, gfortran printed before the backtrace, e.g.,
>  Program received signal 8 (SIGFPE): Floating-point exception.
> to STDERR followed by the backtrace.
>
> This was done by registering an error handler and - finishing with a
> sys_exit(5). Since 4.7 with the patch for PR 48915 (comment 3) [1], GCC does
> no longer print this line but just a simple:
>  A fatal error occurred! Backtrace for this error:
> followed by the the backtrace. It then raises the signal via the default
> handler. (The system might then print more information, e.g. "Floating point
> exception (core dumped)", which might end up on STDOUT contrary to the
> backtrace which goes to STDERR.)
>
> [1] Cf. runtime/compile_options.c at
> http://gcc.gnu.org/viewcvs?view=revision&revision=173750
>
> The attached patch by Harald Anlauf (cf. PR, minutely modified by me)
> restores GCC 4.6's printing of the signal number by simply printing this
> information before the back trace. (Copyright wise, the patch is simple even
> as it exceeds ten lines: it mostly undoes part of Rev. 173750 [1].)
>
> With the patch, one can get (cf. PR) an output to STDERR like:
>
> Program received signal 8 (SIGFPE): Floating-point exception.
>
> Backtrace for this error:
> #0  0x805891F in _gfortrani_show_backtrace at backtrace.c:261
> #1  0x804951F in _gfortrani_backtrace_handler at compile_options.c:93
> #2  0xFFFFE3FF
> #3  0x80493B3 in foo at gfcbug113.f90:8
> #4  0x804940B in backtrace at gfcbug113.f90:3
>
>
> which might be followed by the OS diagnostic, e.g. on Linux with a Bash one
> gets the following to STDOUT:
>
> Floating point exception (core dumped)
>
>
> OK for the trunk?

I see this was already Ok'ed, but still a few comments:

- The integer values for the signal numbers are not standardized,
hence printing them might give the user a false impression that these
numbers convey some information beyond whichever SIG* macro they map
to on that particular target.

- It doesn't test all the signals which are actually handled, see
compile_options.c:set_options(). Also, as a minor point, there's no
need to have #ifdef tests for the C89 signals, again see
set_options().

- The floor is now open for some enterprising person to file a bug
complaining that duplicate information is printed when, as usual,
stdout and stderr are output to the same device. ;-)

-- 
Janne Blomqvist



More information about the Gcc-patches mailing list