【问题标题】:Debugging with Numba使用 Numba 进行调试
【发布时间】:2021-01-21 10:34:04
【问题描述】:

我在这里的第一个问题,如果我做错了,请告诉我。

我的问题

我正在使用 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

解决了提到的 ptrace 问题here

重现 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]

我的错误消息并没有指出段错误的确切行,只是 jitted 函数..

再一次,我收到了这条消息,这可能是我的问题的根源..

attach: No such file or directory.

谁能帮我完成这项工作?

或指向等效问题的链接?在调试 Numba 时,我发现文档和论坛非常简短。

或者可能是在 Numba jitted 函数中跟踪段错误的替代方法?

感谢您阅读我的内容,希望可以理解。

【问题讨论】:

    标签: python gdb numba


    【解决方案1】:

    段错误被提出,但我没有从它的来源获得任何信息

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

    【讨论】:

    • 你是对的,这不是段错误。不过,我之前也有过。而且我想也许我至少可以用 gdb 追踪错误的根源,但也许 SIGABRT 不可能? Valgrind 与 Numba 兼容吗?我没有看到任何指向它的东西。
    • 好的,文档中有关于using Memcheck with Numba 的部分。我的错,我错过了。我试试看。
    • 对我来说似乎更复杂。错误是无法阅读的消息,我不知道我是否在代码中。
    猜你喜欢
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    • 2011-07-26
    • 2011-08-16
    相关资源
    最近更新 更多