From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic303-21.consmr.mail.ir2.yahoo.com (sonic303-21.consmr.mail.ir2.yahoo.com [77.238.178.202]) by sourceware.org (Postfix) with ESMTPS id D983D385E008 for ; Tue, 24 Mar 2020 19:24:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D983D385E008 X-YMail-OSG: L.XlscMVM1nM6SHQuvAk3nJ85k6.jlVp5M1vHH2hawBfWRPBGFg8bz5Z97vrEJj 4vaHxxYRfGBKY1IfmnhfqphMM7l3wmU_hO4naAwxHHEbv2ZV3W6xral09hSW2Hw7zU6ci2_xg1aG 95fr5uQapmTR0oNK.G.WUobSZliCPwGYgcbkM36GmJL3Cb3RKinuwwfY_bCDYx_FHOgwjEHIcuOn EhPIhmG2Xjt8uTtVQNFY4f1s8MEyu0xWrEzmJdIepdoKTdWOGDJV6inADccxiWlVmupCikfxSicE pPu8RTlKEq5XRDrwVQ6WcQj0lM2iY.0seSCZ7jWBZbblXkJfEK5hedMo_gsjE6OcDhonIQT_3PwR CHORUgnRl6t_QWJIhENo_3eFXiQlEOEH2UKVuiT3nI9d.3NrBu1GWq0yLfsxjzniC92TlMd6IzFB JMwaMKn9fiXtfVeuP8L1HvQNQxAjDeVhpD4yZX7GuIVs5WI_4LdLIle3OCCHswNZhsnxvLisMgB1 Fg.Z_twx1eD.A95QD4PQwg1.K1EuXgHwJY9RYrwxOFtm64o34Ns.I2xNospOD6ghteU9_wLyWvJa FVzQptJ_qOd4mQuaw8Yd2DWD.M_4mKlU7iyQty5g85bL71SbiAa3EmDgwMDUHU9LVUkb8ICvUJQq wuQL2Mm4mz0gW6ECt30DngenPo0D3qJhcU3cyeziTLDt2OQyXJdqCVpA1MpGkKp_DgO1kpmTWE40 megJtVw9r0tRRxKVnCqZ5z6JVGsuuYK7r1hoxvuVDZg_PjI3_aQDd0n2igpNG89wbahcIuArBw_1 dLoLkMEHvBWGENBV0YMIweV9AGEdYdF73EnC97_CEL21umJj6NmdbjX7erbsbBHrD72rWknvCJrP NlJ46gOWwDAVwZ.Su3lmDMHi4_IdJXGa19H6MLFgsn6Jnpmk9JbQcQVbqp92BK0eGEEKoh8gmaTD 84Fk.3NZ5HJJwaTfIvim03MiU4pLHUc.HqwySYT4n4vt9JZ5mnPBAs6lHtlPdU6DSN0c35QWaZrl hzrLN6vwFDAWL1qjaPnITByMAhaWrU8at7j.iBNxKCsT1GnScythUuw.LkUrBgb2sWKueC4oVz5J DCLArWgBKXA9sjoEmv2pPDGvATGPxC4NuRNYUtRbAL3RyKyejHPvmlGOkDhEz2fsP8OnSB.wSsIw _GJSro5ydMgTbs38HLubfMi.5IWevlZPeVCg3irOUkF6XVNh_GTIcTIL8tI8.5hbsZTRbQ1jJgHQ q_BcAE55RqlN7JaHNmMEalM0InOfZiecRGx3qgFpSjM5SBDSyNdbCED7dSBG5vXNcjSqJ4L0N0X4 5LeI9CK.ZXSzm5G6RH3T_fnvteSjmfTKA_O4ZD2cNLlAKND2ZyhXFCM7y2hn3s8NyietfcHOyvTZ gMCRiS0MxSJUQvKMQ45TAUZ5VEnTpoA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Tue, 24 Mar 2020 19:24:12 +0000 Received: by smtp429.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID f9d9390007d839b0a103d1b1ee5db2e8; Tue, 24 Mar 2020 19:24:08 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH v2] Fix WOW64 process system DLL paths Date: Tue, 24 Mar 2020 20:23:51 +0100 Message-Id: <20200324192351.3904-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.25.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 200324-0, 03/24/2020), Outbound message X-Antivirus-Status: Clean References: <20200324192351.3904-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-27.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Mar 2020 19:24:15 -0000 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 * windows-nat.c (windows_add_all_dlls): Fix system dll paths. --- v2: - added error check with gdb_assert's - use std::string for newly assembled dll path --- gdb/windows-nat.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 9c5ea5c046..8b7328946b 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1993,16 +1993,39 @@ windows_add_all_dlls (void) return; } +#ifdef __x86_64__ + char system_dir[__PMAX]; + char syswow_dir[__PMAX]; + size_t system_dir_len = 0; + if (wow64_process) + { + 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)); + + 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); + } +#endif for (i = 1; i < (int) (cb_needed / sizeof (HMODULE)); i++) { MODULEINFO mi; #ifdef __USEWIDE wchar_t dll_name[__PMAX]; - char name[__PMAX]; + char dll_name_mb[__PMAX]; #else char dll_name[__PMAX]; - char *name; #endif + const char *name; if (GetModuleInformation (current_process_handle, hmodules[i], &mi, sizeof (mi)) == 0) continue; @@ -2010,10 +2033,25 @@ windows_add_all_dlls (void) dll_name, sizeof (dll_name)) == 0) continue; #ifdef __USEWIDE - wcstombs (name, dll_name, __PMAX); + wcstombs (dll_name_mb, dll_name, __PMAX); + name = dll_name_mb; #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. */ + std::string syswow_dll_path; + if (wow64_process + && strncasecmp (name, system_dir, system_dir_len) == 0 + && strchr (name + system_dir_len, '\\') == nullptr) + { + syswow_dll_path = syswow_dir; + 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.25.2