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

杀马特。学长 韩版系。学妹 提交于 2019-12-08 19:37:48

问题


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

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. 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?

We use the intel icc version 15.0.3 compiler.


回答1:


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.

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



来源:https://stackoverflow.com/questions/46170464/stopping-the-debugger-when-a-nan-floating-point-number-is-produced-without-a-cod

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!