public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Always fix system DLL paths for 32bit programs
       [not found] <20200327114614.5612-1-ssbssa.ref@yahoo.de>
@ 2020-03-27 11:46 ` Hannes Domani
  2020-03-27 13:24   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Hannes Domani @ 2020-03-27 11:46 UTC (permalink / raw)
  To: gdb-patches

GetModuleFileNameEx might also return the 64bit system directory for 32bit
programs even for a 32bit gdb:

(gdb) info sharedlibrary
From        To          Syms Read   Shared Object Library
0x779d0000  0x77b34d20  Yes (*)     C:\Windows\SysWOW64\ntdll.dll
0x76850000  0x7694ad9c  Yes (*)     C:\Windows\syswow64\kernel32.dll
0x75421000  0x75466a18  Yes (*)     C:\Windows\syswow64\KernelBase.dll
0x6fbe1000  0x6fcca1c0  Yes (*)     C:\Windows\system32\dbghelp.dll
0x76d31000  0x76ddb2c4  Yes (*)     C:\Windows\syswow64\msvcrt.dll

So this makes the path conversion for all 32bit programs.

gdb/ChangeLog:

2020-03-27  Hannes Domani  <ssbssa@yahoo.de>

	* windows-nat.c (windows_add_all_dlls): Fix system dll paths.
---
 gdb/windows-nat.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 8b7328946b..f887bd8b40 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1993,29 +1993,36 @@ windows_add_all_dlls (void)
 	return;
     }
 
-#ifdef __x86_64__
   char system_dir[__PMAX];
   char syswow_dir[__PMAX];
   size_t system_dir_len = 0;
+  bool convert_syswow_dir = false;
+#ifdef __x86_64__
   if (wow64_process)
+#endif
     {
-      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));
+      /* This fails on 32bit Windows because it has no SysWOW64 directory,
+	 and in this case a path conversion isn't necessary.  */
+      UINT len = GetSystemWow64DirectoryA (syswow_dir, sizeof (syswow_dir));
+      if (len > 0)
+	{
+	  /* Check that we have passed a large enough buffer.  */
+	  gdb_assert (len < sizeof (syswow_dir));
+
+	  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));
 
-      len = GetSystemWow64DirectoryA (syswow_dir, sizeof (syswow_dir));
-      /* Error check.  */
-      gdb_assert (len != 0);
-      /* Check that we have passed a large enough buffer.  */
-      gdb_assert (len < sizeof (syswow_dir));
+	  strcat (system_dir, "\\");
+	  strcat (syswow_dir, "\\");
+	  system_dir_len = strlen (system_dir);
+
+	  convert_syswow_dir = true;
+	}
 
-      strcat (system_dir, "\\");
-      strcat (syswow_dir, "\\");
-      system_dir_len = strlen (system_dir);
     }
-#endif
   for (i = 1; i < (int) (cb_needed / sizeof (HMODULE)); i++)
     {
       MODULEINFO mi;
@@ -2038,12 +2045,11 @@ windows_add_all_dlls (void)
 #else
       name = dll_name;
 #endif
-#ifdef __x86_64__
-      /* Convert the DLL path of WOW64 processes returned by
+      /* Convert the DLL path of 32bit processes returned by
 	 GetModuleFileNameEx from the 64bit system directory to the
 	 32bit syswow64 directory if necessary.  */
       std::string syswow_dll_path;
-      if (wow64_process
+      if (convert_syswow_dir
 	  && strncasecmp (name, system_dir, system_dir_len) == 0
 	  && strchr (name + system_dir_len, '\\') == nullptr)
 	{
@@ -2051,7 +2057,6 @@ windows_add_all_dlls (void)
 	  syswow_dll_path += name + system_dir_len;
 	  name = syswow_dll_path.c_str();
 	}
-#endif
 
       solib_end->next = windows_make_so (name, mi.lpBaseOfDll);
       solib_end = solib_end->next;
-- 
2.26.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Always fix system DLL paths for 32bit programs
  2020-03-27 11:46 ` [PATCH] Always fix system DLL paths for 32bit programs Hannes Domani
@ 2020-03-27 13:24   ` Eli Zaretskii
  2020-03-27 21:50     ` Hannes Domani
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2020-03-27 13:24 UTC (permalink / raw)
  To: Hannes Domani; +Cc: gdb-patches

> Date: Fri, 27 Mar 2020 12:46:14 +0100
> From: Hannes Domani via Gdb-patches <gdb-patches@sourceware.org>
> 
> GetModuleFileNameEx might also return the 64bit system directory for 32bit
> programs even for a 32bit gdb:
> 
> (gdb) info sharedlibrary
> >From        To          Syms Read   Shared Object Library
> 0x779d0000  0x77b34d20  Yes (*)     C:\Windows\SysWOW64\ntdll.dll
> 0x76850000  0x7694ad9c  Yes (*)     C:\Windows\syswow64\kernel32.dll
> 0x75421000  0x75466a18  Yes (*)     C:\Windows\syswow64\KernelBase.dll
> 0x6fbe1000  0x6fcca1c0  Yes (*)     C:\Windows\system32\dbghelp.dll
> 0x76d31000  0x76ddb2c4  Yes (*)     C:\Windows\syswow64\msvcrt.dll
> 
> So this makes the path conversion for all 32bit programs.
> 
> gdb/ChangeLog:
> 
> 2020-03-27  Hannes Domani  <ssbssa@yahoo.de>
> 
> 	* windows-nat.c (windows_add_all_dlls): Fix system dll paths.

Thanks, this LGTM.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Always fix system DLL paths for 32bit programs
  2020-03-27 13:24   ` Eli Zaretskii
@ 2020-03-27 21:50     ` Hannes Domani
  0 siblings, 0 replies; 3+ messages in thread
From: Hannes Domani @ 2020-03-27 21:50 UTC (permalink / raw)
  To: Gdb-patches

 Am Freitag, 27. März 2020, 16:08:03 MEZ hat Eli Zaretskii <eliz@gnu.org> Folgendes geschrieben:

> > Date: Fri, 27 Mar 2020 12:46:14 +0100
>
> > From: Hannes Domani via Gdb-patches <gdb-patches@sourceware.org>
> >
> > GetModuleFileNameEx might also return the 64bit system directory for 32bit
> > programs even for a 32bit gdb:
> >
> > (gdb) info sharedlibrary
> > >From        To          Syms Read  Shared Object Library
> > 0x779d0000  0x77b34d20  Yes (*)    C:\Windows\SysWOW64\ntdll.dll
> > 0x76850000  0x7694ad9c  Yes (*)    C:\Windows\syswow64\kernel32.dll
> > 0x75421000  0x75466a18  Yes (*)    C:\Windows\syswow64\KernelBase.dll
> > 0x6fbe1000  0x6fcca1c0  Yes (*)    C:\Windows\system32\dbghelp.dll
> > 0x76d31000  0x76ddb2c4  Yes (*)    C:\Windows\syswow64\msvcrt.dll
> >
> > So this makes the path conversion for all 32bit programs.
> >
> > gdb/ChangeLog:
> >
> > 2020-03-27  Hannes Domani  <ssbssa@yahoo.de>
> >
> >     * windows-nat.c (windows_add_all_dlls): Fix system dll paths.
>
>
> Thanks, this LGTM.

Pushed, thanks.


Regards
Hannes Domani

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-27 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200327114614.5612-1-ssbssa.ref@yahoo.de>
2020-03-27 11:46 ` [PATCH] Always fix system DLL paths for 32bit programs Hannes Domani
2020-03-27 13:24   ` Eli Zaretskii
2020-03-27 21:50     ` Hannes Domani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).