static void handle_load_dll (void) { LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll; char *dll_name; dll_name = get_image_name (current_process_handle, event->lpImageName, event->fUnicode); if (!dll_name) return; win32_add_one_solib (dll_name, (CORE_ADDR) (uintptr_t) event->lpBaseOfDll); }
static void win32_add_all_dlls (void) { size_t i; HMODULE dh_buf[1]; HMODULE *DllHandle = dh_buf; DWORD cbNeeded; BOOL ok; if (!load_psapi ()) return; cbNeeded = 0; ok = (*win32_EnumProcessModules) (current_process_handle, DllHandle, sizeof (HMODULE), &cbNeeded); if (!ok || !cbNeeded) return; DllHandle = (HMODULE *) alloca (cbNeeded); if (!DllHandle) return; ok = (*win32_EnumProcessModules) (current_process_handle, DllHandle, cbNeeded, &cbNeeded); if (!ok) return; for (i = 1; i < ((size_t) cbNeeded / sizeof (HMODULE)); i++) { MODULEINFO mi; char dll_name[MAX_PATH]; if (!(*win32_GetModuleInformation) (current_process_handle, DllHandle[i], &mi, sizeof (mi))) continue; if ((*win32_GetModuleFileNameExA) (current_process_handle, DllHandle[i], dll_name, MAX_PATH) == 0) continue; win32_add_one_solib (dll_name, (CORE_ADDR) (uintptr_t) mi.lpBaseOfDll); } }
static void handle_load_dll (void) { LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll; char dll_buf[MAX_PATH + 1]; char *dll_name = NULL; CORE_ADDR load_addr; dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0'; /* Windows does not report the image name of the dlls in the debug event on attaches. We resort to iterating over the list of loaded dlls looking for a match by image base. */ if (!psapi_get_dll_name (event->lpBaseOfDll, dll_buf)) { if (!server_waiting) /* On some versions of Windows and Windows CE, we can't create toolhelp snapshots while the inferior is stopped in a LOAD_DLL_DEBUG_EVENT due to a dll load, but we can while Windows is reporting the already loaded dlls. */ toolhelp_get_dll_name (event->lpBaseOfDll, dll_buf); } dll_name = dll_buf; if (*dll_name == '\0') dll_name = get_image_name (current_process_handle, event->lpImageName, event->fUnicode); if (!dll_name) return; /* The symbols in a dll are offset by 0x1000, which is the the offset from 0 of the first byte in an image - because of the file header and the section alignment. */ load_addr = (CORE_ADDR) (uintptr_t) event->lpBaseOfDll + 0x1000; win32_add_one_solib (dll_name, load_addr); }