-
Notifications
You must be signed in to change notification settings - Fork 229
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
base: main
Are you sure you want to change the base?
Conversation
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
6b2c28a
to
b5f0dae
Compare
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. |
Currently,
Debugger.stack
will be empty when entering post-mortem, leading toIndexError
when user tries to expand variables in the Variables window.This commit fixes that by restoring
Debugger.bottom_frame
toDebugger.stack
.fixes #233