From patchwork Wed Mar 6 10:06:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: LRN X-Patchwork-Id: 31727 Received: (qmail 90781 invoked by alias); 6 Mar 2019 10:06:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 90689 invoked by uid 89); 6 Mar 2019 10:06:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: =?ISO-8859-1?Q?No, score=-22.6 required=5.0 tests=BAYES_00, BODY_8BITS, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GARBLED_BODY, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy==d0=be=d0=b2, 06032019, 06.03.2019, H*RU:sk:broadba?= X-HELO: mail-lj1-f194.google.com Received: from mail-lj1-f194.google.com (HELO mail-lj1-f194.google.com) (209.85.208.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Mar 2019 10:06:12 +0000 Received: by mail-lj1-f194.google.com with SMTP id z7so10344639lji.0 for ; Wed, 06 Mar 2019 02:06:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:references:from:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to; bh=swfdkFvQMYEIddqsliMOQFcrjpXUCYtwkv0H1qu8Oio=; b=sOC2+gnDiYHidT77UibaZZu0g0/so7PCice6DbFAhgJMIFciyr85viitWNmuQsBHqW 8OYC/hkQJpO9i+byBZVXGzk/uiVXG8qCAFP3Cb964bUF1AJXX7WRkGP9mxCNI/15oAw/ 6rvOszt7HO/CipZD5flGjiXVxpldtWbQ9gj98PQZ9K1y5igjpHnxs4iYpprpp3G/wlUg KWzwXzpmKcj2rCUGZP/LKZN3EpT/5oEe42gfgNOq/wE+aaZEnZy8yHWDR/dBcBN5b8Fx 6L3nWZHcASTbAYTXW2KUXcLbYbsgelK5DytTTEVJHLxCnlEAd8THHlscQmDFPFeGziyH J+oA== Return-Path: Received: from [192.168.4.39] (broadband-95-84-200-6.ip.moscow.rt.ru. [95.84.200.6]) by smtp.gmail.com with ESMTPSA id z4sm242771ljz.43.2019.03.06.02.06.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 02:06:07 -0800 (PST) To: gdb-patches@sourceware.org References: <5a785bba-7432-f6e0-1089-5d2bdd3450a3@gmail.com> <871s3lq8fy.fsf@tromey.com> From: LRN Subject: Re: [PATCH] Apply substitute-path to relative filenames as well Message-ID: <97a68efd-1c71-000d-88eb-7bbec121f36e@gmail.com> Date: Wed, 6 Mar 2019 13:06:00 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <871s3lq8fy.fsf@tromey.com> X-IsSubscribed: yes On 06.03.2019 1:10, Tom Tromey wrote: > LRN writes: >> 2019-02-28 Руслан Ижбулатов >> >> * source.c (find_and_open_source): Apply substitute-path to all >> filenames, both absolute and relative > > Is it possible to get a test case for the patch? No. I couldn't find a gdb testcase for the substitute-path feature (there's one that checks issuing the `set substitute-path` command itself, but it doesn't seem to be testing its *runtime effect*, i.e. how it is applied when gdb needs to read a source file), so i can't provide a test case for this change by modifying an existing one. That means i'd have to write one from scratch, and i wouldn't know how to even begin to do that. Also, running gdb testsuite requires dejagnu, which i don't have (and by "i don't have" i mean "i've never built it from the source", as this is how i get 90% of all my dev software). It should technically be possible for me to build it, but that'll take time that i would rather spend on other things. >> gdb::unique_xmalloc_ptr rewritten_filename; > [...] >> + rewritten_filename = rewrite_source_path (filename); > > I think these two lines can now be joined; no need to have a separate > assignment. > New version of the patch is attached. From 74ec81cb519c331d8b10d419eefa2a599fac2f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Thu, 28 Feb 2019 10:25:41 +0000 Subject: [PATCH] Apply substitute-path to relative filenames as well When source file path is relative to the build directory (which is considered a good practice and is enforced in certain buildsystems, such as meson), gdb only applies substitute-path to the build directory path. Then gdb appends the source file path to the rewritten build directory path, and tries to access that. This fails if either two of the following conditions are true: a) The user didn't specify substitute-path for the build directory. This is highly likely, since path substitution for build directories is not documented anywhere, and since gdb does not tell[0] the user the path to the build directory, just the source file path. b) The source file path changed. This can also easily happen, since a source path that is relative to the build directory can include any number of directory names that are not part of the program source tree (starting with the name of the root directory of the source tree). Gdb will not apply substitute-path to that relative path, thus there is no way for the user to tell gdb about these changes. This commit changes the code to apply substitute-path to all filenames, both relative and absolute. This way it is possible to do things like: set substitute-path ../foobar-1.0 /src/my/foobar-1.0 which is completely in line with the user expectations. This might break unusual cases where build directory path is also relative (is that even possible?) and happens to match the path to the source directory (i.e. happens to match a substitution rule). [0]: There's a "maintenance info symtabs" command that does show the names of the build directories, but normal users are not required to know or use that. --- gdb/source.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/gdb/source.c b/gdb/source.c index f99215f..3fc7717 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1027,16 +1027,10 @@ find_and_open_source (const char *filename, } } - gdb::unique_xmalloc_ptr rewritten_filename; - if (IS_ABSOLUTE_PATH (filename)) - { - /* If filename is absolute path, try the source path - substitution on it. */ - rewritten_filename = rewrite_source_path (filename); + gdb::unique_xmalloc_ptr rewritten_filename = rewrite_source_path (filename); - if (rewritten_filename != NULL) - filename = rewritten_filename.get (); - } + if (rewritten_filename != NULL) + filename = rewritten_filename.get (); result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename, OPEN_MODE, fullname);