From e03b759ee90c4c7326690524557e1dd06ba96a7c Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Wed, 8 Oct 2025 10:44:54 +0100 Subject: [PATCH] [llvm-dwarfdump] Support for DW_AT_language_name and DW_AT_language_version Makes sure we dump the attributes in a user-friendly way. --- llvm/lib/BinaryFormat/Dwarf.cpp | 2 ++ llvm/lib/DebugInfo/DWARF/DWARFDie.cpp | 3 +- .../llvm-dwarfdump/X86/DW_AT_language_name.s | 35 +++++++++++++++++++ .../X86/DW_AT_language_version.s | 35 +++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_name.s create mode 100644 llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_version.s diff --git a/llvm/lib/BinaryFormat/Dwarf.cpp b/llvm/lib/BinaryFormat/Dwarf.cpp index 969047a8e5b5c..55fa2df632bfa 100644 --- a/llvm/lib/BinaryFormat/Dwarf.cpp +++ b/llvm/lib/BinaryFormat/Dwarf.cpp @@ -893,6 +893,8 @@ StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) { return DefaultedMemberString(Val); case DW_AT_APPLE_enum_kind: return EnumKindString(Val); + case DW_AT_language_name: + return SourceLanguageNameString(static_cast(Val)); } return StringRef(); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index edc69a36cdff2..212a0c039298b 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -149,7 +149,8 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, if (!Name.empty()) WithColor(OS, Color) << Name; else if (Attr == DW_AT_decl_line || Attr == DW_AT_decl_column || - Attr == DW_AT_call_line || Attr == DW_AT_call_column) { + Attr == DW_AT_call_line || Attr == DW_AT_call_column || + Attr == DW_AT_language_version) { if (std::optional Val = FormValue.getAsUnsignedConstant()) OS << *Val; else diff --git a/llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_name.s b/llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_name.s new file mode 100644 index 0000000000000..af581753be56a --- /dev/null +++ b/llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_name.s @@ -0,0 +1,35 @@ +# Demonstrate dumping DW_AT_language_name. +# RUN: llvm-mc -triple=x86_64--linux -filetype=obj < %s | \ +# RUN: llvm-dwarfdump -v - | FileCheck %s + +# CHECK: .debug_abbrev contents: +# CHECK: DW_AT_language_name DW_FORM_data2 +# CHECK: DW_AT_language_name DW_FORM_data2 +# CHECK: .debug_info contents: +# CHECK: DW_AT_language_name [DW_FORM_data2] (DW_LNAME_C) +# CHECK: DW_AT_language_name [DW_FORM_data2] (0x0000) + + .section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_no + .ascii "\220\001" # DW_AT_language_name + .byte 5 # DW_FORM_data2 + .ascii "\220\001" # DW_AT_language_name + .byte 5 # DW_FORM_data2 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + + .section .debug_info,"",@progbits + .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit +.Ldebug_info_start0: + .short 5 # DWARF version number + .byte 1 # Unit type + .byte 8 # Address Size (in bytes) + .long .debug_abbrev # Offset Into Abbrev. Section + .byte 1 # Abbrev [1] DW_TAG_compile_unit + .short 3 # DW_AT_language_name + .short 0 # DW_AT_language_name + .byte 0 +.Ldebug_info_end0: diff --git a/llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_version.s b/llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_version.s new file mode 100644 index 0000000000000..f1be8fdf6cd3e --- /dev/null +++ b/llvm/test/tools/llvm-dwarfdump/X86/DW_AT_language_version.s @@ -0,0 +1,35 @@ +# Demonstrate dumping DW_AT_language_version. +# RUN: llvm-mc -triple=x86_64--linux -filetype=obj < %s | \ +# RUN: llvm-dwarfdump -v - | FileCheck %s + +# CHECK: .debug_abbrev contents: +# CHECK: DW_AT_language_version DW_FORM_data4 +# CHECK: DW_AT_language_version DW_FORM_data2 +# CHECK: .debug_info contents: +# CHECK: DW_AT_language_version [DW_FORM_data4] (201402) +# CHECK: DW_AT_language_version [DW_FORM_data2] (0) + + .section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_no + .ascii "\221\001" # DW_AT_language_version + .byte 6 # DW_FORM_data4 + .ascii "\221\001" # DW_AT_language_version + .byte 5 # DW_FORM_data2 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + + .section .debug_info,"",@progbits + .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit +.Ldebug_info_start0: + .short 5 # DWARF version number + .byte 1 # Unit type + .byte 8 # Address Size (in bytes) + .long .debug_abbrev # Offset Into Abbrev. Section + .byte 1 # Abbrev [1] DW_TAG_compile_unit + .long 201402 # DW_AT_language_version + .short 0 # DW_AT_language_version + .byte 0 +.Ldebug_info_end0: