Ed Maste | 6f72338 | 2016-08-30 13:08:21 +0000 | [diff] [blame] | 1 | //===--------------------------- libunwind.cpp ----------------------------===// |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 61860a5 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 6 | // |
| 7 | // |
| 8 | // Implements unw_* functions from <libunwind.h> |
| 9 | // |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | |
| 12 | #include <libunwind.h> |
| 13 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 14 | #include "libunwind_ext.h" |
| 15 | #include "config.h" |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | |
| 19 | |
Martin Storsjo | 9f16c6c | 2017-09-26 08:07:26 +0000 | [diff] [blame] | 20 | #if !defined(__USING_SJLJ_EXCEPTIONS__) |
Ed Schouten | edb7680 | 2017-03-09 08:04:07 +0000 | [diff] [blame] | 21 | #include "AddressSpace.hpp" |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 22 | #include "UnwindCursor.hpp" |
| 23 | |
| 24 | using namespace libunwind; |
| 25 | |
| 26 | /// internal object to represent this processes address space |
| 27 | LocalAddressSpace LocalAddressSpace::sThisAddressSpace; |
| 28 | |
| 29 | _LIBUNWIND_EXPORT unw_addr_space_t unw_local_addr_space = |
| 30 | (unw_addr_space_t)&LocalAddressSpace::sThisAddressSpace; |
| 31 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 32 | /// Create a cursor of a thread in this process given 'context' recorded by |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 33 | /// __unw_getcontext(). |
| 34 | _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor, |
| 35 | unw_context_t *context) { |
| 36 | _LIBUNWIND_TRACE_API("__unw_init_local(cursor=%p, context=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 37 | static_cast<void *>(cursor), |
| 38 | static_cast<void *>(context)); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 39 | #if defined(__i386__) |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 40 | # define REGISTER_KIND Registers_x86 |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 41 | #elif defined(__x86_64__) |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 42 | # define REGISTER_KIND Registers_x86_64 |
Martin Storsjo | 8338b0a | 2018-01-02 22:11:30 +0000 | [diff] [blame] | 43 | #elif defined(__powerpc64__) |
| 44 | # define REGISTER_KIND Registers_ppc64 |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 45 | #elif defined(__ppc__) |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 46 | # define REGISTER_KIND Registers_ppc |
| 47 | #elif defined(__aarch64__) |
| 48 | # define REGISTER_KIND Registers_arm64 |
Martin Storsjo | a72285f | 2017-11-02 08:16:16 +0000 | [diff] [blame] | 49 | #elif defined(__arm__) |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 50 | # define REGISTER_KIND Registers_arm |
Peter Zotov | 8d63999 | 2015-08-31 05:26:37 +0000 | [diff] [blame] | 51 | #elif defined(__or1k__) |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 52 | # define REGISTER_KIND Registers_or1k |
John Baldwin | 4030029 | 2018-05-15 22:44:56 +0000 | [diff] [blame] | 53 | #elif defined(__mips__) && defined(_ABIO32) && _MIPS_SIM == _ABIO32 |
John Baldwin | 56441d4 | 2017-12-12 21:43:36 +0000 | [diff] [blame] | 54 | # define REGISTER_KIND Registers_mips_o32 |
John Baldwin | 4030029 | 2018-05-15 22:44:56 +0000 | [diff] [blame] | 55 | #elif defined(__mips64) |
John Baldwin | 541a435 | 2018-01-09 17:07:18 +0000 | [diff] [blame] | 56 | # define REGISTER_KIND Registers_mips_newabi |
Vasileios Kalintiris | 3bd271c | 2015-09-26 18:26:01 +0000 | [diff] [blame] | 57 | #elif defined(__mips__) |
John Baldwin | 56441d4 | 2017-12-12 21:43:36 +0000 | [diff] [blame] | 58 | # warning The MIPS architecture is not supported with this ABI and environment! |
Daniel Cederman | 9f2f07a | 2019-01-14 10:15:20 +0000 | [diff] [blame] | 59 | #elif defined(__sparc__) |
| 60 | # define REGISTER_KIND Registers_sparc |
Ed Maste | 846892c | 2015-08-13 14:21:03 +0000 | [diff] [blame] | 61 | #else |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 62 | # error Architecture not supported |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 63 | #endif |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 64 | // Use "placement new" to allocate UnwindCursor in the cursor buffer. |
Petr Hosek | 36f6154 | 2019-02-02 21:15:49 +0000 | [diff] [blame] | 65 | new (reinterpret_cast<UnwindCursor<LocalAddressSpace, REGISTER_KIND> *>(cursor)) |
| 66 | UnwindCursor<LocalAddressSpace, REGISTER_KIND>( |
| 67 | context, LocalAddressSpace::sThisAddressSpace); |
Asiri Rathnayake | c00dcef | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 68 | #undef REGISTER_KIND |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 69 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 70 | co->setInfoBasedOnIPRegister(); |
| 71 | |
| 72 | return UNW_ESUCCESS; |
| 73 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 74 | _LIBUNWIND_WEAK_ALIAS(__unw_init_local, unw_init_local) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 75 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 76 | /// Get value of specified register at cursor position in stack frame. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 77 | _LIBUNWIND_HIDDEN int __unw_get_reg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 78 | unw_word_t *value) { |
| 79 | _LIBUNWIND_TRACE_API("__unw_get_reg(cursor=%p, regNum=%d, &value=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 80 | static_cast<void *>(cursor), regNum, |
| 81 | static_cast<void *>(value)); |
| 82 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 83 | if (co->validReg(regNum)) { |
| 84 | *value = co->getReg(regNum); |
| 85 | return UNW_ESUCCESS; |
| 86 | } |
| 87 | return UNW_EBADREG; |
| 88 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 89 | _LIBUNWIND_WEAK_ALIAS(__unw_get_reg, unw_get_reg) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 90 | |
| 91 | /// Set value of specified register at cursor position in stack frame. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 92 | _LIBUNWIND_HIDDEN int __unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 93 | unw_word_t value) { |
| 94 | _LIBUNWIND_TRACE_API("__unw_set_reg(cursor=%p, regNum=%d, value=0x%" PRIxPTR |
| 95 | ")", |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 96 | static_cast<void *>(cursor), regNum, value); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 97 | typedef LocalAddressSpace::pint_t pint_t; |
| 98 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 99 | if (co->validReg(regNum)) { |
| 100 | co->setReg(regNum, (pint_t)value); |
| 101 | // specical case altering IP to re-find info (being called by personality |
| 102 | // function) |
Joerg Sonnenberger | 7ac54d3 | 2018-07-17 19:00:51 +0000 | [diff] [blame] | 103 | if (regNum == UNW_REG_IP) { |
| 104 | unw_proc_info_t info; |
| 105 | // First, get the FDE for the old location and then update it. |
| 106 | co->getInfo(&info); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 107 | co->setInfoBasedOnIPRegister(false); |
Joerg Sonnenberger | 7ac54d3 | 2018-07-17 19:00:51 +0000 | [diff] [blame] | 108 | // If the original call expects stack adjustment, perform this now. |
| 109 | // Normal frame unwinding would have included the offset already in the |
| 110 | // CFA computation. |
| 111 | // Note: for PA-RISC and other platforms where the stack grows up, |
| 112 | // this should actually be - info.gp. LLVM doesn't currently support |
| 113 | // any such platforms and Clang doesn't export a macro for them. |
| 114 | if (info.gp) |
| 115 | co->setReg(UNW_REG_SP, co->getReg(UNW_REG_SP) + info.gp); |
| 116 | } |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 117 | return UNW_ESUCCESS; |
| 118 | } |
| 119 | return UNW_EBADREG; |
| 120 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 121 | _LIBUNWIND_WEAK_ALIAS(__unw_set_reg, unw_set_reg) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 122 | |
| 123 | /// Get value of specified float register at cursor position in stack frame. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 124 | _LIBUNWIND_HIDDEN int __unw_get_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 125 | unw_fpreg_t *value) { |
| 126 | _LIBUNWIND_TRACE_API("__unw_get_fpreg(cursor=%p, regNum=%d, &value=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 127 | static_cast<void *>(cursor), regNum, |
| 128 | static_cast<void *>(value)); |
| 129 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 130 | if (co->validFloatReg(regNum)) { |
| 131 | *value = co->getFloatReg(regNum); |
| 132 | return UNW_ESUCCESS; |
| 133 | } |
| 134 | return UNW_EBADREG; |
| 135 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 136 | _LIBUNWIND_WEAK_ALIAS(__unw_get_fpreg, unw_get_fpreg) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 137 | |
| 138 | /// Set value of specified float register at cursor position in stack frame. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 139 | _LIBUNWIND_HIDDEN int __unw_set_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 140 | unw_fpreg_t value) { |
Ranjeet Singh | 421231a | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 141 | #if defined(_LIBUNWIND_ARM_EHABI) |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 142 | _LIBUNWIND_TRACE_API("__unw_set_fpreg(cursor=%p, regNum=%d, value=%llX)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 143 | static_cast<void *>(cursor), regNum, value); |
| 144 | #else |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 145 | _LIBUNWIND_TRACE_API("__unw_set_fpreg(cursor=%p, regNum=%d, value=%g)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 146 | static_cast<void *>(cursor), regNum, value); |
| 147 | #endif |
| 148 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 149 | if (co->validFloatReg(regNum)) { |
| 150 | co->setFloatReg(regNum, value); |
| 151 | return UNW_ESUCCESS; |
| 152 | } |
| 153 | return UNW_EBADREG; |
| 154 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 155 | _LIBUNWIND_WEAK_ALIAS(__unw_set_fpreg, unw_set_fpreg) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 156 | |
| 157 | /// Move cursor to next frame. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 158 | _LIBUNWIND_HIDDEN int __unw_step(unw_cursor_t *cursor) { |
| 159 | _LIBUNWIND_TRACE_API("__unw_step(cursor=%p)", static_cast<void *>(cursor)); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 160 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 161 | return co->step(); |
| 162 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 163 | _LIBUNWIND_WEAK_ALIAS(__unw_step, unw_step) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 164 | |
| 165 | /// Get unwind info at cursor position in stack frame. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 166 | _LIBUNWIND_HIDDEN int __unw_get_proc_info(unw_cursor_t *cursor, |
| 167 | unw_proc_info_t *info) { |
| 168 | _LIBUNWIND_TRACE_API("__unw_get_proc_info(cursor=%p, &info=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 169 | static_cast<void *>(cursor), static_cast<void *>(info)); |
| 170 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 171 | co->getInfo(info); |
| 172 | if (info->end_ip == 0) |
| 173 | return UNW_ENOINFO; |
Saleem Abdulrasool | 2aa34a8 | 2019-09-18 16:15:56 +0000 | [diff] [blame] | 174 | return UNW_ESUCCESS; |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 175 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 176 | _LIBUNWIND_WEAK_ALIAS(__unw_get_proc_info, unw_get_proc_info) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 177 | |
| 178 | /// Resume execution at cursor position (aka longjump). |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 179 | _LIBUNWIND_HIDDEN int __unw_resume(unw_cursor_t *cursor) { |
| 180 | _LIBUNWIND_TRACE_API("__unw_resume(cursor=%p)", static_cast<void *>(cursor)); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 181 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 182 | co->jumpto(); |
| 183 | return UNW_EUNSPEC; |
| 184 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 185 | _LIBUNWIND_WEAK_ALIAS(__unw_resume, unw_resume) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 186 | |
| 187 | /// Get name of function at cursor position in stack frame. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 188 | _LIBUNWIND_HIDDEN int __unw_get_proc_name(unw_cursor_t *cursor, char *buf, |
| 189 | size_t bufLen, unw_word_t *offset) { |
| 190 | _LIBUNWIND_TRACE_API("__unw_get_proc_name(cursor=%p, &buf=%p, bufLen=%lu)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 191 | static_cast<void *>(cursor), static_cast<void *>(buf), |
| 192 | static_cast<unsigned long>(bufLen)); |
| 193 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 194 | if (co->getFunctionName(buf, bufLen, offset)) |
| 195 | return UNW_ESUCCESS; |
Saleem Abdulrasool | 2aa34a8 | 2019-09-18 16:15:56 +0000 | [diff] [blame] | 196 | return UNW_EUNSPEC; |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 197 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 198 | _LIBUNWIND_WEAK_ALIAS(__unw_get_proc_name, unw_get_proc_name) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 199 | |
| 200 | /// Checks if a register is a floating-point register. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 201 | _LIBUNWIND_HIDDEN int __unw_is_fpreg(unw_cursor_t *cursor, |
| 202 | unw_regnum_t regNum) { |
| 203 | _LIBUNWIND_TRACE_API("__unw_is_fpreg(cursor=%p, regNum=%d)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 204 | static_cast<void *>(cursor), regNum); |
| 205 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 206 | return co->validFloatReg(regNum); |
| 207 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 208 | _LIBUNWIND_WEAK_ALIAS(__unw_is_fpreg, unw_is_fpreg) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 209 | |
| 210 | /// Checks if a register is a floating-point register. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 211 | _LIBUNWIND_HIDDEN const char *__unw_regname(unw_cursor_t *cursor, |
| 212 | unw_regnum_t regNum) { |
| 213 | _LIBUNWIND_TRACE_API("__unw_regname(cursor=%p, regNum=%d)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 214 | static_cast<void *>(cursor), regNum); |
| 215 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 216 | return co->getRegisterName(regNum); |
| 217 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 218 | _LIBUNWIND_WEAK_ALIAS(__unw_regname, unw_regname) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 219 | |
| 220 | /// Checks if current frame is signal trampoline. |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 221 | _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) { |
| 222 | _LIBUNWIND_TRACE_API("__unw_is_signal_frame(cursor=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 223 | static_cast<void *>(cursor)); |
| 224 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 225 | return co->isSignalFrame(); |
| 226 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 227 | _LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 228 | |
| 229 | #ifdef __arm__ |
| 230 | // Save VFP registers d0-d15 using FSTMIADX instead of FSTMIADD |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 231 | _LIBUNWIND_HIDDEN void __unw_save_vfp_as_X(unw_cursor_t *cursor) { |
| 232 | _LIBUNWIND_TRACE_API("__unw_get_fpreg_save_vfp_as_X(cursor=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 233 | static_cast<void *>(cursor)); |
| 234 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 235 | return co->saveVFPAsX(); |
| 236 | } |
Petr Hosek | 01fc413 | 2019-04-11 13:08:44 +0000 | [diff] [blame] | 237 | _LIBUNWIND_WEAK_ALIAS(__unw_save_vfp_as_X, unw_save_vfp_as_X) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 238 | #endif |
| 239 | |
| 240 | |
Ranjeet Singh | 421231a | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 241 | #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) |
Ed Maste | 4c43c3d | 2016-07-19 17:15:50 +0000 | [diff] [blame] | 242 | /// SPI: walks cached DWARF entries |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 243 | _LIBUNWIND_HIDDEN void __unw_iterate_dwarf_unwind_cache(void (*func)( |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 244 | unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 245 | _LIBUNWIND_TRACE_API("__unw_iterate_dwarf_unwind_cache(func=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 246 | reinterpret_cast<void *>(func)); |
| 247 | DwarfFDECache<LocalAddressSpace>::iterateCacheEntries(func); |
| 248 | } |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 249 | _LIBUNWIND_WEAK_ALIAS(__unw_iterate_dwarf_unwind_cache, |
| 250 | unw_iterate_dwarf_unwind_cache) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 251 | |
| 252 | /// IPI: for __register_frame() |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 253 | void __unw_add_dynamic_fde(unw_word_t fde) { |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 254 | CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo; |
| 255 | CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo; |
| 256 | const char *message = CFI_Parser<LocalAddressSpace>::decodeFDE( |
| 257 | LocalAddressSpace::sThisAddressSpace, |
| 258 | (LocalAddressSpace::pint_t) fde, &fdeInfo, &cieInfo); |
| 259 | if (message == NULL) { |
| 260 | // dynamically registered FDEs don't have a mach_header group they are in. |
| 261 | // Use fde as mh_group |
| 262 | unw_word_t mh_group = fdeInfo.fdeStart; |
| 263 | DwarfFDECache<LocalAddressSpace>::add((LocalAddressSpace::pint_t)mh_group, |
| 264 | fdeInfo.pcStart, fdeInfo.pcEnd, |
| 265 | fdeInfo.fdeStart); |
| 266 | } else { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 267 | _LIBUNWIND_DEBUG_LOG("__unw_add_dynamic_fde: bad fde: %s", message); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
| 271 | /// IPI: for __deregister_frame() |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 272 | void __unw_remove_dynamic_fde(unw_word_t fde) { |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 273 | // fde is own mh_group |
| 274 | DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde); |
| 275 | } |
Ranjeet Singh | 421231a | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 276 | #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) |
Martin Storsjo | 9f16c6c | 2017-09-26 08:07:26 +0000 | [diff] [blame] | 277 | #endif // !defined(__USING_SJLJ_EXCEPTIONS__) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 278 | |
| 279 | |
| 280 | |
| 281 | // Add logging hooks in Debug builds only |
| 282 | #ifndef NDEBUG |
| 283 | #include <stdlib.h> |
| 284 | |
| 285 | _LIBUNWIND_HIDDEN |
| 286 | bool logAPIs() { |
| 287 | // do manual lock to avoid use of _cxa_guard_acquire or initializers |
| 288 | static bool checked = false; |
| 289 | static bool log = false; |
| 290 | if (!checked) { |
| 291 | log = (getenv("LIBUNWIND_PRINT_APIS") != NULL); |
| 292 | checked = true; |
| 293 | } |
| 294 | return log; |
| 295 | } |
| 296 | |
| 297 | _LIBUNWIND_HIDDEN |
| 298 | bool logUnwinding() { |
| 299 | // do manual lock to avoid use of _cxa_guard_acquire or initializers |
| 300 | static bool checked = false; |
| 301 | static bool log = false; |
| 302 | if (!checked) { |
| 303 | log = (getenv("LIBUNWIND_PRINT_UNWINDING") != NULL); |
| 304 | checked = true; |
| 305 | } |
| 306 | return log; |
| 307 | } |
| 308 | |
Saleem Abdulrasool | d1be5b0 | 2017-01-21 16:22:57 +0000 | [diff] [blame] | 309 | _LIBUNWIND_HIDDEN |
| 310 | bool logDWARF() { |
| 311 | // do manual lock to avoid use of _cxa_guard_acquire or initializers |
| 312 | static bool checked = false; |
| 313 | static bool log = false; |
| 314 | if (!checked) { |
| 315 | log = (getenv("LIBUNWIND_PRINT_DWARF") != NULL); |
| 316 | checked = true; |
| 317 | } |
| 318 | return log; |
| 319 | } |
| 320 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 321 | #endif // NDEBUG |
| 322 | |