How to set a breakpoint programmatically in Fortran / Raise a SIGINT in Fortran

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 answer

  • answered 2021-10-12 09:03 Vladimir F

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

      use iso_c_binding, only: c_int
      implicit none
        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)

    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.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum