1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #define HILOG_TAG "CallStack"
16
17 #include "call_stack.h"
18
19 #include <string>
20 #if HAVE_LIBUNWIND
21 #include <libunwind.h>
22 extern "C" {
23 #include <libunwind_i.h>
24 }
25 #endif
26
27 #include "register.h"
28 #ifdef target_cpu_arm
29 // reg size is int (unw_word_t)
30 #define UNW_WORD_PFLAG "x"
31 #else
32 // reg size is long (unw_word_t)
33 #define UNW_WORD_PFLAG "zx"
34 #endif
35 namespace OHOS {
36 namespace Developtools {
37 namespace NativeDaemon {
38 #if HAVE_LIBUNWIND
39 const std::map<unw_error_t, const std::string> UNW_ERROR_MAP = {
40 {UNW_ESUCCESS, std::to_string(UNW_ESUCCESS)},
41 {UNW_EUNSPEC, std::to_string(UNW_EUNSPEC)},
42 {UNW_ENOMEM, std::to_string(UNW_ENOMEM)},
43 {UNW_EBADREG, std::to_string(UNW_EBADREG)},
44 {UNW_EREADONLYREG, std::to_string(UNW_EREADONLYREG)},
45 {UNW_ESTOPUNWIND, std::to_string(UNW_ESTOPUNWIND)},
46 {UNW_EINVALIDIP, std::to_string(UNW_EINVALIDIP)},
47 {UNW_EBADFRAME, std::to_string(UNW_EBADFRAME)},
48 {UNW_EINVAL, std::to_string(UNW_EINVAL)},
49 {UNW_EBADVERSION, std::to_string(UNW_EBADVERSION)},
50 {UNW_ENOINFO, std::to_string(UNW_ENOINFO)},
51 };
GetUnwErrorName(int error)52 const std::string CallStack::GetUnwErrorName(int error)
53 {
54 if (UNW_ERROR_MAP.count(static_cast<unw_error_t>(-error)) > 0) {
55 return UNW_ERROR_MAP.at(static_cast<unw_error_t>(-error));
56 } else {
57 return "UNKNOW_UNW_ERROR";
58 }
59 }
60
dumpUDI(unw_dyn_info_t & di)61 void CallStack::dumpUDI(unw_dyn_info_t &di)
62 {
63 HLOGV("unwind_table info: ");
64 HLOGV(" di.start_ip: 0x%016" UNW_WORD_PFLAG "", di.start_ip);
65 HLOGV(" di.end_ip: 0x%016" UNW_WORD_PFLAG "", di.end_ip);
66 HLOGV(" di.u.rti.segbase: 0x%016" UNW_WORD_PFLAG "", di.u.rti.segbase);
67 HLOGV(" di.u.rti.table_data: 0x%016" UNW_WORD_PFLAG "", di.u.rti.table_data);
68 HLOGV(" di.u.rti.table_len: 0x%016" UNW_WORD_PFLAG "", di.u.rti.table_len);
69 }
70
fillUDI(unw_dyn_info_t & di,SymbolsFile & symbolsFile,const MemMapItem & mmap,const VirtualThread & thread)71 bool CallStack::fillUDI(unw_dyn_info_t &di, SymbolsFile &symbolsFile, const MemMapItem &mmap,
72 const VirtualThread &thread)
73 {
74 uint64_t fdeTableElfOffset = 0;
75 uint64_t fdeTableSize = 0;
76 uint64_t ehFrameHdrElfOffset = 0;
77 uint64_t SectionVaddr = 0;
78 uint64_t SectionSize = 0;
79 uint64_t SectionFileOffset = 0;
80 di.start_ip = mmap.begin_;
81 di.end_ip = mmap.end_;
82 #ifndef target_cpu_arm
83 if ((UNW_INFO_FORMAT_REMOTE_TABLE == di.format) &&
84 symbolsFile.GetHDRSectionInfo(ehFrameHdrElfOffset, fdeTableElfOffset, fdeTableSize)) {
85 /*
86 unw_word_t name_ptr; // addr. of table name (e.g., library name)
87 unw_word_t segbase; // segment base
88 unw_word_t table_len; // must be a multiple of sizeof(unw_word_t)!
89 unw_word_t table_data;
90 */
91 /*
92 all the rti addr is offset of the elf file
93 begin - page offset = elf file base addr in vaddr user space
94 begin - page offset + elf offset = vaddr in real word.(for this thread)
95 */
96
97 // segbase is file offset .
98 /*
99 00200000-00344000 r--p 00000000 08:02 46404365
100 00344000-005c4000 r-xp 00143000 08:02 46404365
101
102 LOAD 0x00000000001439c0 0x00000000003449c0 0x00000000003449c0
103 0x000000000027f3c0 0x000000000027f3c0 R E 0x1000
104
105 GNU_EH_FRAME 0x00000000000f3248 0x00000000002f3248 0x00000000002f3248
106 0x000000000000bb04 0x000000000000bb04 R 0x4
107
108 */
109 const MemMapItem *ehFrameMmap = thread.FindMapByFileInfo(mmap.name_, ehFrameHdrElfOffset);
110
111 CHECK_NOTNULL(ehFrameMmap, false, "no ehframe mmap found.");
112
113 di.u.rti.segbase = ehFrameMmap->begin_ + ehFrameHdrElfOffset - ehFrameMmap->pageoffset_;
114 di.u.rti.table_data = ehFrameMmap->begin_ + fdeTableElfOffset - ehFrameMmap->pageoffset_;
115 di.u.rti.table_len = fdeTableSize / sizeof(unw_word_t);
116
117 HLOGV(" map pageoffset: 0x%016" PRIx64 "", mmap.pageoffset_);
118 HLOGV(" ehFrameHdrElfOffset: 0x%016" PRIx64 "", ehFrameHdrElfOffset);
119 HLOGV(" fdeTableElfOffset: 0x%016" PRIx64 "", fdeTableElfOffset);
120 HLOGV(" fdeTableSize: 0x%016" PRIx64 "", fdeTableSize);
121 return true;
122 }
123 #else
124 if ((UNW_INFO_FORMAT_ARM_EXIDX == di.format) &&
125 symbolsFile.GetSectionInfo(ARM_EXIDX, SectionVaddr, SectionSize, SectionFileOffset)) {
126 const MemMapItem *targetMmap = thread.FindMapByFileInfo(mmap.name_, SectionFileOffset);
127 CHECK_NOTNULL(targetMmap, false, "no debug mmap found.");
128 HLOGV(" begin: %" PRIx64 " offset:%" PRIx64 "", targetMmap->begin_,
129 targetMmap->pageoffset_);
130
131 di.u.rti.table_data = targetMmap->begin_ + SectionFileOffset - targetMmap->pageoffset_;
132 di.u.rti.table_len = SectionSize;
133 HLOGV(" SectionName: %s", std::string(ARM_EXIDX).c_str());
134 HLOGV(" SectionVaddrt: 0x%016" PRIx64 "", SectionVaddr);
135 HLOGV(" SectionFileOffset 0x%016" PRIx64 "", SectionFileOffset);
136 HLOGV(" SectionSize: 0x%016" PRIx64 "", SectionSize);
137
138 // GetSectionInfo return true, but SectionVaddr || SectionSize is 0 ???
139 HLOG_ASSERT(SectionVaddr != 0 && SectionSize != 0);
140 return true;
141 }
142 #endif
143 return false;
144 }
145
146 /*
147 https://www.nongnu.org/libunwind/man/libunwind-dynamic(3).html
148 */
FindUnwindTable(SymbolsFile * symbolsFile,const MemMapItem & mmap,UnwindInfo * unwindInfoPtr,unw_addr_space_t as,unw_word_t ip,unw_proc_info_t * pi,int need_unwind_info,void * arg)149 int CallStack::FindUnwindTable(SymbolsFile *symbolsFile, const MemMapItem &mmap,
150 UnwindInfo *unwindInfoPtr, unw_addr_space_t as, unw_word_t ip,
151 unw_proc_info_t *pi, int need_unwind_info, void *arg)
152 {
153 HLOGV("try seach debug info at %s", symbolsFile->filePath_.c_str());
154 auto &dynInfoProcessMap = unwindInfoPtr->callStack.unwindDynInfoMap_;
155 // all the thread in same process have same mmap and symbols
156 if (dynInfoProcessMap.find(unwindInfoPtr->thread.pid_) == dynInfoProcessMap.end()) {
157 dynInfoProcessMap.emplace(unwindInfoPtr->thread.pid_, dsoUnwDynInfoMap {});
158 }
159 dsoUnwDynInfoMap &dynFileMap = dynInfoProcessMap[unwindInfoPtr->thread.pid_];
160 // find use dso name as key
161 if (dynFileMap.find(symbolsFile->filePath_) == dynFileMap.end()) {
162 // we make a option empty value first
163 std::optional<unw_dyn_info_t> &odi = dynFileMap[symbolsFile->filePath_];
164
165 unw_dyn_info_t newdi;
166 if (memset_s(&newdi, sizeof(unw_dyn_info_t), 0, sizeof(unw_dyn_info_t)) != EOK) {
167 HLOGE("memset_s failed");
168 }
169 #ifdef target_cpu_arm
170 // arm use .ARM.exidx , not use ehframe
171 newdi.format = UNW_INFO_FORMAT_ARM_EXIDX;
172 #else
173 // otherwise we use EH FRAME
174 newdi.format = UNW_INFO_FORMAT_REMOTE_TABLE;
175 #endif
176 if (fillUDI(newdi, *symbolsFile, mmap, unwindInfoPtr->thread)) {
177 dumpUDI(newdi);
178 odi = newdi;
179 }
180 }
181
182 HLOG_ASSERT(dynInfoProcessMap.find(unwindInfoPtr->thread.pid_) != dynInfoProcessMap.end());
183 HLOG_ASSERT_MESSAGE(dynFileMap.find(symbolsFile->filePath_) != dynFileMap.end(), "%s",
184 symbolsFile->filePath_.c_str());
185 std::optional<unw_dyn_info_t> &odi =
186 dynInfoProcessMap.at(unwindInfoPtr->thread.pid_).at(symbolsFile->filePath_);
187
188 if (odi.has_value()) {
189 unw_dyn_info_t &di = odi.value();
190 /*
191 we dont use dwarf_search_unwind_table
192 because in arm it will search two function:
193 1 arm_search_unwind_table first
194 2 dwarf_search_unwind_table
195
196 see libunwind_i.h for arm
197 define tdep_search_unwind_table UNW_OBJ(search_unwind_table)
198
199 */
200 int ret = static_cast<unw_error_t>(
201 tdep_search_unwind_table(as, ip, &di, pi, need_unwind_info, arg));
202
203 HLOGM("search_unwind_table ret %d:%s", ret, GetUnwErrorName(ret).c_str());
204
205 if (UNW_ESUCCESS != ret) {
206 if (UNW_ENOINFO != ret) {
207 HLOGW("search_unwind_table ret error %d:%s", ret, GetUnwErrorName(ret).c_str());
208 }
209 return -UNW_EUNSPEC;
210 } else {
211 return UNW_ESUCCESS;
212 }
213 } else {
214 HLOGW("no debug info found for thread %d:%s", unwindInfoPtr->thread.tid_,
215 unwindInfoPtr->thread.name_.c_str());
216 return -UNW_EUNSPEC;
217 }
218 }
219
FindProcInfo(unw_addr_space_t as,unw_word_t ip,unw_proc_info_t * pi,int need_unwind_info,void * arg)220 int CallStack::FindProcInfo(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
221 int need_unwind_info, void *arg)
222 {
223 UnwindInfo *unwindInfoPtr = static_cast<UnwindInfo *>(arg);
224
225 HLOGM("need_unwind_info ret %d ip %" UNW_WORD_PFLAG "", need_unwind_info, ip);
226 const MemMapItem *mmap = unwindInfoPtr->thread.FindMapByAddr(ip);
227 if (mmap != nullptr) {
228 SymbolsFile *symbolsFile = unwindInfoPtr->thread.FindSymbolsFileByMap(*mmap);
229 if (symbolsFile != nullptr) {
230 return FindUnwindTable(symbolsFile, *mmap, unwindInfoPtr, as, ip, pi, need_unwind_info,
231 arg);
232 } else {
233 HLOGW("no symbols file found for thread %d:%s", unwindInfoPtr->thread.tid_,
234 unwindInfoPtr->thread.name_.c_str());
235 }
236 } else {
237 HLOGE("ip 0x%016" UNW_WORD_PFLAG " not found in thread %d:%s", ip,
238 unwindInfoPtr->thread.tid_, unwindInfoPtr->thread.name_.c_str());
239 }
240
241 return -UNW_EUNSPEC;
242 }
243
ReadVirtualThreadMemory(UnwindInfo & unwindInfoPtr,unw_word_t addr,unw_word_t * data)244 bool CallStack::ReadVirtualThreadMemory(UnwindInfo &unwindInfoPtr, unw_word_t addr,
245 unw_word_t *data)
246 {
247 auto process = unwindInfoPtr.callStack.porcessMemoryMap_.find(unwindInfoPtr.thread.pid_);
248 if (process != unwindInfoPtr.callStack.porcessMemoryMap_.end()) {
249 auto memory = process->second.find(addr);
250 if (memory != process->second.end()) {
251 *data = memory->second;
252 return true;
253 }
254 }
255
256 if (unwindInfoPtr.thread.ReadRoMemory(addr, (uint8_t *)data, sizeof(unw_word_t))) {
257 unwindInfoPtr.callStack.porcessMemoryMap_[unwindInfoPtr.thread.pid_][addr] = *data;
258 return true;
259 } else {
260 return false;
261 }
262 }
263
AccessMem(unw_addr_space_t as,unw_word_t addr,unw_word_t * valuePoint,int writeOperation,void * arg)264 int CallStack::AccessMem([[maybe_unused]] unw_addr_space_t as, unw_word_t addr,
265 unw_word_t *valuePoint, int writeOperation, void *arg)
266 {
267 UnwindInfo *unwindInfoPtr = static_cast<UnwindInfo *>(arg);
268 size_t stackOffset = 0;
269 *valuePoint = 0;
270 HLOGDUMMY("try access addr 0x%" UNW_WORD_PFLAG " ", addr);
271
272 HLOG_ASSERT(writeOperation == 0);
273
274 /* Check overflow. */
275 CHECK_TRUE(addr + sizeof(unw_word_t) >= addr, -UNW_EUNSPEC,
276 "address overfolw at 0x%" UNW_WORD_PFLAG " increase 0x%zu", addr, sizeof(unw_word_t));
277
278 if (addr < unwindInfoPtr->callStack.stackPoint_ or
279 addr + sizeof(unw_word_t) >= unwindInfoPtr->callStack.stackEnd_) {
280 if (ReadVirtualThreadMemory(*unwindInfoPtr, addr, valuePoint)) {
281 HLOGM("access_mem addr get val 0x%" UNW_WORD_PFLAG ", from mmap", *valuePoint);
282 } else {
283 HLOGW("access_mem addr failed, from mmap, ");
284 HLOGW("stack range 0x%" PRIx64 " - 0x%" PRIx64 "(0x%" PRIx64 ")",
285 unwindInfoPtr->callStack.stackPoint_, unwindInfoPtr->callStack.stackEnd_,
286 unwindInfoPtr->callStack.stackEnd_ - unwindInfoPtr->callStack.stackPoint_);
287 return -UNW_EUNSPEC;
288 }
289 } else {
290 stackOffset = addr - unwindInfoPtr->callStack.stackPoint_;
291 *valuePoint = *(unw_word_t *)&unwindInfoPtr->callStack.stack_[stackOffset];
292 HLOGM("access_mem addr val %" UNW_WORD_PFLAG ", from stack offset %zu", *valuePoint, stackOffset);
293 }
294
295 return UNW_ESUCCESS;
296 }
297
AccessReg(unw_addr_space_t as,unw_regnum_t regnum,unw_word_t * valuePoint,int writeOperation,void * arg)298 int CallStack::AccessReg([[maybe_unused]] unw_addr_space_t as, unw_regnum_t regnum,
299 unw_word_t *valuePoint, int writeOperation, void *arg)
300 {
301 UnwindInfo *unwindInfoPtr = static_cast<UnwindInfo *>(arg);
302 uint64_t val;
303 size_t perfRegIndex = LibunwindRegIdToPerfReg(regnum);
304 if (perfRegIndex < PERF_REG_ARM64_X29) {
305 // libunwind not access other regs
306 HLOGE("access_reg not expected %d", regnum);
307 }
308 /* Don't support write, I suspect we don't need it. */
309 CHECK_TRUE(!writeOperation, -UNW_EINVAL, "access_reg %d", regnum);
310
311 if (unwindInfoPtr->callStack.regsNum_ == 0) {
312 return -UNW_EUNSPEC;
313 }
314 CHECK_TRUE(RegisterGetValue(val, unwindInfoPtr->callStack.regs_, perfRegIndex, unwindInfoPtr->callStack.regsNum_),
315 -UNW_EUNSPEC, "can't read reg %zu", perfRegIndex);
316 *valuePoint = (unw_word_t)val;
317 HLOGV("reg %d:%s, val 0x%" UNW_WORD_PFLAG "", regnum, RegisterGetName(perfRegIndex).c_str(),
318 *valuePoint);
319 return UNW_ESUCCESS;
320 }
321
PutUnwindInfo(unw_addr_space_t as,unw_proc_info_t * pi,void * arg)322 void CallStack::PutUnwindInfo([[maybe_unused]] unw_addr_space_t as,
323 [[maybe_unused]] unw_proc_info_t *pi, [[maybe_unused]] void *arg)
324 {
325 }
326
AccessFpreg(unw_addr_space_t as,unw_regnum_t num,unw_fpreg_t * val,int writeOperation,void * arg)327 int CallStack::AccessFpreg([[maybe_unused]] unw_addr_space_t as, [[maybe_unused]] unw_regnum_t num,
328 [[maybe_unused]] unw_fpreg_t *val, [[maybe_unused]] int writeOperation,
329 [[maybe_unused]] void *arg)
330 {
331 return -UNW_EINVAL;
332 }
333
GetDynInfoListAaddr(unw_addr_space_t as,unw_word_t * dil_vaddr,void * arg)334 int CallStack::GetDynInfoListAaddr([[maybe_unused]] unw_addr_space_t as,
335 [[maybe_unused]] unw_word_t *dil_vaddr,
336 [[maybe_unused]] void *arg)
337 {
338 return -UNW_ENOINFO;
339 }
340
Resume(unw_addr_space_t as,unw_cursor_t * cu,void * arg)341 int CallStack::Resume([[maybe_unused]] unw_addr_space_t as, [[maybe_unused]] unw_cursor_t *cu,
342 [[maybe_unused]] void *arg)
343 {
344 return -UNW_EINVAL;
345 }
346
getProcName(unw_addr_space_t as,unw_word_t addr,char * bufp,size_t buf_len,unw_word_t * offp,void * arg)347 int CallStack::getProcName([[maybe_unused]] unw_addr_space_t as, [[maybe_unused]] unw_word_t addr,
348 [[maybe_unused]] char *bufp, [[maybe_unused]] size_t buf_len,
349 [[maybe_unused]] unw_word_t *offp, [[maybe_unused]] void *arg)
350 {
351 return -UNW_EINVAL;
352 }
353
UnwindStep(unw_cursor_t & c,std::vector<CallFrame> & callStack,size_t maxStackLevel)354 void CallStack::UnwindStep(unw_cursor_t &c, std::vector<CallFrame> &callStack, size_t maxStackLevel)
355 {
356 while (callStack.size() < maxStackLevel) {
357 int ret = unw_step(&c);
358 if (ret > 0) {
359 unw_word_t ip = 0;
360 unw_word_t sp = 0;
361 unw_get_reg(&c, UNW_REG_IP, &ip);
362 unw_get_reg(&c, UNW_REG_SP, &sp);
363
364 if (ip == 0) {
365 HLOGD("ip == 0 something is wrong. break");
366 break;
367 }
368
369 /*
370 * Decrement the IP for any non-activation frames.
371 * this is required to properly find the srcline
372 * for caller frames.
373 * See also the documentation for dwfl_frame_pc(),
374 * which this code tries to replicate.
375 */
376 if (unw_is_signal_frame(&c) <= 0) {
377 --ip;
378 }
379 HLOGV("unwind:%zu: ip 0x%" UNW_WORD_PFLAG " sp 0x%" UNW_WORD_PFLAG "", callStack.size(),
380 ip, sp);
381 if (callStack.back().ip_ == ip && callStack.back().sp_ == sp) {
382 HLOGW("we found a same frame, stop here");
383 break;
384 }
385 callStack.emplace_back(ip, sp);
386 } else {
387 HLOGV("no more frame step found. ret %d:%s", ret, GetUnwErrorName(ret).c_str());
388 break;
389 }
390 }
391 }
392 #endif
393
GetIpSP(uint64_t & ip,uint64_t & sp,const u64 * regs,size_t regNum) const394 bool CallStack::GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, size_t regNum) const
395 {
396 if (regNum > 0) {
397 CHECK_TRUE(RegisterGetSPValue(sp, arch_, regs, regNum), false, "unable get sp");
398 CHECK_TRUE(RegisterGetIPValue(ip, arch_, regs, regNum), false, "unable get ip");
399 if (ip != 0) {
400 return true;
401 }
402 } else {
403 HLOGW("reg size is 0");
404 return false;
405 }
406 return false;
407 }
408
409 #if HAVE_LIBUNWIND
DoUnwind(const VirtualThread & thread,std::vector<CallFrame> & callStack,size_t maxStackLevel)410 bool CallStack::DoUnwind(const VirtualThread &thread, std::vector<CallFrame> &callStack,
411 size_t maxStackLevel)
412 {
413 unw_addr_space_t addr_space;
414 UnwindInfo unwindInfo = {
415 .thread = thread,
416 .callStack = *this,
417 };
418 unw_cursor_t c;
419 if (unwindAddrSpaceMap_.count(thread.tid_) == 0) {
420 addr_space = unw_create_addr_space(&accessors_, 0);
421 CHECK_TRUE(addr_space, false, "Can't create unwind vaddress space.");
422 unwindAddrSpaceMap_.emplace(thread.tid_, addr_space);
423 unw_set_caching_policy(addr_space, UNW_CACHE_GLOBAL);
424 unw_flush_cache(addr_space, 0, 0);
425 } else {
426 addr_space = unwindAddrSpaceMap_.at(thread.tid_);
427 }
428
429 int ret = unw_init_remote(&c, addr_space, &unwindInfo);
430 if (ret) {
431 HLOGE("unwind error %d:%s see unw_error_t.", ret, GetUnwErrorName(ret).c_str());
432 return false;
433 } else {
434 UnwindStep(c, callStack, maxStackLevel);
435 }
436 return true;
437 }
438 #endif
439
UnwindCallStack(const VirtualThread & thread,u64 * regs,u64 regsNum,const u8 * stack,u64 stackSize,std::vector<CallFrame> & callStack,size_t maxStackLevel)440 bool CallStack::UnwindCallStack(const VirtualThread &thread, u64 *regs, u64 regsNum,
441 const u8 *stack, u64 stackSize, std::vector<CallFrame> &callStack,
442 size_t maxStackLevel)
443 {
444 regs_ = regs;
445 regsNum_ = regsNum;
446 stack_ = stack;
447 stackSize_ = stackSize;
448
449 arch_ = buildArchType;
450 UpdateRegForABI(arch_, regs_);
451 if (!RegisterGetSPValue(stackPoint_, arch_, regs_, regsNum_)) {
452 HLOGE("RegisterGetSPValue failed");
453 return false;
454 } else {
455 stackEnd_ = stackPoint_ + stackSize_;
456 }
457
458 uint64_t ip = 0;
459 uint64_t sp = 0;
460 if (!GetIpSP(ip, sp, regs_, regsNum_)) {
461 HLOGW("unable get sp or sp , unable unwind");
462 return false;
463 } else {
464 if (ip != 0) {
465 HLOGV("unwind:%zu: ip 0x%" PRIx64 " sp 0x%" PRIx64 "", callStack.size(), ip, sp);
466 callStack.emplace_back(ip, sp);
467 }
468 }
469
470 /*
471 * If we need more than one entry, do the DWARF
472 * unwind itself.
473 */
474 if (maxStackLevel - 1 > 0) {
475 return DoUnwind(thread, callStack, maxStackLevel);
476 }
477 return true;
478 }
479
480 /*
481 we should have CallStack cache for each thread
482
483 0. A -> B -> C -> E -> F
484 1. C -> E -> F
485 2. B -> C
486 3. A -> B -> C
487 4. B -> G -> H
488 5. J -> C
489
490 0 is our cache
491 1 2 3... is from record
492
493 use expendLimit to setup how may frame match is needs
494
495 */
496
CallStack()497 CallStack::CallStack() {}
498
~CallStack()499 CallStack::~CallStack()
500 {
501 #if HAVE_LIBUNWIND
502 for (auto &pair : unwindAddrSpaceMap_) {
503 unw_destroy_addr_space(pair.second);
504 }
505 #endif
506 }
507 } // namespace NativeDaemon
508 } // namespace Developtools
509 } // namespace OHOS