Skip to content

_remote_debugging: dead code, unnecessary gc state read #148989

@maurycy

Description

@maurycy

Bug report

Bug description:

I'm benchmarking sampling.profiler and I realized unwind_stack_for_thread issues _Py_RemoteDebug_PagedReadRemoteMemory on every sample and on every thread.

// Read GC collecting state from the interpreter (before any skip checks)
uintptr_t interp_addr = GET_MEMBER(uintptr_t, ts, unwinder->debug_offsets.thread_state.interp);
// Read the GC runtime state from the interpreter state
uintptr_t gc_addr = interp_addr + unwinder->debug_offsets.interpreter_state.gc;
char gc_state[SIZEOF_GC_RUNTIME_STATE];
if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, gc_addr, unwinder->debug_offsets.gc.size, gc_state) < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read GC state");
goto error;
}
STATS_INC(unwinder, memory_reads);
STATS_ADD(unwinder, memory_bytes_read, unwinder->debug_offsets.gc.size);

seems it should've been removed with 274a26c.

The result is not used, it pollutes the stats and there's a risk of failing over data that's not even used?

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-refactorCode refactoring (with no changes in behavior)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions