annotate libunwind/src/libunwind.cpp @ 207:2e18cbf3894f

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