Skip to content

Commit 1f5ff68

Browse files
Fix all_subinterpreters handling
1 parent 1b641f5 commit 1f5ff68

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Modules/_remote_debugging/gc_stats.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ extern "C" {
1313

1414
#include "_remote_debugging.h"
1515

16+
typedef struct {
17+
PyObject *result;
18+
bool all_interpreters;
19+
} ReadGCStatsContext;
20+
1621
static int
1722
read_gc_stats(struct gc_stats *stats, unsigned long iid, PyObject *result)
1823
{
@@ -115,6 +120,11 @@ get_gc_stats_from_interpreter_state(RuntimeOffsets *offsets,
115120
unsigned long iid,
116121
void *context)
117122
{
123+
ReadGCStatsContext *ctx = (ReadGCStatsContext *)context;
124+
if (!ctx->all_interpreters && iid > 0) {
125+
return 0;
126+
}
127+
118128
uintptr_t gc_stats_addr;
119129
uintptr_t gc_stats_pointer_address = interpreter_state_addr
120130
+ offsets->debug_offsets.interpreter_state.gc
@@ -137,8 +147,7 @@ get_gc_stats_from_interpreter_state(RuntimeOffsets *offsets,
137147
return -1;
138148
}
139149

140-
PyObject *result = context;
141-
if (read_gc_stats(&stats, iid, result) < 0) {
150+
if (read_gc_stats(&stats, iid, ctx->result) < 0) {
142151
return -1;
143152
}
144153

Modules/_remote_debugging/interpreters.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ iterate_interpreters(
5252
}
5353

5454
while (interpreter_state_addr != 0) {
55-
5655
if (0 > _Py_RemoteDebug_ReadRemoteMemory(
5756
&offsets->handle,
5857
interpreter_state_addr + interpreter_id_offset,
@@ -62,7 +61,6 @@ iterate_interpreters(
6261
return -1;
6362
}
6463

65-
6664
// Call the processor function for this interpreter
6765
if (processor(offsets, interpreter_state_addr, iid, context) < 0) {
6866
return -1;

Modules/_remote_debugging/module.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,11 @@ _remote_debugging_get_gc_stats_impl(PyObject *module, int pid,
19041904
if (result == NULL) {
19051905
goto error;
19061906
}
1907-
if (0 > iterate_interpreters(&offsets, get_gc_stats_from_interpreter_state, result)) {
1907+
ReadGCStatsContext ctx = {
1908+
.result = result,
1909+
.all_interpreters = all_interpreters,
1910+
};
1911+
if (0 > iterate_interpreters(&offsets, get_gc_stats_from_interpreter_state, &ctx)) {
19081912
goto error;
19091913
}
19101914

0 commit comments

Comments
 (0)