From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3DA6A3857828 for ; Tue, 8 Mar 2022 22:41:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3DA6A3857828 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-Vn_0N3WMM96P29lQZAclkA-1; Tue, 08 Mar 2022 17:41:45 -0500 X-MC-Unique: Vn_0N3WMM96P29lQZAclkA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBC8D51DF; Tue, 8 Mar 2022 22:41:44 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.17.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6714D4531B; Tue, 8 Mar 2022 22:41:44 +0000 (UTC) From: Aaron Merey To: tom@tromey.com Cc: gdb-patches@sourceware.org, Aaron Merey Subject: Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink Date: Tue, 8 Mar 2022 17:41:36 -0500 Message-Id: <20220308224136.173615-1-amerey@redhat.com> In-Reply-To: <87o82lu2xy.fsf@tromey.com> References: <87o82lu2xy.fsf@tromey.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 08 Mar 2022 22:41:48 -0000 Hi Tom, On Fri, Mar 4, 2022 at 10:56 AM Tom Tromey wrote: > Aaron> + char *debuglink = bfd_get_debug_link_info (parent->obfd, &crc32); > > bfd_get_debug_link_info says it returns a malloc'd pointer, so I think > this is a memory leak. Using gdb::unique_xmalloc_ptr would solve > this. Fixed, thanks. Aaron --- gdb/auto-load.c | 64 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 9a1ccec87ce..0acf2cee777 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -51,6 +51,9 @@ followed by the path of a python script to load. */ #define AUTO_SECTION_NAME ".debug_gdb_scripts" +/* The section to look in for the name of a separate debug file. */ +#define DEBUGLINK_SECTION_NAME ".gnu_debuglink" + static void maybe_print_unsupported_script_warning (struct auto_load_pspace_info *, struct objfile *objfile, const struct extension_language_defn *language, @@ -823,24 +826,61 @@ auto_load_objfile_script (struct objfile *objfile, gdb::unique_xmalloc_ptr realname = gdb_realpath (objfile_name (objfile)); - if (!auto_load_objfile_script_1 (objfile, realname.get (), language)) + if (auto_load_objfile_script_1 (objfile, realname.get (), language)) + return; + + /* For Windows/DOS .exe executables, strip the .exe suffix, so that + FOO-gdb.gdb could be used for FOO.exe, and try again. */ + + size_t len = strlen (realname.get ()); + const size_t lexe = sizeof (".exe") - 1; + + if (len > lexe && strcasecmp (realname.get () + len - lexe, ".exe") == 0) { - /* For Windows/DOS .exe executables, strip the .exe suffix, so that - FOO-gdb.gdb could be used for FOO.exe, and try again. */ + len -= lexe; + realname.get ()[len] = '\0'; + + auto_load_debug_printf + ("auto-load: Stripped .exe suffix, retrying with \"%s\".", + realname.get ()); + + auto_load_objfile_script_1 (objfile, realname.get (), language); + return; + } - size_t len = strlen (realname.get ()); - const size_t lexe = sizeof (".exe") - 1; + /* If OBJFILE is a separate debug file and its name does not match + the name given in the parent's .gnu_debuglink section, try to + find the auto-load script using the parent's path and the + debuglink name. */ + + struct objfile *parent = objfile->separate_debug_objfile_backlink; + if (parent != nullptr) + { + unsigned long crc32; + gdb::unique_xmalloc_ptr debuglink + (bfd_get_debug_link_info (parent->obfd, &crc32)); - if (len > lexe && strcasecmp (realname.get () + len - lexe, ".exe") == 0) + if (debuglink.get () != nullptr + && strcmp (debuglink.get (), basename (realname.get ())) != 0) { - len -= lexe; - realname.get ()[len] = '\0'; + /* Replace the last component of the parent's path with the + debuglink name. */ - auto_load_debug_printf - ("auto-load: Stripped .exe suffix, retrying with \"%s\".", - realname.get ()); + std::string p_realname = gdb_realpath (objfile_name (parent)).get (); + size_t last = p_realname.find_last_of ('/'); - auto_load_objfile_script_1 (objfile, realname.get (), language); + if (last != std::string::npos) + { + p_realname.replace (last + 1, std::string::npos, + debuglink.get ()); + + auto_load_debug_printf + ("Debug filename mismatch, retrying with \"%s\".", + p_realname.c_str ()); + + auto_load_objfile_script_1 (objfile, + p_realname.c_str (), language); + } } } } -- 2.35.1