LLDB mainline
DWARFCallFrameInfo.h
Go to the documentation of this file.
1//===-- DWARFCallFrameInfo.h ------------------------------------*- C++ -*-===//
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#ifndef LLDB_SYMBOL_DWARFCALLFRAMEINFO_H
10#define LLDB_SYMBOL_DWARFCALLFRAMEINFO_H
11
12#include <map>
13#include <mutex>
14#include <optional>
15
17#include "lldb/Core/dwarf.h"
20#include "lldb/Utility/Flags.h"
22#include "lldb/lldb-private.h"
23
24namespace lldb_private {
25
26// DWARFCallFrameInfo is a class which can read eh_frame and DWARF Call Frame
27// Information FDEs. It stores little information internally. Only two APIs
28// are exported - one to find the high/low pc values of a function given a text
29// address via the information in the eh_frame / debug_frame, and one to
30// generate an UnwindPlan based on the FDE in the eh_frame / debug_frame
31// section.
32
34public:
35 enum Type { EH, DWARF };
36
37 DWARFCallFrameInfo(ObjectFile &objfile, lldb::SectionSP &section, Type type);
38
40
41 // Locate an AddressRange that includes the provided Address in this object's
42 // eh_frame/debug_info Returns true if a range is found to cover that
43 // address.
44 bool GetAddressRange(Address addr, AddressRange &range);
45
46 /// Return an UnwindPlan based on the call frame information encoded in the
47 /// FDE of this DWARFCallFrameInfo section. The returned plan will be valid
48 /// (at least) for the given address.
49 std::unique_ptr<UnwindPlan> GetUnwindPlan(const Address &addr);
50
51 /// Return an UnwindPlan based on the call frame information encoded in the
52 /// FDE of this DWARFCallFrameInfo section. The returned plan will be valid
53 /// (at least) for some address in the given ranges. If no unwind information
54 /// is found, nullptr is returned. \a addr represents the entry point of the
55 /// function. It corresponds to the offset zero in the returned UnwindPlan.
56 std::unique_ptr<UnwindPlan> GetUnwindPlan(llvm::ArrayRef<AddressRange> ranges,
57 const Address &addr);
58
60
61 // Build a vector of file address and size for all functions in this Module
62 // based on the eh_frame FDE entries.
63 //
64 // The eh_frame information can be a useful source of file address and size
65 // of the functions in a Module. Often a binary's non-exported symbols are
66 // stripped before shipping so lldb won't know the start addr / size of many
67 // functions in the Module. But the eh_frame can help to give the addresses
68 // of these stripped symbols, at least.
69 //
70 // \param[out] function_info
71 // A vector provided by the caller is filled out. May be empty if no
72 // FDEs/no eh_frame
73 // is present in this Module.
74
75 void
77
79 const std::function<bool(lldb::addr_t, uint32_t, dw_offset_t)> &callback);
80
81private:
84 CFI_VERSION1 = 1, // DWARF v.2
85 CFI_VERSION3 = 3, // DWARF v.3
86 CFI_VERSION4 = 4 // DWARF v.4, v.5
87 };
88
89 struct CIE {
91 uint8_t version;
92 char augmentation[CFI_AUG_MAX_SIZE]; // This is typically empty or very
93 // short.
94 uint8_t address_size = sizeof(uint32_t); // The size of a target address.
95 uint8_t segment_size = 0; // The size of a segment selector.
96
97 uint32_t code_align;
98 int32_t data_align;
100 dw_offset_t inst_offset; // offset of CIE instructions in mCFIData
101 uint32_t inst_length; // length of CIE instructions in mCFIData
103 uint8_t lsda_addr_encoding; // The encoding of the LSDA address in the FDE
104 // augmentation data
105 lldb::addr_t personality_loc; // (file) address of the pointer to the
106 // personality routine
108
115 };
116
117 typedef std::shared_ptr<CIE> CIESP;
118
119 typedef std::map<dw_offset_t, CIESP> cie_map_t;
120
121 // Start address (file address), size, offset of FDE location used for
122 // finding an FDE for a given File address; the start address field is an
123 // offset into an individual Module.
125
126 bool IsEHFrame() const;
127
128 std::optional<FDEEntryMap::Entry>
130
131 void GetFDEIndex();
132
133 /// Parsed representation of a Frame Descriptor Entry.
134 struct FDE {
136 bool for_signal_trap = false;
138 std::vector<UnwindPlan::Row> rows;
139 };
140 std::optional<FDE> ParseFDE(dw_offset_t offset, const Address &startaddr);
141
142 const CIE *GetCIE(dw_offset_t cie_offset);
143
144 void GetCFIData();
145
146 // Applies the specified DWARF opcode to the given row. This function handle
147 // the commands operates only on a single row (these are the ones what can
148 // appear both in
149 // CIE and in FDE).
150 // Returns true if the opcode is handled and false otherwise.
151 bool HandleCommonDwarfOpcode(uint8_t primary_opcode, uint8_t extended_opcode,
152 int32_t data_align, lldb::offset_t &offset,
153 UnwindPlan::Row &row);
154
159
161 bool m_cfi_data_initialized = false; // only copy the section into the DE once
162
164 bool m_fde_index_initialized = false; // only scan the section for FDEs once
165 std::mutex m_fde_index_mutex; // and isolate the thread that does it
166
168
169 CIESP
170 ParseCIE(const dw_offset_t cie_offset);
171
175};
176
177} // namespace lldb_private
178
179#endif // LLDB_SYMBOL_DWARFCALLFRAMEINFO_H
A section + offset based address range class.
A section + offset based address class.
Definition Address.h:62
lldb::RegisterKind GetRegisterKind() const
RangeDataVector< lldb::addr_t, uint32_t, dw_offset_t > FDEEntryMap
CIESP ParseCIE(const dw_offset_t cie_offset)
void GetFunctionAddressAndSizeVector(FunctionAddressAndSizeVector &function_info)
std::optional< FDEEntryMap::Entry > GetFirstFDEEntryInRange(const AddressRange &range)
void ForEachFDEEntries(const std::function< bool(lldb::addr_t, uint32_t, dw_offset_t)> &callback)
const CIE * GetCIE(dw_offset_t cie_offset)
std::map< dw_offset_t, CIESP > cie_map_t
bool GetAddressRange(Address addr, AddressRange &range)
DWARFCallFrameInfo(ObjectFile &objfile, lldb::SectionSP &section, Type type)
RangeVector< lldb::addr_t, uint32_t > FunctionAddressAndSizeVector
std::unique_ptr< UnwindPlan > GetUnwindPlan(const Address &addr)
Return an UnwindPlan based on the call frame information encoded in the FDE of this DWARFCallFrameInf...
std::optional< FDE > ParseFDE(dw_offset_t offset, const Address &startaddr)
bool HandleCommonDwarfOpcode(uint8_t primary_opcode, uint8_t extended_opcode, int32_t data_align, lldb::offset_t &offset, UnwindPlan::Row &row)
An data extractor class.
A class to manage flags.
Definition Flags.h:22
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
uint64_t dw_offset_t
Definition dwarf.h:24
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
RegisterKind
Register numbering types.
@ eRegisterKindDWARF
the register numbers seen DWARF
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
lldb_private::UnwindPlan::Row initial_row
Parsed representation of a Frame Descriptor Entry.
std::vector< UnwindPlan::Row > rows