Skip to content

Commit

Permalink
[LLDB] - Improved DWARF5 support.
Browse files Browse the repository at this point in the history
This patch improves the support of DWARF5.
Particularly the reporting of source code locations.

Differential revision: https://reviews.llvm.org/D51935

llvm-svn: 342153
  • Loading branch information
George Rimar committed Sep 13, 2018
1 parent f353ae1 commit c6c7bfc
Show file tree
Hide file tree
Showing 18 changed files with 393 additions and 81 deletions.
5 changes: 3 additions & 2 deletions lldb/include/lldb/lldb-enumerations.h
Expand Up @@ -57,7 +57,7 @@ enum StateType {
eStateSuspended, ///< Process or thread is in a suspended state as far
///< as the debugger is concerned while other processes
///< or threads get the chance to run.
kLastStateType = eStateSuspended
kLastStateType = eStateSuspended
};

//----------------------------------------------------------------------
Expand Down Expand Up @@ -672,7 +672,8 @@ enum SectionType {
eSectionTypeDWARFGNUDebugAltLink,
eSectionTypeDWARFDebugTypes, // DWARF .debug_types section
eSectionTypeDWARFDebugNames, // DWARF v5 .debug_names
eSectionTypeOther
eSectionTypeOther,
eSectionTypeDWARFDebugLineStr, // DWARF v5 .debug_line_str
};

FLAGS_ENUM(EmulateInstructionOptions){
Expand Down
@@ -0,0 +1,34 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *

# This test checks that source code location is shown correctly
# when DWARF5 debug information is used.

class TestTargetSourceMap(TestBase):

mydir = TestBase.compute_mydir(__file__)

def test_source_map(self):
# Set the target soure map to map "./" to the current test directory.
yaml_path = os.path.join(self.getSourceDir(), "a.yaml")
yaml_base, ext = os.path.splitext(yaml_path)
obj_path = self.getBuildArtifact(yaml_base)
self.yaml2obj(yaml_path, obj_path)

def cleanup():
if os.path.exists(obj_path):
os.unlink(obj_path)

# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)

# Create a target with the object file we just created from YAML
target = self.dbg.CreateTarget(obj_path)

# Check we are able to show the locations properly.
self.expect("b main", VALID_BREAKPOINT_LOCATION,
substrs=['main + 13 at test.cpp:2:3, address = 0x000000000040052d'])

self.expect("b foo", VALID_BREAKPOINT_LOCATION,
substrs=['foo() + 4 at test.cpp:6:1, address = 0x0000000000400534'])
@@ -0,0 +1,58 @@
# This file is a shorten version of the output
# produced with the following invocations and input:
# ./clang test.cpp -g -gdwarf-5 -o test.exe
# ./obj2yaml test.exe > test.yaml
#
# // test.cpp
# int main() {
# return 0;
# }
#
# void foo() {
# }

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Entry: 0x0000000000400440
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x0000000000400440
AddressAlign: 0x0000000000000010
Content: 31ED4989D15E4889E24883E4F0505449C7C0B005400048C7C14005400048C7C720054000E8B7FFFFFFF4660F1F44000055B820204000483D202040004889E57417B8000000004885C0740D5DBF20204000FFE00F1F4400005DC3660F1F440000BE20204000554881EE202040004889E548C1FE034889F048C1E83F4801C648D1FE7415B8000000004885C0740B5DBF20204000FFE00F1F005DC3660F1F440000803D391B0000007517554889E5E87EFFFFFFC605271B0000015DC30F1F440000F3C30F1F4000662E0F1F840000000000554889E55DEB89660F1F840000000000554889E531C0C745FC000000005DC390554889E55DC3662E0F1F840000000000415741564189FF415541544C8D25B618000055488D2DB6180000534989F64989D54C29E54883EC0848C1FD03E87FFEFFFF4885ED742031DB0F1F8400000000004C89EA4C89F64489FF41FF14DC4883C3014839EB75EA4883C4085B5D415C415D415E415FC390662E0F1F840000000000F3C3
- Name: .debug_str_offsets
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: 200000000500000000000000230000002C0000004A0000004F000000530000005B000000
- Name: .debug_str
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x0000000000000001
Content: 636C616E672076657273696F6E20382E302E3020287472756E6B203334313935382900746573742E637070002F686F6D652F756D622F4C4C564D2F6275696C645F6C6C64622F62696E006D61696E00696E74005F5A33666F6F7600666F6F00
- Name: .debug_abbrev
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: 011101252513050325721710171B25110112060000022E0011011206401803253A0B3B0B49133F190000032E001101120640186E2503253A0B3B0B3F19000004240003253E0B0B0B000000
- Name: .debug_info
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: 50000000050001080000000001000400010800000000000000022005400000000000160000000220054000000000000F00000001560301014F000000033005400000000000060000000156050601050404050400
- Name: .debug_macinfo
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: '00'
- Name: .debug_line
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: 70000000050008004C000000010101FB0E0D00010101010000000100000101011F010000000003011F020F051E021E00000000FD7C0F2E46BA561F7BDA351B04E677091E00000000FD7C0F2E46BA561F7BDA351B04E6770900090220054000000000000105030AC905003F05010A4B0202000101
- Name: .debug_line_str
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x0000000000000001
Content: 2F686F6D652F756D622F4C4C564D2F6275696C645F6C6C64622F62696E00746573742E63707000
...
2 changes: 2 additions & 0 deletions lldb/source/Core/Section.cpp
Expand Up @@ -73,6 +73,8 @@ const char *Section::GetTypeAsCString() const {
return "dwarf-info";
case eSectionTypeDWARFDebugLine:
return "dwarf-line";
case eSectionTypeDWARFDebugLineStr:
return "dwarf-line-str";
case eSectionTypeDWARFDebugLoc:
return "dwarf-loc";
case eSectionTypeDWARFDebugMacInfo:
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Expand Up @@ -1788,6 +1788,7 @@ void ObjectFileELF::CreateSections(SectionList &unified_section_list) {
static ConstString g_sect_name_dwarf_debug_frame(".debug_frame");
static ConstString g_sect_name_dwarf_debug_info(".debug_info");
static ConstString g_sect_name_dwarf_debug_line(".debug_line");
static ConstString g_sect_name_dwarf_debug_line_str(".debug_line_str");
static ConstString g_sect_name_dwarf_debug_loc(".debug_loc");
static ConstString g_sect_name_dwarf_debug_macinfo(".debug_macinfo");
static ConstString g_sect_name_dwarf_debug_macro(".debug_macro");
Expand All @@ -1802,6 +1803,7 @@ void ObjectFileELF::CreateSections(SectionList &unified_section_list) {
".debug_abbrev.dwo");
static ConstString g_sect_name_dwarf_debug_info_dwo(".debug_info.dwo");
static ConstString g_sect_name_dwarf_debug_line_dwo(".debug_line.dwo");
static ConstString g_sect_name_dwarf_debug_line_str_dwo(".debug_line_str.dwo");
static ConstString g_sect_name_dwarf_debug_macro_dwo(".debug_macro.dwo");
static ConstString g_sect_name_dwarf_debug_loc_dwo(".debug_loc.dwo");
static ConstString g_sect_name_dwarf_debug_str_dwo(".debug_str.dwo");
Expand Down Expand Up @@ -1861,6 +1863,8 @@ void ObjectFileELF::CreateSections(SectionList &unified_section_list) {
sect_type = eSectionTypeDWARFDebugInfo;
else if (name == g_sect_name_dwarf_debug_line)
sect_type = eSectionTypeDWARFDebugLine;
else if (name == g_sect_name_dwarf_debug_line_str)
sect_type = eSectionTypeDWARFDebugLineStr;
else if (name == g_sect_name_dwarf_debug_loc)
sect_type = eSectionTypeDWARFDebugLoc;
else if (name == g_sect_name_dwarf_debug_macinfo)
Expand All @@ -1887,6 +1891,8 @@ void ObjectFileELF::CreateSections(SectionList &unified_section_list) {
sect_type = eSectionTypeDWARFDebugInfo;
else if (name == g_sect_name_dwarf_debug_line_dwo)
sect_type = eSectionTypeDWARFDebugLine;
else if (name == g_sect_name_dwarf_debug_line_str_dwo)
sect_type = eSectionTypeDWARFDebugLineStr;
else if (name == g_sect_name_dwarf_debug_macro_dwo)
sect_type = eSectionTypeDWARFDebugMacro;
else if (name == g_sect_name_dwarf_debug_loc_dwo)
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Expand Up @@ -1197,6 +1197,7 @@ AddressClass ObjectFileMachO::GetAddressClass(lldb::addr_t file_addr) {
case eSectionTypeDWARFDebugFrame:
case eSectionTypeDWARFDebugInfo:
case eSectionTypeDWARFDebugLine:
case eSectionTypeDWARFDebugLineStr:
case eSectionTypeDWARFDebugLoc:
case eSectionTypeDWARFDebugMacInfo:
case eSectionTypeDWARFDebugMacro:
Expand Down
31 changes: 29 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
Expand Up @@ -34,8 +34,18 @@ DWARFUnitSP DWARFCompileUnit::Extract(SymbolFileDWARF *dwarf2Data,
cu_sp->m_length = debug_info.GetDWARFInitialLength(offset_ptr);
cu_sp->m_is_dwarf64 = debug_info.IsDWARF64();
cu_sp->m_version = debug_info.GetU16(offset_ptr);
abbr_offset = debug_info.GetDWARFOffset(offset_ptr);
cu_sp->m_addr_size = debug_info.GetU8(offset_ptr);

if (cu_sp->m_version == 5) {
cu_sp->m_unit_type = debug_info.GetU8(offset_ptr);
cu_sp->m_addr_size = debug_info.GetU8(offset_ptr);
abbr_offset = debug_info.GetDWARFOffset(offset_ptr);

if (cu_sp->m_unit_type == llvm::dwarf::DW_UT_skeleton)
cu_sp->m_dwo_id = debug_info.GetU64(offset_ptr);
} else {
abbr_offset = debug_info.GetDWARFOffset(offset_ptr);
cu_sp->m_addr_size = debug_info.GetU8(offset_ptr);
}

bool length_OK =
debug_info.ValidOffset(cu_sp->GetNextCompileUnitOffset() - 1);
Expand Down Expand Up @@ -65,6 +75,23 @@ void DWARFCompileUnit::Dump(Stream *s) const {
GetNextCompileUnitOffset());
}

uint32_t DWARFCompileUnit::GetHeaderByteSize() const {
if (m_version < 5)
return m_is_dwarf64 ? 23 : 11;

switch (m_unit_type) {
case llvm::dwarf::DW_UT_compile:
case llvm::dwarf::DW_UT_partial:
return 12;
case llvm::dwarf::DW_UT_skeleton:
case llvm::dwarf::DW_UT_split_compile:
return 20;
case llvm::dwarf::DW_UT_type:
case llvm::dwarf::DW_UT_split_type:
return 24;
}
llvm_unreachable("invalid UnitType.");
}

const lldb_private::DWARFDataExtractor &DWARFCompileUnit::GetData() const {
return m_dwarf->get_debug_info_data();
Expand Down
4 changes: 1 addition & 3 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
Expand Up @@ -35,9 +35,7 @@ class DWARFCompileUnit : public DWARFUnit {
/// @return
/// Byte size of the compile unit header
//------------------------------------------------------------------
uint32_t GetHeaderByteSize() const override {
return m_is_dwarf64 ? 23 : 11;
}
uint32_t GetHeaderByteSize() const override;

private:
DWARFCompileUnit(SymbolFileDWARF *dwarf2Data);
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
Expand Up @@ -122,18 +122,25 @@ bool DWARFDebugInfoEntry::FastExtract(
case DW_FORM_data1:
case DW_FORM_flag:
case DW_FORM_ref1:
case DW_FORM_strx1:
form_size = 1;
break;

// 2 byte values
case DW_FORM_data2:
case DW_FORM_ref2:
case DW_FORM_strx2:
form_size = 2;
break;

case DW_FORM_strx3:
form_size = 3;
break;

// 4 byte values
case DW_FORM_data4:
case DW_FORM_ref4:
case DW_FORM_strx4:
form_size = 4;
break;

Expand All @@ -150,6 +157,7 @@ bool DWARFDebugInfoEntry::FastExtract(
case DW_FORM_ref_udata:
case DW_FORM_GNU_addr_index:
case DW_FORM_GNU_str_index:
case DW_FORM_strx:
debug_info_data.Skip_LEB128(&offset);
break;

Expand Down

0 comments on commit c6c7bfc

Please sign in to comment.