gpt4 book ai didi

带有 SIGFPE 的核心转储用于非零除法

转载 作者:行者123 更新时间:2023-12-02 04:55:58 27 4
gpt4 key购买 nike

我有一个可疑的 qemu-kvm 进程与 SIGFPE 核心转储:

Program terminated with signal 8, Arithmetic exception.
#0 bdrv_exceed_io_limits (bs=0x7f75916b7270, is_write=false, nb_sectors=1)
at /usr/src/debug/qemu-kvm-0.12.1.2/block.c:3730
3730 elapsed_time /= (NANOSECONDS_PER_SECOND);

其中 elapsed_timedouble(下面 gdb 输出中的值)并且 NANOSECONDS_PER_SECOND 是一个宏:

#define NANOSECONDS_PER_SECOND  1000000000.0

我想不出应该如何导致 SIGFPE 的原因。有什么线索吗?

场景:我使用 RHEL-6.5 作为主机并尝试启动 Windows 客户机。它可以用相同的命令稳定地重现。

完整回溯:

(gdb) bt
#0 bdrv_exceed_io_limits (bs=0x7ffff86f9270, is_write=false, nb_sectors=1) at /usr/src/debug/qemu-kvm-0.12.1.2/block.c:3730
#1 bdrv_io_limits_intercept (bs=0x7ffff86f9270, is_write=false, nb_sectors=1) at /usr/src/debug/qemu-kvm-0.12.1.2/block.c:181
#2 0x00007ffff7e0bf6d in bdrv_co_do_readv (bs=0x7ffff86f9270, sector_num=0, nb_sectors=1, qiov=0x7fffe8000ab8, flags=<value optimized out>)
at /usr/src/debug/qemu-kvm-0.12.1.2/block.c:2136
#3 0x00007ffff7e0c293 in bdrv_co_do_rw (opaque=0x7fffe8000b00) at /usr/src/debug/qemu-kvm-0.12.1.2/block.c:3880
#4 0x00007ffff7e125eb in coroutine_trampoline (i0=<value optimized out>, i1=<value optimized out>)
at /usr/src/debug/qemu-kvm-0.12.1.2/coroutine-ucontext.c:129
#5 0x00007ffff5718ba0 in ?? () from /lib64/libc.so.6
#6 0x00007fffffffbf60 in ?? ()
#7 0x0000000000000000 in ?? ()

(gdb) disass
0x00007ffff7e0b6ae <+190>: mov 0x8a0(%rbx),%rax
0x00007ffff7e0b6b5 <+197>: test %rax,%rax
=> 0x00007ffff7e0b6b8 <+200>: divsd 0x170660(%rip),%xmm0 # 0x7ffff7f7bd20
0x00007ffff7e0b6c0 <+208>: je 0x7ffff7e0b950 <bdrv_io_limits_intercept+864>
0x00007ffff7e0b6c6 <+214>: mov 0x888(%rbx),%rsi

(gdb) x/gf 0x7ffff7f7bd20
0x7ffff7f7bd20: 1000000000

(gdb) p elapsed_time
$3 = 919718

(gdb) p $_siginfo
$1 = {si_signo = 8, si_errno = 0, si_code = 6, _sifields = {_pad = {-136186690, 32767, 4244976, 0, -560757824, 32767, -
-560757344, 32767, 0, 0, 0, 0, 0, 0, 34884976, 0, -136186690, 32767, 34884976, 0, 4258127, 0, 0, 0, -55876128, 3265
-136186690, si_uid = 32767}, _timer = {si_tid = -136186690, si_overrun = 32767, si_sigval = {sival_int = 4244976, s
_rt = {si_pid = -136186690, si_uid = 32767, si_sigval = {sival_int = 4244976, sival_ptr = 0x40c5f0}}, _sigchld = {s
si_uid = 32767, si_status = 4244976, si_utime = -2408436515056123904, si_stime = -584917379700457473}, _sigfault
0x7ffff7e1f4be}, _sigpoll = {si_band = 140737352168638, si_fd = 4244976}}}

那么,这个 divsd 指令可能有什么问题?关于如何调试它有什么建议吗?

我自己回答:这是一个内核错误,它意外地将 mxcsr 设置为一些错误的值,当该位未正确屏蔽时,Linux 内核会触发 SIGFPE 代码 INEXACT。

最佳答案

您代码中的 SIGFPE 不是由于被零除,而是由于以下一些原因:

FPE_FLTOVF_TRAP: float 溢出陷阱。
FPE_FLTUND_TRAP: float 下溢陷阱。 (通常不会启用对 float 下溢的捕获。)

Macro: int SIGFPE:

The SIGFPE signal reports a fatal arithmetic error. Although the name is derived from "floating-point exception", this signal actually covers all arithmetic errors, including division by zero and overflow. If a program stores integer data in a location which is then used in a floating-point operation, this often causes an "invalid operation" exception, because the processor cannot recognize the data as a floating-point number.

Actual floating-point exceptions are a complicated subject because there are many types of exceptions with subtly different meanings, and the SIGFPE signal doesn't distinguish between them. The IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985) defines various floating-point exceptions and requires conforming computer systems to report their occurrences. However, this standard does not specify how the exceptions are reported, or what kinds of handling and control the operating system can offer to the programmer.

因为:
NANOSECONDS_PER_SECOND = 1000000000.0elapsed_time = 919718 所以 elapsed_time/= (NANOSECONDS_PER_SECOND); => 919718/100 0000 000.0 == 0.0000919718,我确信这会导致 float 下溢陷阱 SIGFPF 的原因。

float 溢出陷阱不可能是个案,因为操作是除法。

关于带有 SIGFPE 的核心转储用于非零除法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17961431/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com