Skip to content

Commit c020ccc

Browse files
authored
Print gdb version to ease debugging (#12836)
1 parent a6fb689 commit c020ccc

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

tests/stubtest_third_party.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import argparse
77
import os
8+
import re
89
import subprocess
910
import sys
1011
import tempfile
@@ -204,13 +205,7 @@ def setup_gdb_stubtest_command(venv_dir: Path, stubtest_cmd: list[str]) -> bool:
204205
print_error("gdb is not supported on Windows")
205206
return False
206207

207-
try:
208-
gdb_version = subprocess.check_output(["gdb", "--version"], text=True, stderr=subprocess.STDOUT)
209-
except FileNotFoundError:
210-
print_error("gdb is not installed")
211-
return False
212-
if "Python scripting is not supported in this copy of GDB" in gdb_version:
213-
print_error("Python scripting is not supported in this copy of GDB")
208+
if not gdb_version_check():
214209
return False
215210

216211
gdb_script = venv_dir / "gdb_stubtest.py"
@@ -277,6 +272,24 @@ def setup_gdb_stubtest_command(venv_dir: Path, stubtest_cmd: list[str]) -> bool:
277272
return True
278273

279274

275+
def gdb_version_check() -> bool:
276+
try:
277+
gdb_version_output = subprocess.check_output(["gdb", "--version"], text=True, stderr=subprocess.STDOUT)
278+
except FileNotFoundError:
279+
print_error("gdb is not installed")
280+
return False
281+
if "Python scripting is not supported in this copy of GDB" in gdb_version_output:
282+
print_error("Python scripting is not supported in this copy of GDB")
283+
return False
284+
m = re.search(r"GNU gdb\s+.*?(\d+\.\d+(\.[\da-z-]+)+)", gdb_version_output)
285+
if m is None:
286+
print_error("Failed to determine gdb version:\n" + gdb_version_output)
287+
return False
288+
gdb_version = m.group(1)
289+
print(f"({gdb_version}) ", end="", flush=True)
290+
return True
291+
292+
280293
def setup_uwsgi_stubtest_command(dist: Path, venv_dir: Path, stubtest_cmd: list[str]) -> bool:
281294
"""Perform some black magic in order to run stubtest inside uWSGI.
282295

0 commit comments

Comments
 (0)