@@ -818,19 +818,6 @@ void ObjFile::initializeDependencies() {
818
818
debugTypesObj = makeTpiSource (ctx, this );
819
819
}
820
820
821
- // Make a PDB path assuming the PDB is in the same folder as the OBJ
822
- static std::string getPdbBaseName (ObjFile *file, StringRef tSPath) {
823
- StringRef localPath =
824
- !file->parentName .empty () ? file->parentName : file->getName ();
825
- SmallString<128 > path = sys::path::parent_path (localPath);
826
-
827
- // Currently, type server PDBs are only created by MSVC cl, which only runs
828
- // on Windows, so we can assume type server paths are Windows style.
829
- sys::path::append (path,
830
- sys::path::filename (tSPath, sys::path::Style::windows));
831
- return std::string (path);
832
- }
833
-
834
821
// The casing of the PDB path stamped in the OBJ can differ from the actual path
835
822
// on disk. With this, we ensure to always use lowercase as a key for the
836
823
// pdbInputFileInstances map, at least on Windows.
@@ -843,17 +830,35 @@ static std::string normalizePdbPath(StringRef path) {
843
830
}
844
831
845
832
// If existing, return the actual PDB path on disk.
846
- static std::optional<std::string> findPdbPath (StringRef pdbPath,
847
- ObjFile *dependentFile) {
833
+ static std::optional<std::string>
834
+ findPdbPath (StringRef pdbPath, ObjFile *dependentFile, StringRef outputPath ) {
848
835
// Ensure the file exists before anything else. In some cases, if the path
849
836
// points to a removable device, Driver::enqueuePath() would fail with an
850
837
// error (EAGAIN, "resource unavailable try again") which we want to skip
851
838
// silently.
852
839
if (llvm::sys::fs::exists (pdbPath))
853
840
return normalizePdbPath (pdbPath);
854
- std::string ret = getPdbBaseName (dependentFile, pdbPath);
855
- if (llvm::sys::fs::exists (ret))
856
- return normalizePdbPath (ret);
841
+
842
+ StringRef objPath = !dependentFile->parentName .empty ()
843
+ ? dependentFile->parentName
844
+ : dependentFile->getName ();
845
+
846
+ // Currently, type server PDBs are only created by MSVC cl, which only runs
847
+ // on Windows, so we can assume type server paths are Windows style.
848
+ StringRef pdbName = sys::path::filename (pdbPath, sys::path::Style::windows);
849
+
850
+ // Check if the PDB is in the same folder as the OBJ.
851
+ SmallString<128 > path;
852
+ sys::path::append (path, sys::path::parent_path (objPath), pdbName);
853
+ if (llvm::sys::fs::exists (path))
854
+ return normalizePdbPath (path);
855
+
856
+ // Check if the PDB is in the output folder.
857
+ path.clear ();
858
+ sys::path::append (path, sys::path::parent_path (outputPath), pdbName);
859
+ if (llvm::sys::fs::exists (path))
860
+ return normalizePdbPath (path);
861
+
857
862
return std::nullopt;
858
863
}
859
864
@@ -865,7 +870,7 @@ PDBInputFile::~PDBInputFile() = default;
865
870
PDBInputFile *PDBInputFile::findFromRecordPath (const COFFLinkerContext &ctx,
866
871
StringRef path,
867
872
ObjFile *fromFile) {
868
- auto p = findPdbPath (path.str (), fromFile);
873
+ auto p = findPdbPath (path.str (), fromFile, ctx. config . outputFile );
869
874
if (!p)
870
875
return nullptr ;
871
876
auto it = ctx.pdbInputFileInstances .find (*p);
@@ -931,7 +936,7 @@ std::optional<DILineInfo> ObjFile::getDILineInfo(uint32_t offset,
931
936
}
932
937
933
938
void ObjFile::enqueuePdbFile (StringRef path, ObjFile *fromFile) {
934
- auto p = findPdbPath (path.str (), fromFile);
939
+ auto p = findPdbPath (path.str (), fromFile, ctx. config . outputFile );
935
940
if (!p)
936
941
return ;
937
942
auto it = ctx.pdbInputFileInstances .emplace (*p, nullptr );
0 commit comments