Apply substitute-path rules to relative filenames

Message ID 58b1109863f72_3d472af4edac70d0358b9@davida2.mail
State New, archived
Headers

Commit Message

David Grayson Feb. 25, 2017, 5:05 a.m. UTC
  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 <davidegrayson@gmail.com>

	* gdb/source.c: Apply substitute-path rules to all source
	filenames, not just absolute source filenames and compilation
	directory names.
  

Patch

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)