+2021-04-11 Eli Zaretskii <eliz@gnu.org>
+
+ * win32-low.cc (win32_add_dll): New function, with body almost
+ identical to what win32_add_all_dlls did. Accepts one argument;
+ if that is non-NULL, returns the file name of the DLL that is
+ loaded at the base address equal to that argument, or NULL if not
+ found. If the argument is NULL, add all the DLLs loaded by the
+ inferior to the list of solibs and return NULL.
+ (win32_add_all_dlls): Now a thin wrapper around win32_add_dll.
+ (windows_nat::handle_load_dll) [!_WIN32_WCE]: If get_image_name
+ failed to glean the file name of the DLL, call win32_add_dll to
+ try harder using the lpBaseOfDll member of the load-DLL event.
+
2021-03-30 Luis Machado <luis.machado@linaro.org>
* server.cc (handle_general_set, handle_query): Update variable
#ifndef _WIN32_WCE
-/* Iterate over all DLLs currently mapped by our inferior, and
- add them to our list of solibs. */
+/* Iterate over all DLLs currently mapped by our inferior, looking for
+ a DLL loaded at LOAD_ADDR; if found, return its file name,
+ otherwise return NULL. If LOAD_ADDR is NULL, add all mapped DLLs
+ to our list of solibs. */
-static void
-win32_add_all_dlls (void)
+static char *
+win32_add_dll (LPVOID load_addr)
{
size_t i;
HMODULE dh_buf[1];
BOOL ok;
if (!load_psapi ())
- return;
+ return NULL;
cbNeeded = 0;
#ifdef __x86_64__
&cbNeeded);
if (!ok || !cbNeeded)
- return;
+ return NULL;
DllHandle = (HMODULE *) alloca (cbNeeded);
if (!DllHandle)
- return;
+ return NULL;
#ifdef __x86_64__
if (wow64_process)
cbNeeded,
&cbNeeded);
if (!ok)
- return;
+ return NULL;
char system_dir[MAX_PATH];
char syswow_dir[MAX_PATH];
for (i = 1; i < ((size_t) cbNeeded / sizeof (HMODULE)); i++)
{
MODULEINFO mi;
- char dll_name[MAX_PATH];
+ static char dll_name[MAX_PATH];
if (!(*win32_GetModuleInformation) (current_process_handle,
DllHandle[i],
MAX_PATH) == 0)
continue;
+ if (load_addr != nullptr && mi.lpBaseOfDll != load_addr)
+ continue;
+
const char *name = dll_name;
/* Convert the DLL path of 32bit processes returned by
GetModuleFileNameEx from the 64bit system directory to the
name = syswow_dll_path.c_str();
}
- win32_add_one_solib (name, (CORE_ADDR) (uintptr_t) mi.lpBaseOfDll);
+ if (load_addr != nullptr)
+ {
+ if (name != dll_name)
+ strcpy (dll_name, name);
+ return dll_name;
+ }
+ else
+ win32_add_one_solib (name, (CORE_ADDR) (uintptr_t) mi.lpBaseOfDll);
}
+ return NULL;
}
-#endif
+
+/* Iterate over all DLLs currently mapped by our inferior, and
+ add them to our list of solibs. */
+
+static void
+win32_add_all_dlls (void)
+{
+ win32_add_dll (NULL);
+}
+#endif /* !_WIN32_WCE */
typedef HANDLE (WINAPI *winapi_CreateToolhelp32Snapshot) (DWORD, DWORD);
typedef BOOL (WINAPI *winapi_Module32First) (HANDLE, LPMODULEENTRY32);
dll_name = get_image_name (current_process_handle,
event->lpImageName, event->fUnicode);
- if (!dll_name)
+#ifndef _WIN32_WCE
+ if (dll_name == nullptr
+ && event->lpBaseOfDll != nullptr)
+ dll_name = win32_add_dll (event->lpBaseOfDll);
+#endif
+ if (dll_name == nullptr)
return;
win32_add_one_solib (dll_name, (CORE_ADDR) (uintptr_t) event->lpBaseOfDll);