46#define FRAME_COUNT 10000
47 using namespace std::chrono;
48 auto time_value = steady_clock::now();
54 ABI *abi = process_sp ? process_sp->GetABI().get() :
nullptr;
58 if ((
m_frames.size() % FRAME_COUNT) == 0) {
59 const auto now = steady_clock::now();
60 const auto delta_t = now - time_value;
61 printf(
"%u frames in %.9f ms (%g frames/sec)\n", FRAME_COUNT,
62 duration<double, std::milli>(delta_t).count(),
63 (
float)FRAME_COUNT / duration<double>(delta_t).count());
77 ABI *abi = process_sp ? process_sp->GetABI().get() :
nullptr;
83 if (reg_ctx_sp.get() ==
nullptr)
86 if (!reg_ctx_sp->IsValid())
89 if (!reg_ctx_sp->GetCFA(first_cursor_sp->cfa))
92 if (!reg_ctx_sp->ReadPC(first_cursor_sp->start_pc))
97 first_cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
107 LLDB_LOGF(log,
"th%d Unwind of this thread is complete.",
115 "Get one more frame called with empty frame list");
129 m_thread, prev_frame->reg_ctx_lldb_sp, cursor_sp->sctx, cur_idx, *
this));
131 uint64_t max_stack_depth =
m_thread.GetMaxBacktraceDepth();
141 if (cur_idx >= max_stack_depth) {
143 "%*sFrame %d unwound too many frames, assuming unwind has "
144 "gone astray, stopping.",
145 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
149 if (reg_ctx_sp.get() ==
nullptr) {
153 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
157 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
163 LLDB_LOGF(log,
"%*sFrame %d did not get a RegisterContext, stopping.",
164 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
168 if (!reg_ctx_sp->IsValid()) {
172 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
176 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
183 "%*sFrame %d invalid RegisterContext for this frame, "
184 "stopping stack walk",
185 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
188 if (!reg_ctx_sp->GetCFA(cursor_sp->cfa)) {
192 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
196 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
203 "%*sFrame %d did not get CFA for this frame, stopping stack walk",
204 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
211 if (!reg_ctx_sp->IsTrapHandlerFrame()) {
217 if (!reg_ctx_sp->TryFallbackUnwindPlan() ||
218 !reg_ctx_sp->GetCFA(cursor_sp->cfa) ||
220 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
224 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
231 "%*sFrame %d did not get a valid CFA for this frame, "
232 "stopping stack walk",
233 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
237 "%*sFrame %d had a bad CFA value but we switched the "
238 "UnwindPlan being used and got one that looks more "
240 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
244 if (!reg_ctx_sp->ReadPC(cursor_sp->start_pc)) {
248 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
252 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
259 "%*sFrame %d did not get PC for this frame, stopping stack walk",
260 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
268 !prev_frame->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
272 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
276 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
282 LLDB_LOGF(log,
"%*sFrame %d did not get a valid PC, stopping stack walk",
283 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
287 if (prev_frame->start_pc == cursor_sp->start_pc &&
288 prev_frame->cfa == cursor_sp->cfa) {
290 "th%d pc of this frame is the same as the previous frame and "
291 "CFAs for both frames are identical -- stopping unwind",
296 cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
397 bool &behaves_like_zeroth_frame) {
404 ABI *abi = process_sp ? process_sp->GetABI().get() :
nullptr;
414 behaves_like_zeroth_frame =
true;
415 }
else if (
m_frames[idx - 1]->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
419 behaves_like_zeroth_frame =
true;
420 }
else if (
m_frames[idx]->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
426 behaves_like_zeroth_frame =
true;
427 }
else if (
m_frames[idx]->reg_ctx_lldb_sp->BehavesLikeZerothFrame()) {
428 behaves_like_zeroth_frame =
true;
430 behaves_like_zeroth_frame =
false;