Skip to content

Commit 180e894

Browse files
committed
up
1 parent 585755d commit 180e894

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

‎Lib/test/test_external_inspection.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,17 @@ async def main():
679679
stacks = self._extract_coroutine_funcnames(asyncio.run(main()))
680680
self.assertEqual(stacks["consumer"], ["consumer"])
681681

682+
@skip_if_not_supported
683+
def test_self_trace_with_empty_linetable(self):
684+
def sample():
685+
return RemoteUnwinder(os.getpid()).get_stack_trace()
686+
687+
sample.__code__ = sample.__code__.replace(co_linetable=b"")
688+
frame = self._find_frame_in_trace(
689+
sample(), lambda f: f.funcname == sample.__qualname__
690+
)
691+
self.assertEqual(frame.location, (-1, -1, -1, -1))
692+
682693
@skip_if_not_supported
683694
@unittest.skipIf(
684695
sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED,

‎Modules/_remote_debugging/object_reading.c‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ read_py_bytes(
185185
uintptr_t address,
186186
Py_ssize_t max_len
187187
) {
188-
PyObject *result = NULL;
189-
char *buf = NULL;
190-
191188
// Read the entire PyBytesObject at once
192189
char bytes_obj[SIZEOF_BYTES_OBJ];
193190
int res = _Py_RemoteDebug_PagedReadRemoteMemory(
@@ -198,7 +195,7 @@ read_py_bytes(
198195
);
199196
if (res < 0) {
200197
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read PyBytesObject");
201-
goto err;
198+
return NULL;
202199
}
203200

204201
Py_ssize_t len = GET_MEMBER(Py_ssize_t, bytes_obj, unwinder->debug_offsets.bytes_object.ob_size);
@@ -209,36 +206,26 @@ read_py_bytes(
209206
return NULL;
210207
}
211208

212-
buf = (char *)PyMem_RawMalloc(len+1);
213-
if (buf == NULL) {
214-
PyErr_NoMemory();
209+
PyBytesWriter *writer = PyBytesWriter_Create(len);
210+
if (writer == NULL) {
215211
set_exception_cause(unwinder, PyExc_MemoryError, "Failed to allocate buffer for bytes reading");
216212
return NULL;
217213
}
218214

219215
size_t offset = (size_t)unwinder->debug_offsets.bytes_object.ob_sval;
220-
res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset, len, buf);
216+
res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset,
217+
len, PyBytesWriter_GetData(writer));
221218
if (res < 0) {
219+
PyBytesWriter_Discard(writer);
222220
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read bytes data from remote memory");
223-
goto err;
221+
return NULL;
224222
}
225-
buf[len] = '\0';
226223

227-
result = PyBytes_FromStringAndSize(buf, len);
224+
PyObject *result = PyBytesWriter_Finish(writer);
228225
if (result == NULL) {
229226
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to create PyBytes from remote bytes data");
230-
goto err;
231227
}
232-
233-
PyMem_RawFree(buf);
234-
assert(result != NULL);
235228
return result;
236-
237-
err:
238-
if (buf != NULL) {
239-
PyMem_RawFree(buf);
240-
}
241-
return NULL;
242229
}
243230

244231
long

0 commit comments

Comments
 (0)