Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_external_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,17 @@ async def main():
stacks = self._extract_coroutine_funcnames(asyncio.run(main()))
self.assertEqual(stacks["consumer"], ["consumer"])

@skip_if_not_supported
def test_self_trace_with_empty_linetable(self):
def sample():
return RemoteUnwinder(os.getpid()).get_stack_trace()

sample.__code__ = sample.__code__.replace(co_linetable=b"")
frame = self._find_frame_in_trace(
sample(), lambda f: f.funcname == sample.__qualname__
)
self.assertEqual(frame.location, (-1, -1, -1, -1))

@skip_if_not_supported
@unittest.skipIf(
sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED,
Expand Down
29 changes: 8 additions & 21 deletions Modules/_remote_debugging/object_reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ read_py_bytes(
uintptr_t address,
Py_ssize_t max_len
) {
PyObject *result = NULL;
char *buf = NULL;

// Read the entire PyBytesObject at once
char bytes_obj[SIZEOF_BYTES_OBJ];
int res = _Py_RemoteDebug_PagedReadRemoteMemory(
Expand All @@ -198,7 +195,7 @@ read_py_bytes(
);
if (res < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read PyBytesObject");
goto err;
return NULL;
}

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

buf = (char *)PyMem_RawMalloc(len+1);
if (buf == NULL) {
PyErr_NoMemory();
PyBytesWriter *writer = PyBytesWriter_Create(len);
if (writer == NULL) {
set_exception_cause(unwinder, PyExc_MemoryError, "Failed to allocate buffer for bytes reading");
return NULL;
}

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

result = PyBytes_FromStringAndSize(buf, len);
PyObject *result = PyBytesWriter_Finish(writer);
if (result == NULL) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to create PyBytes from remote bytes data");
goto err;
}

PyMem_RawFree(buf);
assert(result != NULL);
return result;

err:
if (buf != NULL) {
PyMem_RawFree(buf);
}
return NULL;
}

long
Expand Down
Loading