diff --git a/Include/internal/pycore_debug_offsets.h b/Include/internal/pycore_debug_offsets.h index 34debf35d14df4d..13ef12f26ec4e72 100644 --- a/Include/internal/pycore_debug_offsets.h +++ b/Include/internal/pycore_debug_offsets.h @@ -17,31 +17,34 @@ extern "C" { // Macros to burn global values in custom sections so out-of-process // profilers can locate them easily. - #define GENERATE_DEBUG_SECTION(name, declaration) \ _GENERATE_DEBUG_SECTION_WINDOWS(name) \ _GENERATE_DEBUG_SECTION_APPLE(name) \ declaration \ - _GENERATE_DEBUG_SECTION_LINUX(name) + _GENERATE_DEBUG_SECTION_LINUX(name) \ + __attribute__((used)) #if defined(MS_WINDOWS) #define _GENERATE_DEBUG_SECTION_WINDOWS(name) \ _Pragma(Py_STRINGIFY(section(Py_STRINGIFY(name), read, write))) \ - __declspec(allocate(Py_STRINGIFY(name))) + __declspec(allocate(Py_STRINGIFY(name))) \ + __declspec(dllexport) #else #define _GENERATE_DEBUG_SECTION_WINDOWS(name) #endif #if defined(__APPLE__) #define _GENERATE_DEBUG_SECTION_APPLE(name) \ - __attribute__((section(SEG_DATA "," Py_STRINGIFY(name)))) + __attribute__((section(SEG_DATA "," Py_STRINGIFY(name)))) \ + __attribute__((visibility("default"))) #else #define _GENERATE_DEBUG_SECTION_APPLE(name) #endif #if defined(__linux__) && (defined(__GNUC__) || defined(__clang__)) #define _GENERATE_DEBUG_SECTION_LINUX(name) \ - __attribute__((section("." Py_STRINGIFY(name)))) + __attribute__((section("." Py_STRINGIFY(name)))) \ + __attribute__((visibility("default"))) #else #define _GENERATE_DEBUG_SECTION_LINUX(name) #endif diff --git a/Modules/_testexternalinspection.c b/Modules/_testexternalinspection.c index 25e0e9c64ec27df..9f0c28954cbc06d 100644 --- a/Modules/_testexternalinspection.c +++ b/Modules/_testexternalinspection.c @@ -414,7 +414,11 @@ get_py_runtime(pid_t pid) static uintptr_t get_async_debug(pid_t pid) { - return search_map_for_section(pid, "AsyncioDebug", "_asyncio.cpython"); + uintptr_t result = search_map_for_section(pid, "AsyncioDebug", "_asyncio.cpython"); + if (result == 0 && !PyErr_Occurred()) { + PyErr_SetString(PyExc_RuntimeError, "Cannot find AsyncioDebug section"); + } + return result; }