Skip to content

bpo-40436: Fix code parsing gdb version #19792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2020
Merged

bpo-40436: Fix code parsing gdb version #19792

merged 1 commit into from
Apr 29, 2020

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 29, 2020

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

https://bugs.python.org/issue40436

test_gdb and test.pythoninfo now check gdb command exit code.
@@ -376,6 +376,9 @@ def collect_gdb(info_add):
stderr=subprocess.PIPE,
universal_newlines=True)
version = proc.communicate()[0]
if proc.returncode:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this more readable:

Suggested change
if proc.returncode:
if proc.returncode != 0:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both syntaxes are equivalent. I prefer `if proc.returncode:" (coding style preference) ;-)

version = proc.communicate()[0]
version, stderr = proc.communicate()

if proc.returncode:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this more readable:

Suggested change
if proc.returncode:
if proc.returncode != 0:

if proc.returncode:
raise Exception(f"Command {' '.join(cmd)!r} failed "
f"with exit code {proc.returncode}: "
f"stdout={version!r} stderr={stderr!r}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is normally skipped if gdb is not found:

raise unittest.SkipTest("Couldn't find gdb on the path")

Should we not do the same?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is still skipped when gdb is not found. But the new code is when gdb is available but is broken. I would prefer to not fail silently when gdb is broken, but get an error even if it's a third-party component. It should help to debug Python CIs like buildbots.

It's like the existing test which raises an exception if Python fails to parse the gdb version:

    match = re.search(r"^GNU gdb.*?\b(\d+)\.(\d+)", version)
    if match is None:
        raise Exception("unable to parse GDB version: %r" % version)

@vstinner vstinner merged commit ec9bea4 into python:master Apr 29, 2020
@vstinner vstinner deleted the gdb_version branch April 29, 2020 15:11
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 29, 2020
test_gdb and test.pythoninfo now check gdb command exit code.
(cherry picked from commit ec9bea4)

Co-authored-by: Victor Stinner <[email protected]>
@bedevere-bot
Copy link

GH-19795 is a backport of this pull request to the 3.8 branch.

@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 29, 2020
test_gdb and test.pythoninfo now check gdb command exit code.
(cherry picked from commit ec9bea4)

Co-authored-by: Victor Stinner <[email protected]>
@bedevere-bot
Copy link

GH-19796 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit that referenced this pull request Apr 29, 2020
test_gdb and test.pythoninfo now check gdb command exit code.
(cherry picked from commit ec9bea4)

Co-authored-by: Victor Stinner <[email protected]>
miss-islington added a commit that referenced this pull request Apr 29, 2020
test_gdb and test.pythoninfo now check gdb command exit code.
(cherry picked from commit ec9bea4)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants