1 //===-- CompactUnwindInfo.cpp -----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/CompactUnwindInfo.h"
10 #include "lldb/Core/Module.h"
11 #include "lldb/Core/Section.h"
12 #include "lldb/Symbol/ObjectFile.h"
13 #include "lldb/Symbol/UnwindPlan.h"
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/Target.h"
16 #include "lldb/Utility/ArchSpec.h"
17 #include "lldb/Utility/DataBufferHeap.h"
18 #include "lldb/Utility/Log.h"
19 #include "lldb/Utility/StreamString.h"
21 #include "llvm/Support/MathExtras.h"
27 using namespace lldb_private;
29 namespace lldb_private {
31 // Constants from <mach-o/compact_unwind_encoding.h>
33 FLAGS_ANONYMOUS_ENUM(){
34 UNWIND_IS_NOT_FUNCTION_START = 0x80000000, UNWIND_HAS_LSDA = 0x40000000,
35 UNWIND_PERSONALITY_MASK = 0x30000000,
38 FLAGS_ANONYMOUS_ENUM(){
39 UNWIND_X86_MODE_MASK = 0x0F000000,
40 UNWIND_X86_MODE_EBP_FRAME = 0x01000000,
41 UNWIND_X86_MODE_STACK_IMMD = 0x02000000,
42 UNWIND_X86_MODE_STACK_IND = 0x03000000,
43 UNWIND_X86_MODE_DWARF = 0x04000000,
45 UNWIND_X86_EBP_FRAME_REGISTERS = 0x00007FFF,
46 UNWIND_X86_EBP_FRAME_OFFSET = 0x00FF0000,
48 UNWIND_X86_FRAMELESS_STACK_SIZE = 0x00FF0000,
49 UNWIND_X86_FRAMELESS_STACK_ADJUST = 0x0000E000,
50 UNWIND_X86_FRAMELESS_STACK_REG_COUNT = 0x00001C00,
51 UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF,
53 UNWIND_X86_DWARF_SECTION_OFFSET = 0x00FFFFFF,
57 UNWIND_X86_REG_NONE = 0,
58 UNWIND_X86_REG_EBX = 1,
59 UNWIND_X86_REG_ECX = 2,
60 UNWIND_X86_REG_EDX = 3,
61 UNWIND_X86_REG_EDI = 4,
62 UNWIND_X86_REG_ESI = 5,
63 UNWIND_X86_REG_EBP = 6,
66 FLAGS_ANONYMOUS_ENUM(){
67 UNWIND_X86_64_MODE_MASK = 0x0F000000,
68 UNWIND_X86_64_MODE_RBP_FRAME = 0x01000000,
69 UNWIND_X86_64_MODE_STACK_IMMD = 0x02000000,
70 UNWIND_X86_64_MODE_STACK_IND = 0x03000000,
71 UNWIND_X86_64_MODE_DWARF = 0x04000000,
73 UNWIND_X86_64_RBP_FRAME_REGISTERS = 0x00007FFF,
74 UNWIND_X86_64_RBP_FRAME_OFFSET = 0x00FF0000,
76 UNWIND_X86_64_FRAMELESS_STACK_SIZE = 0x00FF0000,
77 UNWIND_X86_64_FRAMELESS_STACK_ADJUST = 0x0000E000,
78 UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT = 0x00001C00,
79 UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF,
81 UNWIND_X86_64_DWARF_SECTION_OFFSET = 0x00FFFFFF,
85 UNWIND_X86_64_REG_NONE = 0,
86 UNWIND_X86_64_REG_RBX = 1,
87 UNWIND_X86_64_REG_R12 = 2,
88 UNWIND_X86_64_REG_R13 = 3,
89 UNWIND_X86_64_REG_R14 = 4,
90 UNWIND_X86_64_REG_R15 = 5,
91 UNWIND_X86_64_REG_RBP = 6,
94 FLAGS_ANONYMOUS_ENUM(){
95 UNWIND_ARM64_MODE_MASK = 0x0F000000,
96 UNWIND_ARM64_MODE_FRAMELESS = 0x02000000,
97 UNWIND_ARM64_MODE_DWARF = 0x03000000,
98 UNWIND_ARM64_MODE_FRAME = 0x04000000,
100 UNWIND_ARM64_FRAME_X19_X20_PAIR = 0x00000001,
101 UNWIND_ARM64_FRAME_X21_X22_PAIR = 0x00000002,
102 UNWIND_ARM64_FRAME_X23_X24_PAIR = 0x00000004,
103 UNWIND_ARM64_FRAME_X25_X26_PAIR = 0x00000008,
104 UNWIND_ARM64_FRAME_X27_X28_PAIR = 0x00000010,
105 UNWIND_ARM64_FRAME_D8_D9_PAIR = 0x00000100,
106 UNWIND_ARM64_FRAME_D10_D11_PAIR = 0x00000200,
107 UNWIND_ARM64_FRAME_D12_D13_PAIR = 0x00000400,
108 UNWIND_ARM64_FRAME_D14_D15_PAIR = 0x00000800,
110 UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK = 0x00FFF000,
111 UNWIND_ARM64_DWARF_SECTION_OFFSET = 0x00FFFFFF,
114 FLAGS_ANONYMOUS_ENUM(){
115 UNWIND_ARM_MODE_MASK = 0x0F000000,
116 UNWIND_ARM_MODE_FRAME = 0x01000000,
117 UNWIND_ARM_MODE_FRAME_D = 0x02000000,
118 UNWIND_ARM_MODE_DWARF = 0x04000000,
120 UNWIND_ARM_FRAME_STACK_ADJUST_MASK = 0x00C00000,
122 UNWIND_ARM_FRAME_FIRST_PUSH_R4 = 0x00000001,
123 UNWIND_ARM_FRAME_FIRST_PUSH_R5 = 0x00000002,
124 UNWIND_ARM_FRAME_FIRST_PUSH_R6 = 0x00000004,
126 UNWIND_ARM_FRAME_SECOND_PUSH_R8 = 0x00000008,
127 UNWIND_ARM_FRAME_SECOND_PUSH_R9 = 0x00000010,
128 UNWIND_ARM_FRAME_SECOND_PUSH_R10 = 0x00000020,
129 UNWIND_ARM_FRAME_SECOND_PUSH_R11 = 0x00000040,
130 UNWIND_ARM_FRAME_SECOND_PUSH_R12 = 0x00000080,
132 UNWIND_ARM_FRAME_D_REG_COUNT_MASK = 0x00000700,
134 UNWIND_ARM_DWARF_SECTION_OFFSET = 0x00FFFFFF,
138 #ifndef UNWIND_SECOND_LEVEL_REGULAR
139 #define UNWIND_SECOND_LEVEL_REGULAR 2
142 #ifndef UNWIND_SECOND_LEVEL_COMPRESSED
143 #define UNWIND_SECOND_LEVEL_COMPRESSED 3
146 #ifndef UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET
147 #define UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(entry) (entry & 0x00FFFFFF)
150 #ifndef UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX
151 #define UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(entry) \
152 ((entry >> 24) & 0xFF)
155 #define EXTRACT_BITS(value, mask) \
157 llvm::countTrailingZeros(static_cast<uint32_t>(mask), llvm::ZB_Width)) & \
158 (((1 << llvm::countPopulation(static_cast<uint32_t>(mask)))) - 1))
162 CompactUnwindInfo::CompactUnwindInfo(ObjectFile &objfile, SectionSP §ion_sp)
163 : m_objfile(objfile), m_section_sp(section_sp),
164 m_section_contents_if_encrypted(), m_mutex(), m_indexes(),
165 m_indexes_computed(eLazyBoolCalculate), m_unwindinfo_data(),
166 m_unwindinfo_data_computed(false), m_unwind_header() {}
170 CompactUnwindInfo::~CompactUnwindInfo() {}
172 bool CompactUnwindInfo::GetUnwindPlan(Target &target, Address addr,
173 UnwindPlan &unwind_plan) {
174 if (!IsValid(target.GetProcessSP())) {
177 FunctionInfo function_info;
178 if (GetCompactUnwindInfoForFunction(target, addr, function_info)) {
179 // shortcut return for functions that have no compact unwind
180 if (function_info.encoding == 0)
183 if (ArchSpec arch = m_objfile.GetArchitecture()) {
185 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND));
186 if (log && log->GetVerbose()) {
190 Address::DumpStyle::DumpStyleResolvedDescriptionNoFunctionArguments,
191 Address::DumpStyle::DumpStyleFileAddress,
192 arch.GetAddressByteSize());
193 log->Printf("Got compact unwind encoding 0x%x for function %s",
194 function_info.encoding, strm.GetData());
197 if (function_info.valid_range_offset_start != 0 &&
198 function_info.valid_range_offset_end != 0) {
199 SectionList *sl = m_objfile.GetSectionList();
201 addr_t func_range_start_file_addr =
202 function_info.valid_range_offset_start +
203 m_objfile.GetBaseAddress().GetFileAddress();
204 AddressRange func_range(func_range_start_file_addr,
205 function_info.valid_range_offset_end -
206 function_info.valid_range_offset_start,
208 unwind_plan.SetPlanValidAddressRange(func_range);
212 if (arch.GetTriple().getArch() == llvm::Triple::x86_64) {
213 return CreateUnwindPlan_x86_64(target, function_info, unwind_plan,
216 if (arch.GetTriple().getArch() == llvm::Triple::aarch64) {
217 return CreateUnwindPlan_arm64(target, function_info, unwind_plan, addr);
219 if (arch.GetTriple().getArch() == llvm::Triple::x86) {
220 return CreateUnwindPlan_i386(target, function_info, unwind_plan, addr);
222 if (arch.GetTriple().getArch() == llvm::Triple::arm ||
223 arch.GetTriple().getArch() == llvm::Triple::thumb) {
224 return CreateUnwindPlan_armv7(target, function_info, unwind_plan, addr);
231 bool CompactUnwindInfo::IsValid(const ProcessSP &process_sp) {
232 if (m_section_sp.get() == nullptr)
235 if (m_indexes_computed == eLazyBoolYes && m_unwindinfo_data_computed)
238 ScanIndex(process_sp);
240 return m_indexes_computed == eLazyBoolYes && m_unwindinfo_data_computed;
243 void CompactUnwindInfo::ScanIndex(const ProcessSP &process_sp) {
244 std::lock_guard<std::mutex> guard(m_mutex);
245 if (m_indexes_computed == eLazyBoolYes && m_unwindinfo_data_computed)
248 // We can't read the index for some reason.
249 if (m_indexes_computed == eLazyBoolNo) {
253 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND));
255 m_objfile.GetModule()->LogMessage(
256 log, "Reading compact unwind first-level indexes");
258 if (!m_unwindinfo_data_computed) {
259 if (m_section_sp->IsEncrypted()) {
260 // Can't get section contents of a protected/encrypted section until we
261 // have a live process and can read them out of memory.
262 if (process_sp.get() == nullptr)
264 m_section_contents_if_encrypted =
265 std::make_shared<DataBufferHeap>(m_section_sp->GetByteSize(), 0);
267 if (process_sp->ReadMemory(
268 m_section_sp->GetLoadBaseAddress(&process_sp->GetTarget()),
269 m_section_contents_if_encrypted->GetBytes(),
270 m_section_sp->GetByteSize(),
271 error) == m_section_sp->GetByteSize() &&
273 m_unwindinfo_data.SetAddressByteSize(
274 process_sp->GetTarget().GetArchitecture().GetAddressByteSize());
275 m_unwindinfo_data.SetByteOrder(
276 process_sp->GetTarget().GetArchitecture().GetByteOrder());
277 m_unwindinfo_data.SetData(m_section_contents_if_encrypted, 0);
280 m_objfile.ReadSectionData(m_section_sp.get(), m_unwindinfo_data);
282 if (m_unwindinfo_data.GetByteSize() != m_section_sp->GetByteSize())
284 m_unwindinfo_data_computed = true;
287 if (m_unwindinfo_data.GetByteSize() > 0) {
290 // struct unwind_info_section_header
292 // uint32_t version; // UNWIND_SECTION_VERSION
293 // uint32_t commonEncodingsArraySectionOffset;
294 // uint32_t commonEncodingsArrayCount;
295 // uint32_t personalityArraySectionOffset;
296 // uint32_t personalityArrayCount;
297 // uint32_t indexSectionOffset;
298 // uint32_t indexCount;
300 m_unwind_header.version = m_unwindinfo_data.GetU32(&offset);
301 m_unwind_header.common_encodings_array_offset =
302 m_unwindinfo_data.GetU32(&offset);
303 m_unwind_header.common_encodings_array_count =
304 m_unwindinfo_data.GetU32(&offset);
305 m_unwind_header.personality_array_offset =
306 m_unwindinfo_data.GetU32(&offset);
307 m_unwind_header.personality_array_count = m_unwindinfo_data.GetU32(&offset);
308 uint32_t indexSectionOffset = m_unwindinfo_data.GetU32(&offset);
310 uint32_t indexCount = m_unwindinfo_data.GetU32(&offset);
312 if (m_unwind_header.common_encodings_array_offset >
313 m_unwindinfo_data.GetByteSize() ||
314 m_unwind_header.personality_array_offset >
315 m_unwindinfo_data.GetByteSize() ||
316 indexSectionOffset > m_unwindinfo_data.GetByteSize() ||
317 offset > m_unwindinfo_data.GetByteSize()) {
318 Host::SystemLog(Host::eSystemLogError, "error: Invalid offset "
319 "encountered in compact unwind "
321 // don't trust anything from this compact_unwind section if it looks
322 // blatantly invalid data in the header.
323 m_indexes_computed = eLazyBoolNo;
327 // Parse the basic information from the indexes We wait to scan the second
328 // level page info until it's needed
330 // struct unwind_info_section_header_index_entry {
331 // uint32_t functionOffset;
332 // uint32_t secondLevelPagesSectionOffset;
333 // uint32_t lsdaIndexArraySectionOffset;
336 bool clear_address_zeroth_bit = false;
337 if (ArchSpec arch = m_objfile.GetArchitecture()) {
338 if (arch.GetTriple().getArch() == llvm::Triple::arm ||
339 arch.GetTriple().getArch() == llvm::Triple::thumb)
340 clear_address_zeroth_bit = true;
343 offset = indexSectionOffset;
344 for (uint32_t idx = 0; idx < indexCount; idx++) {
345 uint32_t function_offset =
346 m_unwindinfo_data.GetU32(&offset); // functionOffset
347 uint32_t second_level_offset =
348 m_unwindinfo_data.GetU32(&offset); // secondLevelPagesSectionOffset
349 uint32_t lsda_offset =
350 m_unwindinfo_data.GetU32(&offset); // lsdaIndexArraySectionOffset
352 if (second_level_offset > m_section_sp->GetByteSize() ||
353 lsda_offset > m_section_sp->GetByteSize()) {
354 m_indexes_computed = eLazyBoolNo;
357 if (clear_address_zeroth_bit)
358 function_offset &= ~1ull;
360 UnwindIndex this_index;
361 this_index.function_offset = function_offset;
362 this_index.second_level = second_level_offset;
363 this_index.lsda_array_start = lsda_offset;
365 if (m_indexes.size() > 0) {
366 m_indexes[m_indexes.size() - 1].lsda_array_end = lsda_offset;
369 if (second_level_offset == 0) {
370 this_index.sentinal_entry = true;
373 m_indexes.push_back(this_index);
375 m_indexes_computed = eLazyBoolYes;
377 m_indexes_computed = eLazyBoolNo;
381 uint32_t CompactUnwindInfo::GetLSDAForFunctionOffset(uint32_t lsda_offset,
383 uint32_t function_offset) {
384 // struct unwind_info_section_header_lsda_index_entry {
385 // uint32_t functionOffset;
386 // uint32_t lsdaOffset;
389 offset_t first_entry = lsda_offset;
391 uint32_t high = lsda_count;
393 uint32_t mid = (low + high) / 2;
394 offset_t offset = first_entry + (mid * 8);
395 uint32_t mid_func_offset =
396 m_unwindinfo_data.GetU32(&offset); // functionOffset
397 uint32_t mid_lsda_offset = m_unwindinfo_data.GetU32(&offset); // lsdaOffset
398 if (mid_func_offset == function_offset) {
399 return mid_lsda_offset;
401 if (mid_func_offset < function_offset) {
410 lldb::offset_t CompactUnwindInfo::BinarySearchRegularSecondPage(
411 uint32_t entry_page_offset, uint32_t entry_count, uint32_t function_offset,
412 uint32_t *entry_func_start_offset, uint32_t *entry_func_end_offset) {
413 // typedef uint32_t compact_unwind_encoding_t;
414 // struct unwind_info_regular_second_level_entry {
415 // uint32_t functionOffset;
416 // compact_unwind_encoding_t encoding;
418 offset_t first_entry = entry_page_offset;
421 uint32_t high = entry_count;
422 uint32_t last = high - 1;
424 uint32_t mid = (low + high) / 2;
425 offset_t offset = first_entry + (mid * 8);
426 uint32_t mid_func_offset =
427 m_unwindinfo_data.GetU32(&offset); // functionOffset
428 uint32_t next_func_offset = 0;
430 offset = first_entry + ((mid + 1) * 8);
431 next_func_offset = m_unwindinfo_data.GetU32(&offset); // functionOffset
433 if (mid_func_offset <= function_offset) {
434 if (mid == last || (next_func_offset > function_offset)) {
435 if (entry_func_start_offset)
436 *entry_func_start_offset = mid_func_offset;
437 if (mid != last && entry_func_end_offset)
438 *entry_func_end_offset = next_func_offset;
439 return first_entry + (mid * 8);
447 return LLDB_INVALID_OFFSET;
450 uint32_t CompactUnwindInfo::BinarySearchCompressedSecondPage(
451 uint32_t entry_page_offset, uint32_t entry_count,
452 uint32_t function_offset_to_find, uint32_t function_offset_base,
453 uint32_t *entry_func_start_offset, uint32_t *entry_func_end_offset) {
454 offset_t first_entry = entry_page_offset;
457 uint32_t high = entry_count;
458 uint32_t last = high - 1;
460 uint32_t mid = (low + high) / 2;
461 offset_t offset = first_entry + (mid * 4);
462 uint32_t entry = m_unwindinfo_data.GetU32(&offset); // entry
463 uint32_t mid_func_offset = UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(entry);
464 mid_func_offset += function_offset_base;
465 uint32_t next_func_offset = 0;
467 offset = first_entry + ((mid + 1) * 4);
468 uint32_t next_entry = m_unwindinfo_data.GetU32(&offset); // entry
469 next_func_offset = UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(next_entry);
470 next_func_offset += function_offset_base;
472 if (mid_func_offset <= function_offset_to_find) {
473 if (mid == last || (next_func_offset > function_offset_to_find)) {
474 if (entry_func_start_offset)
475 *entry_func_start_offset = mid_func_offset;
476 if (mid != last && entry_func_end_offset)
477 *entry_func_end_offset = next_func_offset;
478 return UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(entry);
490 bool CompactUnwindInfo::GetCompactUnwindInfoForFunction(
491 Target &target, Address address, FunctionInfo &unwind_info) {
492 unwind_info.encoding = 0;
493 unwind_info.lsda_address.Clear();
494 unwind_info.personality_ptr_address.Clear();
496 if (!IsValid(target.GetProcessSP()))
499 addr_t text_section_file_address = LLDB_INVALID_ADDRESS;
500 SectionList *sl = m_objfile.GetSectionList();
502 SectionSP text_sect = sl->FindSectionByType(eSectionTypeCode, true);
503 if (text_sect.get()) {
504 text_section_file_address = text_sect->GetFileAddress();
507 if (text_section_file_address == LLDB_INVALID_ADDRESS)
510 addr_t function_offset =
511 address.GetFileAddress() - m_objfile.GetBaseAddress().GetFileAddress();
514 key.function_offset = function_offset;
516 std::vector<UnwindIndex>::const_iterator it;
517 it = std::lower_bound(m_indexes.begin(), m_indexes.end(), key);
518 if (it == m_indexes.end()) {
522 if (it->function_offset != key.function_offset) {
523 if (it != m_indexes.begin())
527 if (it->sentinal_entry) {
531 auto next_it = it + 1;
532 if (next_it != m_indexes.end()) {
533 // initialize the function offset end range to be the start of the next
534 // index offset. If we find an entry which is at the end of the index
535 // table, this will establish the range end.
536 unwind_info.valid_range_offset_end = next_it->function_offset;
539 offset_t second_page_offset = it->second_level;
540 offset_t lsda_array_start = it->lsda_array_start;
541 offset_t lsda_array_count = (it->lsda_array_end - it->lsda_array_start) / 8;
543 offset_t offset = second_page_offset;
544 uint32_t kind = m_unwindinfo_data.GetU32(
545 &offset); // UNWIND_SECOND_LEVEL_REGULAR or UNWIND_SECOND_LEVEL_COMPRESSED
547 if (kind == UNWIND_SECOND_LEVEL_REGULAR) {
548 // struct unwind_info_regular_second_level_page_header {
549 // uint32_t kind; // UNWIND_SECOND_LEVEL_REGULAR
550 // uint16_t entryPageOffset;
551 // uint16_t entryCount;
553 // typedef uint32_t compact_unwind_encoding_t;
554 // struct unwind_info_regular_second_level_entry {
555 // uint32_t functionOffset;
556 // compact_unwind_encoding_t encoding;
558 uint16_t entry_page_offset =
559 m_unwindinfo_data.GetU16(&offset); // entryPageOffset
560 uint16_t entry_count = m_unwindinfo_data.GetU16(&offset); // entryCount
562 offset_t entry_offset = BinarySearchRegularSecondPage(
563 second_page_offset + entry_page_offset, entry_count, function_offset,
564 &unwind_info.valid_range_offset_start,
565 &unwind_info.valid_range_offset_end);
566 if (entry_offset == LLDB_INVALID_OFFSET) {
569 entry_offset += 4; // skip over functionOffset
570 unwind_info.encoding = m_unwindinfo_data.GetU32(&entry_offset); // encoding
571 if (unwind_info.encoding & UNWIND_HAS_LSDA) {
572 SectionList *sl = m_objfile.GetSectionList();
574 uint32_t lsda_offset = GetLSDAForFunctionOffset(
575 lsda_array_start, lsda_array_count, function_offset);
576 addr_t objfile_base_address =
577 m_objfile.GetBaseAddress().GetFileAddress();
578 unwind_info.lsda_address.ResolveAddressUsingFileSections(
579 objfile_base_address + lsda_offset, sl);
582 if (unwind_info.encoding & UNWIND_PERSONALITY_MASK) {
583 uint32_t personality_index =
584 EXTRACT_BITS(unwind_info.encoding, UNWIND_PERSONALITY_MASK);
586 if (personality_index > 0) {
588 if (personality_index < m_unwind_header.personality_array_count) {
589 offset_t offset = m_unwind_header.personality_array_offset;
590 offset += 4 * personality_index;
591 SectionList *sl = m_objfile.GetSectionList();
593 uint32_t personality_offset = m_unwindinfo_data.GetU32(&offset);
594 addr_t objfile_base_address =
595 m_objfile.GetBaseAddress().GetFileAddress();
596 unwind_info.personality_ptr_address.ResolveAddressUsingFileSections(
597 objfile_base_address + personality_offset, sl);
603 } else if (kind == UNWIND_SECOND_LEVEL_COMPRESSED) {
604 // struct unwind_info_compressed_second_level_page_header {
605 // uint32_t kind; // UNWIND_SECOND_LEVEL_COMPRESSED
606 // uint16_t entryPageOffset; // offset from this 2nd lvl page
607 // idx to array of entries
608 // // (an entry has a function
609 // offset and index into the
611 // // NB function offset from the
612 // entry in the compressed page
613 // // must be added to the index's
614 // functionOffset value.
615 // uint16_t entryCount;
616 // uint16_t encodingsPageOffset; // offset from this 2nd lvl page
617 // idx to array of encodings
618 // uint16_t encodingsCount;
620 uint16_t entry_page_offset =
621 m_unwindinfo_data.GetU16(&offset); // entryPageOffset
622 uint16_t entry_count = m_unwindinfo_data.GetU16(&offset); // entryCount
623 uint16_t encodings_page_offset =
624 m_unwindinfo_data.GetU16(&offset); // encodingsPageOffset
625 uint16_t encodings_count =
626 m_unwindinfo_data.GetU16(&offset); // encodingsCount
628 uint32_t encoding_index = BinarySearchCompressedSecondPage(
629 second_page_offset + entry_page_offset, entry_count, function_offset,
630 it->function_offset, &unwind_info.valid_range_offset_start,
631 &unwind_info.valid_range_offset_end);
632 if (encoding_index == UINT32_MAX ||
634 encodings_count + m_unwind_header.common_encodings_array_count) {
637 uint32_t encoding = 0;
638 if (encoding_index < m_unwind_header.common_encodings_array_count) {
639 offset = m_unwind_header.common_encodings_array_offset +
640 (encoding_index * sizeof(uint32_t));
641 encoding = m_unwindinfo_data.GetU32(
642 &offset); // encoding entry from the commonEncodingsArray
644 uint32_t page_specific_entry_index =
645 encoding_index - m_unwind_header.common_encodings_array_count;
646 offset = second_page_offset + encodings_page_offset +
647 (page_specific_entry_index * sizeof(uint32_t));
648 encoding = m_unwindinfo_data.GetU32(
649 &offset); // encoding entry from the page-specific encoding array
654 unwind_info.encoding = encoding;
655 if (unwind_info.encoding & UNWIND_HAS_LSDA) {
656 SectionList *sl = m_objfile.GetSectionList();
658 uint32_t lsda_offset = GetLSDAForFunctionOffset(
659 lsda_array_start, lsda_array_count, function_offset);
660 addr_t objfile_base_address =
661 m_objfile.GetBaseAddress().GetFileAddress();
662 unwind_info.lsda_address.ResolveAddressUsingFileSections(
663 objfile_base_address + lsda_offset, sl);
666 if (unwind_info.encoding & UNWIND_PERSONALITY_MASK) {
667 uint32_t personality_index =
668 EXTRACT_BITS(unwind_info.encoding, UNWIND_PERSONALITY_MASK);
670 if (personality_index > 0) {
672 if (personality_index < m_unwind_header.personality_array_count) {
673 offset_t offset = m_unwind_header.personality_array_offset;
674 offset += 4 * personality_index;
675 SectionList *sl = m_objfile.GetSectionList();
677 uint32_t personality_offset = m_unwindinfo_data.GetU32(&offset);
678 addr_t objfile_base_address =
679 m_objfile.GetBaseAddress().GetFileAddress();
680 unwind_info.personality_ptr_address.ResolveAddressUsingFileSections(
681 objfile_base_address + personality_offset, sl);
691 enum x86_64_eh_regnum {
708 rip = 16 // this is officially the Return Address register number, but close
712 // Convert the compact_unwind_info.h register numbering scheme to
713 // eRegisterKindEHFrame (eh_frame) register numbering scheme.
714 uint32_t translate_to_eh_frame_regnum_x86_64(uint32_t unwind_regno) {
715 switch (unwind_regno) {
716 case UNWIND_X86_64_REG_RBX:
717 return x86_64_eh_regnum::rbx;
718 case UNWIND_X86_64_REG_R12:
719 return x86_64_eh_regnum::r12;
720 case UNWIND_X86_64_REG_R13:
721 return x86_64_eh_regnum::r13;
722 case UNWIND_X86_64_REG_R14:
723 return x86_64_eh_regnum::r14;
724 case UNWIND_X86_64_REG_R15:
725 return x86_64_eh_regnum::r15;
726 case UNWIND_X86_64_REG_RBP:
727 return x86_64_eh_regnum::rbp;
729 return LLDB_INVALID_REGNUM;
733 bool CompactUnwindInfo::CreateUnwindPlan_x86_64(Target &target,
734 FunctionInfo &function_info,
735 UnwindPlan &unwind_plan,
736 Address pc_or_function_start) {
737 unwind_plan.SetSourceName("compact unwind info");
738 unwind_plan.SetSourcedFromCompiler(eLazyBoolYes);
739 unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
740 unwind_plan.SetRegisterKind(eRegisterKindEHFrame);
742 unwind_plan.SetLSDAAddress(function_info.lsda_address);
743 unwind_plan.SetPersonalityFunctionPtr(function_info.personality_ptr_address);
745 UnwindPlan::RowSP row(new UnwindPlan::Row);
747 const int wordsize = 8;
748 int mode = function_info.encoding & UNWIND_X86_64_MODE_MASK;
750 case UNWIND_X86_64_MODE_RBP_FRAME: {
751 row->GetCFAValue().SetIsRegisterPlusOffset(
752 translate_to_eh_frame_regnum_x86_64(UNWIND_X86_64_REG_RBP),
755 row->SetRegisterLocationToAtCFAPlusOffset(x86_64_eh_regnum::rbp,
756 wordsize * -2, true);
757 row->SetRegisterLocationToAtCFAPlusOffset(x86_64_eh_regnum::rip,
758 wordsize * -1, true);
759 row->SetRegisterLocationToIsCFAPlusOffset(x86_64_eh_regnum::rsp, 0, true);
761 uint32_t saved_registers_offset =
762 EXTRACT_BITS(function_info.encoding, UNWIND_X86_64_RBP_FRAME_OFFSET);
764 uint32_t saved_registers_locations =
765 EXTRACT_BITS(function_info.encoding, UNWIND_X86_64_RBP_FRAME_REGISTERS);
767 saved_registers_offset += 2;
769 for (int i = 0; i < 5; i++) {
770 uint32_t regnum = saved_registers_locations & 0x7;
772 case UNWIND_X86_64_REG_NONE:
774 case UNWIND_X86_64_REG_RBX:
775 case UNWIND_X86_64_REG_R12:
776 case UNWIND_X86_64_REG_R13:
777 case UNWIND_X86_64_REG_R14:
778 case UNWIND_X86_64_REG_R15:
779 row->SetRegisterLocationToAtCFAPlusOffset(
780 translate_to_eh_frame_regnum_x86_64(regnum),
781 wordsize * -saved_registers_offset, true);
784 saved_registers_offset--;
785 saved_registers_locations >>= 3;
787 unwind_plan.AppendRow(row);
791 case UNWIND_X86_64_MODE_STACK_IND: {
792 // The clang in Xcode 6 is emitting incorrect compact unwind encodings for
793 // this style of unwind. It was fixed in llvm r217020. The clang in Xcode
798 case UNWIND_X86_64_MODE_STACK_IMMD: {
799 uint32_t stack_size = EXTRACT_BITS(function_info.encoding,
800 UNWIND_X86_64_FRAMELESS_STACK_SIZE);
801 uint32_t register_count = EXTRACT_BITS(
802 function_info.encoding, UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT);
803 uint32_t permutation = EXTRACT_BITS(
804 function_info.encoding, UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION);
806 if (mode == UNWIND_X86_64_MODE_STACK_IND &&
807 function_info.valid_range_offset_start != 0) {
808 uint32_t stack_adjust = EXTRACT_BITS(
809 function_info.encoding, UNWIND_X86_64_FRAMELESS_STACK_ADJUST);
811 // offset into the function instructions; 0 == beginning of first
813 uint32_t offset_to_subl_insn = EXTRACT_BITS(
814 function_info.encoding, UNWIND_X86_64_FRAMELESS_STACK_SIZE);
816 SectionList *sl = m_objfile.GetSectionList();
818 ProcessSP process_sp = target.GetProcessSP();
820 Address subl_payload_addr(function_info.valid_range_offset_start, sl);
821 subl_payload_addr.Slide(offset_to_subl_insn);
823 uint64_t large_stack_size = process_sp->ReadUnsignedIntegerFromMemory(
824 subl_payload_addr.GetLoadAddress(&target), 4, 0, error);
825 if (large_stack_size != 0 && error.Success()) {
826 // Got the large stack frame size correctly - use it
827 stack_size = large_stack_size + (stack_adjust * wordsize);
839 int32_t offset = mode == UNWIND_X86_64_MODE_STACK_IND
841 : stack_size * wordsize;
842 row->GetCFAValue().SetIsRegisterPlusOffset(x86_64_eh_regnum::rsp, offset);
845 row->SetRegisterLocationToAtCFAPlusOffset(x86_64_eh_regnum::rip,
846 wordsize * -1, true);
847 row->SetRegisterLocationToIsCFAPlusOffset(x86_64_eh_regnum::rsp, 0, true);
849 if (register_count > 0) {
851 // We need to include (up to) 6 registers in 10 bits. That would be 18
852 // bits if we just used 3 bits per reg to indicate the order they're
853 // saved on the stack.
855 // This is done with Lehmer code permutation, e.g. see
856 // http://stackoverflow.com/questions/1506078/fast-permutation-number-
857 // permutation-mapping-algorithms
858 int permunreg[6] = {0, 0, 0, 0, 0, 0};
860 // This decodes the variable-base number in the 10 bits and gives us the
861 // Lehmer code sequence which can then be decoded.
863 switch (register_count) {
865 permunreg[0] = permutation / 120; // 120 == 5!
866 permutation -= (permunreg[0] * 120);
867 permunreg[1] = permutation / 24; // 24 == 4!
868 permutation -= (permunreg[1] * 24);
869 permunreg[2] = permutation / 6; // 6 == 3!
870 permutation -= (permunreg[2] * 6);
871 permunreg[3] = permutation / 2; // 2 == 2!
872 permutation -= (permunreg[3] * 2);
873 permunreg[4] = permutation; // 1 == 1!
877 permunreg[0] = permutation / 120;
878 permutation -= (permunreg[0] * 120);
879 permunreg[1] = permutation / 24;
880 permutation -= (permunreg[1] * 24);
881 permunreg[2] = permutation / 6;
882 permutation -= (permunreg[2] * 6);
883 permunreg[3] = permutation / 2;
884 permutation -= (permunreg[3] * 2);
885 permunreg[4] = permutation;
888 permunreg[0] = permutation / 60;
889 permutation -= (permunreg[0] * 60);
890 permunreg[1] = permutation / 12;
891 permutation -= (permunreg[1] * 12);
892 permunreg[2] = permutation / 3;
893 permutation -= (permunreg[2] * 3);
894 permunreg[3] = permutation;
897 permunreg[0] = permutation / 20;
898 permutation -= (permunreg[0] * 20);
899 permunreg[1] = permutation / 4;
900 permutation -= (permunreg[1] * 4);
901 permunreg[2] = permutation;
904 permunreg[0] = permutation / 5;
905 permutation -= (permunreg[0] * 5);
906 permunreg[1] = permutation;
909 permunreg[0] = permutation;
913 // Decode the Lehmer code for this permutation of the registers v.
914 // http://en.wikipedia.org/wiki/Lehmer_code
916 int registers[6] = {UNWIND_X86_64_REG_NONE, UNWIND_X86_64_REG_NONE,
917 UNWIND_X86_64_REG_NONE, UNWIND_X86_64_REG_NONE,
918 UNWIND_X86_64_REG_NONE, UNWIND_X86_64_REG_NONE};
919 bool used[7] = {false, false, false, false, false, false, false};
920 for (uint32_t i = 0; i < register_count; i++) {
922 for (int j = 1; j < 7; j++) {
924 if (renum == permunreg[i]) {
934 uint32_t saved_registers_offset = 1;
935 saved_registers_offset++;
937 for (int i = (sizeof(registers) / sizeof(int)) - 1; i >= 0; i--) {
938 switch (registers[i]) {
939 case UNWIND_X86_64_REG_NONE:
941 case UNWIND_X86_64_REG_RBX:
942 case UNWIND_X86_64_REG_R12:
943 case UNWIND_X86_64_REG_R13:
944 case UNWIND_X86_64_REG_R14:
945 case UNWIND_X86_64_REG_R15:
946 case UNWIND_X86_64_REG_RBP:
947 row->SetRegisterLocationToAtCFAPlusOffset(
948 translate_to_eh_frame_regnum_x86_64(registers[i]),
949 wordsize * -saved_registers_offset, true);
950 saved_registers_offset++;
955 unwind_plan.AppendRow(row);
959 case UNWIND_X86_64_MODE_DWARF: {
970 enum i386_eh_regnum {
979 eip = 8 // this is officially the Return Address register number, but close
983 // Convert the compact_unwind_info.h register numbering scheme to
984 // eRegisterKindEHFrame (eh_frame) register numbering scheme.
985 uint32_t translate_to_eh_frame_regnum_i386(uint32_t unwind_regno) {
986 switch (unwind_regno) {
987 case UNWIND_X86_REG_EBX:
988 return i386_eh_regnum::ebx;
989 case UNWIND_X86_REG_ECX:
990 return i386_eh_regnum::ecx;
991 case UNWIND_X86_REG_EDX:
992 return i386_eh_regnum::edx;
993 case UNWIND_X86_REG_EDI:
994 return i386_eh_regnum::edi;
995 case UNWIND_X86_REG_ESI:
996 return i386_eh_regnum::esi;
997 case UNWIND_X86_REG_EBP:
998 return i386_eh_regnum::ebp;
1000 return LLDB_INVALID_REGNUM;
1004 bool CompactUnwindInfo::CreateUnwindPlan_i386(Target &target,
1005 FunctionInfo &function_info,
1006 UnwindPlan &unwind_plan,
1007 Address pc_or_function_start) {
1008 unwind_plan.SetSourceName("compact unwind info");
1009 unwind_plan.SetSourcedFromCompiler(eLazyBoolYes);
1010 unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
1011 unwind_plan.SetRegisterKind(eRegisterKindEHFrame);
1013 unwind_plan.SetLSDAAddress(function_info.lsda_address);
1014 unwind_plan.SetPersonalityFunctionPtr(function_info.personality_ptr_address);
1016 UnwindPlan::RowSP row(new UnwindPlan::Row);
1018 const int wordsize = 4;
1019 int mode = function_info.encoding & UNWIND_X86_MODE_MASK;
1021 case UNWIND_X86_MODE_EBP_FRAME: {
1022 row->GetCFAValue().SetIsRegisterPlusOffset(
1023 translate_to_eh_frame_regnum_i386(UNWIND_X86_REG_EBP), 2 * wordsize);
1025 row->SetRegisterLocationToAtCFAPlusOffset(i386_eh_regnum::ebp,
1026 wordsize * -2, true);
1027 row->SetRegisterLocationToAtCFAPlusOffset(i386_eh_regnum::eip,
1028 wordsize * -1, true);
1029 row->SetRegisterLocationToIsCFAPlusOffset(i386_eh_regnum::esp, 0, true);
1031 uint32_t saved_registers_offset =
1032 EXTRACT_BITS(function_info.encoding, UNWIND_X86_EBP_FRAME_OFFSET);
1034 uint32_t saved_registers_locations =
1035 EXTRACT_BITS(function_info.encoding, UNWIND_X86_EBP_FRAME_REGISTERS);
1037 saved_registers_offset += 2;
1039 for (int i = 0; i < 5; i++) {
1040 uint32_t regnum = saved_registers_locations & 0x7;
1042 case UNWIND_X86_REG_NONE:
1044 case UNWIND_X86_REG_EBX:
1045 case UNWIND_X86_REG_ECX:
1046 case UNWIND_X86_REG_EDX:
1047 case UNWIND_X86_REG_EDI:
1048 case UNWIND_X86_REG_ESI:
1049 row->SetRegisterLocationToAtCFAPlusOffset(
1050 translate_to_eh_frame_regnum_i386(regnum),
1051 wordsize * -saved_registers_offset, true);
1054 saved_registers_offset--;
1055 saved_registers_locations >>= 3;
1057 unwind_plan.AppendRow(row);
1061 case UNWIND_X86_MODE_STACK_IND:
1062 case UNWIND_X86_MODE_STACK_IMMD: {
1063 uint32_t stack_size =
1064 EXTRACT_BITS(function_info.encoding, UNWIND_X86_FRAMELESS_STACK_SIZE);
1065 uint32_t register_count = EXTRACT_BITS(
1066 function_info.encoding, UNWIND_X86_FRAMELESS_STACK_REG_COUNT);
1067 uint32_t permutation = EXTRACT_BITS(
1068 function_info.encoding, UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION);
1070 if (mode == UNWIND_X86_MODE_STACK_IND &&
1071 function_info.valid_range_offset_start != 0) {
1072 uint32_t stack_adjust = EXTRACT_BITS(function_info.encoding,
1073 UNWIND_X86_FRAMELESS_STACK_ADJUST);
1075 // offset into the function instructions; 0 == beginning of first
1077 uint32_t offset_to_subl_insn =
1078 EXTRACT_BITS(function_info.encoding, UNWIND_X86_FRAMELESS_STACK_SIZE);
1080 SectionList *sl = m_objfile.GetSectionList();
1082 ProcessSP process_sp = target.GetProcessSP();
1084 Address subl_payload_addr(function_info.valid_range_offset_start, sl);
1085 subl_payload_addr.Slide(offset_to_subl_insn);
1087 uint64_t large_stack_size = process_sp->ReadUnsignedIntegerFromMemory(
1088 subl_payload_addr.GetLoadAddress(&target), 4, 0, error);
1089 if (large_stack_size != 0 && error.Success()) {
1090 // Got the large stack frame size correctly - use it
1091 stack_size = large_stack_size + (stack_adjust * wordsize);
1104 mode == UNWIND_X86_MODE_STACK_IND ? stack_size : stack_size * wordsize;
1105 row->GetCFAValue().SetIsRegisterPlusOffset(i386_eh_regnum::esp, offset);
1107 row->SetRegisterLocationToAtCFAPlusOffset(i386_eh_regnum::eip,
1108 wordsize * -1, true);
1109 row->SetRegisterLocationToIsCFAPlusOffset(i386_eh_regnum::esp, 0, true);
1111 if (register_count > 0) {
1113 // We need to include (up to) 6 registers in 10 bits. That would be 18
1114 // bits if we just used 3 bits per reg to indicate the order they're
1115 // saved on the stack.
1117 // This is done with Lehmer code permutation, e.g. see
1118 // http://stackoverflow.com/questions/1506078/fast-permutation-number-
1119 // permutation-mapping-algorithms
1120 int permunreg[6] = {0, 0, 0, 0, 0, 0};
1122 // This decodes the variable-base number in the 10 bits and gives us the
1123 // Lehmer code sequence which can then be decoded.
1125 switch (register_count) {
1127 permunreg[0] = permutation / 120; // 120 == 5!
1128 permutation -= (permunreg[0] * 120);
1129 permunreg[1] = permutation / 24; // 24 == 4!
1130 permutation -= (permunreg[1] * 24);
1131 permunreg[2] = permutation / 6; // 6 == 3!
1132 permutation -= (permunreg[2] * 6);
1133 permunreg[3] = permutation / 2; // 2 == 2!
1134 permutation -= (permunreg[3] * 2);
1135 permunreg[4] = permutation; // 1 == 1!
1139 permunreg[0] = permutation / 120;
1140 permutation -= (permunreg[0] * 120);
1141 permunreg[1] = permutation / 24;
1142 permutation -= (permunreg[1] * 24);
1143 permunreg[2] = permutation / 6;
1144 permutation -= (permunreg[2] * 6);
1145 permunreg[3] = permutation / 2;
1146 permutation -= (permunreg[3] * 2);
1147 permunreg[4] = permutation;
1150 permunreg[0] = permutation / 60;
1151 permutation -= (permunreg[0] * 60);
1152 permunreg[1] = permutation / 12;
1153 permutation -= (permunreg[1] * 12);
1154 permunreg[2] = permutation / 3;
1155 permutation -= (permunreg[2] * 3);
1156 permunreg[3] = permutation;
1159 permunreg[0] = permutation / 20;
1160 permutation -= (permunreg[0] * 20);
1161 permunreg[1] = permutation / 4;
1162 permutation -= (permunreg[1] * 4);
1163 permunreg[2] = permutation;
1166 permunreg[0] = permutation / 5;
1167 permutation -= (permunreg[0] * 5);
1168 permunreg[1] = permutation;
1171 permunreg[0] = permutation;
1175 // Decode the Lehmer code for this permutation of the registers v.
1176 // http://en.wikipedia.org/wiki/Lehmer_code
1178 int registers[6] = {UNWIND_X86_REG_NONE, UNWIND_X86_REG_NONE,
1179 UNWIND_X86_REG_NONE, UNWIND_X86_REG_NONE,
1180 UNWIND_X86_REG_NONE, UNWIND_X86_REG_NONE};
1181 bool used[7] = {false, false, false, false, false, false, false};
1182 for (uint32_t i = 0; i < register_count; i++) {
1184 for (int j = 1; j < 7; j++) {
1186 if (renum == permunreg[i]) {
1196 uint32_t saved_registers_offset = 1;
1197 saved_registers_offset++;
1199 for (int i = (sizeof(registers) / sizeof(int)) - 1; i >= 0; i--) {
1200 switch (registers[i]) {
1201 case UNWIND_X86_REG_NONE:
1203 case UNWIND_X86_REG_EBX:
1204 case UNWIND_X86_REG_ECX:
1205 case UNWIND_X86_REG_EDX:
1206 case UNWIND_X86_REG_EDI:
1207 case UNWIND_X86_REG_ESI:
1208 case UNWIND_X86_REG_EBP:
1209 row->SetRegisterLocationToAtCFAPlusOffset(
1210 translate_to_eh_frame_regnum_i386(registers[i]),
1211 wordsize * -saved_registers_offset, true);
1212 saved_registers_offset++;
1218 unwind_plan.AppendRow(row);
1222 case UNWIND_X86_MODE_DWARF: {
1229 // DWARF register numbers from "DWARF for the ARM 64-bit Architecture (AArch64)"
1232 enum arm64_eh_regnum {
1249 // Compact unwind encodes d8-d15 but we don't have eh_frame / dwarf reg #'s
1250 // for the 64-bit fp regs. Normally in DWARF it's context sensitive - so it
1251 // knows it is fetching a 32- or 64-bit quantity from reg v8 to indicate s0
1252 // or d0 - but the unwinder is operating at a lower level and we'd try to
1253 // fetch 128 bits if we were told that v8 were stored on the stack...
1264 enum arm_eh_regnum {
1300 bool CompactUnwindInfo::CreateUnwindPlan_arm64(Target &target,
1301 FunctionInfo &function_info,
1302 UnwindPlan &unwind_plan,
1303 Address pc_or_function_start) {
1304 unwind_plan.SetSourceName("compact unwind info");
1305 unwind_plan.SetSourcedFromCompiler(eLazyBoolYes);
1306 unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
1307 unwind_plan.SetRegisterKind(eRegisterKindEHFrame);
1309 unwind_plan.SetLSDAAddress(function_info.lsda_address);
1310 unwind_plan.SetPersonalityFunctionPtr(function_info.personality_ptr_address);
1312 UnwindPlan::RowSP row(new UnwindPlan::Row);
1314 const int wordsize = 8;
1315 int mode = function_info.encoding & UNWIND_ARM64_MODE_MASK;
1317 if (mode == UNWIND_ARM64_MODE_DWARF)
1320 if (mode == UNWIND_ARM64_MODE_FRAMELESS) {
1323 uint32_t stack_size =
1324 (EXTRACT_BITS(function_info.encoding,
1325 UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK)) *
1328 // Our previous Call Frame Address is the stack pointer plus the stack size
1329 row->GetCFAValue().SetIsRegisterPlusOffset(arm64_eh_regnum::sp, stack_size);
1331 // Our previous PC is in the LR
1332 row->SetRegisterLocationToRegister(arm64_eh_regnum::pc, arm64_eh_regnum::ra,
1335 unwind_plan.AppendRow(row);
1339 // Should not be possible
1340 if (mode != UNWIND_ARM64_MODE_FRAME)
1343 // mode == UNWIND_ARM64_MODE_FRAME
1345 row->GetCFAValue().SetIsRegisterPlusOffset(arm64_eh_regnum::fp, 2 * wordsize);
1347 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::fp, wordsize * -2,
1349 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::pc, wordsize * -1,
1351 row->SetRegisterLocationToIsCFAPlusOffset(arm64_eh_regnum::sp, 0, true);
1353 int reg_pairs_saved_count = 1;
1355 uint32_t saved_register_bits = function_info.encoding & 0xfff;
1357 if (saved_register_bits & UNWIND_ARM64_FRAME_X19_X20_PAIR) {
1358 int cfa_offset = reg_pairs_saved_count * -2 * wordsize;
1359 cfa_offset -= wordsize;
1360 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x19, cfa_offset,
1362 cfa_offset -= wordsize;
1363 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x20, cfa_offset,
1365 reg_pairs_saved_count++;
1368 if (saved_register_bits & UNWIND_ARM64_FRAME_X21_X22_PAIR) {
1369 int cfa_offset = reg_pairs_saved_count * -2 * wordsize;
1370 cfa_offset -= wordsize;
1371 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x21, cfa_offset,
1373 cfa_offset -= wordsize;
1374 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x22, cfa_offset,
1376 reg_pairs_saved_count++;
1379 if (saved_register_bits & UNWIND_ARM64_FRAME_X23_X24_PAIR) {
1380 int cfa_offset = reg_pairs_saved_count * -2 * wordsize;
1381 cfa_offset -= wordsize;
1382 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x23, cfa_offset,
1384 cfa_offset -= wordsize;
1385 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x24, cfa_offset,
1387 reg_pairs_saved_count++;
1390 if (saved_register_bits & UNWIND_ARM64_FRAME_X25_X26_PAIR) {
1391 int cfa_offset = reg_pairs_saved_count * -2 * wordsize;
1392 cfa_offset -= wordsize;
1393 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x25, cfa_offset,
1395 cfa_offset -= wordsize;
1396 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x26, cfa_offset,
1398 reg_pairs_saved_count++;
1401 if (saved_register_bits & UNWIND_ARM64_FRAME_X27_X28_PAIR) {
1402 int cfa_offset = reg_pairs_saved_count * -2 * wordsize;
1403 cfa_offset -= wordsize;
1404 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x27, cfa_offset,
1406 cfa_offset -= wordsize;
1407 row->SetRegisterLocationToAtCFAPlusOffset(arm64_eh_regnum::x28, cfa_offset,
1409 reg_pairs_saved_count++;
1412 // If we use the v8-v15 regnums here, the unwinder will try to grab 128 bits
1414 // not sure if we have a good way to represent the 64-bitness of these saves.
1416 if (saved_register_bits & UNWIND_ARM64_FRAME_D8_D9_PAIR) {
1417 reg_pairs_saved_count++;
1419 if (saved_register_bits & UNWIND_ARM64_FRAME_D10_D11_PAIR) {
1420 reg_pairs_saved_count++;
1422 if (saved_register_bits & UNWIND_ARM64_FRAME_D12_D13_PAIR) {
1423 reg_pairs_saved_count++;
1425 if (saved_register_bits & UNWIND_ARM64_FRAME_D14_D15_PAIR) {
1426 reg_pairs_saved_count++;
1429 unwind_plan.AppendRow(row);
1433 bool CompactUnwindInfo::CreateUnwindPlan_armv7(Target &target,
1434 FunctionInfo &function_info,
1435 UnwindPlan &unwind_plan,
1436 Address pc_or_function_start) {
1437 unwind_plan.SetSourceName("compact unwind info");
1438 unwind_plan.SetSourcedFromCompiler(eLazyBoolYes);
1439 unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
1440 unwind_plan.SetRegisterKind(eRegisterKindEHFrame);
1442 unwind_plan.SetLSDAAddress(function_info.lsda_address);
1443 unwind_plan.SetPersonalityFunctionPtr(function_info.personality_ptr_address);
1445 UnwindPlan::RowSP row(new UnwindPlan::Row);
1447 const int wordsize = 4;
1448 int mode = function_info.encoding & UNWIND_ARM_MODE_MASK;
1450 if (mode == UNWIND_ARM_MODE_DWARF)
1453 uint32_t stack_adjust = (EXTRACT_BITS(function_info.encoding,
1454 UNWIND_ARM_FRAME_STACK_ADJUST_MASK)) *
1457 row->GetCFAValue().SetIsRegisterPlusOffset(arm_r7,
1458 (2 * wordsize) + stack_adjust);
1460 row->SetRegisterLocationToAtCFAPlusOffset(
1461 arm_r7, (wordsize * -2) - stack_adjust, true);
1462 row->SetRegisterLocationToAtCFAPlusOffset(
1463 arm_pc, (wordsize * -1) - stack_adjust, true);
1464 row->SetRegisterLocationToIsCFAPlusOffset(arm_sp, 0, true);
1466 int cfa_offset = -stack_adjust - (2 * wordsize);
1468 uint32_t saved_register_bits = function_info.encoding & 0xff;
1470 if (saved_register_bits & UNWIND_ARM_FRAME_FIRST_PUSH_R6) {
1471 cfa_offset -= wordsize;
1472 row->SetRegisterLocationToAtCFAPlusOffset(arm_r6, cfa_offset, true);
1475 if (saved_register_bits & UNWIND_ARM_FRAME_FIRST_PUSH_R5) {
1476 cfa_offset -= wordsize;
1477 row->SetRegisterLocationToAtCFAPlusOffset(arm_r5, cfa_offset, true);
1480 if (saved_register_bits & UNWIND_ARM_FRAME_FIRST_PUSH_R4) {
1481 cfa_offset -= wordsize;
1482 row->SetRegisterLocationToAtCFAPlusOffset(arm_r4, cfa_offset, true);
1485 if (saved_register_bits & UNWIND_ARM_FRAME_SECOND_PUSH_R12) {
1486 cfa_offset -= wordsize;
1487 row->SetRegisterLocationToAtCFAPlusOffset(arm_r12, cfa_offset, true);
1490 if (saved_register_bits & UNWIND_ARM_FRAME_SECOND_PUSH_R11) {
1491 cfa_offset -= wordsize;
1492 row->SetRegisterLocationToAtCFAPlusOffset(arm_r11, cfa_offset, true);
1495 if (saved_register_bits & UNWIND_ARM_FRAME_SECOND_PUSH_R10) {
1496 cfa_offset -= wordsize;
1497 row->SetRegisterLocationToAtCFAPlusOffset(arm_r10, cfa_offset, true);
1500 if (saved_register_bits & UNWIND_ARM_FRAME_SECOND_PUSH_R9) {
1501 cfa_offset -= wordsize;
1502 row->SetRegisterLocationToAtCFAPlusOffset(arm_r9, cfa_offset, true);
1505 if (saved_register_bits & UNWIND_ARM_FRAME_SECOND_PUSH_R8) {
1506 cfa_offset -= wordsize;
1507 row->SetRegisterLocationToAtCFAPlusOffset(arm_r8, cfa_offset, true);
1510 if (mode == UNWIND_ARM_MODE_FRAME_D) {
1511 uint32_t d_reg_bits =
1512 EXTRACT_BITS(function_info.encoding, UNWIND_ARM_FRAME_D_REG_COUNT_MASK);
1513 switch (d_reg_bits) {
1517 row->SetRegisterLocationToAtCFAPlusOffset(arm_d8, cfa_offset, true);
1523 row->SetRegisterLocationToAtCFAPlusOffset(arm_d10, cfa_offset, true);
1525 row->SetRegisterLocationToAtCFAPlusOffset(arm_d8, cfa_offset, true);
1532 row->SetRegisterLocationToAtCFAPlusOffset(arm_d12, cfa_offset, true);
1534 row->SetRegisterLocationToAtCFAPlusOffset(arm_d10, cfa_offset, true);
1536 row->SetRegisterLocationToAtCFAPlusOffset(arm_d8, cfa_offset, true);
1544 row->SetRegisterLocationToAtCFAPlusOffset(arm_d14, cfa_offset, true);
1546 row->SetRegisterLocationToAtCFAPlusOffset(arm_d12, cfa_offset, true);
1548 row->SetRegisterLocationToAtCFAPlusOffset(arm_d10, cfa_offset, true);
1550 row->SetRegisterLocationToAtCFAPlusOffset(arm_d8, cfa_offset, true);
1555 // sp = (sp - 24) & (-16);
1556 // vst {d8, d9, d10}
1558 row->SetRegisterLocationToAtCFAPlusOffset(arm_d14, cfa_offset, true);
1560 row->SetRegisterLocationToAtCFAPlusOffset(arm_d12, cfa_offset, true);
1562 // FIXME we don't have a way to represent reg saves at an specific
1563 // alignment short of
1564 // coming up with some DWARF location description.
1569 // sp = (sp - 40) & (-16);
1570 // vst {d8, d9, d10, d11}
1574 row->SetRegisterLocationToAtCFAPlusOffset(arm_d14, cfa_offset, true);
1576 // FIXME we don't have a way to represent reg saves at an specific
1577 // alignment short of
1578 // coming up with some DWARF location description.
1582 // sp = (sp - 56) & (-16);
1583 // vst {d8, d9, d10, d11}
1584 // vst {d12, d13, d14}
1586 // FIXME we don't have a way to represent reg saves at an specific
1587 // alignment short of
1588 // coming up with some DWARF location description.
1592 // sp = (sp - 64) & (-16);
1593 // vst {d8, d9, d10, d11}
1594 // vst {d12, d13, d14, d15}
1596 // FIXME we don't have a way to represent reg saves at an specific
1597 // alignment short of
1598 // coming up with some DWARF location description.
1604 unwind_plan.AppendRow(row);