简体   繁体   English

在没有代码更改的情况下生成NaN浮点数时停止调试器

[英]Stopping the debugger when a NaN floating point number is produced without a code change

I read this and this . 我读到这个这个 The quintessence is that one can throw a SIGFPE if a nan is produced by including fenv.h and enabling all floating point exceptions but FE_INEXACT by feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); 精髓是,如果一个南由包括fenv.h并启用所有浮点异常,但所产生的一个可以抛出SIGFPE FE_INEXACT通过feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT);

Thus, the code changes form 因此,代码改变了形式

int main () {
   double dirty = 0.0;
   double nanvalue = 0.0/dirty;
   return 0;
 }

to

 #include <fenv.h>
 int main () {
     feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT);  // Enable all floating point exceptions but FE_INEXACT
     double dirty = 0.0;
     double nanvalue = 0.0/dirty;
     return 0;
 }

This works fine, but you have to change the code. 这工作正常,但您必须更改代码。 I have the problem, that in a huge c and c++ code base, somewhere a nan is produced and I don't know where. 我有问题,在一个巨大的c和c ++代码库中,某个地方生成了一个nan,我不知道在哪里。 It is not an option to apply the above change to hunderts of files and track the error. 将上述更改应用于文件的hunderts并跟踪错误不是一种选择。

Is there a way to enable the all floating point exceptions, WITHOUT a code change? 有没有办法在没有代码更改的情况下启用所有浮点异常? Is there a compile option I am not aware of? 有没有我不知道的编译选项?

We use the intel icc version 15.0.3 compiler. 我们使用intel icc 15.0.3版编译器。

No matter how many files your code spans, you only need to add feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT) once only, at the first line of your main() function. 无论你的代码有多少文件跨越,你只需要添加feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT)只有一次 ,你的第一行main()函数。

It will enable the exceptions for your whole program until you disable the exceptions by calling another function such as fedisableexcept() . 它将启用整个程序的异常,直到通过调用另一个函数(如fedisableexcept()禁用异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM