Debugging with Numba

Viewed 599

My first question here, tell me if I am doing things wrong.

My problem

I am writing a module using Numba. Of course I have run accross a segfault, and I can't find where it comes from. So I am trying to debug it using gdb from Numba, but it does not work: the segfault is raised but I get no information from where it comes from:

[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) 

During the gdb initialisation, this is also printed in stderr:

attach: No such file or directory.

Note that I have already managed the ptrace problem mentioned here by setting kernel.yama.ptrace_scope=0

Reproducing Numba's debug example

I don't know if it counts as a working reproducer, but I tried to run the example from the Numba documentation that I mentionned earlier :

  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)

And I can't get the same output as they do:

[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]

My error message does not indicate me the exact line of the segfault, just the jitted function..

And again, I have this message, which may be the source of my problem..

attach: No such file or directory.

Could anyone help me make this work ?

Or a link to an equivalent question ? I have found the documentation and forums really short when it comes to debugging Numba.

Or maybe alternative ways to trace a segfault in Numba jitted functions ?

Thank you for reading me, I hope it is understandable.

1 Answers

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

This is not segfault, this is SIGABRT because of double free or corruption that was detected by glibc. This kind of error is better debugged by Valgrind or AddressSanitizer, not gdb. If your program is relatively small use Valgrind because it is easier to use. If not I'd suggest to use AddressSanitizer.

Related