[Python-checkins] bpo-40436: Fix code parsing gdb version (GH-19792)

Victor Stinner webhook-mailer at python.org
Wed Apr 29 11:11:52 EDT 2020


https://github.com/python/cpython/commit/ec9bea4a3766bd815148a27f61eb24e7dd459ac7
commit: ec9bea4a3766bd815148a27f61eb24e7dd459ac7
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-04-29T17:11:48+02:00
summary:

bpo-40436: Fix code parsing gdb version (GH-19792)

test_gdb and test.pythoninfo now check gdb command exit code.

files:
A Misc/NEWS.d/next/Tests/2020-04-29-16-08-24.bpo-40436.gDMnYl.rst
M Lib/test/pythoninfo.py
M Lib/test/test_gdb.py

diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py
index cc230dd2297a0..cc0bbc5fe3e77 100644
--- a/Lib/test/pythoninfo.py
+++ b/Lib/test/pythoninfo.py
@@ -376,6 +376,9 @@ def collect_gdb(info_add):
                                 stderr=subprocess.PIPE,
                                 universal_newlines=True)
         version = proc.communicate()[0]
+        if proc.returncode:
+            # ignore gdb failure: test_gdb will log the error
+            return
     except OSError:
         return
 
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
index fb1480145a7e1..210cd0d3787a8 100644
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -17,12 +17,18 @@
 
 def get_gdb_version():
     try:
-        proc = subprocess.Popen(["gdb", "-nx", "--version"],
+        cmd = ["gdb", "-nx", "--version"]
+        proc = subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 universal_newlines=True)
         with proc:
-            version = proc.communicate()[0]
+            version, stderr = proc.communicate()
+
+        if proc.returncode:
+            raise Exception(f"Command {' '.join(cmd)!r} failed "
+                            f"with exit code {proc.returncode}: "
+                            f"stdout={version!r} stderr={stderr!r}")
     except OSError:
         # This is what "no gdb" looks like.  There may, however, be other
         # errors that manifest this way too.
diff --git a/Misc/NEWS.d/next/Tests/2020-04-29-16-08-24.bpo-40436.gDMnYl.rst b/Misc/NEWS.d/next/Tests/2020-04-29-16-08-24.bpo-40436.gDMnYl.rst
new file mode 100644
index 0000000000000..0aee2c3aa2b4d
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-04-29-16-08-24.bpo-40436.gDMnYl.rst
@@ -0,0 +1 @@
+test_gdb and test.pythoninfo now check gdb command exit code.



More information about the Python-checkins mailing list