1 //===-- CompactUnwindInfo.h -------------------------------------*- 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 #ifndef liblldb_CompactUnwindInfo_h_
11 #define liblldb_CompactUnwindInfo_h_
16 #include "lldb/Core/DataExtractor.h"
17 #include "lldb/Core/RangeMap.h"
18 #include "lldb/Symbol/ObjectFile.h"
19 #include "lldb/Symbol/UnwindPlan.h"
20 #include "lldb/lldb-private.h"
22 namespace lldb_private {
24 // Compact Unwind info is an unwind format used on Darwin. The unwind instructions
25 // for typical compiler-generated functions can be expressed in a 32-bit encoding.
26 // The format includes a two-level index so the unwind information for a function
27 // can be found by two binary searches in the section. It can represent both
28 // stack frames that use a frame-pointer register and frameless functions, on
29 // i386/x86_64 for instance. When a function is too complex to be represented in
30 // the compact unwind format, it calls out to eh_frame unwind instructions.
32 // On Mac OS X / iOS, a function will have either a compact unwind representation
33 // or an eh_frame representation. If lldb is going to benefit from the compiler's
34 // description about saved register locations, it must be able to read both
35 // sources of information.
37 class CompactUnwindInfo
41 CompactUnwindInfo (ObjectFile& objfile,
42 lldb::SectionSP& section);
47 GetUnwindPlan (Target &target, Address addr, UnwindPlan& unwind_plan);
50 IsValid (const lldb::ProcessSP &process_sp);
55 // The top level index entries of the compact unwind info
56 // (internal representation of struct unwind_info_section_header_index_entry)
57 // There are relatively few of these (one per 500/1000 functions, depending on format) so
58 // creating them on first scan will not be too costly.
61 uint32_t function_offset; // The offset of the first function covered by this index
62 uint32_t second_level; // The offset (inside unwind_info sect) to the second level page for this index
63 // (either UNWIND_SECOND_LEVEL_REGULAR or UNWIND_SECOND_LEVEL_COMPRESSED)
64 uint32_t lsda_array_start;// The offset (inside unwind_info sect) LSDA array for this index
65 uint32_t lsda_array_end; // The offset to the LSDA array for the NEXT index
66 bool sentinal_entry; // There is an empty index at the end which provides the upper bound of
67 // function addresses that are described
74 sentinal_entry (false)
78 operator< (const CompactUnwindInfo::UnwindIndex& rhs) const
80 return function_offset < rhs.function_offset;
84 operator== (const CompactUnwindInfo::UnwindIndex& rhs) const
86 return function_offset == rhs.function_offset;
91 // An internal object used to store the information we retrieve about a function --
92 // the encoding bits and possibly the LSDA/personality function.
95 uint32_t encoding; // compact encoding 32-bit value for this function
96 Address lsda_address; // the address of the LSDA data for this function
97 Address personality_ptr_address; // the address where the personality routine addr can be found
99 uint32_t valid_range_offset_start; // first offset that this encoding is valid for (start of the function)
100 uint32_t valid_range_offset_end; // the offset of the start of the next function
101 FunctionInfo () : encoding(0), lsda_address(), personality_ptr_address(), valid_range_offset_start(0), valid_range_offset_end(0) { }
107 uint32_t common_encodings_array_offset;
108 uint32_t common_encodings_array_count;
109 uint32_t personality_array_offset;
110 uint32_t personality_array_count;
112 UnwindHeader () : common_encodings_array_offset (0), common_encodings_array_count (0), personality_array_offset (0), personality_array_count (0) { }
116 ScanIndex(const lldb::ProcessSP &process_sp);
119 GetCompactUnwindInfoForFunction (Target &target, Address address, FunctionInfo &unwind_info);
122 BinarySearchRegularSecondPage (uint32_t entry_page_offset, uint32_t entry_count, uint32_t function_offset, uint32_t *entry_func_start_offset, uint32_t *entry_func_end_offset);
125 BinarySearchCompressedSecondPage (uint32_t entry_page_offset, uint32_t entry_count, uint32_t function_offset_to_find, uint32_t function_offset_base, uint32_t *entry_func_start_offset, uint32_t *entry_func_end_offset);
128 GetLSDAForFunctionOffset (uint32_t lsda_offset, uint32_t lsda_count, uint32_t function_offset);
131 CreateUnwindPlan_x86_64 (Target &target, FunctionInfo &function_info, UnwindPlan &unwind_plan, Address pc_or_function_start);
134 CreateUnwindPlan_i386 (Target &target, FunctionInfo &function_info, UnwindPlan &unwind_plan, Address pc_or_function_start);
137 CreateUnwindPlan_arm64 (Target &target, FunctionInfo &function_info, UnwindPlan &unwind_plan, Address pc_or_function_start);
140 CreateUnwindPlan_armv7 (Target &target, FunctionInfo &function_info, UnwindPlan &unwind_plan, Address pc_or_function_start);
142 ObjectFile &m_objfile;
143 lldb::SectionSP m_section_sp;
144 lldb::DataBufferSP m_section_contents_if_encrypted; // if the binary is encrypted, read the sect contents
145 // out of live memory and cache them here
147 std::vector<UnwindIndex> m_indexes;
149 LazyBool m_indexes_computed; // eLazyBoolYes once we've tried to parse the unwind info
150 // eLazyBoolNo means we cannot parse the unwind info & should not retry
151 // eLazyBoolCalculate means we haven't tried to parse it yet
153 DataExtractor m_unwindinfo_data;
154 bool m_unwindinfo_data_computed; // true once we've mapped in the unwindinfo data
156 UnwindHeader m_unwind_header;
159 } // namespace lldb_private
161 #endif // liblldb_CompactUnwindInfo_h_