Fix crash when expanding variables in post-mortem#465
Fix crash when expanding variables in post-mortem#465qhuy4119 wants to merge 3 commits intoinducer:mainfrom
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
| 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.
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.
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.
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.stackwill be empty when entering post-mortem, leading toIndexErrorwhen user tries to expand variables in the Variables window.This commit fixes that by restoring
Debugger.bottom_frametoDebugger.stack.fixes #233