jankratochvil created this revision. jankratochvil added reviewers: labath, grimar. jankratochvil added a project: LLDB. Herald added a subscriber: JDevlieghere. jankratochvil requested review of this revision. Herald added a reviewer: jdoerfert. Herald added a subscriber: sstefan1.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D98197 Files: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h lldb/test/Shell/SymbolFile/DWARF/dwarf5-implicit-const.s
Index: lldb/test/Shell/SymbolFile/DWARF/dwarf5-implicit-const.s =================================================================== --- /dev/null +++ lldb/test/Shell/SymbolFile/DWARF/dwarf5-implicit-const.s @@ -0,0 +1,193 @@ +# Test handling of DWARF5 DW_FORM_implicit_const as used by GCC. + +# UNSUPPORTED: system-darwin, system-windows +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -o %t -triple x86_64-pc-linux %s +# RUN: %lldb %t -o "p main" \ +# RUN: -o exit | FileCheck %s + +# Failing case was: +# error: need to add support for DW_TAG_base_type 'int' encoded with DW_ATE = 0x5, bit_size = 0 +# (void (*)()) $0 = 0x0000000000000000 +# CHECK: (int (*)()) $0 = 0x0000000000000000 + + .text +.Ltext0: + .globl main + .type main, @function +main: +.LFB0: +.LM1: + .long 0 +.LM2: + .long 0 +.LFE0: + .size main, .-main +.Letext0: + .section .debug_info,"",@progbits +.Ldebug_info0: + .long .Ldebug_info0_end - .Ldebug_info0_start # Length of Compilation Unit Info +.Ldebug_info0_start: + .value 0x5 # DWARF version number + .byte 0x1 # DW_UT_compile + .byte 0x8 # Pointer Size (in bytes) + .long .Ldebug_abbrev0 # Offset Into Abbrev. Section + .uleb128 0x1 # (DIE DW_TAG_compile_unit) + .long .LASF2 # DW_AT_producer: "GNU C17 11.0.0 20210210 (Red Hat 11.0.0-0) -mtune=generic -march=x86-64 -gdwarf-5 -gno-as-loc-support" + .byte 0x1d # DW_AT_language + .long .LASF0 # DW_AT_name: "main.c" + .long .LASF1 # DW_AT_comp_dir: "" + .quad .Ltext0 # DW_AT_low_pc + .quad .Letext0-.Ltext0 # DW_AT_high_pc + .long .Ldebug_line0 # DW_AT_stmt_list + .uleb128 0x2 # (DIE DW_TAG_subprogram) + # DW_AT_external + .long .LASF3 # DW_AT_name: "main" + .byte 0x1 # DW_AT_decl_file (main.c) + .byte 0x1 # DW_AT_decl_line + .quad .LFB0 # DW_AT_low_pc + .quad .LFE0-.LFB0 # DW_AT_high_pc + .long .Ltype_int - .Ldebug_info0 # DW_AT_type +.Ltype_int: + .uleb128 0x3 # (DIE DW_TAG_base_type) + # DW_AT_byte_size + .byte 0x5 # DW_AT_encoding + .ascii "int\0" # DW_AT_name + .byte 0 # end of children of DIE DW_TAG_compile_unit +.Ldebug_info0_end: + .section .debug_abbrev,"",@progbits +.Ldebug_abbrev0: + .uleb128 0x1 # (abbrev code) + .uleb128 0x11 # (TAG: DW_TAG_compile_unit) + .byte 0x1 # DW_children_yes + .uleb128 0x25 # (DW_AT_producer) + .uleb128 0xe # (DW_FORM_strp) + .uleb128 0x13 # (DW_AT_language) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x1f # (DW_FORM_line_strp) + .uleb128 0x1b # (DW_AT_comp_dir) + .uleb128 0x1f # (DW_FORM_line_strp) + .uleb128 0x11 # (DW_AT_low_pc) + .uleb128 0x1 # (DW_FORM_addr) + .uleb128 0x12 # (DW_AT_high_pc) + .uleb128 0x7 # (DW_FORM_data8) + .uleb128 0x10 # (DW_AT_stmt_list) + .uleb128 0x17 # (DW_FORM_sec_offset) + .byte 0 + .byte 0 + .uleb128 0x2 # (abbrev code) + .uleb128 0x2e # (TAG: DW_TAG_subprogram) + .byte 0 # DW_children_no + .uleb128 0x3f # (DW_AT_external) + .uleb128 0x19 # (DW_FORM_flag_present) + .uleb128 0x3 # (DW_AT_name) + .uleb128 0xe # (DW_FORM_strp) + .uleb128 0x3a # (DW_AT_decl_file) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x3b # (DW_AT_decl_line) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x11 # (DW_AT_low_pc) + .uleb128 0x1 # (DW_FORM_addr) + .uleb128 0x12 # (DW_AT_high_pc) + .uleb128 0x7 # (DW_FORM_data8) + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0 + .byte 0 + .uleb128 0x3 # (abbrev code) + .uleb128 0x24 # (TAG: DW_TAG_base_type) + .byte 0 # DW_children_no + .uleb128 0xb # (DW_AT_byte_size) + .uleb128 0x21 # (DW_FORM_implicit_const) + .sleb128 4 + .uleb128 0x3e # (DW_AT_encoding) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .byte 0 + .byte 0 + .byte 0 + .section .debug_line,"",@progbits +.Ldebug_line0: + .long .LELT0-.LSLT0 # Length of Source Line Info +.LSLT0: + .value 0x5 # DWARF version number + .byte 0x8 # Address Size + .byte 0 # Segment Size + .long .LELTP0-.LASLTP0 # Prolog Length +.LASLTP0: + .byte 0x1 # Minimum Instruction Length + .byte 0x1 # Maximum Operations Per Instruction + .byte 0x1 # Default is_stmt_start flag + .byte 0xf6 # Line Base Value (Special Opcodes) + .byte 0xf2 # Line Range Value (Special Opcodes) + .byte 0xd # Special Opcode Base + .byte 0 # opcode: 0x1 has 0 args + .byte 0x1 # opcode: 0x2 has 1 args + .byte 0x1 # opcode: 0x3 has 1 args + .byte 0x1 # opcode: 0x4 has 1 args + .byte 0x1 # opcode: 0x5 has 1 args + .byte 0 # opcode: 0x6 has 0 args + .byte 0 # opcode: 0x7 has 0 args + .byte 0 # opcode: 0x8 has 0 args + .byte 0x1 # opcode: 0x9 has 1 args + .byte 0 # opcode: 0xa has 0 args + .byte 0 # opcode: 0xb has 0 args + .byte 0x1 # opcode: 0xc has 1 args + .byte 0x1 # Directory entry format count + .uleb128 0x1 # DW_LNCT_path + .uleb128 0x1f # DW_FORM_line_strp + .uleb128 0x2 # Directories count + .long .LASF1 # Directory Entry: 0: "" + .long .LASF4 # Directory Entry: 0: "" + .byte 0x2 # File name entry format count + .uleb128 0x1 # DW_LNCT_path + .uleb128 0x1f # DW_FORM_line_strp + .uleb128 0x2 # DW_LNCT_directory_index + .uleb128 0xb # DW_FORM_data1 + .uleb128 0x2 # File names count + .long .LASF0 # File Entry: 0: "main.c" + .byte 0 + .long .LASF5 # File Entry: 0: "main.c" + .byte 0x1 +.LELTP0: + .byte 0 # set address *.LM1 + .uleb128 0x9 + .byte 0x2 + .quad .LM1 + .byte 0x1 # copy line 1 + .byte 0x5 # column 12 + .uleb128 0xc # 12 + .byte 0 # set address *.LM2 + .uleb128 0x9 + .byte 0x2 + .quad .LM2 + .byte 0x1 # copy line 1 + .byte 0x5 # column 13 + .uleb128 0xd # 13 + .byte 0 # set address *.Letext0 + .uleb128 0x9 + .byte 0x2 + .quad .Letext0 + .byte 0 # end sequence + .uleb128 0x1 + .byte 0x1 +.LELT0: + .section .debug_str,"MS",@progbits,1 +.LASF2: + .string "GNU C17 11.0.0 20210210 (Red Hat 11.0.0-0) -mtune=generic -march=x86-64 -gdwarf-5 -gno-as-loc-support" +.LASF3: + .string "main" + .section .debug_line_str,"MS",@progbits,1 +.LASF1: + .string "" +.LASF4: + .string "" +.LASF0: + .string "main.c" +.LASF5: + .string "main.c" + .ident "GCC: (GNU) 11.0.0 20210210 (Red Hat 11.0.0-0)" + .section .note.GNU-stack,"",@progbits Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h @@ -28,6 +28,11 @@ const char *cstr; } value; const uint8_t *data; + bool operator==(const ValueTypeTag &rhs) const { + static_assert(sizeof(value.uval) >= sizeof(value.cstr), + "uval needs to contain whole cstr"); + return data == rhs.data && value.uval == rhs.value.uval; + } } ValueType; enum { Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -432,7 +432,7 @@ } LLVM_FALLTHROUGH; default: - attributes.Append(cu, offset, attr, form); + attributes.Append(form_value, offset, attr); break; } Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h @@ -24,6 +24,7 @@ dw_attr_t get_attr() const { return m_attr; } dw_form_t get_form() const { return m_form; } + DWARFFormValue::ValueType get_value() const { return m_value; } void get(dw_attr_t &attr, dw_form_t &form, DWARFFormValue::ValueType &val) const { attr = m_attr; @@ -31,7 +32,8 @@ val = m_value; } bool operator==(const DWARFAttribute &rhs) const { - return m_attr == rhs.m_attr && m_form == rhs.m_form; + return m_attr == rhs.m_attr && m_form == rhs.m_form && + m_value == rhs.m_value; } typedef std::vector<DWARFAttribute> collection; typedef collection::iterator iterator; @@ -48,8 +50,8 @@ DWARFAttributes(); ~DWARFAttributes(); - void Append(DWARFUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, - dw_form_t form); + void Append(const DWARFFormValue &form_value, dw_offset_t attr_die_offset, + dw_attr_t attr); DWARFUnit *CompileUnitAtIndex(uint32_t i) const { return m_infos[i].cu; } dw_offset_t DIEOffsetAtIndex(uint32_t i) const { return m_infos[i].die_offset; @@ -58,6 +60,9 @@ return m_infos[i].attr.get_attr(); } dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); } + DWARFFormValue::ValueType ValueAtIndex(uint32_t i) const { + return m_infos[i].attr.get_value(); + } bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const; DWARFDIE FormValueAsReferenceAtIndex(uint32_t i) const; DWARFDIE FormValueAsReference(dw_attr_t attr) const; Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp @@ -25,10 +25,11 @@ return UINT32_MAX; } -void DWARFAttributes::Append(DWARFUnit *cu, dw_offset_t attr_die_offset, - dw_attr_t attr, dw_form_t form) { - AttributeValue attr_value = { - cu, attr_die_offset, {attr, form, DWARFFormValue::ValueType()}}; +void DWARFAttributes::Append(const DWARFFormValue &form_value, + dw_offset_t attr_die_offset, dw_attr_t attr) { + AttributeValue attr_value = {const_cast<DWARFUnit *>(form_value.GetUnit()), + attr_die_offset, + {attr, form_value.Form(), form_value.Value()}}; m_infos.push_back(attr_value); } @@ -37,6 +38,10 @@ const DWARFUnit *cu = CompileUnitAtIndex(i); form_value.SetUnit(cu); form_value.SetForm(FormAtIndex(i)); + if (form_value.Form() == DW_FORM_implicit_const) { + form_value.SetValue(ValueAtIndex(i)); + return true; + } lldb::offset_t offset = DIEOffsetAtIndex(i); return form_value.ExtractValue(cu->GetData(), &offset); } Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp @@ -58,7 +58,7 @@ DWARFFormValue::ValueType val; if (form == DW_FORM_implicit_const) - val.value.sval = data.GetULEB128(offset_ptr); + val.value.sval = data.GetSLEB128(offset_ptr); m_attributes.push_back(DWARFAttribute(attr, form, val)); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits