78 Commits
Author SHA1 Message Date
Kumar Aditya c79146a9eb gh-160804: Support generator based awaitables in asyncio introspection (#160805) 2026-10-28 08:14:16 +00:00
Jelle Zijlstra b577a5403a gh-159739: Avoid destroying a remote unwinder cache twice (#159982)
In a free-threaded build, if allocating the thread-local bytecode cache fails after the code-object cache has been created, the initializer destroys the first cache and returns an error without clearing its pointer. Failed construction then invokes the unwinder's deallocator, which destroys the same cache again and can crash the profiling process instead of propagating `MemoryError`.
2026-10-20 21:38:55 -07:00
Timofei IvankovandPablo Galindo Salgado 2188f9b60a gh-159620: Fix remote asyncio stacks stopping at async generators (GH-159623)
Follow asynchronous-generator send/throw wrappers when unwinding suspended
and running asyncio tasks.

Co-authored-by: Pablo Galindo Salgado <pablogsal@gmail.com>
2026-10-17 23:07:03 +00:00
Victor Stinner 15dd7356f3 gh-158893: Add internal _Py_strerror() function (#158982)
Add a new internal _Py_strerror() function to Python/fileutils.c. It
uses strerror_r() if available, or use strerror() otherwise.

Replace all strerror(code) calls with _Py_strerror(code).
2026-10-07 20:31:27 +00:00
Timofei IvankovandMaurycy Pawłowski-Wieroński 05302c0ad6 gh-158522: Fix truncated stack for a task whose coroutine recurses (#158526)
* gh-158522: Fix truncated stack for a task whose coroutine recurses

* fix lint

* Apply suggestion from @maurycy

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>

* Update Misc/NEWS.d/next/Library/2026-09-30-20-09-46.gh-issue-158522.L6j7tU.rst

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>

* Fix line length in the new test

---------

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
2026-10-05 16:46:39 +01:00
he_taoandPablo Galindo Salgado 38416fedef gh-158539: Fix exception mode missing handlers in generators/coroutines (#158581)
* gh-158539: Fix exception mode missing handlers in generators/coroutines

The sampling profiler's exception mode decided whether a thread was
handling an exception by reading the embedded PyThreadState.exc_state.
Generators, coroutines and async generators repoint tstate->exc_info
at their own _PyErr_StackItem while they run, so an except block
running in one of them (or in a function they call) stored the
exception in that item instead, and was never sampled.

Follow tstate->exc_info and its previous_item chain, mirroring
_PyErr_GetTopmostException(), and export the two debug offsets needed
to walk the chain from remote memory.  The common case where exc_info
points at the embedded exc_state keeps the existing zero-extra-read
fast path.

* gh-158539: Handle deep exception chains without changing debug offsets

* gh-158539: Use portable static assertion messages

* gh-158539: Keep layout assertions with debug-offset validation

* gh-158539: Use the platform guard for in-process inspection tests

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-05 15:16:14 +00:00
tonghuaroot (童话)andPablo Galindo Salgado e4a24732eb gh-152721: Fix quadratic RLE replay time in the profiling binary reader (#152722)
* gh-152721: Fix quadratic RLE replay time in the profiling binary reader

* gh-152721: Clarify the batch-list comment

Reword per review: the list is built with append per element, not
pre-sized; note the old alloc(count - i) + trim per batch was O(count^2).

* Cap RLE batch size to bound the per-batch timestamp list

* Move MAX_RLE_BATCH_SAMPLES comment to its own line (keep under 79 cols)

* Drop the now-redundant emit_batch trim and fix the review nits

The batch list is built to its exact size, so the PyList_SetSlice trim was a no-op; call emit_sample directly. Also point the cap comment at the issue (gh-151378) and drop the stale over-long comment.

* gh-152721: Test replay batches beyond the RLE limit

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-05 14:37:01 +00:00
Pablo Galindo Salgado 1643525f0f gh-158552: Wait for Windows threads to suspend before blocking sampling (#158802)
* gh-158552: Wait for Windows threads to suspend before blocking sampling

* Use a named Windows thread enumeration status constant
2026-10-05 14:51:26 +01:00
Maurycy Pawłowski-WierońskiandPablo Galindo Salgado 5fecd448bb gh-155811: Add a seqcount to gc_stats to prevent torn reads (#155828)
* update_seq

* no need for XCHGL, MOVL is enough?

* gh-155811: Retry an inconsistent GC snapshot once

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-05 01:49:56 +00:00
Stan UlbrychandVictor Stinner b93fb19a6e Run a job that the test suite with MSan to the CI (#158625)
* Run the test suite with MSan in CI

* Additional fixes

* Add `_Py_MSAN_UNPOISON_STRING`

* Apply Victor's suggestions

Co-authored-by: Victor Stinner <victor.stinner@gmail.com>

* Apply Victor's suggestions

Co-authored-by: Victor Stinner <victor.stinner@gmail.com>

---------

Co-authored-by: Victor Stinner <victor.stinner@gmail.com>
2026-10-05 02:11:42 +01:00
Maurycy Pawłowski-WierońskiandPablo Galindo Salgado f839c061d3 gh-151292: _remote_debugging: Do not corrupt the binary file when hitting OverflowError (#152892)
* the kolektor

* test

* better test

* news

* =Q, move const to the base, not self.running

* gh-151292: Track binary writer finalization state

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-05 01:04:20 +00:00
Maurycy Pawłowski-WierońskiandPablo Galindo Salgado 7d25916b41 gh-154194: Degrade frames in Tachyon instead of failing the sample (#154195)
* degrade gracefully

* news

* better NEWS wording

* do not raise on MAX_REMOTE_STR_READ

* bye MAX_REMOTE_STR_READ

* fix -m asyncio ps|pstree

* test truncation and linetable sentinel

* simpler

* simpler

* redundant now

* respect #157790 in the news

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-05 00:37:21 +00:00
Maurycy Pawłowski-Wieroński e0861c6ae7 gh-153364: Make frame, coroutine, and task-waiter chain walks iterative and bounded (#153365)
* let me declare single limit

* use our new limit in process_frame_chain()

* add it in parse_async_frame_chain()

* parse_coro_chain()

* NEWS

* async in the message?

* test

* no race

* process_task_awaited_by

* process_task_awaited_by limit test

* NEWS

* MAX_TASK_WAITER_CHAIN_DEPTH

* TASK_WAITER_CHAIN_DEPTH in test

* TASK_WAITER_CHAIN_DEPTH 256

* prevent the drift with the comment

* better naming, better style

* MAX_TASK_WAITER_CHAIN_DEPTH comment

* task-waiter iterative bfs walk

* iterative coro-walk

* nicer news

* 1 << 14

* comment

* unused read_Py_ssize_t

* fix tombstones

* simplify

* correct msg

* better test

* news for tombstones

* left-over from when testing buggy version

* redundant new line
2026-10-04 23:57:47 +00:00
Shankar Rao S PatilandPablo Galindo Salgado 72f821fdb8 gh-149302: Fix incorrect docstring in RemoteUnwinder.get_all_awaited_by (#149312)
* Fix incorrect docstring for get_all_awaited_by in _remote_debugging

* Regenerate Argument Clinic output after docstring fix

* Clarify task waiter relationships and fallback task list

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-04 21:29:13 +00:00
liuzhijie-0614andPablo Galindo Salgado ca5277c0f6 gh-157660: Fix stale TLBC caches in _remote_debugging (#157732)
* gh-157660: Fix stale TLBC caches in _remote_debugging

`profiling.sampling` reporting errors or incorrect line numbers in free-threaded
builds when a thread-local bytecode array grows or gains entries after being cached.

* gh-157660: Retry transient sampling races in TLBC tests

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-09-27 20:19:35 +00:00
Pablo Galindo Salgado 80f9aa0b18 gh-157605: Accept empty native-thread stacks when sampling
Accept empty native-thread stacks when sampling instead of raising an error. Distinguish interpreter-owned C frames from cleared Python frames so frame cleanup cannot produce a false <native> marker.
2026-09-25 01:04:31 +01:00
Pablo Galindo Salgado d3663ef943 gh-154090: Store profiling mode and capture settings in binary profiles (GH-154105) 2026-09-24 23:17:30 +00:00
Timofei Ivankov a1669c95d9 -157788: Fix python -m asyncio ps failing on long task names (#157790) 2026-09-19 21:03:39 +00:00
Pablo Galindo Salgado 7f0ccd6c0e gh-154060: Preserve replay duration and rate (#154101) 2026-08-26 10:24:00 +01:00
Serhiy StorchakaandClaude Opus 5 2c47c65f2e gh-156261: Move converters used in several files to Argument Clinic (GH-156262)
The pid_t, Py_off_t, HANDLE, DWORD and BOOL converters were defined in
9 files.  The Py_off_t type and its converter function are now shared too.
DWORD in _winapi is used with bitwise=True to keep accepting negative
values.

The pid_t converter is now used for the pid parameters in the
_remote_debugging module, which were declared as int.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 19:47:55 +03:00
Stan Ulbrych bf95881b84 Remote Debugging: silence some unused function warnings (#149898) 2026-08-19 21:28:43 +01:00
Maurycy Pawłowski-Wieroński a2c9a3b0aa gh-156060: Do not scan every process four times in remote_debugging.get_child_pids() on macOS (#156061) 2026-08-19 20:27:00 +00:00
Goutam Adwant aeedae8b44 gh-151022: Fix remote debugging linetable reads (#151036) 2026-07-19 20:32:43 +02:00
Maurycy Pawłowski-Wieroński 1d196507e6 gh-151292: Change total_samples:u32 in the binary format to total_samples:u64 (#153425) 2026-07-09 13:59:28 +00:00
tonghuaroot (童话) 8e580b0685 gh-152718: Reject oversized table counts in the profiling binary reader (#152719) 2026-07-04 23:56:09 +01:00
Maurycy Pawłowski-Wieroński 639a5525fb gh-151378: Fix unbounded memory growth when recording binary and the thread is sleeping (#152089) 2026-07-04 20:03:01 +01:00
Zain Nadeem 37b238f1a6 gh-152356: Fix Windows blocking sampling after target process exit (#152471) 2026-06-28 18:58:56 +02:00
Pablo Galindo Salgado 8cda6ae2f1 gh-151613: Fix remote debugging frame cache ABA (#151614)
The remote debugging frame cache previously used only the last_profiled_frame address as its cache anchor. If a frame returned and a later frame reused the same _PyInterpreterFrame address, the profiler could accept a stale cache entry and splice parent frames from a different call chain into the current stack.

This adds a last_profiled_frame_seq counter next to last_profiled_frame, increments it when the anchor advances, stores it in frame cache entries, and validates cache hits against both the frame address and the sequence. Cache miss walks now copy stack chunks before storing new cache entries so stored continuations come from a stable snapshot. The new regression test exercises alternating call chains and checks that cached stacks never contain frames from both branches.
2026-06-27 16:56:31 +00:00
sobolevn a173a6d65b gh-151584: Remove PyUnstable_Module_SetGIL call in _remote_debugging (#151585) 2026-06-17 15:37:08 +03:00
Maurycy Pawłowski-Wieroński 6ce088e20a gh-151424: Fix impossible stack traces in RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss (#151426) 2026-06-14 00:10:56 +01:00
AN Long ec23ec6870 gh-149931: Fix memory leaks on failed realloc (#149932) 2026-05-26 01:37:14 +01:00
Pablo Galindo Salgado a5be25d3bd gh-149619: Harden _remote_debugging error paths (#150349) 2026-05-25 23:22:46 +01:00
Serhiy Storchaka cdc499ae77 gh-150285: Fix too long docstrings in the _remote_debugging module (GH-150289) 2026-05-24 15:02:43 +03:00
Pablo Galindo Salgado 661df25692 gh-149584: Fix excessive overhead in the Tachyon profiler regarding the cache behavior (#149649)
Use exact remote reads for interpreter state, thread state, and
interpreter frame structs instead of pulling full remote pages into the
profiler page cache. This matches the core change from
python/cpython#149585.

The profiler clears the page cache between samples, so live entries are
always packed at the front. Track the live count and only clear/search
that prefix instead of scanning all 1024 slots on the hot path.

Use the frame cache to predict the next thread state and top frame
address, then batch interpreter/thread/frame reads with process_vm_readv
when profiling a Linux target. Reuse prefetched frame buffers in the
frame walker when the prediction is valid.

Cache the last FrameInfo tuple per code object/instruction offset, reuse
cached thread id objects, and append cached parent frames directly on
full frame-cache hits. This cuts Python allocation churn in the
steady-state profiler path.
2026-05-20 04:32:08 -07:00
Nezuko Agent 0ed497a350 gh-149953: Fix null pointer dereference order in code_objects.c (#149956)
Move  check before
2026-05-18 11:28:28 +03:00
Maurycy Pawłowski-Wieroński 354ef336e4 gh-149474: use Py_fopen in Binary{Reader,Writer} for audit hook and path-like support (#149524) 2026-05-09 01:01:35 +01:00
Maurycy Pawłowski-Wieroński d36e5b8644 gh-149521: Do not update last_profiled_frame if it's not changed (#149522) 2026-05-08 08:25:49 +00:00
Maurycy Pawłowski-Wieroński c266f0c375 gh-149009: Validate thread_count in profiling.sampling binary reader (#149147) 2026-05-05 00:50:06 +00:00
Maurycy Pawłowski-Wieroński 04ce318522 gh-146256: Add --jsonl collector to the profiling.sampling (#146257) 2026-05-05 00:44:37 +00:00
Maurycy Pawłowski-Wieroński f025dba62e gh-149230: _remote_debugging: Fix async-aware for tasks in non-main threads (#149235) 2026-05-05 01:33:56 +01:00
Maurycy Pawłowski-Wieroński 6f8c964dc0 gh-149342: _remote_debugging: Fix binary profile corruption when sampling a (temporarily) empty stack (#149343) 2026-05-05 00:32:06 +00:00
Maurycy Pawłowski-Wieroński 9dca1ff759 gh-149300: _remote_debugging: clean up magic and duplicate consts in the binary format helper (#149301) 2026-05-05 01:31:53 +01:00
Pablo Galindo Salgado 8c796782fc gh-146462: Add dict introspection debug offsets (#148633) 2026-05-04 23:00:23 +00:00
Sergey Miryanov e89568f0cb GH-148726: Add heap_size to generational GC (#149195) 2026-05-04 22:14:45 +01:00
Sergey Miryanov 39f123c587 GH-146527: Add get_gc_stats function to _remote_debugging (#148071) 2026-05-02 15:04:18 +00:00
Pablo Galindo Salgado efcac6f281 gh-149214: Fix non ascii characters in remote debugging (#149228) 2026-05-02 15:07:28 +01:00
Maurycy Pawłowski-Wieroński 0efd679a6c gh-148252: Avoid overflow in _remote_debugging binary reader bounds checks (#148972) 2026-04-28 00:06:23 +01:00
Maurycy Pawłowski-Wieroński b2f126c4a0 gh-148989: _remote_debugging: Remove dead code, unnecessary gc state read (#148990)
dead code
2026-04-25 22:28:51 +01:00
Pablo Galindo Salgado eb4c78df07 gh-148252: Fix stack depth calculation in binary reader on 32-bit platforms (#148253)
Compute ``final_depth`` in ``decode_stack_pop_push()`` and
``decode_stack_suffix()`` using ``uint64_t`` before validating it.

On 32-bit builds, using ``size_t`` arithmetic for ``keep + push`` can wrap
for large input values, causing the later bounds check to validate the wrong
final depth. Using a widened type keeps the validation aligned with the
actual result.
2026-04-13 23:43:55 +01:00
Pablo Galindo Salgado 289fd2c97a gh-148178: Validate remote debug offset tables on load (#148187)
Treat the debug offset tables read from a target process as untrusted input
and validate them before the unwinder uses any reported sizes or offsets.

Add a shared validator in debug_offsets_validation.h and run it once when
_Py_DebugOffsets is loaded and once when AsyncioDebug is loaded. The checks
cover section sizes used for fixed local buffers and every offset that is
later dereferenced against a local buffer or local object view. This keeps
the bounds checks out of the sampling hot path while rejecting malformed
tables up front.
2026-04-13 22:22:23 +00:00