Skip to content

Commit 0287101

Browse files
author
Diptorup Deb
committed
Fixes breakpoint on function name.
1 parent ae07cb6 commit 0287101

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

numba_dpex/core/debuginfo.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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)

numba_dpex/kernel_api_impl/spirv/target.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from numba.core.typing import cmathdecl, enumdecl
2222

2323
from numba_dpex.core.datamodel.models import _init_kernel_data_model_manager
24+
from numba_dpex.core.debuginfo import DIBuilder as DpexDIbuilder
2425
from numba_dpex.core.types import IntEnumLiteral
2526
from numba_dpex.core.typing import dpnpdecl
2627
from numba_dpex.core.utils import itanium_mangler
@@ -135,6 +136,7 @@ class SPIRVTargetContext(BaseContext):
135136

136137
implement_powi_as_math_call = True
137138
allow_dynamic_globals = True
139+
DIBuilder = DpexDIbuilder
138140

139141
def __init__(self, typingctx, target=SPIRV_TARGET_NAME):
140142
super().__init__(typingctx, target)

0 commit comments

Comments
 (0)