|
| 1 | +# SPDX-FileCopyrightText: 2020 - 2024 Intel Corporation |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +"""Implements a custom debug metadata generator class for numba-dpex kernels. |
| 6 | +""" |
| 7 | + |
| 8 | +from numba.core import debuginfo |
| 9 | + |
| 10 | + |
| 11 | +class DIBuilder(debuginfo.DIBuilder): |
| 12 | + """Overrides Numba's default DIBuilder with numba-dpex-specific customizations.""" |
| 13 | + |
| 14 | + # pylint: disable=too-many-arguments |
| 15 | + def mark_subprogram(self, function, qualname, argnames, argtypes, line): |
| 16 | + """Sets DW_AT_name and DW_AT_linkagename tags for a kernel decorated function. |
| 17 | +
|
| 18 | + Numba generates a unique name for every function it compiles, but in |
| 19 | + upstream Numba the unique name is not used as the "qualified" name of |
| 20 | + the function. The behavior leads to a bug discovered in Numba-dpex when |
| 21 | + a compiled function uses closure variables. |
| 22 | + Refer (https://github.com/IntelPython/numba-dpex/issues/898). |
| 23 | + To resolve the issue numba-dpex uses the unique_name as the qualified |
| 24 | + name. Refer to |
| 25 | + :class:`numba_dpex.core.passes.passes.QualNameDisambiguationLowering`. |
| 26 | + However, doing so breaks setting GDB breakpoints based on function |
| 27 | + name as the function name is no longer what is in the source, but what |
| 28 | + is the unique name generated by Numba. To fix it, numba-dpex uses a |
| 29 | + modified DISubprogram metadata generator. The name (DW_AT_name) tag is |
| 30 | + set to the base function name, discarding the unique qualifier and |
| 31 | + linkagename is set to an empty string. |
| 32 | + """ |
| 33 | + name = qualname[0 : qualname.find("$")] # noqa: E203 |
| 34 | + argmap = dict(zip(argnames, argtypes)) |
| 35 | + |
| 36 | + di_subp = self._add_subprogram( |
| 37 | + name=name, |
| 38 | + linkagename="", |
| 39 | + line=line, |
| 40 | + function=function, |
| 41 | + argmap=argmap, |
| 42 | + ) |
| 43 | + function.set_metadata("dbg", di_subp) |
0 commit comments