From 2a50da82ff4ccf0562195995fd9c09f4d10d2983 Mon Sep 17 00:00:00 2001 From: Tcc100 Date: Mon, 11 Mar 2024 17:41:55 +0100 Subject: [PATCH] Restore stack frame after display (#2069) The commands `context threads` and `threads` use `thread.switch()` to examine other threads, which resets the selected stack frame to `#0`. This commit restores the selected frame afterwards. Co-authored-by: T --- pwndbg/commands/context.py | 6 ++++++ pwndbg/commands/tls.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/pwndbg/commands/context.py b/pwndbg/commands/context.py index 834fa70c9ca..0c51d58531a 100644 --- a/pwndbg/commands/context.py +++ b/pwndbg/commands/context.py @@ -886,6 +886,10 @@ def context_threads(with_banner=True, target=sys.stdout, width=None): original_thread = gdb.selected_thread() except SystemError: original_thread = None + try: + original_frame = gdb.selected_frame() + except gdb.error: + original_frame = None all_threads = gdb.selected_inferior().threads()[::-1] @@ -949,6 +953,8 @@ def context_threads(with_banner=True, target=sys.stdout, width=None): if original_thread is not None and original_thread.is_valid(): original_thread.switch() + if original_frame is not None and original_frame.is_valid(): + original_frame.select() return out diff --git a/pwndbg/commands/tls.py b/pwndbg/commands/tls.py index 711aba236ec..990a607c28c 100644 --- a/pwndbg/commands/tls.py +++ b/pwndbg/commands/tls.py @@ -88,6 +88,10 @@ def threads(num_threads, respect_config) -> None: original_thread = gdb.selected_thread() except SystemError: original_thread = None + try: + original_frame = gdb.selected_frame() + except gdb.error: + original_frame = None all_threads = gdb.selected_inferior().threads()[::-1] @@ -143,6 +147,8 @@ def threads(num_threads, respect_config) -> None: if original_thread is not None and original_thread.is_valid(): original_thread.switch() + if original_frame is not None and original_frame.is_valid(): + original_frame.select() print(tabulate(table, headers)) print(f"\nShowing {len(displayed_threads)} of {len(all_threads)} threads.")