产生 NaN 浮点数时停止调试器

Stopping the debugger when a NaN floating point number is produced(产生 NaN 浮点数时停止调试器)
本文介绍了产生 NaN 浮点数时停止调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C++ 程序.在程序中的某处(难以重现,但可重现)计算会导致浮点蜂设置为 NaN.由于涉及 NaN 的浮点运算会导致 NaN,因此传播速度很快.

I have an C++ program. Somewhere in the program (hard to reproduce, but reproduceable) a caclculation results in a float beeing set to a NaN. Since a floating point operation involving a NaN results in a NaN, this spreads fast.

有什么方法可以设置编译器 (gcc 4.4) 或调试器 (gdb) 在浮点运算导致 NaN 时停止?这将非常有用.

Is there any way I can setup the compiler (gcc 4.4) or the debuger (gdb) to stop when a floating point operation results in a NaN? That would be extremely useful.

谢谢!内森

PS:这可能很重要:我在 ubuntu linux 10.10 下工作.

PS: It might matter: I am working under ubuntu linux 10.10.

推荐答案

您可以启用浮点异常 - 参见 glibc 控制函数 - 当你的 NaN 值产生时你会得到一个 SIGFPE

You could enable floating point exceptions - see glibc Control Functions - then you'll get a SIGFPE when your NaN value is produced

这篇关于产生 NaN 浮点数时停止调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)