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;
107 LLDB_LOGF(log,
"th%d Unwind of this thread is complete.",
116 "Get one more frame called with empty frame list");
130 m_thread, prev_frame->reg_ctx_lldb_sp, cursor_sp->sctx, cur_idx, *
this));
132 uint64_t max_stack_depth =
m_thread.GetMaxBacktraceDepth();
142 if (cur_idx >= max_stack_depth) {
144 "%*sFrame %d unwound too many frames, assuming unwind has "
145 "gone astray, stopping.",
146 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
150 if (reg_ctx_sp.get() ==
nullptr) {
154 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
158 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
164 LLDB_LOGF(log,
"%*sFrame %d did not get a RegisterContext, stopping.",
165 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
169 if (!reg_ctx_sp->IsValid()) {
173 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
177 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
184 "%*sFrame %d invalid RegisterContext for this frame, "
185 "stopping stack walk",
186 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
189 if (!reg_ctx_sp->GetCFA(cursor_sp->cfa)) {
193 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
197 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
204 "%*sFrame %d did not get CFA for this frame, stopping stack walk",
205 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
212 if (!reg_ctx_sp->IsTrapHandlerFrame()) {
218 if (!reg_ctx_sp->TryFallbackUnwindPlan() ||
219 !reg_ctx_sp->GetCFA(cursor_sp->cfa) ||
221 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
225 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
232 "%*sFrame %d did not get a valid CFA for this frame, "
233 "stopping stack walk",
234 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
238 "%*sFrame %d had a bad CFA value but we switched the "
239 "UnwindPlan being used and got one that looks more "
241 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
245 if (!reg_ctx_sp->ReadPC(cursor_sp->start_pc)) {
249 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
253 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
260 "%*sFrame %d did not get PC for this frame, stopping stack walk",
261 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
269 !prev_frame->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
273 if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
277 if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
283 LLDB_LOGF(log,
"%*sFrame %d did not get a valid PC, stopping stack walk",
284 cur_idx < 100 ? cur_idx : 100,
"", cur_idx);
288 if (prev_frame->start_pc == cursor_sp->start_pc &&
289 prev_frame->cfa == cursor_sp->cfa) {
291 "th%d pc of this frame is the same as the previous frame and "
292 "CFAs for both frames are identical -- stopping unwind",
297 cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
398 bool &behaves_like_zeroth_frame) {
405 ABI *abi = process_sp ? process_sp->GetABI().get() :
nullptr;
415 behaves_like_zeroth_frame =
true;
416 }
else if (
m_frames[idx - 1]->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
420 behaves_like_zeroth_frame =
true;
421 }
else if (
m_frames[idx]->reg_ctx_lldb_sp->IsTrapHandlerFrame()) {
427 behaves_like_zeroth_frame =
true;
428 }
else if (
m_frames[idx]->reg_ctx_lldb_sp->BehavesLikeZerothFrame()) {
429 behaves_like_zeroth_frame =
true;
431 behaves_like_zeroth_frame =
false;