diff --git a/Modules/_testexternalinspection.c b/Modules/_testexternalinspection.c index 77984460400c5d..fcb18aeef08c39 100644 --- a/Modules/_testexternalinspection.c +++ b/Modules/_testexternalinspection.c @@ -133,6 +133,10 @@ return_section_address( cmd = (struct segment_command_64*)((void*)cmd + cmd->cmdsize); } + + // We should not be here, but if we are there, we should say about this + PyErr_SetString( + PyExc_RuntimeError, "Cannot find section address.\n"); return 0; } @@ -188,6 +192,8 @@ search_section_in_file( munmap(map, fs.st_size); if (close(fd) != 0) { + // This might hide one of the above exceptions, maybe we + // should chain them? PyErr_SetFromErrno(PyExc_OSError); } return result; @@ -217,7 +223,6 @@ search_map_for_section(pid_t pid, const char* secname, const char* substr) { mach_port_t proc_ref = pid_to_task(pid); if (proc_ref == 0) { - PyErr_SetString(PyExc_PermissionError, "Cannot get task for PID"); return 0; } @@ -260,6 +265,9 @@ search_map_for_section(pid_t pid, const char* secname, const char* substr) { address += size; } + + PyErr_SetString(PyExc_RuntimeError, + "mach_vm_region failed to find the section"); return 0; } @@ -306,6 +314,8 @@ find_map_start_address(pid_t pid, char* result_filename, const char* map) if (!match_found) { map_filename[0] = '\0'; + PyErr_Format(PyExc_RuntimeError, + "Cannot find map start address for map: %s", map); } return result_address; @@ -401,6 +411,8 @@ search_map_for_section(pid_t pid, const char* secname, const char* map) static uintptr_t search_map_for_section(pid_t pid, const char* secname, const char* map) { + PyErr_SetString(PyExc_NotImplementedError, + "Not supported on this platform"); return 0; } #endif @@ -419,7 +431,8 @@ get_py_runtime(pid_t pid) static uintptr_t get_async_debug(pid_t pid) { - uintptr_t result = 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"); } @@ -482,6 +495,9 @@ read_memory(pid_t pid, uintptr_t remote_address, size_t len, void* dst) } total_bytes_read = len; #else + PyErr_SetString( + PyExc_RuntimeError, + "Memory reading is not supported on this platform"); return -1; #endif return total_bytes_read; @@ -789,6 +805,9 @@ parse_coro_chain( pid, coro_address + offsets->gen_object.gi_frame_state, &gi_frame_state); + if (err) { + return -1; + } if (gi_frame_state == FRAME_SUSPENDED_YIELD_FROM) { char owner;