From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id dmN1J/TUsV/AUQAAWB0awg (envelope-from ) for ; Sun, 15 Nov 2020 20:25:08 -0500 Received: by simark.ca (Postfix, from userid 112) id 9485E1F08B; Sun, 15 Nov 2020 20:25:08 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 26D641E58F for ; Sun, 15 Nov 2020 20:25:08 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A93243857831; Mon, 16 Nov 2020 01:25:07 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 9B0D8385DC14 for ; Mon, 16 Nov 2020 01:25:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9B0D8385DC14 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (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 11C991E58F; Sun, 15 Nov 2020 20:25:03 -0500 (EST) Subject: Re: [PATCH] Search for DWZ files in debug-file-directories as well To: Sergio Durigan Junior , gdb-patches@sourceware.org References: <20201114234842.2334396-1-sergiodj@sergiodj.net> From: Simon Marchi Message-ID: <47d6fb03-c296-df0e-6613-0cd08b3c7b0f@simark.ca> Date: Sun, 15 Nov 2020 20:25:03 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201114234842.2334396-1-sergiodj@sergiodj.net> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit 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: , Cc: Mark Wielaard Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2020-11-14 6:48 p.m., Sergio Durigan Junior via Gdb-patches wrote: > When Debian (and Ubuntu) builds its binaries, it (still) doesn't use > dwz's "--relative" option. This causes their debuginfo files to > carry a .gnu_debugaltlink section containing a full pathname to the > DWZ alt debug file, like this: > > $ readelf -wk /usr/bin/cat > Contents of the .gnu_debugaltlink section: > > Separate debug info file: /usr/lib/debug/.dwz/x86_64-linux-gnu/coreutils.debug > Build-ID (0x14 bytes): > ee 76 5d 71 97 37 ce 46 99 44 32 bb e8 a9 1a ef 99 96 88 db > > Contents of the .gnu_debuglink section: > > Separate debug info file: 06d3bee37b8c7e67b31cb2689cb351102ae73b.debug > CRC value: 0x53267655 > > This usually works OK, because most of the debuginfo files installed > via apt will be present in /usr/lib/debug anyway. However, imagine > the following scenario: > > - You are using /usr/bin/cat, it crashes on you and generates a > corefile. > > - You don't want/need to "apt install" the debuginfo file for > coreutils from the repositories. Instead, you already have the > debuginfo files in a separate directory (e.g., $HOME/dbgsym). > > - You start GDB and "set debug-file-directory $HOME/dbgsym". > You then get the following message: > > $ gdb -ex 'set debug-file-directory ./dbgsym/usr/lib/debug' -ex 'file /bin/cat' -ex 'core-file ./cat.core' > GNU gdb (Ubuntu 10.1-0ubuntu1) 10.1 > ... > Reading symbols from /bin/cat... > Reading symbols from /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug... > could not find '.gnu_debugaltlink' file for /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug > > This error happens because GDB is trying to locate the build-id > link (inside /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id) for the > DWZ alt debug file, which doesn't exist. Arguably, this is a problem > with how dh_dwz works in Debian, and it's something I'm also planning > to tackle. But, back at the problem at hand. > > Besides not being able to find the build-id link in the directory > mentioned above, GDB also tried to open the DWZ alt file using its > filename. The problem here is that, since we don't have the distro's > debuginfo installed, it can't find anything under /usr/lib/debug that > satisfies it. > > It occurred to me that a good way to workaround this problem is to > actually try to locate the DWZ alt debug file inside the > debug-file-directories (that were likely provided by the user). So > this is what the proposed patch does. > > The idea here is simple: get the filename extracted from the > .gnu_debugaltlink section, and manipulate it in order to replace the > initial part of the path (everything before "/.dwz/") by whatever > debug-file-directories the user might have provided. > > I talked with Mark Wielaard and he agrees this is a sensible approach. > In fact, apparently this is something that eu-readelf also does. > > I regtested this code, and no regressions were found. Hi Sergio, I don't really have an opinion on this at the moment because I don't know much about how dwz files are used in practice. Is having a ".dwz" somewhat standard? > @@ -2238,6 +2236,61 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd) > if (dwz_bfd == NULL) > dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid); > > + if (dwz_bfd == nullptr) > + { > + /* If the user has provided us with different > + debug-file-directories, we can try them in order. */ > + size_t dwz_pos = filename.find ("/.dwz/"); > + > + if (dwz_pos != std::string::npos) > + { > + std::string tmpfilename = filename.erase (0, dwz_pos); "filename.erase", I think that modifies filename in place. If so, is this what you intended? > + std::vector> debugdir_vec > + = dirnames_to_char_ptr_vec (debug_file_directory); > + > + for (const gdb::unique_xmalloc_ptr &debugdir : debugdir_vec) > + { > + /* The idea is to iterate over the > + debug-file-directories provided by the user and > + replace the hard-coded path in the "filename" by each > + debug-file-directory. > + > + For example, suppose that filename is: > + > + /usr/lib/debug/.dwz/foo.debug > + > + And suppose that we have "$HOME/bar" as the > + debug-file-directory. We would then adjust filename > + to look like: > + > + $HOME/bar/.dwz/foo.debug > + > + which would hopefully allow us to find the alt debug > + file. */ > + std::string ddir = debugdir.get (); > + > + if (filename.size () > ddir.size () > + && filename.compare (0, ddir.size (), ddir) == 0) > + continue; What's the intent of this condition? Can you add a comment to make it explicit? > + > + std::string new_filename = tmpfilename.insert (0, ddir); Same question as above for "tmpfilename.insert". Simon