* [PATCH] Fix WOW64 process system DLL paths
[not found] <20200324171734.3335-1-ssbssa.ref@yahoo.de>
@ 2020-03-24 17:17 ` Hannes Domani
2020-03-24 18:33 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Hannes Domani @ 2020-03-24 17:17 UTC (permalink / raw)
To: gdb-patches
GetModuleFileNameEx returns for some DLLs of WOW64 processes
the path inside the 64bit system directory instead of the 32bit
syswow64 directory.
Problem happens e.g. with dbghelp.dll:
(gdb) start
Temporary breakpoint 1 at 0x415a00: file fiber.cpp, line 430.
Starting program: C:\src\tests\fiber.exe
warning: `C:\Windows\system32\dbghelp.dll': Shared library architecture i386:x86-64 is not compatible with target architecture i386.
Temporary breakpoint 1, main () at fiber.cpp:430
430 {
(gdb) info sharedlibrary
From To Syms Read Shared Object Library
0x77070000 0x771d4d20 Yes (*) C:\Windows\SysWOW64\ntdll.dll
0x74dc0000 0x74ebad9c Yes (*) C:\Windows\syswow64\kernel32.dll
0x75341000 0x75386a18 Yes (*) C:\Windows\syswow64\KernelBase.dll
0x6f6a1000 0x6f7c48fc Yes (*) C:\Windows\system32\dbghelp.dll
0x74d01000 0x74dab2c4 Yes (*) C:\Windows\syswow64\msvcrt.dll
(*): Shared library is missing debugging information.
This detects this situation and converts the DLL path to the
syswow64 equivalent.
gdb/ChangeLog:
2020-03-24 Hannes Domani <ssbssa@yahoo.de>
* windows-nat.c (windows_add_all_dlls): Fix system dll paths.
---
gdb/windows-nat.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 9c5ea5c046..6f46d3d361 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1993,6 +1993,21 @@ windows_add_all_dlls (void)
return;
}
+#ifdef __x86_64__
+ char system_dir[__PMAX];
+ char syswow_dir[__PMAX];
+ size_t system_dir_len = 0;
+ size_t syswow_dir_len = 0;
+ if (wow64_process)
+ {
+ GetSystemDirectoryA (system_dir, __PMAX);
+ GetSystemWow64DirectoryA (syswow_dir, __PMAX);
+ strcat (system_dir, "\\");
+ strcat (syswow_dir, "\\");
+ system_dir_len = strlen (system_dir);
+ syswow_dir_len = strlen (syswow_dir);
+ }
+#endif
for (i = 1; i < (int) (cb_needed / sizeof (HMODULE)); i++)
{
MODULEINFO mi;
@@ -2014,6 +2029,19 @@ windows_add_all_dlls (void)
#else
name = dll_name;
#endif
+#ifdef __x86_64__
+ /* Convert the DLL path of WOW64 processes returned by
+ GetModuleFileNameEx from the 64bit system directory to the
+ 32bit syswow64 directory if necessary. */
+ if (wow64_process
+ && strncasecmp (name, system_dir, system_dir_len) == 0
+ && strchr (name + system_dir_len, '\\') == nullptr)
+ {
+ strcpy (syswow_dir + syswow_dir_len, name + system_dir_len);
+ strcpy (name, syswow_dir);
+ syswow_dir[syswow_dir_len] = 0;
+ }
+#endif
solib_end->next = windows_make_so (name, mi.lpBaseOfDll);
solib_end = solib_end->next;
--
2.25.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix WOW64 process system DLL paths
2020-03-24 17:17 ` [PATCH] Fix WOW64 process system DLL paths Hannes Domani
@ 2020-03-24 18:33 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2020-03-24 18:33 UTC (permalink / raw)
To: Hannes Domani, gdb-patches
On 2020-03-24 1:17 p.m., Hannes Domani via Gdb-patches wrote:
> diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
> index 9c5ea5c046..6f46d3d361 100644
> --- a/gdb/windows-nat.c
> +++ b/gdb/windows-nat.c
> @@ -1993,6 +1993,21 @@ windows_add_all_dlls (void)
> return;
> }
>
> +#ifdef __x86_64__
> + char system_dir[__PMAX];
> + char syswow_dir[__PMAX];
> + size_t system_dir_len = 0;
> + size_t syswow_dir_len = 0;
> + if (wow64_process)
> + {
> + GetSystemDirectoryA (system_dir, __PMAX);
> + GetSystemWow64DirectoryA (syswow_dir, __PMAX);
This functions are documented to possibly fail, so let's check the return value.
If there is not imaginable reason why they would fail, then I using an assertion
is fine. We should also check that we have passed a large enough buffer.
For example:
UINT len = GetSystemDirectoryA (system_dir, sizeof (system_dir));
/* Error check. */
gdb_assert (len != 0);
/* Check that we have passed a large enough buffer. */
gdb_assert (len < sizeof (system_dir));
> + strcat (system_dir, "\\");
> + strcat (syswow_dir, "\\");
> + system_dir_len = strlen (system_dir);
> + syswow_dir_len = strlen (syswow_dir);
> + }
> +#endif
> for (i = 1; i < (int) (cb_needed / sizeof (HMODULE)); i++)
> {
> MODULEINFO mi;
> @@ -2014,6 +2029,19 @@ windows_add_all_dlls (void)
> #else
> name = dll_name;
> #endif
> +#ifdef __x86_64__
> + /* Convert the DLL path of WOW64 processes returned by
> + GetModuleFileNameEx from the 64bit system directory to the
> + 32bit syswow64 directory if necessary. */
> + if (wow64_process
> + && strncasecmp (name, system_dir, system_dir_len) == 0
> + && strchr (name + system_dir_len, '\\') == nullptr)
> + {
> + strcpy (syswow_dir + syswow_dir_len, name + system_dir_len);
> + strcpy (name, syswow_dir);
> + syswow_dir[syswow_dir_len] = 0;
> + }
> +#endif
Here, I wouldn't mind if you used some std::string a bit more to make
the string less error-prone (even if it involves a bit more copying),
but it's as you wish.
Simon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-03-24 18:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20200324171734.3335-1-ssbssa.ref@yahoo.de>
2020-03-24 17:17 ` [PATCH] Fix WOW64 process system DLL paths Hannes Domani
2020-03-24 18:33 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox