1 //===------------------------- UnwindCursor.hpp ---------------------------===//
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
8 // C++ interface to lower levels of libunwind
9 //===----------------------------------------------------------------------===//
11 #ifndef __UNWINDCURSOR_HPP__
12 #define __UNWINDCURSOR_HPP__
24 #include <mach-o/dyld.h>
27 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
28 // Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and
30 // MinGW-w64 has always provided this struct.
31 #if defined(_WIN32) && defined(_LIBUNWIND_TARGET_X86_64) && \
32 !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000
33 struct _DISPATCHER_CONTEXT {
36 PRUNTIME_FUNCTION FunctionEntry;
37 ULONG64 EstablisherFrame;
39 PCONTEXT ContextRecord;
40 PEXCEPTION_ROUTINE LanguageHandler;
42 PUNWIND_HISTORY_TABLE HistoryTable;
53 uint8_t FrameRegister : 4;
54 uint8_t FrameOffset : 4;
55 uint16_t UnwindCodes[2];
58 extern "C" _Unwind_Reason_Code __libunwind_seh_personality(
59 int, _Unwind_Action, uint64_t, _Unwind_Exception *,
60 struct _Unwind_Context *);
66 #include "AddressSpace.hpp"
67 #include "CompactUnwinder.hpp"
69 #include "DwarfInstructions.hpp"
70 #include "EHHeaderParser.hpp"
71 #include "libunwind.h"
72 #include "Registers.hpp"
73 #include "RWMutex.hpp"
74 #include "Unwind-EHABI.h"
78 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
79 /// Cache of recently found FDEs.
81 class _LIBUNWIND_HIDDEN DwarfFDECache {
82 typedef typename A::pint_t pint_t;
84 static pint_t findFDE(pint_t mh, pint_t pc);
85 static void add(pint_t mh, pint_t ip_start, pint_t ip_end, pint_t fde);
86 static void removeAllIn(pint_t mh);
87 static void iterateCacheEntries(void (*func)(unw_word_t ip_start,
89 unw_word_t fde, unw_word_t mh));
100 // These fields are all static to avoid needing an initializer.
101 // There is only one instance of this class per process.
102 static RWMutex _lock;
104 static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
105 static bool _registeredForDyldUnloads;
107 static entry *_buffer;
108 static entry *_bufferUsed;
109 static entry *_bufferEnd;
110 static entry _initialBuffer[64];
113 template <typename A>
114 typename DwarfFDECache<A>::entry *
115 DwarfFDECache<A>::_buffer = _initialBuffer;
117 template <typename A>
118 typename DwarfFDECache<A>::entry *
119 DwarfFDECache<A>::_bufferUsed = _initialBuffer;
121 template <typename A>
122 typename DwarfFDECache<A>::entry *
123 DwarfFDECache<A>::_bufferEnd = &_initialBuffer[64];
125 template <typename A>
126 typename DwarfFDECache<A>::entry DwarfFDECache<A>::_initialBuffer[64];
128 template <typename A>
129 RWMutex DwarfFDECache<A>::_lock;
132 template <typename A>
133 bool DwarfFDECache<A>::_registeredForDyldUnloads = false;
136 template <typename A>
137 typename A::pint_t DwarfFDECache<A>::findFDE(pint_t mh, pint_t pc) {
139 _LIBUNWIND_LOG_IF_FALSE(_lock.lock_shared());
140 for (entry *p = _buffer; p < _bufferUsed; ++p) {
141 if ((mh == p->mh) || (mh == 0)) {
142 if ((p->ip_start <= pc) && (pc < p->ip_end)) {
148 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock_shared());
152 template <typename A>
153 void DwarfFDECache<A>::add(pint_t mh, pint_t ip_start, pint_t ip_end,
155 #if !defined(_LIBUNWIND_NO_HEAP)
156 _LIBUNWIND_LOG_IF_FALSE(_lock.lock());
157 if (_bufferUsed >= _bufferEnd) {
158 size_t oldSize = (size_t)(_bufferEnd - _buffer);
159 size_t newSize = oldSize * 4;
160 // Can't use operator new (we are below it).
161 entry *newBuffer = (entry *)malloc(newSize * sizeof(entry));
162 memcpy(newBuffer, _buffer, oldSize * sizeof(entry));
163 if (_buffer != _initialBuffer)
166 _bufferUsed = &newBuffer[oldSize];
167 _bufferEnd = &newBuffer[newSize];
169 _bufferUsed->mh = mh;
170 _bufferUsed->ip_start = ip_start;
171 _bufferUsed->ip_end = ip_end;
172 _bufferUsed->fde = fde;
175 if (!_registeredForDyldUnloads) {
176 _dyld_register_func_for_remove_image(&dyldUnloadHook);
177 _registeredForDyldUnloads = true;
180 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock());
184 template <typename A>
185 void DwarfFDECache<A>::removeAllIn(pint_t mh) {
186 _LIBUNWIND_LOG_IF_FALSE(_lock.lock());
188 for (const entry *s = _buffer; s < _bufferUsed; ++s) {
196 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock());
200 template <typename A>
201 void DwarfFDECache<A>::dyldUnloadHook(const struct mach_header *mh, intptr_t ) {
202 removeAllIn((pint_t) mh);
206 template <typename A>
207 void DwarfFDECache<A>::iterateCacheEntries(void (*func)(
208 unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)) {
209 _LIBUNWIND_LOG_IF_FALSE(_lock.lock());
210 for (entry *p = _buffer; p < _bufferUsed; ++p) {
211 (*func)(p->ip_start, p->ip_end, p->fde, p->mh);
213 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock());
215 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
218 #define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
220 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
221 template <typename A> class UnwindSectionHeader {
223 UnwindSectionHeader(A &addressSpace, typename A::pint_t addr)
224 : _addressSpace(addressSpace), _addr(addr) {}
226 uint32_t version() const {
227 return _addressSpace.get32(_addr +
228 offsetof(unwind_info_section_header, version));
230 uint32_t commonEncodingsArraySectionOffset() const {
231 return _addressSpace.get32(_addr +
232 offsetof(unwind_info_section_header,
233 commonEncodingsArraySectionOffset));
235 uint32_t commonEncodingsArrayCount() const {
236 return _addressSpace.get32(_addr + offsetof(unwind_info_section_header,
237 commonEncodingsArrayCount));
239 uint32_t personalityArraySectionOffset() const {
240 return _addressSpace.get32(_addr + offsetof(unwind_info_section_header,
241 personalityArraySectionOffset));
243 uint32_t personalityArrayCount() const {
244 return _addressSpace.get32(
245 _addr + offsetof(unwind_info_section_header, personalityArrayCount));
247 uint32_t indexSectionOffset() const {
248 return _addressSpace.get32(
249 _addr + offsetof(unwind_info_section_header, indexSectionOffset));
251 uint32_t indexCount() const {
252 return _addressSpace.get32(
253 _addr + offsetof(unwind_info_section_header, indexCount));
258 typename A::pint_t _addr;
261 template <typename A> class UnwindSectionIndexArray {
263 UnwindSectionIndexArray(A &addressSpace, typename A::pint_t addr)
264 : _addressSpace(addressSpace), _addr(addr) {}
266 uint32_t functionOffset(uint32_t index) const {
267 return _addressSpace.get32(
268 _addr + arrayoffsetof(unwind_info_section_header_index_entry, index,
271 uint32_t secondLevelPagesSectionOffset(uint32_t index) const {
272 return _addressSpace.get32(
273 _addr + arrayoffsetof(unwind_info_section_header_index_entry, index,
274 secondLevelPagesSectionOffset));
276 uint32_t lsdaIndexArraySectionOffset(uint32_t index) const {
277 return _addressSpace.get32(
278 _addr + arrayoffsetof(unwind_info_section_header_index_entry, index,
279 lsdaIndexArraySectionOffset));
284 typename A::pint_t _addr;
287 template <typename A> class UnwindSectionRegularPageHeader {
289 UnwindSectionRegularPageHeader(A &addressSpace, typename A::pint_t addr)
290 : _addressSpace(addressSpace), _addr(addr) {}
292 uint32_t kind() const {
293 return _addressSpace.get32(
294 _addr + offsetof(unwind_info_regular_second_level_page_header, kind));
296 uint16_t entryPageOffset() const {
297 return _addressSpace.get16(
298 _addr + offsetof(unwind_info_regular_second_level_page_header,
301 uint16_t entryCount() const {
302 return _addressSpace.get16(
304 offsetof(unwind_info_regular_second_level_page_header, entryCount));
309 typename A::pint_t _addr;
312 template <typename A> class UnwindSectionRegularArray {
314 UnwindSectionRegularArray(A &addressSpace, typename A::pint_t addr)
315 : _addressSpace(addressSpace), _addr(addr) {}
317 uint32_t functionOffset(uint32_t index) const {
318 return _addressSpace.get32(
319 _addr + arrayoffsetof(unwind_info_regular_second_level_entry, index,
322 uint32_t encoding(uint32_t index) const {
323 return _addressSpace.get32(
325 arrayoffsetof(unwind_info_regular_second_level_entry, index, encoding));
330 typename A::pint_t _addr;
333 template <typename A> class UnwindSectionCompressedPageHeader {
335 UnwindSectionCompressedPageHeader(A &addressSpace, typename A::pint_t addr)
336 : _addressSpace(addressSpace), _addr(addr) {}
338 uint32_t kind() const {
339 return _addressSpace.get32(
341 offsetof(unwind_info_compressed_second_level_page_header, kind));
343 uint16_t entryPageOffset() const {
344 return _addressSpace.get16(
345 _addr + offsetof(unwind_info_compressed_second_level_page_header,
348 uint16_t entryCount() const {
349 return _addressSpace.get16(
351 offsetof(unwind_info_compressed_second_level_page_header, entryCount));
353 uint16_t encodingsPageOffset() const {
354 return _addressSpace.get16(
355 _addr + offsetof(unwind_info_compressed_second_level_page_header,
356 encodingsPageOffset));
358 uint16_t encodingsCount() const {
359 return _addressSpace.get16(
360 _addr + offsetof(unwind_info_compressed_second_level_page_header,
366 typename A::pint_t _addr;
369 template <typename A> class UnwindSectionCompressedArray {
371 UnwindSectionCompressedArray(A &addressSpace, typename A::pint_t addr)
372 : _addressSpace(addressSpace), _addr(addr) {}
374 uint32_t functionOffset(uint32_t index) const {
375 return UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(
376 _addressSpace.get32(_addr + index * sizeof(uint32_t)));
378 uint16_t encodingIndex(uint32_t index) const {
379 return UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(
380 _addressSpace.get32(_addr + index * sizeof(uint32_t)));
385 typename A::pint_t _addr;
388 template <typename A> class UnwindSectionLsdaArray {
390 UnwindSectionLsdaArray(A &addressSpace, typename A::pint_t addr)
391 : _addressSpace(addressSpace), _addr(addr) {}
393 uint32_t functionOffset(uint32_t index) const {
394 return _addressSpace.get32(
395 _addr + arrayoffsetof(unwind_info_section_header_lsda_index_entry,
396 index, functionOffset));
398 uint32_t lsdaOffset(uint32_t index) const {
399 return _addressSpace.get32(
400 _addr + arrayoffsetof(unwind_info_section_header_lsda_index_entry,
406 typename A::pint_t _addr;
408 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
410 class _LIBUNWIND_HIDDEN AbstractUnwindCursor {
412 // NOTE: provide a class specific placement deallocation function (S5.3.4 p20)
413 // This avoids an unnecessary dependency to libc++abi.
414 void operator delete(void *, size_t) {}
416 virtual ~AbstractUnwindCursor() {}
417 virtual bool validReg(int) { _LIBUNWIND_ABORT("validReg not implemented"); }
418 virtual unw_word_t getReg(int) { _LIBUNWIND_ABORT("getReg not implemented"); }
419 virtual void setReg(int, unw_word_t) {
420 _LIBUNWIND_ABORT("setReg not implemented");
422 virtual bool validFloatReg(int) {
423 _LIBUNWIND_ABORT("validFloatReg not implemented");
425 virtual unw_fpreg_t getFloatReg(int) {
426 _LIBUNWIND_ABORT("getFloatReg not implemented");
428 virtual void setFloatReg(int, unw_fpreg_t) {
429 _LIBUNWIND_ABORT("setFloatReg not implemented");
431 virtual int step() { _LIBUNWIND_ABORT("step not implemented"); }
432 virtual void getInfo(unw_proc_info_t *) {
433 _LIBUNWIND_ABORT("getInfo not implemented");
435 virtual void jumpto() { _LIBUNWIND_ABORT("jumpto not implemented"); }
436 virtual bool isSignalFrame() {
437 _LIBUNWIND_ABORT("isSignalFrame not implemented");
439 virtual bool getFunctionName(char *, size_t, unw_word_t *) {
440 _LIBUNWIND_ABORT("getFunctionName not implemented");
442 virtual void setInfoBasedOnIPRegister(bool = false) {
443 _LIBUNWIND_ABORT("setInfoBasedOnIPRegister not implemented");
445 virtual const char *getRegisterName(int) {
446 _LIBUNWIND_ABORT("getRegisterName not implemented");
449 virtual void saveVFPAsX() { _LIBUNWIND_ABORT("saveVFPAsX not implemented"); }
453 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
455 /// \c UnwindCursor contains all state (including all register values) during
456 /// an unwind. This is normally stack-allocated inside a unw_cursor_t.
457 template <typename A, typename R>
458 class UnwindCursor : public AbstractUnwindCursor {
459 typedef typename A::pint_t pint_t;
461 UnwindCursor(unw_context_t *context, A &as);
462 UnwindCursor(CONTEXT *context, A &as);
463 UnwindCursor(A &as, void *threadArg);
464 virtual ~UnwindCursor() {}
465 virtual bool validReg(int);
466 virtual unw_word_t getReg(int);
467 virtual void setReg(int, unw_word_t);
468 virtual bool validFloatReg(int);
469 virtual unw_fpreg_t getFloatReg(int);
470 virtual void setFloatReg(int, unw_fpreg_t);
472 virtual void getInfo(unw_proc_info_t *);
473 virtual void jumpto();
474 virtual bool isSignalFrame();
475 virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);
476 virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);
477 virtual const char *getRegisterName(int num);
479 virtual void saveVFPAsX();
482 DISPATCHER_CONTEXT *getDispatcherContext() { return &_dispContext; }
483 void setDispatcherContext(DISPATCHER_CONTEXT *disp) { _dispContext = *disp; }
485 // libunwind does not and should not depend on C++ library which means that we
486 // need our own defition of inline placement new.
487 static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }
491 pint_t getLastPC() const { return _dispContext.ControlPc; }
492 void setLastPC(pint_t pc) { _dispContext.ControlPc = pc; }
493 RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {
494 _dispContext.FunctionEntry = RtlLookupFunctionEntry(pc,
495 &_dispContext.ImageBase,
496 _dispContext.HistoryTable);
497 *base = _dispContext.ImageBase;
498 return _dispContext.FunctionEntry;
500 bool getInfoFromSEH(pint_t pc);
501 int stepWithSEHData() {
502 _dispContext.LanguageHandler = RtlVirtualUnwind(UNW_FLAG_UHANDLER,
503 _dispContext.ImageBase,
504 _dispContext.ControlPc,
505 _dispContext.FunctionEntry,
506 _dispContext.ContextRecord,
507 &_dispContext.HandlerData,
508 &_dispContext.EstablisherFrame,
510 // Update some fields of the unwind info now, since we have them.
511 _info.lsda = reinterpret_cast<unw_word_t>(_dispContext.HandlerData);
512 if (_dispContext.LanguageHandler) {
513 _info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);
516 return UNW_STEP_SUCCESS;
520 unw_proc_info_t _info;
521 DISPATCHER_CONTEXT _dispContext;
523 UNWIND_HISTORY_TABLE _histTable;
524 bool _unwindInfoMissing;
528 template <typename A, typename R>
529 UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
530 : _addressSpace(as), _unwindInfoMissing(false) {
531 static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
532 "UnwindCursor<> does not fit in unw_cursor_t");
533 memset(&_info, 0, sizeof(_info));
534 memset(&_histTable, 0, sizeof(_histTable));
535 _dispContext.ContextRecord = &_msContext;
536 _dispContext.HistoryTable = &_histTable;
537 // Initialize MS context from ours.
539 _msContext.ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_FLOATING_POINT;
540 #if defined(_LIBUNWIND_TARGET_X86_64)
541 _msContext.Rax = r.getRegister(UNW_X86_64_RAX);
542 _msContext.Rcx = r.getRegister(UNW_X86_64_RCX);
543 _msContext.Rdx = r.getRegister(UNW_X86_64_RDX);
544 _msContext.Rbx = r.getRegister(UNW_X86_64_RBX);
545 _msContext.Rsp = r.getRegister(UNW_X86_64_RSP);
546 _msContext.Rbp = r.getRegister(UNW_X86_64_RBP);
547 _msContext.Rsi = r.getRegister(UNW_X86_64_RSI);
548 _msContext.Rdi = r.getRegister(UNW_X86_64_RDI);
549 _msContext.R8 = r.getRegister(UNW_X86_64_R8);
550 _msContext.R9 = r.getRegister(UNW_X86_64_R9);
551 _msContext.R10 = r.getRegister(UNW_X86_64_R10);
552 _msContext.R11 = r.getRegister(UNW_X86_64_R11);
553 _msContext.R12 = r.getRegister(UNW_X86_64_R12);
554 _msContext.R13 = r.getRegister(UNW_X86_64_R13);
555 _msContext.R14 = r.getRegister(UNW_X86_64_R14);
556 _msContext.R15 = r.getRegister(UNW_X86_64_R15);
557 _msContext.Rip = r.getRegister(UNW_REG_IP);
562 t.v = r.getVectorRegister(UNW_X86_64_XMM0);
563 _msContext.Xmm0 = t.m;
564 t.v = r.getVectorRegister(UNW_X86_64_XMM1);
565 _msContext.Xmm1 = t.m;
566 t.v = r.getVectorRegister(UNW_X86_64_XMM2);
567 _msContext.Xmm2 = t.m;
568 t.v = r.getVectorRegister(UNW_X86_64_XMM3);
569 _msContext.Xmm3 = t.m;
570 t.v = r.getVectorRegister(UNW_X86_64_XMM4);
571 _msContext.Xmm4 = t.m;
572 t.v = r.getVectorRegister(UNW_X86_64_XMM5);
573 _msContext.Xmm5 = t.m;
574 t.v = r.getVectorRegister(UNW_X86_64_XMM6);
575 _msContext.Xmm6 = t.m;
576 t.v = r.getVectorRegister(UNW_X86_64_XMM7);
577 _msContext.Xmm7 = t.m;
578 t.v = r.getVectorRegister(UNW_X86_64_XMM8);
579 _msContext.Xmm8 = t.m;
580 t.v = r.getVectorRegister(UNW_X86_64_XMM9);
581 _msContext.Xmm9 = t.m;
582 t.v = r.getVectorRegister(UNW_X86_64_XMM10);
583 _msContext.Xmm10 = t.m;
584 t.v = r.getVectorRegister(UNW_X86_64_XMM11);
585 _msContext.Xmm11 = t.m;
586 t.v = r.getVectorRegister(UNW_X86_64_XMM12);
587 _msContext.Xmm12 = t.m;
588 t.v = r.getVectorRegister(UNW_X86_64_XMM13);
589 _msContext.Xmm13 = t.m;
590 t.v = r.getVectorRegister(UNW_X86_64_XMM14);
591 _msContext.Xmm14 = t.m;
592 t.v = r.getVectorRegister(UNW_X86_64_XMM15);
593 _msContext.Xmm15 = t.m;
594 #elif defined(_LIBUNWIND_TARGET_ARM)
595 _msContext.R0 = r.getRegister(UNW_ARM_R0);
596 _msContext.R1 = r.getRegister(UNW_ARM_R1);
597 _msContext.R2 = r.getRegister(UNW_ARM_R2);
598 _msContext.R3 = r.getRegister(UNW_ARM_R3);
599 _msContext.R4 = r.getRegister(UNW_ARM_R4);
600 _msContext.R5 = r.getRegister(UNW_ARM_R5);
601 _msContext.R6 = r.getRegister(UNW_ARM_R6);
602 _msContext.R7 = r.getRegister(UNW_ARM_R7);
603 _msContext.R8 = r.getRegister(UNW_ARM_R8);
604 _msContext.R9 = r.getRegister(UNW_ARM_R9);
605 _msContext.R10 = r.getRegister(UNW_ARM_R10);
606 _msContext.R11 = r.getRegister(UNW_ARM_R11);
607 _msContext.R12 = r.getRegister(UNW_ARM_R12);
608 _msContext.Sp = r.getRegister(UNW_ARM_SP);
609 _msContext.Lr = r.getRegister(UNW_ARM_LR);
610 _msContext.Pc = r.getRegister(UNW_ARM_IP);
611 for (int i = UNW_ARM_D0; i <= UNW_ARM_D31; ++i) {
616 d.d = r.getFloatRegister(i);
617 _msContext.D[i - UNW_ARM_D0] = d.w;
619 #elif defined(_LIBUNWIND_TARGET_AARCH64)
620 for (int i = UNW_ARM64_X0; i <= UNW_ARM64_X30; ++i)
621 _msContext.X[i - UNW_ARM64_X0] = r.getRegister(i);
622 _msContext.Sp = r.getRegister(UNW_REG_SP);
623 _msContext.Pc = r.getRegister(UNW_REG_IP);
624 for (int i = UNW_ARM64_D0; i <= UNW_ARM64_D31; ++i)
625 _msContext.V[i - UNW_ARM64_D0].D[0] = r.getFloatRegister(i);
629 template <typename A, typename R>
630 UnwindCursor<A, R>::UnwindCursor(CONTEXT *context, A &as)
631 : _addressSpace(as), _unwindInfoMissing(false) {
632 static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
633 "UnwindCursor<> does not fit in unw_cursor_t");
634 memset(&_info, 0, sizeof(_info));
635 memset(&_histTable, 0, sizeof(_histTable));
636 _dispContext.ContextRecord = &_msContext;
637 _dispContext.HistoryTable = &_histTable;
638 _msContext = *context;
642 template <typename A, typename R>
643 bool UnwindCursor<A, R>::validReg(int regNum) {
644 if (regNum == UNW_REG_IP || regNum == UNW_REG_SP) return true;
645 #if defined(_LIBUNWIND_TARGET_X86_64)
646 if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_R15) return true;
647 #elif defined(_LIBUNWIND_TARGET_ARM)
648 if (regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) return true;
649 #elif defined(_LIBUNWIND_TARGET_AARCH64)
650 if (regNum >= UNW_ARM64_X0 && regNum <= UNW_ARM64_X30) return true;
655 template <typename A, typename R>
656 unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
658 #if defined(_LIBUNWIND_TARGET_X86_64)
659 case UNW_REG_IP: return _msContext.Rip;
660 case UNW_X86_64_RAX: return _msContext.Rax;
661 case UNW_X86_64_RDX: return _msContext.Rdx;
662 case UNW_X86_64_RCX: return _msContext.Rcx;
663 case UNW_X86_64_RBX: return _msContext.Rbx;
665 case UNW_X86_64_RSP: return _msContext.Rsp;
666 case UNW_X86_64_RBP: return _msContext.Rbp;
667 case UNW_X86_64_RSI: return _msContext.Rsi;
668 case UNW_X86_64_RDI: return _msContext.Rdi;
669 case UNW_X86_64_R8: return _msContext.R8;
670 case UNW_X86_64_R9: return _msContext.R9;
671 case UNW_X86_64_R10: return _msContext.R10;
672 case UNW_X86_64_R11: return _msContext.R11;
673 case UNW_X86_64_R12: return _msContext.R12;
674 case UNW_X86_64_R13: return _msContext.R13;
675 case UNW_X86_64_R14: return _msContext.R14;
676 case UNW_X86_64_R15: return _msContext.R15;
677 #elif defined(_LIBUNWIND_TARGET_ARM)
678 case UNW_ARM_R0: return _msContext.R0;
679 case UNW_ARM_R1: return _msContext.R1;
680 case UNW_ARM_R2: return _msContext.R2;
681 case UNW_ARM_R3: return _msContext.R3;
682 case UNW_ARM_R4: return _msContext.R4;
683 case UNW_ARM_R5: return _msContext.R5;
684 case UNW_ARM_R6: return _msContext.R6;
685 case UNW_ARM_R7: return _msContext.R7;
686 case UNW_ARM_R8: return _msContext.R8;
687 case UNW_ARM_R9: return _msContext.R9;
688 case UNW_ARM_R10: return _msContext.R10;
689 case UNW_ARM_R11: return _msContext.R11;
690 case UNW_ARM_R12: return _msContext.R12;
692 case UNW_ARM_SP: return _msContext.Sp;
693 case UNW_ARM_LR: return _msContext.Lr;
695 case UNW_ARM_IP: return _msContext.Pc;
696 #elif defined(_LIBUNWIND_TARGET_AARCH64)
697 case UNW_REG_SP: return _msContext.Sp;
698 case UNW_REG_IP: return _msContext.Pc;
699 default: return _msContext.X[regNum - UNW_ARM64_X0];
702 _LIBUNWIND_ABORT("unsupported register");
705 template <typename A, typename R>
706 void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {
708 #if defined(_LIBUNWIND_TARGET_X86_64)
709 case UNW_REG_IP: _msContext.Rip = value; break;
710 case UNW_X86_64_RAX: _msContext.Rax = value; break;
711 case UNW_X86_64_RDX: _msContext.Rdx = value; break;
712 case UNW_X86_64_RCX: _msContext.Rcx = value; break;
713 case UNW_X86_64_RBX: _msContext.Rbx = value; break;
715 case UNW_X86_64_RSP: _msContext.Rsp = value; break;
716 case UNW_X86_64_RBP: _msContext.Rbp = value; break;
717 case UNW_X86_64_RSI: _msContext.Rsi = value; break;
718 case UNW_X86_64_RDI: _msContext.Rdi = value; break;
719 case UNW_X86_64_R8: _msContext.R8 = value; break;
720 case UNW_X86_64_R9: _msContext.R9 = value; break;
721 case UNW_X86_64_R10: _msContext.R10 = value; break;
722 case UNW_X86_64_R11: _msContext.R11 = value; break;
723 case UNW_X86_64_R12: _msContext.R12 = value; break;
724 case UNW_X86_64_R13: _msContext.R13 = value; break;
725 case UNW_X86_64_R14: _msContext.R14 = value; break;
726 case UNW_X86_64_R15: _msContext.R15 = value; break;
727 #elif defined(_LIBUNWIND_TARGET_ARM)
728 case UNW_ARM_R0: _msContext.R0 = value; break;
729 case UNW_ARM_R1: _msContext.R1 = value; break;
730 case UNW_ARM_R2: _msContext.R2 = value; break;
731 case UNW_ARM_R3: _msContext.R3 = value; break;
732 case UNW_ARM_R4: _msContext.R4 = value; break;
733 case UNW_ARM_R5: _msContext.R5 = value; break;
734 case UNW_ARM_R6: _msContext.R6 = value; break;
735 case UNW_ARM_R7: _msContext.R7 = value; break;
736 case UNW_ARM_R8: _msContext.R8 = value; break;
737 case UNW_ARM_R9: _msContext.R9 = value; break;
738 case UNW_ARM_R10: _msContext.R10 = value; break;
739 case UNW_ARM_R11: _msContext.R11 = value; break;
740 case UNW_ARM_R12: _msContext.R12 = value; break;
742 case UNW_ARM_SP: _msContext.Sp = value; break;
743 case UNW_ARM_LR: _msContext.Lr = value; break;
745 case UNW_ARM_IP: _msContext.Pc = value; break;
746 #elif defined(_LIBUNWIND_TARGET_AARCH64)
747 case UNW_REG_SP: _msContext.Sp = value; break;
748 case UNW_REG_IP: _msContext.Pc = value; break;
779 case UNW_ARM64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;
782 _LIBUNWIND_ABORT("unsupported register");
786 template <typename A, typename R>
787 bool UnwindCursor<A, R>::validFloatReg(int regNum) {
788 #if defined(_LIBUNWIND_TARGET_ARM)
789 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) return true;
790 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) return true;
791 #elif defined(_LIBUNWIND_TARGET_AARCH64)
792 if (regNum >= UNW_ARM64_D0 && regNum <= UNW_ARM64_D31) return true;
799 template <typename A, typename R>
800 unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {
801 #if defined(_LIBUNWIND_TARGET_ARM)
802 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {
807 d.w = _msContext.S[regNum - UNW_ARM_S0];
810 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {
815 d.w = _msContext.D[regNum - UNW_ARM_D0];
818 _LIBUNWIND_ABORT("unsupported float register");
819 #elif defined(_LIBUNWIND_TARGET_AARCH64)
820 return _msContext.V[regNum - UNW_ARM64_D0].D[0];
823 _LIBUNWIND_ABORT("float registers unimplemented");
827 template <typename A, typename R>
828 void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
829 #if defined(_LIBUNWIND_TARGET_ARM)
830 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {
836 _msContext.S[regNum - UNW_ARM_S0] = d.w;
838 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {
844 _msContext.D[regNum - UNW_ARM_D0] = d.w;
846 _LIBUNWIND_ABORT("unsupported float register");
847 #elif defined(_LIBUNWIND_TARGET_AARCH64)
848 _msContext.V[regNum - UNW_ARM64_D0].D[0] = value;
852 _LIBUNWIND_ABORT("float registers unimplemented");
856 template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {
857 RtlRestoreContext(&_msContext, nullptr);
861 template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {}
864 template <typename A, typename R>
865 const char *UnwindCursor<A, R>::getRegisterName(int regNum) {
866 return R::getRegisterName(regNum);
869 template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {
873 #else // !defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) || !defined(_WIN32)
875 /// UnwindCursor contains all state (including all register values) during
876 /// an unwind. This is normally stack allocated inside a unw_cursor_t.
877 template <typename A, typename R>
878 class UnwindCursor : public AbstractUnwindCursor{
879 typedef typename A::pint_t pint_t;
881 UnwindCursor(unw_context_t *context, A &as);
882 UnwindCursor(A &as, void *threadArg);
883 virtual ~UnwindCursor() {}
884 virtual bool validReg(int);
885 virtual unw_word_t getReg(int);
886 virtual void setReg(int, unw_word_t);
887 virtual bool validFloatReg(int);
888 virtual unw_fpreg_t getFloatReg(int);
889 virtual void setFloatReg(int, unw_fpreg_t);
891 virtual void getInfo(unw_proc_info_t *);
892 virtual void jumpto();
893 virtual bool isSignalFrame();
894 virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);
895 virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);
896 virtual const char *getRegisterName(int num);
898 virtual void saveVFPAsX();
901 // libunwind does not and should not depend on C++ library which means that we
902 // need our own defition of inline placement new.
903 static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }
907 #if defined(_LIBUNWIND_ARM_EHABI)
908 bool getInfoFromEHABISection(pint_t pc, const UnwindInfoSections §s);
910 int stepWithEHABI() {
913 // FIXME: Calling decode_eht_entry() here is violating the libunwind
914 // abstraction layer.
915 const uint32_t *ehtp =
916 decode_eht_entry(reinterpret_cast<const uint32_t *>(_info.unwind_info),
918 if (_Unwind_VRS_Interpret((_Unwind_Context *)this, ehtp, off, len) !=
919 _URC_CONTINUE_UNWIND)
921 return UNW_STEP_SUCCESS;
925 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
926 bool getInfoFromDwarfSection(pint_t pc, const UnwindInfoSections §s,
927 uint32_t fdeSectionOffsetHint=0);
928 int stepWithDwarfFDE() {
929 return DwarfInstructions<A, R>::stepWithDwarf(_addressSpace,
930 (pint_t)this->getReg(UNW_REG_IP),
931 (pint_t)_info.unwind_info,
936 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
937 bool getInfoFromCompactEncodingSection(pint_t pc,
938 const UnwindInfoSections §s);
939 int stepWithCompactEncoding() {
940 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
941 if ( compactSaysUseDwarf() )
942 return stepWithDwarfFDE();
945 return stepWithCompactEncoding(dummy);
948 #if defined(_LIBUNWIND_TARGET_X86_64)
949 int stepWithCompactEncoding(Registers_x86_64 &) {
950 return CompactUnwinder_x86_64<A>::stepWithCompactEncoding(
951 _info.format, _info.start_ip, _addressSpace, _registers);
955 #if defined(_LIBUNWIND_TARGET_I386)
956 int stepWithCompactEncoding(Registers_x86 &) {
957 return CompactUnwinder_x86<A>::stepWithCompactEncoding(
958 _info.format, (uint32_t)_info.start_ip, _addressSpace, _registers);
962 #if defined(_LIBUNWIND_TARGET_PPC)
963 int stepWithCompactEncoding(Registers_ppc &) {
968 #if defined(_LIBUNWIND_TARGET_PPC64)
969 int stepWithCompactEncoding(Registers_ppc64 &) {
975 #if defined(_LIBUNWIND_TARGET_AARCH64)
976 int stepWithCompactEncoding(Registers_arm64 &) {
977 return CompactUnwinder_arm64<A>::stepWithCompactEncoding(
978 _info.format, _info.start_ip, _addressSpace, _registers);
982 #if defined(_LIBUNWIND_TARGET_MIPS_O32)
983 int stepWithCompactEncoding(Registers_mips_o32 &) {
988 #if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
989 int stepWithCompactEncoding(Registers_mips_newabi &) {
994 #if defined(_LIBUNWIND_TARGET_SPARC)
995 int stepWithCompactEncoding(Registers_sparc &) { return UNW_EINVAL; }
998 bool compactSaysUseDwarf(uint32_t *offset=NULL) const {
1000 return compactSaysUseDwarf(dummy, offset);
1003 #if defined(_LIBUNWIND_TARGET_X86_64)
1004 bool compactSaysUseDwarf(Registers_x86_64 &, uint32_t *offset) const {
1005 if ((_info.format & UNWIND_X86_64_MODE_MASK) == UNWIND_X86_64_MODE_DWARF) {
1007 *offset = (_info.format & UNWIND_X86_64_DWARF_SECTION_OFFSET);
1014 #if defined(_LIBUNWIND_TARGET_I386)
1015 bool compactSaysUseDwarf(Registers_x86 &, uint32_t *offset) const {
1016 if ((_info.format & UNWIND_X86_MODE_MASK) == UNWIND_X86_MODE_DWARF) {
1018 *offset = (_info.format & UNWIND_X86_DWARF_SECTION_OFFSET);
1025 #if defined(_LIBUNWIND_TARGET_PPC)
1026 bool compactSaysUseDwarf(Registers_ppc &, uint32_t *) const {
1031 #if defined(_LIBUNWIND_TARGET_PPC64)
1032 bool compactSaysUseDwarf(Registers_ppc64 &, uint32_t *) const {
1037 #if defined(_LIBUNWIND_TARGET_AARCH64)
1038 bool compactSaysUseDwarf(Registers_arm64 &, uint32_t *offset) const {
1039 if ((_info.format & UNWIND_ARM64_MODE_MASK) == UNWIND_ARM64_MODE_DWARF) {
1041 *offset = (_info.format & UNWIND_ARM64_DWARF_SECTION_OFFSET);
1048 #if defined(_LIBUNWIND_TARGET_MIPS_O32)
1049 bool compactSaysUseDwarf(Registers_mips_o32 &, uint32_t *) const {
1054 #if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
1055 bool compactSaysUseDwarf(Registers_mips_newabi &, uint32_t *) const {
1060 #if defined(_LIBUNWIND_TARGET_SPARC)
1061 bool compactSaysUseDwarf(Registers_sparc &, uint32_t *) const { return true; }
1064 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1066 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1067 compact_unwind_encoding_t dwarfEncoding() const {
1069 return dwarfEncoding(dummy);
1072 #if defined(_LIBUNWIND_TARGET_X86_64)
1073 compact_unwind_encoding_t dwarfEncoding(Registers_x86_64 &) const {
1074 return UNWIND_X86_64_MODE_DWARF;
1078 #if defined(_LIBUNWIND_TARGET_I386)
1079 compact_unwind_encoding_t dwarfEncoding(Registers_x86 &) const {
1080 return UNWIND_X86_MODE_DWARF;
1084 #if defined(_LIBUNWIND_TARGET_PPC)
1085 compact_unwind_encoding_t dwarfEncoding(Registers_ppc &) const {
1090 #if defined(_LIBUNWIND_TARGET_PPC64)
1091 compact_unwind_encoding_t dwarfEncoding(Registers_ppc64 &) const {
1096 #if defined(_LIBUNWIND_TARGET_AARCH64)
1097 compact_unwind_encoding_t dwarfEncoding(Registers_arm64 &) const {
1098 return UNWIND_ARM64_MODE_DWARF;
1102 #if defined(_LIBUNWIND_TARGET_ARM)
1103 compact_unwind_encoding_t dwarfEncoding(Registers_arm &) const {
1108 #if defined (_LIBUNWIND_TARGET_OR1K)
1109 compact_unwind_encoding_t dwarfEncoding(Registers_or1k &) const {
1114 #if defined (_LIBUNWIND_TARGET_RISCV)
1115 compact_unwind_encoding_t dwarfEncoding(Registers_riscv &) const {
1120 #if defined (_LIBUNWIND_TARGET_MIPS_O32)
1121 compact_unwind_encoding_t dwarfEncoding(Registers_mips_o32 &) const {
1126 #if defined (_LIBUNWIND_TARGET_MIPS_NEWABI)
1127 compact_unwind_encoding_t dwarfEncoding(Registers_mips_newabi &) const {
1132 #if defined(_LIBUNWIND_TARGET_SPARC)
1133 compact_unwind_encoding_t dwarfEncoding(Registers_sparc &) const { return 0; }
1136 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1138 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1139 // For runtime environments using SEH unwind data without Windows runtime
1141 pint_t getLastPC() const { /* FIXME: Implement */ return 0; }
1142 void setLastPC(pint_t pc) { /* FIXME: Implement */ }
1143 RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {
1144 /* FIXME: Implement */
1148 bool getInfoFromSEH(pint_t pc);
1149 int stepWithSEHData() { /* FIXME: Implement */ return 0; }
1150 #endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1155 unw_proc_info_t _info;
1156 bool _unwindInfoMissing;
1157 bool _isSignalFrame;
1161 template <typename A, typename R>
1162 UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
1163 : _addressSpace(as), _registers(context), _unwindInfoMissing(false),
1164 _isSignalFrame(false) {
1165 static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
1166 "UnwindCursor<> does not fit in unw_cursor_t");
1167 memset(&_info, 0, sizeof(_info));
1170 template <typename A, typename R>
1171 UnwindCursor<A, R>::UnwindCursor(A &as, void *)
1172 : _addressSpace(as), _unwindInfoMissing(false), _isSignalFrame(false) {
1173 memset(&_info, 0, sizeof(_info));
1175 // fill in _registers from thread arg
1179 template <typename A, typename R>
1180 bool UnwindCursor<A, R>::validReg(int regNum) {
1181 return _registers.validRegister(regNum);
1184 template <typename A, typename R>
1185 unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
1186 return _registers.getRegister(regNum);
1189 template <typename A, typename R>
1190 void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {
1191 _registers.setRegister(regNum, (typename A::pint_t)value);
1194 template <typename A, typename R>
1195 bool UnwindCursor<A, R>::validFloatReg(int regNum) {
1196 return _registers.validFloatRegister(regNum);
1199 template <typename A, typename R>
1200 unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {
1201 return _registers.getFloatRegister(regNum);
1204 template <typename A, typename R>
1205 void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
1206 _registers.setFloatRegister(regNum, value);
1209 template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {
1210 _registers.jumpto();
1214 template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {
1215 _registers.saveVFPAsX();
1219 template <typename A, typename R>
1220 const char *UnwindCursor<A, R>::getRegisterName(int regNum) {
1221 return _registers.getRegisterName(regNum);
1224 template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {
1225 return _isSignalFrame;
1228 #endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1230 #if defined(_LIBUNWIND_ARM_EHABI)
1231 struct EHABIIndexEntry {
1232 uint32_t functionOffset;
1236 template<typename A>
1237 struct EHABISectionIterator {
1238 typedef EHABISectionIterator _Self;
1240 typedef typename A::pint_t value_type;
1241 typedef typename A::pint_t* pointer;
1242 typedef typename A::pint_t& reference;
1243 typedef size_t size_type;
1244 typedef size_t difference_type;
1246 static _Self begin(A& addressSpace, const UnwindInfoSections& sects) {
1247 return _Self(addressSpace, sects, 0);
1249 static _Self end(A& addressSpace, const UnwindInfoSections& sects) {
1250 return _Self(addressSpace, sects,
1251 sects.arm_section_length / sizeof(EHABIIndexEntry));
1254 EHABISectionIterator(A& addressSpace, const UnwindInfoSections& sects, size_t i)
1255 : _i(i), _addressSpace(&addressSpace), _sects(§s) {}
1257 _Self& operator++() { ++_i; return *this; }
1258 _Self& operator+=(size_t a) { _i += a; return *this; }
1259 _Self& operator--() { assert(_i > 0); --_i; return *this; }
1260 _Self& operator-=(size_t a) { assert(_i >= a); _i -= a; return *this; }
1262 _Self operator+(size_t a) { _Self out = *this; out._i += a; return out; }
1263 _Self operator-(size_t a) { assert(_i >= a); _Self out = *this; out._i -= a; return out; }
1265 size_t operator-(const _Self& other) { return _i - other._i; }
1267 bool operator==(const _Self& other) const {
1268 assert(_addressSpace == other._addressSpace);
1269 assert(_sects == other._sects);
1270 return _i == other._i;
1273 typename A::pint_t operator*() const { return functionAddress(); }
1275 typename A::pint_t functionAddress() const {
1276 typename A::pint_t indexAddr = _sects->arm_section + arrayoffsetof(
1277 EHABIIndexEntry, _i, functionOffset);
1278 return indexAddr + signExtendPrel31(_addressSpace->get32(indexAddr));
1281 typename A::pint_t dataAddress() {
1282 typename A::pint_t indexAddr = _sects->arm_section + arrayoffsetof(
1283 EHABIIndexEntry, _i, data);
1290 const UnwindInfoSections* _sects;
1295 template <typename A>
1296 EHABISectionIterator<A> EHABISectionUpperBound(
1297 EHABISectionIterator<A> first,
1298 EHABISectionIterator<A> last,
1299 typename A::pint_t value) {
1300 size_t len = last - first;
1302 size_t l2 = len / 2;
1303 EHABISectionIterator<A> m = first + l2;
1316 template <typename A, typename R>
1317 bool UnwindCursor<A, R>::getInfoFromEHABISection(
1319 const UnwindInfoSections §s) {
1320 EHABISectionIterator<A> begin =
1321 EHABISectionIterator<A>::begin(_addressSpace, sects);
1322 EHABISectionIterator<A> end =
1323 EHABISectionIterator<A>::end(_addressSpace, sects);
1327 EHABISectionIterator<A> itNextPC = EHABISectionUpperBound(begin, end, pc);
1328 if (itNextPC == begin)
1330 EHABISectionIterator<A> itThisPC = itNextPC - 1;
1332 pint_t thisPC = itThisPC.functionAddress();
1333 // If an exception is thrown from a function, corresponding to the last entry
1334 // in the table, we don't really know the function extent and have to choose a
1335 // value for nextPC. Choosing max() will allow the range check during trace to
1337 pint_t nextPC = (itNextPC == end) ? UINTPTR_MAX : itNextPC.functionAddress();
1338 pint_t indexDataAddr = itThisPC.dataAddress();
1340 if (indexDataAddr == 0)
1343 uint32_t indexData = _addressSpace.get32(indexDataAddr);
1344 if (indexData == UNW_EXIDX_CANTUNWIND)
1347 // If the high bit is set, the exception handling table entry is inline inside
1348 // the index table entry on the second word (aka |indexDataAddr|). Otherwise,
1349 // the table points at an offset in the exception handling table (section 5 EHABI).
1350 pint_t exceptionTableAddr;
1351 uint32_t exceptionTableData;
1352 bool isSingleWordEHT;
1353 if (indexData & 0x80000000) {
1354 exceptionTableAddr = indexDataAddr;
1355 // TODO(ajwong): Should this data be 0?
1356 exceptionTableData = indexData;
1357 isSingleWordEHT = true;
1359 exceptionTableAddr = indexDataAddr + signExtendPrel31(indexData);
1360 exceptionTableData = _addressSpace.get32(exceptionTableAddr);
1361 isSingleWordEHT = false;
1364 // Now we know the 3 things:
1365 // exceptionTableAddr -- exception handler table entry.
1366 // exceptionTableData -- the data inside the first word of the eht entry.
1367 // isSingleWordEHT -- whether the entry is in the index.
1368 unw_word_t personalityRoutine = 0xbadf00d;
1369 bool scope32 = false;
1372 // If the high bit in the exception handling table entry is set, the entry is
1373 // in compact form (section 6.3 EHABI).
1374 if (exceptionTableData & 0x80000000) {
1375 // Grab the index of the personality routine from the compact form.
1376 uint32_t choice = (exceptionTableData & 0x0f000000) >> 24;
1377 uint32_t extraWords = 0;
1380 personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr0;
1383 lsda = isSingleWordEHT ? 0 : (exceptionTableAddr + 4);
1386 personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr1;
1387 extraWords = (exceptionTableData & 0x00ff0000) >> 16;
1389 lsda = exceptionTableAddr + (extraWords + 1) * 4;
1392 personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr2;
1393 extraWords = (exceptionTableData & 0x00ff0000) >> 16;
1395 lsda = exceptionTableAddr + (extraWords + 1) * 4;
1398 _LIBUNWIND_ABORT("unknown personality routine");
1402 if (isSingleWordEHT) {
1403 if (extraWords != 0) {
1404 _LIBUNWIND_ABORT("index inlined table detected but pr function "
1405 "requires extra words");
1410 pint_t personalityAddr =
1411 exceptionTableAddr + signExtendPrel31(exceptionTableData);
1412 personalityRoutine = personalityAddr;
1414 // ARM EHABI # 6.2, # 9.2
1418 // +--------------------------------------+
1419 // | +--------+--------+--------+-------+ |
1420 // | |0| prel31 to personalityRoutine | |
1421 // | +--------+--------+--------+-------+ |
1422 // | | N | unwind opcodes | | <-- UnwindData
1423 // | +--------+--------+--------+-------+ |
1424 // | | Word 2 unwind opcodes | |
1425 // | +--------+--------+--------+-------+ |
1427 // | +--------+--------+--------+-------+ |
1428 // | | Word N unwind opcodes | |
1429 // | +--------+--------+--------+-------+ |
1430 // | | LSDA | | <-- lsda
1432 // | +--------+--------+--------+-------+ |
1433 // +--------------------------------------+
1435 uint32_t *UnwindData = reinterpret_cast<uint32_t*>(exceptionTableAddr) + 1;
1436 uint32_t FirstDataWord = *UnwindData;
1437 size_t N = ((FirstDataWord >> 24) & 0xff);
1438 size_t NDataWords = N + 1;
1439 lsda = reinterpret_cast<uintptr_t>(UnwindData + NDataWords);
1442 _info.start_ip = thisPC;
1443 _info.end_ip = nextPC;
1444 _info.handler = personalityRoutine;
1445 _info.unwind_info = exceptionTableAddr;
1447 // flags is pr_cache.additional. See EHABI #7.2 for definition of bit 0.
1448 _info.flags = isSingleWordEHT ? 1 : 0 | scope32 ? 0x2 : 0; // Use enum?
1454 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1455 template <typename A, typename R>
1456 bool UnwindCursor<A, R>::getInfoFromDwarfSection(pint_t pc,
1457 const UnwindInfoSections §s,
1458 uint32_t fdeSectionOffsetHint) {
1459 typename CFI_Parser<A>::FDE_Info fdeInfo;
1460 typename CFI_Parser<A>::CIE_Info cieInfo;
1461 bool foundFDE = false;
1462 bool foundInCache = false;
1463 // If compact encoding table gave offset into dwarf section, go directly there
1464 if (fdeSectionOffsetHint != 0) {
1465 foundFDE = CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,
1466 (uint32_t)sects.dwarf_section_length,
1467 sects.dwarf_section + fdeSectionOffsetHint,
1468 &fdeInfo, &cieInfo);
1470 #if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
1471 if (!foundFDE && (sects.dwarf_index_section != 0)) {
1472 foundFDE = EHHeaderParser<A>::findFDE(
1473 _addressSpace, pc, sects.dwarf_index_section,
1474 (uint32_t)sects.dwarf_index_section_length, &fdeInfo, &cieInfo);
1478 // otherwise, search cache of previously found FDEs.
1479 pint_t cachedFDE = DwarfFDECache<A>::findFDE(sects.dso_base, pc);
1480 if (cachedFDE != 0) {
1482 CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,
1483 (uint32_t)sects.dwarf_section_length,
1484 cachedFDE, &fdeInfo, &cieInfo);
1485 foundInCache = foundFDE;
1489 // Still not found, do full scan of __eh_frame section.
1490 foundFDE = CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,
1491 (uint32_t)sects.dwarf_section_length, 0,
1492 &fdeInfo, &cieInfo);
1495 typename CFI_Parser<A>::PrologInfo prolog;
1496 if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo, pc,
1497 R::getArch(), &prolog)) {
1498 // Save off parsed FDE info
1499 _info.start_ip = fdeInfo.pcStart;
1500 _info.end_ip = fdeInfo.pcEnd;
1501 _info.lsda = fdeInfo.lsda;
1502 _info.handler = cieInfo.personality;
1503 _info.gp = prolog.spExtraArgSize;
1505 _info.format = dwarfEncoding();
1506 _info.unwind_info = fdeInfo.fdeStart;
1507 _info.unwind_info_size = (uint32_t)fdeInfo.fdeLength;
1508 _info.extra = (unw_word_t) sects.dso_base;
1510 // Add to cache (to make next lookup faster) if we had no hint
1511 // and there was no index.
1512 if (!foundInCache && (fdeSectionOffsetHint == 0)) {
1513 #if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
1514 if (sects.dwarf_index_section == 0)
1516 DwarfFDECache<A>::add(sects.dso_base, fdeInfo.pcStart, fdeInfo.pcEnd,
1522 //_LIBUNWIND_DEBUG_LOG("can't find/use FDE for pc=0x%llX", (uint64_t)pc);
1525 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1528 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1529 template <typename A, typename R>
1530 bool UnwindCursor<A, R>::getInfoFromCompactEncodingSection(pint_t pc,
1531 const UnwindInfoSections §s) {
1532 const bool log = false;
1534 fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX, mh=0x%llX)\n",
1535 (uint64_t)pc, (uint64_t)sects.dso_base);
1537 const UnwindSectionHeader<A> sectionHeader(_addressSpace,
1538 sects.compact_unwind_section);
1539 if (sectionHeader.version() != UNWIND_SECTION_VERSION)
1542 // do a binary search of top level index to find page with unwind info
1543 pint_t targetFunctionOffset = pc - sects.dso_base;
1544 const UnwindSectionIndexArray<A> topIndex(_addressSpace,
1545 sects.compact_unwind_section
1546 + sectionHeader.indexSectionOffset());
1548 uint32_t high = sectionHeader.indexCount();
1549 uint32_t last = high - 1;
1550 while (low < high) {
1551 uint32_t mid = (low + high) / 2;
1552 //if ( log ) fprintf(stderr, "\tmid=%d, low=%d, high=%d, *mid=0x%08X\n",
1553 //mid, low, high, topIndex.functionOffset(mid));
1554 if (topIndex.functionOffset(mid) <= targetFunctionOffset) {
1555 if ((mid == last) ||
1556 (topIndex.functionOffset(mid + 1) > targetFunctionOffset)) {
1566 const uint32_t firstLevelFunctionOffset = topIndex.functionOffset(low);
1567 const uint32_t firstLevelNextPageFunctionOffset =
1568 topIndex.functionOffset(low + 1);
1569 const pint_t secondLevelAddr =
1570 sects.compact_unwind_section + topIndex.secondLevelPagesSectionOffset(low);
1571 const pint_t lsdaArrayStartAddr =
1572 sects.compact_unwind_section + topIndex.lsdaIndexArraySectionOffset(low);
1573 const pint_t lsdaArrayEndAddr =
1574 sects.compact_unwind_section + topIndex.lsdaIndexArraySectionOffset(low+1);
1576 fprintf(stderr, "\tfirst level search for result index=%d "
1577 "to secondLevelAddr=0x%llX\n",
1578 low, (uint64_t) secondLevelAddr);
1579 // do a binary search of second level page index
1580 uint32_t encoding = 0;
1581 pint_t funcStart = 0;
1584 pint_t personality = 0;
1585 uint32_t pageKind = _addressSpace.get32(secondLevelAddr);
1586 if (pageKind == UNWIND_SECOND_LEVEL_REGULAR) {
1588 UnwindSectionRegularPageHeader<A> pageHeader(_addressSpace,
1590 UnwindSectionRegularArray<A> pageIndex(
1591 _addressSpace, secondLevelAddr + pageHeader.entryPageOffset());
1592 // binary search looks for entry with e where index[e].offset <= pc <
1593 // index[e+1].offset
1595 fprintf(stderr, "\tbinary search for targetFunctionOffset=0x%08llX in "
1596 "regular page starting at secondLevelAddr=0x%llX\n",
1597 (uint64_t) targetFunctionOffset, (uint64_t) secondLevelAddr);
1599 high = pageHeader.entryCount();
1600 while (low < high) {
1601 uint32_t mid = (low + high) / 2;
1602 if (pageIndex.functionOffset(mid) <= targetFunctionOffset) {
1603 if (mid == (uint32_t)(pageHeader.entryCount() - 1)) {
1606 funcEnd = firstLevelNextPageFunctionOffset + sects.dso_base;
1608 } else if (pageIndex.functionOffset(mid + 1) > targetFunctionOffset) {
1609 // next is too big, so we found it
1611 funcEnd = pageIndex.functionOffset(low + 1) + sects.dso_base;
1620 encoding = pageIndex.encoding(low);
1621 funcStart = pageIndex.functionOffset(low) + sects.dso_base;
1622 if (pc < funcStart) {
1626 "\tpc not in table, pc=0x%llX, funcStart=0x%llX, funcEnd=0x%llX\n",
1627 (uint64_t) pc, (uint64_t) funcStart, (uint64_t) funcEnd);
1634 "\tpc not in table, pc=0x%llX, funcStart=0x%llX, funcEnd=0x%llX\n",
1635 (uint64_t) pc, (uint64_t) funcStart, (uint64_t) funcEnd);
1638 } else if (pageKind == UNWIND_SECOND_LEVEL_COMPRESSED) {
1640 UnwindSectionCompressedPageHeader<A> pageHeader(_addressSpace,
1642 UnwindSectionCompressedArray<A> pageIndex(
1643 _addressSpace, secondLevelAddr + pageHeader.entryPageOffset());
1644 const uint32_t targetFunctionPageOffset =
1645 (uint32_t)(targetFunctionOffset - firstLevelFunctionOffset);
1646 // binary search looks for entry with e where index[e].offset <= pc <
1647 // index[e+1].offset
1649 fprintf(stderr, "\tbinary search of compressed page starting at "
1650 "secondLevelAddr=0x%llX\n",
1651 (uint64_t) secondLevelAddr);
1653 last = pageHeader.entryCount() - 1;
1654 high = pageHeader.entryCount();
1655 while (low < high) {
1656 uint32_t mid = (low + high) / 2;
1657 if (pageIndex.functionOffset(mid) <= targetFunctionPageOffset) {
1658 if ((mid == last) ||
1659 (pageIndex.functionOffset(mid + 1) > targetFunctionPageOffset)) {
1669 funcStart = pageIndex.functionOffset(low) + firstLevelFunctionOffset
1673 pageIndex.functionOffset(low + 1) + firstLevelFunctionOffset
1676 funcEnd = firstLevelNextPageFunctionOffset + sects.dso_base;
1677 if (pc < funcStart) {
1678 _LIBUNWIND_DEBUG_LOG("malformed __unwind_info, pc=0x%llX not in second "
1679 "level compressed unwind table. funcStart=0x%llX",
1680 (uint64_t) pc, (uint64_t) funcStart);
1684 _LIBUNWIND_DEBUG_LOG("malformed __unwind_info, pc=0x%llX not in second "
1685 "level compressed unwind table. funcEnd=0x%llX",
1686 (uint64_t) pc, (uint64_t) funcEnd);
1689 uint16_t encodingIndex = pageIndex.encodingIndex(low);
1690 if (encodingIndex < sectionHeader.commonEncodingsArrayCount()) {
1691 // encoding is in common table in section header
1692 encoding = _addressSpace.get32(
1693 sects.compact_unwind_section +
1694 sectionHeader.commonEncodingsArraySectionOffset() +
1695 encodingIndex * sizeof(uint32_t));
1697 // encoding is in page specific table
1698 uint16_t pageEncodingIndex =
1699 encodingIndex - (uint16_t)sectionHeader.commonEncodingsArrayCount();
1700 encoding = _addressSpace.get32(secondLevelAddr +
1701 pageHeader.encodingsPageOffset() +
1702 pageEncodingIndex * sizeof(uint32_t));
1705 _LIBUNWIND_DEBUG_LOG("malformed __unwind_info at 0x%0llX bad second "
1707 (uint64_t) sects.compact_unwind_section);
1711 // look up LSDA, if encoding says function has one
1712 if (encoding & UNWIND_HAS_LSDA) {
1713 UnwindSectionLsdaArray<A> lsdaIndex(_addressSpace, lsdaArrayStartAddr);
1714 uint32_t funcStartOffset = (uint32_t)(funcStart - sects.dso_base);
1716 high = (uint32_t)(lsdaArrayEndAddr - lsdaArrayStartAddr) /
1717 sizeof(unwind_info_section_header_lsda_index_entry);
1718 // binary search looks for entry with exact match for functionOffset
1721 "\tbinary search of lsda table for targetFunctionOffset=0x%08X\n",
1723 while (low < high) {
1724 uint32_t mid = (low + high) / 2;
1725 if (lsdaIndex.functionOffset(mid) == funcStartOffset) {
1726 lsda = lsdaIndex.lsdaOffset(mid) + sects.dso_base;
1728 } else if (lsdaIndex.functionOffset(mid) < funcStartOffset) {
1735 _LIBUNWIND_DEBUG_LOG("found encoding 0x%08X with HAS_LSDA bit set for "
1736 "pc=0x%0llX, but lsda table has no entry",
1737 encoding, (uint64_t) pc);
1742 // extact personality routine, if encoding says function has one
1743 uint32_t personalityIndex = (encoding & UNWIND_PERSONALITY_MASK) >>
1744 (__builtin_ctz(UNWIND_PERSONALITY_MASK));
1745 if (personalityIndex != 0) {
1746 --personalityIndex; // change 1-based to zero-based index
1747 if (personalityIndex > sectionHeader.personalityArrayCount()) {
1748 _LIBUNWIND_DEBUG_LOG("found encoding 0x%08X with personality index %d, "
1749 "but personality table has only %d entries",
1750 encoding, personalityIndex,
1751 sectionHeader.personalityArrayCount());
1754 int32_t personalityDelta = (int32_t)_addressSpace.get32(
1755 sects.compact_unwind_section +
1756 sectionHeader.personalityArraySectionOffset() +
1757 personalityIndex * sizeof(uint32_t));
1758 pint_t personalityPointer = sects.dso_base + (pint_t)personalityDelta;
1759 personality = _addressSpace.getP(personalityPointer);
1761 fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX), "
1762 "personalityDelta=0x%08X, personality=0x%08llX\n",
1763 (uint64_t) pc, personalityDelta, (uint64_t) personality);
1767 fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX), "
1768 "encoding=0x%08X, lsda=0x%08llX for funcStart=0x%llX\n",
1769 (uint64_t) pc, encoding, (uint64_t) lsda, (uint64_t) funcStart);
1770 _info.start_ip = funcStart;
1771 _info.end_ip = funcEnd;
1773 _info.handler = personality;
1776 _info.format = encoding;
1777 _info.unwind_info = 0;
1778 _info.unwind_info_size = 0;
1779 _info.extra = sects.dso_base;
1782 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1785 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1786 template <typename A, typename R>
1787 bool UnwindCursor<A, R>::getInfoFromSEH(pint_t pc) {
1789 RUNTIME_FUNCTION *unwindEntry = lookUpSEHUnwindInfo(pc, &base);
1791 _LIBUNWIND_DEBUG_LOG("\tpc not in table, pc=0x%llX", (uint64_t) pc);
1797 _info.unwind_info_size = sizeof(RUNTIME_FUNCTION);
1798 _info.unwind_info = reinterpret_cast<unw_word_t>(unwindEntry);
1800 _info.start_ip = base + unwindEntry->BeginAddress;
1801 #ifdef _LIBUNWIND_TARGET_X86_64
1802 _info.end_ip = base + unwindEntry->EndAddress;
1803 // Only fill in the handler and LSDA if they're stale.
1804 if (pc != getLastPC()) {
1805 UNWIND_INFO *xdata = reinterpret_cast<UNWIND_INFO *>(base + unwindEntry->UnwindData);
1806 if (xdata->Flags & (UNW_FLAG_EHANDLER|UNW_FLAG_UHANDLER)) {
1807 // The personality is given in the UNWIND_INFO itself. The LSDA immediately
1808 // follows the UNWIND_INFO. (This follows how both Clang and MSVC emit
1809 // these structures.)
1810 // N.B. UNWIND_INFO structs are DWORD-aligned.
1811 uint32_t lastcode = (xdata->CountOfCodes + 1) & ~1;
1812 const uint32_t *handler = reinterpret_cast<uint32_t *>(&xdata->UnwindCodes[lastcode]);
1813 _info.lsda = reinterpret_cast<unw_word_t>(handler+1);
1815 _info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);
1823 #elif defined(_LIBUNWIND_TARGET_ARM)
1824 _info.end_ip = _info.start_ip + unwindEntry->FunctionLength;
1825 _info.lsda = 0; // FIXME
1826 _info.handler = 0; // FIXME
1834 template <typename A, typename R>
1835 void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
1836 pint_t pc = (pint_t)this->getReg(UNW_REG_IP);
1837 #if defined(_LIBUNWIND_ARM_EHABI)
1838 // Remove the thumb bit so the IP represents the actual instruction address.
1839 // This matches the behaviour of _Unwind_GetIP on arm.
1843 // If the last line of a function is a "throw" the compiler sometimes
1844 // emits no instructions after the call to __cxa_throw. This means
1845 // the return address is actually the start of the next function.
1846 // To disambiguate this, back up the pc when we know it is a return
1848 if (isReturnAddress)
1851 // Ask address space object to find unwind sections for this pc.
1852 UnwindInfoSections sects;
1853 if (_addressSpace.findUnwindSections(pc, sects)) {
1854 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1855 // If there is a compact unwind encoding table, look there first.
1856 if (sects.compact_unwind_section != 0) {
1857 if (this->getInfoFromCompactEncodingSection(pc, sects)) {
1858 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1859 // Found info in table, done unless encoding says to use dwarf.
1860 uint32_t dwarfOffset;
1861 if ((sects.dwarf_section != 0) && compactSaysUseDwarf(&dwarfOffset)) {
1862 if (this->getInfoFromDwarfSection(pc, sects, dwarfOffset)) {
1863 // found info in dwarf, done
1868 // If unwind table has entry, but entry says there is no unwind info,
1869 // record that we have no unwind info.
1870 if (_info.format == 0)
1871 _unwindInfoMissing = true;
1875 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1877 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1878 // If there is SEH unwind info, look there next.
1879 if (this->getInfoFromSEH(pc))
1883 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1884 // If there is dwarf unwind info, look there next.
1885 if (sects.dwarf_section != 0) {
1886 if (this->getInfoFromDwarfSection(pc, sects)) {
1887 // found info in dwarf, done
1893 #if defined(_LIBUNWIND_ARM_EHABI)
1894 // If there is ARM EHABI unwind info, look there next.
1895 if (sects.arm_section != 0 && this->getInfoFromEHABISection(pc, sects))
1900 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1901 // There is no static unwind info for this pc. Look to see if an FDE was
1902 // dynamically registered for it.
1903 pint_t cachedFDE = DwarfFDECache<A>::findFDE(0, pc);
1904 if (cachedFDE != 0) {
1905 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
1906 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
1907 const char *msg = CFI_Parser<A>::decodeFDE(_addressSpace,
1908 cachedFDE, &fdeInfo, &cieInfo);
1910 typename CFI_Parser<A>::PrologInfo prolog;
1911 if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo,
1912 pc, R::getArch(), &prolog)) {
1913 // save off parsed FDE info
1914 _info.start_ip = fdeInfo.pcStart;
1915 _info.end_ip = fdeInfo.pcEnd;
1916 _info.lsda = fdeInfo.lsda;
1917 _info.handler = cieInfo.personality;
1918 _info.gp = prolog.spExtraArgSize;
1919 // Some frameless functions need SP
1920 // altered when resuming in function.
1922 _info.format = dwarfEncoding();
1923 _info.unwind_info = fdeInfo.fdeStart;
1924 _info.unwind_info_size = (uint32_t)fdeInfo.fdeLength;
1931 // Lastly, ask AddressSpace object about platform specific ways to locate
1934 if (_addressSpace.findOtherFDE(pc, fde)) {
1935 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
1936 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
1937 if (!CFI_Parser<A>::decodeFDE(_addressSpace, fde, &fdeInfo, &cieInfo)) {
1938 // Double check this FDE is for a function that includes the pc.
1939 if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd)) {
1940 typename CFI_Parser<A>::PrologInfo prolog;
1941 if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo,
1942 pc, R::getArch(), &prolog)) {
1943 // save off parsed FDE info
1944 _info.start_ip = fdeInfo.pcStart;
1945 _info.end_ip = fdeInfo.pcEnd;
1946 _info.lsda = fdeInfo.lsda;
1947 _info.handler = cieInfo.personality;
1948 _info.gp = prolog.spExtraArgSize;
1950 _info.format = dwarfEncoding();
1951 _info.unwind_info = fdeInfo.fdeStart;
1952 _info.unwind_info_size = (uint32_t)fdeInfo.fdeLength;
1959 #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1961 // no unwind info, flag that we can't reliably unwind
1962 _unwindInfoMissing = true;
1965 template <typename A, typename R>
1966 int UnwindCursor<A, R>::step() {
1967 // Bottom of stack is defined is when unwind info cannot be found.
1968 if (_unwindInfoMissing)
1969 return UNW_STEP_END;
1971 // Use unwinding info to modify register set as if function returned.
1973 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1974 result = this->stepWithCompactEncoding();
1975 #elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1976 result = this->stepWithSEHData();
1977 #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1978 result = this->stepWithDwarfFDE();
1979 #elif defined(_LIBUNWIND_ARM_EHABI)
1980 result = this->stepWithEHABI();
1982 #error Need _LIBUNWIND_SUPPORT_COMPACT_UNWIND or \
1983 _LIBUNWIND_SUPPORT_SEH_UNWIND or \
1984 _LIBUNWIND_SUPPORT_DWARF_UNWIND or \
1985 _LIBUNWIND_ARM_EHABI
1988 // update info based on new PC
1989 if (result == UNW_STEP_SUCCESS) {
1990 this->setInfoBasedOnIPRegister(true);
1991 if (_unwindInfoMissing)
1992 return UNW_STEP_END;
1998 template <typename A, typename R>
1999 void UnwindCursor<A, R>::getInfo(unw_proc_info_t *info) {
2003 template <typename A, typename R>
2004 bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
2005 unw_word_t *offset) {
2006 return _addressSpace.findFunctionName((pint_t)this->getReg(UNW_REG_IP),
2007 buf, bufLen, offset);
2010 } // namespace libunwind
2012 #endif // __UNWINDCURSOR_HPP__