【问题标题】:How to set a breakpoint programmatically in Fortran / Raise a SIGINT in Fortran如何在 Fortran 中以编程方式设置断点/在 Fortran 中引发 SIGINT
【发布时间】:2021-10-12 08:44:02
【问题描述】:

我希望附加到我的 Fortran 程序的调试器 (Gdb) 在某些编程情况下停止。 在 C/C++ 中,这很容易实现:Set breakpoint in C or C++ code programmatically for gdb on Linux

如何在 Fortran 中发出这样的信号?

【问题讨论】:

    标签: fortran gdb signals sigint raise


    【解决方案1】:

    只需调用与链接答案中相同的 C 系统函数

      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
    

    避免手动输入 SIGINT 整数值可能并不容易。请咨询您的signal.hman raise。值 2 用于 POSIX。在 POSIX 系统上,您还可以使用 SIGTRAP = 5

    【讨论】:

    • 如果 OP 使用 gfortran,它会提供 SIGNAL 作为供应商扩展的函数或子例程。有关详细信息,请查看 gfortran 手册。
    • 如果我对手册的理解正确SIGNAL只能用于设置信号处理程序! (见gcc.gnu.org/onlinedocs/gfortran/SIGNAL.html
    猜你喜欢
    • 2013-04-05
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多