blob: 21aa42680e5b7b0226a86d0a6d7bcbbc17614c30 [file] [log] [blame]
Louis Dionne7f068e52021-11-17 16:25:01 -05001//===----------------------------------------------------------------------===//
Saleem Abdulrasool17552662015-04-24 19:39:17 +00002//
Chandler Carruth61860a52019-01-19 10:56:40 +00003// 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 Abdulrasool17552662015-04-24 19:39:17 +00006//
7//
8// Implements unw_* functions from <libunwind.h>
9//
10//===----------------------------------------------------------------------===//
11
12#include <libunwind.h>
13
Saleem Abdulrasool17552662015-04-24 19:39:17 +000014#include "config.h"
gejin7f493162021-08-26 16:20:38 +080015#include "libunwind_ext.h"
Saleem Abdulrasool17552662015-04-24 19:39:17 +000016
17#include <stdlib.h>
18
Saleem Abdulrasool7e85c7a2021-06-13 14:28:43 -070019// Define the __has_feature extension for compilers that do not support it so
20// that we can later check for the presence of ASan in a compiler-neutral way.
21#if !defined(__has_feature)
22#define __has_feature(feature) 0
23#endif
24
25#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
Shoaib Meenaic8d0fb82021-05-23 20:41:57 -070026#include <sanitizer/asan_interface.h>
27#endif
Saleem Abdulrasool17552662015-04-24 19:39:17 +000028
Martin Storsjo9f16c6c2017-09-26 08:07:26 +000029#if !defined(__USING_SJLJ_EXCEPTIONS__)
Ed Schoutenedb76802017-03-09 08:04:07 +000030#include "AddressSpace.hpp"
Saleem Abdulrasool17552662015-04-24 19:39:17 +000031#include "UnwindCursor.hpp"
32
33using namespace libunwind;
34
35/// internal object to represent this processes address space
36LocalAddressSpace LocalAddressSpace::sThisAddressSpace;
37
38_LIBUNWIND_EXPORT unw_addr_space_t unw_local_addr_space =
39 (unw_addr_space_t)&LocalAddressSpace::sThisAddressSpace;
40
Saleem Abdulrasool17552662015-04-24 19:39:17 +000041/// Create a cursor of a thread in this process given 'context' recorded by
Petr Hosek9bbfad52019-04-03 21:50:03 +000042/// __unw_getcontext().
43_LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
44 unw_context_t *context) {
45 _LIBUNWIND_TRACE_API("__unw_init_local(cursor=%p, context=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +000046 static_cast<void *>(cursor),
47 static_cast<void *>(context));
Saleem Abdulrasool17552662015-04-24 19:39:17 +000048#if defined(__i386__)
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000049# define REGISTER_KIND Registers_x86
Saleem Abdulrasool17552662015-04-24 19:39:17 +000050#elif defined(__x86_64__)
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000051# define REGISTER_KIND Registers_x86_64
Martin Storsjo8338b0a2018-01-02 22:11:30 +000052#elif defined(__powerpc64__)
53# define REGISTER_KIND Registers_ppc64
Sam James72464132022-01-27 21:48:38 +000054#elif defined(__powerpc__)
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000055# define REGISTER_KIND Registers_ppc
56#elif defined(__aarch64__)
57# define REGISTER_KIND Registers_arm64
Martin Storsjoa72285f2017-11-02 08:16:16 +000058#elif defined(__arm__)
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000059# define REGISTER_KIND Registers_arm
Peter Zotov8d639992015-08-31 05:26:37 +000060#elif defined(__or1k__)
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000061# define REGISTER_KIND Registers_or1k
Brian Cainb432c472020-04-09 00:14:02 -050062#elif defined(__hexagon__)
63# define REGISTER_KIND Registers_hexagon
John Baldwin40300292018-05-15 22:44:56 +000064#elif defined(__mips__) && defined(_ABIO32) && _MIPS_SIM == _ABIO32
John Baldwin56441d42017-12-12 21:43:36 +000065# define REGISTER_KIND Registers_mips_o32
John Baldwin40300292018-05-15 22:44:56 +000066#elif defined(__mips64)
John Baldwin541a4352018-01-09 17:07:18 +000067# define REGISTER_KIND Registers_mips_newabi
Vasileios Kalintiris3bd271c2015-09-26 18:26:01 +000068#elif defined(__mips__)
John Baldwin56441d42017-12-12 21:43:36 +000069# warning The MIPS architecture is not supported with this ABI and environment!
Koakumaf2ef96e2022-02-05 13:08:26 -080070#elif defined(__sparc__) && defined(__arch64__)
71#define REGISTER_KIND Registers_sparc64
Daniel Cederman9f2f07a2019-01-14 10:15:20 +000072#elif defined(__sparc__)
73# define REGISTER_KIND Registers_sparc
Kamlesh Kumarf6ac3de2021-03-02 06:57:54 +053074#elif defined(__riscv)
Sam Elliott81f7e172019-12-16 16:35:17 +000075# define REGISTER_KIND Registers_riscv
Kazushi (Jam) Marukawa1fe8aef2020-12-26 22:50:17 +090076#elif defined(__ve__)
77# define REGISTER_KIND Registers_ve
Ed Maste846892c2015-08-13 14:21:03 +000078#else
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000079# error Architecture not supported
Saleem Abdulrasool17552662015-04-24 19:39:17 +000080#endif
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000081 // Use "placement new" to allocate UnwindCursor in the cursor buffer.
Petr Hosek36f61542019-02-02 21:15:49 +000082 new (reinterpret_cast<UnwindCursor<LocalAddressSpace, REGISTER_KIND> *>(cursor))
83 UnwindCursor<LocalAddressSpace, REGISTER_KIND>(
84 context, LocalAddressSpace::sThisAddressSpace);
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000085#undef REGISTER_KIND
Saleem Abdulrasool17552662015-04-24 19:39:17 +000086 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
87 co->setInfoBasedOnIPRegister();
88
89 return UNW_ESUCCESS;
90}
Petr Hosek9bbfad52019-04-03 21:50:03 +000091_LIBUNWIND_WEAK_ALIAS(__unw_init_local, unw_init_local)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000092
Saleem Abdulrasool17552662015-04-24 19:39:17 +000093/// Get value of specified register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +000094_LIBUNWIND_HIDDEN int __unw_get_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
95 unw_word_t *value) {
96 _LIBUNWIND_TRACE_API("__unw_get_reg(cursor=%p, regNum=%d, &value=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +000097 static_cast<void *>(cursor), regNum,
98 static_cast<void *>(value));
99 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
100 if (co->validReg(regNum)) {
101 *value = co->getReg(regNum);
102 return UNW_ESUCCESS;
103 }
104 return UNW_EBADREG;
105}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000106_LIBUNWIND_WEAK_ALIAS(__unw_get_reg, unw_get_reg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000107
108/// Set value of specified register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000109_LIBUNWIND_HIDDEN int __unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
110 unw_word_t value) {
111 _LIBUNWIND_TRACE_API("__unw_set_reg(cursor=%p, regNum=%d, value=0x%" PRIxPTR
112 ")",
Martin Storsjo97e2d982017-10-30 19:06:34 +0000113 static_cast<void *>(cursor), regNum, value);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000114 typedef LocalAddressSpace::pint_t pint_t;
115 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
116 if (co->validReg(regNum)) {
117 co->setReg(regNum, (pint_t)value);
118 // specical case altering IP to re-find info (being called by personality
119 // function)
Joerg Sonnenberger7ac54d32018-07-17 19:00:51 +0000120 if (regNum == UNW_REG_IP) {
121 unw_proc_info_t info;
122 // First, get the FDE for the old location and then update it.
123 co->getInfo(&info);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000124 co->setInfoBasedOnIPRegister(false);
Joerg Sonnenberger7ac54d32018-07-17 19:00:51 +0000125 // If the original call expects stack adjustment, perform this now.
126 // Normal frame unwinding would have included the offset already in the
127 // CFA computation.
128 // Note: for PA-RISC and other platforms where the stack grows up,
129 // this should actually be - info.gp. LLVM doesn't currently support
130 // any such platforms and Clang doesn't export a macro for them.
131 if (info.gp)
132 co->setReg(UNW_REG_SP, co->getReg(UNW_REG_SP) + info.gp);
133 }
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000134 return UNW_ESUCCESS;
135 }
136 return UNW_EBADREG;
137}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000138_LIBUNWIND_WEAK_ALIAS(__unw_set_reg, unw_set_reg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000139
140/// Get value of specified float register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000141_LIBUNWIND_HIDDEN int __unw_get_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum,
142 unw_fpreg_t *value) {
143 _LIBUNWIND_TRACE_API("__unw_get_fpreg(cursor=%p, regNum=%d, &value=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000144 static_cast<void *>(cursor), regNum,
145 static_cast<void *>(value));
146 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
147 if (co->validFloatReg(regNum)) {
148 *value = co->getFloatReg(regNum);
149 return UNW_ESUCCESS;
150 }
151 return UNW_EBADREG;
152}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000153_LIBUNWIND_WEAK_ALIAS(__unw_get_fpreg, unw_get_fpreg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000154
155/// Set value of specified float register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000156_LIBUNWIND_HIDDEN int __unw_set_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum,
157 unw_fpreg_t value) {
Ranjeet Singh421231a2017-03-31 15:28:06 +0000158#if defined(_LIBUNWIND_ARM_EHABI)
Petr Hosek9bbfad52019-04-03 21:50:03 +0000159 _LIBUNWIND_TRACE_API("__unw_set_fpreg(cursor=%p, regNum=%d, value=%llX)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000160 static_cast<void *>(cursor), regNum, value);
161#else
Petr Hosek9bbfad52019-04-03 21:50:03 +0000162 _LIBUNWIND_TRACE_API("__unw_set_fpreg(cursor=%p, regNum=%d, value=%g)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000163 static_cast<void *>(cursor), regNum, value);
164#endif
165 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
166 if (co->validFloatReg(regNum)) {
167 co->setFloatReg(regNum, value);
168 return UNW_ESUCCESS;
169 }
170 return UNW_EBADREG;
171}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000172_LIBUNWIND_WEAK_ALIAS(__unw_set_fpreg, unw_set_fpreg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000173
174/// Move cursor to next frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000175_LIBUNWIND_HIDDEN int __unw_step(unw_cursor_t *cursor) {
176 _LIBUNWIND_TRACE_API("__unw_step(cursor=%p)", static_cast<void *>(cursor));
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000177 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
178 return co->step();
179}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000180_LIBUNWIND_WEAK_ALIAS(__unw_step, unw_step)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000181
182/// Get unwind info at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000183_LIBUNWIND_HIDDEN int __unw_get_proc_info(unw_cursor_t *cursor,
184 unw_proc_info_t *info) {
185 _LIBUNWIND_TRACE_API("__unw_get_proc_info(cursor=%p, &info=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000186 static_cast<void *>(cursor), static_cast<void *>(info));
187 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
188 co->getInfo(info);
189 if (info->end_ip == 0)
190 return UNW_ENOINFO;
Saleem Abdulrasool2aa34a82019-09-18 16:15:56 +0000191 return UNW_ESUCCESS;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000192}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000193_LIBUNWIND_WEAK_ALIAS(__unw_get_proc_info, unw_get_proc_info)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000194
195/// Resume execution at cursor position (aka longjump).
Petr Hosek9bbfad52019-04-03 21:50:03 +0000196_LIBUNWIND_HIDDEN int __unw_resume(unw_cursor_t *cursor) {
197 _LIBUNWIND_TRACE_API("__unw_resume(cursor=%p)", static_cast<void *>(cursor));
Saleem Abdulrasool7e85c7a2021-06-13 14:28:43 -0700198#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
Shoaib Meenaic8d0fb82021-05-23 20:41:57 -0700199 // Inform the ASan runtime that now might be a good time to clean stuff up.
200 __asan_handle_no_return();
201#endif
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000202 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
203 co->jumpto();
204 return UNW_EUNSPEC;
205}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000206_LIBUNWIND_WEAK_ALIAS(__unw_resume, unw_resume)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000207
208/// Get name of function at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000209_LIBUNWIND_HIDDEN int __unw_get_proc_name(unw_cursor_t *cursor, char *buf,
210 size_t bufLen, unw_word_t *offset) {
211 _LIBUNWIND_TRACE_API("__unw_get_proc_name(cursor=%p, &buf=%p, bufLen=%lu)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000212 static_cast<void *>(cursor), static_cast<void *>(buf),
213 static_cast<unsigned long>(bufLen));
214 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
215 if (co->getFunctionName(buf, bufLen, offset))
216 return UNW_ESUCCESS;
Saleem Abdulrasool2aa34a82019-09-18 16:15:56 +0000217 return UNW_EUNSPEC;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000218}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000219_LIBUNWIND_WEAK_ALIAS(__unw_get_proc_name, unw_get_proc_name)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000220
221/// Checks if a register is a floating-point register.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000222_LIBUNWIND_HIDDEN int __unw_is_fpreg(unw_cursor_t *cursor,
223 unw_regnum_t regNum) {
224 _LIBUNWIND_TRACE_API("__unw_is_fpreg(cursor=%p, regNum=%d)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000225 static_cast<void *>(cursor), regNum);
226 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
227 return co->validFloatReg(regNum);
228}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000229_LIBUNWIND_WEAK_ALIAS(__unw_is_fpreg, unw_is_fpreg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000230
231/// Checks if a register is a floating-point register.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000232_LIBUNWIND_HIDDEN const char *__unw_regname(unw_cursor_t *cursor,
233 unw_regnum_t regNum) {
234 _LIBUNWIND_TRACE_API("__unw_regname(cursor=%p, regNum=%d)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000235 static_cast<void *>(cursor), regNum);
236 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
237 return co->getRegisterName(regNum);
238}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000239_LIBUNWIND_WEAK_ALIAS(__unw_regname, unw_regname)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000240
241/// Checks if current frame is signal trampoline.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000242_LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) {
243 _LIBUNWIND_TRACE_API("__unw_is_signal_frame(cursor=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000244 static_cast<void *>(cursor));
245 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
246 return co->isSignalFrame();
247}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000248_LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000249
Xing Xuebbcbce92022-04-13 11:01:59 -0400250#ifdef _AIX
251_LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) {
252 _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)",
253 static_cast<void *>(cursor));
254 AbstractUnwindCursor *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
255 return co->getDataRelBase();
256}
257_LIBUNWIND_WEAK_ALIAS(__unw_get_data_rel_base, unw_get_data_rel_base)
258#endif
259
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000260#ifdef __arm__
261// Save VFP registers d0-d15 using FSTMIADX instead of FSTMIADD
Petr Hosek9bbfad52019-04-03 21:50:03 +0000262_LIBUNWIND_HIDDEN void __unw_save_vfp_as_X(unw_cursor_t *cursor) {
263 _LIBUNWIND_TRACE_API("__unw_get_fpreg_save_vfp_as_X(cursor=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000264 static_cast<void *>(cursor));
265 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
266 return co->saveVFPAsX();
267}
Petr Hosek01fc4132019-04-11 13:08:44 +0000268_LIBUNWIND_WEAK_ALIAS(__unw_save_vfp_as_X, unw_save_vfp_as_X)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000269#endif
270
271
Ranjeet Singh421231a2017-03-31 15:28:06 +0000272#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
Ed Maste4c43c3d2016-07-19 17:15:50 +0000273/// SPI: walks cached DWARF entries
Petr Hosek9bbfad52019-04-03 21:50:03 +0000274_LIBUNWIND_HIDDEN void __unw_iterate_dwarf_unwind_cache(void (*func)(
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000275 unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)) {
Petr Hosek9bbfad52019-04-03 21:50:03 +0000276 _LIBUNWIND_TRACE_API("__unw_iterate_dwarf_unwind_cache(func=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000277 reinterpret_cast<void *>(func));
278 DwarfFDECache<LocalAddressSpace>::iterateCacheEntries(func);
279}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000280_LIBUNWIND_WEAK_ALIAS(__unw_iterate_dwarf_unwind_cache,
281 unw_iterate_dwarf_unwind_cache)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000282
283/// IPI: for __register_frame()
Petr Hosek9bbfad52019-04-03 21:50:03 +0000284void __unw_add_dynamic_fde(unw_word_t fde) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000285 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
286 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
287 const char *message = CFI_Parser<LocalAddressSpace>::decodeFDE(
288 LocalAddressSpace::sThisAddressSpace,
289 (LocalAddressSpace::pint_t) fde, &fdeInfo, &cieInfo);
290 if (message == NULL) {
291 // dynamically registered FDEs don't have a mach_header group they are in.
292 // Use fde as mh_group
293 unw_word_t mh_group = fdeInfo.fdeStart;
294 DwarfFDECache<LocalAddressSpace>::add((LocalAddressSpace::pint_t)mh_group,
295 fdeInfo.pcStart, fdeInfo.pcEnd,
296 fdeInfo.fdeStart);
297 } else {
Petr Hosek9bbfad52019-04-03 21:50:03 +0000298 _LIBUNWIND_DEBUG_LOG("__unw_add_dynamic_fde: bad fde: %s", message);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000299 }
300}
301
302/// IPI: for __deregister_frame()
Petr Hosek9bbfad52019-04-03 21:50:03 +0000303void __unw_remove_dynamic_fde(unw_word_t fde) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000304 // fde is own mh_group
305 DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde);
306}
Peter S. Housel038090f2021-10-14 13:31:05 -0700307
308void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
309 // The eh_frame section start serves as the mh_group
310 unw_word_t mh_group = eh_frame_start;
311 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
312 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
313 auto p = (LocalAddressSpace::pint_t)eh_frame_start;
314 while (true) {
315 if (CFI_Parser<LocalAddressSpace>::decodeFDE(
316 LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
317 true) == NULL) {
318 DwarfFDECache<LocalAddressSpace>::add((LocalAddressSpace::pint_t)mh_group,
319 fdeInfo.pcStart, fdeInfo.pcEnd,
320 fdeInfo.fdeStart);
321 p += fdeInfo.fdeLength;
322 } else if (CFI_Parser<LocalAddressSpace>::parseCIE(
323 LocalAddressSpace::sThisAddressSpace, p, &cieInfo) == NULL) {
324 p += cieInfo.cieLength;
325 } else
326 return;
327 }
328}
329
330void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
331 // The eh_frame section start serves as the mh_group
332 DwarfFDECache<LocalAddressSpace>::removeAllIn(
333 (LocalAddressSpace::pint_t)eh_frame_start);
334}
335
Ranjeet Singh421231a2017-03-31 15:28:06 +0000336#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
Martin Storsjo9f16c6c2017-09-26 08:07:26 +0000337#endif // !defined(__USING_SJLJ_EXCEPTIONS__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000338
339
340
341// Add logging hooks in Debug builds only
342#ifndef NDEBUG
343#include <stdlib.h>
344
345_LIBUNWIND_HIDDEN
346bool logAPIs() {
347 // do manual lock to avoid use of _cxa_guard_acquire or initializers
348 static bool checked = false;
349 static bool log = false;
350 if (!checked) {
351 log = (getenv("LIBUNWIND_PRINT_APIS") != NULL);
352 checked = true;
353 }
354 return log;
355}
356
357_LIBUNWIND_HIDDEN
358bool logUnwinding() {
359 // do manual lock to avoid use of _cxa_guard_acquire or initializers
360 static bool checked = false;
361 static bool log = false;
362 if (!checked) {
363 log = (getenv("LIBUNWIND_PRINT_UNWINDING") != NULL);
364 checked = true;
365 }
366 return log;
367}
368
Saleem Abdulrasoold1be5b02017-01-21 16:22:57 +0000369_LIBUNWIND_HIDDEN
370bool logDWARF() {
371 // do manual lock to avoid use of _cxa_guard_acquire or initializers
372 static bool checked = false;
373 static bool log = false;
374 if (!checked) {
375 log = (getenv("LIBUNWIND_PRINT_DWARF") != NULL);
376 checked = true;
377 }
378 return log;
379}
380
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000381#endif // NDEBUG
382