Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ede14ae

Browse files
committed
Merge 3.5 (test_gdb)
2 parents 2ec5587 + 329ca71 commit ede14ae

1 file changed

Lines changed: 29 additions & 19 deletions

File tree

Lib/test/test_gdb.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,32 @@
2121
from test import support
2222
from test.support import run_unittest, findfile, python_is_optimized
2323

24-
try:
25-
gdb_version, _ = subprocess.Popen(["gdb", "-nx", "--version"],
26-
stdout=subprocess.PIPE).communicate()
27-
except OSError:
28-
# This is what "no gdb" looks like. There may, however, be other
29-
# errors that manifest this way too.
30-
raise unittest.SkipTest("Couldn't find gdb on the path")
31-
try:
32-
gdb_version_number = re.search(b"^GNU gdb [^\d]*(\d+)\.(\d)", gdb_version)
33-
gdb_major_version = int(gdb_version_number.group(1))
34-
gdb_minor_version = int(gdb_version_number.group(2))
35-
except Exception:
36-
raise ValueError("unable to parse GDB version: %r" % gdb_version)
37-
24+
def get_gdb_version():
25+
try:
26+
proc = subprocess.Popen(["gdb", "-nx", "--version"],
27+
stdout=subprocess.PIPE,
28+
universal_newlines=True)
29+
with proc:
30+
version = proc.communicate()[0]
31+
except OSError:
32+
# This is what "no gdb" looks like. There may, however, be other
33+
# errors that manifest this way too.
34+
raise unittest.SkipTest("Couldn't find gdb on the path")
35+
36+
# Regex to parse:
37+
# 'GNU gdb (GDB; SUSE Linux Enterprise 12) 7.7\n' -> 7.7
38+
# 'GNU gdb (GDB) Fedora 7.9.1-17.fc22\n' -> 7.9
39+
match = re.search("^GNU gdb .*? (\d+)\.(\d)", version)
40+
if match is None:
41+
raise Exception("unable to parse GDB version: %r" % version)
42+
return (version, int(match.group(1)), int(match.group(2)))
43+
44+
gdb_version, gdb_major_version, gdb_minor_version = get_gdb_version()
3845
if gdb_major_version < 7:
39-
raise unittest.SkipTest("gdb versions before 7.0 didn't support python embedding"
40-
" Saw:\n" + gdb_version.decode('ascii', 'replace'))
46+
raise unittest.SkipTest("gdb versions before 7.0 didn't support python "
47+
"embedding. Saw %s.%s:\n%s"
48+
% (gdb_major_version, gdb_minor_version,
49+
gdb_version))
4150

4251
if not sysconfig.is_python_build():
4352
raise unittest.SkipTest("test_gdb only works on source builds at the moment.")
@@ -65,7 +74,8 @@ def run_gdb(*args, **env_vars):
6574
base_cmd += ('-iex', 'add-auto-load-safe-path ' + checkout_hook_path)
6675
proc = subprocess.Popen(base_cmd + args,
6776
stdout=subprocess.PIPE,
68-
stderr=subprocess.PIPE, env=env)
77+
stderr=subprocess.PIPE,
78+
env=env)
6979
with proc:
7080
out, err = proc.communicate()
7181
return out.decode('utf-8', 'replace'), err.decode('utf-8', 'replace')
@@ -886,8 +896,8 @@ def test_locals_after_up(self):
886896

887897
def test_main():
888898
if support.verbose:
889-
print("GDB version:")
890-
for line in os.fsdecode(gdb_version).splitlines():
899+
print("GDB version %s.%s:" % (gdb_major_version, gdb_minor_version))
900+
for line in gdb_version.splitlines():
891901
print(" " * 4 + line)
892902
run_unittest(PrettyPrintTests,
893903
PyListTests,

0 commit comments

Comments
 (0)