blob: 292544d91429334e042ccaff805c9aee884f3782 [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
Ulrich Weigand393e3ee2022-05-02 14:35:29 +020078#elif defined(__s390x__)
79# define REGISTER_KIND Registers_s390x
Ed Maste846892c2015-08-13 14:21:03 +000080#else
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000081# error Architecture not supported
Saleem Abdulrasool17552662015-04-24 19:39:17 +000082#endif
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000083 // Use "placement new" to allocate UnwindCursor in the cursor buffer.
Petr Hosek36f61542019-02-02 21:15:49 +000084 new (reinterpret_cast<UnwindCursor<LocalAddressSpace, REGISTER_KIND> *>(cursor))
85 UnwindCursor<LocalAddressSpace, REGISTER_KIND>(
86 context, LocalAddressSpace::sThisAddressSpace);
Asiri Rathnayakec00dcef2016-05-25 12:36:34 +000087#undef REGISTER_KIND
Saleem Abdulrasool17552662015-04-24 19:39:17 +000088 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
89 co->setInfoBasedOnIPRegister();
90
91 return UNW_ESUCCESS;
92}
Petr Hosek9bbfad52019-04-03 21:50:03 +000093_LIBUNWIND_WEAK_ALIAS(__unw_init_local, unw_init_local)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000094
Saleem Abdulrasool17552662015-04-24 19:39:17 +000095/// Get value of specified register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +000096_LIBUNWIND_HIDDEN int __unw_get_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
97 unw_word_t *value) {
98 _LIBUNWIND_TRACE_API("__unw_get_reg(cursor=%p, regNum=%d, &value=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +000099 static_cast<void *>(cursor), regNum,
100 static_cast<void *>(value));
101 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
102 if (co->validReg(regNum)) {
103 *value = co->getReg(regNum);
104 return UNW_ESUCCESS;
105 }
106 return UNW_EBADREG;
107}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000108_LIBUNWIND_WEAK_ALIAS(__unw_get_reg, unw_get_reg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000109
110/// Set value of specified register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000111_LIBUNWIND_HIDDEN int __unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
112 unw_word_t value) {
113 _LIBUNWIND_TRACE_API("__unw_set_reg(cursor=%p, regNum=%d, value=0x%" PRIxPTR
114 ")",
Martin Storsjo97e2d982017-10-30 19:06:34 +0000115 static_cast<void *>(cursor), regNum, value);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000116 typedef LocalAddressSpace::pint_t pint_t;
117 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
118 if (co->validReg(regNum)) {
119 co->setReg(regNum, (pint_t)value);
Gabriel Ravier42aa6de2022-08-20 18:09:03 -0700120 // special case altering IP to re-find info (being called by personality
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000121 // function)
Joerg Sonnenberger7ac54d32018-07-17 19:00:51 +0000122 if (regNum == UNW_REG_IP) {
123 unw_proc_info_t info;
124 // First, get the FDE for the old location and then update it.
125 co->getInfo(&info);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000126 co->setInfoBasedOnIPRegister(false);
Joerg Sonnenberger7ac54d32018-07-17 19:00:51 +0000127 // If the original call expects stack adjustment, perform this now.
128 // Normal frame unwinding would have included the offset already in the
129 // CFA computation.
130 // Note: for PA-RISC and other platforms where the stack grows up,
131 // this should actually be - info.gp. LLVM doesn't currently support
132 // any such platforms and Clang doesn't export a macro for them.
133 if (info.gp)
134 co->setReg(UNW_REG_SP, co->getReg(UNW_REG_SP) + info.gp);
135 }
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000136 return UNW_ESUCCESS;
137 }
138 return UNW_EBADREG;
139}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000140_LIBUNWIND_WEAK_ALIAS(__unw_set_reg, unw_set_reg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000141
142/// Get value of specified float register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000143_LIBUNWIND_HIDDEN int __unw_get_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum,
144 unw_fpreg_t *value) {
145 _LIBUNWIND_TRACE_API("__unw_get_fpreg(cursor=%p, regNum=%d, &value=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000146 static_cast<void *>(cursor), regNum,
147 static_cast<void *>(value));
148 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
149 if (co->validFloatReg(regNum)) {
150 *value = co->getFloatReg(regNum);
151 return UNW_ESUCCESS;
152 }
153 return UNW_EBADREG;
154}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000155_LIBUNWIND_WEAK_ALIAS(__unw_get_fpreg, unw_get_fpreg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000156
157/// Set value of specified float register at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000158_LIBUNWIND_HIDDEN int __unw_set_fpreg(unw_cursor_t *cursor, unw_regnum_t regNum,
159 unw_fpreg_t value) {
Ranjeet Singh421231a2017-03-31 15:28:06 +0000160#if defined(_LIBUNWIND_ARM_EHABI)
Petr Hosek9bbfad52019-04-03 21:50:03 +0000161 _LIBUNWIND_TRACE_API("__unw_set_fpreg(cursor=%p, regNum=%d, value=%llX)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000162 static_cast<void *>(cursor), regNum, value);
163#else
Petr Hosek9bbfad52019-04-03 21:50:03 +0000164 _LIBUNWIND_TRACE_API("__unw_set_fpreg(cursor=%p, regNum=%d, value=%g)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000165 static_cast<void *>(cursor), regNum, value);
166#endif
167 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
168 if (co->validFloatReg(regNum)) {
169 co->setFloatReg(regNum, value);
170 return UNW_ESUCCESS;
171 }
172 return UNW_EBADREG;
173}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000174_LIBUNWIND_WEAK_ALIAS(__unw_set_fpreg, unw_set_fpreg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000175
176/// Move cursor to next frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000177_LIBUNWIND_HIDDEN int __unw_step(unw_cursor_t *cursor) {
178 _LIBUNWIND_TRACE_API("__unw_step(cursor=%p)", static_cast<void *>(cursor));
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000179 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
180 return co->step();
181}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000182_LIBUNWIND_WEAK_ALIAS(__unw_step, unw_step)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000183
Florian Mayer7ff728a2022-06-03 14:33:08 -0700184// Move cursor to next frame and for stage2 of unwinding.
185// This resets MTE tags of tagged frames to zero.
186extern "C" _LIBUNWIND_HIDDEN int __unw_step_stage2(unw_cursor_t *cursor) {
187 _LIBUNWIND_TRACE_API("__unw_step_stage2(cursor=%p)",
188 static_cast<void *>(cursor));
189 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
190 return co->step(true);
191}
192
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000193/// Get unwind info at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000194_LIBUNWIND_HIDDEN int __unw_get_proc_info(unw_cursor_t *cursor,
195 unw_proc_info_t *info) {
196 _LIBUNWIND_TRACE_API("__unw_get_proc_info(cursor=%p, &info=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000197 static_cast<void *>(cursor), static_cast<void *>(info));
198 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
199 co->getInfo(info);
200 if (info->end_ip == 0)
201 return UNW_ENOINFO;
Saleem Abdulrasool2aa34a82019-09-18 16:15:56 +0000202 return UNW_ESUCCESS;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000203}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000204_LIBUNWIND_WEAK_ALIAS(__unw_get_proc_info, unw_get_proc_info)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000205
206/// Resume execution at cursor position (aka longjump).
Petr Hosek9bbfad52019-04-03 21:50:03 +0000207_LIBUNWIND_HIDDEN int __unw_resume(unw_cursor_t *cursor) {
208 _LIBUNWIND_TRACE_API("__unw_resume(cursor=%p)", static_cast<void *>(cursor));
Saleem Abdulrasool7e85c7a2021-06-13 14:28:43 -0700209#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
Shoaib Meenaic8d0fb82021-05-23 20:41:57 -0700210 // Inform the ASan runtime that now might be a good time to clean stuff up.
211 __asan_handle_no_return();
212#endif
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000213 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
214 co->jumpto();
215 return UNW_EUNSPEC;
216}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000217_LIBUNWIND_WEAK_ALIAS(__unw_resume, unw_resume)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000218
219/// Get name of function at cursor position in stack frame.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000220_LIBUNWIND_HIDDEN int __unw_get_proc_name(unw_cursor_t *cursor, char *buf,
221 size_t bufLen, unw_word_t *offset) {
222 _LIBUNWIND_TRACE_API("__unw_get_proc_name(cursor=%p, &buf=%p, bufLen=%lu)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000223 static_cast<void *>(cursor), static_cast<void *>(buf),
224 static_cast<unsigned long>(bufLen));
225 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
226 if (co->getFunctionName(buf, bufLen, offset))
227 return UNW_ESUCCESS;
Saleem Abdulrasool2aa34a82019-09-18 16:15:56 +0000228 return UNW_EUNSPEC;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000229}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000230_LIBUNWIND_WEAK_ALIAS(__unw_get_proc_name, unw_get_proc_name)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000231
232/// Checks if a register is a floating-point register.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000233_LIBUNWIND_HIDDEN int __unw_is_fpreg(unw_cursor_t *cursor,
234 unw_regnum_t regNum) {
235 _LIBUNWIND_TRACE_API("__unw_is_fpreg(cursor=%p, regNum=%d)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000236 static_cast<void *>(cursor), regNum);
237 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
238 return co->validFloatReg(regNum);
239}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000240_LIBUNWIND_WEAK_ALIAS(__unw_is_fpreg, unw_is_fpreg)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000241
242/// Checks if a register is a floating-point register.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000243_LIBUNWIND_HIDDEN const char *__unw_regname(unw_cursor_t *cursor,
244 unw_regnum_t regNum) {
245 _LIBUNWIND_TRACE_API("__unw_regname(cursor=%p, regNum=%d)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000246 static_cast<void *>(cursor), regNum);
247 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
248 return co->getRegisterName(regNum);
249}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000250_LIBUNWIND_WEAK_ALIAS(__unw_regname, unw_regname)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000251
252/// Checks if current frame is signal trampoline.
Petr Hosek9bbfad52019-04-03 21:50:03 +0000253_LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) {
254 _LIBUNWIND_TRACE_API("__unw_is_signal_frame(cursor=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000255 static_cast<void *>(cursor));
256 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
257 return co->isSignalFrame();
258}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000259_LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000260
Xing Xuebbcbce92022-04-13 11:01:59 -0400261#ifdef _AIX
262_LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) {
263 _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)",
264 static_cast<void *>(cursor));
265 AbstractUnwindCursor *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
266 return co->getDataRelBase();
267}
268_LIBUNWIND_WEAK_ALIAS(__unw_get_data_rel_base, unw_get_data_rel_base)
269#endif
270
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000271#ifdef __arm__
272// Save VFP registers d0-d15 using FSTMIADX instead of FSTMIADD
Petr Hosek9bbfad52019-04-03 21:50:03 +0000273_LIBUNWIND_HIDDEN void __unw_save_vfp_as_X(unw_cursor_t *cursor) {
274 _LIBUNWIND_TRACE_API("__unw_get_fpreg_save_vfp_as_X(cursor=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000275 static_cast<void *>(cursor));
276 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
277 return co->saveVFPAsX();
278}
Petr Hosek01fc4132019-04-11 13:08:44 +0000279_LIBUNWIND_WEAK_ALIAS(__unw_save_vfp_as_X, unw_save_vfp_as_X)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000280#endif
281
282
Ranjeet Singh421231a2017-03-31 15:28:06 +0000283#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
Ed Maste4c43c3d2016-07-19 17:15:50 +0000284/// SPI: walks cached DWARF entries
Petr Hosek9bbfad52019-04-03 21:50:03 +0000285_LIBUNWIND_HIDDEN void __unw_iterate_dwarf_unwind_cache(void (*func)(
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000286 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 +0000287 _LIBUNWIND_TRACE_API("__unw_iterate_dwarf_unwind_cache(func=%p)",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000288 reinterpret_cast<void *>(func));
289 DwarfFDECache<LocalAddressSpace>::iterateCacheEntries(func);
290}
Petr Hosek9bbfad52019-04-03 21:50:03 +0000291_LIBUNWIND_WEAK_ALIAS(__unw_iterate_dwarf_unwind_cache,
292 unw_iterate_dwarf_unwind_cache)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000293
294/// IPI: for __register_frame()
Petr Hosek9bbfad52019-04-03 21:50:03 +0000295void __unw_add_dynamic_fde(unw_word_t fde) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000296 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
297 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
298 const char *message = CFI_Parser<LocalAddressSpace>::decodeFDE(
299 LocalAddressSpace::sThisAddressSpace,
300 (LocalAddressSpace::pint_t) fde, &fdeInfo, &cieInfo);
301 if (message == NULL) {
302 // dynamically registered FDEs don't have a mach_header group they are in.
303 // Use fde as mh_group
304 unw_word_t mh_group = fdeInfo.fdeStart;
305 DwarfFDECache<LocalAddressSpace>::add((LocalAddressSpace::pint_t)mh_group,
306 fdeInfo.pcStart, fdeInfo.pcEnd,
307 fdeInfo.fdeStart);
308 } else {
Petr Hosek9bbfad52019-04-03 21:50:03 +0000309 _LIBUNWIND_DEBUG_LOG("__unw_add_dynamic_fde: bad fde: %s", message);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000310 }
311}
312
313/// IPI: for __deregister_frame()
Petr Hosek9bbfad52019-04-03 21:50:03 +0000314void __unw_remove_dynamic_fde(unw_word_t fde) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000315 // fde is own mh_group
316 DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde);
317}
Peter S. Housel038090f2021-10-14 13:31:05 -0700318
319void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
320 // The eh_frame section start serves as the mh_group
321 unw_word_t mh_group = eh_frame_start;
322 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
323 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
324 auto p = (LocalAddressSpace::pint_t)eh_frame_start;
325 while (true) {
326 if (CFI_Parser<LocalAddressSpace>::decodeFDE(
327 LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
328 true) == NULL) {
329 DwarfFDECache<LocalAddressSpace>::add((LocalAddressSpace::pint_t)mh_group,
330 fdeInfo.pcStart, fdeInfo.pcEnd,
331 fdeInfo.fdeStart);
332 p += fdeInfo.fdeLength;
333 } else if (CFI_Parser<LocalAddressSpace>::parseCIE(
334 LocalAddressSpace::sThisAddressSpace, p, &cieInfo) == NULL) {
335 p += cieInfo.cieLength;
336 } else
337 return;
338 }
339}
340
341void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
342 // The eh_frame section start serves as the mh_group
343 DwarfFDECache<LocalAddressSpace>::removeAllIn(
344 (LocalAddressSpace::pint_t)eh_frame_start);
345}
346
Ranjeet Singh421231a2017-03-31 15:28:06 +0000347#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
Martin Storsjo9f16c6c2017-09-26 08:07:26 +0000348#endif // !defined(__USING_SJLJ_EXCEPTIONS__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000349
350
351
352// Add logging hooks in Debug builds only
353#ifndef NDEBUG
354#include <stdlib.h>
355
356_LIBUNWIND_HIDDEN
357bool logAPIs() {
358 // do manual lock to avoid use of _cxa_guard_acquire or initializers
359 static bool checked = false;
360 static bool log = false;
361 if (!checked) {
362 log = (getenv("LIBUNWIND_PRINT_APIS") != NULL);
363 checked = true;
364 }
365 return log;
366}
367
368_LIBUNWIND_HIDDEN
369bool logUnwinding() {
370 // do manual lock to avoid use of _cxa_guard_acquire or initializers
371 static bool checked = false;
372 static bool log = false;
373 if (!checked) {
374 log = (getenv("LIBUNWIND_PRINT_UNWINDING") != NULL);
375 checked = true;
376 }
377 return log;
378}
379
Saleem Abdulrasoold1be5b02017-01-21 16:22:57 +0000380_LIBUNWIND_HIDDEN
381bool logDWARF() {
382 // do manual lock to avoid use of _cxa_guard_acquire or initializers
383 static bool checked = false;
384 static bool log = false;
385 if (!checked) {
386 log = (getenv("LIBUNWIND_PRINT_DWARF") != NULL);
387 checked = true;
388 }
389 return log;
390}
391
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000392#endif // NDEBUG
393