From 5295aa52c19464921cd5557547d265ed75619889 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 2 Oct 2017 16:02:04 +0000 Subject: [PATCH] [dwarfdump] Add -show-form This enables printing of DWARF form types after the DWARF attribute types. Differential revision: https://reviews.llvm.org/D38459 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314685 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/DIContext.h | 1 + lib/DebugInfo/DWARF/DWARFDie.cpp | 2 +- test/tools/llvm-dwarfdump/X86/form.test | 40 +++++++++++++++++++++++++ test/tools/llvm-dwarfdump/cmdline.test | 3 +- tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 13 ++++++-- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 test/tools/llvm-dwarfdump/X86/form.test diff --git a/include/llvm/DebugInfo/DIContext.h b/include/llvm/DebugInfo/DIContext.h index d5ff7cb35bf..ce0a156e9f7 100644 --- a/include/llvm/DebugInfo/DIContext.h +++ b/include/llvm/DebugInfo/DIContext.h @@ -141,6 +141,7 @@ struct DIDumpOptions { unsigned RecurseDepth = -1U; bool ShowChildren = false; bool ShowParents = false; + bool ShowForm = false; bool SummarizeTypes = false; bool Verbose = false; diff --git a/lib/DebugInfo/DWARF/DWARFDie.cpp b/lib/DebugInfo/DWARF/DWARFDie.cpp index 31074a81a98..a2371038b96 100644 --- a/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -139,7 +139,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, else WithColor(OS, syntax::Attribute).get() << format("DW_AT_Unknown_%x", Attr); - if (DumpOpts.Verbose) { + if (DumpOpts.Verbose || DumpOpts.ShowForm) { auto formString = FormEncodingString(Form); if (!formString.empty()) OS << " [" << formString << ']'; diff --git a/test/tools/llvm-dwarfdump/X86/form.test b/test/tools/llvm-dwarfdump/X86/form.test new file mode 100644 index 00000000000..92b7996a06d --- /dev/null +++ b/test/tools/llvm-dwarfdump/X86/form.test @@ -0,0 +1,40 @@ +# This test verifies that DWARF form types are printed in verbose mode and when +# passing -F but not in brief mode. + +# RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \ +# RUN: | llvm-dwarfdump -v --debug-info - \ +# RUN: | FileCheck %s + +# RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \ +# RUN: | llvm-dwarfdump -F --debug-info - \ +# RUN: | FileCheck %s + +# RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \ +# RUN: | llvm-dwarfdump --debug-info - \ +# RUN: | FileCheck %s --check-prefix NO-FORM + +# CHECK: DW_TAG_compile_unit +# CHECK: DW_AT_producer [DW_FORM_strp] +# CHECK: DW_AT_language [DW_FORM_data2] +# CHECK: DW_AT_name [DW_FORM_strp] +# CHECK: DW_AT_stmt_list [DW_FORM_sec_offset] +# CHECK: DW_AT_comp_dir [DW_FORM_strp] +# CHECK: DW_AT_low_pc [DW_FORM_addr] +# CHECK: DW_AT_high_pc [DW_FORM_data4] + +# CHECK: DW_TAG_subprogram +# CHECK: DW_AT_low_pc [DW_FORM_addr] +# CHECK: DW_AT_high_pc [DW_FORM_data4] +# CHECK: DW_AT_frame_base [DW_FORM_exprloc] +# CHECK: DW_AT_name [DW_FORM_strp] +# CHECK: DW_AT_decl_file [DW_FORM_data1] +# CHECK: DW_AT_decl_line [DW_FORM_data1] +# CHECK: DW_AT_type [DW_FORM_ref4] +# CHECK: DW_AT_external [DW_FORM_flag_present] + +# CHECK: DW_TAG_base_type +# CHECK: DW_AT_name [DW_FORM_strp] +# CHECK: DW_AT_encoding [DW_FORM_data1] +# CHECK: DW_AT_byte_size [DW_FORM_data1] + +# NO-FORM-NOT: DW_FORM_ diff --git a/test/tools/llvm-dwarfdump/cmdline.test b/test/tools/llvm-dwarfdump/cmdline.test index fd06f77dda3..16b422a960b 100644 --- a/test/tools/llvm-dwarfdump/cmdline.test +++ b/test/tools/llvm-dwarfdump/cmdline.test @@ -8,8 +8,9 @@ HELP: -eh-frame HELP: Specific Options HELP: -find HELP: -name -HELP: -recurse-depth= +HELP: -recurse-depth= HELP: -show-children +HELP: -show-form HELP: -show-parents HELP: -summarize-types HELP-NOT: -reverse-iterate diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index f8909800852..28b4a136fb1 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -170,13 +170,19 @@ static opt cat(DwarfDumpCategory)); static alias ShowParentsAlias("p", desc("Alias for -show-parents"), aliasopt(ShowParents)); +static opt + ShowForm("show-form", + desc("Show DWARF form types after the DWARF attribute types."), + cat(DwarfDumpCategory)); +static alias ShowFormAlias("F", desc("Alias for -show-form"), + aliasopt(ShowForm), cat(DwarfDumpCategory)); static opt RecurseDepth( "recurse-depth", desc("Only recurse to a depth of N when displaying debug info entries."), cat(DwarfDumpCategory), init(-1U), value_desc("N")); static alias RecurseDepthAlias("r", desc("Alias for -recurse-depth"), aliasopt(RecurseDepth)); - + static opt SummarizeTypes("summarize-types", desc("Abbreviate the description of type unit entries"), @@ -210,6 +216,7 @@ static DIDumpOptions getDumpOpts() { DumpOpts.RecurseDepth = RecurseDepth; DumpOpts.ShowChildren = ShowChildren; DumpOpts.ShowParents = ShowParents; + DumpOpts.ShowForm = ShowForm; DumpOpts.SummarizeTypes = SummarizeTypes; DumpOpts.Verbose = Verbose; // In -verify mode, print DIEs without children in error messages. @@ -277,7 +284,7 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename, StringSet<> Names; for (auto name : Name) Names.insert(name); - + filterByName(Names, DICtx.compile_units(), OS); filterByName(Names, DICtx.dwo_compile_units(), OS); return true; @@ -308,7 +315,7 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename, if (!DumpOffsets[DIDT_ID_DebugInfo]) return true; } - + // Dump the complete DWARF structure. DICtx.dump(OS, getDumpOpts(), DumpOffsets); return true; -- 2.40.0