1 //===------------------------- UnwindCursor.hpp ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
9 // C++ interface to lower levels of libunwind
10 //===----------------------------------------------------------------------===//
12 #ifndef __UNWINDCURSOR_HPP__
13 #define __UNWINDCURSOR_HPP__
26 #include <mach-o/dyld.h>
29 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
30 // Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and
32 // MinGW-w64 has always provided this struct.
33 #if defined(_WIN32) && defined(_LIBUNWIND_TARGET_X86_64) && \
34 !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000
35 struct _DISPATCHER_CONTEXT {
38 PRUNTIME_FUNCTION FunctionEntry;
39 ULONG64 EstablisherFrame;
41 PCONTEXT ContextRecord;
42 PEXCEPTION_ROUTINE LanguageHandler;
44 PUNWIND_HISTORY_TABLE HistoryTable;
55 uint8_t FrameRegister : 4;
56 uint8_t FrameOffset : 4;
57 uint16_t UnwindCodes[2];
60 extern "C" _Unwind_Reason_Code __libunwind_seh_personality(
61 int, _Unwind_Action, uint64_t, _Unwind_Exception *,
62 struct _Unwind_Context *);
68 #include "AddressSpace.hpp"
69 #include "CompactUnwinder.hpp"
71 #include "DwarfInstructions.hpp"
72 #include "EHHeaderParser.hpp"
73 #include "libunwind.h"
74 #include "Registers.hpp"
75 #include "RWMutex.hpp"
76 #include "Unwind-EHABI.h"
80 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
81 /// Cache of recently found FDEs.
83 class _LIBUNWIND_HIDDEN DwarfFDECache {
84 typedef typename A::pint_t pint_t;
86 static pint_t findFDE(pint_t mh, pint_t pc);
87 static void add(pint_t mh, pint_t ip_start, pint_t ip_end, pint_t fde);
88 static void removeAllIn(pint_t mh);
89 static void iterateCacheEntries(void (*func)(unw_word_t ip_start,
91 unw_word_t fde, unw_word_t mh));
102 // These fields are all static to avoid needing an initializer.
103 // There is only one instance of this class per process.
104 static RWMutex _lock;
106 static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
107 static bool _registeredForDyldUnloads;
109 // Can't use std::vector<> here because this code is below libc++.
110 static entry *_buffer;
111 static entry *_bufferUsed;
112 static entry *_bufferEnd;
113 static entry _initialBuffer[64];
116 template <typename A>
117 typename DwarfFDECache<A>::entry *
118 DwarfFDECache<A>::_buffer = _initialBuffer;
120 template <typename A>
121 typename DwarfFDECache<A>::entry *
122 DwarfFDECache<A>::_bufferUsed = _initialBuffer;
124 template <typename A>
125 typename DwarfFDECache<A>::entry *
126 DwarfFDECache<A>::_bufferEnd = &_initialBuffer[64];
128 template <typename A>
129 typename DwarfFDECache<A>::entry DwarfFDECache<A>::_initialBuffer[64];
131 template <typename A>
132 RWMutex DwarfFDECache<A>::_lock;
135 template <typename A>
136 bool DwarfFDECache<A>::_registeredForDyldUnloads = false;
139 template <typename A>
140 typename A::pint_t DwarfFDECache<A>::findFDE(pint_t mh, pint_t pc) {
142 _LIBUNWIND_LOG_IF_FALSE(_lock.lock_shared());
143 for (entry *p = _buffer; p < _bufferUsed; ++p) {
144 if ((mh == p->mh) || (mh == 0)) {
145 if ((p->ip_start <= pc) && (pc < p->ip_end)) {
151 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock_shared());
155 template <typename A>
156 void DwarfFDECache<A>::add(pint_t mh, pint_t ip_start, pint_t ip_end,
158 #if !defined(_LIBUNWIND_NO_HEAP)
159 _LIBUNWIND_LOG_IF_FALSE(_lock.lock());
160 if (_bufferUsed >= _bufferEnd) {
161 size_t oldSize = (size_t)(_bufferEnd - _buffer);
162 size_t newSize = oldSize * 4;
163 // Can't use operator new (we are below it).
164 entry *newBuffer = (entry *)malloc(newSize * sizeof(entry));
165 memcpy(newBuffer, _buffer, oldSize * sizeof(entry));
166 if (_buffer != _initialBuffer)
169 _bufferUsed = &newBuffer[oldSize];
170 _bufferEnd = &newBuffer[newSize];
172 _bufferUsed->mh = mh;
173 _bufferUsed->ip_start = ip_start;
174 _bufferUsed->ip_end = ip_end;
175 _bufferUsed->fde = fde;
178 if (!_registeredForDyldUnloads) {
179 _dyld_register_func_for_remove_image(&dyldUnloadHook);
180 _registeredForDyldUnloads = true;
183 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock());
187 template <typename A>
188 void DwarfFDECache<A>::removeAllIn(pint_t mh) {
189 _LIBUNWIND_LOG_IF_FALSE(_lock.lock());
191 for (const entry *s = _buffer; s < _bufferUsed; ++s) {
199 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock());
203 template <typename A>
204 void DwarfFDECache<A>::dyldUnloadHook(const struct mach_header *mh, intptr_t ) {
205 removeAllIn((pint_t) mh);
209 template <typename A>
210 void DwarfFDECache<A>::iterateCacheEntries(void (*func)(
211 unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)) {
212 _LIBUNWIND_LOG_IF_FALSE(_lock.lock());
213 for (entry *p = _buffer; p < _bufferUsed; ++p) {
214 (*func)(p->ip_start, p->ip_end, p->fde, p->mh);
216 _LIBUNWIND_LOG_IF_FALSE(_lock.unlock());
218 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
221 #define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
223 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
224 template <typename A> class UnwindSectionHeader {
226 UnwindSectionHeader(A &addressSpace, typename A::pint_t addr)
227 : _addressSpace(addressSpace), _addr(addr) {}
229 uint32_t version() const {
230 return _addressSpace.get32(_addr +
231 offsetof(unwind_info_section_header, version));
233 uint32_t commonEncodingsArraySectionOffset() const {
234 return _addressSpace.get32(_addr +
235 offsetof(unwind_info_section_header,
236 commonEncodingsArraySectionOffset));
238 uint32_t commonEncodingsArrayCount() const {
239 return _addressSpace.get32(_addr + offsetof(unwind_info_section_header,
240 commonEncodingsArrayCount));
242 uint32_t personalityArraySectionOffset() const {
243 return _addressSpace.get32(_addr + offsetof(unwind_info_section_header,
244 personalityArraySectionOffset));
246 uint32_t personalityArrayCount() const {
247 return _addressSpace.get32(
248 _addr + offsetof(unwind_info_section_header, personalityArrayCount));
250 uint32_t indexSectionOffset() const {
251 return _addressSpace.get32(
252 _addr + offsetof(unwind_info_section_header, indexSectionOffset));
254 uint32_t indexCount() const {
255 return _addressSpace.get32(
256 _addr + offsetof(unwind_info_section_header, indexCount));
261 typename A::pint_t _addr;
264 template <typename A> class UnwindSectionIndexArray {
266 UnwindSectionIndexArray(A &addressSpace, typename A::pint_t addr)
267 : _addressSpace(addressSpace), _addr(addr) {}
269 uint32_t functionOffset(uint32_t index) const {
270 return _addressSpace.get32(
271 _addr + arrayoffsetof(unwind_info_section_header_index_entry, index,
274 uint32_t secondLevelPagesSectionOffset(uint32_t index) const {
275 return _addressSpace.get32(
276 _addr + arrayoffsetof(unwind_info_section_header_index_entry, index,
277 secondLevelPagesSectionOffset));
279 uint32_t lsdaIndexArraySectionOffset(uint32_t index) const {
280 return _addressSpace.get32(
281 _addr + arrayoffsetof(unwind_info_section_header_index_entry, index,
282 lsdaIndexArraySectionOffset));
287 typename A::pint_t _addr;
290 template <typename A> class UnwindSectionRegularPageHeader {
292 UnwindSectionRegularPageHeader(A &addressSpace, typename A::pint_t addr)
293 : _addressSpace(addressSpace), _addr(addr) {}
295 uint32_t kind() const {
296 return _addressSpace.get32(
297 _addr + offsetof(unwind_info_regular_second_level_page_header, kind));
299 uint16_t entryPageOffset() const {
300 return _addressSpace.get16(
301 _addr + offsetof(unwind_info_regular_second_level_page_header,
304 uint16_t entryCount() const {
305 return _addressSpace.get16(
307 offsetof(unwind_info_regular_second_level_page_header, entryCount));
312 typename A::pint_t _addr;
315 template <typename A> class UnwindSectionRegularArray {
317 UnwindSectionRegularArray(A &addressSpace, typename A::pint_t addr)
318 : _addressSpace(addressSpace), _addr(addr) {}
320 uint32_t functionOffset(uint32_t index) const {
321 return _addressSpace.get32(
322 _addr + arrayoffsetof(unwind_info_regular_second_level_entry, index,
325 uint32_t encoding(uint32_t index) const {
326 return _addressSpace.get32(
328 arrayoffsetof(unwind_info_regular_second_level_entry, index, encoding));
333 typename A::pint_t _addr;
336 template <typename A> class UnwindSectionCompressedPageHeader {
338 UnwindSectionCompressedPageHeader(A &addressSpace, typename A::pint_t addr)
339 : _addressSpace(addressSpace), _addr(addr) {}
341 uint32_t kind() const {
342 return _addressSpace.get32(
344 offsetof(unwind_info_compressed_second_level_page_header, kind));
346 uint16_t entryPageOffset() const {
347 return _addressSpace.get16(
348 _addr + offsetof(unwind_info_compressed_second_level_page_header,
351 uint16_t entryCount() const {
352 return _addressSpace.get16(
354 offsetof(unwind_info_compressed_second_level_page_header, entryCount));
356 uint16_t encodingsPageOffset() const {
357 return _addressSpace.get16(
358 _addr + offsetof(unwind_info_compressed_second_level_page_header,
359 encodingsPageOffset));
361 uint16_t encodingsCount() const {
362 return _addressSpace.get16(
363 _addr + offsetof(unwind_info_compressed_second_level_page_header,
369 typename A::pint_t _addr;
372 template <typename A> class UnwindSectionCompressedArray {
374 UnwindSectionCompressedArray(A &addressSpace, typename A::pint_t addr)
375 : _addressSpace(addressSpace), _addr(addr) {}
377 uint32_t functionOffset(uint32_t index) const {
378 return UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(
379 _addressSpace.get32(_addr + index * sizeof(uint32_t)));
381 uint16_t encodingIndex(uint32_t index) const {
382 return UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(
383 _addressSpace.get32(_addr + index * sizeof(uint32_t)));
388 typename A::pint_t _addr;
391 template <typename A> class UnwindSectionLsdaArray {
393 UnwindSectionLsdaArray(A &addressSpace, typename A::pint_t addr)
394 : _addressSpace(addressSpace), _addr(addr) {}
396 uint32_t functionOffset(uint32_t index) const {
397 return _addressSpace.get32(
398 _addr + arrayoffsetof(unwind_info_section_header_lsda_index_entry,
399 index, functionOffset));
401 uint32_t lsdaOffset(uint32_t index) const {
402 return _addressSpace.get32(
403 _addr + arrayoffsetof(unwind_info_section_header_lsda_index_entry,
409 typename A::pint_t _addr;
411 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
413 class _LIBUNWIND_HIDDEN AbstractUnwindCursor {
415 // NOTE: provide a class specific placement deallocation function (S5.3.4 p20)
416 // This avoids an unnecessary dependency to libc++abi.
417 void operator delete(void *, size_t) {}
419 virtual ~AbstractUnwindCursor() {}
420 virtual bool validReg(int) { _LIBUNWIND_ABORT("validReg not implemented"); }
421 virtual unw_word_t getReg(int) { _LIBUNWIND_ABORT("getReg not implemented"); }
422 virtual void setReg(int, unw_word_t) {
423 _LIBUNWIND_ABORT("setReg not implemented");
425 virtual bool validFloatReg(int) {
426 _LIBUNWIND_ABORT("validFloatReg not implemented");
428 virtual unw_fpreg_t getFloatReg(int) {
429 _LIBUNWIND_ABORT("getFloatReg not implemented");
431 virtual void setFloatReg(int, unw_fpreg_t) {
432 _LIBUNWIND_ABORT("setFloatReg not implemented");
434 virtual int step() { _LIBUNWIND_ABORT("step not implemented"); }
435 virtual void getInfo(unw_proc_info_t *) {
436 _LIBUNWIND_ABORT("getInfo not implemented");
438 virtual void jumpto() { _LIBUNWIND_ABORT("jumpto not implemented"); }
439 virtual bool isSignalFrame() {
440 _LIBUNWIND_ABORT("isSignalFrame not implemented");
442 virtual bool getFunctionName(char *, size_t, unw_word_t *) {
443 _LIBUNWIND_ABORT("getFunctionName not implemented");
445 virtual void setInfoBasedOnIPRegister(bool = false) {
446 _LIBUNWIND_ABORT("setInfoBasedOnIPRegister not implemented");
448 virtual const char *getRegisterName(int) {
449 _LIBUNWIND_ABORT("getRegisterName not implemented");
452 virtual void saveVFPAsX() { _LIBUNWIND_ABORT("saveVFPAsX not implemented"); }
456 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
458 /// \c UnwindCursor contains all state (including all register values) during
459 /// an unwind. This is normally stack-allocated inside a unw_cursor_t.
460 template <typename A, typename R>
461 class UnwindCursor : public AbstractUnwindCursor {
462 typedef typename A::pint_t pint_t;
464 UnwindCursor(unw_context_t *context, A &as);
465 UnwindCursor(CONTEXT *context, A &as);
466 UnwindCursor(A &as, void *threadArg);
467 virtual ~UnwindCursor() {}
468 virtual bool validReg(int);
469 virtual unw_word_t getReg(int);
470 virtual void setReg(int, unw_word_t);
471 virtual bool validFloatReg(int);
472 virtual unw_fpreg_t getFloatReg(int);
473 virtual void setFloatReg(int, unw_fpreg_t);
475 virtual void getInfo(unw_proc_info_t *);
476 virtual void jumpto();
477 virtual bool isSignalFrame();
478 virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);
479 virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);
480 virtual const char *getRegisterName(int num);
482 virtual void saveVFPAsX();
485 DISPATCHER_CONTEXT *getDispatcherContext() { return &_dispContext; }
486 void setDispatcherContext(DISPATCHER_CONTEXT *disp) { _dispContext = *disp; }
490 pint_t getLastPC() const { return _dispContext.ControlPc; }
491 void setLastPC(pint_t pc) { _dispContext.ControlPc = pc; }
492 RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {
493 _dispContext.FunctionEntry = RtlLookupFunctionEntry(pc,
494 &_dispContext.ImageBase,
495 _dispContext.HistoryTable);
496 *base = _dispContext.ImageBase;
497 return _dispContext.FunctionEntry;
499 bool getInfoFromSEH(pint_t pc);
500 int stepWithSEHData() {
501 _dispContext.LanguageHandler = RtlVirtualUnwind(UNW_FLAG_UHANDLER,
502 _dispContext.ImageBase,
503 _dispContext.ControlPc,
504 _dispContext.FunctionEntry,
505 _dispContext.ContextRecord,
506 &_dispContext.HandlerData,
507 &_dispContext.EstablisherFrame,
509 // Update some fields of the unwind info now, since we have them.
510 _info.lsda = reinterpret_cast<unw_word_t>(_dispContext.HandlerData);
511 if (_dispContext.LanguageHandler) {
512 _info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);
515 return UNW_STEP_SUCCESS;
519 unw_proc_info_t _info;
520 DISPATCHER_CONTEXT _dispContext;
522 UNWIND_HISTORY_TABLE _histTable;
523 bool _unwindInfoMissing;
527 template <typename A, typename R>
528 UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
529 : _addressSpace(as), _unwindInfoMissing(false) {
530 static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
531 "UnwindCursor<> does not fit in unw_cursor_t");
532 memset(&_info, 0, sizeof(_info));
533 memset(&_histTable, 0, sizeof(_histTable));
534 _dispContext.ContextRecord = &_msContext;
535 _dispContext.HistoryTable = &_histTable;
536 // Initialize MS context from ours.
538 _msContext.ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_FLOATING_POINT;
539 #if defined(_LIBUNWIND_TARGET_X86_64)
540 _msContext.Rax = r.getRegister(UNW_X86_64_RAX);
541 _msContext.Rcx = r.getRegister(UNW_X86_64_RCX);
542 _msContext.Rdx = r.getRegister(UNW_X86_64_RDX);
543 _msContext.Rbx = r.getRegister(UNW_X86_64_RBX);
544 _msContext.Rsp = r.getRegister(UNW_X86_64_RSP);
545 _msContext.Rbp = r.getRegister(UNW_X86_64_RBP);
546 _msContext.Rsi = r.getRegister(UNW_X86_64_RSI);
547 _msContext.Rdi = r.getRegister(UNW_X86_64_RDI);
548 _msContext.R8 = r.getRegister(UNW_X86_64_R8);
549 _msContext.R9 = r.getRegister(UNW_X86_64_R9);
550 _msContext.R10 = r.getRegister(UNW_X86_64_R10);
551 _msContext.R11 = r.getRegister(UNW_X86_64_R11);
552 _msContext.R12 = r.getRegister(UNW_X86_64_R12);
553 _msContext.R13 = r.getRegister(UNW_X86_64_R13);
554 _msContext.R14 = r.getRegister(UNW_X86_64_R14);
555 _msContext.R15 = r.getRegister(UNW_X86_64_R15);
556 _msContext.Rip = r.getRegister(UNW_REG_IP);
561 t.v = r.getVectorRegister(UNW_X86_64_XMM0);
562 _msContext.Xmm0 = t.m;
563 t.v = r.getVectorRegister(UNW_X86_64_XMM1);
564 _msContext.Xmm1 = t.m;
565 t.v = r.getVectorRegister(UNW_X86_64_XMM2);
566 _msContext.Xmm2 = t.m;
567 t.v = r.getVectorRegister(UNW_X86_64_XMM3);
568 _msContext.Xmm3 = t.m;
569 t.v = r.getVectorRegister(UNW_X86_64_XMM4);
570 _msContext.Xmm4 = t.m;
571 t.v = r.getVectorRegister(UNW_X86_64_XMM5);
572 _msContext.Xmm5 = t.m;
573 t.v = r.getVectorRegister(UNW_X86_64_XMM6);
574 _msContext.Xmm6 = t.m;
575 t.v = r.getVectorRegister(UNW_X86_64_XMM7);
576 _msContext.Xmm7 = t.m;
577 t.v = r.getVectorRegister(UNW_X86_64_XMM8);
578 _msContext.Xmm8 = t.m;
579 t.v = r.getVectorRegister(UNW_X86_64_XMM9);
580 _msContext.Xmm9 = t.m;
581 t.v = r.getVectorRegister(UNW_X86_64_XMM10);
582 _msContext.Xmm10 = t.m;
583 t.v = r.getVectorRegister(UNW_X86_64_XMM11);
584 _msContext.Xmm11 = t.m;
585 t.v = r.getVectorRegister(UNW_X86_64_XMM12);
586 _msContext.Xmm12 = t.m;
587 t.v = r.getVectorRegister(UNW_X86_64_XMM13);
588 _msContext.Xmm13 = t.m;
589 t.v = r.getVectorRegister(UNW_X86_64_XMM14);
590 _msContext.Xmm14 = t.m;
591 t.v = r.getVectorRegister(UNW_X86_64_XMM15);
592 _msContext.Xmm15 = t.m;
593 #elif defined(_LIBUNWIND_TARGET_ARM)
594 _msContext.R0 = r.getRegister(UNW_ARM_R0);
595 _msContext.R1 = r.getRegister(UNW_ARM_R1);
596 _msContext.R2 = r.getRegister(UNW_ARM_R2);
597 _msContext.R3 = r.getRegister(UNW_ARM_R3);
598 _msContext.R4 = r.getRegister(UNW_ARM_R4);
599 _msContext.R5 = r.getRegister(UNW_ARM_R5);
600 _msContext.R6 = r.getRegister(UNW_ARM_R6);
601 _msContext.R7 = r.getRegister(UNW_ARM_R7);
602 _msContext.R8 = r.getRegister(UNW_ARM_R8);
603 _msContext.R9 = r.getRegister(UNW_ARM_R9);
604 _msContext.R10 = r.getRegister(UNW_ARM_R10);
605 _msContext.R11 = r.getRegister(UNW_ARM_R11);
606 _msContext.R12 = r.getRegister(UNW_ARM_R12);
607 _msContext.Sp = r.getRegister(UNW_ARM_SP);
608 _msContext.Lr = r.getRegister(UNW_ARM_LR);
609 _msContext.Pc = r.getRegister(UNW_ARM_IP);
610 for (int i = UNW_ARM_D0; i <= UNW_ARM_D31; ++i) {
615 d.d = r.getFloatRegister(i);
616 _msContext.D[i - UNW_ARM_D0] = d.w;
618 #elif defined(_LIBUNWIND_TARGET_AARCH64)
619 for (int i = UNW_ARM64_X0; i <= UNW_ARM64_X30; ++i)
620 _msContext.X[i - UNW_ARM64_X0] = r.getRegister(i);
621 _msContext.Sp = r.getRegister(UNW_REG_SP);
622 _msContext.Pc = r.getRegister(UNW_REG_IP);
623 for (int i = UNW_ARM64_D0; i <= UNW_ARM64_D31; ++i)
624 _msContext.V[i - UNW_ARM64_D0].D[0] = r.getFloatRegister(i);
628 template <typename A, typename R>
629 UnwindCursor<A, R>::UnwindCursor(CONTEXT *context, A &as)
630 : _addressSpace(as), _unwindInfoMissing(false) {
631 static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
632 "UnwindCursor<> does not fit in unw_cursor_t");
633 memset(&_info, 0, sizeof(_info));
634 memset(&_histTable, 0, sizeof(_histTable));
635 _dispContext.ContextRecord = &_msContext;
636 _dispContext.HistoryTable = &_histTable;
637 _msContext = *context;
641 template <typename A, typename R>
642 bool UnwindCursor<A, R>::validReg(int regNum) {
643 if (regNum == UNW_REG_IP || regNum == UNW_REG_SP) return true;
644 #if defined(_LIBUNWIND_TARGET_X86_64)
645 if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_R15) return true;
646 #elif defined(_LIBUNWIND_TARGET_ARM)
647 if (regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) return true;
648 #elif defined(_LIBUNWIND_TARGET_AARCH64)
649 if (regNum >= UNW_ARM64_X0 && regNum <= UNW_ARM64_X30) return true;
654 template <typename A, typename R>
655 unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
657 #if defined(_LIBUNWIND_TARGET_X86_64)
658 case UNW_REG_IP: return _msContext.Rip;
659 case UNW_X86_64_RAX: return _msContext.Rax;
660 case UNW_X86_64_RDX: return _msContext.Rdx;
661 case UNW_X86_64_RCX: return _msContext.Rcx;
662 case UNW_X86_64_RBX: return _msContext.Rbx;
664 case UNW_X86_64_RSP: return _msContext.Rsp;
665 case UNW_X86_64_RBP: return _msContext.Rbp;
666 case UNW_X86_64_RSI: return _msContext.Rsi;
667 case UNW_X86_64_RDI: return _msContext.Rdi;
668 case UNW_X86_64_R8: return _msContext.R8;
669 case UNW_X86_64_R9: return _msContext.R9;
670 case UNW_X86_64_R10: return _msContext.R10;
671 case UNW_X86_64_R11: return _msContext.R11;
672 case UNW_X86_64_R12: return _msContext.R12;
673 case UNW_X86_64_R13: return _msContext.R13;
674 case UNW_X86_64_R14: return _msContext.R14;
675 case UNW_X86_64_R15: return _msContext.R15;
676 #elif defined(_LIBUNWIND_TARGET_ARM)
677 case UNW_ARM_R0: return _msContext.R0;
678 case UNW_ARM_R1: return _msContext.R1;
679 case UNW_ARM_R2: return _msContext.R2;
680 case UNW_ARM_R3: return _msContext.R3;
681 case UNW_ARM_R4: return _msContext.R4;
682 case UNW_ARM_R5: return _msContext.R5;
683 case UNW_ARM_R6: return _msContext.R6;
684 case UNW_ARM_R7: return _msContext.R7;
685 case UNW_ARM_R8: return _msContext.R8;
686 case UNW_ARM_R9: return _msContext.R9;
687 case UNW_ARM_R10: return _msContext.R10;
688 case UNW_ARM_R11: return _msContext.R11;
689 case UNW_ARM_R12: return _msContext.R12;
691 case UNW_ARM_SP: return _msContext.Sp;
692 case UNW_ARM_LR: return _msContext.Lr;
694 case UNW_ARM_IP: return _msContext.Pc;
695 #elif defined(_LIBUNWIND_TARGET_AARCH64)
696 case UNW_REG_SP: return _msContext.Sp;
697 case UNW_REG_IP: return _msContext.Pc;
698 default: return _msContext.X[regNum - UNW_ARM64_X0];
701 _LIBUNWIND_ABORT("unsupported register");
704 template <typename A, typename R>
705 void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {
707 #if defined(_LIBUNWIND_TARGET_X86_64)
708 case UNW_REG_IP: _msContext.Rip = value; break;
709 case UNW_X86_64_RAX: _msContext.Rax = value; break;
710 case UNW_X86_64_RDX: _msContext.Rdx = value; break;
711 case UNW_X86_64_RCX: _msContext.Rcx = value; break;
712 case UNW_X86_64_RBX: _msContext.Rbx = value; break;
714 case UNW_X86_64_RSP: _msContext.Rsp = value; break;
715 case UNW_X86_64_RBP: _msContext.Rbp = value; break;
716 case UNW_X86_64_RSI: _msContext.Rsi = value; break;
717 case UNW_X86_64_RDI: _msContext.Rdi = value; break;
718 case UNW_X86_64_R8: _msContext.R8 = value; break;
719 case UNW_X86_64_R9: _msContext.R9 = value; break;
720 case UNW_X86_64_R10: _msContext.R10 = value; break;
721 case UNW_X86_64_R11: _msContext.R11 = value; break;
722 case UNW_X86_64_R12: _msContext.R12 = value; break;
723 case UNW_X86_64_R13: _msContext.R13 = value; break;
724 case UNW_X86_64_R14: _msContext.R14 = value; break;
725 case UNW_X86_64_R15: _msContext.R15 = value; break;
726 #elif defined(_LIBUNWIND_TARGET_ARM)
727 case UNW_ARM_R0: _msContext.R0 = value; break;
728 case UNW_ARM_R1: _msContext.R1 = value; break;
729 case UNW_ARM_R2: _msContext.R2 = value; break;
730 case UNW_ARM_R3: _msContext.R3 = value; break;
731 case UNW_ARM_R4: _msContext.R4 = value; break;
732 case UNW_ARM_R5: _msContext.R5 = value; break;
733 case UNW_ARM_R6: _msContext.R6 = value; break;
734 case UNW_ARM_R7: _msContext.R7 = value; break;
735 case UNW_ARM_R8: _msContext.R8 = value; break;
736 case UNW_ARM_R9: _msContext.R9 = value; break;
737 case UNW_ARM_R10: _msContext.R10 = value; break;
738 case UNW_ARM_R11: _msContext.R11 = value; break;
739 case UNW_ARM_R12: _msContext.R12 = value; break;
741 case UNW_ARM_SP: _msContext.Sp = value; break;
742 case UNW_ARM_LR: _msContext.Lr = value; break;
744 case UNW_ARM_IP: _msContext.Pc = value; break;
745 #elif defined(_LIBUNWIND_TARGET_AARCH64)
746 case UNW_REG_SP: _msContext.Sp = value; break;
747 case UNW_REG_IP: _msContext.Pc = value; break;
778 case UNW_ARM64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;
781 _LIBUNWIND_ABORT("unsupported register");
785 template <typename A, typename R>
786 bool UnwindCursor<A, R>::validFloatReg(int regNum) {
787 #if defined(_LIBUNWIND_TARGET_ARM)
788 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) return true;
789 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) return true;
790 #elif defined(_LIBUNWIND_TARGET_AARCH64)
791 if (regNum >= UNW_ARM64_D0 && regNum <= UNW_ARM64_D31) return true;
796 template <typename A, typename R>
797 unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {
798 #if defined(_LIBUNWIND_TARGET_ARM)
799 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {
804 d.w = _msContext.S[regNum - UNW_ARM_S0];
807 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {
812 d.w = _msContext.D[regNum - UNW_ARM_D0];
815 _LIBUNWIND_ABORT("unsupported float register");
816 #elif defined(_LIBUNWIND_TARGET_AARCH64)
817 return _msContext.V[regNum - UNW_ARM64_D0].D[0];
819 _LIBUNWIND_ABORT("float registers unimplemented");
823 template <typename A, typename R>
824 void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
825 #if defined(_LIBUNWIND_TARGET_ARM)
826 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {
832 _msContext.S[regNum - UNW_ARM_S0] = d.w;
834 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {
840 _msContext.D[regNum - UNW_ARM_D0] = d.w;
842 _LIBUNWIND_ABORT("unsupported float register");
843 #elif defined(_LIBUNWIND_TARGET_AARCH64)
844 _msContext.V[regNum - UNW_ARM64_D0].D[0] = value;
846 _LIBUNWIND_ABORT("float registers unimplemented");
850 template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {
851 RtlRestoreContext(&_msContext, nullptr);
855 template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {}
858 template <typename A, typename R>
859 const char *UnwindCursor<A, R>::getRegisterName(int regNum) {
860 return R::getRegisterName(regNum);
863 template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {
867 #else // !defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) || !defined(_WIN32)
869 /// UnwindCursor contains all state (including all register values) during
870 /// an unwind. This is normally stack allocated inside a unw_cursor_t.
871 template <typename A, typename R>
872 class UnwindCursor : public AbstractUnwindCursor{
873 typedef typename A::pint_t pint_t;
875 UnwindCursor(unw_context_t *context, A &as);
876 UnwindCursor(A &as, void *threadArg);
877 virtual ~UnwindCursor() {}
878 virtual bool validReg(int);
879 virtual unw_word_t getReg(int);
880 virtual void setReg(int, unw_word_t);
881 virtual bool validFloatReg(int);
882 virtual unw_fpreg_t getFloatReg(int);
883 virtual void setFloatReg(int, unw_fpreg_t);
885 virtual void getInfo(unw_proc_info_t *);
886 virtual void jumpto();
887 virtual bool isSignalFrame();
888 virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);
889 virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);
890 virtual const char *getRegisterName(int num);
892 virtual void saveVFPAsX();
897 #if defined(_LIBUNWIND_ARM_EHABI)
898 bool getInfoFromEHABISection(pint_t pc, const UnwindInfoSections §s);
900 int stepWithEHABI() {
903 // FIXME: Calling decode_eht_entry() here is violating the libunwind
904 // abstraction layer.
905 const uint32_t *ehtp =
906 decode_eht_entry(reinterpret_cast<const uint32_t *>(_info.unwind_info),
908 if (_Unwind_VRS_Interpret((_Unwind_Context *)this, ehtp, off, len) !=
909 _URC_CONTINUE_UNWIND)
911 return UNW_STEP_SUCCESS;
915 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
916 bool getInfoFromDwarfSection(pint_t pc, const UnwindInfoSections §s,
917 uint32_t fdeSectionOffsetHint=0);
918 int stepWithDwarfFDE() {
919 return DwarfInstructions<A, R>::stepWithDwarf(_addressSpace,
920 (pint_t)this->getReg(UNW_REG_IP),
921 (pint_t)_info.unwind_info,
926 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
927 bool getInfoFromCompactEncodingSection(pint_t pc,
928 const UnwindInfoSections §s);
929 int stepWithCompactEncoding() {
930 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
931 if ( compactSaysUseDwarf() )
932 return stepWithDwarfFDE();
935 return stepWithCompactEncoding(dummy);
938 #if defined(_LIBUNWIND_TARGET_X86_64)
939 int stepWithCompactEncoding(Registers_x86_64 &) {
940 return CompactUnwinder_x86_64<A>::stepWithCompactEncoding(
941 _info.format, _info.start_ip, _addressSpace, _registers);
945 #if defined(_LIBUNWIND_TARGET_I386)
946 int stepWithCompactEncoding(Registers_x86 &) {
947 return CompactUnwinder_x86<A>::stepWithCompactEncoding(
948 _info.format, (uint32_t)_info.start_ip, _addressSpace, _registers);
952 #if defined(_LIBUNWIND_TARGET_PPC)
953 int stepWithCompactEncoding(Registers_ppc &) {
958 #if defined(_LIBUNWIND_TARGET_PPC64)
959 int stepWithCompactEncoding(Registers_ppc64 &) {
965 #if defined(_LIBUNWIND_TARGET_AARCH64)
966 int stepWithCompactEncoding(Registers_arm64 &) {
967 return CompactUnwinder_arm64<A>::stepWithCompactEncoding(
968 _info.format, _info.start_ip, _addressSpace, _registers);
972 #if defined(_LIBUNWIND_TARGET_MIPS_O32)
973 int stepWithCompactEncoding(Registers_mips_o32 &) {
978 #if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
979 int stepWithCompactEncoding(Registers_mips_newabi &) {
984 #if defined(_LIBUNWIND_TARGET_SPARC)
985 int stepWithCompactEncoding(Registers_sparc &) { return UNW_EINVAL; }
988 bool compactSaysUseDwarf(uint32_t *offset=NULL) const {
990 return compactSaysUseDwarf(dummy, offset);
993 #if defined(_LIBUNWIND_TARGET_X86_64)
994 bool compactSaysUseDwarf(Registers_x86_64 &, uint32_t *offset) const {
995 if ((_info.format & UNWIND_X86_64_MODE_MASK) == UNWIND_X86_64_MODE_DWARF) {
997 *offset = (_info.format & UNWIND_X86_64_DWARF_SECTION_OFFSET);
1004 #if defined(_LIBUNWIND_TARGET_I386)
1005 bool compactSaysUseDwarf(Registers_x86 &, uint32_t *offset) const {
1006 if ((_info.format & UNWIND_X86_MODE_MASK) == UNWIND_X86_MODE_DWARF) {
1008 *offset = (_info.format & UNWIND_X86_DWARF_SECTION_OFFSET);
1015 #if defined(_LIBUNWIND_TARGET_PPC)
1016 bool compactSaysUseDwarf(Registers_ppc &, uint32_t *) const {
1021 #if defined(_LIBUNWIND_TARGET_PPC64)
1022 bool compactSaysUseDwarf(Registers_ppc64 &, uint32_t *) const {
1027 #if defined(_LIBUNWIND_TARGET_AARCH64)
1028 bool compactSaysUseDwarf(Registers_arm64 &, uint32_t *offset) const {
1029 if ((_info.format & UNWIND_ARM64_MODE_MASK) == UNWIND_ARM64_MODE_DWARF) {
1031 *offset = (_info.format & UNWIND_ARM64_DWARF_SECTION_OFFSET);
1038 #if defined(_LIBUNWIND_TARGET_MIPS_O32)
1039 bool compactSaysUseDwarf(Registers_mips_o32 &, uint32_t *) const {
1044 #if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
1045 bool compactSaysUseDwarf(Registers_mips_newabi &, uint32_t *) const {
1050 #if defined(_LIBUNWIND_TARGET_SPARC)
1051 bool compactSaysUseDwarf(Registers_sparc &, uint32_t *) const { return true; }
1054 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1056 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1057 compact_unwind_encoding_t dwarfEncoding() const {
1059 return dwarfEncoding(dummy);
1062 #if defined(_LIBUNWIND_TARGET_X86_64)
1063 compact_unwind_encoding_t dwarfEncoding(Registers_x86_64 &) const {
1064 return UNWIND_X86_64_MODE_DWARF;
1068 #if defined(_LIBUNWIND_TARGET_I386)
1069 compact_unwind_encoding_t dwarfEncoding(Registers_x86 &) const {
1070 return UNWIND_X86_MODE_DWARF;
1074 #if defined(_LIBUNWIND_TARGET_PPC)
1075 compact_unwind_encoding_t dwarfEncoding(Registers_ppc &) const {
1080 #if defined(_LIBUNWIND_TARGET_PPC64)
1081 compact_unwind_encoding_t dwarfEncoding(Registers_ppc64 &) const {
1086 #if defined(_LIBUNWIND_TARGET_AARCH64)
1087 compact_unwind_encoding_t dwarfEncoding(Registers_arm64 &) const {
1088 return UNWIND_ARM64_MODE_DWARF;
1092 #if defined(_LIBUNWIND_TARGET_ARM)
1093 compact_unwind_encoding_t dwarfEncoding(Registers_arm &) const {
1098 #if defined (_LIBUNWIND_TARGET_OR1K)
1099 compact_unwind_encoding_t dwarfEncoding(Registers_or1k &) const {
1104 #if defined (_LIBUNWIND_TARGET_RISCV)
1105 compact_unwind_encoding_t dwarfEncoding(Registers_riscv &) const {
1110 #if defined (_LIBUNWIND_TARGET_MIPS_O32)
1111 compact_unwind_encoding_t dwarfEncoding(Registers_mips_o32 &) const {
1116 #if defined (_LIBUNWIND_TARGET_MIPS_NEWABI)
1117 compact_unwind_encoding_t dwarfEncoding(Registers_mips_newabi &) const {
1122 #if defined(_LIBUNWIND_TARGET_SPARC)
1123 compact_unwind_encoding_t dwarfEncoding(Registers_sparc &) const { return 0; }
1126 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1128 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1129 // For runtime environments using SEH unwind data without Windows runtime
1131 pint_t getLastPC() const { /* FIXME: Implement */ return 0; }
1132 void setLastPC(pint_t pc) { /* FIXME: Implement */ }
1133 RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {
1134 /* FIXME: Implement */
1138 bool getInfoFromSEH(pint_t pc);
1139 int stepWithSEHData() { /* FIXME: Implement */ return 0; }
1140 #endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1145 unw_proc_info_t _info;
1146 bool _unwindInfoMissing;
1147 bool _isSignalFrame;
1151 template <typename A, typename R>
1152 UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
1153 : _addressSpace(as), _registers(context), _unwindInfoMissing(false),
1154 _isSignalFrame(false) {
1155 static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
1156 "UnwindCursor<> does not fit in unw_cursor_t");
1157 memset(&_info, 0, sizeof(_info));
1160 template <typename A, typename R>
1161 UnwindCursor<A, R>::UnwindCursor(A &as, void *)
1162 : _addressSpace(as), _unwindInfoMissing(false), _isSignalFrame(false) {
1163 memset(&_info, 0, sizeof(_info));
1165 // fill in _registers from thread arg
1169 template <typename A, typename R>
1170 bool UnwindCursor<A, R>::validReg(int regNum) {
1171 return _registers.validRegister(regNum);
1174 template <typename A, typename R>
1175 unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
1176 return _registers.getRegister(regNum);
1179 template <typename A, typename R>
1180 void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {
1181 _registers.setRegister(regNum, (typename A::pint_t)value);
1184 template <typename A, typename R>
1185 bool UnwindCursor<A, R>::validFloatReg(int regNum) {
1186 return _registers.validFloatRegister(regNum);
1189 template <typename A, typename R>
1190 unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {
1191 return _registers.getFloatRegister(regNum);
1194 template <typename A, typename R>
1195 void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
1196 _registers.setFloatRegister(regNum, value);
1199 template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {
1200 _registers.jumpto();
1204 template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {
1205 _registers.saveVFPAsX();
1209 template <typename A, typename R>
1210 const char *UnwindCursor<A, R>::getRegisterName(int regNum) {
1211 return _registers.getRegisterName(regNum);
1214 template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {
1215 return _isSignalFrame;
1218 #endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1220 #if defined(_LIBUNWIND_ARM_EHABI)
1221 struct EHABIIndexEntry {
1222 uint32_t functionOffset;
1226 template<typename A>
1227 struct EHABISectionIterator {
1228 typedef EHABISectionIterator _Self;
1230 typedef std::random_access_iterator_tag iterator_category;
1231 typedef typename A::pint_t value_type;
1232 typedef typename A::pint_t* pointer;
1233 typedef typename A::pint_t& reference;
1234 typedef size_t size_type;
1235 typedef size_t difference_type;
1237 static _Self begin(A& addressSpace, const UnwindInfoSections& sects) {
1238 return _Self(addressSpace, sects, 0);
1240 static _Self end(A& addressSpace, const UnwindInfoSections& sects) {
1241 return _Self(addressSpace, sects,
1242 sects.arm_section_length / sizeof(EHABIIndexEntry));
1245 EHABISectionIterator(A& addressSpace, const UnwindInfoSections& sects, size_t i)
1246 : _i(i), _addressSpace(&addressSpace), _sects(§s) {}
1248 _Self& operator++() { ++_i; return *this; }
1249 _Self& operator+=(size_t a) { _i += a; return *this; }
1250 _Self& operator--() { assert(_i > 0); --_i; return *this; }
1251 _Self& operator-=(size_t a) { assert(_i >= a); _i -= a; return *this; }
1253 _Self operator+(size_t a) { _Self out = *this; out._i += a; return out; }
1254 _Self operator-(size_t a) { assert(_i >= a); _Self out = *this; out._i -= a; return out; }
1256 size_t operator-(const _Self& other) { return _i - other._i; }
1258 bool operator==(const _Self& other) const {
1259 assert(_addressSpace == other._addressSpace);
1260 assert(_sects == other._sects);
1261 return _i == other._i;
1264 typename A::pint_t operator*() const { return functionAddress(); }
1266 typename A::pint_t functionAddress() const {
1267 typename A::pint_t indexAddr = _sects->arm_section + arrayoffsetof(
1268 EHABIIndexEntry, _i, functionOffset);
1269 return indexAddr + signExtendPrel31(_addressSpace->get32(indexAddr));
1272 typename A::pint_t dataAddress() {
1273 typename A::pint_t indexAddr = _sects->arm_section + arrayoffsetof(
1274 EHABIIndexEntry, _i, data);
1281 const UnwindInfoSections* _sects;
1284 template <typename A, typename R>
1285 bool UnwindCursor<A, R>::getInfoFromEHABISection(
1287 const UnwindInfoSections §s) {
1288 EHABISectionIterator<A> begin =
1289 EHABISectionIterator<A>::begin(_addressSpace, sects);
1290 EHABISectionIterator<A> end =
1291 EHABISectionIterator<A>::end(_addressSpace, sects);
1295 EHABISectionIterator<A> itNextPC = std::upper_bound(begin, end, pc);
1296 if (itNextPC == begin)
1298 EHABISectionIterator<A> itThisPC = itNextPC - 1;
1300 pint_t thisPC = itThisPC.functionAddress();
1301 // If an exception is thrown from a function, corresponding to the last entry
1302 // in the table, we don't really know the function extent and have to choose a
1303 // value for nextPC. Choosing max() will allow the range check during trace to
1305 pint_t nextPC = (itNextPC == end) ? std::numeric_limits<pint_t>::max()
1306 : itNextPC.functionAddress();
1307 pint_t indexDataAddr = itThisPC.dataAddress();
1309 if (indexDataAddr == 0)
1312 uint32_t indexData = _addressSpace.get32(indexDataAddr);
1313 if (indexData == UNW_EXIDX_CANTUNWIND)
1316 // If the high bit is set, the exception handling table entry is inline inside
1317 // the index table entry on the second word (aka |indexDataAddr|). Otherwise,
1318 // the table points at an offset in the exception handling table (section 5 EHABI).
1319 pint_t exceptionTableAddr;
1320 uint32_t exceptionTableData;
1321 bool isSingleWordEHT;
1322 if (indexData & 0x80000000) {
1323 exceptionTableAddr = indexDataAddr;
1324 // TODO(ajwong): Should this data be 0?
1325 exceptionTableData = indexData;
1326 isSingleWordEHT = true;
1328 exceptionTableAddr = indexDataAddr + signExtendPrel31(indexData);
1329 exceptionTableData = _addressSpace.get32(exceptionTableAddr);
1330 isSingleWordEHT = false;
1333 // Now we know the 3 things:
1334 // exceptionTableAddr -- exception handler table entry.
1335 // exceptionTableData -- the data inside the first word of the eht entry.
1336 // isSingleWordEHT -- whether the entry is in the index.
1337 unw_word_t personalityRoutine = 0xbadf00d;
1338 bool scope32 = false;
1341 // If the high bit in the exception handling table entry is set, the entry is
1342 // in compact form (section 6.3 EHABI).
1343 if (exceptionTableData & 0x80000000) {
1344 // Grab the index of the personality routine from the compact form.
1345 uint32_t choice = (exceptionTableData & 0x0f000000) >> 24;
1346 uint32_t extraWords = 0;
1349 personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr0;
1352 lsda = isSingleWordEHT ? 0 : (exceptionTableAddr + 4);
1355 personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr1;
1356 extraWords = (exceptionTableData & 0x00ff0000) >> 16;
1358 lsda = exceptionTableAddr + (extraWords + 1) * 4;
1361 personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr2;
1362 extraWords = (exceptionTableData & 0x00ff0000) >> 16;
1364 lsda = exceptionTableAddr + (extraWords + 1) * 4;
1367 _LIBUNWIND_ABORT("unknown personality routine");
1371 if (isSingleWordEHT) {
1372 if (extraWords != 0) {
1373 _LIBUNWIND_ABORT("index inlined table detected but pr function "
1374 "requires extra words");
1379 pint_t personalityAddr =
1380 exceptionTableAddr + signExtendPrel31(exceptionTableData);
1381 personalityRoutine = personalityAddr;
1383 // ARM EHABI # 6.2, # 9.2
1387 // +--------------------------------------+
1388 // | +--------+--------+--------+-------+ |
1389 // | |0| prel31 to personalityRoutine | |
1390 // | +--------+--------+--------+-------+ |
1391 // | | N | unwind opcodes | | <-- UnwindData
1392 // | +--------+--------+--------+-------+ |
1393 // | | Word 2 unwind opcodes | |
1394 // | +--------+--------+--------+-------+ |
1396 // | +--------+--------+--------+-------+ |
1397 // | | Word N unwind opcodes | |
1398 // | +--------+--------+--------+-------+ |
1399 // | | LSDA | | <-- lsda
1401 // | +--------+--------+--------+-------+ |
1402 // +--------------------------------------+
1404 uint32_t *UnwindData = reinterpret_cast<uint32_t*>(exceptionTableAddr) + 1;
1405 uint32_t FirstDataWord = *UnwindData;
1406 size_t N = ((FirstDataWord >> 24) & 0xff);
1407 size_t NDataWords = N + 1;
1408 lsda = reinterpret_cast<uintptr_t>(UnwindData + NDataWords);
1411 _info.start_ip = thisPC;
1412 _info.end_ip = nextPC;
1413 _info.handler = personalityRoutine;
1414 _info.unwind_info = exceptionTableAddr;
1416 // flags is pr_cache.additional. See EHABI #7.2 for definition of bit 0.
1417 _info.flags = isSingleWordEHT ? 1 : 0 | scope32 ? 0x2 : 0; // Use enum?
1423 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1424 template <typename A, typename R>
1425 bool UnwindCursor<A, R>::getInfoFromDwarfSection(pint_t pc,
1426 const UnwindInfoSections §s,
1427 uint32_t fdeSectionOffsetHint) {
1428 typename CFI_Parser<A>::FDE_Info fdeInfo;
1429 typename CFI_Parser<A>::CIE_Info cieInfo;
1430 bool foundFDE = false;
1431 bool foundInCache = false;
1432 // If compact encoding table gave offset into dwarf section, go directly there
1433 if (fdeSectionOffsetHint != 0) {
1434 foundFDE = CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,
1435 (uint32_t)sects.dwarf_section_length,
1436 sects.dwarf_section + fdeSectionOffsetHint,
1437 &fdeInfo, &cieInfo);
1439 #if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
1440 if (!foundFDE && (sects.dwarf_index_section != 0)) {
1441 foundFDE = EHHeaderParser<A>::findFDE(
1442 _addressSpace, pc, sects.dwarf_index_section,
1443 (uint32_t)sects.dwarf_index_section_length, &fdeInfo, &cieInfo);
1447 // otherwise, search cache of previously found FDEs.
1448 pint_t cachedFDE = DwarfFDECache<A>::findFDE(sects.dso_base, pc);
1449 if (cachedFDE != 0) {
1451 CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,
1452 (uint32_t)sects.dwarf_section_length,
1453 cachedFDE, &fdeInfo, &cieInfo);
1454 foundInCache = foundFDE;
1458 // Still not found, do full scan of __eh_frame section.
1459 foundFDE = CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,
1460 (uint32_t)sects.dwarf_section_length, 0,
1461 &fdeInfo, &cieInfo);
1464 typename CFI_Parser<A>::PrologInfo prolog;
1465 if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo, pc,
1466 R::getArch(), &prolog)) {
1467 // Save off parsed FDE info
1468 _info.start_ip = fdeInfo.pcStart;
1469 _info.end_ip = fdeInfo.pcEnd;
1470 _info.lsda = fdeInfo.lsda;
1471 _info.handler = cieInfo.personality;
1472 _info.gp = prolog.spExtraArgSize;
1474 _info.format = dwarfEncoding();
1475 _info.unwind_info = fdeInfo.fdeStart;
1476 _info.unwind_info_size = (uint32_t)fdeInfo.fdeLength;
1477 _info.extra = (unw_word_t) sects.dso_base;
1479 // Add to cache (to make next lookup faster) if we had no hint
1480 // and there was no index.
1481 if (!foundInCache && (fdeSectionOffsetHint == 0)) {
1482 #if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
1483 if (sects.dwarf_index_section == 0)
1485 DwarfFDECache<A>::add(sects.dso_base, fdeInfo.pcStart, fdeInfo.pcEnd,
1491 //_LIBUNWIND_DEBUG_LOG("can't find/use FDE for pc=0x%llX", (uint64_t)pc);
1494 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1497 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1498 template <typename A, typename R>
1499 bool UnwindCursor<A, R>::getInfoFromCompactEncodingSection(pint_t pc,
1500 const UnwindInfoSections §s) {
1501 const bool log = false;
1503 fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX, mh=0x%llX)\n",
1504 (uint64_t)pc, (uint64_t)sects.dso_base);
1506 const UnwindSectionHeader<A> sectionHeader(_addressSpace,
1507 sects.compact_unwind_section);
1508 if (sectionHeader.version() != UNWIND_SECTION_VERSION)
1511 // do a binary search of top level index to find page with unwind info
1512 pint_t targetFunctionOffset = pc - sects.dso_base;
1513 const UnwindSectionIndexArray<A> topIndex(_addressSpace,
1514 sects.compact_unwind_section
1515 + sectionHeader.indexSectionOffset());
1517 uint32_t high = sectionHeader.indexCount();
1518 uint32_t last = high - 1;
1519 while (low < high) {
1520 uint32_t mid = (low + high) / 2;
1521 //if ( log ) fprintf(stderr, "\tmid=%d, low=%d, high=%d, *mid=0x%08X\n",
1522 //mid, low, high, topIndex.functionOffset(mid));
1523 if (topIndex.functionOffset(mid) <= targetFunctionOffset) {
1524 if ((mid == last) ||
1525 (topIndex.functionOffset(mid + 1) > targetFunctionOffset)) {
1535 const uint32_t firstLevelFunctionOffset = topIndex.functionOffset(low);
1536 const uint32_t firstLevelNextPageFunctionOffset =
1537 topIndex.functionOffset(low + 1);
1538 const pint_t secondLevelAddr =
1539 sects.compact_unwind_section + topIndex.secondLevelPagesSectionOffset(low);
1540 const pint_t lsdaArrayStartAddr =
1541 sects.compact_unwind_section + topIndex.lsdaIndexArraySectionOffset(low);
1542 const pint_t lsdaArrayEndAddr =
1543 sects.compact_unwind_section + topIndex.lsdaIndexArraySectionOffset(low+1);
1545 fprintf(stderr, "\tfirst level search for result index=%d "
1546 "to secondLevelAddr=0x%llX\n",
1547 low, (uint64_t) secondLevelAddr);
1548 // do a binary search of second level page index
1549 uint32_t encoding = 0;
1550 pint_t funcStart = 0;
1553 pint_t personality = 0;
1554 uint32_t pageKind = _addressSpace.get32(secondLevelAddr);
1555 if (pageKind == UNWIND_SECOND_LEVEL_REGULAR) {
1557 UnwindSectionRegularPageHeader<A> pageHeader(_addressSpace,
1559 UnwindSectionRegularArray<A> pageIndex(
1560 _addressSpace, secondLevelAddr + pageHeader.entryPageOffset());
1561 // binary search looks for entry with e where index[e].offset <= pc <
1562 // index[e+1].offset
1564 fprintf(stderr, "\tbinary search for targetFunctionOffset=0x%08llX in "
1565 "regular page starting at secondLevelAddr=0x%llX\n",
1566 (uint64_t) targetFunctionOffset, (uint64_t) secondLevelAddr);
1568 high = pageHeader.entryCount();
1569 while (low < high) {
1570 uint32_t mid = (low + high) / 2;
1571 if (pageIndex.functionOffset(mid) <= targetFunctionOffset) {
1572 if (mid == (uint32_t)(pageHeader.entryCount() - 1)) {
1575 funcEnd = firstLevelNextPageFunctionOffset + sects.dso_base;
1577 } else if (pageIndex.functionOffset(mid + 1) > targetFunctionOffset) {
1578 // next is too big, so we found it
1580 funcEnd = pageIndex.functionOffset(low + 1) + sects.dso_base;
1589 encoding = pageIndex.encoding(low);
1590 funcStart = pageIndex.functionOffset(low) + sects.dso_base;
1591 if (pc < funcStart) {
1595 "\tpc not in table, pc=0x%llX, funcStart=0x%llX, funcEnd=0x%llX\n",
1596 (uint64_t) pc, (uint64_t) funcStart, (uint64_t) funcEnd);
1603 "\tpc not in table, pc=0x%llX, funcStart=0x%llX, funcEnd=0x%llX\n",
1604 (uint64_t) pc, (uint64_t) funcStart, (uint64_t) funcEnd);
1607 } else if (pageKind == UNWIND_SECOND_LEVEL_COMPRESSED) {
1609 UnwindSectionCompressedPageHeader<A> pageHeader(_addressSpace,
1611 UnwindSectionCompressedArray<A> pageIndex(
1612 _addressSpace, secondLevelAddr + pageHeader.entryPageOffset());
1613 const uint32_t targetFunctionPageOffset =
1614 (uint32_t)(targetFunctionOffset - firstLevelFunctionOffset);
1615 // binary search looks for entry with e where index[e].offset <= pc <
1616 // index[e+1].offset
1618 fprintf(stderr, "\tbinary search of compressed page starting at "
1619 "secondLevelAddr=0x%llX\n",
1620 (uint64_t) secondLevelAddr);
1622 last = pageHeader.entryCount() - 1;
1623 high = pageHeader.entryCount();
1624 while (low < high) {
1625 uint32_t mid = (low + high) / 2;
1626 if (pageIndex.functionOffset(mid) <= targetFunctionPageOffset) {
1627 if ((mid == last) ||
1628 (pageIndex.functionOffset(mid + 1) > targetFunctionPageOffset)) {
1638 funcStart = pageIndex.functionOffset(low) + firstLevelFunctionOffset
1642 pageIndex.functionOffset(low + 1) + firstLevelFunctionOffset
1645 funcEnd = firstLevelNextPageFunctionOffset + sects.dso_base;
1646 if (pc < funcStart) {
1647 _LIBUNWIND_DEBUG_LOG("malformed __unwind_info, pc=0x%llX not in second "
1648 "level compressed unwind table. funcStart=0x%llX",
1649 (uint64_t) pc, (uint64_t) funcStart);
1653 _LIBUNWIND_DEBUG_LOG("malformed __unwind_info, pc=0x%llX not in second "
1654 "level compressed unwind table. funcEnd=0x%llX",
1655 (uint64_t) pc, (uint64_t) funcEnd);
1658 uint16_t encodingIndex = pageIndex.encodingIndex(low);
1659 if (encodingIndex < sectionHeader.commonEncodingsArrayCount()) {
1660 // encoding is in common table in section header
1661 encoding = _addressSpace.get32(
1662 sects.compact_unwind_section +
1663 sectionHeader.commonEncodingsArraySectionOffset() +
1664 encodingIndex * sizeof(uint32_t));
1666 // encoding is in page specific table
1667 uint16_t pageEncodingIndex =
1668 encodingIndex - (uint16_t)sectionHeader.commonEncodingsArrayCount();
1669 encoding = _addressSpace.get32(secondLevelAddr +
1670 pageHeader.encodingsPageOffset() +
1671 pageEncodingIndex * sizeof(uint32_t));
1674 _LIBUNWIND_DEBUG_LOG("malformed __unwind_info at 0x%0llX bad second "
1676 (uint64_t) sects.compact_unwind_section);
1680 // look up LSDA, if encoding says function has one
1681 if (encoding & UNWIND_HAS_LSDA) {
1682 UnwindSectionLsdaArray<A> lsdaIndex(_addressSpace, lsdaArrayStartAddr);
1683 uint32_t funcStartOffset = (uint32_t)(funcStart - sects.dso_base);
1685 high = (uint32_t)(lsdaArrayEndAddr - lsdaArrayStartAddr) /
1686 sizeof(unwind_info_section_header_lsda_index_entry);
1687 // binary search looks for entry with exact match for functionOffset
1690 "\tbinary search of lsda table for targetFunctionOffset=0x%08X\n",
1692 while (low < high) {
1693 uint32_t mid = (low + high) / 2;
1694 if (lsdaIndex.functionOffset(mid) == funcStartOffset) {
1695 lsda = lsdaIndex.lsdaOffset(mid) + sects.dso_base;
1697 } else if (lsdaIndex.functionOffset(mid) < funcStartOffset) {
1704 _LIBUNWIND_DEBUG_LOG("found encoding 0x%08X with HAS_LSDA bit set for "
1705 "pc=0x%0llX, but lsda table has no entry",
1706 encoding, (uint64_t) pc);
1711 // extact personality routine, if encoding says function has one
1712 uint32_t personalityIndex = (encoding & UNWIND_PERSONALITY_MASK) >>
1713 (__builtin_ctz(UNWIND_PERSONALITY_MASK));
1714 if (personalityIndex != 0) {
1715 --personalityIndex; // change 1-based to zero-based index
1716 if (personalityIndex > sectionHeader.personalityArrayCount()) {
1717 _LIBUNWIND_DEBUG_LOG("found encoding 0x%08X with personality index %d, "
1718 "but personality table has only %d entires",
1719 encoding, personalityIndex,
1720 sectionHeader.personalityArrayCount());
1723 int32_t personalityDelta = (int32_t)_addressSpace.get32(
1724 sects.compact_unwind_section +
1725 sectionHeader.personalityArraySectionOffset() +
1726 personalityIndex * sizeof(uint32_t));
1727 pint_t personalityPointer = sects.dso_base + (pint_t)personalityDelta;
1728 personality = _addressSpace.getP(personalityPointer);
1730 fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX), "
1731 "personalityDelta=0x%08X, personality=0x%08llX\n",
1732 (uint64_t) pc, personalityDelta, (uint64_t) personality);
1736 fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX), "
1737 "encoding=0x%08X, lsda=0x%08llX for funcStart=0x%llX\n",
1738 (uint64_t) pc, encoding, (uint64_t) lsda, (uint64_t) funcStart);
1739 _info.start_ip = funcStart;
1740 _info.end_ip = funcEnd;
1742 _info.handler = personality;
1745 _info.format = encoding;
1746 _info.unwind_info = 0;
1747 _info.unwind_info_size = 0;
1748 _info.extra = sects.dso_base;
1751 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1754 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1755 template <typename A, typename R>
1756 bool UnwindCursor<A, R>::getInfoFromSEH(pint_t pc) {
1758 RUNTIME_FUNCTION *unwindEntry = lookUpSEHUnwindInfo(pc, &base);
1760 _LIBUNWIND_DEBUG_LOG("\tpc not in table, pc=0x%llX", (uint64_t) pc);
1766 _info.unwind_info_size = sizeof(RUNTIME_FUNCTION);
1767 _info.unwind_info = reinterpret_cast<unw_word_t>(unwindEntry);
1769 _info.start_ip = base + unwindEntry->BeginAddress;
1770 #ifdef _LIBUNWIND_TARGET_X86_64
1771 _info.end_ip = base + unwindEntry->EndAddress;
1772 // Only fill in the handler and LSDA if they're stale.
1773 if (pc != getLastPC()) {
1774 UNWIND_INFO *xdata = reinterpret_cast<UNWIND_INFO *>(base + unwindEntry->UnwindData);
1775 if (xdata->Flags & (UNW_FLAG_EHANDLER|UNW_FLAG_UHANDLER)) {
1776 // The personality is given in the UNWIND_INFO itself. The LSDA immediately
1777 // follows the UNWIND_INFO. (This follows how both Clang and MSVC emit
1778 // these structures.)
1779 // N.B. UNWIND_INFO structs are DWORD-aligned.
1780 uint32_t lastcode = (xdata->CountOfCodes + 1) & ~1;
1781 const uint32_t *handler = reinterpret_cast<uint32_t *>(&xdata->UnwindCodes[lastcode]);
1782 _info.lsda = reinterpret_cast<unw_word_t>(handler+1);
1784 _info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);
1792 #elif defined(_LIBUNWIND_TARGET_ARM)
1793 _info.end_ip = _info.start_ip + unwindEntry->FunctionLength;
1794 _info.lsda = 0; // FIXME
1795 _info.handler = 0; // FIXME
1803 template <typename A, typename R>
1804 void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
1805 pint_t pc = (pint_t)this->getReg(UNW_REG_IP);
1806 #if defined(_LIBUNWIND_ARM_EHABI)
1807 // Remove the thumb bit so the IP represents the actual instruction address.
1808 // This matches the behaviour of _Unwind_GetIP on arm.
1812 // If the last line of a function is a "throw" the compiler sometimes
1813 // emits no instructions after the call to __cxa_throw. This means
1814 // the return address is actually the start of the next function.
1815 // To disambiguate this, back up the pc when we know it is a return
1817 if (isReturnAddress)
1820 // Ask address space object to find unwind sections for this pc.
1821 UnwindInfoSections sects;
1822 if (_addressSpace.findUnwindSections(pc, sects)) {
1823 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1824 // If there is a compact unwind encoding table, look there first.
1825 if (sects.compact_unwind_section != 0) {
1826 if (this->getInfoFromCompactEncodingSection(pc, sects)) {
1827 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1828 // Found info in table, done unless encoding says to use dwarf.
1829 uint32_t dwarfOffset;
1830 if ((sects.dwarf_section != 0) && compactSaysUseDwarf(&dwarfOffset)) {
1831 if (this->getInfoFromDwarfSection(pc, sects, dwarfOffset)) {
1832 // found info in dwarf, done
1837 // If unwind table has entry, but entry says there is no unwind info,
1838 // record that we have no unwind info.
1839 if (_info.format == 0)
1840 _unwindInfoMissing = true;
1844 #endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1846 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1847 // If there is SEH unwind info, look there next.
1848 if (this->getInfoFromSEH(pc))
1852 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1853 // If there is dwarf unwind info, look there next.
1854 if (sects.dwarf_section != 0) {
1855 if (this->getInfoFromDwarfSection(pc, sects)) {
1856 // found info in dwarf, done
1862 #if defined(_LIBUNWIND_ARM_EHABI)
1863 // If there is ARM EHABI unwind info, look there next.
1864 if (sects.arm_section != 0 && this->getInfoFromEHABISection(pc, sects))
1869 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1870 // There is no static unwind info for this pc. Look to see if an FDE was
1871 // dynamically registered for it.
1872 pint_t cachedFDE = DwarfFDECache<A>::findFDE(0, pc);
1873 if (cachedFDE != 0) {
1874 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
1875 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
1876 const char *msg = CFI_Parser<A>::decodeFDE(_addressSpace,
1877 cachedFDE, &fdeInfo, &cieInfo);
1879 typename CFI_Parser<A>::PrologInfo prolog;
1880 if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo,
1881 pc, R::getArch(), &prolog)) {
1882 // save off parsed FDE info
1883 _info.start_ip = fdeInfo.pcStart;
1884 _info.end_ip = fdeInfo.pcEnd;
1885 _info.lsda = fdeInfo.lsda;
1886 _info.handler = cieInfo.personality;
1887 _info.gp = prolog.spExtraArgSize;
1888 // Some frameless functions need SP
1889 // altered when resuming in function.
1891 _info.format = dwarfEncoding();
1892 _info.unwind_info = fdeInfo.fdeStart;
1893 _info.unwind_info_size = (uint32_t)fdeInfo.fdeLength;
1900 // Lastly, ask AddressSpace object about platform specific ways to locate
1903 if (_addressSpace.findOtherFDE(pc, fde)) {
1904 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
1905 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
1906 if (!CFI_Parser<A>::decodeFDE(_addressSpace, fde, &fdeInfo, &cieInfo)) {
1907 // Double check this FDE is for a function that includes the pc.
1908 if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd)) {
1909 typename CFI_Parser<A>::PrologInfo prolog;
1910 if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo,
1911 pc, R::getArch(), &prolog)) {
1912 // save off parsed FDE info
1913 _info.start_ip = fdeInfo.pcStart;
1914 _info.end_ip = fdeInfo.pcEnd;
1915 _info.lsda = fdeInfo.lsda;
1916 _info.handler = cieInfo.personality;
1917 _info.gp = prolog.spExtraArgSize;
1919 _info.format = dwarfEncoding();
1920 _info.unwind_info = fdeInfo.fdeStart;
1921 _info.unwind_info_size = (uint32_t)fdeInfo.fdeLength;
1928 #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1930 // no unwind info, flag that we can't reliably unwind
1931 _unwindInfoMissing = true;
1934 template <typename A, typename R>
1935 int UnwindCursor<A, R>::step() {
1936 // Bottom of stack is defined is when unwind info cannot be found.
1937 if (_unwindInfoMissing)
1938 return UNW_STEP_END;
1940 // Use unwinding info to modify register set as if function returned.
1942 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
1943 result = this->stepWithCompactEncoding();
1944 #elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
1945 result = this->stepWithSEHData();
1946 #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
1947 result = this->stepWithDwarfFDE();
1948 #elif defined(_LIBUNWIND_ARM_EHABI)
1949 result = this->stepWithEHABI();
1951 #error Need _LIBUNWIND_SUPPORT_COMPACT_UNWIND or \
1952 _LIBUNWIND_SUPPORT_SEH_UNWIND or \
1953 _LIBUNWIND_SUPPORT_DWARF_UNWIND or \
1954 _LIBUNWIND_ARM_EHABI
1957 // update info based on new PC
1958 if (result == UNW_STEP_SUCCESS) {
1959 this->setInfoBasedOnIPRegister(true);
1960 if (_unwindInfoMissing)
1961 return UNW_STEP_END;
1967 template <typename A, typename R>
1968 void UnwindCursor<A, R>::getInfo(unw_proc_info_t *info) {
1972 template <typename A, typename R>
1973 bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
1974 unw_word_t *offset) {
1975 return _addressSpace.findFunctionName((pint_t)this->getReg(UNW_REG_IP),
1976 buf, bufLen, offset);
1979 } // namespace libunwind
1981 #endif // __UNWINDCURSOR_HPP__