LLDB mainline
DWARFContext.cpp
Go to the documentation of this file.
1//===-- DWARFContext.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "DWARFContext.h"
10
11#include "lldb/Core/Section.h"
12#include <optional>
13
14using namespace lldb;
15using namespace lldb_private;
16
18 SectionType section_type) {
19 if (!section_list)
20 return DWARFDataExtractor();
21
22 auto section_sp = section_list->FindSectionByType(section_type, true);
23 if (!section_sp)
24 return DWARFDataExtractor();
25
27 section_sp->GetSectionData(data);
28 return data;
29}
30
32DWARFContext::LoadOrGetSection(std::optional<SectionType> main_section_type,
33 std::optional<SectionType> dwo_section_type,
34 SectionData &data) {
35 llvm::call_once(data.flag, [&] {
36 if (dwo_section_type && isDwo())
37 data.data = LoadSection(m_dwo_section_list, *dwo_section_type);
38 else if (main_section_type)
39 data.data = LoadSection(m_main_section_list, *main_section_type);
40 });
41 return data.data;
42}
43
47}
48
52}
53
57}
58
62}
63
67}
68
72}
73
77}
78
82}
83
87}
88
93}
94
98}
99
103}
104
109}
110
114}
115
120}
121
125}
126
127llvm::DWARFContext &DWARFContext::GetAsLLVM() {
128 if (!m_llvm_context) {
129 llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> section_map;
130 uint8_t addr_size = 0;
131 auto AddSection = [&](llvm::StringRef name, DWARFDataExtractor data) {
132 // Set the address size the first time we see it.
133 if (addr_size == 0)
134 addr_size = data.GetAddressByteSize();
135
136 section_map.try_emplace(
137 name, llvm::MemoryBuffer::getMemBuffer(toStringRef(data.GetData()),
138 name, false));
139 };
140
141 AddSection("debug_line_str", getOrLoadLineStrData());
142 AddSection("debug_cu_index", getOrLoadCuIndexData());
143 AddSection("debug_tu_index", getOrLoadTuIndexData());
144
145 m_llvm_context = llvm::DWARFContext::create(section_map, addr_size);
146 }
147 return *m_llvm_context;
148}
static DWARFDataExtractor LoadSection(SectionList *section_list, SectionType section_type)
const DWARFDataExtractor & getOrLoadLineData()
const DWARFDataExtractor & getOrLoadTuIndexData()
std::unique_ptr< llvm::DWARFContext > m_llvm_context
Definition: DWARFContext.h:24
SectionData m_data_debug_rnglists
Definition: DWARFContext.h:42
SectionData m_data_debug_cu_index
Definition: DWARFContext.h:34
const DWARFDataExtractor & getOrLoadLocListsData()
SectionData m_data_debug_str_offsets
Definition: DWARFContext.h:44
const DWARFDataExtractor & getOrLoadStrOffsetsData()
const DWARFDataExtractor & getOrLoadCuIndexData()
const DWARFDataExtractor & getOrLoadStrData()
llvm::DWARFContext & GetAsLLVM()
SectionData m_data_debug_abbrev
Definition: DWARFContext.h:31
const DWARFDataExtractor & LoadOrGetSection(std::optional< lldb::SectionType > main_section_type, std::optional< lldb::SectionType > dwo_section_type, SectionData &data)
const DWARFDataExtractor & getOrLoadArangesData()
SectionData m_data_debug_tu_index
Definition: DWARFContext.h:45
const DWARFDataExtractor & getOrLoadDebugTypesData()
const DWARFDataExtractor & getOrLoadDebugInfoData()
const DWARFDataExtractor & getOrLoadRangesData()
SectionData m_data_debug_line_str
Definition: DWARFContext.h:37
const DWARFDataExtractor & getOrLoadRngListsData()
const DWARFDataExtractor & getOrLoadAbbrevData()
const DWARFDataExtractor & getOrLoadMacroData()
SectionData m_data_debug_ranges
Definition: DWARFContext.h:41
const DWARFDataExtractor & getOrLoadLocData()
SectionData m_data_debug_types
Definition: DWARFContext.h:46
SectionData m_data_debug_loclists
Definition: DWARFContext.h:39
const DWARFDataExtractor & getOrLoadLineStrData()
SectionData m_data_debug_aranges
Definition: DWARFContext.h:33
const DWARFDataExtractor & getOrLoadAddrData()
SectionData m_data_debug_macro
Definition: DWARFContext.h:40
lldb::SectionSP FindSectionByType(lldb::SectionType sect_type, bool check_children, size_t start_idx=0) const
Definition: Section.cpp:586
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
@ eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeDWARFDebugLocDwo
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
@ eSectionTypeDWARFDebugTypes
DWARF .debug_types section.
@ eSectionTypeDWARFDebugRngLists
DWARF v5 .debug_rnglists.
@ eSectionTypeDWARFDebugStrOffsetsDwo
@ eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugTypesDwo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRngListsDwo
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugTuIndex
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugLineStr
DWARF v5 .debug_line_str.
@ eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAbbrevDwo
@ eSectionTypeDWARFDebugStrDwo
@ eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDWARFDebugLocListsDwo
@ eSectionTypeDWARFDebugInfoDwo
@ eSectionTypeDWARFDebugAddr