------- Comment #5 from fxcoudert at gcc dot gnu dot org 2009-02-22 22:33
-------
(In reply to comment #3)
> Try abort(). (Though I do not recall whether it works, I think it does.)
Does not work. abort() raises a SIGABRT, and we only catch SIGSEGV, SIGBUS,
SIGILL and SIGFPE.
>> Anyway I'm looking for a solution that keeps the
>> program running after the backtrace.
One such solution that I can see (other than adding a new intrinsic) is to
modify the library to also catch SIGUSR2 and generate a backtrace when it's
received (untested patch below); that way, a backtrace can be emitted without
the code stopping, either
-- programmaticaly by calling the KILL and GETPID intrinsics, or the POSIX
functions via ISO_C_BINDING
-- by the user sending the signal from another terminal, to know where his
program is stuck
The only issue I see with that is that SIGUSR2 is a symbolic constant, not
available in Fortran code, so that the user needs to know what (potentialy
nonportable) signal number it corresponds to.
diff -rpu libgfortran/runtime/compile_options.c
libgfortran.new/runtime/compile_options.c
--- libgfortran/runtime/compile_options.c 2009-02-22 23:25:25.000000000
+0100
+++ libgfortran.new/runtime/compile_options.c 2009-02-22 23:30:20.000000000
+0100
@@ -73,6 +73,13 @@ handler (int signum)
desc = "Floating-point exception";
break;
#endif
+
+#if defined(SIGUSR2)
+ case SIGUSR2:
+ name = "SIGUSR2";
+ desc = "User-defined signal";
+ break;
+#endif
}
if (name)
@@ -80,6 +87,16 @@ handler (int signum)
else
st_printf ("\nProgram received signal %d.\n", signum);
+#if defined(SIGUSR2)
+ if (signum == SIGUSR2
+ && (options.backtrace == 1
+ || (options.backtrace == -1 && compile_options.backtrace == 1)))
+ {
+ show_backtrace ();
+ return;
+ }
+#endif
+
sys_exit (5);
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36044