【发布时间】: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
我希望附加到我的 Fortran 程序的调试器 (Gdb) 在某些编程情况下停止。 在 C/C++ 中,这很容易实现:Set breakpoint in C or C++ code programmatically for gdb on Linux
如何在 Fortran 中发出这样的信号?
【问题讨论】:
标签: fortran gdb signals sigint raise
只需调用与链接答案中相同的 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.h 或man raise。值 2 用于 POSIX。在 POSIX 系统上,您还可以使用 SIGTRAP = 5。
【讨论】:
SIGNAL 作为供应商扩展的函数或子例程。有关详细信息,请查看 gfortran 手册。
SIGNAL只能用于设置信号处理程序! (见gcc.gnu.org/onlinedocs/gfortran/SIGNAL.html)