Another attempt at fixing #22968/#23987. The previous backport didn't work because the 3.10 debugger uses another code path.