From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KCaoGFeNvl/zEgAAWB0awg (envelope-from ) for ; Wed, 25 Nov 2020 11:59:03 -0500 Received: by simark.ca (Postfix, from userid 112) id 628911F0AB; Wed, 25 Nov 2020 11:59:03 -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.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED 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 032B91E776 for ; Wed, 25 Nov 2020 11:59:03 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B6D4386103F; Wed, 25 Nov 2020 16:59:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B6D4386103F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606323542; bh=xsmBsocLvUdwchfyoZS3sls5ffUabs1Dsn5XeSPOeO0=; 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=aoK9nw+QxZQS0DgGpOYDQgLRlVrtoBHTRSVoauPBT8IJ+1/KmzaXwaOZNX/t2XTSe ifQDps8fut5frAk+5Ri1FuZTQ64PJv3+2hO2pPhsnvucE1kJIcqHbWyVfic/5QDtuw TdCkzImBWqNSmY1n5CJeF8rptIX5QH/j+UJwFqhc= Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by sourceware.org (Postfix) with ESMTPS id 64CBD3861826 for ; Wed, 25 Nov 2020 16:58:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 64CBD3861826 Received: by mail-qv1-xf41.google.com with SMTP id p12so1222742qvj.13 for ; Wed, 25 Nov 2020 08:58:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xsmBsocLvUdwchfyoZS3sls5ffUabs1Dsn5XeSPOeO0=; b=qSeprfWE1NdT6SvvKrnE12CYHXaLRmlgKxGY1nZnqrYdxzjjyRKkWSTtvUa6bCSrUz GkOa8YzSbJOnt9LVuSBu46gkj3fs/Cy5gOAR+svr5v9lixITnf8V4J3vGTVTfsqPtX7x bWxLuORC8G+cpXe5jQ0P64hYEWq06fnlYIHIdiAMwG6szJLm9iIxEXluv8G+bwdnHfTB Dy0x17cFkkxzXYfUGmzNHw12lwSJR2tiSSINza2T4222ojNsVahUWBrqR100AsMNqDmM LYM7JJ8WF8Cbr85U9Ln3B4FdKHHobWTdFykaIk5lf9/Sv3nlXDs7pcUVpq7+sqOPwnk8 7hpA== X-Gm-Message-State: AOAM530pGqoViQ95fkwkBUeAX8JV52dKQBOdqX+0CLUzbiqeH3g/ui48 D9osPLSzQpNKToxOl+++bPfJwXSVehJ+7Q== X-Google-Smtp-Source: ABdhPJwJ4xmGM7MGJ6Pa95f0UDXztkHl6R6H3RuuHNOmK/GsU6SjwiY09eRxX0IG8gzBX81R8IquaA== X-Received: by 2002:a0c:8e47:: with SMTP id w7mr4443494qvb.55.1606323538766; Wed, 25 Nov 2020 08:58:58 -0800 (PST) Received: from ?IPv6:2804:7f0:8284:370e:18fe:65d7:a5d3:1acf? ([2804:7f0:8284:370e:18fe:65d7:a5d3:1acf]) by smtp.gmail.com with ESMTPSA id b3sm2770793qte.85.2020.11.25.08.58.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Nov 2020 08:58:58 -0800 (PST) Subject: Re: [PATCH v2] 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> <20201119022708.3627287-1-sergiodj@sergiodj.net> Message-ID: <30b3b6b7-704c-acb8-01ca-b0db0f5704ba@linaro.org> Date: Wed, 25 Nov 2020 13:58:52 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201119022708.3627287-1-sergiodj@sergiodj.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US 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: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: Simon Marchi , Mark Wielaard Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi, I like the idea of GDB trying harder to find a particular file. Sometimes it is a bit frustrating to deal with GDB and hardcoded paths. With that said, the code is a bit confusing as-is, maybe because there is a lot of fiddling with the paths etc. I think putting the new code into a function with the appropriate name would help here. Your choice. In any case, it looks OK for me as-is. Just a nit below... On 11/18/20 11:27 PM, Sergio Durigan Junior via Gdb-patches wrote: > Changes from v1: > > - Addressed Simon's comments (new comment explaining how we try to > match for the current debug-file-directory; properly use > .erase/.insert methods -- keeping in mind that they modify the > string in-place). > > > 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. > > 2020-11-14 Sergio Durigan Junior > > * dwarf2/read.c (dwarf2_get_dwz_file): Convert 'filename' to a > std::string. Implement ability to search for DWZ files in the > debug-file-directories provided by the user as well. > --- > gdb/dwarf2/read.c | 73 +++++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 67 insertions(+), 6 deletions(-) > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 3c59826291..c462b9bb2c 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -2190,7 +2190,7 @@ locate_dwz_sections (bfd *abfd, asection *sectp, dwz_file *dwz_file) > struct dwz_file * > dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd) > { > - const char *filename; > + std::string filename; > bfd_size_type buildid_len_arg; > size_t buildid_len; > bfd_byte *buildid; > @@ -2216,19 +2216,17 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd) > > filename = data.get (); > > - std::string abs_storage; > - if (!IS_ABSOLUTE_PATH (filename)) > + if (!IS_ABSOLUTE_PATH (filename.c_str ())) > { > gdb::unique_xmalloc_ptr abs > = gdb_realpath (bfd_get_filename (per_bfd->obfd)); > > - abs_storage = ldirname (abs.get ()) + SLASH_STRING + filename; > - filename = abs_storage.c_str (); > + filename = ldirname (abs.get ()) + SLASH_STRING + filename; > } > > /* First try the file name given in the section. If that doesn't > work, try to use the build-id instead. */ > - gdb_bfd_ref_ptr dwz_bfd (gdb_bfd_open (filename, gnutarget)); > + gdb_bfd_ref_ptr dwz_bfd (gdb_bfd_open (filename.c_str (), gnutarget)); > if (dwz_bfd != NULL) > { > if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid)) > @@ -2238,6 +2236,69 @@ 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::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.dwz > + > + And suppose that we have "$HOME/bar" as the > + debug-file-directory. We would then adjust filename > + to look like: > + > + $HOME/bar/.dwz/foo.dwz > + > + which would hopefully allow us to find the alt debug > + file. */ > + std::string ddir = debugdir.get (); > + > + /* Check whether the beginning of FILENAME is DDIR. If > + it is, then we are dealing with a file which we > + already attempted to open before, so we just skip it > + and continue processing the reamining remaining? > + debug-file-directories. */ debug-file-directories doesn't exist in the code. I suppose this should be "debug file directories" or "debug-file-directory's"? > + if (filename.size () > ddir.size () > + && filename.compare (0, ddir.size (), ddir) == 0) > + continue; > + > + /* Replace FILENAME's default debug-file-directory with > + DDIR. */ > + std::string new_filename = filename; > + new_filename.erase (0, dwz_pos); > + new_filename.insert (0, ddir); > + > + dwz_bfd = gdb_bfd_open (new_filename.c_str (), gnutarget); > + > + if (dwz_bfd != nullptr) > + { > + if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid)) > + { > + dwz_bfd.reset (nullptr); > + continue; > + } > + /* Found it. */ > + break; > + } > + } > + } > + } > + > if (dwz_bfd == nullptr) > { > gdb::unique_xmalloc_ptr alt_filename; >