使用Numba进行调试

2024-09-27 00:19:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我的第一个问题是,告诉我我是否做错了

我的问题

我正在用Numba编写一个模块。当然,我已经运行了一个分段故障,我找不到它来自哪里。因此,我试图调试它using gdb from Numba,但它不起作用:segfault被引发,但我没有从它的来源获得任何信息:

[Reading symbols]
28  ../sysdeps/unix/sysv/linux/nanosleep.c: Aucun fichier ou dossier de ce type.
0x00007feacc67ea30 in __GI___nanosleep (requested_time=0x7ffdfe227510, 
    remaining=0x7ffdfe227510) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
Breakpoint 1 at 0x7fea9d234150: file numba/_helperlib.c, line 1131.
Continuing.
double free or corruption (!prev)
51  ../sysdeps/unix/sysv/linux/raise.c: Aucun fichier ou dossier de ce type.

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
(gdb) 

在gdb初始化期间,这也会打印在stderr中:

attach: No such file or directory.

注意,我已经通过设置kernel.yama.ptrace_scope=0

复制Numba的调试示例

我不知道它是否算是一个正常工作的复制机,但我试着运行我前面提到的Numba文档中的示例:

  from numba import njit, gdb_init
  import numpy as np

  @njit(debug=True)
  def foo(a, index):
      gdb_init() # instruct Numba to attach gdb at this location, but not to pause execution
      b = a + 1
      c = a * 2.34
      d = c[index] # access an address that is a) invalid b) out of the page
      print(a, b, c, d)

  bad_index = int(1e9) # this index is invalid
  z = np.arange(10)
  r = foo(z, bad_index)
  print(r)

我无法获得与他们相同的输出:

[Reading symbols]
0x00007efcb5a60a30 in __GI___nanosleep (requested_time=0x7ffff4990f70, 
    remaining=0x7ffff4990f70) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28  ../sysdeps/unix/sysv/linux/nanosleep.c: Aucun fichier ou dossier de ce type.
Breakpoint 1 at 0x7efcabf3d150: file numba/_helperlib.c, line 1131.
Continuing.
Traceback (most recent call last):
  File "/home/.../test_segfault.py", line 16, in <module>
    r = foo(z, bad_index)
IndexError: index is out of bounds
[Inferior 1 (process 4299) exited with code 01]

我的错误消息并没有指明SEGFULT的确切行,只是jitted函数

再一次,我有这个信息,这可能是我的问题的根源

attach: No such file or directory.

有人能帮我做这件事吗

或是与一个同等问题的链接?我发现文档和论坛在调试Numba时非常简短

或者可以用其他方法跟踪Numba jitted函数中的segfault

谢谢你阅读我的文章,我希望这是可以理解的


Tags: indexlinuxunixouatfilesysvnumba
1条回答
网友
1楼 · 发布于 2024-09-27 00:19:01

the segfault is raised but I get no information from where it comes from

这不是SEGFULT,这是SIGABRT,因为glibc检测到双重自由或损坏。这种错误最好由Valgrind或AddressSanitizer调试,而不是由gdb调试。如果您的程序相对较小,请使用Valgrind,因为它更易于使用。如果不是的话,我建议使用消毒液

相关问题 更多 >

    热门问题