From patchwork Sat Feb 25 05:05:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Grayson X-Patchwork-Id: 19381 Received: (qmail 80177 invoked by alias); 25 Feb 2017 05:06:11 -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 79913 invoked by uid 89); 25 Feb 2017 05:05:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=five, learn X-HELO: mail-pg0-f45.google.com Received: from mail-pg0-f45.google.com (HELO mail-pg0-f45.google.com) (74.125.83.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 25 Feb 2017 05:05:32 +0000 Received: by mail-pg0-f45.google.com with SMTP id 1so19881509pgi.1 for ; Fri, 24 Feb 2017 21:05:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:message-id:subject :mime-version:content-transfer-encoding; bh=LnlVfqPj80ly8kUoBHDirRNVowT7ItoHt3Ht7+gHqOI=; b=TN1B4ldGYUuRqKq9CQKmCy6U8IkLu6QdcpVT5h+/v2NluP6IMDeEGYgaEaHUklgVa/ DInuZq8cn+YOV/iNnP2cVPYURfBIGg/nJoj7tMXColI/HJy+vSBa4SqMqMvIeOe2s9I8 sX1DbBK4H1QZcBVMLKUCSVX26gdcntXidQadCSRRL0XThXS1w+RSCS7OQtSHyuWxHRFt Q3fZUISfNrm2EGQaBZMtYIpXY0wz7mW1uYrtkjCubG7dY3wFi9wpryvrqK131ySWWaBf RoNcV7RpjFSmiadqts+5AkNmBctsWE6AAtmSvs0rA0vxdP5EZ1C/twiqHCUk1pg2znKJ /zTQ== X-Gm-Message-State: AMke39km1Lhwm3fm5zp9gD5X6gEJWU0b4AEGB/xlinfxGHSm7wVYaqXKq7MJcqwaO7JMEQ== X-Received: by 10.99.112.75 with SMTP id a11mr8033506pgn.7.1487999131070; Fri, 24 Feb 2017 21:05:31 -0800 (PST) Received: from davida2 (wsip-98-180-230-141.lv.lv.cox.net. [98.180.230.141]) by smtp.gmail.com with ESMTPSA id 4sm630998pfr.124.2017.02.24.21.05.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 21:05:30 -0800 (PST) Date: Fri, 24 Feb 2017 21:05:28 -0800 From: David Grayson To: gdb-patches@sourceware.org Message-ID: <58b1109863f72_3d472af4edac70d0358b9@davida2.mail> Subject: [PATCH] Apply substitute-path rules to relative filenames Mime-Version: 1.0 X-IsSubscribed: yes Hello. I am attaching a patch to gdb/source.c that makes the substitute-path rules apply to all source filenames, instead of only absolute source filenames and compilation directory names. I hope it will be considered for the next verison of GDB. ==== Motivation for the change ==== I am trying to debug a Windows program that I cross-compiled from Linux and I want GDB to find my source files when I run it. The error message from (unpatched) GDB was: ../samples/hello_triangle/HelloTriangle.cpp: No such file or directory. Based on my reading of the documentation[1], I expected that I could fix this by adding the following substitute-path rule: set substitute-path ../samples src/angle/samples However, that did not change the error message. When find_and_open_source in gdb/source.c is called, the filename argument is "../samples/hello_triangle/HelloTriangle.cpp" (equal to the filename argument I passed to GCC), while the "dirname" argument is "/home/david/tmp/nix-build-angle_samples-2017-02-17-i686-w64-mingw32.drv-0/build (equal to the CWD when I invoked GCC). Since the "dirname" is long and complicated, I would rather not have to use it in my substitute-path rule. Instead, I would like substitute-path rules to apply to source filenames even if they are relative. After applying this patch, GDB was able to successfully find my source file. ==== Testing ==== I have manually tested that this patch fixes my particular issue. I ran "make check" on a native Linux GDB built from the current git revision. I am not sure how to make sense of the test suite results, and thought it wasn't too important to learn about that, but please let me know if you want me to do something more to test this patch. ==== Context ==== The code for applying substitute-path rules to absolute source filenames was added on 2008-02-08 and discussed here: https://sourceware.org/ml/gdb-patches/2008-02/subjects.html#00130 In the discussion, there was no reason given to only apply the substitution rules to absolute filenames. I also searched the last five years of discussions on this mailing list and I don't think the issue came up (sorry if it did). Thanks! --David Grayson [1]: https://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html 2017-02-24 David Grayson * gdb/source.c: Apply substitute-path rules to all source filenames, not just absolute source filenames and compilation directory names. diff -ur gdb-7.12.1-orig/gdb/source.c gdb-7.12.1/gdb/source.c --- gdb-7.12.1-orig/gdb/source.c 2017-02-24 19:33:13.340349333 -0800 +++ gdb-7.12.1/gdb/source.c 2017-02-24 19:34:40.660349333 -0800 @@ -1103,10 +1103,7 @@ } } - if (IS_ABSOLUTE_PATH (filename)) { - /* If filename is absolute path, try the source path - substitution on it. */ char *rewritten_filename = rewrite_source_path (filename); if (rewritten_filename != NULL)