[llvm-dwarfdump] Hide .debug_str and DIE reference offsets in brief mode

This patch hides the .debug_str offset and DIE reference offsets into
the CU when llvm-dwarfdump is invoked with -brief.

Differential Revision: https://reviews.llvm.org/D36835

llvm-svn: 311201
This commit is contained in:
Jonas Devlieghere 2017-08-18 21:35:44 +00:00
parent 69774d67c8
commit a2faf7b60f
4 changed files with 131 additions and 41 deletions

View File

@ -14,6 +14,7 @@
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include <cstdint>
@ -101,7 +102,7 @@ public:
bool isFormClass(FormClass FC) const;
const DWARFUnit *getUnit() const { return U; }
void dump(raw_ostream &OS) const;
void dump(raw_ostream &OS, DIDumpOptions DumpOpts = DIDumpOptions()) const;
/// Extracts a value in \p Data at offset \p *OffsetPtr.
///

View File

@ -106,12 +106,12 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
DWARFUnit *U = Die.getDwarfUnit();
DWARFFormValue formValue(Form);
if (!formValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr, U))
return;
OS << "\t(";
StringRef Name;
std::string File;
auto Color = syntax::Enumerator;
@ -124,14 +124,14 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
}
} else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant())
Name = AttributeValueString(Attr, *Val);
if (!Name.empty())
WithColor(OS, Color) << Name;
else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
OS << *formValue.getAsUnsignedConstant();
else
formValue.dump(OS);
formValue.dump(OS, DumpOpts);
// We have dumped the attribute raw value. For some attributes
// having both the raw value and the pretty-printed value is
// interesting. These attributes are handled below.
@ -328,11 +328,11 @@ void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, unsigned Indent,
DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
const uint32_t Offset = getOffset();
uint32_t offset = Offset;
if (debug_info_data.isValidOffset(offset)) {
uint32_t abbrCode = debug_info_data.getULEB128(&offset);
WithColor(OS, syntax::Address).get() << format("\n0x%8.8x: ", Offset);
if (abbrCode) {
auto AbbrevDecl = getAbbreviationDeclarationPtr();
if (AbbrevDecl) {
@ -359,7 +359,7 @@ void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, unsigned Indent,
dumpAttribute(OS, *this, &offset, AttrSpec.Attr, AttrSpec.Form,
Indent, DumpOpts);
}
DWARFDie child = getFirstChild();
if (RecurseDepth > 0 && child) {
while (child) {

View File

@ -396,7 +396,7 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
return true;
}
void DWARFFormValue::dump(raw_ostream &OS) const {
void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
uint64_t UValue = Value.uval;
bool CURelativeOffset = false;
@ -481,7 +481,8 @@ void DWARFFormValue::dump(raw_ostream &OS) const {
OS << Value.uval;
break;
case DW_FORM_strp:
OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)UValue);
if (!DumpOpts.Brief)
OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)UValue);
dumpString(OS);
break;
case DW_FORM_strx:
@ -540,7 +541,7 @@ void DWARFFormValue::dump(raw_ostream &OS) const {
break;
}
if (CURelativeOffset) {
if (CURelativeOffset && !DumpOpts.Brief) {
OS << " => {";
WithColor(OS, syntax::Address).get()
<< format("0x%8.8" PRIx64, UValue + (U ? U->getOffset() : 0));

View File

@ -5,22 +5,52 @@
# CHECK: DW_TAG_compile_unit
# CHECK-NOT: DW_FORM
# CHECK: DW_AT
# CHECK-NOT: debug_str
# CHECK-NOT: DW_AT_type {{.*}} =>
# This test is meant to verify that --brief hides DW_FORMs
# and abbreviation codes from .debug_info section.
# This test is meant to verify that -brief hides DW_FORMs and abbreviation
# codes from .debug_info section. Furthermore it verifies that it also hides
# .debug_str and die reference offsets into the CU.
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 12
.globl _main ## -- Begin function main
.p2align 4, 0x90
_main: ## @main
Lfunc_begin0:
.file 1 "brief.c"
.loc 1 1 0 ## brief.c:1:0
.cfi_startproc
## BB#0: ## %entry
pushq %rbp
Lcfi0:
.cfi_def_cfa_offset 16
Lcfi1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Lcfi2:
.cfi_def_cfa_register %rbp
xorl %eax, %eax
Ltmp0:
.loc 1 1 12 prologue_end ## brief.c:1:12
popq %rbp
retq
Ltmp1:
Lfunc_end0:
.cfi_endproc
## -- End function
.section __DWARF,__debug_str,regular,debug
Linfo_string:
.asciz "basic.c" ## string offset=42
.section __DWARF,__debug_loc,regular,debug
Lsection_debug_loc:
.asciz "clang version 6.0.0 (trunk 311115) (llvm/trunk 311188)" ## string offset=0
.asciz "brief.c" ## string offset=55
.asciz "/private/tmp" ## string offset=63
.asciz "main" ## string offset=76
.asciz "int" ## string offset=81
.section __DWARF,__debug_abbrev,regular,debug
Lsection_abbrev:
.byte 1 ## Abbreviation Code
.byte 17 ## DW_TAG_compile_unit
.byte 0 ## DW_CHILDREN_no
.byte 1 ## DW_CHILDREN_yes
.byte 37 ## DW_AT_producer
.byte 14 ## DW_FORM_strp
.byte 19 ## DW_AT_language
@ -31,24 +61,79 @@ Lsection_abbrev:
.byte 23 ## DW_FORM_sec_offset
.byte 27 ## DW_AT_comp_dir
.byte 14 ## DW_FORM_strp
.byte 17 ## DW_AT_low_pc
.byte 1 ## DW_FORM_addr
.byte 18 ## DW_AT_high_pc
.byte 6 ## DW_FORM_data4
.byte 0 ## EOM(1)
.byte 0 ## EOM(2)
.byte 2 ## Abbreviation Code
.byte 46 ## DW_TAG_subprogram
.byte 0 ## DW_CHILDREN_no
.byte 17 ## DW_AT_low_pc
.byte 1 ## DW_FORM_addr
.byte 18 ## DW_AT_high_pc
.byte 6 ## DW_FORM_data4
.byte 64 ## DW_AT_frame_base
.byte 24 ## DW_FORM_exprloc
.byte 3 ## DW_AT_name
.byte 14 ## DW_FORM_strp
.byte 58 ## DW_AT_decl_file
.byte 11 ## DW_FORM_data1
.byte 59 ## DW_AT_decl_line
.byte 11 ## DW_FORM_data1
.byte 73 ## DW_AT_type
.byte 19 ## DW_FORM_ref4
.byte 63 ## DW_AT_external
.byte 25 ## DW_FORM_flag_present
.byte 0 ## EOM(1)
.byte 0 ## EOM(2)
.byte 3 ## Abbreviation Code
.byte 36 ## DW_TAG_base_type
.byte 0 ## DW_CHILDREN_no
.byte 3 ## DW_AT_name
.byte 14 ## DW_FORM_strp
.byte 62 ## DW_AT_encoding
.byte 11 ## DW_FORM_data1
.byte 11 ## DW_AT_byte_size
.byte 11 ## DW_FORM_data1
.byte 0 ## EOM(1)
.byte 0 ## EOM(2)
.byte 0 ## EOM(3)
.section __DWARF,__debug_info,regular,debug
Lsection_info:
Lcu_begin0:
.long 26 ## Length of Unit
.long 71 ## Length of Unit
.short 4 ## DWARF version number
Lset0 = Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
.long Lset0
.byte 8 ## Address Size (in bytes)
.byte 1 ## Abbrev [1] 0xb:0x13 DW_TAG_compile_unit
.byte 1 ## Abbrev [1] 0xb:0x40 DW_TAG_compile_unit
.long 0 ## DW_AT_producer
.short 12 ## DW_AT_language
.long 42 ## DW_AT_name
.long 55 ## DW_AT_name
Lset1 = Lline_table_start0-Lsection_line ## DW_AT_stmt_list
.long Lset1
.long 50 ## DW_AT_comp_dir
.long 63 ## DW_AT_comp_dir
.quad Lfunc_begin0 ## DW_AT_low_pc
Lset2 = Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
.long Lset2
.byte 2 ## Abbrev [2] 0x2a:0x19 DW_TAG_subprogram
.quad Lfunc_begin0 ## DW_AT_low_pc
Lset3 = Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
.long Lset3
.byte 1 ## DW_AT_frame_base
.byte 86
.long 76 ## DW_AT_name
.byte 1 ## DW_AT_decl_file
.byte 1 ## DW_AT_decl_line
.long 67 ## DW_AT_type
## DW_AT_external
.byte 3 ## Abbrev [3] 0x43:0x7 DW_TAG_base_type
.long 81 ## DW_AT_name
.byte 5 ## DW_AT_encoding
.byte 4 ## DW_AT_byte_size
.byte 0 ## End Of Children Mark
.section __DWARF,__debug_ranges,regular,debug
Ldebug_range:
.section __DWARF,__debug_macinfo,regular,debug
@ -61,13 +146,20 @@ Lnames_begin:
.short 1 ## Header Version
.short 0 ## Header Hash Function
.long 1 ## Header Bucket Count
.long 0 ## Header Hash Count
.long 1 ## Header Hash Count
.long 12 ## Header Data Length
.long 0 ## HeaderData Die Offset Base
.long 1 ## HeaderData Atom Count
.short 1 ## DW_ATOM_die_offset
.short 6 ## DW_FORM_data4
.long -1 ## Bucket 0
.long 0 ## Bucket 0
.long 2090499946 ## Hash in Bucket 0
.long LNames0-Lnames_begin ## Offset in Bucket 0
LNames0:
.long 76 ## main
.long 1 ## Num DIEs
.long 42
.long 0
.section __DWARF,__apple_objc,regular,debug
Lobjc_begin:
.long 1212240712 ## Header Magic
@ -100,7 +192,7 @@ Ltypes_begin:
.short 1 ## Header Version
.short 0 ## Header Hash Function
.long 1 ## Header Bucket Count
.long 0 ## Header Hash Count
.long 1 ## Header Hash Count
.long 20 ## Header Data Length
.long 0 ## HeaderData Die Offset Base
.long 3 ## HeaderData Atom Count
@ -110,20 +202,16 @@ Ltypes_begin:
.short 5 ## DW_FORM_data2
.short 4 ## DW_ATOM_type_flags
.short 11 ## DW_FORM_data1
.long -1 ## Bucket 0
.section __DWARF,__apple_exttypes,regular,debug
Lexttypes_begin:
.long 1212240712 ## Header Magic
.short 1 ## Header Version
.short 0 ## Header Hash Function
.long 1 ## Header Bucket Count
.long 0 ## Header Hash Count
.long 12 ## Header Data Length
.long 0 ## HeaderData Die Offset Base
.long 1 ## HeaderData Atom Count
.short 7 ## DW_ATOM_ext_types
.short 6 ## DW_FORM_data4
.long -1 ## Bucket 0
.long 0 ## Bucket 0
.long 193495088 ## Hash in Bucket 0
.long Ltypes0-Ltypes_begin ## Offset in Bucket 0
Ltypes0:
.long 81 ## int
.long 1 ## Num DIEs
.long 67
.short 36
.byte 0
.long 0
.subsections_via_symbols
.section __DWARF,__debug_line,regular,debug