Skip to content

Commit c509434

Browse files
authored
setup.py: add DEBUG variable to help debugging with gdb (#178)
1 parent 0d1adf7 commit c509434

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

tests/setup.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import sysconfig
1313

1414

15+
# Set to true to debug C/C++ extensions in gdb
16+
DEBUG = False
17+
1518
# C++ is only supported on Python 3.6 and newer
1619
TEST_CXX = (sys.version_info >= (3, 6))
1720

@@ -76,8 +79,13 @@
7679
('test_pythoncapi_compat_cpp14ext', ['/std:c++14', '/Zc:__cplusplus']),
7780
]
7881

82+
DEBUG_FLAGS = ('-O0', '-ggdb')
83+
7984

8085
def main():
86+
cflags = list(CFLAGS)
87+
cxxflags = list(CXXFLAGS)
88+
8189
# gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
8290
# option emits a C++ compiler warning. Remove "-std11" option from the
8391
# CC command.
@@ -92,23 +100,27 @@ def main():
92100
# CC env var overrides sysconfig CC variable in setuptools
93101
os.environ['CC'] = cmd
94102

103+
if DEBUG:
104+
cflags.extend(DEBUG_FLAGS)
105+
cxxflags.extend(DEBUG_FLAGS)
106+
95107
# C extension
96108
extensions = []
97109
for std in C_VERSIONS:
98110
if not MSVC:
99-
cflags = CFLAGS + ['-std=%s' % std]
111+
flags = cflags + ['-std=%s' % std]
100112
else:
101-
cflags = CFLAGS + ['/std:%s' % std]
113+
flags = cflags + ['/std:%s' % std]
102114
c_ext = Extension(
103115
'test_pythoncapi_compat_cext_%s' % std,
104116
sources=['test_pythoncapi_compat_cext.c'],
105-
extra_compile_args=cflags)
117+
extra_compile_args=flags)
106118
extensions.append(c_ext)
107119

108120
if TEST_CXX:
109121
# C++ extension
110122
for name, std_flags in CXX_VERSIONS:
111-
flags = list(CXXFLAGS)
123+
flags = list(cxxflags)
112124
if std_flags is not None:
113125
flags.extend(std_flags)
114126
cpp_ext = Extension(

0 commit comments

Comments
 (0)