From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qJz3LClfbGA1TgAAWB0awg (envelope-from ) for ; Tue, 06 Apr 2021 09:16:25 -0400 Received: by simark.ca (Postfix, from userid 112) id B658A1E939; Tue, 6 Apr 2021 09:16:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 C547D1E54D for ; Tue, 6 Apr 2021 09:16:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 84ECB3846078; Tue, 6 Apr 2021 13:16:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84ECB3846078 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617714984; bh=rCithZDqhpl8+WNWkI4wrWNk8thYJZeBl+CM0nOUiY8=; 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=Y0AIFFOFyVbJuDjyjMRnbyYbcr5Puw55V1EcOhDr4P4HKOypCx908D2xsuDB9skwv RaZYo2RSRw4TKXfL5IJBrXNdht5TLaAHXb+nkI0Pp7bUk9M6GTVmZFevuvXPBj+z5M JyekqORLg30SrKzyD1F0ephr9Ps4S3zqeJRGNdfs= Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 26ABD3846078 for ; Tue, 6 Apr 2021 13:16:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 26ABD3846078 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49975) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lTlZ7-0001a0-OS; Tue, 06 Apr 2021 09:16:21 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3532 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lTlZ7-0002oL-0L; Tue, 06 Apr 2021 09:16:21 -0400 Date: Tue, 06 Apr 2021 16:16:19 +0300 Message-Id: <83lf9vbljw.fsf@gnu.org> To: ssbssa@yahoo.de In-Reply-To: <83y2dwbow6.fsf@gnu.org> (message from Eli Zaretskii via Gdb-patches on Mon, 05 Apr 2021 20:51:53 +0300) 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> 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" > Date: Mon, 05 Apr 2021 20:51:53 +0300 > From: Eli Zaretskii via Gdb-patches > Cc: gdb-patches@sourceware.org > > https://sourceware.org/bugzilla/show_bug.cgi?id=17659 > > That bug describes the same problem and provides a patch. The bug was > closed without applying the because the problem was deemed resolved by > the addition of windows_add_all_dlls function to windows-nat.c. > > However, AFAIU windows_add_all_dlls solves the problem only for DLLs > loaded at startup of the debuggee. It cannot solve the problem of > DLLs loaded dynamically by the debuggee at run time. Which is what > happens in Emacs built with native-compilation capability: it compiles > Lisp into shared libraries, and loads those shared libraries as > needed. > > The problem clearly shows itself if you enable debugevents: GDB > reports some of the LOAD_DLL_DEBUG_EVENT's without announcing the name > of the loaded DLL. Later you can see that the DLL is not in the list > shown by "info shared", although Process Explorer shows that DLL as > being loaded by the debuggee. > > So I've reopened that bug, and I hope the patch there can be applied > to GDB some time soon. Here's a patch I propose, which completely solves the issue I described, and is IMO less complex than the code proposed in Bugzilla (it slightly refactors the existing code in windows_add_all_dlls). OK to commit to master (with a suitable ChangeLog entry)? --- gdb/windows-nat.c~0 2021-03-25 03:47:10.000000000 +0200 +++ gdb/windows-nat.c 2021-04-06 16:11:14.853125000 +0300 @@ -869,6 +869,8 @@ windows_make_so (const char *name, LPVOI return so; } +static bool windows_add_dll (LPVOID); + /* See nat/windows-nat.h. */ void @@ -884,12 +886,21 @@ windows_nat::handle_load_dll () (source: MSDN LOAD_DLL_DEBUG_INFO structure). */ dll_name = get_image_name (current_process_handle, event->lpImageName, event->fUnicode); + /* If the DLL name could not be gleaned via lpImageName, try harder + by enumerating all the DLLs loaded into the inferior, looking for + one that is loaded at base address = lpBaseOfDll. */ + if (dll_name) + { + + solib_end->next = windows_make_so (dll_name, event->lpBaseOfDll); + solib_end = solib_end->next; + } + else if (windows_add_dll (event->lpBaseOfDll)) + dll_name = solib_end->so_name; + if (!dll_name) return; - solib_end->next = windows_make_so (dll_name, event->lpBaseOfDll); - solib_end = solib_end->next; - lm_info_windows *li = (lm_info_windows *) solib_end->lm_info; DEBUG_EVENTS ("Loading dll \"%s\" at %s.", solib_end->so_name, @@ -1899,6 +1910,19 @@ windows_nat_target::wait (ptid_t ptid, s static void windows_add_all_dlls (void) { + windows_add_dll (NULL); +} + +/* Iterate over all DLLs currently mapped by our inferior, looking for + a DLL which is loaded at LOAD_ADDR. If found, add the DLL to our + list of solibs and return non-zero; otherwise do nothing and return + zero. LOAD_ADDR NULL means add all DLLs to the list of solibs; + this is used when the inferior finishes its initialization, and all + the DLLs it statically depends on are presumed loaded. */ + +static bool +windows_add_dll (LPVOID load_addr) +{ HMODULE dummy_hmodule; DWORD cb_needed; HMODULE *hmodules; @@ -1910,18 +1934,18 @@ windows_add_all_dlls (void) if (EnumProcessModulesEx (current_process_handle, &dummy_hmodule, sizeof (HMODULE), &cb_needed, LIST_MODULES_32BIT) == 0) - return; + return false; } else #endif { if (EnumProcessModules (current_process_handle, &dummy_hmodule, sizeof (HMODULE), &cb_needed) == 0) - return; + return false; } if (cb_needed < 1) - return; + return false; hmodules = (HMODULE *) alloca (cb_needed); #ifdef __x86_64__ @@ -1930,14 +1954,14 @@ windows_add_all_dlls (void) if (EnumProcessModulesEx (current_process_handle, hmodules, cb_needed, &cb_needed, LIST_MODULES_32BIT) == 0) - return; + return false; } else #endif { if (EnumProcessModules (current_process_handle, hmodules, cb_needed, &cb_needed) == 0) - return; + return false; } char system_dir[__PMAX]; @@ -1983,6 +2007,7 @@ windows_add_all_dlls (void) if (GetModuleInformation (current_process_handle, hmodules[i], &mi, sizeof (mi)) == 0) continue; + if (GetModuleFileNameEx (current_process_handle, hmodules[i], dll_name, sizeof (dll_name)) == 0) continue; @@ -2005,9 +2030,15 @@ windows_add_all_dlls (void) name = syswow_dll_path.c_str(); } - solib_end->next = windows_make_so (name, mi.lpBaseOfDll); - solib_end = solib_end->next; + if (!(load_addr && mi.lpBaseOfDll != load_addr)) + { + solib_end->next = windows_make_so (name, mi.lpBaseOfDll); + solib_end = solib_end->next; + if (load_addr) + return true; + } } + return false; } void