|
41 | 41 | #define GET_MEMBER(type, obj, offset) (*(type*)((char*)(obj) + (offset))) |
42 | 42 |
|
43 | 43 | /* Size macros for opaque buffers */ |
44 | | -#define SIZEOF_UNICODE_OBJ sizeof(PyUnicodeObject) |
45 | 44 | #define SIZEOF_BYTES_OBJ sizeof(PyBytesObject) |
46 | | -#define SIZEOF_INTERP_FRAME sizeof(_PyInterpreterFrame) |
| 45 | +#define SIZEOF_CODE_OBJ sizeof(PyCodeObject) |
47 | 46 | #define SIZEOF_GEN_OBJ sizeof(PyGenObject) |
| 47 | +#define SIZEOF_INTERP_FRAME sizeof(_PyInterpreterFrame) |
| 48 | +#define SIZEOF_LLIST_NODE sizeof(struct llist_node) |
| 49 | +#define SIZEOF_PAGE_CACHE_ENTRY sizeof(page_cache_entry_t) |
| 50 | +#define SIZEOF_PYOBJECT sizeof(PyObject) |
48 | 51 | #define SIZEOF_SET_OBJ sizeof(PySetObject) |
49 | | -#define SIZEOF_TYPE_OBJ sizeof(PyTypeObject) |
50 | 52 | #define SIZEOF_TASK_OBJ 4096 |
51 | | -#define SIZEOF_PYOBJECT sizeof(PyObject) |
52 | | -#define SIZEOF_LLIST_NODE sizeof(struct llist_node) |
53 | 53 | #define SIZEOF_THREAD_STATE sizeof(PyThreadState) |
54 | | -#define SIZEOF_CODE_OBJ sizeof(PyCodeObject) |
| 54 | +#define SIZEOF_TYPE_OBJ sizeof(PyTypeObject) |
| 55 | +#define SIZEOF_UNICODE_OBJ sizeof(PyUnicodeObject) |
55 | 56 |
|
56 | 57 | // Calculate the minimum buffer size needed to read interpreter state fields |
57 | 58 | // We need to read code_object_generation and potentially tlbc_generation |
| 59 | +#ifndef MAX |
| 60 | +#define _MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 61 | +#else |
| 62 | +#define _MAX(a, b) MAX(a, b) |
| 63 | +#endif |
| 64 | + |
58 | 65 | #ifdef Py_GIL_DISABLED |
59 | | -#define INTERP_STATE_MIN_SIZE MAX(MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \ |
| 66 | +#define INTERP_STATE_MIN_SIZE _MAX(_MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \ |
60 | 67 | offsetof(PyInterpreterState, tlbc_indices.tlbc_generation) + sizeof(uint32_t)), \ |
61 | 68 | offsetof(PyInterpreterState, threads.head) + sizeof(void*)) |
62 | 69 | #else |
63 | | -#define INTERP_STATE_MIN_SIZE MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \ |
| 70 | +#define INTERP_STATE_MIN_SIZE _MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \ |
64 | 71 | offsetof(PyInterpreterState, threads.head) + sizeof(void*)) |
65 | 72 | #endif |
66 | | -#define INTERP_STATE_BUFFER_SIZE MAX(INTERP_STATE_MIN_SIZE, 256) |
| 73 | +#define INTERP_STATE_BUFFER_SIZE _MAX(INTERP_STATE_MIN_SIZE, 256) |
| 74 | +#undef _MAX |
67 | 75 |
|
68 | 76 |
|
69 | 77 |
|
@@ -392,7 +400,7 @@ read_py_long( |
392 | 400 | unsigned int shift = PYLONG_BITS_IN_DIGIT; |
393 | 401 |
|
394 | 402 | // Read the entire PyLongObject at once |
395 | | - char long_obj[unwinder->debug_offsets.long_object.size]; |
| 403 | + char long_obj[SIZEOF_LONG_OBJ]; |
396 | 404 | int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory( |
397 | 405 | &unwinder->handle, |
398 | 406 | address, |
@@ -531,7 +539,7 @@ parse_task_name( |
531 | 539 | uintptr_t task_address |
532 | 540 | ) { |
533 | 541 | // Read the entire TaskObj at once |
534 | | - char task_obj[unwinder->async_debug_offsets.asyncio_task_object.size]; |
| 542 | + char task_obj[SIZEOF_TASK_OBJ]; |
535 | 543 | int err = _Py_RemoteDebug_PagedReadRemoteMemory( |
536 | 544 | &unwinder->handle, |
537 | 545 | task_address, |
@@ -594,7 +602,7 @@ static int parse_task_awaited_by( |
594 | 602 | int recurse_task |
595 | 603 | ) { |
596 | 604 | // Read the entire TaskObj at once |
597 | | - char task_obj[unwinder->async_debug_offsets.asyncio_task_object.size]; |
| 605 | + char task_obj[SIZEOF_TASK_OBJ]; |
598 | 606 | if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address, |
599 | 607 | unwinder->async_debug_offsets.asyncio_task_object.size, |
600 | 608 | task_obj) < 0) { |
@@ -745,7 +753,7 @@ create_task_result( |
745 | 753 | PyObject* result = NULL; |
746 | 754 | PyObject *call_stack = NULL; |
747 | 755 | PyObject *tn = NULL; |
748 | | - char task_obj[unwinder->async_debug_offsets.asyncio_task_object.size]; |
| 756 | + char task_obj[SIZEOF_TASK_OBJ]; |
749 | 757 | uintptr_t coro_addr; |
750 | 758 |
|
751 | 759 | result = PyList_New(0); |
|
0 commit comments