Skip to content

Commit 7368d40

Browse files
adrian-prantlmemfrob
authored andcommitted
Add debug info support for Swift/Clang APINotes.
In order for dsymutil to collect .apinotes files (which capture attributes such as nullability, Swift import names, and availability), I want to propose adding an apinotes: field to DIModule that gets translated into a DW_AT_LLVM_apinotes (path) nested inside DW_TAG_module. This will be primarily used by LLDB to indirectly extract the Swift names of Clang declarations that were deserialized from DWARF. <rdar://problem/59514626> Differential Revision: https://reviews.llvm.org/D75585
1 parent f07eedc commit 7368d40

File tree

16 files changed

+88
-43
lines changed

16 files changed

+88
-43
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,15 @@ LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
288288
* \param ConfigMacrosLen The length of the C string passed to \c ConfigMacros.
289289
* \param IncludePath The path to the module map file.
290290
* \param IncludePathLen The length of the C string passed to \c IncludePath.
291+
* \param APINotesFile The path to an API notes file for the module.
292+
* \param APINotesFileLen The length of the C string passed to \c APINotestFile.
291293
*/
292294
LLVMMetadataRef
293295
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
294296
const char *Name, size_t NameLen,
295297
const char *ConfigMacros, size_t ConfigMacrosLen,
296-
const char *IncludePath, size_t IncludePathLen);
298+
const char *IncludePath, size_t IncludePathLen,
299+
const char *APINotestFile, size_t APINotestFileLen);
297300

298301
/**
299302
* Creates a new descriptor for a namespace with the specified parent scope.

llvm/include/llvm/BinaryFormat/Dwarf.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ HANDLE_DW_AT(0x3e00, LLVM_include_path, 0, LLVM)
412412
HANDLE_DW_AT(0x3e01, LLVM_config_macros, 0, LLVM)
413413
HANDLE_DW_AT(0x3e02, LLVM_sysroot, 0, LLVM)
414414
HANDLE_DW_AT(0x3e03, LLVM_tag_offset, 0, LLVM)
415+
// The missing numbers here are reserved for ptrauth support.
416+
HANDLE_DW_AT(0x3e07, LLVM_apinotes, 0, APPLE)
417+
415418
// Apple extensions.
419+
416420
HANDLE_DW_AT(0x3fe1, APPLE_optimized, 0, APPLE)
417421
HANDLE_DW_AT(0x3fe2, APPLE_flags, 0, APPLE)
418422
HANDLE_DW_AT(0x3fe3, APPLE_isa, 0, APPLE)

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,10 @@ namespace llvm {
741741
/// A space-separated shell-quoted list of -D macro
742742
/// definitions as they would appear on a command line.
743743
/// \param IncludePath The path to the module map file.
744+
/// \param APINotesFile The path to an API notes file for this module.
744745
DIModule *createModule(DIScope *Scope, StringRef Name,
745746
StringRef ConfigurationMacros,
746-
StringRef IncludePath);
747+
StringRef IncludePath, StringRef APINotesFile = {});
747748

748749
/// This creates a descriptor for a lexical block with a new file
749750
/// attached. This merely extends the existing

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,43 +2089,52 @@ class DIModule : public DIScope {
20892089

20902090
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
20912091
StringRef ConfigurationMacros, StringRef IncludePath,
2092-
StorageType Storage, bool ShouldCreate = true) {
2092+
StringRef APINotesFile, StorageType Storage,
2093+
bool ShouldCreate = true) {
20932094
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
20942095
getCanonicalMDString(Context, ConfigurationMacros),
20952096
getCanonicalMDString(Context, IncludePath),
2097+
getCanonicalMDString(Context, APINotesFile),
20962098
Storage, ShouldCreate);
20972099
}
20982100
static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
20992101
MDString *Name, MDString *ConfigurationMacros,
2100-
MDString *IncludePath, StorageType Storage,
2101-
bool ShouldCreate = true);
2102+
MDString *IncludePath, MDString *APINotesFile,
2103+
StorageType Storage, bool ShouldCreate = true);
21022104

21032105
TempDIModule cloneImpl() const {
21042106
return getTemporary(getContext(), getScope(), getName(),
2105-
getConfigurationMacros(), getIncludePath());
2107+
getConfigurationMacros(), getIncludePath(),
2108+
getAPINotesFile());
21062109
}
21072110

21082111
public:
21092112
DEFINE_MDNODE_GET(DIModule,
21102113
(DIScope * Scope, StringRef Name,
2111-
StringRef ConfigurationMacros, StringRef IncludePath),
2112-
(Scope, Name, ConfigurationMacros, IncludePath))
2114+
StringRef ConfigurationMacros, StringRef IncludePath,
2115+
StringRef APINotesFile),
2116+
(Scope, Name, ConfigurationMacros, IncludePath,
2117+
APINotesFile))
21132118
DEFINE_MDNODE_GET(DIModule,
2114-
(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
2115-
MDString *IncludePath),
2116-
(Scope, Name, ConfigurationMacros, IncludePath))
2119+
(Metadata * Scope, MDString *Name,
2120+
MDString *ConfigurationMacros, MDString *IncludePath,
2121+
MDString *APINotesFile),
2122+
(Scope, Name, ConfigurationMacros, IncludePath,
2123+
APINotesFile))
21172124

21182125
TempDIModule clone() const { return cloneImpl(); }
21192126

21202127
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
21212128
StringRef getName() const { return getStringOperand(1); }
21222129
StringRef getConfigurationMacros() const { return getStringOperand(2); }
21232130
StringRef getIncludePath() const { return getStringOperand(3); }
2131+
StringRef getAPINotesFile() const { return getStringOperand(4); }
21242132

21252133
Metadata *getRawScope() const { return getOperand(0); }
21262134
MDString *getRawName() const { return getOperandAs<MDString>(1); }
21272135
MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
21282136
MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
2137+
MDString *getRawAPINotesFile() const { return getOperandAs<MDString>(4); }
21292138

21302139
static bool classof(const Metadata *MD) {
21312140
return MD->getMetadataID() == DIModuleKind;

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4827,18 +4827,20 @@ bool LLParser::ParseDIMacroFile(MDNode *&Result, bool IsDistinct) {
48274827

48284828
/// ParseDIModule:
48294829
/// ::= !DIModule(scope: !0, name: "SomeModule", configMacros: "-DNDEBUG",
4830-
/// includePath: "/usr/include")
4830+
/// includePath: "/usr/include", apinotes: "module.apinotes")
48314831
bool LLParser::ParseDIModule(MDNode *&Result, bool IsDistinct) {
48324832
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
48334833
REQUIRED(scope, MDField, ); \
48344834
REQUIRED(name, MDStringField, ); \
48354835
OPTIONAL(configMacros, MDStringField, ); \
4836-
OPTIONAL(includePath, MDStringField, );
4836+
OPTIONAL(includePath, MDStringField, ); \
4837+
OPTIONAL(apinotes, MDStringField, );
48374838
PARSE_MD_FIELDS();
48384839
#undef VISIT_MD_FIELDS
48394840

4840-
Result = GET_OR_DISTINCT(DIModule, (Context, scope.Val, name.Val,
4841-
configMacros.Val, includePath.Val));
4841+
Result =
4842+
GET_OR_DISTINCT(DIModule, (Context, scope.Val, name.Val, configMacros.Val,
4843+
includePath.Val, apinotes.Val));
48424844
return false;
48434845
}
48444846

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,14 +1418,15 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
14181418
}
14191419

14201420
case bitc::METADATA_MODULE: {
1421-
if (Record.size() < 5 || Record.size() > 6)
1421+
if (Record.size() < 5 || Record.size() > 7)
14221422
return error("Invalid record");
14231423

14241424
IsDistinct = Record[0];
14251425
MetadataList.assignValue(
1426-
GET_OR_DISTINCT(
1427-
DIModule, (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
1428-
getMDString(Record[3]), getMDString(Record[4]))),
1426+
GET_OR_DISTINCT(DIModule,
1427+
(Context, getMDOrNull(Record[1]),
1428+
getMDString(Record[2]), getMDString(Record[3]),
1429+
getMDString(Record[4]), getMDString(Record[5]))),
14291430
NextMetadataNo);
14301431
NextMetadataNo++;
14311432
break;

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ DIE *DwarfUnit::getOrCreateModule(const DIModule *M) {
11261126
M->getConfigurationMacros());
11271127
if (!M->getIncludePath().empty())
11281128
addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath());
1129+
if (!M->getAPINotesFile().empty())
1130+
addString(MDie, dwarf::DW_AT_LLVM_apinotes, M->getAPINotesFile());
11291131

11301132
return &MDie;
11311133
}

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ static void writeDIModule(raw_ostream &Out, const DIModule *N,
20612061
Printer.printString("name", N->getName());
20622062
Printer.printString("configMacros", N->getConfigurationMacros());
20632063
Printer.printString("includePath", N->getIncludePath());
2064+
Printer.printString("apinotes", N->getAPINotesFile());
20642065
Out << ")";
20652066
}
20662067

llvm/lib/IR/DIBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,10 @@ DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
831831

832832
DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
833833
StringRef ConfigurationMacros,
834-
StringRef IncludePath) {
834+
StringRef IncludePath,
835+
StringRef APINotesFile) {
835836
return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
836-
ConfigurationMacros, IncludePath);
837+
ConfigurationMacros, IncludePath, APINotesFile);
837838
}
838839

839840
DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,

llvm/lib/IR/DebugInfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,13 @@ LLVMMetadataRef
791791
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
792792
const char *Name, size_t NameLen,
793793
const char *ConfigMacros, size_t ConfigMacrosLen,
794-
const char *IncludePath, size_t IncludePathLen) {
794+
const char *IncludePath, size_t IncludePathLen,
795+
const char *APINotesFile, size_t APINotesFileLen) {
795796
return wrap(unwrap(Builder)->createModule(
796797
unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
797798
StringRef(ConfigMacros, ConfigMacrosLen),
798-
StringRef(IncludePath, IncludePathLen)));
799+
StringRef(IncludePath, IncludePathLen),
800+
StringRef(APINotesFile, APINotesFileLen)));
799801
}
800802

801803
LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder,

0 commit comments

Comments
 (0)