From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BX80KqYhbmBceQAAWB0awg (envelope-from ) for ; Wed, 07 Apr 2021 17:18:30 -0400 Received: by simark.ca (Postfix, from userid 112) id A00321E965; Wed, 7 Apr 2021 17:18:30 -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 A21C31E01F for ; Wed, 7 Apr 2021 17:18:29 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E64F385801D; Wed, 7 Apr 2021 21:18:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E64F385801D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617830309; bh=Cu/y938xwCzoIIKSAcyERqpZOYRkrrw27DVrW0hkdm0=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=TQD6GnIhFZBH7upGnWhn1Xudedg0xQeABATmNG3LOQdyj8obL0n4kaqsqyB0MhdeG CeVFAjxTu4oCNOv+zjSvofudQYhEPv+sbT2j/ZMrVIoKJuUVqPOrdV6S7WXHe7PkyM 32IDqryqSzeR6ymdpjOcDWvS0OKRspZRcvH983yM= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id B9740385801D for ; Wed, 7 Apr 2021 21:18:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B9740385801D Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 137LI9WU005373 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 7 Apr 2021 17:18:14 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 137LI9WU005373 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 26BBE1E01F; Wed, 7 Apr 2021 17:18:09 -0400 (EDT) Subject: Re: Subtle problems with "info sharedlibrary" on MS-Windows To: Eli Zaretskii , ssbssa@yahoo.de 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> Message-ID: Date: Wed, 7 Apr 2021 17:18:08 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <83lf9vbljw.fsf@gnu.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 7 Apr 2021 21:18:09 +0000 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: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2021-04-06 9:16 a.m., Eli Zaretskii via Gdb-patches wrote: >> 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)? The patch LGTM, see minor comments below. > > --- 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) According to our style guideline, we would use dll_name != nullptr (yes, I know the surrounding code doesn't respect that) > + { > + > + 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 non-zero -> true > + zero. LOAD_ADDR NULL means add all DLLs to the list of solibs; zero -> false > + 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)) Perhaps matter of personal preference, but I would understand it better (less mental steps) as 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; Here and above, it should be `load_addr != nullptr`. Simon