在不更改代码的情况下生成NaN浮点数时停止调试器 [英] Stopping the debugger when a NaN floating point number is produced without a code change

查看:95
本文介绍了在不更改代码的情况下生成NaN浮点数时停止调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了 this

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);

因此,代码将更改为

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

 #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;
 }

这可以正常工作,但是您必须更改代码.我的问题是,在庞大的C和C ++代码库中,会在某个地方生成nan,但我不知道在哪里.不能将以上更改应用于文件和文件 跟踪错误.

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. It is not an option to apply the above change to hunderts of files and track the error.

是否有一种无需更改代码即可启用所有浮点异常的方法?有我不知道的编译选项吗?

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?

我们使用的是Intel icc版本15.0.3编译器.

We use the intel icc version 15.0.3 compiler.

推荐答案

无论您的代码跨度有多少个文件,您只需要在您的第一行添加feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT) 一次 main()功能.

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.

它将启用整个程序的异常,直到通过调用fedisableexcept()之类的另一个函数禁用异常为止.

It will enable the exceptions for your whole program until you disable the exceptions by calling another function such as fedisableexcept().

这篇关于在不更改代码的情况下生成NaN浮点数时停止调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆