Ed Maste | 17473fd | 2016-08-30 13:08:21 +0000 | [diff] [blame] | 1 | //===--------------------------- libunwind.cpp ----------------------------===// |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | // |
| 9 | // Implements unw_* functions from <libunwind.h> |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include <libunwind.h> |
| 14 | |
| 15 | #ifndef NDEBUG |
| 16 | #include <cstdlib> // getenv |
| 17 | #endif |
| 18 | #include <new> |
Saleem Abdulrasool | a802ef4 | 2015-05-11 16:35:13 +0000 | [diff] [blame] | 19 | #include <algorithm> |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 20 | |
| 21 | #include "libunwind_ext.h" |
| 22 | #include "config.h" |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | |
| 26 | |
Martin Storsjo | e53dc3f | 2017-09-26 08:07:26 +0000 | [diff] [blame] | 27 | #if !defined(__USING_SJLJ_EXCEPTIONS__) |
Ed Schouten | 188f3c7 | 2017-03-09 08:04:07 +0000 | [diff] [blame] | 28 | #include "AddressSpace.hpp" |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 29 | #include "UnwindCursor.hpp" |
| 30 | |
| 31 | using namespace libunwind; |
| 32 | |
| 33 | /// internal object to represent this processes address space |
| 34 | LocalAddressSpace LocalAddressSpace::sThisAddressSpace; |
| 35 | |
| 36 | _LIBUNWIND_EXPORT unw_addr_space_t unw_local_addr_space = |
| 37 | (unw_addr_space_t)&LocalAddressSpace::sThisAddressSpace; |
| 38 | |
| 39 | /// record the registers and stack position of the caller |
| 40 | extern int unw_getcontext(unw_context_t *); |
| 41 | // note: unw_getcontext() implemented in assembly |
| 42 | |
| 43 | /// Create a cursor of a thread in this process given 'context' recorded by |
| 44 | /// unw_getcontext(). |
| 45 | _LIBUNWIND_EXPORT int unw_init_local(unw_cursor_t *cursor, |
| 46 | unw_context_t *context) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 47 | _LIBUNWIND_TRACE_API("unw_init_local(cursor=%p, context=%p)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 48 | static_cast<void *>(cursor), |
| 49 | static_cast<void *>(context)); |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 50 | #if defined(__i386__) |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 51 | # define REGISTER_KIND Registers_x86 |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 52 | #elif defined(__x86_64__) |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 53 | # define REGISTER_KIND Registers_x86_64 |
Martin Storsjo | dc25db1 | 2018-01-02 22:11:30 +0000 | [diff] [blame] | 54 | #elif defined(__powerpc64__) |
| 55 | # define REGISTER_KIND Registers_ppc64 |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 56 | #elif defined(__ppc__) |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 57 | # define REGISTER_KIND Registers_ppc |
| 58 | #elif defined(__aarch64__) |
| 59 | # define REGISTER_KIND Registers_arm64 |
Martin Storsjo | 23a943b | 2017-11-02 08:16:16 +0000 | [diff] [blame] | 60 | #elif defined(__arm__) |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 61 | # define REGISTER_KIND Registers_arm |
Peter Zotov | d4255ab | 2015-08-31 05:26:37 +0000 | [diff] [blame] | 62 | #elif defined(__or1k__) |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 63 | # define REGISTER_KIND Registers_or1k |
John Baldwin | 375a366 | 2017-12-12 21:43:36 +0000 | [diff] [blame] | 64 | #elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float) |
| 65 | # define REGISTER_KIND Registers_mips_o32 |
| 66 | #elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float) |
John Baldwin | da0af18 | 2018-01-09 17:07:18 +0000 | [diff] [blame^] | 67 | # define REGISTER_KIND Registers_mips_newabi |
Vasileios Kalintiris | db1c263 | 2015-09-26 18:26:01 +0000 | [diff] [blame] | 68 | #elif defined(__mips__) |
John Baldwin | 375a366 | 2017-12-12 21:43:36 +0000 | [diff] [blame] | 69 | # warning The MIPS architecture is not supported with this ABI and environment! |
Ed Maste | 40377de | 2015-08-13 14:21:03 +0000 | [diff] [blame] | 70 | #else |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 71 | # error Architecture not supported |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 72 | #endif |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 73 | // Use "placement new" to allocate UnwindCursor in the cursor buffer. |
| 74 | new ((void *)cursor) UnwindCursor<LocalAddressSpace, REGISTER_KIND>( |
| 75 | context, LocalAddressSpace::sThisAddressSpace); |
| 76 | #undef REGISTER_KIND |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 77 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 78 | co->setInfoBasedOnIPRegister(); |
| 79 | |
| 80 | return UNW_ESUCCESS; |
| 81 | } |
| 82 | |
| 83 | #ifdef UNW_REMOTE |
| 84 | /// Create a cursor into a thread in another process. |
| 85 | _LIBUNWIND_EXPORT int unw_init_remote_thread(unw_cursor_t *cursor, |
| 86 | unw_addr_space_t as, |
| 87 | void *arg) { |
| 88 | // special case: unw_init_remote(xx, unw_local_addr_space, xx) |
| 89 | if (as == (unw_addr_space_t)&LocalAddressSpace::sThisAddressSpace) |
| 90 | return unw_init_local(cursor, NULL); //FIXME |
| 91 | |
| 92 | // use "placement new" to allocate UnwindCursor in the cursor buffer |
| 93 | switch (as->cpuType) { |
| 94 | case CPU_TYPE_I386: |
| 95 | new ((void *)cursor) |
Saleem Abdulrasool | fa05468 | 2017-01-21 16:22:46 +0000 | [diff] [blame] | 96 | UnwindCursor<RemoteAddressSpace<Pointer32<LittleEndian>>, |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 97 | Registers_x86>(((unw_addr_space_i386 *)as)->oas, arg); |
| 98 | break; |
| 99 | case CPU_TYPE_X86_64: |
Saleem Abdulrasool | fa05468 | 2017-01-21 16:22:46 +0000 | [diff] [blame] | 100 | new ((void *)cursor) |
| 101 | UnwindCursor<RemoteAddressSpace<Pointer64<LittleEndian>>, |
| 102 | Registers_x86_64>(((unw_addr_space_x86_64 *)as)->oas, arg); |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 103 | break; |
| 104 | case CPU_TYPE_POWERPC: |
| 105 | new ((void *)cursor) |
Saleem Abdulrasool | fa05468 | 2017-01-21 16:22:46 +0000 | [diff] [blame] | 106 | UnwindCursor<RemoteAddressSpace<Pointer32<BigEndian>>, |
| 107 | Registers_ppc>(((unw_addr_space_ppc *)as)->oas, arg); |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 108 | break; |
| 109 | default: |
| 110 | return UNW_EUNSPEC; |
| 111 | } |
| 112 | return UNW_ESUCCESS; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | static bool is64bit(task_t task) { |
| 117 | return false; // FIXME |
| 118 | } |
| 119 | |
| 120 | /// Create an address_space object for use in examining another task. |
| 121 | _LIBUNWIND_EXPORT unw_addr_space_t unw_create_addr_space_for_task(task_t task) { |
| 122 | #if __i386__ |
| 123 | if (is64bit(task)) { |
| 124 | unw_addr_space_x86_64 *as = new unw_addr_space_x86_64(task); |
| 125 | as->taskPort = task; |
| 126 | as->cpuType = CPU_TYPE_X86_64; |
| 127 | //as->oas |
| 128 | } else { |
| 129 | unw_addr_space_i386 *as = new unw_addr_space_i386(task); |
| 130 | as->taskPort = task; |
| 131 | as->cpuType = CPU_TYPE_I386; |
| 132 | //as->oas |
| 133 | } |
| 134 | #else |
| 135 | // FIXME |
| 136 | #endif |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /// Delete an address_space object. |
| 141 | _LIBUNWIND_EXPORT void unw_destroy_addr_space(unw_addr_space_t asp) { |
| 142 | switch (asp->cpuType) { |
| 143 | #if __i386__ || __x86_64__ |
| 144 | case CPU_TYPE_I386: { |
| 145 | unw_addr_space_i386 *as = (unw_addr_space_i386 *)asp; |
| 146 | delete as; |
| 147 | } |
| 148 | break; |
| 149 | case CPU_TYPE_X86_64: { |
| 150 | unw_addr_space_x86_64 *as = (unw_addr_space_x86_64 *)asp; |
| 151 | delete as; |
| 152 | } |
| 153 | break; |
| 154 | #endif |
| 155 | case CPU_TYPE_POWERPC: { |
| 156 | unw_addr_space_ppc *as = (unw_addr_space_ppc *)asp; |
| 157 | delete as; |
| 158 | } |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | #endif // UNW_REMOTE |
| 163 | |
| 164 | |
| 165 | /// Get value of specified register at cursor position in stack frame. |
| 166 | _LIBUNWIND_EXPORT int unw_get_reg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 167 | unw_word_t *value) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 168 | _LIBUNWIND_TRACE_API("unw_get_reg(cursor=%p, regNum=%d, &value=%p)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 169 | static_cast<void *>(cursor), regNum, |
| 170 | static_cast<void *>(value)); |
| 171 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 172 | if (co->validReg(regNum)) { |
| 173 | *value = co->getReg(regNum); |
| 174 | return UNW_ESUCCESS; |
| 175 | } |
| 176 | return UNW_EBADREG; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | /// Set value of specified register at cursor position in stack frame. |
| 181 | _LIBUNWIND_EXPORT int unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 182 | unw_word_t value) { |
Martin Storsjo | 85f4cfd | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 183 | _LIBUNWIND_TRACE_API("unw_set_reg(cursor=%p, regNum=%d, value=0x%" PRIxPTR ")", |
| 184 | static_cast<void *>(cursor), regNum, value); |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 185 | typedef LocalAddressSpace::pint_t pint_t; |
| 186 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 187 | if (co->validReg(regNum)) { |
| 188 | co->setReg(regNum, (pint_t)value); |
| 189 | // specical case altering IP to re-find info (being called by personality |
| 190 | // function) |
| 191 | if (regNum == UNW_REG_IP) |
| 192 | co->setInfoBasedOnIPRegister(false); |
| 193 | return UNW_ESUCCESS; |
| 194 | } |
| 195 | return UNW_EBADREG; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /// Get value of specified float register at cursor position in stack frame. |
| 200 | _LIBUNWIND_EXPORT int unw_get_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 201 | unw_fpreg_t *value) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 202 | _LIBUNWIND_TRACE_API("unw_get_fpreg(cursor=%p, regNum=%d, &value=%p)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 203 | static_cast<void *>(cursor), regNum, |
| 204 | static_cast<void *>(value)); |
| 205 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 206 | if (co->validFloatReg(regNum)) { |
| 207 | *value = co->getFloatReg(regNum); |
| 208 | return UNW_ESUCCESS; |
| 209 | } |
| 210 | return UNW_EBADREG; |
| 211 | } |
| 212 | |
| 213 | |
| 214 | /// Set value of specified float register at cursor position in stack frame. |
| 215 | _LIBUNWIND_EXPORT int unw_set_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum, |
| 216 | unw_fpreg_t value) { |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 217 | #if defined(_LIBUNWIND_ARM_EHABI) |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 218 | _LIBUNWIND_TRACE_API("unw_set_fpreg(cursor=%p, regNum=%d, value=%llX)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 219 | static_cast<void *>(cursor), regNum, value); |
| 220 | #else |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 221 | _LIBUNWIND_TRACE_API("unw_set_fpreg(cursor=%p, regNum=%d, value=%g)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 222 | static_cast<void *>(cursor), regNum, value); |
| 223 | #endif |
| 224 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 225 | if (co->validFloatReg(regNum)) { |
| 226 | co->setFloatReg(regNum, value); |
| 227 | return UNW_ESUCCESS; |
| 228 | } |
| 229 | return UNW_EBADREG; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /// Move cursor to next frame. |
| 234 | _LIBUNWIND_EXPORT int unw_step(unw_cursor_t *cursor) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 235 | _LIBUNWIND_TRACE_API("unw_step(cursor=%p)", static_cast<void *>(cursor)); |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 236 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 237 | return co->step(); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | /// Get unwind info at cursor position in stack frame. |
| 242 | _LIBUNWIND_EXPORT int unw_get_proc_info(unw_cursor_t *cursor, |
| 243 | unw_proc_info_t *info) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 244 | _LIBUNWIND_TRACE_API("unw_get_proc_info(cursor=%p, &info=%p)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 245 | static_cast<void *>(cursor), static_cast<void *>(info)); |
| 246 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 247 | co->getInfo(info); |
| 248 | if (info->end_ip == 0) |
| 249 | return UNW_ENOINFO; |
| 250 | else |
| 251 | return UNW_ESUCCESS; |
| 252 | } |
| 253 | |
| 254 | |
| 255 | /// Resume execution at cursor position (aka longjump). |
| 256 | _LIBUNWIND_EXPORT int unw_resume(unw_cursor_t *cursor) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 257 | _LIBUNWIND_TRACE_API("unw_resume(cursor=%p)", static_cast<void *>(cursor)); |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 258 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 259 | co->jumpto(); |
| 260 | return UNW_EUNSPEC; |
| 261 | } |
| 262 | |
| 263 | |
| 264 | /// Get name of function at cursor position in stack frame. |
| 265 | _LIBUNWIND_EXPORT int unw_get_proc_name(unw_cursor_t *cursor, char *buf, |
| 266 | size_t bufLen, unw_word_t *offset) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 267 | _LIBUNWIND_TRACE_API("unw_get_proc_name(cursor=%p, &buf=%p, bufLen=%lu)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 268 | static_cast<void *>(cursor), static_cast<void *>(buf), |
| 269 | static_cast<unsigned long>(bufLen)); |
| 270 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 271 | if (co->getFunctionName(buf, bufLen, offset)) |
| 272 | return UNW_ESUCCESS; |
| 273 | else |
| 274 | return UNW_EUNSPEC; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | /// Checks if a register is a floating-point register. |
| 279 | _LIBUNWIND_EXPORT int unw_is_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 280 | _LIBUNWIND_TRACE_API("unw_is_fpreg(cursor=%p, regNum=%d)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 281 | static_cast<void *>(cursor), regNum); |
| 282 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 283 | return co->validFloatReg(regNum); |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /// Checks if a register is a floating-point register. |
| 288 | _LIBUNWIND_EXPORT const char *unw_regname(unw_cursor_t *cursor, |
| 289 | unw_regnum_t regNum) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 290 | _LIBUNWIND_TRACE_API("unw_regname(cursor=%p, regNum=%d)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 291 | static_cast<void *>(cursor), regNum); |
| 292 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 293 | return co->getRegisterName(regNum); |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /// Checks if current frame is signal trampoline. |
| 298 | _LIBUNWIND_EXPORT int unw_is_signal_frame(unw_cursor_t *cursor) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 299 | _LIBUNWIND_TRACE_API("unw_is_signal_frame(cursor=%p)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 300 | static_cast<void *>(cursor)); |
| 301 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 302 | return co->isSignalFrame(); |
| 303 | } |
| 304 | |
| 305 | #ifdef __arm__ |
| 306 | // Save VFP registers d0-d15 using FSTMIADX instead of FSTMIADD |
| 307 | _LIBUNWIND_EXPORT void unw_save_vfp_as_X(unw_cursor_t *cursor) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 308 | _LIBUNWIND_TRACE_API("unw_fpreg_save_vfp_as_X(cursor=%p)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 309 | static_cast<void *>(cursor)); |
| 310 | AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; |
| 311 | return co->saveVFPAsX(); |
| 312 | } |
| 313 | #endif |
| 314 | |
| 315 | |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 316 | #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) |
Ed Maste | 63469ff | 2016-07-19 17:15:50 +0000 | [diff] [blame] | 317 | /// SPI: walks cached DWARF entries |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 318 | _LIBUNWIND_EXPORT void unw_iterate_dwarf_unwind_cache(void (*func)( |
| 319 | unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)) { |
Ed Maste | adc2908 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 320 | _LIBUNWIND_TRACE_API("unw_iterate_dwarf_unwind_cache(func=%p)", |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 321 | reinterpret_cast<void *>(func)); |
| 322 | DwarfFDECache<LocalAddressSpace>::iterateCacheEntries(func); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | /// IPI: for __register_frame() |
| 327 | void _unw_add_dynamic_fde(unw_word_t fde) { |
| 328 | CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo; |
| 329 | CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo; |
| 330 | const char *message = CFI_Parser<LocalAddressSpace>::decodeFDE( |
| 331 | LocalAddressSpace::sThisAddressSpace, |
| 332 | (LocalAddressSpace::pint_t) fde, &fdeInfo, &cieInfo); |
| 333 | if (message == NULL) { |
| 334 | // dynamically registered FDEs don't have a mach_header group they are in. |
| 335 | // Use fde as mh_group |
| 336 | unw_word_t mh_group = fdeInfo.fdeStart; |
| 337 | DwarfFDECache<LocalAddressSpace>::add((LocalAddressSpace::pint_t)mh_group, |
| 338 | fdeInfo.pcStart, fdeInfo.pcEnd, |
| 339 | fdeInfo.fdeStart); |
| 340 | } else { |
| 341 | _LIBUNWIND_DEBUG_LOG("_unw_add_dynamic_fde: bad fde: %s", message); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /// IPI: for __deregister_frame() |
| 346 | void _unw_remove_dynamic_fde(unw_word_t fde) { |
| 347 | // fde is own mh_group |
| 348 | DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde); |
| 349 | } |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 350 | #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) |
Martin Storsjo | e53dc3f | 2017-09-26 08:07:26 +0000 | [diff] [blame] | 351 | #endif // !defined(__USING_SJLJ_EXCEPTIONS__) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 352 | |
| 353 | |
| 354 | |
| 355 | // Add logging hooks in Debug builds only |
| 356 | #ifndef NDEBUG |
| 357 | #include <stdlib.h> |
| 358 | |
| 359 | _LIBUNWIND_HIDDEN |
| 360 | bool logAPIs() { |
| 361 | // do manual lock to avoid use of _cxa_guard_acquire or initializers |
| 362 | static bool checked = false; |
| 363 | static bool log = false; |
| 364 | if (!checked) { |
| 365 | log = (getenv("LIBUNWIND_PRINT_APIS") != NULL); |
| 366 | checked = true; |
| 367 | } |
| 368 | return log; |
| 369 | } |
| 370 | |
| 371 | _LIBUNWIND_HIDDEN |
| 372 | bool logUnwinding() { |
| 373 | // do manual lock to avoid use of _cxa_guard_acquire or initializers |
| 374 | static bool checked = false; |
| 375 | static bool log = false; |
| 376 | if (!checked) { |
| 377 | log = (getenv("LIBUNWIND_PRINT_UNWINDING") != NULL); |
| 378 | checked = true; |
| 379 | } |
| 380 | return log; |
| 381 | } |
| 382 | |
Saleem Abdulrasool | e1d4b2e | 2017-01-21 16:22:57 +0000 | [diff] [blame] | 383 | _LIBUNWIND_HIDDEN |
| 384 | bool logDWARF() { |
| 385 | // do manual lock to avoid use of _cxa_guard_acquire or initializers |
| 386 | static bool checked = false; |
| 387 | static bool log = false; |
| 388 | if (!checked) { |
| 389 | log = (getenv("LIBUNWIND_PRINT_DWARF") != NULL); |
| 390 | checked = true; |
| 391 | } |
| 392 | return log; |
| 393 | } |
| 394 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 395 | #endif // NDEBUG |
| 396 | |