Skip to content

Commit 0dff52b

Browse files
authored
[llvm-dwarfdump] Support for DW_AT_language_name and DW_AT_language_version (#162449)
Depends on: * #162434 * #162446 Makes sure we dump the attributes in a user-friendly way. More info on the attributes here: https://dwarfstd.org/languages-v6.html
1 parent 66da680 commit 0dff52b

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

llvm/lib/BinaryFormat/Dwarf.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
893893
return DefaultedMemberString(Val);
894894
case DW_AT_APPLE_enum_kind:
895895
return EnumKindString(Val);
896+
case DW_AT_language_name:
897+
return SourceLanguageNameString(static_cast<SourceLanguageName>(Val));
896898
}
897899

898900
return StringRef();

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
149149
if (!Name.empty())
150150
WithColor(OS, Color) << Name;
151151
else if (Attr == DW_AT_decl_line || Attr == DW_AT_decl_column ||
152-
Attr == DW_AT_call_line || Attr == DW_AT_call_column) {
152+
Attr == DW_AT_call_line || Attr == DW_AT_call_column ||
153+
Attr == DW_AT_language_version) {
153154
if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
154155
OS << *Val;
155156
else
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Demonstrate dumping DW_AT_language_name.
2+
# RUN: llvm-mc -triple=x86_64--linux -filetype=obj < %s | \
3+
# RUN: llvm-dwarfdump -v - | FileCheck %s
4+
5+
# CHECK: .debug_abbrev contents:
6+
# CHECK: DW_AT_language_name DW_FORM_data2
7+
# CHECK: DW_AT_language_name DW_FORM_data2
8+
# CHECK: .debug_info contents:
9+
# CHECK: DW_AT_language_name [DW_FORM_data2] (DW_LNAME_C)
10+
# CHECK: DW_AT_language_name [DW_FORM_data2] (0x0000)
11+
12+
.section .debug_abbrev,"",@progbits
13+
.byte 1 # Abbreviation Code
14+
.byte 17 # DW_TAG_compile_unit
15+
.byte 1 # DW_CHILDREN_no
16+
.ascii "\220\001" # DW_AT_language_name
17+
.byte 5 # DW_FORM_data2
18+
.ascii "\220\001" # DW_AT_language_name
19+
.byte 5 # DW_FORM_data2
20+
.byte 0 # EOM(1)
21+
.byte 0 # EOM(2)
22+
.byte 0 # EOM(3)
23+
24+
.section .debug_info,"",@progbits
25+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
26+
.Ldebug_info_start0:
27+
.short 5 # DWARF version number
28+
.byte 1 # Unit type
29+
.byte 8 # Address Size (in bytes)
30+
.long .debug_abbrev # Offset Into Abbrev. Section
31+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
32+
.short 3 # DW_AT_language_name
33+
.short 0 # DW_AT_language_name
34+
.byte 0
35+
.Ldebug_info_end0:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Demonstrate dumping DW_AT_language_version.
2+
# RUN: llvm-mc -triple=x86_64--linux -filetype=obj < %s | \
3+
# RUN: llvm-dwarfdump -v - | FileCheck %s
4+
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)
11+
12+
.section .debug_abbrev,"",@progbits
13+
.byte 1 # Abbreviation Code
14+
.byte 17 # DW_TAG_compile_unit
15+
.byte 1 # DW_CHILDREN_no
16+
.ascii "\221\001" # DW_AT_language_version
17+
.byte 6 # DW_FORM_data4
18+
.ascii "\221\001" # DW_AT_language_version
19+
.byte 5 # DW_FORM_data2
20+
.byte 0 # EOM(1)
21+
.byte 0 # EOM(2)
22+
.byte 0 # EOM(3)
23+
24+
.section .debug_info,"",@progbits
25+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
26+
.Ldebug_info_start0:
27+
.short 5 # DWARF version number
28+
.byte 1 # Unit type
29+
.byte 8 # Address Size (in bytes)
30+
.long .debug_abbrev # Offset Into Abbrev. Section
31+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
32+
.long 201402 # DW_AT_language_version
33+
.short 0 # DW_AT_language_version
34+
.byte 0
35+
.Ldebug_info_end0:

0 commit comments

Comments
 (0)