Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Lib/test/test_external_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3799,6 +3799,30 @@ def gen():
skip_non_matching_threads=True,
)

@requires_gil_enabled("Free threaded builds don't have an 'active thread'")
def test_filtered_active_thread_is_not_replaced(self):
samples = []

def sample():
for kwargs in ({"all_threads": True}, {"only_active_thread": True}):
unwinder = RemoteUnwinder(
os.getpid(), mode=PROFILING_MODE_EXCEPTION, **kwargs
)
samples.append(
self._get_thread_statuses(unwinder.get_stack_trace())
)

thread = threading.Thread(target=sample)
try:
raise ValueError
except ValueError:
thread.start()
thread.join()

all_threads, active_thread = samples
self.assertEqual(list(all_threads), [threading.get_native_id()])
self.assertEqual(active_thread, {})


@requires_remote_subprocess_debugging()
class TestFrameCaching(RemoteInspectionTestBase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :mod:`!_remote_debugging` returning a different thread when the selected
thread does not match the profiling mode with ``only_active_thread=True``.
3 changes: 3 additions & 0 deletions Modules/_remote_debugging/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ _remote_debugging_RemoteUnwinder_get_stack_trace_impl(RemoteUnwinderObject *self
goto exit;
}
// Thread was skipped due to mode filtering, continue to next thread
if (self->tstate_addr || self->only_active_thread) {
break;
}
continue;
}
// This was an actual error
Expand Down
Loading