45#define FRAME_COUNT 10000
46 using namespace std::chrono;
47 auto time_value = steady_clock::now();
53 ABI *abi = process_sp ? process_sp->GetABI().get() :
nullptr;
57 if ((
m_frames.size() % FRAME_COUNT) == 0) {
58 const auto now = steady_clock::now();
59 const auto delta_t = now - time_value;
60 printf(
"%u frames in %.9f ms (%g frames/sec)\n", FRAME_COUNT,
61 duration<double, std::milli>(delta_t).count(),
62 (
float)FRAME_COUNT / duration<double>(delta_t).count());
76 ABI *abi = process_sp ? process_sp->GetABI().get() :
nullptr;
82 if (reg_ctx_sp.get() ==
nullptr)
85 if (!reg_ctx_sp->IsValid())
88 if (!reg_ctx_sp->GetCFA(first_cursor_sp->cfa))
91 if (!reg_ctx_sp->ReadPC(first_cursor_sp->start_pc))
96 first_cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
106 LLDB_LOGF(log,
"th%d Unwind of this thread is complete.",
114 "Get one more frame called with empty frame list");
128 m_thread, prev_frame->reg_ctx_lldb_sp, cursor_sp->sctx, cur_idx, *
this));
130 uint64_t max_stack_depth =
m_thread.GetMaxBacktraceDepth();
140 if (cur_idx >= max_stack_depth) {
142 "%*sFrame %d unwound too many frames, assuming unwind has "
143 "gone astray, stopping.",
144 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
148 if (reg_ctx_sp.get() ==
nullptr) {
152 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
156 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
162 LLDB_LOGF(log,
"%*sFrame %d did not get a RegisterContext, stopping.",
163 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
167 if (!reg_ctx_sp->IsValid()) {
171 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
175 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
182 "%*sFrame %d invalid RegisterContext for this frame, "
183 "stopping stack walk",
184 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
187 if (!reg_ctx_sp->GetCFA(cursor_sp->cfa)) {
191 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
195 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
202 "%*sFrame %d did not get CFA for this frame, stopping stack walk",
203 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
210 if (!reg_ctx_sp->IsTrapHandlerFrame()) {
216 if (!reg_ctx_sp->TryFallbackUnwindPlan() ||
217 !reg_ctx_sp->GetCFA(cursor_sp->cfa) ||
219 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
223 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
230 "%*sFrame %d did not get a valid CFA for this frame, "
231 "stopping stack walk",
232 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
236 "%*sFrame %d had a bad CFA value but we switched the "
237 "UnwindPlan being used and got one that looks more "
239 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
243 if (!reg_ctx_sp->ReadPC(cursor_sp->start_pc)) {
247 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
251 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
258 "%*sFrame %d did not get PC for this frame, stopping stack walk",
259 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
267 !prev_frame->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
271 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
275 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
281 LLDB_LOGF(log,
"%*sFrame %d did not get a valid PC, stopping stack walk",
282 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
286 if (prev_frame->start_pc == cursor_sp->start_pc &&
287 prev_frame->cfa == cursor_sp->cfa) {
289 "th%d pc of this frame is the same as the previous frame and "
290 "CFAs for both frames are identical -- stopping unwind",
295 cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
396 bool &behaves_like_zeroth_frame) {
403 ABI *abi = process_sp ? process_sp->GetABI().get() :
nullptr;
413 behaves_like_zeroth_frame =
true;
414 }
else if (
m_frames[idx - 1]->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
418 behaves_like_zeroth_frame =
true;
419 }
else if (
m_frames[idx]->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
425 behaves_like_zeroth_frame =
true;
426 }
else if (
m_frames[idx]->reg_ctx_lldb_sp->BehavesLikeZerothFrame()) {
427 behaves_like_zeroth_frame =
true;
429 behaves_like_zeroth_frame =
false;