Skip to content

Commit

Permalink
Restore stack frame after display (pwndbg#2069)
Browse files Browse the repository at this point in the history
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 <T>
  • Loading branch information
Tcc100 authored Mar 11, 2024
1 parent bb5de91 commit 2a50da8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pwndbg/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions pwndbg/commands/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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.")

0 comments on commit 2a50da8

Please sign in to comment.