Skip to content

Commit 8f0741f

Browse files
committed
[llvm][dwarfdump] Pretty-print DW_AT_language_version in non-verbose dwarfdump
1 parent d4f862a commit 8f0741f

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F) {
107107
return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference();
108108
}
109109

110+
static llvm::StringRef
111+
prettyLanguageVersionString(const DWARFAttribute &AttrValue,
112+
const DWARFDie &Die) {
113+
assert(AttrValue.Attr == DW_AT_language_version);
114+
115+
auto NameForm = Die.find(DW_AT_language_name);
116+
if (!NameForm)
117+
return {};
118+
119+
auto LName = NameForm->getAsUnsignedConstant();
120+
if (!LName)
121+
return {};
122+
123+
auto LVersion = AttrValue.Value.getAsUnsignedConstant();
124+
if (!LVersion)
125+
return {};
126+
127+
return llvm::dwarf::LanguageDescription(
128+
static_cast<SourceLanguageName>(*LName), *LVersion);
129+
}
130+
110131
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
111132
const DWARFAttribute &AttrValue, unsigned Indent,
112133
DIDumpOptions DumpOpts) {
@@ -143,7 +164,9 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
143164
}
144165
}
145166
}
146-
} else if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
167+
} else if (Attr == llvm::dwarf::DW_AT_language_version && !DumpOpts.Verbose)
168+
Name = prettyLanguageVersionString(AttrValue, Die);
169+
else if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
147170
Name = AttributeValueString(Attr, *Val);
148171

149172
if (!Name.empty())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Demonstrate dumping DW_AT_language_version in human-readable form.
2+
# RUN: llvm-mc -triple=x86_64--linux -filetype=obj < %s | \
3+
# RUN: llvm-dwarfdump - | FileCheck %s --implicit-check-not "DW_AT_language_version"
4+
5+
# CHECK: .debug_info contents:
6+
# CHECK: DW_AT_language_name (DW_LNAME_C)
7+
# CHECK: DW_AT_language_version (C11)
8+
9+
.section .debug_abbrev,"",@progbits
10+
.byte 1 # Abbreviation Code
11+
.byte 17 # DW_TAG_compile_unit
12+
.byte 1 # DW_CHILDREN_no
13+
.ascii "\220\001" # DW_AT_language_name
14+
.byte 5 # DW_FORM_data2
15+
.ascii "\221\001" # DW_AT_language_version
16+
.byte 6 # DW_FORM_data4
17+
.byte 0 # EOM(1)
18+
.byte 0 # EOM(2)
19+
.byte 0 # EOM(3)
20+
21+
.section .debug_info,"",@progbits
22+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
23+
.Ldebug_info_start0:
24+
.short 5 # DWARF version number
25+
.byte 1 # Unit type
26+
.byte 8 # Address Size (in bytes)
27+
.long .debug_abbrev # Offset Into Abbrev. Section
28+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
29+
.short 3 # DW_AT_language_name
30+
.long 201112 # DW_AT_language_version
31+
.byte 0
32+
.Ldebug_info_end0:

llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_version.s

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Demonstrate dumping DW_AT_language_version.
2-
# RUN: llvm-mc -triple=x86_64--linux -filetype=obj < %s | \
3-
# RUN: llvm-dwarfdump -v - | FileCheck %s
2+
# RUN: llvm-mc -triple=x86_64--linux -filetype=obj -o %t.o < %s
3+
# RUN: llvm-dwarfdump -v %t.o | FileCheck %s --check-prefix=VERBOSE
4+
# RUN: llvm-dwarfdump %t.o | FileCheck %s --check-prefix=NO-VERBOSE
45

5-
# CHECK: .debug_abbrev contents:
6-
# CHECK: DW_AT_language_version DW_FORM_data4
7-
# CHECK: DW_AT_language_version DW_FORM_data2
8-
# CHECK: .debug_info contents:
9-
# CHECK: DW_AT_language_version [DW_FORM_data4] (201402)
10-
# CHECK: DW_AT_language_version [DW_FORM_data2] (0)
6+
# VERBOSE: .debug_abbrev contents:
7+
# VERBOSE: DW_AT_language_version DW_FORM_data4
8+
# VERBOSE: DW_AT_language_version DW_FORM_data2
9+
# VERBOSE: .debug_info contents:
10+
# VERBOSE: DW_AT_language_version [DW_FORM_data4] (201402)
11+
# VERBOSE: DW_AT_language_version [DW_FORM_data2] (0)
12+
13+
# NO-VERBOSE: .debug_info contents:
14+
# NO-VERBOSE: DW_AT_language_version (201402)
15+
# NO-VERBOSE: DW_AT_language_version (0)
1116

1217
.section .debug_abbrev,"",@progbits
1318
.byte 1 # Abbreviation Code

0 commit comments

Comments
 (0)