Skip to content

Commit 8d03cb7

Browse files
committed
Record parseable interface imports in the debug info.
When a Swift module built with debug info imports a library without debug info from a textual interface, the textual interface is necessary to reconstruct types defined in the library's interface. By recording the Swift interface files in DWARF dsymutil can collect them and LLDB can find them. rdar://problem/49751363
1 parent c4626ba commit 8d03cb7

File tree

13 files changed

+77
-10
lines changed

13 files changed

+77
-10
lines changed

include/swift/AST/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,10 @@ class FileUnit : public DeclContext {
827827
return getParentModule()->getName().str();
828828
}
829829

830+
/// If this is a module imported from a parseable interface, return the path
831+
/// to the interface file, otherwise an empty StringRef.
832+
virtual StringRef getParseableInterface() const { return {}; }
833+
830834
/// Traverse the decls within this file.
831835
///
832836
/// \returns true if traversal was aborted, false if it completed

include/swift/Serialization/ModuleFormat.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,8 @@ namespace input_block {
643643
IMPORTED_HEADER_CONTENTS,
644644
MODULE_FLAGS, // [unused]
645645
SEARCH_PATH,
646-
FILE_DEPENDENCY
646+
FILE_DEPENDENCY,
647+
PARSEABLE_INTERFACE_PATH
647648
};
648649

649650
using ImportedModuleLayout = BCRecordLayout<
@@ -690,6 +691,12 @@ namespace input_block {
690691
BCFixed<1>, // SDK-relative?
691692
BCBlob // path
692693
>;
694+
695+
using ParseableInterfaceLayout = BCRecordLayout<
696+
PARSEABLE_INTERFACE_PATH,
697+
BCBlob // file path
698+
>;
699+
693700
}
694701

695702
/// The record types within the "decls-and-types" block.

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace swift {
3333
StringRef GroupInfoPath;
3434
StringRef ImportedHeader;
3535
StringRef ModuleLinkName;
36+
StringRef ParseableInterface;
3637
ArrayRef<std::string> ExtraClangOptions;
3738

3839
/// Describes a single-file dependency for this module, along with the

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ class SerializedASTFile final : public LoadedFile {
186186
friend class ModuleFile;
187187

188188
ModuleFile &File;
189+
190+
/// The parseable interface this module was generated from if any.
191+
/// Used for debug info.
192+
std::string ParseableInterface;
193+
189194
bool IsSIB;
190195

191196
~SerializedASTFile() = default;
@@ -277,6 +282,13 @@ class SerializedASTFile final : public LoadedFile {
277282

278283
virtual const clang::Module *getUnderlyingClangModule() const override;
279284

285+
/// If this is a module imported from a parseable interface, return the path
286+
/// to the interface file, otherwise an empty StringRef.
287+
virtual StringRef getParseableInterface() const override {
288+
return ParseableInterface;
289+
}
290+
void setParseableInterface(StringRef PI) { ParseableInterface = PI; }
291+
280292
virtual bool getAllGenericSignatures(
281293
SmallVectorImpl<GenericSignature*> &genericSignatures)
282294
override;

include/swift/Serialization/Validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct ValidationInfo {
9292
class ExtendedValidationInfo {
9393
SmallVector<StringRef, 4> ExtraClangImporterOpts;
9494
StringRef SDKPath;
95+
StringRef ParseableInterface;
9596
struct {
9697
unsigned ArePrivateImportsEnabled : 1;
9798
unsigned IsSIB : 1;
@@ -113,6 +114,8 @@ class ExtendedValidationInfo {
113114
void addExtraClangImporterOption(StringRef option) {
114115
ExtraClangImporterOpts.push_back(option);
115116
}
117+
StringRef getParseableInterface() const { return ParseableInterface; }
118+
void setParseableInterface(StringRef PI) { ParseableInterface = PI; }
116119

117120
bool isSIB() const { return Bits.IsSIB; }
118121
void setIsSIB(bool val) {

lib/AST/Module.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,10 @@ StringRef ModuleDecl::getModuleFilename() const {
11341134
// per-file names. Modules can consist of more than one file.
11351135
StringRef Result;
11361136
for (auto F : getFiles()) {
1137+
Result = F->getParseableInterface();
1138+
if (!Result.empty())
1139+
return Result;
1140+
11371141
if (auto SF = dyn_cast<SourceFile>(F)) {
11381142
if (!Result.empty())
11391143
return StringRef();

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ CompilerInvocation::getParseableInterfaceOutputPathForWholeModule() const {
124124
.SupplementaryOutputs.ParseableInterfaceOutputPath;
125125
}
126126

127-
SerializationOptions
128-
CompilerInvocation::computeSerializationOptions(const SupplementaryOutputPaths &outs,
129-
bool moduleIsPublic) {
127+
SerializationOptions CompilerInvocation::computeSerializationOptions(
128+
const SupplementaryOutputPaths &outs, bool moduleIsPublic) {
130129
const FrontendOptions &opts = getFrontendOptions();
131130

132131
SerializationOptions serializationOpts;

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,12 @@ class swift::ParseableInterfaceBuilder {
582582
std::string OutPathStr = OutPath;
583583
SerializationOpts.OutputPath = OutPathStr.c_str();
584584
SerializationOpts.ModuleLinkName = FEOpts.ModuleLinkName;
585+
586+
// Record any non-SDK parseable interface files for the debug info.
587+
StringRef SDKPath = SubInstance.getASTContext().SearchPathOpts.SDKPath;
588+
if (!getRelativeDepPath(InPath, SDKPath))
589+
SerializationOpts.ParseableInterface = InPath;
590+
585591
SmallVector<FileDependency, 16> Deps;
586592
if (collectDepsForSerialization(SubInstance, Deps,
587593
FEOpts.SerializeParseableModuleInterfaceDependencyHashes)) {

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
191191

192192
private:
193193
static StringRef getFilenameFromDC(const DeclContext *DC) {
194-
if (auto LF = dyn_cast<LoadedFile>(DC))
194+
if (auto *LF = dyn_cast<LoadedFile>(DC))
195195
return LF->getFilename();
196-
if (auto SF = dyn_cast<SourceFile>(DC))
196+
if (auto *SF = dyn_cast<SourceFile>(DC))
197197
return SF->getFilename();
198-
else if (auto M = dyn_cast<ModuleDecl>(DC))
198+
if (auto *M = dyn_cast<ModuleDecl>(DC))
199199
return M->getModuleFilename();
200-
else
201-
return StringRef();
200+
return {};
202201
}
203202

204203
using DebugLoc = SILLocation::DebugLoc;
@@ -717,7 +716,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
717716
ModuleDecl *M = IM.second;
718717
if (Optional<ASTSourceDescriptor> ModuleDesc = getClangModule(*M))
719718
return getOrCreateModule(*ModuleDesc, ModuleDesc->getModuleOrNull());
720-
721719
StringRef Path = getFilenameFromDC(M);
722720
StringRef Name = M->getName().str();
723721
return getOrCreateModule(M, TheCU, Name, Path);

lib/Serialization/ModuleFile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,11 @@ ModuleFile::ModuleFile(
13321332
SearchPaths.push_back({blobData, isFramework, isSystem});
13331333
break;
13341334
}
1335+
case input_block::PARSEABLE_INTERFACE_PATH: {
1336+
if (extInfo)
1337+
extInfo->setParseableInterface(blobData);
1338+
break;
1339+
}
13351340
default:
13361341
// Unknown input kind, possibly for use by a future version of the
13371342
// module format.

0 commit comments

Comments
 (0)