aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2025-10-10 18:58:18 +0100
committerGitHub <noreply@github.com>2025-10-10 18:58:18 +0100
commit7dbf115a924dee4d0adc4d8c0aec1849e79fc21d (patch)
tree6a1102e25ad7d0bf084f02338edf7731e4b2d14d /llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
parent0f73e75bf78c4adebcc674c30ca253118f0bcdfc (diff)
downloadllvm-7dbf115a924dee4d0adc4d8c0aec1849e79fc21d.zip
llvm-7dbf115a924dee4d0adc4d8c0aec1849e79fc21d.tar.gz
llvm-7dbf115a924dee4d0adc4d8c0aec1849e79fc21d.tar.bz2
[llvm][DebugInfo] Add support for emitting DW_AT_language_name (#162621)
Depends on: * https://github.com/llvm/llvm-project/pull/162445 * https://github.com/llvm/llvm-project/pull/162449 Emit `DW_AT_language_name` (new in DWARFv6) if `DICompileUnit` has a `sourceLanguageName` field. Emit a `DW_AT_language` otherwise.
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 12d749c..e57ed24 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -569,40 +569,30 @@ void CodeViewDebug::emitCodeViewMagicVersion() {
OS.emitInt32(COFF::DEBUG_SECTION_MAGIC);
}
-static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
- switch (DWLang) {
- case dwarf::DW_LANG_C:
- case dwarf::DW_LANG_C89:
- case dwarf::DW_LANG_C99:
- case dwarf::DW_LANG_C11:
+static SourceLanguage
+MapDWARFLanguageToCVLang(dwarf::SourceLanguageName DWLName) {
+ switch (DWLName) {
+ case dwarf::DW_LNAME_C:
return SourceLanguage::C;
- case dwarf::DW_LANG_C_plus_plus:
- case dwarf::DW_LANG_C_plus_plus_03:
- case dwarf::DW_LANG_C_plus_plus_11:
- case dwarf::DW_LANG_C_plus_plus_14:
+ case dwarf::DW_LNAME_C_plus_plus:
return SourceLanguage::Cpp;
- case dwarf::DW_LANG_Fortran77:
- case dwarf::DW_LANG_Fortran90:
- case dwarf::DW_LANG_Fortran95:
- case dwarf::DW_LANG_Fortran03:
- case dwarf::DW_LANG_Fortran08:
+ case dwarf::DW_LNAME_Fortran:
return SourceLanguage::Fortran;
- case dwarf::DW_LANG_Pascal83:
+ case dwarf::DW_LNAME_Pascal:
return SourceLanguage::Pascal;
- case dwarf::DW_LANG_Cobol74:
- case dwarf::DW_LANG_Cobol85:
+ case dwarf::DW_LNAME_Cobol:
return SourceLanguage::Cobol;
- case dwarf::DW_LANG_Java:
+ case dwarf::DW_LNAME_Java:
return SourceLanguage::Java;
- case dwarf::DW_LANG_D:
+ case dwarf::DW_LNAME_D:
return SourceLanguage::D;
- case dwarf::DW_LANG_Swift:
+ case dwarf::DW_LNAME_Swift:
return SourceLanguage::Swift;
- case dwarf::DW_LANG_Rust:
+ case dwarf::DW_LNAME_Rust:
return SourceLanguage::Rust;
- case dwarf::DW_LANG_ObjC:
+ case dwarf::DW_LNAME_ObjC:
return SourceLanguage::ObjC;
- case dwarf::DW_LANG_ObjC_plus_plus:
+ case dwarf::DW_LNAME_ObjC_plus_plus:
return SourceLanguage::ObjCpp;
default:
// There's no CodeView representation for this language, and CV doesn't
@@ -612,6 +602,14 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
}
}
+static SourceLanguage MapDWARFLanguageToCVLang(dwarf::SourceLanguage DWLang) {
+ auto MaybeLName = dwarf::toDW_LNAME(DWLang);
+ if (!MaybeLName)
+ return MapDWARFLanguageToCVLang(static_cast<dwarf::SourceLanguageName>(0));
+
+ return MapDWARFLanguageToCVLang(MaybeLName->first);
+}
+
void CodeViewDebug::beginModule(Module *M) {
// If COFF debug section is not available, skip any debug info related stuff.
if (!Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) {
@@ -633,8 +631,13 @@ void CodeViewDebug::beginModule(Module *M) {
Node = *CUs->operands().begin();
}
const auto *CU = cast<DICompileUnit>(Node);
+ DISourceLanguageName Lang = CU->getSourceLanguage();
CurrentSourceLanguage =
- MapDWLangToCVLang(CU->getSourceLanguage().getUnversionedName());
+ Lang.hasVersionedName()
+ ? MapDWARFLanguageToCVLang(
+ static_cast<dwarf::SourceLanguageName>(Lang.getName()))
+ : MapDWARFLanguageToCVLang(
+ static_cast<dwarf::SourceLanguage>(Lang.getName()));
if (!M->getCodeViewFlag() ||
CU->getEmissionKind() == DICompileUnit::NoDebug) {
Asm = nullptr;