LLDB mainline
RegisterContextUnwind.cpp
Go to the documentation of this file.
1//===-- RegisterContextUnwind.cpp -----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Core/Address.h"
12#include "lldb/Core/Module.h"
13#include "lldb/Core/Value.h"
21#include "lldb/Symbol/Symbol.h"
24#include "lldb/Target/ABI.h"
29#include "lldb/Target/Process.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
36#include "lldb/Utility/Log.h"
39#include "lldb/lldb-private.h"
40
41#include <cassert>
42#include <memory>
43
44using namespace lldb;
45using namespace lldb_private;
46
48 if (sym_ctx.symbol)
49 return sym_ctx.symbol->GetName();
50 else if (sym_ctx.function)
51 return sym_ctx.function->GetName();
52 return ConstString();
53}
54
56 const SharedPtr &next_frame,
57 SymbolContext &sym_ctx,
58 uint32_t frame_number,
59 UnwindLLDB &unwind_lldb)
60 : RegisterContext(thread, frame_number), m_thread(thread),
67 m_sym_ctx_valid(false), m_frame_number(frame_number), m_registers(),
68 m_parent_unwind(unwind_lldb) {
69 m_sym_ctx.Clear(false);
70 m_sym_ctx_valid = false;
71
72 if (IsFrameZero()) {
74 } else {
76 }
77
78 // This same code exists over in the GetFullUnwindPlanForFrame() but it may
79 // not have been executed yet
80 if (IsFrameZero() || next_frame->m_frame_type == eTrapHandlerFrame ||
81 next_frame->m_frame_type == eDebuggerFrame) {
82 m_all_registers_available = true;
83 }
84}
85
87 std::shared_ptr<const UnwindPlan> unwind_plan_sp) {
88 if (!unwind_plan_sp)
89 return false;
90
91 // check if m_current_pc is valid
92 if (unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
93 // yes - current offset can be used as is
94 return true;
95 }
96
97 // If don't have an offset or we're at the start of the function, we've got
98 // nothing else to try.
100 return false;
101
102 // check pc - 1 to see if it's valid
103 Address pc_minus_one(m_current_pc);
104 pc_minus_one.SetOffset(m_current_pc.GetOffset() - 1);
105 if (unwind_plan_sp->PlanValidAtAddress(pc_minus_one)) {
106 return true;
107 }
108
109 return false;
110}
111
112// Initialize a RegisterContextUnwind which is the first frame of a stack -- the
113// zeroth frame or currently executing frame.
114
116 Log *log = GetLog(LLDBLog::Unwind);
117 ExecutionContext exe_ctx(m_thread.shared_from_this());
118 RegisterContextSP reg_ctx_sp = m_thread.GetRegisterContext();
119
120 if (reg_ctx_sp.get() == nullptr) {
122 UnwindLogMsg("frame does not have a register context");
123 return;
124 }
125
126 addr_t current_pc = reg_ctx_sp->GetPC();
127
128 if (current_pc == LLDB_INVALID_ADDRESS) {
130 UnwindLogMsg("frame does not have a pc");
131 return;
132 }
133
134 Process *process = exe_ctx.GetProcessPtr();
135
136 // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
137 // this will strip bit zero in case we read a PC from memory or from the LR.
138 // (which would be a no-op in frame 0 where we get it from the register set,
139 // but still a good idea to make the call here for other ABIs that may
140 // exist.)
141 if (ABISP abi_sp = process->GetABI())
142 current_pc = abi_sp->FixCodeAddress(current_pc);
143
144 std::shared_ptr<const UnwindPlan> lang_runtime_plan_sp =
147 if (lang_runtime_plan_sp.get()) {
148 UnwindLogMsg("This is an async frame");
149 }
150
151 // Initialize m_current_pc, an Address object, based on current_pc, an
152 // addr_t.
153 m_current_pc.SetLoadAddress(current_pc, &process->GetTarget());
154
155 // If we don't have a Module for some reason, we're not going to find
156 // symbol/function information - just stick in some reasonable defaults and
157 // hope we can unwind past this frame.
158 ModuleSP pc_module_sp(m_current_pc.GetModule());
159 if (!m_current_pc.IsValid() || !pc_module_sp) {
160 UnwindLogMsg("using architectural default unwind method");
161 }
162
163 m_sym_ctx_valid = m_current_pc.ResolveFunctionScope(m_sym_ctx);
164
165 if (m_sym_ctx.symbol) {
166 UnwindLogMsg("with pc value of 0x%" PRIx64 ", symbol name is '%s'",
167 current_pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
168 } else if (m_sym_ctx.function) {
169 UnwindLogMsg("with pc value of 0x%" PRIx64 ", function name is '%s'",
170 current_pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
171 } else {
172 UnwindLogMsg("with pc value of 0x%" PRIx64
173 ", no symbol/function name is known.",
174 current_pc);
175 }
176
177 if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
179 } else {
180 // FIXME: Detect eDebuggerFrame here.
182 }
183
184 // If we were able to find a symbol/function, set addr_range to the bounds of
185 // that symbol/function. else treat the current pc value as the start_pc and
186 // record no offset.
187 if (m_sym_ctx_valid) {
188 m_start_pc = m_sym_ctx.GetFunctionOrSymbolAddress();
189 if (m_current_pc.GetModule() == m_start_pc.GetModule()) {
191 m_current_pc.GetFileAddress() - m_start_pc.GetFileAddress();
192 }
194 } else {
196 m_current_offset = std::nullopt;
197 m_current_offset_backed_up_one = std::nullopt;
198 }
199
200 // We've set m_frame_type and m_sym_ctx before these calls.
201
204
205 const UnwindPlan::Row *active_row = nullptr;
206 lldb::RegisterKind row_register_kind = eRegisterKindGeneric;
207
208 // If we have LanguageRuntime UnwindPlan for this unwind, use those
209 // rules to find the caller frame instead of the function's normal
210 // UnwindPlans. The full unwind plan for this frame will be
211 // the LanguageRuntime-provided unwind plan, and there will not be a
212 // fast unwind plan.
213 if (lang_runtime_plan_sp.get()) {
214 active_row =
215 lang_runtime_plan_sp->GetRowForFunctionOffset(m_current_offset);
216 row_register_kind = lang_runtime_plan_sp->GetRegisterKind();
217 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(),
218 m_cfa)) {
219 UnwindLogMsg("Cannot set cfa");
220 } else {
221 m_full_unwind_plan_sp = lang_runtime_plan_sp;
222 if (log) {
223 StreamString active_row_strm;
224 active_row->Dump(active_row_strm, lang_runtime_plan_sp.get(), &m_thread,
225 m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
226 UnwindLogMsg("async active row: %s", active_row_strm.GetData());
227 }
228 UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
230 "initialized async frame current pc is 0x%" PRIx64
231 " cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
232 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
233 (uint64_t)m_cfa, (uint64_t)m_afa);
234
235 return;
236 }
237 }
238
240 m_full_unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
241 active_row =
242 m_full_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
243 row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
245 if (active_row && log) {
246 StreamString active_row_strm;
247 active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread,
248 m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
249 UnwindLogMsg("%s", active_row_strm.GetData());
250 }
251 }
252
253 if (!active_row) {
254 UnwindLogMsg("could not find an unwindplan row for this frame's pc");
256 return;
257 }
258
259 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(), m_cfa)) {
260 // Try the fall back unwind plan since the
261 // full unwind plan failed.
262 FuncUnwindersSP func_unwinders_sp;
263 std::shared_ptr<const UnwindPlan> call_site_unwind_plan;
264 bool cfa_status = false;
265
266 if (m_sym_ctx_valid) {
267 func_unwinders_sp =
268 pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
270 }
271
272 if (func_unwinders_sp.get() != nullptr)
273 call_site_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(
274 process->GetTarget(), m_thread);
275
276 if (call_site_unwind_plan != nullptr) {
277 m_fallback_unwind_plan_sp = call_site_unwind_plan;
279 cfa_status = true;
280 }
281 if (!cfa_status) {
282 UnwindLogMsg("could not read CFA value for first frame.");
284 return;
285 }
286 } else
287 ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
288
291 "could not read CFA or AFA values for first frame, not valid.");
293 return;
294 }
295
296 // Give the Architecture a chance to replace the UnwindPlan.
298
299 UnwindLogMsg("initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64
300 " afa is 0x%" PRIx64 " using %s UnwindPlan",
301 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
302 (uint64_t)m_cfa,
303 (uint64_t)m_afa,
304 m_full_unwind_plan_sp->GetSourceName().GetCString());
305}
306
307// Initialize a RegisterContextUnwind for the non-zeroth frame -- rely on the
308// RegisterContextUnwind "below" it to provide things like its current pc value.
309
311 Log *log = GetLog(LLDBLog::Unwind);
312 if (IsFrameZero()) {
314 UnwindLogMsg("non-zeroth frame tests positive for IsFrameZero -- that "
315 "shouldn't happen.");
316 return;
317 }
318
319 if (!GetNextFrame().get() || !GetNextFrame()->IsValid()) {
321 UnwindLogMsg("Could not get next frame, marking this frame as invalid.");
322 return;
323 }
324 if (!m_thread.GetRegisterContext()) {
326 UnwindLogMsg("Could not get register context for this thread, marking this "
327 "frame as invalid.");
328 return;
329 }
330
331 ExecutionContext exe_ctx(m_thread.shared_from_this());
332 Process *process = exe_ctx.GetProcessPtr();
333
334 // Some languages may have a logical parent stack frame which is
335 // not a real stack frame, but the programmer would consider it to
336 // be the caller of the frame, e.g. Swift asynchronous frames.
337 //
338 // A LanguageRuntime may provide an UnwindPlan that is used in this
339 // stack trace base on the RegisterContext contents, intsead
340 // of the normal UnwindPlans we would use for the return-pc.
341 std::shared_ptr<const UnwindPlan> lang_runtime_plan_sp =
344 if (lang_runtime_plan_sp.get()) {
345 UnwindLogMsg("This is an async frame");
346 }
347
348 addr_t pc;
350 UnwindLogMsg("could not get pc value");
352 return;
353 }
354
355 // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
356 // this will strip bit zero in case we read a PC from memory or from the LR.
357 ABISP abi_sp = process->GetABI();
358 if (abi_sp)
359 pc = abi_sp->FixCodeAddress(pc);
360
361 if (log) {
362 UnwindLogMsg("pc = 0x%" PRIx64, pc);
363 addr_t reg_val;
365 UnwindLogMsg("fp = 0x%" PRIx64, reg_val);
367 UnwindLogMsg("sp = 0x%" PRIx64, reg_val);
368 }
369
370 // A pc of 0x0 means it's the end of the stack crawl unless we're above a trap
371 // handler function
372 bool above_trap_handler = false;
373 if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
375 above_trap_handler = true;
376
377 if (pc == 0 || pc == 0x1) {
378 if (!above_trap_handler) {
380 UnwindLogMsg("this frame has a pc of 0x0");
381 return;
382 }
383 }
384
385 const bool allow_section_end = true;
386 m_current_pc.SetLoadAddress(pc, &process->GetTarget(), allow_section_end);
387
388 // If we don't have a Module for some reason, we're not going to find
389 // symbol/function information - just stick in some reasonable defaults and
390 // hope we can unwind past this frame. If we're above a trap handler,
391 // we may be at a bogus address because we jumped through a bogus function
392 // pointer and trapped, so don't force the arch default unwind plan in that
393 // case.
394 ModuleSP pc_module_sp(m_current_pc.GetModule());
395 if ((!m_current_pc.IsValid() || !pc_module_sp) &&
396 above_trap_handler == false) {
397 UnwindLogMsg("using architectural default unwind method");
398
399 // Test the pc value to see if we know it's in an unmapped/non-executable
400 // region of memory.
401 uint32_t permissions;
402 if (process->GetLoadAddressPermissions(pc, permissions) &&
403 (permissions & ePermissionsExecutable) == 0) {
404 // If this is the second frame off the stack, we may have unwound the
405 // first frame incorrectly. But using the architecture default unwind
406 // plan may get us back on track -- albeit possibly skipping a real
407 // frame. Give this frame a clearly-invalid pc and see if we can get any
408 // further.
409 if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
411 UnwindLogMsg("had a pc of 0x%" PRIx64 " which is not in executable "
412 "memory but on frame 1 -- "
413 "allowing it once.",
414 (uint64_t)pc);
416 } else {
417 // anywhere other than the second frame, a non-executable pc means
418 // we're off in the weeds -- stop now.
420 UnwindLogMsg("pc is in a non-executable section of memory and this "
421 "isn't the 2nd frame in the stack walk.");
422 return;
423 }
424 }
425
426 if (abi_sp) {
427 m_fast_unwind_plan_sp.reset();
428 m_full_unwind_plan_sp = abi_sp->CreateDefaultUnwindPlan();
429 if (m_frame_type != eSkipFrame) // don't override eSkipFrame
430 {
432 }
434 m_current_offset = std::nullopt;
435 m_current_offset_backed_up_one = std::nullopt;
436 RegisterKind row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
437 if (const UnwindPlan::Row *row =
438 m_full_unwind_plan_sp->GetRowForFunctionOffset(0)) {
439 if (!ReadFrameAddress(row_register_kind, row->GetCFAValue(), m_cfa)) {
440 UnwindLogMsg("failed to get cfa value");
441 if (m_frame_type != eSkipFrame) // don't override eSkipFrame
442 {
444 }
445 return;
446 }
447
448 ReadFrameAddress(row_register_kind, row->GetAFAValue(), m_afa);
449
450 // A couple of sanity checks..
451 if (m_cfa == LLDB_INVALID_ADDRESS || m_cfa == 0 || m_cfa == 1) {
452 UnwindLogMsg("could not find a valid cfa address");
454 return;
455 }
456
457 // m_cfa should point into the stack memory; if we can query memory
458 // region permissions, see if the memory is allocated & readable.
459 if (process->GetLoadAddressPermissions(m_cfa, permissions) &&
460 (permissions & ePermissionsReadable) == 0) {
463 "the CFA points to a region of memory that is not readable");
464 return;
465 }
466 } else {
467 UnwindLogMsg("could not find a row for function offset zero");
469 return;
470 }
471
472 if (CheckIfLoopingStack()) {
474 if (CheckIfLoopingStack()) {
475 UnwindLogMsg("same CFA address as next frame, assuming the unwind is "
476 "looping - stopping");
478 return;
479 }
480 }
481
482 // Give the Architecture a chance to replace the UnwindPlan.
484
485 UnwindLogMsg("initialized frame cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
486 (uint64_t)m_cfa, (uint64_t)m_afa);
487 return;
488 }
490 UnwindLogMsg("could not find any symbol for this pc, or a default unwind "
491 "plan, to continue unwind.");
492 return;
493 }
494
495 m_sym_ctx_valid = m_current_pc.ResolveFunctionScope(m_sym_ctx);
496
497 if (m_sym_ctx.symbol) {
498 UnwindLogMsg("with pc value of 0x%" PRIx64 ", symbol name is '%s'", pc,
499 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
500 } else if (m_sym_ctx.function) {
501 UnwindLogMsg("with pc value of 0x%" PRIx64 ", function name is '%s'", pc,
502 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
503 } else {
504 UnwindLogMsg("with pc value of 0x%" PRIx64
505 ", no symbol/function name is known.",
506 pc);
507 }
508
509 bool decr_pc_and_recompute_addr_range;
510
511 if (!m_sym_ctx_valid) {
512 // Always decrement and recompute if the symbol lookup failed
513 decr_pc_and_recompute_addr_range = true;
516 // Don't decrement if we're "above" an asynchronous event like
517 // sigtramp.
518 decr_pc_and_recompute_addr_range = false;
519 } else if (Address addr = m_sym_ctx.GetFunctionOrSymbolAddress();
520 addr != m_current_pc) {
521 // If our "current" pc isn't the start of a function, decrement the pc
522 // if we're up the stack.
524 decr_pc_and_recompute_addr_range = false;
525 else
526 decr_pc_and_recompute_addr_range = true;
527 } else if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
528 // Signal dispatch may set the return address of the handler it calls to
529 // point to the first byte of a return trampoline (like __kernel_rt_sigreturn),
530 // so do not decrement and recompute if the symbol we already found is a trap
531 // handler.
532 decr_pc_and_recompute_addr_range = false;
533 } else if (m_behaves_like_zeroth_frame) {
534 decr_pc_and_recompute_addr_range = false;
535 } else {
536 // Decrement to find the function containing the call.
537 decr_pc_and_recompute_addr_range = true;
538 }
539
540 // We need to back up the pc by 1 byte and re-search for the Symbol to handle
541 // the case where the "saved pc" value is pointing to the next function, e.g.
542 // if a function ends with a CALL instruction.
543 // FIXME this may need to be an architectural-dependent behavior; if so we'll
544 // need to add a member function
545 // to the ABI plugin and consult that.
546 if (decr_pc_and_recompute_addr_range) {
547 UnwindLogMsg("Backing up the pc value of 0x%" PRIx64
548 " by 1 and re-doing symbol lookup; old symbol was %s",
549 pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
550 Address temporary_pc;
551 temporary_pc.SetLoadAddress(pc - 1, &process->GetTarget());
552 m_sym_ctx.Clear(false);
554
555 UnwindLogMsg("Symbol is now %s",
556 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
557 }
558
559 // If we were able to find a symbol/function, set addr_range_ptr to the
560 // bounds of that symbol/function. else treat the current pc value as the
561 // start_pc and record no offset.
562 if (m_sym_ctx_valid) {
563 m_start_pc = m_sym_ctx.GetFunctionOrSymbolAddress();
564 m_current_offset = pc - m_start_pc.GetLoadAddress(&process->GetTarget());
566 if (decr_pc_and_recompute_addr_range &&
569 if (m_sym_ctx_valid) {
570 m_current_pc.SetLoadAddress(pc - 1, &process->GetTarget());
571 }
572 }
573 } else {
575 m_current_offset = std::nullopt;
576 m_current_offset_backed_up_one = std::nullopt;
577 }
578
579 if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
581 } else {
582 // FIXME: Detect eDebuggerFrame here.
583 if (m_frame_type != eSkipFrame) // don't override eSkipFrame
584 {
586 }
587 }
588
589 const UnwindPlan::Row *active_row;
590 RegisterKind row_register_kind = eRegisterKindGeneric;
591
592 // If we have LanguageRuntime UnwindPlan for this unwind, use those
593 // rules to find the caller frame instead of the function's normal
594 // UnwindPlans. The full unwind plan for this frame will be
595 // the LanguageRuntime-provided unwind plan, and there will not be a
596 // fast unwind plan.
597 if (lang_runtime_plan_sp.get()) {
598 active_row =
599 lang_runtime_plan_sp->GetRowForFunctionOffset(m_current_offset);
600 row_register_kind = lang_runtime_plan_sp->GetRegisterKind();
601 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(),
602 m_cfa)) {
603 UnwindLogMsg("Cannot set cfa");
604 } else {
605 m_full_unwind_plan_sp = lang_runtime_plan_sp;
606 if (log) {
607 StreamString active_row_strm;
608 active_row->Dump(active_row_strm, lang_runtime_plan_sp.get(), &m_thread,
609 m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
610 UnwindLogMsg("async active row: %s", active_row_strm.GetData());
611 }
612 UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
614 "initialized async frame current pc is 0x%" PRIx64
615 " cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
616 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
617 (uint64_t)m_cfa, (uint64_t)m_afa);
618
619 return;
620 }
621 }
622
623 // We've set m_frame_type and m_sym_ctx before this call.
625
626 // Try to get by with just the fast UnwindPlan if possible - the full
627 // UnwindPlan may be expensive to get (e.g. if we have to parse the entire
628 // eh_frame section of an ObjectFile for the first time.)
629
631 m_fast_unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
632 active_row =
633 m_fast_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
634 row_register_kind = m_fast_unwind_plan_sp->GetRegisterKind();
636 if (active_row && log) {
637 StreamString active_row_strm;
638 active_row->Dump(active_row_strm, m_fast_unwind_plan_sp.get(), &m_thread,
639 m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
640 UnwindLogMsg("Using fast unwind plan '%s'",
641 m_fast_unwind_plan_sp->GetSourceName().AsCString());
642 UnwindLogMsg("active row: %s", active_row_strm.GetData());
643 }
644 } else {
647 active_row = m_full_unwind_plan_sp->GetRowForFunctionOffset(
649 row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
651 if (active_row && log) {
652 StreamString active_row_strm;
653 active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(),
654 &m_thread,
655 m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
656 UnwindLogMsg("Using full unwind plan '%s'",
657 m_full_unwind_plan_sp->GetSourceName().AsCString());
658 UnwindLogMsg("active row: %s", active_row_strm.GetData());
659 }
660 }
661 }
662
663 if (!active_row) {
665 UnwindLogMsg("could not find unwind row for this pc");
666 return;
667 }
668
669 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(), m_cfa)) {
670 UnwindLogMsg("failed to get cfa");
672 return;
673 }
674
675 ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
676
677 UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
678
679 if (CheckIfLoopingStack()) {
681 if (CheckIfLoopingStack()) {
682 UnwindLogMsg("same CFA address as next frame, assuming the unwind is "
683 "looping - stopping");
685 return;
686 }
687 }
688
689 // Give the Architecture a chance to replace the UnwindPlan.
691
692 UnwindLogMsg("initialized frame current pc is 0x%" PRIx64
693 " cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
694 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
695 (uint64_t)m_cfa,
696 (uint64_t)m_afa);
697}
698
700 // If we have a bad stack setup, we can get the same CFA value multiple times
701 // -- or even more devious, we can actually oscillate between two CFA values.
702 // Detect that here and break out to avoid a possible infinite loop in lldb
703 // trying to unwind the stack. To detect when we have the same CFA value
704 // multiple times, we compare the
705 // CFA of the current
706 // frame with the 2nd next frame because in some specail case (e.g. signal
707 // hanlders, hand written assembly without ABI compliance) we can have 2
708 // frames with the same
709 // CFA (in theory we
710 // can have arbitrary number of frames with the same CFA, but more then 2 is
711 // very unlikely)
712
714 if (next_frame) {
715 RegisterContextUnwind::SharedPtr next_next_frame =
716 next_frame->GetNextFrame();
717 addr_t next_next_frame_cfa = LLDB_INVALID_ADDRESS;
718 if (next_next_frame && next_next_frame->GetCFA(next_next_frame_cfa)) {
719 if (next_next_frame_cfa == m_cfa) {
720 // We have a loop in the stack unwind
721 return true;
722 }
723 }
724 }
725 return false;
726}
727
729
731 if (m_frame_number == 0)
732 return true;
734 return true;
735 return false;
736}
737
738// Find a fast unwind plan for this frame, if possible.
739//
740// On entry to this method,
741//
742// 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame
743// if either of those are correct,
744// 2. m_sym_ctx should already be filled in, and
745// 3. m_current_pc should have the current pc value for this frame
746// 4. m_current_offset_backed_up_one should have the current byte offset into
747// the function, maybe backed up by 1, std::nullopt if unknown
748
749std::shared_ptr<const UnwindPlan>
751 ModuleSP pc_module_sp(m_current_pc.GetModule());
752
753 if (!m_current_pc.IsValid() || !pc_module_sp ||
754 pc_module_sp->GetObjectFile() == nullptr)
755 return nullptr;
756
757 if (IsFrameZero())
758 return nullptr;
759
760 FuncUnwindersSP func_unwinders_sp(
761 pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
763 if (!func_unwinders_sp)
764 return nullptr;
765
766 // If we're in _sigtramp(), unwinding past this frame requires special
767 // knowledge.
769 return nullptr;
770
771 if (std::shared_ptr<const UnwindPlan> unwind_plan_sp =
772 func_unwinders_sp->GetUnwindPlanFastUnwind(
773 *m_thread.CalculateTarget(), m_thread)) {
774 if (unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
776 return unwind_plan_sp;
777 }
778 }
779 return nullptr;
780}
781
782// On entry to this method,
783//
784// 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame
785// if either of those are correct,
786// 2. m_sym_ctx should already be filled in, and
787// 3. m_current_pc should have the current pc value for this frame
788// 4. m_current_offset_backed_up_one should have the current byte offset into
789// the function, maybe backed up by 1, std::nullopt if unknown
790
791std::shared_ptr<const UnwindPlan>
793 std::shared_ptr<const UnwindPlan> arch_default_unwind_plan_sp;
794 ExecutionContext exe_ctx(m_thread.shared_from_this());
795 Process *process = exe_ctx.GetProcessPtr();
796 ABI *abi = process ? process->GetABI().get() : nullptr;
797 if (abi) {
798 arch_default_unwind_plan_sp = abi->CreateDefaultUnwindPlan();
799 } else {
801 "unable to get architectural default UnwindPlan from ABI plugin");
802 }
803
807 // If this frame behaves like a 0th frame (currently executing or
808 // interrupted asynchronously), all registers can be retrieved.
810 }
811
812 // If we've done a jmp 0x0 / bl 0x0 (called through a null function pointer)
813 // so the pc is 0x0 in the zeroth frame, we need to use the "unwind at first
814 // instruction" arch default UnwindPlan Also, if this Process can report on
815 // memory region attributes, any non-executable region means we jumped
816 // through a bad function pointer - handle the same way as 0x0. Note, if we
817 // have a symbol context & a symbol, we don't want to follow this code path.
818 // This is for jumping to memory regions without any information available.
819
820 if ((!m_sym_ctx_valid ||
821 (m_sym_ctx.function == nullptr && m_sym_ctx.symbol == nullptr)) &&
823 uint32_t permissions;
824 addr_t current_pc_addr =
825 m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr());
826 if (current_pc_addr == 0 ||
827 (process &&
828 process->GetLoadAddressPermissions(current_pc_addr, permissions) &&
829 (permissions & ePermissionsExecutable) == 0)) {
830 if (abi) {
832 return abi->CreateFunctionEntryUnwindPlan();
833 }
834 }
835 }
836
837 // No Module for the current pc, try using the architecture default unwind.
838 ModuleSP pc_module_sp(m_current_pc.GetModule());
839 if (!m_current_pc.IsValid() || !pc_module_sp ||
840 pc_module_sp->GetObjectFile() == nullptr) {
842 return arch_default_unwind_plan_sp;
843 }
844
845 FuncUnwindersSP func_unwinders_sp;
846 if (m_sym_ctx_valid) {
847 func_unwinders_sp =
848 pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
850 }
851
852 // No FuncUnwinders available for this pc (stripped function symbols, lldb
853 // could not augment its function table with another source, like
854 // LC_FUNCTION_STARTS or eh_frame in ObjectFileMachO). See if eh_frame or the
855 // .ARM.exidx tables have unwind information for this address, else fall back
856 // to the architectural default unwind.
857 if (!func_unwinders_sp) {
859
860 if (!pc_module_sp || !pc_module_sp->GetObjectFile() ||
861 !m_current_pc.IsValid())
862 return arch_default_unwind_plan_sp;
863
864 // Even with -fomit-frame-pointer, we can try eh_frame to get back on
865 // track.
866 if (DWARFCallFrameInfo *eh_frame =
867 pc_module_sp->GetUnwindTable().GetEHFrameInfo()) {
868 if (std::unique_ptr<UnwindPlan> plan_up =
869 eh_frame->GetUnwindPlan(m_current_pc))
870 return plan_up;
871 }
872
873 ArmUnwindInfo *arm_exidx =
874 pc_module_sp->GetUnwindTable().GetArmUnwindInfo();
875 if (arm_exidx) {
876 auto unwind_plan_sp =
877 std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
878 if (arm_exidx->GetUnwindPlan(exe_ctx.GetTargetRef(), m_current_pc,
879 *unwind_plan_sp))
880 return unwind_plan_sp;
881 }
882
883 CallFrameInfo *object_file_unwind =
884 pc_module_sp->GetUnwindTable().GetObjectFileUnwindInfo();
885 if (object_file_unwind) {
886 if (std::unique_ptr<UnwindPlan> plan_up =
887 object_file_unwind->GetUnwindPlan(m_current_pc))
888 return plan_up;
889 }
890
891 return arch_default_unwind_plan_sp;
892 }
893
894 if (m_frame_type == eTrapHandlerFrame && process) {
895 m_fast_unwind_plan_sp.reset();
896
897 // On some platforms the unwind information for signal handlers is not
898 // present or correct. Give the platform plugins a chance to provide
899 // substitute plan. Otherwise, use eh_frame.
900 if (m_sym_ctx_valid) {
901 lldb::PlatformSP platform = process->GetTarget().GetPlatform();
902 if (auto unwind_plan_sp = platform->GetTrapHandlerUnwindPlan(
903 process->GetTarget().GetArchitecture().GetTriple(),
905 return unwind_plan_sp;
906 }
907
908 auto unwind_plan_sp =
909 func_unwinders_sp->GetEHFrameUnwindPlan(process->GetTarget());
910 if (!unwind_plan_sp)
911 unwind_plan_sp =
912 func_unwinders_sp->GetObjectFileUnwindPlan(process->GetTarget());
913 if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc) &&
914 unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolYes) {
915 return unwind_plan_sp;
916 }
917 }
918
919 // Ask the DynamicLoader if the eh_frame CFI should be trusted in this frame
920 // even when it's frame zero This comes up if we have hand-written functions
921 // in a Module and hand-written eh_frame. The assembly instruction
922 // inspection may fail and the eh_frame CFI were probably written with some
923 // care to do the right thing. It'd be nice if there was a way to ask the
924 // eh_frame directly if it is asynchronous (can be trusted at every
925 // instruction point) or synchronous (the normal case - only at call sites).
926 // But there is not.
927 if (process && process->GetDynamicLoader() &&
929 // We must specifically call the GetEHFrameUnwindPlan() method here --
930 // normally we would call GetUnwindPlanAtCallSite() -- because CallSite may
931 // return an unwind plan sourced from either eh_frame (that's what we
932 // intend) or compact unwind (this won't work)
933 auto unwind_plan_sp =
934 func_unwinders_sp->GetEHFrameUnwindPlan(process->GetTarget());
935 if (!unwind_plan_sp)
936 unwind_plan_sp =
937 func_unwinders_sp->GetObjectFileUnwindPlan(process->GetTarget());
938 if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
939 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because the "
940 "DynamicLoader suggested we prefer it",
941 unwind_plan_sp->GetSourceName().GetCString());
942 return unwind_plan_sp;
943 }
944 }
945
946 // Typically the NonCallSite UnwindPlan is the unwind created by inspecting
947 // the assembly language instructions
948 if (m_behaves_like_zeroth_frame && process) {
949 auto unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite(
950 process->GetTarget(), m_thread);
951 if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
952 if (unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
953 // We probably have an UnwindPlan created by inspecting assembly
954 // instructions. The assembly profilers work really well with compiler-
955 // generated functions but hand- written assembly can be problematic.
956 // We set the eh_frame based unwind plan as our fallback unwind plan if
957 // instruction emulation doesn't work out even for non call sites if it
958 // is available and use the architecture default unwind plan if it is
959 // not available. The eh_frame unwind plan is more reliable even on non
960 // call sites then the architecture default plan and for hand written
961 // assembly code it is often written in a way that it valid at all
962 // location what helps in the most common cases when the instruction
963 // emulation fails.
964 std::shared_ptr<const UnwindPlan> call_site_unwind_plan =
965 func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget(),
966 m_thread);
967 if (call_site_unwind_plan &&
968 call_site_unwind_plan.get() != unwind_plan_sp.get() &&
969 call_site_unwind_plan->GetSourceName() !=
970 unwind_plan_sp->GetSourceName()) {
971 m_fallback_unwind_plan_sp = call_site_unwind_plan;
972 } else {
973 m_fallback_unwind_plan_sp = arch_default_unwind_plan_sp;
974 }
975 }
976 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because this "
977 "is the non-call site unwind plan and this is a "
978 "zeroth frame",
979 unwind_plan_sp->GetSourceName().GetCString());
980 return unwind_plan_sp;
981 }
982
983 // If we're on the first instruction of a function, and we have an
984 // architectural default UnwindPlan for the initial instruction of a
985 // function, use that.
986 if (m_current_offset == 0) {
987 unwind_plan_sp =
988 func_unwinders_sp->GetUnwindPlanArchitectureDefaultAtFunctionEntry(
989 m_thread);
990 if (unwind_plan_sp) {
991 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because we are at "
992 "the first instruction of a function",
993 unwind_plan_sp->GetSourceName().GetCString());
994 return unwind_plan_sp;
995 }
996 }
997 }
998
999 std::shared_ptr<const UnwindPlan> unwind_plan_sp;
1000 // Typically this is unwind info from an eh_frame section intended for
1001 // exception handling; only valid at call sites
1002 if (process) {
1003 unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtCallSite(
1004 process->GetTarget(), m_thread);
1005 }
1006 if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp)) {
1007 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because this "
1008 "is the call-site unwind plan",
1009 unwind_plan_sp->GetSourceName().GetCString());
1010 return unwind_plan_sp;
1011 }
1012
1013 // We'd prefer to use an UnwindPlan intended for call sites when we're at a
1014 // call site but if we've struck out on that, fall back to using the non-
1015 // call-site assembly inspection UnwindPlan if possible.
1016 if (process) {
1017 unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite(
1018 process->GetTarget(), m_thread);
1019 }
1020 if (unwind_plan_sp &&
1021 unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
1022 // We probably have an UnwindPlan created by inspecting assembly
1023 // instructions. The assembly profilers work really well with compiler-
1024 // generated functions but hand- written assembly can be problematic. We
1025 // set the eh_frame based unwind plan as our fallback unwind plan if
1026 // instruction emulation doesn't work out even for non call sites if it is
1027 // available and use the architecture default unwind plan if it is not
1028 // available. The eh_frame unwind plan is more reliable even on non call
1029 // sites then the architecture default plan and for hand written assembly
1030 // code it is often written in a way that it valid at all location what
1031 // helps in the most common cases when the instruction emulation fails.
1032 std::shared_ptr<const UnwindPlan> call_site_unwind_plan =
1033 func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget(),
1034 m_thread);
1035 if (call_site_unwind_plan &&
1036 call_site_unwind_plan.get() != unwind_plan_sp.get() &&
1037 call_site_unwind_plan->GetSourceName() !=
1038 unwind_plan_sp->GetSourceName()) {
1039 m_fallback_unwind_plan_sp = call_site_unwind_plan;
1040 } else {
1041 m_fallback_unwind_plan_sp = arch_default_unwind_plan_sp;
1042 }
1043 }
1044
1045 if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp)) {
1046 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because we "
1047 "failed to find a call-site unwind plan that would work",
1048 unwind_plan_sp->GetSourceName().GetCString());
1049 return unwind_plan_sp;
1050 }
1051
1052 // If nothing else, use the architectural default UnwindPlan and hope that
1053 // does the job.
1054 if (arch_default_unwind_plan_sp)
1056 "frame uses %s for full UnwindPlan because we are falling back "
1057 "to the arch default plan",
1058 arch_default_unwind_plan_sp->GetSourceName().GetCString());
1059 else
1061 "Unable to find any UnwindPlan for full unwind of this frame.");
1062
1063 return arch_default_unwind_plan_sp;
1064}
1065
1069
1071 return m_thread.GetRegisterContext()->GetRegisterCount();
1072}
1073
1075 return m_thread.GetRegisterContext()->GetRegisterInfoAtIndex(reg);
1076}
1077
1079 return m_thread.GetRegisterContext()->GetRegisterSetCount();
1080}
1081
1083 return m_thread.GetRegisterContext()->GetRegisterSet(reg_set);
1084}
1085
1087 lldb::RegisterKind kind, uint32_t num) {
1088 return m_thread.GetRegisterContext()->ConvertRegisterKindToRegisterNumber(
1089 kind, num);
1090}
1091
1094 const RegisterInfo *reg_info, RegisterValue &value) {
1095 if (!IsValid())
1096 return false;
1097 bool success = false;
1098
1099 switch (regloc.type) {
1101 const RegisterInfo *other_reg_info =
1103
1104 if (!other_reg_info)
1105 return false;
1106
1107 success =
1108 m_thread.GetRegisterContext()->ReadRegister(other_reg_info, value);
1109 } break;
1111 const RegisterInfo *other_reg_info =
1113
1114 if (!other_reg_info)
1115 return false;
1116
1117 if (IsFrameZero()) {
1118 success =
1119 m_thread.GetRegisterContext()->ReadRegister(other_reg_info, value);
1120 } else {
1121 success = GetNextFrame()->ReadRegister(other_reg_info, value);
1122 }
1123 } break;
1125 auto regnum = regloc.location.reg_plus_offset.register_number;
1126 const RegisterInfo *other_reg_info =
1128
1129 if (!other_reg_info)
1130 return false;
1131
1132 if (IsFrameZero()) {
1133 success =
1134 m_thread.GetRegisterContext()->ReadRegister(other_reg_info, value);
1135 } else {
1136 success = GetNextFrame()->ReadRegister(other_reg_info, value);
1137 }
1138 if (success) {
1139 UnwindLogMsg("read (%d)'s location", regnum);
1140 value = value.GetAsUInt64(~0ull, &success) +
1142 UnwindLogMsg("success %s", success ? "yes" : "no");
1143 }
1144 } break;
1146 success =
1147 value.SetUInt(regloc.location.inferred_value, reg_info->byte_size);
1148 break;
1149
1151 break;
1153 llvm_unreachable("FIXME debugger inferior function call unwind");
1156 reg_info, regloc.location.target_memory_location, reg_info->byte_size,
1157 value));
1158 success = error.Success();
1159 } break;
1160 default:
1161 llvm_unreachable("Unknown ConcreteRegisterLocation type.");
1162 }
1163 return success;
1164}
1165
1168 const RegisterInfo *reg_info, const RegisterValue &value) {
1169 if (!IsValid())
1170 return false;
1171
1172 bool success = false;
1173
1174 switch (regloc.type) {
1176 const RegisterInfo *other_reg_info =
1178 success =
1179 m_thread.GetRegisterContext()->WriteRegister(other_reg_info, value);
1180 } break;
1182 const RegisterInfo *other_reg_info =
1184 if (IsFrameZero()) {
1185 success =
1186 m_thread.GetRegisterContext()->WriteRegister(other_reg_info, value);
1187 } else {
1188 success = GetNextFrame()->WriteRegister(other_reg_info, value);
1189 }
1190 } break;
1194 break;
1196 llvm_unreachable("FIXME debugger inferior function call unwind");
1199 reg_info, regloc.location.target_memory_location, reg_info->byte_size,
1200 value));
1201 success = error.Success();
1202 } break;
1203 default:
1204 llvm_unreachable("Unknown ConcreteRegisterLocation type.");
1205 }
1206 return success;
1207}
1208
1212
1213// After the final stack frame in a stack walk we'll get one invalid
1214// (eNotAValidFrame) stack frame -- one past the end of the stack walk. But
1215// higher-level code will need to tell the difference between "the unwind plan
1216// below this frame failed" versus "we successfully completed the stack walk"
1217// so this method helps to disambiguate that.
1218
1222
1223// A skip frame is a bogus frame on the stack -- but one where we're likely to
1224// find a real frame farther
1225// up the stack if we keep looking. It's always the second frame in an unwind
1226// (i.e. the first frame after frame zero) where unwinding can be the
1227// trickiest. Ideally we'll mark up this frame in some way so the user knows
1228// we're displaying bad data and we may have skipped one frame of their real
1229// program in the process of getting back on track.
1230
1234
1236 lldb_private::Process *process,
1238 PlatformSP platform_sp(process->GetTarget().GetPlatform());
1239 if (platform_sp) {
1240 const std::vector<ConstString> trap_handler_names(
1241 platform_sp->GetTrapHandlerSymbolNames());
1242 for (ConstString name : trap_handler_names) {
1243 if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
1244 (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name)) {
1245 return true;
1246 }
1247 }
1248 }
1249 const std::vector<ConstString> user_specified_trap_handler_names(
1250 m_parent_unwind.GetUserSpecifiedTrapHandlerFunctionNames());
1251 for (ConstString name : user_specified_trap_handler_names) {
1252 if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
1253 (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name)) {
1254 return true;
1255 }
1256 }
1257
1258 return false;
1259}
1260
1261// Search this stack frame's UnwindPlans for the AbstractRegisterLocation
1262// for this register.
1263//
1264// \param[in] lldb_regnum
1265// The register number (in the eRegisterKindLLDB register numbering)
1266// we are searching for.
1267//
1268// \param[out] kind
1269// Set to the RegisterKind of the UnwindPlan which is the basis for
1270// the returned AbstractRegisterLocation; if the location is in terms
1271// of another register number, this Kind is needed to interpret it
1272// correctly.
1273//
1274// \return
1275// An empty optional indicaTes that there was an error in processing
1276// the request.
1277//
1278// If there is no unwind rule for a volatile (caller-preserved) register,
1279// the returned AbstractRegisterLocation will be IsUndefined,
1280// indicating that we should stop searching.
1281//
1282// If there is no unwind rule for a non-volatile (callee-preserved)
1283// register, the returned AbstractRegisterLocation will be IsSame.
1284// In frame 0, IsSame means get the value from the live register context.
1285// Else it means to continue descending down the stack to more-live frames
1286// looking for a location/value.
1287//
1288// If an AbstractRegisterLocation is found in an UnwindPlan, that will
1289// be returned, with no consideration of the current ABI rules for
1290// registers. Functions using an alternate ABI calling convention
1291// will work as long as the UnwindPlans are exhaustive about what
1292// registers are volatile/non-volatile.
1293std::optional<UnwindPlan::Row::AbstractRegisterLocation>
1295 lldb::RegisterKind &kind) {
1296 RegisterNumber regnum(m_thread, eRegisterKindLLDB, lldb_regnum);
1297 Log *log = GetLog(LLDBLog::Unwind);
1298
1299 kind = eRegisterKindLLDB;
1301
1302 // First, try to find a register location via the FastUnwindPlan
1304 const UnwindPlan::Row *active_row =
1305 m_fast_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1306 if (regnum.GetAsKind(kind) == LLDB_INVALID_REGNUM) {
1307 UnwindLogMsg("could not convert lldb regnum %s (%d) into %d RegisterKind "
1308 "reg numbering scheme",
1309 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1310 (int)kind);
1311 return {};
1312 }
1313 kind = m_fast_unwind_plan_sp->GetRegisterKind();
1314 // The Fast UnwindPlan typically only provides fp & pc as we move up
1315 // the stack, without requiring additional parsing or memory reads.
1316 // It may mark all other registers as IsUndefined() because, indicating
1317 // that it doesn't know if they were spilled to stack or not.
1318 // If this case, for an IsUndefined register, we should continue on
1319 // to the Full UnwindPlan which may have more accurate information
1320 // about register locations of all registers.
1321 if (active_row &&
1322 active_row->GetRegisterInfo(regnum.GetAsKind(kind),
1323 unwindplan_regloc) &&
1324 !unwindplan_regloc.IsUndefined()) {
1326 "supplying caller's saved %s (%d)'s location using FastUnwindPlan",
1327 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1328 return unwindplan_regloc;
1329 }
1330 }
1331
1332 // Second, try to find a register location via the FullUnwindPlan.
1333 bool got_new_full_unwindplan = false;
1334 if (!m_full_unwind_plan_sp) {
1336 got_new_full_unwindplan = true;
1337 }
1341
1342 const UnwindPlan::Row *active_row =
1343 m_full_unwind_plan_sp->GetRowForFunctionOffset(
1345 kind = m_full_unwind_plan_sp->GetRegisterKind();
1346
1347 if (got_new_full_unwindplan && active_row && log) {
1348 StreamString active_row_strm;
1349 ExecutionContext exe_ctx(m_thread.shared_from_this());
1350 active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread,
1351 m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
1352 UnwindLogMsg("Using full unwind plan '%s'",
1353 m_full_unwind_plan_sp->GetSourceName().AsCString());
1354 UnwindLogMsg("active row: %s", active_row_strm.GetData());
1355 }
1356
1357 if (regnum.GetAsKind(kind) == LLDB_INVALID_REGNUM) {
1358 if (kind == eRegisterKindGeneric)
1359 UnwindLogMsg("could not convert lldb regnum %s (%d) into "
1360 "eRegisterKindGeneric reg numbering scheme",
1361 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1362 else
1363 UnwindLogMsg("could not convert lldb regnum %s (%d) into %d "
1364 "RegisterKind reg numbering scheme",
1365 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1366 (int)kind);
1367 return {};
1368 }
1369
1370 if (regnum.IsValid() && active_row &&
1371 active_row->GetRegisterInfo(regnum.GetAsKind(kind),
1372 unwindplan_regloc)) {
1374 "supplying caller's saved %s (%d)'s location using %s UnwindPlan",
1375 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1376 m_full_unwind_plan_sp->GetSourceName().GetCString());
1377 return unwindplan_regloc;
1378 }
1379
1380 // When asking for the caller's pc, and did not find a register
1381 // location for PC above in the UnwindPlan. Check if we have a
1382 // Return Address register on this target.
1383 //
1384 // On a Return Address Register architecture like arm/mips/riscv,
1385 // the caller's pc is in the RA register, and will be spilled to
1386 // stack before any other function is called. If no function
1387 // has been called yet, the return address may still be in the
1388 // live RA reg.
1389 //
1390 // There's a lot of variety of what we might see in an UnwindPlan.
1391 // We may have
1392 // ra=IsSame {unncessary}
1393 // ra=StackAddr {caller's return addr spilled to stack}
1394 // or no reg location for pc or ra at all, in a frameless function -
1395 // the caller's return address is in live ra reg.
1396 //
1397 // If a function has been interrupted in a non-call way --
1398 // async signal/sigtramp, or a hardware exception / interrupt / fault --
1399 // then the "pc" and "ra" are two distinct values, and must be
1400 // handled separately. The "pc" is the pc value at the point
1401 // the function was interrupted. The "ra" is the return address
1402 // register value at that point.
1403 // The UnwindPlan for the sigtramp/trap handler will normally have
1404 // register loations for both pc and lr, and so we'll have already
1405 // fetched them above.
1406 if (pc_regnum.IsValid() && pc_regnum == regnum) {
1407 uint32_t return_address_regnum = LLDB_INVALID_REGNUM;
1408
1409 // Get the return address register number from the UnwindPlan
1410 // or the register set definition.
1411 if (m_full_unwind_plan_sp->GetReturnAddressRegister() !=
1413 return_address_regnum =
1414 m_full_unwind_plan_sp->GetReturnAddressRegister();
1415 } else {
1416 RegisterNumber arch_default_ra_regnum(m_thread, eRegisterKindGeneric,
1418 return_address_regnum = arch_default_ra_regnum.GetAsKind(kind);
1419 }
1420
1421 // This system is using a return address register.
1422 if (return_address_regnum != LLDB_INVALID_REGNUM) {
1423 RegisterNumber return_address_reg;
1424 return_address_reg.init(m_thread,
1425 m_full_unwind_plan_sp->GetRegisterKind(),
1426 return_address_regnum);
1427 UnwindLogMsg("requested caller's saved PC but this UnwindPlan uses a "
1428 "RA reg; getting %s (%d) instead",
1429 return_address_reg.GetName(),
1430 return_address_reg.GetAsKind(eRegisterKindLLDB));
1431
1432 // Do we have a location for the ra register?
1433 if (active_row &&
1434 active_row->GetRegisterInfo(return_address_reg.GetAsKind(kind),
1435 unwindplan_regloc)) {
1436 UnwindLogMsg("supplying caller's saved %s (%d)'s location using "
1437 "%s UnwindPlan",
1438 return_address_reg.GetName(),
1439 return_address_reg.GetAsKind(eRegisterKindLLDB),
1440 m_full_unwind_plan_sp->GetSourceName().GetCString());
1441 // If we have "ra=IsSame", rewrite to "ra=InRegister(ra)" because the
1442 // calling function thinks it is fetching "pc" and if we return an
1443 // IsSame register location, it will try to read pc.
1444 if (unwindplan_regloc.IsSame())
1445 unwindplan_regloc.SetInRegister(return_address_reg.GetAsKind(kind));
1446 return unwindplan_regloc;
1447 } else {
1448 // No unwind rule for the return address reg on frame 0, or an
1449 // interrupted function, means that the caller's address is still in
1450 // RA reg (0th frame) or the trap handler below this one (sigtramp
1451 // etc) has a save location for the RA reg.
1452 if (BehavesLikeZerothFrame()) {
1453 unwindplan_regloc.SetInRegister(return_address_reg.GetAsKind(kind));
1454 return unwindplan_regloc;
1455 }
1456 }
1457 }
1458 }
1459 }
1460
1461 ExecutionContext exe_ctx(m_thread.shared_from_this());
1462 Process *process = exe_ctx.GetProcessPtr();
1463
1464 // Third, try finding a register location via the ABI
1465 // FallbackRegisterLocation.
1466 //
1467 // If the UnwindPlan failed to give us an unwind location for this
1468 // register, we may be able to fall back to some ABI-defined default. For
1469 // example, some ABIs allow to determine the caller's SP via the CFA. Also,
1470 // the ABI willset volatile registers to the undefined state.
1471 ABI *abi = process ? process->GetABI().get() : nullptr;
1472 if (abi) {
1473 const RegisterInfo *reg_info =
1475 if (reg_info &&
1476 abi->GetFallbackRegisterLocation(reg_info, unwindplan_regloc)) {
1477 if (!unwindplan_regloc.IsUndefined())
1479 "supplying caller's saved %s (%d)'s location using ABI default",
1480 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1481 // ABI defined volatile registers with no register location
1482 // will be returned as IsUndefined, stopping the search down
1483 // the stack.
1484 return unwindplan_regloc;
1485 }
1486 }
1487
1488 // We have no AbstractRegisterLocation, and the ABI says this is a
1489 // non-volatile / callee-preserved register. Continue down the stack
1490 // or to frame 0 & the live RegisterContext.
1491 std::string unwindplan_name;
1493 unwindplan_name += "via '";
1494 unwindplan_name += m_full_unwind_plan_sp->GetSourceName().AsCString();
1495 unwindplan_name += "'";
1496 }
1497 UnwindLogMsg("no save location for %s (%d) %s", regnum.GetName(),
1498 regnum.GetAsKind(eRegisterKindLLDB), unwindplan_name.c_str());
1499
1500 unwindplan_regloc.SetSame();
1501 return unwindplan_regloc;
1502}
1503
1504// Answer the question: Where did THIS frame save the CALLER frame ("previous"
1505// frame)'s register value?
1506
1509 uint32_t lldb_regnum,
1511 RegisterNumber regnum(m_thread, eRegisterKindLLDB, lldb_regnum);
1512 Log *log = GetLog(LLDBLog::Unwind);
1513
1514 // Have we already found this register location?
1515 if (!m_registers.empty()) {
1516 auto iterator = m_registers.find(regnum.GetAsKind(eRegisterKindLLDB));
1517 if (iterator != m_registers.end()) {
1518 regloc = iterator->second;
1519 UnwindLogMsg("supplying caller's saved %s (%d)'s location, cached",
1520 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1522 }
1523 }
1524
1525 RegisterKind abs_regkind;
1526 std::optional<UnwindPlan::Row::AbstractRegisterLocation> abs_regloc =
1527 GetAbstractRegisterLocation(lldb_regnum, abs_regkind);
1528
1529 if (!abs_regloc)
1531
1532 if (abs_regloc->IsUndefined()) {
1534 "did not supply reg location for %s (%d) because it is volatile",
1535 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1537 }
1538
1539 ExecutionContext exe_ctx(m_thread.shared_from_this());
1540 Process *process = exe_ctx.GetProcessPtr();
1541 // abs_regloc has valid contents about where to retrieve the register
1542 if (abs_regloc->IsUnspecified()) {
1545 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc;
1546 UnwindLogMsg("save location for %s (%d) is unspecified, continue searching",
1547 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1549 }
1550
1551 if (abs_regloc->IsSame()) {
1552 if (IsFrameZero()) {
1553 regloc.type =
1556 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1557 UnwindLogMsg("supplying caller's register %s (%d) from the live "
1558 "RegisterContext at frame 0",
1559 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1561 }
1562 // PC/RA reg don't follow the usual "callee-saved aka non-volatile" versus
1563 // "caller saved aka volatile" system. A stack frame can provide its caller
1564 // return address, but if we don't find a rule for pc/RA mid-stack, we
1565 // never want to iterate further down the stack looking for it.
1566 // Defensively prevent iterating down the stack for these two.
1567 if (!BehavesLikeZerothFrame() &&
1570 UnwindLogMsg("register %s (%d) is marked as 'IsSame' - it is a pc or "
1571 "return address reg on a frame which does not have all "
1572 "registers available -- treat as if we have no information",
1573 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1575 }
1576
1579 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1581 "supplying caller's register %s (%d) value is unmodified in this frame",
1582 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1584 }
1585
1586 if (abs_regloc->IsCFAPlusOffset()) {
1587 int offset = abs_regloc->GetOffset();
1589 regloc.location.inferred_value = m_cfa + offset;
1590 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1591 UnwindLogMsg("supplying caller's register %s (%d), value is CFA plus "
1592 "offset %d [value is 0x%" PRIx64 "]",
1593 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1594 regloc.location.inferred_value);
1596 }
1597
1598 if (abs_regloc->IsAtCFAPlusOffset()) {
1599 int offset = abs_regloc->GetOffset();
1600 regloc.type =
1602 regloc.location.target_memory_location = m_cfa + offset;
1603 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1604 UnwindLogMsg("supplying caller's register %s (%d) from the stack, saved at "
1605 "CFA plus offset %d [saved at 0x%" PRIx64 "]",
1606 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1609 }
1610
1611 if (abs_regloc->IsAFAPlusOffset()) {
1614
1615 int offset = abs_regloc->GetOffset();
1617 regloc.location.inferred_value = m_afa + offset;
1618 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1619 UnwindLogMsg("supplying caller's register %s (%d), value is AFA plus "
1620 "offset %d [value is 0x%" PRIx64 "]",
1621 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1622 regloc.location.inferred_value);
1624 }
1625
1626 if (abs_regloc->IsAtAFAPlusOffset()) {
1629
1630 int offset = abs_regloc->GetOffset();
1631 regloc.type =
1633 regloc.location.target_memory_location = m_afa + offset;
1634 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1635 UnwindLogMsg("supplying caller's register %s (%d) from the stack, saved at "
1636 "AFA plus offset %d [saved at 0x%" PRIx64 "]",
1637 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1640 }
1641
1642 if (abs_regloc->IsInOtherRegister()) {
1643 RegisterNumber row_regnum(m_thread, abs_regkind,
1644 abs_regloc->GetRegisterNumber());
1645 if (row_regnum.GetAsKind(eRegisterKindLLDB) == LLDB_INVALID_REGNUM) {
1646 UnwindLogMsg("could not supply caller's %s (%d) location - was saved in "
1647 "another reg but couldn't convert that regnum",
1648 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1650 }
1653 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1655 "supplying caller's register %s (%d), saved in register %s (%d)",
1656 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1657 row_regnum.GetName(), row_regnum.GetAsKind(eRegisterKindLLDB));
1659 }
1660
1661 if (abs_regloc->IsDWARFExpression() || abs_regloc->IsAtDWARFExpression()) {
1662 DataExtractor dwarfdata(abs_regloc->GetDWARFExpressionBytes(),
1663 abs_regloc->GetDWARFExpressionLength(),
1664 process->GetByteOrder(),
1665 process->GetAddressByteSize());
1666 ModuleSP opcode_ctx;
1667 DWARFExpressionList dwarfexpr(opcode_ctx, dwarfdata, nullptr);
1668 dwarfexpr.GetMutableExpressionAtAddress()->SetRegisterKind(abs_regkind);
1669 Value cfa_val = Scalar(m_cfa);
1671 llvm::Expected<Value> result =
1672 dwarfexpr.Evaluate(&exe_ctx, this, 0, &cfa_val, nullptr);
1673 if (!result) {
1674 LLDB_LOG_ERROR(log, result.takeError(),
1675 "DWARF expression failed to evaluate: {0}");
1676 } else {
1677 addr_t val;
1678 val = result->GetScalar().ULongLong();
1679 if (abs_regloc->IsDWARFExpression()) {
1680 regloc.type =
1682 regloc.location.inferred_value = val;
1683 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1684 UnwindLogMsg("supplying caller's register %s (%d) via DWARF expression "
1685 "(IsDWARFExpression)",
1686 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1688 } else {
1689 regloc.type = UnwindLLDB::ConcreteRegisterLocation::
1690 eRegisterSavedAtMemoryLocation;
1691 regloc.location.target_memory_location = val;
1692 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1693 UnwindLogMsg("supplying caller's register %s (%d) via DWARF expression "
1694 "(IsAtDWARFExpression)",
1695 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1697 }
1698 }
1699 UnwindLogMsg("tried to use IsDWARFExpression or IsAtDWARFExpression for %s "
1700 "(%d) but failed",
1701 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1703 }
1704
1705 if (abs_regloc->IsConstant()) {
1707 regloc.location.inferred_value = abs_regloc->GetConstant();
1708 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1709 UnwindLogMsg("supplying caller's register %s (%d) via constant value",
1710 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1712 }
1713
1714 UnwindLogMsg("no save location for %s (%d) in this stack frame",
1715 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1716
1717 // FIXME UnwindPlan::Row types atDWARFExpression and isDWARFExpression are
1718 // unsupported.
1719
1721}
1722
1725 return {};
1726 ProcessSP process_sp = m_thread.GetProcess();
1727 if (!process_sp)
1728 return {};
1729
1730 UnwindPlanSP arch_override_plan_sp;
1731 if (Architecture *arch = process_sp->GetTarget().GetArchitecturePlugin())
1732 arch_override_plan_sp =
1733 arch->GetArchitectureUnwindPlan(m_thread, this, m_full_unwind_plan_sp);
1734
1735 if (arch_override_plan_sp) {
1736 m_full_unwind_plan_sp = arch_override_plan_sp;
1738 m_registers.clear();
1739 if (GetLog(LLDBLog::Unwind)) {
1741 "Replacing Full Unwindplan with Architecture UnwindPlan, '%s'",
1742 m_full_unwind_plan_sp->GetSourceName().AsCString());
1743 const UnwindPlan::Row *active_row =
1744 m_full_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1745 if (active_row) {
1746 StreamString active_row_strm;
1747 active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(),
1748 &m_thread,
1749 m_start_pc.GetLoadAddress(&process_sp->GetTarget()));
1750 UnwindLogMsg("%s", active_row_strm.GetData());
1751 }
1752 }
1753 }
1754
1755 return {};
1756}
1757
1758// TryFallbackUnwindPlan() -- this method is a little tricky.
1759//
1760// When this is called, the frame above -- the caller frame, the "previous"
1761// frame -- is invalid or bad.
1762//
1763// Instead of stopping the stack walk here, we'll try a different UnwindPlan
1764// and see if we can get a valid frame above us.
1765//
1766// This most often happens when an unwind plan based on assembly instruction
1767// inspection is not correct -- mostly with hand-written assembly functions or
1768// functions where the stack frame is set up "out of band", e.g. the kernel
1769// saved the register context and then called an asynchronous trap handler like
1770// _sigtramp.
1771//
1772// Often in these cases, if we just do a dumb stack walk we'll get past this
1773// tricky frame and our usual techniques can continue to be used.
1774
1776 if (m_fallback_unwind_plan_sp == nullptr)
1777 return false;
1778
1779 if (m_full_unwind_plan_sp == nullptr)
1780 return false;
1781
1783 m_full_unwind_plan_sp->GetSourceName() ==
1784 m_fallback_unwind_plan_sp->GetSourceName()) {
1785 return false;
1786 }
1787
1788 // If a compiler generated unwind plan failed, trying the arch default
1789 // unwindplan isn't going to do any better.
1790 if (m_full_unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolYes)
1791 return false;
1792
1793 // Get the caller's pc value and our own CFA value. Swap in the fallback
1794 // unwind plan, re-fetch the caller's pc value and CFA value. If they're the
1795 // same, then the fallback unwind plan provides no benefit.
1796
1799
1800 addr_t old_caller_pc_value = LLDB_INVALID_ADDRESS;
1801 addr_t new_caller_pc_value = LLDB_INVALID_ADDRESS;
1804 regloc) ==
1806 const RegisterInfo *reg_info =
1808 if (reg_info) {
1809 RegisterValue reg_value;
1810 if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
1811 old_caller_pc_value = reg_value.GetAsUInt64();
1812 if (ProcessSP process_sp = m_thread.GetProcess()) {
1813 if (ABISP abi_sp = process_sp->GetABI())
1814 old_caller_pc_value = abi_sp->FixCodeAddress(old_caller_pc_value);
1815 }
1816 }
1817 }
1818 }
1819
1820 // This is a tricky wrinkle! If SavedLocationForRegister() detects a really
1821 // impossible register location for the full unwind plan, it may call
1822 // ForceSwitchToFallbackUnwindPlan() which in turn replaces the full
1823 // unwindplan with the fallback... in short, we're done, we're using the
1824 // fallback UnwindPlan. We checked if m_fallback_unwind_plan_sp was nullptr
1825 // at the top -- the only way it became nullptr since then is via
1826 // SavedLocationForRegister().
1827 if (m_fallback_unwind_plan_sp == nullptr)
1828 return true;
1829
1830 // Switch the full UnwindPlan to be the fallback UnwindPlan. If we decide
1831 // this isn't working, we need to restore. We'll also need to save & restore
1832 // the value of the m_cfa ivar. Save is down below a bit in 'old_cfa'.
1833 std::shared_ptr<const UnwindPlan> original_full_unwind_plan_sp =
1835 addr_t old_cfa = m_cfa;
1836 addr_t old_afa = m_afa;
1837
1838 m_registers.clear();
1839
1841
1842 const UnwindPlan::Row *active_row =
1843 m_fallback_unwind_plan_sp->GetRowForFunctionOffset(
1845
1846 if (active_row &&
1847 active_row->GetCFAValue().GetValueType() !=
1849 addr_t new_cfa;
1850 if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1851 active_row->GetCFAValue(), new_cfa) ||
1852 new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1853 UnwindLogMsg("failed to get cfa with fallback unwindplan");
1855 m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1856 return false;
1857 }
1858 m_cfa = new_cfa;
1859
1861 active_row->GetAFAValue(), m_afa);
1862
1864 regloc) ==
1866 const RegisterInfo *reg_info =
1868 if (reg_info) {
1869 RegisterValue reg_value;
1870 if (ReadRegisterValueFromRegisterLocation(regloc, reg_info,
1871 reg_value)) {
1872 new_caller_pc_value = reg_value.GetAsUInt64();
1873 if (ProcessSP process_sp = m_thread.GetProcess()) {
1874 if (ABISP abi_sp = process_sp->GetABI())
1875 new_caller_pc_value = abi_sp->FixCodeAddress(new_caller_pc_value);
1876 }
1877 }
1878 }
1879 }
1880
1881 if (new_caller_pc_value == LLDB_INVALID_ADDRESS) {
1882 UnwindLogMsg("failed to get a pc value for the caller frame with the "
1883 "fallback unwind plan");
1885 m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1886 m_cfa = old_cfa;
1887 m_afa = old_afa;
1888 return false;
1889 }
1890
1891 if (old_caller_pc_value == new_caller_pc_value &&
1892 m_cfa == old_cfa &&
1893 m_afa == old_afa) {
1894 UnwindLogMsg("fallback unwind plan got the same values for this frame "
1895 "CFA and caller frame pc, not using");
1897 m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1898 return false;
1899 }
1900
1901 UnwindLogMsg("trying to unwind from this function with the UnwindPlan '%s' "
1902 "because UnwindPlan '%s' failed.",
1903 m_fallback_unwind_plan_sp->GetSourceName().GetCString(),
1904 original_full_unwind_plan_sp->GetSourceName().GetCString());
1905
1906 // We've copied the fallback unwind plan into the full - now clear the
1907 // fallback.
1910 }
1911
1912 return true;
1913}
1914
1916 if (m_fallback_unwind_plan_sp == nullptr)
1917 return false;
1918
1919 if (m_full_unwind_plan_sp == nullptr)
1920 return false;
1921
1923 m_full_unwind_plan_sp->GetSourceName() ==
1924 m_fallback_unwind_plan_sp->GetSourceName()) {
1925 return false;
1926 }
1927
1928 const UnwindPlan::Row *active_row =
1929 m_fallback_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1930
1931 if (active_row &&
1932 active_row->GetCFAValue().GetValueType() !=
1934 addr_t new_cfa;
1935 if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1936 active_row->GetCFAValue(), new_cfa) ||
1937 new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1938 UnwindLogMsg("failed to get cfa with fallback unwindplan");
1940 return false;
1941 }
1942
1944 active_row->GetAFAValue(), m_afa);
1945
1948
1949 m_registers.clear();
1950
1951 m_cfa = new_cfa;
1952
1954
1955 UnwindLogMsg("switched unconditionally to the fallback unwindplan %s",
1956 m_full_unwind_plan_sp->GetSourceName().GetCString());
1957 return true;
1958 }
1959 return false;
1960}
1961
1963 std::shared_ptr<const UnwindPlan> unwind_plan) {
1964 if (unwind_plan->GetUnwindPlanForSignalTrap() != eLazyBoolYes) {
1965 // Unwind plan does not indicate trap handler. Do nothing. We may
1966 // already be flagged as trap handler flag due to the symbol being
1967 // in the trap handler symbol list, and that should take precedence.
1968 return;
1969 } else if (m_frame_type != eNormalFrame) {
1970 // If this is already a trap handler frame, nothing to do.
1971 // If this is a skip or debug or invalid frame, don't override that.
1972 return;
1973 }
1974
1976 UnwindLogMsg("This frame is marked as a trap handler via its UnwindPlan");
1977
1979 // We backed up the pc by 1 to compute the symbol context, but
1980 // now need to undo that because the pc of the trap handler
1981 // frame may in fact be the first instruction of a signal return
1982 // trampoline, rather than the instruction after a call. This
1983 // happens on systems where the signal handler dispatch code, rather
1984 // than calling the handler and being returned to, jumps to the
1985 // handler after pushing the address of a return trampoline on the
1986 // stack -- on these systems, when the handler returns, control will
1987 // be transferred to the return trampoline, so that's the best
1988 // symbol we can present in the callstack.
1989 UnwindLogMsg("Resetting current offset and re-doing symbol lookup; "
1990 "old symbol was %s",
1991 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
1993
1994 m_sym_ctx_valid = m_current_pc.ResolveFunctionScope(m_sym_ctx);
1995
1996 UnwindLogMsg("Symbol is now %s",
1997 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
1998
1999 ExecutionContext exe_ctx(m_thread.shared_from_this());
2000 Process *process = exe_ctx.GetProcessPtr();
2001 Target *target = &process->GetTarget();
2002
2003 if (m_sym_ctx_valid) {
2004 m_start_pc = m_sym_ctx.GetFunctionOrSymbolAddress();
2005 m_current_offset = m_current_pc.GetLoadAddress(target) -
2006 m_start_pc.GetLoadAddress(target);
2007 }
2008 }
2009}
2010
2012 lldb::RegisterKind row_register_kind, const UnwindPlan::Row::FAValue &fa,
2013 addr_t &address) {
2014 RegisterValue reg_value;
2015
2016 address = LLDB_INVALID_ADDRESS;
2017 addr_t cfa_reg_contents;
2018 ABISP abi_sp = m_thread.GetProcess()->GetABI();
2019
2020 switch (fa.GetValueType()) {
2022 UnwindLogMsg("CFA value via dereferencing reg");
2023 RegisterNumber regnum_to_deref(m_thread, row_register_kind,
2024 fa.GetRegisterNumber());
2025 addr_t reg_to_deref_contents;
2026 if (ReadGPRValue(regnum_to_deref, reg_to_deref_contents)) {
2027 const RegisterInfo *reg_info =
2029 RegisterValue reg_value;
2030 if (reg_info) {
2032 reg_info, reg_to_deref_contents, reg_info->byte_size, reg_value);
2033 if (error.Success()) {
2034 address = reg_value.GetAsUInt64();
2036 "CFA value via dereferencing reg %s (%d): reg has val 0x%" PRIx64
2037 ", CFA value is 0x%" PRIx64,
2038 regnum_to_deref.GetName(),
2039 regnum_to_deref.GetAsKind(eRegisterKindLLDB),
2040 reg_to_deref_contents, address);
2041 return true;
2042 } else {
2043 UnwindLogMsg("Tried to deref reg %s (%d) [0x%" PRIx64
2044 "] but memory read failed.",
2045 regnum_to_deref.GetName(),
2046 regnum_to_deref.GetAsKind(eRegisterKindLLDB),
2047 reg_to_deref_contents);
2048 }
2049 }
2050 }
2051 break;
2052 }
2054 UnwindLogMsg("CFA value via register plus offset");
2055 RegisterNumber cfa_reg(m_thread, row_register_kind,
2056 fa.GetRegisterNumber());
2057 if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
2058 if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
2059 cfa_reg_contents == 1) {
2061 "Got an invalid CFA register value - reg %s (%d), value 0x%" PRIx64,
2062 cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
2063 cfa_reg_contents);
2064 return false;
2065 }
2066 address = cfa_reg_contents + fa.GetOffset();
2068 "CFA is 0x%" PRIx64 ": Register %s (%d) contents are 0x%" PRIx64
2069 ", offset is %d",
2070 address, cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
2071 cfa_reg_contents, fa.GetOffset());
2072 return true;
2073 } else
2074 UnwindLogMsg("unable to read CFA register %s (%d)", cfa_reg.GetName(),
2075 cfa_reg.GetAsKind(eRegisterKindLLDB));
2076 break;
2077 }
2079 UnwindLogMsg("CFA value via DWARF expression");
2080 ExecutionContext exe_ctx(m_thread.shared_from_this());
2081 Process *process = exe_ctx.GetProcessPtr();
2084 process->GetByteOrder(),
2085 process->GetAddressByteSize());
2086 ModuleSP opcode_ctx;
2087 DWARFExpressionList dwarfexpr(opcode_ctx, dwarfdata, nullptr);
2089 row_register_kind);
2090 llvm::Expected<Value> result =
2091 dwarfexpr.Evaluate(&exe_ctx, this, 0, nullptr, nullptr);
2092 if (result) {
2093 address = result->GetScalar().ULongLong();
2094 UnwindLogMsg("CFA value set by DWARF expression is 0x%" PRIx64,
2095 address);
2096 return true;
2097 }
2098 UnwindLogMsg("Failed to set CFA value via DWARF expression: %s",
2099 llvm::toString(result.takeError()).c_str());
2100 break;
2101 }
2103 UnwindLogMsg("CFA value via heuristic search");
2104 Process &process = *m_thread.GetProcess();
2105 lldb::addr_t return_address_hint = GetReturnAddressHint(fa.GetOffset());
2106 if (return_address_hint == LLDB_INVALID_ADDRESS)
2107 return false;
2108 const unsigned max_iterations = 256;
2109 for (unsigned i = 0; i < max_iterations; ++i) {
2110 Status st;
2111 lldb::addr_t candidate_addr =
2112 return_address_hint + i * process.GetAddressByteSize();
2113 lldb::addr_t candidate =
2114 process.ReadPointerFromMemory(candidate_addr, st);
2115 if (st.Fail()) {
2116 UnwindLogMsg("Cannot read memory at 0x%" PRIx64 ": %s", candidate_addr,
2117 st.AsCString());
2118 return false;
2119 }
2120 Address addr;
2121 uint32_t permissions;
2122 if (process.GetLoadAddressPermissions(candidate, permissions) &&
2123 permissions & lldb::ePermissionsExecutable) {
2124 address = candidate_addr;
2125 UnwindLogMsg("Heuristically found CFA: 0x%" PRIx64, address);
2126 return true;
2127 }
2128 }
2129 UnwindLogMsg("No suitable CFA found");
2130 break;
2131 }
2133 address = fa.GetConstant();
2134 UnwindLogMsg("CFA value set by constant is 0x%" PRIx64, address);
2135 return true;
2136 }
2137 default:
2138 return false;
2139 }
2140 return false;
2141}
2142
2144 addr_t hint;
2146 return LLDB_INVALID_ADDRESS;
2147 if (!m_sym_ctx.module_sp || !m_sym_ctx.symbol)
2148 return LLDB_INVALID_ADDRESS;
2149 if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2150 hint = abi_sp->FixCodeAddress(hint);
2151
2152 hint += plan_offset;
2153
2154 if (auto next = GetNextFrame()) {
2155 if (!next->m_sym_ctx.module_sp || !next->m_sym_ctx.symbol)
2156 return LLDB_INVALID_ADDRESS;
2157 if (auto expected_size =
2158 next->m_sym_ctx.module_sp->GetSymbolFile()->GetParameterStackSize(
2159 *next->m_sym_ctx.symbol))
2160 hint += *expected_size;
2161 else {
2162 UnwindLogMsgVerbose("Could not retrieve parameter size: %s",
2163 llvm::toString(expected_size.takeError()).c_str());
2164 return LLDB_INVALID_ADDRESS;
2165 }
2166 }
2167 return hint;
2168}
2169
2170// Retrieve a general purpose register value for THIS frame, as saved by the
2171// NEXT frame, i.e. the frame that
2172// this frame called. e.g.
2173//
2174// foo () { }
2175// bar () { foo (); }
2176// main () { bar (); }
2177//
2178// stopped in foo() so
2179// frame 0 - foo
2180// frame 1 - bar
2181// frame 2 - main
2182// and this RegisterContext is for frame 1 (bar) - if we want to get the pc
2183// value for frame 1, we need to ask
2184// where frame 0 (the "next" frame) saved that and retrieve the value.
2185
2187 uint32_t regnum, addr_t &value) {
2188 if (!IsValid())
2189 return false;
2190
2191 uint32_t lldb_regnum;
2192 if (register_kind == eRegisterKindLLDB) {
2193 lldb_regnum = regnum;
2194 } else if (!m_thread.GetRegisterContext()->ConvertBetweenRegisterKinds(
2195 register_kind, regnum, eRegisterKindLLDB, lldb_regnum)) {
2196 return false;
2197 }
2198
2199 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(lldb_regnum);
2200 assert(reg_info);
2201 if (!reg_info) {
2203 "Could not find RegisterInfo definition for lldb register number %d",
2204 lldb_regnum);
2205 return false;
2206 }
2207
2208 uint32_t generic_regnum = LLDB_INVALID_REGNUM;
2209 if (register_kind == eRegisterKindGeneric)
2210 generic_regnum = regnum;
2211 else
2212 m_thread.GetRegisterContext()->ConvertBetweenRegisterKinds(
2213 register_kind, regnum, eRegisterKindGeneric, generic_regnum);
2214 ABISP abi_sp = m_thread.GetProcess()->GetABI();
2215
2216 RegisterValue reg_value;
2217 // if this is frame 0 (currently executing frame), get the requested reg
2218 // contents from the actual thread registers
2219 if (IsFrameZero()) {
2220 if (m_thread.GetRegisterContext()->ReadRegister(reg_info, reg_value)) {
2221 value = reg_value.GetAsUInt64();
2222 if (abi_sp && generic_regnum != LLDB_INVALID_REGNUM) {
2223 if (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
2224 generic_regnum == LLDB_REGNUM_GENERIC_RA)
2225 value = abi_sp->FixCodeAddress(value);
2226 }
2227 return true;
2228 }
2229 return false;
2230 }
2231
2232 bool pc_register = false;
2233 if (generic_regnum != LLDB_INVALID_REGNUM &&
2234 (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
2235 generic_regnum == LLDB_REGNUM_GENERIC_RA))
2236 pc_register = true;
2237
2239 if (!m_parent_unwind.SearchForSavedLocationForRegister(
2240 lldb_regnum, regloc, m_frame_number - 1, pc_register)) {
2241 return false;
2242 }
2243 if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
2244 value = reg_value.GetAsUInt64();
2245 if (pc_register) {
2246 if (ABISP abi_sp = m_thread.GetProcess()->GetABI()) {
2247 value = abi_sp->FixCodeAddress(value);
2248 }
2249 }
2250 return true;
2251 }
2252 return false;
2253}
2254
2256 addr_t &value) {
2257 return ReadGPRValue(regnum.GetRegisterKind(), regnum.GetRegisterNumber(),
2258 value);
2259}
2260
2261// Find the value of a register in THIS frame
2262
2264 RegisterValue &value) {
2265 if (!IsValid())
2266 return false;
2267
2268 const uint32_t lldb_regnum = reg_info->kinds[eRegisterKindLLDB];
2269 UnwindLogMsgVerbose("looking for register saved location for reg %d",
2270 lldb_regnum);
2271
2272 // If this is the 0th frame, hand this over to the live register context
2273 if (IsFrameZero()) {
2274 UnwindLogMsgVerbose("passing along to the live register context for reg %d",
2275 lldb_regnum);
2276 return m_thread.GetRegisterContext()->ReadRegister(reg_info, value);
2277 }
2278
2279 bool is_pc_regnum = false;
2282 is_pc_regnum = true;
2283 }
2284
2286 // Find out where the NEXT frame saved THIS frame's register contents
2287 if (!m_parent_unwind.SearchForSavedLocationForRegister(
2288 lldb_regnum, regloc, m_frame_number - 1, is_pc_regnum))
2289 return false;
2290
2291 bool result = ReadRegisterValueFromRegisterLocation(regloc, reg_info, value);
2292 if (result) {
2293 if (is_pc_regnum && value.GetType() == RegisterValue::eTypeUInt64) {
2294 addr_t reg_value = value.GetAsUInt64(LLDB_INVALID_ADDRESS);
2295 if (reg_value != LLDB_INVALID_ADDRESS) {
2296 if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2297 value = abi_sp->FixCodeAddress(reg_value);
2298 }
2299 }
2300 }
2301 return result;
2302}
2303
2305 const RegisterValue &value) {
2306 if (!IsValid())
2307 return false;
2308
2309 const uint32_t lldb_regnum = reg_info->kinds[eRegisterKindLLDB];
2310 UnwindLogMsgVerbose("looking for register saved location for reg %d",
2311 lldb_regnum);
2312
2313 // If this is the 0th frame, hand this over to the live register context
2314 if (IsFrameZero()) {
2315 UnwindLogMsgVerbose("passing along to the live register context for reg %d",
2316 lldb_regnum);
2317 return m_thread.GetRegisterContext()->WriteRegister(reg_info, value);
2318 }
2319
2321 // Find out where the NEXT frame saved THIS frame's register contents
2322 if (!m_parent_unwind.SearchForSavedLocationForRegister(
2323 lldb_regnum, regloc, m_frame_number - 1, false))
2324 return false;
2325
2326 return WriteRegisterValueToRegisterLocation(regloc, reg_info, value);
2327}
2328
2329// Don't need to implement this one
2331 lldb::WritableDataBufferSP &data_sp) {
2332 return false;
2333}
2334
2335// Don't need to implement this one
2337 const lldb::DataBufferSP &data_sp) {
2338 return false;
2339}
2340
2341// Retrieve the pc value for THIS from
2342
2344 if (!IsValid()) {
2345 return false;
2346 }
2347 if (m_cfa == LLDB_INVALID_ADDRESS) {
2348 return false;
2349 }
2350 cfa = m_cfa;
2351 return true;
2352}
2353
2356 if (m_frame_number == 0)
2357 return regctx;
2358 return m_parent_unwind.GetRegisterContextForFrameNum(m_frame_number - 1);
2359}
2360
2365
2366// Retrieve the address of the start of the function of THIS frame
2367
2369 if (!IsValid())
2370 return false;
2371
2372 if (!m_start_pc.IsValid()) {
2373 bool read_successfully = ReadPC (start_pc);
2374 if (read_successfully)
2375 {
2376 ProcessSP process_sp (m_thread.GetProcess());
2377 if (process_sp)
2378 {
2379 if (ABISP abi_sp = process_sp->GetABI())
2380 start_pc = abi_sp->FixCodeAddress(start_pc);
2381 }
2382 }
2383 return read_successfully;
2384 }
2385 start_pc = m_start_pc.GetLoadAddress(CalculateTarget().get());
2386 return true;
2387}
2388
2389// Retrieve the current pc value for THIS frame, as saved by the NEXT frame.
2390
2392 if (!IsValid())
2393 return false;
2394
2395 bool above_trap_handler = false;
2396 if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
2398 above_trap_handler = true;
2399
2401 // A pc value of 0 or 1 is impossible in the middle of the stack -- it
2402 // indicates the end of a stack walk.
2403 // On the currently executing frame (or such a frame interrupted
2404 // asynchronously by sigtramp et al) this may occur if code has jumped
2405 // through a NULL pointer -- we want to be able to unwind past that frame
2406 // to help find the bug.
2407
2408 if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2409 pc = abi_sp->FixCodeAddress(pc);
2410
2411 return !(m_all_registers_available == false &&
2412 above_trap_handler == false && (pc == 0 || pc == 1));
2413 } else {
2414 return false;
2415 }
2416}
2417
2418void RegisterContextUnwind::UnwindLogMsg(const char *fmt, ...) {
2419 Log *log = GetLog(LLDBLog::Unwind);
2420 if (!log)
2421 return;
2422
2423 va_list args;
2424 va_start(args, fmt);
2425
2426 llvm::SmallString<0> logmsg;
2427 if (VASprintf(logmsg, fmt, args)) {
2428 LLDB_LOGF(log, "%*sth%d/fr%u %s",
2429 m_frame_number < 100 ? m_frame_number : 100, "",
2430 m_thread.GetIndexID(), m_frame_number, logmsg.c_str());
2431 }
2432 va_end(args);
2433}
2434
2436 Log *log = GetLog(LLDBLog::Unwind);
2437 if (!log || !log->GetVerbose())
2438 return;
2439
2440 va_list args;
2441 va_start(args, fmt);
2442
2443 llvm::SmallString<0> logmsg;
2444 if (VASprintf(logmsg, fmt, args)) {
2445 LLDB_LOGF(log, "%*sth%d/fr%u %s",
2446 m_frame_number < 100 ? m_frame_number : 100, "",
2447 m_thread.GetIndexID(), m_frame_number, logmsg.c_str());
2448 }
2449 va_end(args);
2450}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
static ConstString GetSymbolOrFunctionName(const SymbolContext &sym_ctx)
A class to represent register numbers, and able to convert between different register numbering schem...
bool IsValid() const
uint32_t GetAsKind(lldb::RegisterKind kind)
lldb::RegisterKind GetRegisterKind() const
uint32_t GetRegisterNumber() const
void init(lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num)
const char * GetName()
virtual lldb::UnwindPlanSP CreateDefaultUnwindPlan()=0
virtual bool GetFallbackRegisterLocation(const RegisterInfo *reg_info, UnwindPlan::Row::AbstractRegisterLocation &unwind_regloc)
Definition ABI.cpp:211
virtual lldb::UnwindPlanSP CreateFunctionEntryUnwindPlan()=0
A section + offset based address class.
Definition Address.h:62
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition Address.cpp:1035
bool ResolveFunctionScope(lldb_private::SymbolContext &sym_ctx)
Resolve this address to its containing function.
Definition Address.cpp:266
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Definition Address.h:441
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:468
bool GetUnwindPlan(Target &target, const Address &addr, UnwindPlan &unwind_plan)
virtual std::unique_ptr< UnwindPlan > GetUnwindPlan(llvm::ArrayRef< AddressRange > ranges, const Address &addr)=0
A uniqued constant string class.
Definition ConstString.h:40
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr) const
DWARFExpression * GetMutableExpressionAtAddress(lldb::addr_t func_load_addr=LLDB_INVALID_ADDRESS, lldb::addr_t load_addr=0)
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
An data extractor class.
virtual bool AlwaysRelyOnEHUnwindInfo(SymbolContext &sym_ctx)
Ask if the eh_frame information for the given SymbolContext should be relied on even when it's the fi...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Target & GetTargetRef() const
Returns a reference to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
ConstString GetName() const
Definition Function.cpp:708
static lldb::UnwindPlanSP GetRuntimeUnwindPlan(lldb_private::Thread &thread, lldb_private::RegisterContext *regctx, bool &behaves_like_zeroth_frame)
A language runtime may be able to provide a special UnwindPlan for the frame represented by the regis...
bool GetVerbose() const
Definition Log.cpp:326
A plug-in interface definition class for debugging a process.
Definition Process.h:357
virtual bool GetLoadAddressPermissions(lldb::addr_t load_addr, uint32_t &permissions)
Attempt to get the attributes for a region of memory in the process.
Definition Process.cpp:2550
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3616
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition Process.cpp:2260
uint32_t GetAddressByteSize() const
Definition Process.cpp:3620
virtual DynamicLoader * GetDynamicLoader()
Get the dynamic loader plug-in for this process.
Definition Process.cpp:2824
const lldb::ABISP & GetABI()
Definition Process.cpp:1481
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1270
std::optional< UnwindPlan::Row::AbstractRegisterLocation > GetAbstractRegisterLocation(uint32_t lldb_regnum, lldb::RegisterKind &kind)
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
void UnwindLogMsg(const char *fmt,...) __attribute__((format(printf
void PropagateTrapHandlerFlagFromUnwindPlan(std::shared_ptr< const UnwindPlan > unwind_plan)
Check if the given unwind plan indicates a signal trap handler, and update frame type and symbol cont...
void void UnwindLogMsgVerbose(const char *fmt,...) __attribute__((format(printf
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
bool ReadRegisterValueFromRegisterLocation(lldb_private::UnwindLLDB::ConcreteRegisterLocation regloc, const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value)
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) override
std::shared_ptr< RegisterContextUnwind > SharedPtr
bool ReadFrameAddress(lldb::RegisterKind register_kind, const UnwindPlan::Row::FAValue &fa, lldb::addr_t &address)
bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override
bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override
RegisterContextUnwind(lldb_private::Thread &thread, const SharedPtr &next_frame, lldb_private::SymbolContext &sym_ctx, uint32_t frame_number, lldb_private::UnwindLLDB &unwind_lldb)
std::shared_ptr< const UnwindPlan > GetFastUnwindPlanForFrame()
std::shared_ptr< const UnwindPlan > m_fast_unwind_plan_sp
std::map< uint32_t, lldb_private::UnwindLLDB::ConcreteRegisterLocation > m_registers
std::shared_ptr< const UnwindPlan > GetFullUnwindPlanForFrame()
bool ForceSwitchToFallbackUnwindPlan()
Switch to the fallback unwind plan unconditionally without any safety checks that it is providing bet...
lldb_private::UnwindLLDB::RegisterSearchResult SavedLocationForRegister(uint32_t lldb_regnum, lldb_private::UnwindLLDB::ConcreteRegisterLocation &regloc)
bool ReadGPRValue(lldb::RegisterKind register_kind, uint32_t regnum, lldb::addr_t &value)
lldb_private::UnwindLLDB & m_parent_unwind
bool WriteRegisterValueToRegisterLocation(lldb_private::UnwindLLDB::ConcreteRegisterLocation regloc, const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value)
bool TryFallbackUnwindPlan()
If the unwind has to the caller frame has failed, try something else.
std::optional< int > m_current_offset
How far into the function we've executed.
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value) override
lldb::addr_t GetReturnAddressHint(int32_t plan_offset)
bool IsTrapHandlerSymbol(lldb_private::Process *process, const lldb_private::SymbolContext &m_sym_ctx) const
Determines if a SymbolContext is a trap handler or not.
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
void void bool IsUnwindPlanValidForCurrentPC(std::shared_ptr< const UnwindPlan > unwind_plan_sp)
std::shared_ptr< const UnwindPlan > m_fallback_unwind_plan_sp
lldb_private::SymbolContext & m_sym_ctx
bool BehavesLikeZerothFrame() const override
Indicates that this frame is currently executing code, that the PC value is not a return-pc but an ac...
std::shared_ptr< const UnwindPlan > m_full_unwind_plan_sp
virtual Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value)
RegisterContext(Thread &thread, uint32_t concrete_frame_idx)
lldb::TargetSP CalculateTarget() override
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value)
bool SetUInt(uint64_t uint, uint32_t byte_size)
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
RegisterValue::Type GetType() const
An error handling class.
Definition Status.h:118
bool Fail() const
Test for error condition.
Definition Status.cpp:294
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:195
const char * GetData() const
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
Symbol * symbol
The Symbol for a given query.
ConstString GetName() const
Definition Symbol.cpp:511
lldb::PlatformSP GetPlatform()
Definition Target.h:1510
const ArchSpec & GetArchitecture() const
Definition Target.h:1056
const uint8_t * GetDWARFExpressionBytes() const
Definition UnwindPlan.h:311
const FAValue & GetAFAValue() const
Definition UnwindPlan.h:368
const FAValue & GetCFAValue() const
Definition UnwindPlan.h:365
bool GetRegisterInfo(uint32_t reg_num, AbstractRegisterLocation &register_location) const
void Dump(Stream &s, const UnwindPlan *unwind_plan, Thread *thread, lldb::addr_t base_addr) const
@ LoadAddress
A load address value.
Definition Value.h:49
void SetValueType(ValueType value_type)
Definition Value.h:89
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_FP
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
bool VASprintf(llvm::SmallVectorImpl< char > &buf, const char *fmt, va_list args)
Definition VASprintf.cpp:19
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::FuncUnwinders > FuncUnwindersSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
std::shared_ptr< lldb_private::Module > ModuleSP
RegisterKind
Register numbering types.
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
Registers are grouped into register sets.
An UnwindPlan::Row::AbstractRegisterLocation, combined with the register context and memory for a spe...
Definition UnwindLLDB.h:46
struct lldb_private::UnwindLLDB::ConcreteRegisterLocation::@250272047141350077067164323227154322243030206067::@235335143127077156324316317012344113206032105310 reg_plus_offset
union lldb_private::UnwindLLDB::ConcreteRegisterLocation::@250272047141350077067164323227154322243030206067 location