mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
GH-100987: Allow objects other than code objects as the "executable" of an internal frame. (GH-105727)
* Add table describing possible executable classes for out-of-process debuggers. * Remove shim code object creation code as it is no longer needed. * Make lltrace a bit more robust w.r.t. non-standard frames.
This commit is contained in:
parent
ad56340b66
commit
7199584ac8
28 changed files with 541 additions and 606 deletions
|
@ -2316,76 +2316,3 @@ _PyStaticCode_Init(PyCodeObject *co)
|
|||
}
|
||||
|
||||
#define MAX_CODE_UNITS_PER_LOC_ENTRY 8
|
||||
|
||||
PyCodeObject *
|
||||
_Py_MakeShimCode(const _PyShimCodeDef *codedef)
|
||||
{
|
||||
PyObject *name = NULL;
|
||||
PyObject *co_code = NULL;
|
||||
PyObject *lines = NULL;
|
||||
PyCodeObject *codeobj = NULL;
|
||||
uint8_t *loc_table = NULL;
|
||||
|
||||
name = _PyUnicode_FromASCII(codedef->cname, strlen(codedef->cname));
|
||||
if (name == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
co_code = PyBytes_FromStringAndSize(
|
||||
(const char *)codedef->code, codedef->codelen);
|
||||
if (co_code == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
int code_units = codedef->codelen / sizeof(_Py_CODEUNIT);
|
||||
int loc_entries = (code_units + MAX_CODE_UNITS_PER_LOC_ENTRY - 1) /
|
||||
MAX_CODE_UNITS_PER_LOC_ENTRY;
|
||||
loc_table = PyMem_Malloc(loc_entries);
|
||||
if (loc_table == NULL) {
|
||||
PyErr_NoMemory();
|
||||
goto cleanup;
|
||||
}
|
||||
for (int i = 0; i < loc_entries-1; i++) {
|
||||
loc_table[i] = 0x80 | (PY_CODE_LOCATION_INFO_NONE << 3) | 7;
|
||||
code_units -= MAX_CODE_UNITS_PER_LOC_ENTRY;
|
||||
}
|
||||
assert(loc_entries > 0);
|
||||
assert(code_units > 0 && code_units <= MAX_CODE_UNITS_PER_LOC_ENTRY);
|
||||
loc_table[loc_entries-1] = 0x80 |
|
||||
(PY_CODE_LOCATION_INFO_NONE << 3) | (code_units-1);
|
||||
lines = PyBytes_FromStringAndSize((const char *)loc_table, loc_entries);
|
||||
PyMem_Free(loc_table);
|
||||
if (lines == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
_Py_DECLARE_STR(shim_name, "<shim>");
|
||||
struct _PyCodeConstructor con = {
|
||||
.filename = &_Py_STR(shim_name),
|
||||
.name = name,
|
||||
.qualname = name,
|
||||
.flags = CO_NEWLOCALS | CO_OPTIMIZED,
|
||||
|
||||
.code = co_code,
|
||||
.firstlineno = 1,
|
||||
.linetable = lines,
|
||||
|
||||
.consts = (PyObject *)&_Py_SINGLETON(tuple_empty),
|
||||
.names = (PyObject *)&_Py_SINGLETON(tuple_empty),
|
||||
|
||||
.localsplusnames = (PyObject *)&_Py_SINGLETON(tuple_empty),
|
||||
.localspluskinds = (PyObject *)&_Py_SINGLETON(bytes_empty),
|
||||
|
||||
.argcount = 0,
|
||||
.posonlyargcount = 0,
|
||||
.kwonlyargcount = 0,
|
||||
|
||||
.stacksize = codedef->stacksize,
|
||||
|
||||
.exceptiontable = (PyObject *)&_Py_SINGLETON(bytes_empty),
|
||||
};
|
||||
|
||||
codeobj = _PyCode_New(&con);
|
||||
cleanup:
|
||||
Py_XDECREF(name);
|
||||
Py_XDECREF(co_code);
|
||||
Py_XDECREF(lines);
|
||||
return codeobj;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue