Skip to content

Commit 7ec84db

Browse files
committed
Merging r353250:
------------------------------------------------------------------------ r353250 | zturner | 2019-02-06 01:50:35 +0100 (Wed, 06 Feb 2019) | 24 lines [PDB] Remove dots and normalize slashes with /PDBSOURCEPATH. In a previous patch, I made changes so that PDBs which were generated on non-Windows platforms contained sensical paths for the host. While this is an esoteric use case, we need it to be supported for certain cross compilation scenarios especially with LLDB, which can debug things on non-Windows platforms. However, this regressed a case where you specify /PDBSOURCEPATH and use a windows-style path. Previously, we would still remove dots and canonicalize slashes to backslashes, but since my change intentionally tried to support non-backslash paths, this was broken. This patch fixes the situation by trying to guess which path style the user is specifying when /PDBSOURCEPATH is passed. It is intentionally conservative, erring on the side of a Windows path style unless absolutely certain. All dots are removed and slashes canonicalized to whatever the deduced path style is after appending the file path to the /PDBSOURCEPATH argument. Differential Revision: https://reviews.llvm.org/D57769 ------------------------------------------------------------------------ llvm-svn: 353300
1 parent a2f4603 commit 7ec84db

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

lld/COFF/PDB.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,24 @@ static void pdbMakeAbsolute(SmallVectorImpl<char> &FileName) {
288288
// It's not absolute in any path syntax. Relative paths necessarily refer to
289289
// the local file system, so we can make it native without ending up with a
290290
// nonsensical path.
291-
sys::path::native(FileName);
292291
if (Config->PDBSourcePath.empty()) {
292+
sys::path::native(FileName);
293293
sys::fs::make_absolute(FileName);
294294
return;
295295
}
296-
// Only apply native and dot removal to the relative file path. We want to
297-
// leave the path the user specified untouched since we assume they specified
298-
// it for a reason.
299-
sys::path::remove_dots(FileName, /*remove_dot_dots=*/true);
300296

297+
// Try to guess whether /PDBSOURCEPATH is a unix path or a windows path.
298+
// Since PDB's are more of a Windows thing, we make this conservative and only
299+
// decide that it's a unix path if we're fairly certain. Specifically, if
300+
// it starts with a forward slash.
301301
SmallString<128> AbsoluteFileName = Config->PDBSourcePath;
302-
sys::path::append(AbsoluteFileName, FileName);
302+
sys::path::Style GuessedStyle = AbsoluteFileName.startswith("/")
303+
? sys::path::Style::posix
304+
: sys::path::Style::windows;
305+
sys::path::append(AbsoluteFileName, GuessedStyle, FileName);
306+
sys::path::native(AbsoluteFileName, GuessedStyle);
307+
sys::path::remove_dots(AbsoluteFileName, true, GuessedStyle);
308+
303309
FileName = std::move(AbsoluteFileName);
304310
}
305311

lld/test/COFF/pdb-relative-source-lines.test

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,69 +37,69 @@ RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=line
3737
RUN: ./lld-link -debug "-pdbsourcepath:/usr/src" -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
3838
RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=POSIX %s
3939

40-
CHECK-LABEL: - Module: 'c:\src{{[\\/]}}pdb_lines_1_relative.obj'
41-
CHECK-NEXT: ObjFile: 'c:\src{{[\\/]}}pdb_lines_1_relative.obj'
40+
CHECK-LABEL: - Module: 'c:\src\pdb_lines_1_relative.obj'
41+
CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_1_relative.obj'
4242
CHECK: SourceFiles:
43-
CHECK-NEXT: - 'c:\src{{[\\/]}}pdb_lines_1.c'
44-
CHECK-NEXT: - 'c:\src{{[\\/]}}foo.h'
43+
CHECK-NEXT: - 'c:\src\pdb_lines_1.c'
44+
CHECK-NEXT: - 'c:\src\foo.h'
4545
CHECK: Subsections:
46-
CHECK: - FileName: 'c:\src{{[\\/]}}pdb_lines_1.c'
47-
CHECK: - FileName: 'c:\src{{[\\/]}}foo.h'
46+
CHECK: - FileName: 'c:\src\pdb_lines_1.c'
47+
CHECK: - FileName: 'c:\src\foo.h'
4848
CHECK: - !FileChecksums
49-
CHECK: - FileName: 'c:\src{{[\\/]}}pdb_lines_1.c'
50-
CHECK: - FileName: 'c:\src{{[\\/]}}foo.h'
49+
CHECK: - FileName: 'c:\src\pdb_lines_1.c'
50+
CHECK: - FileName: 'c:\src\foo.h'
5151

52-
CHECK-LABEL: - Module: 'c:\src{{[\\/]}}pdb_lines_2_relative.obj'
53-
CHECK-NEXT: ObjFile: 'c:\src{{[\\/]}}pdb_lines_2_relative.obj'
52+
CHECK-LABEL: - Module: 'c:\src\pdb_lines_2_relative.obj'
53+
CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_2_relative.obj'
5454
CHECK: SourceFiles:
55-
CHECK-NEXT: - 'c:\src{{[\\/]}}pdb_lines_2.c'
55+
CHECK-NEXT: - 'c:\src\pdb_lines_2.c'
5656
CHECK: Subsections:
57-
CHECK: - FileName: 'c:\src{{[\\/]}}pdb_lines_2.c'
57+
CHECK: - FileName: 'c:\src\pdb_lines_2.c'
5858
CHECK: - !FileChecksums
59-
CHECK: - FileName: 'c:\src{{[\\/]}}pdb_lines_2.c'
59+
CHECK: - FileName: 'c:\src\pdb_lines_2.c'
6060

6161
CHECK-LABEL: - Kind: S_ENVBLOCK
6262
CHECK-NEXT: EnvBlockSym:
6363
CHECK-NEXT: Entries:
6464
CHECK-NEXT: - cwd
6565
CHECK-NEXT: - 'c:\src'
6666
CHECK-NEXT: - exe
67-
CHECK-NEXT: - 'c:\src{{[\\/]}}lld-link'
67+
CHECK-NEXT: - 'c:\src\lld-link'
6868
CHECK-NEXT: - pdb
69-
CHECK-NEXT: - 'c:\src{{[\\/]}}out.pdb'
69+
CHECK-NEXT: - 'c:\src\out.pdb'
7070
CHECK-NEXT: - cmd
7171
CHECK-NEXT: - '-debug -pdbsourcepath:c:\src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'
7272

7373

74-
POSIX-LABEL: - Module: '/usr/src{{[\\/]}}pdb_lines_1_relative.obj'
75-
POSIX-NEXT: ObjFile: '/usr/src{{[\\/]}}pdb_lines_1_relative.obj'
74+
POSIX-LABEL: - Module: '/usr/src/pdb_lines_1_relative.obj'
75+
POSIX-NEXT: ObjFile: '/usr/src/pdb_lines_1_relative.obj'
7676
POSIX: SourceFiles:
77-
POSIX-NEXT: - '/usr/src{{[\\/]}}pdb_lines_1.c'
78-
POSIX-NEXT: - '/usr/src{{[\\/]}}foo.h'
77+
POSIX-NEXT: - '/usr/src/pdb_lines_1.c'
78+
POSIX-NEXT: - '/usr/src/foo.h'
7979
POSIX: Subsections:
80-
POSIX: - FileName: '/usr/src{{[\\/]}}pdb_lines_1.c'
81-
POSIX: - FileName: '/usr/src{{[\\/]}}foo.h'
80+
POSIX: - FileName: '/usr/src/pdb_lines_1.c'
81+
POSIX: - FileName: '/usr/src/foo.h'
8282
POSIX: - !FileChecksums
83-
POSIX: - FileName: '/usr/src{{[\\/]}}pdb_lines_1.c'
84-
POSIX: - FileName: '/usr/src{{[\\/]}}foo.h'
83+
POSIX: - FileName: '/usr/src/pdb_lines_1.c'
84+
POSIX: - FileName: '/usr/src/foo.h'
8585

86-
POSIX-LABEL: - Module: '/usr/src{{[\\/]}}pdb_lines_2_relative.obj'
87-
POSIX-NEXT: ObjFile: '/usr/src{{[\\/]}}pdb_lines_2_relative.obj'
86+
POSIX-LABEL: - Module: '/usr/src/pdb_lines_2_relative.obj'
87+
POSIX-NEXT: ObjFile: '/usr/src/pdb_lines_2_relative.obj'
8888
POSIX: SourceFiles:
89-
POSIX-NEXT: - '/usr/src{{[\\/]}}pdb_lines_2.c'
89+
POSIX-NEXT: - '/usr/src/pdb_lines_2.c'
9090
POSIX: Subsections:
91-
POSIX: - FileName: '/usr/src{{[\\/]}}pdb_lines_2.c'
91+
POSIX: - FileName: '/usr/src/pdb_lines_2.c'
9292
POSIX: - !FileChecksums
93-
POSIX: - FileName: '/usr/src{{[\\/]}}pdb_lines_2.c'
93+
POSIX: - FileName: '/usr/src/pdb_lines_2.c'
9494

9595
POSIX-LABEL: - Kind: S_ENVBLOCK
9696
POSIX-NEXT: EnvBlockSym:
9797
POSIX-NEXT: Entries:
9898
POSIX-NEXT: - cwd
9999
POSIX-NEXT: - '/usr/src'
100100
POSIX-NEXT: - exe
101-
POSIX-NEXT: - '/usr/src{{[\\/]}}lld-link'
101+
POSIX-NEXT: - '/usr/src/lld-link'
102102
POSIX-NEXT: - pdb
103-
POSIX-NEXT: - '/usr/src{{[\\/]}}out.pdb'
103+
POSIX-NEXT: - '/usr/src/out.pdb'
104104
POSIX-NEXT: - cmd
105105
POSIX-NEXT: - '-debug -pdbsourcepath:/usr/src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'

0 commit comments

Comments
 (0)