1 //===-- SymbolFileDWARFDwp.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "SymbolFileDWARFDwp.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Section.h"
17 #include "lldb/Symbol/ObjectFile.h"
19 #include "SymbolFileDWARFDwoDwp.h"
21 static llvm::DWARFSectionKind
22 lldbSectTypeToLlvmSectionKind(lldb::SectionType type) {
24 case lldb::eSectionTypeDWARFDebugInfo:
25 return llvm::DW_SECT_INFO;
26 // case lldb::eSectionTypeDWARFDebugTypes:
27 // return llvm::DW_SECT_TYPES;
28 case lldb::eSectionTypeDWARFDebugAbbrev:
29 return llvm::DW_SECT_ABBREV;
30 case lldb::eSectionTypeDWARFDebugLine:
31 return llvm::DW_SECT_LINE;
32 case lldb::eSectionTypeDWARFDebugLoc:
33 return llvm::DW_SECT_LOC;
34 case lldb::eSectionTypeDWARFDebugStrOffsets:
35 return llvm::DW_SECT_STR_OFFSETS;
36 // case lldb::eSectionTypeDWARFDebugMacinfo:
37 // return llvm::DW_SECT_MACINFO;
38 case lldb::eSectionTypeDWARFDebugMacro:
39 return llvm::DW_SECT_MACRO;
41 // Note: 0 is an invalid dwarf section kind.
42 return llvm::DWARFSectionKind(0);
46 std::unique_ptr<SymbolFileDWARFDwp>
47 SymbolFileDWARFDwp::Create(lldb::ModuleSP module_sp,
48 const lldb_private::FileSpec &file_spec) {
49 const lldb::offset_t file_offset = 0;
50 lldb::DataBufferSP file_data_sp;
51 lldb::offset_t file_data_offset = 0;
52 lldb::ObjectFileSP obj_file = lldb_private::ObjectFile::FindPlugin(
53 module_sp, &file_spec, file_offset, file_spec.GetByteSize(), file_data_sp,
55 if (obj_file == nullptr)
58 std::unique_ptr<SymbolFileDWARFDwp> dwp_symfile(
59 new SymbolFileDWARFDwp(module_sp, obj_file));
61 lldb_private::DWARFDataExtractor debug_cu_index;
62 if (!dwp_symfile->LoadRawSectionData(lldb::eSectionTypeDWARFDebugCuIndex,
66 llvm::DataExtractor llvm_debug_cu_index(
67 llvm::StringRef(debug_cu_index.PeekCStr(0), debug_cu_index.GetByteSize()),
68 debug_cu_index.GetByteOrder() == lldb::eByteOrderLittle,
69 debug_cu_index.GetAddressByteSize());
70 if (!dwp_symfile->m_debug_cu_index.parse(llvm_debug_cu_index))
72 dwp_symfile->InitDebugCUIndexMap();
76 void SymbolFileDWARFDwp::InitDebugCUIndexMap() {
77 m_debug_cu_index_map.clear();
78 for (const auto &entry : m_debug_cu_index.getRows())
79 m_debug_cu_index_map.emplace(entry.getSignature(), &entry);
82 SymbolFileDWARFDwp::SymbolFileDWARFDwp(lldb::ModuleSP module_sp,
83 lldb::ObjectFileSP obj_file)
84 : m_obj_file(std::move(obj_file)), m_debug_cu_index(llvm::DW_SECT_INFO)
87 std::unique_ptr<SymbolFileDWARFDwo>
88 SymbolFileDWARFDwp::GetSymbolFileForDwoId(DWARFUnit *dwarf_cu,
90 return std::unique_ptr<SymbolFileDWARFDwo>(
91 new SymbolFileDWARFDwoDwp(this, m_obj_file, dwarf_cu, dwo_id));
94 bool SymbolFileDWARFDwp::LoadSectionData(
95 uint64_t dwo_id, lldb::SectionType sect_type,
96 lldb_private::DWARFDataExtractor &data) {
97 lldb_private::DWARFDataExtractor section_data;
98 if (!LoadRawSectionData(sect_type, section_data))
101 auto it = m_debug_cu_index_map.find(dwo_id);
102 if (it == m_debug_cu_index_map.end())
106 it->second->getOffset(lldbSectTypeToLlvmSectionKind(sect_type));
108 data.SetData(section_data, offsets->Offset, offsets->Length);
110 data.SetData(section_data, 0, section_data.GetByteSize());
115 bool SymbolFileDWARFDwp::LoadRawSectionData(
116 lldb::SectionType sect_type, lldb_private::DWARFDataExtractor &data) {
117 std::lock_guard<std::mutex> lock(m_sections_mutex);
119 auto it = m_sections.find(sect_type);
120 if (it != m_sections.end()) {
121 if (it->second.GetByteSize() == 0)
128 const lldb_private::SectionList *section_list =
129 m_obj_file->GetSectionList(false /* update_module_section_list */);
131 lldb::SectionSP section_sp(
132 section_list->FindSectionByType(sect_type, true));
134 if (m_obj_file->ReadSectionData(section_sp.get(), data) != 0) {
135 m_sections[sect_type] = data;
140 m_sections[sect_type].Clear();