From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id NUclI3/pcWCGUQAAWB0awg (envelope-from ) for ; Sat, 10 Apr 2021 14:07:59 -0400 Received: by simark.ca (Postfix, from userid 112) id 829701EE1B; Sat, 10 Apr 2021 14:07:59 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E47BA1E54D for ; Sat, 10 Apr 2021 14:07:57 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 59E85385783A; Sat, 10 Apr 2021 18:07:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59E85385783A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618078077; bh=Tn/s9zsy/v0OcRBGpp3C4xh8WDuHteFOiRfK2l36umM=; h=Date:To:In-Reply-To:Subject:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kwqZEpaU5Al3dy4E/64NCIOGN1GBTbXnR8nKr356CKIrfklNU5M+ENU9K31Ip0mix UgFnShCU6H/J6rEhNcJMF2r/kjhk96w77Y4kyYJXIw/5Qo2XC1w4XuGeqyWPoRKQd/ QUU5nDMKtWgghXwu2B+MOdLELxLRl18ttqIvlxfI= Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 56779385783A for ; Sat, 10 Apr 2021 18:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 56779385783A Received: from fencepost.gnu.org ([2001:470:142:3::e]:48421) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVI1P-0005CG-Fv; Sat, 10 Apr 2021 14:07:51 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1875 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVI1O-0006s5-4F; Sat, 10 Apr 2021 14:07:51 -0400 Date: Sat, 10 Apr 2021 21:07:31 +0300 Message-Id: <834kge57z0.fsf@gnu.org> To: Tom Tromey In-Reply-To: <87sg3ygp1d.fsf@tromey.com> (message from Tom Tromey on Sat, 10 Apr 2021 09:03:26 -0600) Subject: Re: Subtle problems with "info sharedlibrary" on MS-Windows References: <83czw7p4nd.fsf@gnu.org> <777379173.1335754.1615393830518@mail.yahoo.com> <83mtvbne96.fsf@gnu.org> <259022839.1083386.1615397702855@mail.yahoo.com> <83y2dwbow6.fsf@gnu.org> <83lf9vbljw.fsf@gnu.org> <87sg3ygp1d.fsf@tromey.com> 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: , From: Eli Zaretskii via Gdb-patches Reply-To: Eli Zaretskii Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" > From: Tom Tromey > Cc: ssbssa@yahoo.de, Eli Zaretskii > Date: Sat, 10 Apr 2021 09:03:26 -0600 > > I suppose a patch similar to this is needed for gdbserver as well? Is the below okay? --- gdbserver/win32-low.cc~ 2021-03-25 03:47:10.000000000 +0200 +++ gdbserver/win32-low.cc 2021-04-10 21:05:48.677425000 +0300 @@ -1165,11 +1165,13 @@ load_psapi (void) #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]; @@ -1178,7 +1180,7 @@ win32_add_all_dlls (void) BOOL ok; if (!load_psapi ()) - return; + return NULL; cbNeeded = 0; #ifdef __x86_64__ @@ -1196,11 +1198,11 @@ win32_add_all_dlls (void) &cbNeeded); if (!ok || !cbNeeded) - return; + return NULL; DllHandle = (HMODULE *) alloca (cbNeeded); if (!DllHandle) - return; + return NULL; #ifdef __x86_64__ if (wow64_process) @@ -1216,7 +1218,7 @@ win32_add_all_dlls (void) cbNeeded, &cbNeeded); if (!ok) - return; + return NULL; char system_dir[MAX_PATH]; char syswow_dir[MAX_PATH]; @@ -1252,7 +1254,7 @@ win32_add_all_dlls (void) 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], @@ -1265,6 +1267,9 @@ win32_add_all_dlls (void) 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 @@ -1280,9 +1285,24 @@ win32_add_all_dlls (void) } win32_add_one_solib (name, (CORE_ADDR) (uintptr_t) mi.lpBaseOfDll); + if (load_addr != nullptr) + { + strcpy (dll_name, name); + return dll_name; + } } + 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); @@ -1298,7 +1318,12 @@ windows_nat::handle_load_dll () 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);