[RFC] Apply compilation dir to source_path lookup

Eli Zaretskii eliz@gnu.org
Sat Sep 14 07:11:00 GMT 2019


> From: Mike Gulick <mgulick@mathworks.com>
> CC: Mike Gulick <mgulick@mathworks.com>, "gdb-patches@sourceware.org"
> 	<gdb-patches@sourceware.org>
> Date: Fri, 13 Sep 2019 22:52:19 +0000
> 
> The only way this would be a problem is if both the compilation
> directory and the source file contained a drive letter.

Are you sure this is the only problematic use case?

Does GDB even try to prepend any directories to a source file whose
name is absolute and includes a drive letter?  If it does, is that
TRT?

> I had assumed that if the debug information contained a compilation
> directory, then the file path would be relative to that.  GCC at
> least seems to behave this way.
> 
> [mgulick@mgulick-deb9-64:~/test/src] ...
> $ gcc -g -o test.o -fdebug-prefix-map=$HOME= -c test.c
> [mgulick@mgulick-deb9-64:~/test/src] ...
> $ dwarfdump test.o
> ...
>                     DW_AT_name                  test.c
>                     DW_AT_comp_dir              /test/src
> ...
> 
> [mgulick@mgulick-deb9-64:~/test/src] ...
> $ gcc -g -o test.o -fdebug-prefix-map=$HOME= -c `pwd`/test.c
> [mgulick@mgulick-deb9-64:~/test/src] ...
> $ dwarfdump test.o
> ...
>                     DW_AT_name                  /test/src/test.c
> ...
> 
> In this case there is no DW_AT_comp_dir present.

That's not exactly what I see on Windows (but note that I used -g3):

D:\usr\eli\data>gcc -g3 -c -o test.o d:/usr/eli/data/test.c
D:\usr\eli\data>objdump --dwarf test.o
...
    <3a>   DW_AT_name        : d:/usr/eli/data/test.c
    <51>   DW_AT_comp_dir    : D:\usr\eli\data

D:\usr\eli\data>gcc -g3 -c -o test.o -fdebug-prefix-map=D:\usr= d:/usr/eli/data/test.c
D:\usr\eli\data>objdump --dwarf test.o
...
    <3a>   DW_AT_name        : /eli/data/test.c
    <4b>   DW_AT_comp_dir    : \eli\data

> If you are concerned about this (possibly some crazy compiler emitting
> strange dwarf), the following change should suffice:

I'm not familiar with the code enough to be sure, but how do we
convince ourselves that removing one of the several drive letters and
doing nothing else is TRT in this case?  Maybe we should prepend that
drive letter to the complete file name we produce?

Thanks.



More information about the Gdb-patches mailing list