Skip to content

gh-57537: Support breakpoints for zipimport modules on pdb #130290

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 4 commits into from
Feb 20, 2025

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Feb 19, 2025

Currently when pdb sets a breakpoint on a known function, it uses the filename of the code object of that specific function to locate the source. However, this does not work for zipimport modules, because the module_globals passed in is of the current frame, and linecache needs that to get the source.

The correct way to deal with this is to pass in the module_globals of the function itself, not of the current frame. This not only solves the problem for zipimport, but also fixes other potential issues when the module of the function has its own loader.

'p x + x',
'q'
]))
self.assertIn('82', stdout)
Copy link
Member

Choose a reason for hiding this comment

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

What is '82'?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the result of p x + x, I want to confirm that we did stop inside foo.bar. I can maybe change the testing code to use string so it's more obvious? Or I can add a comment here. The other possibility is to use a more advanced command to rule out the false positives (for example, you can't simply check bar because it will be shown anyway).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, a string would be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

I constructed a small piece of unique string and the assertion is close to the command - I think that made it clearer.

@@ -1134,6 +1134,7 @@ def do_break(self, arg, temporary=False):
filename = None
lineno = None
cond = None
module_globals = None
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably call this func_globals. Up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to match the name for linecache. It is a module globals acquired from a function, and the part matters is about the module (loader and stuff).

@gaogaotiantian gaogaotiantian merged commit ee337be into python:main Feb 20, 2025
43 checks passed
@gaogaotiantian gaogaotiantian deleted the pdb-zipimport-break branch February 20, 2025 02:01
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.

2 participants