1

I want the debugger (Gdb) attached to my Fortran program to stop under some programmed circumstances. In C/C++ this is easily possible: Set breakpoint in C or C++ code programmatically for gdb on Linux

How to raise such a signal in Fortran?

1 Answers1

2

Just call the same C system function as in the linked answer

  use iso_c_binding, only: c_int
  
  implicit none

  interface
    function raise(sig) bind(C, name="raise")
      use iso_c_binding, only: c_int
      integer(c_int) :: raise
      integer(c_int), value :: sig
    end function
  end interface

  integer(c_int), parameter :: SIGINT = 2
  
  
  print *, raise(SIGINT)
    
end

It is probably not easy to avoid entering the SIGINT integer value manually. Consult your signal.h or man raise. The value 2 is for POSIX. On POSIX systems you can also use SIGTRAP = 5.

  • If OP is using gfortran, it provides `SIGNAL` as a function or subroutine as vendor extension. Check the gfortran manual for details. – steve Oct 12 '21 at 15:26
  • If I understand the manual correctly `SIGNAL` can only be used to set a signal handler! (see https://gcc.gnu.org/onlinedocs/gfortran/SIGNAL.html) – user2722085 Oct 13 '21 at 09:25