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