QNX Neutrino 6:如何在div-by上生成SIGFPE?

时间:2014-05-06 16:07:15

标签: floating-point qnx-neutrino

我正在尝试交叉编译一个程序(如果有任何用途的Yorick)在LE ARM上运行...我想使用feenableexcept()来捕获SIGFPE ...麻烦是objdump目标库,显示没有这样的符号存在。有谁知道QNX库是否具有相同的功能?我一直在谷歌上搜索QNX对此的支持并没有太多运气......我只能看到,在我的目标平台的所有库中都没有feenableexcept符号......谢谢!

更新:我发现QNX有一个名为fpemu的库,它看起来很有趣,但似乎只存在于x86,mips和ppc ......有没有人知道是否有ARM版本?

我可能感兴趣的芯片使用的是at91sam9263

UPDATE2:所以在它周围配音时,QNX会出现以下documentation on fenv.h。基于此,我尝试了以下程序......

#pragma STD FENV_ACCESS ON
#include <stdio.h>
#include <signal.h>
#include <fenv.h>

void signal_handler (int signo) {
    if(signo == SIGFPE) {
      printf("Caught FPE\n");
    }
}

int main(int argc, char *argv[])
{
    double d;
    fexcept_t enables;

    signal(SIGFPE,(*signal_handler));   

    enables = fegettrapenable();
    printf("The FP trap enable mask is 0x%X\n", enables);

    if( fesettrapenable(fegettrapenable() | FE_DIVBYZERO) )
    {
    printf("### ERROR could not set the FE enable mask\n");
        fexcept_t enables = fegettrapenable();
    printf("The FP trap enable mask is 0x%X\n", enables);
        return(-1);
    }

    printf("Floating point mask successfully set\n");
    enables = fegettrapenable();
    printf("The FP trap enable mask is 0x%X and FE_DIVBYZERO is 0x%X\n", enables, (int)FE_DIVBYZERO);

    d = 2.0 / 0.0;
    printf("For div by zero, got the result %e\n", d);
    printf("The exception test is %d\n", fetestexcept(FE_DIVBYZERO));


    printf("Testing feraiseexcpetion()\n");
    feraiseexcept(FE_DIVBYZERO);

    return 0 ;
}

这给了我以下输出....

The FP trap enable mask is 0x0
Floating point mask successfully set
The FP trap enable mask is 0x4 and FE_DIVBYZERO is 0x4
For div by zero, got the result inf **<<<< DAMN IT - no signal!!!!**
The exception test is 0
Testing feraiseexcpetion()
Caught FPE

开溜!!它几乎看起来会起作用,除了div为零显然不会引发SIGFPE ......任何人都知道为什么?!

0 个答案:

没有答案