File indexing completed on 2026-05-10 08:42:51
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_SYMBOL_DWARFCALLFRAMEINFO_H
0010 #define LLDB_SYMBOL_DWARFCALLFRAMEINFO_H
0011
0012 #include <map>
0013 #include <mutex>
0014 #include <optional>
0015
0016 #include "lldb/Core/AddressRange.h"
0017 #include "lldb/Core/dwarf.h"
0018 #include "lldb/Symbol/ObjectFile.h"
0019 #include "lldb/Symbol/UnwindPlan.h"
0020 #include "lldb/Utility/Flags.h"
0021 #include "lldb/Utility/RangeMap.h"
0022 #include "lldb/Utility/VMRange.h"
0023 #include "lldb/lldb-private.h"
0024
0025 namespace lldb_private {
0026
0027
0028
0029
0030
0031
0032
0033
0034 class DWARFCallFrameInfo {
0035 public:
0036 enum Type { EH, DWARF };
0037
0038 DWARFCallFrameInfo(ObjectFile &objfile, lldb::SectionSP §ion, Type type);
0039
0040 ~DWARFCallFrameInfo() = default;
0041
0042
0043
0044
0045 bool GetAddressRange(Address addr, AddressRange &range);
0046
0047
0048
0049
0050 bool GetUnwindPlan(const Address &addr, UnwindPlan &unwind_plan);
0051
0052
0053
0054
0055 bool GetUnwindPlan(const AddressRange &range, UnwindPlan &unwind_plan);
0056
0057 typedef RangeVector<lldb::addr_t, uint32_t> FunctionAddressAndSizeVector;
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 void
0074 GetFunctionAddressAndSizeVector(FunctionAddressAndSizeVector &function_info);
0075
0076 void ForEachFDEEntries(
0077 const std::function<bool(lldb::addr_t, uint32_t, dw_offset_t)> &callback);
0078
0079 private:
0080 enum { CFI_AUG_MAX_SIZE = 8, CFI_HEADER_SIZE = 8 };
0081 enum CFIVersion {
0082 CFI_VERSION1 = 1,
0083 CFI_VERSION3 = 3,
0084 CFI_VERSION4 = 4
0085 };
0086
0087 struct CIE {
0088 dw_offset_t cie_offset;
0089 uint8_t version;
0090 char augmentation[CFI_AUG_MAX_SIZE];
0091
0092 uint8_t address_size = sizeof(uint32_t);
0093 uint8_t segment_size = 0;
0094
0095 uint32_t code_align;
0096 int32_t data_align;
0097 uint32_t return_addr_reg_num;
0098 dw_offset_t inst_offset;
0099 uint32_t inst_length;
0100 uint8_t ptr_encoding;
0101 uint8_t lsda_addr_encoding;
0102
0103 lldb::addr_t personality_loc;
0104
0105 lldb_private::UnwindPlan::Row initial_row;
0106
0107 CIE(dw_offset_t offset)
0108 : cie_offset(offset), version(-1), code_align(0), data_align(0),
0109 return_addr_reg_num(LLDB_INVALID_REGNUM), inst_offset(0),
0110 inst_length(0), ptr_encoding(0),
0111 lsda_addr_encoding(llvm::dwarf::DW_EH_PE_omit),
0112 personality_loc(LLDB_INVALID_ADDRESS) {}
0113 };
0114
0115 typedef std::shared_ptr<CIE> CIESP;
0116
0117 typedef std::map<dw_offset_t, CIESP> cie_map_t;
0118
0119
0120
0121
0122 typedef RangeDataVector<lldb::addr_t, uint32_t, dw_offset_t> FDEEntryMap;
0123
0124 bool IsEHFrame() const;
0125
0126 std::optional<FDEEntryMap::Entry>
0127 GetFirstFDEEntryInRange(const AddressRange &range);
0128
0129 void GetFDEIndex();
0130
0131 bool FDEToUnwindPlan(dw_offset_t offset, Address startaddr,
0132 UnwindPlan &unwind_plan);
0133
0134 const CIE *GetCIE(dw_offset_t cie_offset);
0135
0136 void GetCFIData();
0137
0138
0139
0140
0141
0142
0143 bool HandleCommonDwarfOpcode(uint8_t primary_opcode, uint8_t extended_opcode,
0144 int32_t data_align, lldb::offset_t &offset,
0145 UnwindPlan::Row &row);
0146
0147 ObjectFile &m_objfile;
0148 lldb::SectionSP m_section_sp;
0149 Flags m_flags = 0;
0150 cie_map_t m_cie_map;
0151
0152 DataExtractor m_cfi_data;
0153 bool m_cfi_data_initialized = false;
0154
0155 FDEEntryMap m_fde_index;
0156 bool m_fde_index_initialized = false;
0157 std::mutex m_fde_index_mutex;
0158
0159 Type m_type;
0160
0161 CIESP
0162 ParseCIE(const dw_offset_t cie_offset);
0163
0164 lldb::RegisterKind GetRegisterKind() const {
0165 return m_type == EH ? lldb::eRegisterKindEHFrame : lldb::eRegisterKindDWARF;
0166 }
0167 };
0168
0169 }
0170
0171 #endif