Skip to content
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

Fix crash when expanding variables in post-mortem #465

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

qhuy4119
Copy link
Contributor

Currently, Debugger.stack will be empty when entering post-mortem, leading to IndexError when user tries to expand variables in the Variables window.
This commit fixes that by restoring Debugger.bottom_frame to Debugger.stack.

fixes #233

Currently, Debugger.stack will be empty when entering post-mortem,
leading to IndexError when user tries to expand variables in the Variables window.
This commit fixes that by restoring Debugger.bottom_frame to Debugger.stack.
pudb/debugger.py Outdated
@@ -403,6 +403,7 @@ def interaction(self, frame, exc_tuple=None, show_exc_dialog=True):
self.stack, index = self.get_shortened_stack(frame, tb)

if self.post_mortem:
self.stack.append((self.bottom_frame, self.bottom_frame.f_lineno))
Copy link
Owner

@inducer inducer Jul 14, 2021

Choose a reason for hiding this comment

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

How does pdb handle this situation? self.stack here is something that's managed by bdb, I'm not sure we're at liberty to modify it.

Copy link
Contributor Author

@qhuy4119 qhuy4119 Jul 14, 2021

Choose a reason for hiding this comment

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

After finishing the execution of the script, pdb enters this finally block (kinda like our post-mortem mode). At this point, if we type p <variable name> on the command line, pdb will print a NameError, and the user continues with the pdb REPL. So currently our IndexError is similar to this NameError.

I haven't dig into how bdb manages the stack in this case.

The problem with the current PuDB is that if I have an object at the module level, say a = list(range(100)) for example, I can't expand it in post-mortem to see what the elements are . This PR allows user to inspect data structures like that.

Copy link
Owner

Choose a reason for hiding this comment

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

Instead of modifying data structures that aren't ours to modify, could you instead create a @property that provides a modified view of the stack, and then change the relevant spots of the code to use that view of the stack instead? Also make sure to add comments to explain why this is being done.

If we're in post_mortem, accessing the stack will return the bottom
frame instead of an empty stack. By doing this, users can expand
variables in post_mortem.
@qhuy4119 qhuy4119 force-pushed the fix-post-mortem-variable-crash branch from 6b2c28a to b5f0dae Compare July 18, 2021 10:02
@inducer
Copy link
Owner

inducer commented Jul 20, 2021

This actually isn't right. Post-mortem mode also kicks in if the debuggee runs into an exception. Your proposed change appears to break inspecting the stack in that situation.

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.

Crash on editing Variable settings
2 participants