0

我正在使用 GNU Scientific Library 开发一个程序。它在将非线性方程求解一半后给出“非法指令(核心转储)”。见下文。这种“非法指令”错误的通常原因是什么,在这种情况下我该如何调试?

...
iter  0: A = 1.0000, lambda = 1.0000, b = 0.0000, cond(J) =   6.0000, |f(x)| = 101.0200
iter  1: A = 3.5110, lambda = -12.8820, b = 1.2364, cond(J) =  92.8216, |f(x)| = -nan
iter  2: A = 3.5110, lambda = -12.8820, b = 1.2364, cond(J) =      nan, |f(x)| = -nan
iter  3: A = 3.5110, lambda = -12.8820, b = 1.2364, cond(J) =      nan, |f(x)| = -nan
iter  4: A = 3.5110, lambda = -12.8820, b = 1.2364, cond(J) =      nan, |f(x)| = -nan
Illegal instruction (core dumped)

有了gdb,我得到了一些额外的信息。

Program received signal SIGILL, Illegal instruction.
0x00000000004d1030 in nielsen_reject (nu=<optimized out>, mu=<optimized out>) at nielsen.c:98
98    *nu <<= 1;
(gdb) p nu
$1 = <optimized out>
(gdb) x/i $pc
 => 0x4d1030 <trust_iterate+8912>:  ud2 

上面,nielsen.c98看起来像这样

...
static int
nielsen_reject(double * mu, long * nu)
{
  *mu *= (double) *nu;

  /* nu := 2*nu */
  *nu <<= 1;

  return GSL_SUCCESS;
}

CPU 是 x86_64 根据uname -m. 操作系统是 Mac(主机)上的 Ubuntu 16.04 VirtualMachine。GCC 版本是 5.4。

gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

代码使用 gcc 编译,并打开了 Address Sanitizer 和 Undefined Sanitizer ( -fsanitize=address,undefined)。

当消毒剂打开时,编译器似乎会产生“ud2”指令。我想知道这个错误是编译器错误、消毒程序错误还是代码错误?

4

0 回答 0