From 6bfd17b67077ddad858578282807f4382787326b Mon Sep 17 00:00:00 2001 From: Huy Nguyen Quang Date: Wed, 14 Jul 2021 10:30:54 +0700 Subject: [PATCH 1/2] Fix crash when expanding variables in post-mortem 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/pudb/debugger.py b/pudb/debugger.py index bbdb8705..debf3a03 100644 --- a/pudb/debugger.py +++ b/pudb/debugger.py @@ -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)) index = len(self.stack)-1 self.set_frame_index(index) From b5f0dae04fe63d9c20d976aa6b38fe008cf125ba Mon Sep 17 00:00:00 2001 From: Huy Nguyen Quang Date: Sun, 18 Jul 2021 16:50:30 +0700 Subject: [PATCH 2/2] Use stack property to return a modified view of the stack in post_mortem 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. --- pudb/debugger.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pudb/debugger.py b/pudb/debugger.py index ce69c84c..927534b9 100644 --- a/pudb/debugger.py +++ b/pudb/debugger.py @@ -200,6 +200,14 @@ def __init__(self, stdin=None, stdout=None, term_size=None, steal_output=False, for bpoint_descr in load_breakpoints(): self.set_break(*bpoint_descr) + @property + def stack(self): + if self.post_mortem: + # Return the bottom frame so the user can expand variables in post_mortem + return [(self.bottom_frame, self.bottom_frame.f_lineno)] + else: + return self._stack + # These (dispatch_line and set_continue) are copied from bdb with the # patch from https://bugs.python.org/issue16482 applied. See # https://github.com/inducer/pudb/pull/90. @@ -401,10 +409,9 @@ def interaction(self, frame, exc_tuple=None, show_exc_dialog=True): if not found_bottom_frame and not self.post_mortem: return - self.stack, index = self.get_shortened_stack(frame, tb) + self._stack, index = self.get_shortened_stack(frame, tb) if self.post_mortem: - self.stack.append((self.bottom_frame, self.bottom_frame.f_lineno)) index = len(self.stack)-1 self.set_frame_index(index)