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;
16using namespace lldb_private::plugin::dwarf;
17
19 SectionType section_type) {
20 if (!section_list)
21 return DWARFDataExtractor();
22
23 auto section_sp = section_list->FindSectionByType(section_type, true);
24 if (!section_sp)
25 return DWARFDataExtractor();
26
28 section_sp->GetSectionData(data);
29 return data;
30}
31
33DWARFContext::LoadOrGetSection(std::optional<SectionType> main_section_type,
34 std::optional<SectionType> dwo_section_type,
35 SectionData &data) {
36 llvm::call_once(data.flag, [&] {
37 if (dwo_section_type && isDwo())
38 data.data = LoadSection(m_dwo_section_list, *dwo_section_type);
39 else if (main_section_type)
40 data.data = LoadSection(m_main_section_list, *main_section_type);
41 });
42 return data.data;
43}
44
48}
49
53}
54
58}
59
63}
64
68}
69
73}
74
78}
79
83}
84
88}
89
94}
95
99}
100
104}
105
110}
111
115}
116
121}
122
126}
127
128llvm::DWARFContext &DWARFContext::GetAsLLVM() {
129 if (!m_llvm_context) {
130 llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> section_map;
131 uint8_t addr_size = 0;
132 auto AddSection = [&](llvm::StringRef name, DWARFDataExtractor data) {
133 // Set the address size the first time we see it.
134 if (addr_size == 0)
135 addr_size = data.GetAddressByteSize();
136
137 section_map.try_emplace(
138 name, llvm::MemoryBuffer::getMemBuffer(toStringRef(data.GetData()),
139 name, false));
140 };
141
142 AddSection("debug_line_str", getOrLoadLineStrData());
143 AddSection("debug_cu_index", getOrLoadCuIndexData());
144 AddSection("debug_tu_index", getOrLoadTuIndexData());
145 if (isDwo()) {
146 AddSection("debug_info.dwo", getOrLoadDebugInfoData());
147 AddSection("debug_types.dwo", getOrLoadDebugTypesData());
148 }
149 m_llvm_context = llvm::DWARFContext::create(section_map, addr_size);
150 }
151 return *m_llvm_context;
152}
static DWARFDataExtractor LoadSection(SectionList *section_list, SectionType section_type)
lldb::SectionSP FindSectionByType(lldb::SectionType sect_type, bool check_children, size_t start_idx=0) const
Definition: Section.cpp:592
const DWARFDataExtractor & getOrLoadLineData()
const DWARFDataExtractor & getOrLoadTuIndexData()
const DWARFDataExtractor & getOrLoadLocListsData()
const DWARFDataExtractor & getOrLoadStrOffsetsData()
const DWARFDataExtractor & getOrLoadCuIndexData()
std::unique_ptr< llvm::DWARFContext > m_llvm_context
Definition: DWARFContext.h:25
const DWARFDataExtractor & getOrLoadStrData()
const DWARFDataExtractor & LoadOrGetSection(std::optional< lldb::SectionType > main_section_type, std::optional< lldb::SectionType > dwo_section_type, SectionData &data)
const DWARFDataExtractor & getOrLoadArangesData()
const DWARFDataExtractor & getOrLoadDebugTypesData()
const DWARFDataExtractor & getOrLoadDebugInfoData()
const DWARFDataExtractor & getOrLoadRangesData()
const DWARFDataExtractor & getOrLoadRngListsData()
const DWARFDataExtractor & getOrLoadAbbrevData()
const DWARFDataExtractor & getOrLoadMacroData()
const DWARFDataExtractor & getOrLoadLocData()
const DWARFDataExtractor & getOrLoadLineStrData()
const DWARFDataExtractor & getOrLoadAddrData()
A class that represents a running process on the host machine.
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