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),
61 m_fast_unwind_plan_sp(), m_full_unwind_plan_sp(),
62 m_fallback_unwind_plan_sp(), m_all_registers_available(false),
63 m_frame_type(-1), m_cfa(LLDB_INVALID_ADDRESS),
64 m_afa(LLDB_INVALID_ADDRESS), m_start_pc(), m_current_pc(),
65 m_current_offset(0), m_current_offset_backed_up_one(0),
66 m_behaves_like_zeroth_frame(false), m_sym_ctx(sym_ctx),
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) {
83 }
84}
85
87 lldb::UnwindPlanSP 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 m_current_offset <= 0, we've got nothing else to try
98 if (m_current_offset <= 0)
99 return false;
100
101 // check pc - 1 to see if it's valid
102 Address pc_minus_one(m_current_pc);
103 pc_minus_one.SetOffset(m_current_pc.GetOffset() - 1);
104 if (unwind_plan_sp->PlanValidAtAddress(pc_minus_one)) {
105 return true;
106 }
107
108 return false;
109}
110
111// Initialize a RegisterContextUnwind which is the first frame of a stack -- the
112// zeroth frame or currently executing frame.
113
115 Log *log = GetLog(LLDBLog::Unwind);
116 ExecutionContext exe_ctx(m_thread.shared_from_this());
118
119 if (reg_ctx_sp.get() == nullptr) {
121 UnwindLogMsg("frame does not have a register context");
122 return;
123 }
124
125 addr_t current_pc = reg_ctx_sp->GetPC();
126
127 if (current_pc == LLDB_INVALID_ADDRESS) {
129 UnwindLogMsg("frame does not have a pc");
130 return;
131 }
132
133 Process *process = exe_ctx.GetProcessPtr();
134
135 // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
136 // this will strip bit zero in case we read a PC from memory or from the LR.
137 // (which would be a no-op in frame 0 where we get it from the register set,
138 // but still a good idea to make the call here for other ABIs that may
139 // exist.)
140 if (ABISP abi_sp = process->GetABI())
141 current_pc = abi_sp->FixCodeAddress(current_pc);
142
145 if (lang_runtime_plan_sp.get()) {
146 UnwindLogMsg("This is an async frame");
147 }
148
149 // Initialize m_current_pc, an Address object, based on current_pc, an
150 // addr_t.
151 m_current_pc.SetLoadAddress(current_pc, &process->GetTarget());
152
153 // If we don't have a Module for some reason, we're not going to find
154 // symbol/function information - just stick in some reasonable defaults and
155 // hope we can unwind past this frame.
156 ModuleSP pc_module_sp(m_current_pc.GetModule());
157 if (!m_current_pc.IsValid() || !pc_module_sp) {
158 UnwindLogMsg("using architectural default unwind method");
159 }
160
161 AddressRange addr_range;
163
164 if (m_sym_ctx.symbol) {
165 UnwindLogMsg("with pc value of 0x%" PRIx64 ", symbol name is '%s'",
166 current_pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
167 } else if (m_sym_ctx.function) {
168 UnwindLogMsg("with pc value of 0x%" PRIx64 ", function name is '%s'",
169 current_pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
170 } else {
171 UnwindLogMsg("with pc value of 0x%" PRIx64
172 ", no symbol/function name is known.",
173 current_pc);
174 }
175
176 if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
178 } else {
179 // FIXME: Detect eDebuggerFrame here.
181 }
182
183 // If we were able to find a symbol/function, set addr_range to the bounds of
184 // that symbol/function. else treat the current pc value as the start_pc and
185 // record no offset.
186 if (addr_range.GetBaseAddress().IsValid()) {
187 m_start_pc = addr_range.GetBaseAddress();
190 } else if (m_current_pc.GetModule() == m_start_pc.GetModule()) {
191 // This means that whatever symbol we kicked up isn't really correct ---
192 // we should not cross section boundaries ... We really should NULL out
193 // the function/symbol in this case unless there is a bad assumption here
194 // due to inlined functions?
197 }
199 } else {
201 m_current_offset = -1;
203 }
204
205 // We've set m_frame_type and m_sym_ctx before these calls.
206
209
210 UnwindPlan::RowSP active_row;
211 lldb::RegisterKind row_register_kind = eRegisterKindGeneric;
212
213 // If we have LanguageRuntime UnwindPlan for this unwind, use those
214 // rules to find the caller frame instead of the function's normal
215 // UnwindPlans. The full unwind plan for this frame will be
216 // the LanguageRuntime-provided unwind plan, and there will not be a
217 // fast unwind plan.
218 if (lang_runtime_plan_sp.get()) {
219 active_row =
220 lang_runtime_plan_sp->GetRowForFunctionOffset(m_current_offset);
221 row_register_kind = lang_runtime_plan_sp->GetRegisterKind();
222 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(),
223 m_cfa)) {
224 UnwindLogMsg("Cannot set cfa");
225 } else {
226 m_full_unwind_plan_sp = lang_runtime_plan_sp;
227 if (log) {
228 StreamString active_row_strm;
229 active_row->Dump(active_row_strm, lang_runtime_plan_sp.get(), &m_thread,
231 UnwindLogMsg("async active row: %s", active_row_strm.GetData());
232 }
233 UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
235 "initialized async frame current pc is 0x%" PRIx64
236 " cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
237 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
238 (uint64_t)m_cfa, (uint64_t)m_afa);
239
240 return;
241 }
242 }
243
245 m_full_unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
246 active_row =
247 m_full_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
248 row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
249 if (active_row.get() && log) {
250 StreamString active_row_strm;
251 active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread,
253 UnwindLogMsg("%s", active_row_strm.GetData());
254 }
255 }
256
257 if (!active_row.get()) {
258 UnwindLogMsg("could not find an unwindplan row for this frame's pc");
260 return;
261 }
262
263 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(), m_cfa)) {
264 // Try the fall back unwind plan since the
265 // full unwind plan failed.
266 FuncUnwindersSP func_unwinders_sp;
267 UnwindPlanSP call_site_unwind_plan;
268 bool cfa_status = false;
269
270 if (m_sym_ctx_valid) {
271 func_unwinders_sp =
272 pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
274 }
275
276 if (func_unwinders_sp.get() != nullptr)
277 call_site_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(
278 process->GetTarget(), m_thread);
279
280 if (call_site_unwind_plan.get() != nullptr) {
281 m_fallback_unwind_plan_sp = call_site_unwind_plan;
283 cfa_status = true;
284 }
285 if (!cfa_status) {
286 UnwindLogMsg("could not read CFA value for first frame.");
288 return;
289 }
290 } else
291 ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
292
295 "could not read CFA or AFA values for first frame, not valid.");
297 return;
298 }
299
300 UnwindLogMsg("initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64
301 " afa is 0x%" PRIx64 " using %s UnwindPlan",
302 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
303 (uint64_t)m_cfa,
304 (uint64_t)m_afa,
305 m_full_unwind_plan_sp->GetSourceName().GetCString());
306}
307
308// Initialize a RegisterContextUnwind for the non-zeroth frame -- rely on the
309// RegisterContextUnwind "below" it to provide things like its current pc value.
310
312 Log *log = GetLog(LLDBLog::Unwind);
313 if (IsFrameZero()) {
315 UnwindLogMsg("non-zeroth frame tests positive for IsFrameZero -- that "
316 "shouldn't happen.");
317 return;
318 }
319
320 if (!GetNextFrame().get() || !GetNextFrame()->IsValid()) {
322 UnwindLogMsg("Could not get next frame, marking this frame as invalid.");
323 return;
324 }
327 UnwindLogMsg("Could not get register context for this thread, marking this "
328 "frame as invalid.");
329 return;
330 }
331
332 ExecutionContext exe_ctx(m_thread.shared_from_this());
333 Process *process = exe_ctx.GetProcessPtr();
334
335 // Some languages may have a logical parent stack frame which is
336 // not a real stack frame, but the programmer would consider it to
337 // be the caller of the frame, e.g. Swift asynchronous frames.
338 //
339 // A LanguageRuntime may provide an UnwindPlan that is used in this
340 // stack trace base on the RegisterContext contents, intsead
341 // of the normal UnwindPlans we would use for the return-pc.
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 if (abi_sp)
366 reg_val = abi_sp->FixDataAddress(reg_val);
367 UnwindLogMsg("fp = 0x%" PRIx64, reg_val);
368 }
370 if (abi_sp)
371 reg_val = abi_sp->FixDataAddress(reg_val);
372 UnwindLogMsg("sp = 0x%" PRIx64, reg_val);
373 }
374 }
375
376 // A pc of 0x0 means it's the end of the stack crawl unless we're above a trap
377 // handler function
378 bool above_trap_handler = false;
379 if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
381 above_trap_handler = true;
382
383 if (pc == 0 || pc == 0x1) {
384 if (!above_trap_handler) {
386 UnwindLogMsg("this frame has a pc of 0x0");
387 return;
388 }
389 }
390
391 const bool allow_section_end = true;
392 m_current_pc.SetLoadAddress(pc, &process->GetTarget(), allow_section_end);
393
394 // If we don't have a Module for some reason, we're not going to find
395 // symbol/function information - just stick in some reasonable defaults and
396 // hope we can unwind past this frame. If we're above a trap handler,
397 // we may be at a bogus address because we jumped through a bogus function
398 // pointer and trapped, so don't force the arch default unwind plan in that
399 // case.
400 ModuleSP pc_module_sp(m_current_pc.GetModule());
401 if ((!m_current_pc.IsValid() || !pc_module_sp) &&
402 above_trap_handler == false) {
403 UnwindLogMsg("using architectural default unwind method");
404
405 // Test the pc value to see if we know it's in an unmapped/non-executable
406 // region of memory.
407 uint32_t permissions;
408 if (process->GetLoadAddressPermissions(pc, permissions) &&
409 (permissions & ePermissionsExecutable) == 0) {
410 // If this is the second frame off the stack, we may have unwound the
411 // first frame incorrectly. But using the architecture default unwind
412 // plan may get us back on track -- albeit possibly skipping a real
413 // frame. Give this frame a clearly-invalid pc and see if we can get any
414 // further.
415 if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
417 UnwindLogMsg("had a pc of 0x%" PRIx64 " which is not in executable "
418 "memory but on frame 1 -- "
419 "allowing it once.",
420 (uint64_t)pc);
422 } else {
423 // anywhere other than the second frame, a non-executable pc means
424 // we're off in the weeds -- stop now.
426 UnwindLogMsg("pc is in a non-executable section of memory and this "
427 "isn't the 2nd frame in the stack walk.");
428 return;
429 }
430 }
431
432 if (abi_sp) {
433 m_fast_unwind_plan_sp.reset();
435 std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
436 abi_sp->CreateDefaultUnwindPlan(*m_full_unwind_plan_sp);
437 if (m_frame_type != eSkipFrame) // don't override eSkipFrame
438 {
440 }
442 m_current_offset = -1;
444 RegisterKind row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
445 UnwindPlan::RowSP row = m_full_unwind_plan_sp->GetRowForFunctionOffset(0);
446 if (row.get()) {
447 if (!ReadFrameAddress(row_register_kind, row->GetCFAValue(), m_cfa)) {
448 UnwindLogMsg("failed to get cfa value");
449 if (m_frame_type != eSkipFrame) // don't override eSkipFrame
450 {
452 }
453 return;
454 }
455
456 ReadFrameAddress(row_register_kind, row->GetAFAValue(), m_afa);
457
458 // A couple of sanity checks..
459 if (m_cfa == LLDB_INVALID_ADDRESS || m_cfa == 0 || m_cfa == 1) {
460 UnwindLogMsg("could not find a valid cfa address");
462 return;
463 }
464
465 // m_cfa should point into the stack memory; if we can query memory
466 // region permissions, see if the memory is allocated & readable.
467 if (process->GetLoadAddressPermissions(m_cfa, permissions) &&
468 (permissions & ePermissionsReadable) == 0) {
471 "the CFA points to a region of memory that is not readable");
472 return;
473 }
474 } else {
475 UnwindLogMsg("could not find a row for function offset zero");
477 return;
478 }
479
480 if (CheckIfLoopingStack()) {
482 if (CheckIfLoopingStack()) {
483 UnwindLogMsg("same CFA address as next frame, assuming the unwind is "
484 "looping - stopping");
486 return;
487 }
488 }
489
490 UnwindLogMsg("initialized frame cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
491 (uint64_t)m_cfa, (uint64_t)m_afa);
492 return;
493 }
495 UnwindLogMsg("could not find any symbol for this pc, or a default unwind "
496 "plan, to continue unwind.");
497 return;
498 }
499
500 AddressRange addr_range;
502
503 if (m_sym_ctx.symbol) {
504 UnwindLogMsg("with pc value of 0x%" PRIx64 ", symbol name is '%s'", pc,
505 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
506 } else if (m_sym_ctx.function) {
507 UnwindLogMsg("with pc value of 0x%" PRIx64 ", function name is '%s'", pc,
508 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
509 } else {
510 UnwindLogMsg("with pc value of 0x%" PRIx64
511 ", no symbol/function name is known.",
512 pc);
513 }
514
515 bool decr_pc_and_recompute_addr_range;
516
517 if (!m_sym_ctx_valid) {
518 // Always decrement and recompute if the symbol lookup failed
519 decr_pc_and_recompute_addr_range = true;
522 // Don't decrement if we're "above" an asynchronous event like
523 // sigtramp.
524 decr_pc_and_recompute_addr_range = false;
525 } else if (!addr_range.GetBaseAddress().IsValid() ||
526 addr_range.GetBaseAddress().GetSection() != m_current_pc.GetSection() ||
527 addr_range.GetBaseAddress().GetOffset() != m_current_pc.GetOffset()) {
528 // If our "current" pc isn't the start of a function, decrement the pc
529 // if we're up the stack.
531 decr_pc_and_recompute_addr_range = false;
532 else
533 decr_pc_and_recompute_addr_range = true;
534 } else if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
535 // Signal dispatch may set the return address of the handler it calls to
536 // point to the first byte of a return trampoline (like __kernel_rt_sigreturn),
537 // so do not decrement and recompute if the symbol we already found is a trap
538 // handler.
539 decr_pc_and_recompute_addr_range = false;
540 } else if (m_behaves_like_zeroth_frame) {
541 decr_pc_and_recompute_addr_range = false;
542 } else {
543 // Decrement to find the function containing the call.
544 decr_pc_and_recompute_addr_range = true;
545 }
546
547 // We need to back up the pc by 1 byte and re-search for the Symbol to handle
548 // the case where the "saved pc" value is pointing to the next function, e.g.
549 // if a function ends with a CALL instruction.
550 // FIXME this may need to be an architectural-dependent behavior; if so we'll
551 // need to add a member function
552 // to the ABI plugin and consult that.
553 if (decr_pc_and_recompute_addr_range) {
554 UnwindLogMsg("Backing up the pc value of 0x%" PRIx64
555 " by 1 and re-doing symbol lookup; old symbol was %s",
556 pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
557 Address temporary_pc;
558 temporary_pc.SetLoadAddress(pc - 1, &process->GetTarget());
559 m_sym_ctx.Clear(false);
560 m_sym_ctx_valid = temporary_pc.ResolveFunctionScope(m_sym_ctx, &addr_range);
561
562 UnwindLogMsg("Symbol is now %s",
563 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
564 }
565
566 // If we were able to find a symbol/function, set addr_range_ptr to the
567 // bounds of that symbol/function. else treat the current pc value as the
568 // start_pc and record no offset.
569 if (addr_range.GetBaseAddress().IsValid()) {
570 m_start_pc = addr_range.GetBaseAddress();
573 if (decr_pc_and_recompute_addr_range &&
576 if (m_sym_ctx_valid) {
577 m_current_pc.SetLoadAddress(pc - 1, &process->GetTarget());
578 }
579 }
580 } else {
582 m_current_offset = -1;
584 }
585
586 if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
588 } else {
589 // FIXME: Detect eDebuggerFrame here.
590 if (m_frame_type != eSkipFrame) // don't override eSkipFrame
591 {
593 }
594 }
595
596 UnwindPlan::RowSP active_row;
597 RegisterKind row_register_kind = eRegisterKindGeneric;
598
599 // If we have LanguageRuntime UnwindPlan for this unwind, use those
600 // rules to find the caller frame instead of the function's normal
601 // UnwindPlans. The full unwind plan for this frame will be
602 // the LanguageRuntime-provided unwind plan, and there will not be a
603 // fast unwind plan.
604 if (lang_runtime_plan_sp.get()) {
605 active_row =
606 lang_runtime_plan_sp->GetRowForFunctionOffset(m_current_offset);
607 row_register_kind = lang_runtime_plan_sp->GetRegisterKind();
608 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(),
609 m_cfa)) {
610 UnwindLogMsg("Cannot set cfa");
611 } else {
612 m_full_unwind_plan_sp = lang_runtime_plan_sp;
613 if (log) {
614 StreamString active_row_strm;
615 active_row->Dump(active_row_strm, lang_runtime_plan_sp.get(), &m_thread,
617 UnwindLogMsg("async active row: %s", active_row_strm.GetData());
618 }
619 UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
621 "initialized async frame current pc is 0x%" PRIx64
622 " cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
623 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
624 (uint64_t)m_cfa, (uint64_t)m_afa);
625
626 return;
627 }
628 }
629
630 // We've set m_frame_type and m_sym_ctx before this call.
632
633 // Try to get by with just the fast UnwindPlan if possible - the full
634 // UnwindPlan may be expensive to get (e.g. if we have to parse the entire
635 // eh_frame section of an ObjectFile for the first time.)
636
638 m_fast_unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
639 active_row =
640 m_fast_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
641 row_register_kind = m_fast_unwind_plan_sp->GetRegisterKind();
643 if (active_row.get() && log) {
644 StreamString active_row_strm;
645 active_row->Dump(active_row_strm, m_fast_unwind_plan_sp.get(), &m_thread,
647 UnwindLogMsg("Using fast unwind plan '%s'",
648 m_fast_unwind_plan_sp->GetSourceName().AsCString());
649 UnwindLogMsg("active row: %s", active_row_strm.GetData());
650 }
651 } else {
654 active_row = m_full_unwind_plan_sp->GetRowForFunctionOffset(
656 row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
658 if (active_row.get() && log) {
659 StreamString active_row_strm;
660 active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(),
661 &m_thread,
663 UnwindLogMsg("Using full unwind plan '%s'",
664 m_full_unwind_plan_sp->GetSourceName().AsCString());
665 UnwindLogMsg("active row: %s", active_row_strm.GetData());
666 }
667 }
668 }
669
670 if (!active_row.get()) {
672 UnwindLogMsg("could not find unwind row for this pc");
673 return;
674 }
675
676 if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(), m_cfa)) {
677 UnwindLogMsg("failed to get cfa");
679 return;
680 }
681
682 ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
683
684 UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
685
686 if (CheckIfLoopingStack()) {
688 if (CheckIfLoopingStack()) {
689 UnwindLogMsg("same CFA address as next frame, assuming the unwind is "
690 "looping - stopping");
692 return;
693 }
694 }
695
696 UnwindLogMsg("initialized frame current pc is 0x%" PRIx64
697 " cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
698 (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
699 (uint64_t)m_cfa,
700 (uint64_t)m_afa);
701}
702
704 // If we have a bad stack setup, we can get the same CFA value multiple times
705 // -- or even more devious, we can actually oscillate between two CFA values.
706 // Detect that here and break out to avoid a possible infinite loop in lldb
707 // trying to unwind the stack. To detect when we have the same CFA value
708 // multiple times, we compare the
709 // CFA of the current
710 // frame with the 2nd next frame because in some specail case (e.g. signal
711 // hanlders, hand written assembly without ABI compliance) we can have 2
712 // frames with the same
713 // CFA (in theory we
714 // can have arbitrary number of frames with the same CFA, but more then 2 is
715 // very unlikely)
716
718 if (next_frame) {
719 RegisterContextUnwind::SharedPtr next_next_frame =
720 next_frame->GetNextFrame();
721 addr_t next_next_frame_cfa = LLDB_INVALID_ADDRESS;
722 if (next_next_frame && next_next_frame->GetCFA(next_next_frame_cfa)) {
723 if (next_next_frame_cfa == m_cfa) {
724 // We have a loop in the stack unwind
725 return true;
726 }
727 }
728 }
729 return false;
730}
731
733
735 if (m_frame_number == 0)
736 return true;
738 return true;
739 return false;
740}
741
742// Find a fast unwind plan for this frame, if possible.
743//
744// On entry to this method,
745//
746// 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame
747// if either of those are correct,
748// 2. m_sym_ctx should already be filled in, and
749// 3. m_current_pc should have the current pc value for this frame
750// 4. m_current_offset_backed_up_one should have the current byte offset into
751// the function, maybe backed up by 1, -1 if unknown
752
754 UnwindPlanSP unwind_plan_sp;
755 ModuleSP pc_module_sp(m_current_pc.GetModule());
756
757 if (!m_current_pc.IsValid() || !pc_module_sp ||
758 pc_module_sp->GetObjectFile() == nullptr)
759 return unwind_plan_sp;
760
761 if (IsFrameZero())
762 return unwind_plan_sp;
763
764 FuncUnwindersSP func_unwinders_sp(
765 pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
767 if (!func_unwinders_sp)
768 return unwind_plan_sp;
769
770 // If we're in _sigtramp(), unwinding past this frame requires special
771 // knowledge.
773 return unwind_plan_sp;
774
775 unwind_plan_sp = func_unwinders_sp->GetUnwindPlanFastUnwind(
777 if (unwind_plan_sp) {
778 if (unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
780 return unwind_plan_sp;
781 } else {
782 unwind_plan_sp.reset();
783 }
784 }
785 return unwind_plan_sp;
786}
787
788// On entry to this method,
789//
790// 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame
791// if either of those are correct,
792// 2. m_sym_ctx should already be filled in, and
793// 3. m_current_pc should have the current pc value for this frame
794// 4. m_current_offset_backed_up_one should have the current byte offset into
795// the function, maybe backed up by 1, -1 if unknown
796
798 UnwindPlanSP unwind_plan_sp;
799 UnwindPlanSP arch_default_unwind_plan_sp;
800 ExecutionContext exe_ctx(m_thread.shared_from_this());
801 Process *process = exe_ctx.GetProcessPtr();
802 ABI *abi = process ? process->GetABI().get() : nullptr;
803 if (abi) {
804 arch_default_unwind_plan_sp =
805 std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
806 abi->CreateDefaultUnwindPlan(*arch_default_unwind_plan_sp);
807 } else {
809 "unable to get architectural default UnwindPlan from ABI plugin");
810 }
811
815 // If this frame behaves like a 0th frame (currently executing or
816 // interrupted asynchronously), all registers can be retrieved.
818 }
819
820 // If we've done a jmp 0x0 / bl 0x0 (called through a null function pointer)
821 // so the pc is 0x0 in the zeroth frame, we need to use the "unwind at first
822 // instruction" arch default UnwindPlan Also, if this Process can report on
823 // memory region attributes, any non-executable region means we jumped
824 // through a bad function pointer - handle the same way as 0x0. Note, if we
825 // have a symbol context & a symbol, we don't want to follow this code path.
826 // This is for jumping to memory regions without any information available.
827
828 if ((!m_sym_ctx_valid ||
829 (m_sym_ctx.function == nullptr && m_sym_ctx.symbol == nullptr)) &&
831 uint32_t permissions;
832 addr_t current_pc_addr =
834 if (current_pc_addr == 0 ||
835 (process &&
836 process->GetLoadAddressPermissions(current_pc_addr, permissions) &&
837 (permissions & ePermissionsExecutable) == 0)) {
838 if (abi) {
839 unwind_plan_sp =
840 std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
841 abi->CreateFunctionEntryUnwindPlan(*unwind_plan_sp);
843 return unwind_plan_sp;
844 }
845 }
846 }
847
848 // No Module for the current pc, try using the architecture default unwind.
849 ModuleSP pc_module_sp(m_current_pc.GetModule());
850 if (!m_current_pc.IsValid() || !pc_module_sp ||
851 pc_module_sp->GetObjectFile() == nullptr) {
853 return arch_default_unwind_plan_sp;
854 }
855
856 FuncUnwindersSP func_unwinders_sp;
857 if (m_sym_ctx_valid) {
858 func_unwinders_sp =
859 pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
861 }
862
863 // No FuncUnwinders available for this pc (stripped function symbols, lldb
864 // could not augment its function table with another source, like
865 // LC_FUNCTION_STARTS or eh_frame in ObjectFileMachO). See if eh_frame or the
866 // .ARM.exidx tables have unwind information for this address, else fall back
867 // to the architectural default unwind.
868 if (!func_unwinders_sp) {
870
871 if (!pc_module_sp || !pc_module_sp->GetObjectFile() ||
873 return arch_default_unwind_plan_sp;
874
875 // Even with -fomit-frame-pointer, we can try eh_frame to get back on
876 // track.
877 DWARFCallFrameInfo *eh_frame =
878 pc_module_sp->GetUnwindTable().GetEHFrameInfo();
879 if (eh_frame) {
880 unwind_plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
881 if (eh_frame->GetUnwindPlan(m_current_pc, *unwind_plan_sp))
882 return unwind_plan_sp;
883 else
884 unwind_plan_sp.reset();
885 }
886
887 ArmUnwindInfo *arm_exidx =
888 pc_module_sp->GetUnwindTable().GetArmUnwindInfo();
889 if (arm_exidx) {
890 unwind_plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
891 if (arm_exidx->GetUnwindPlan(exe_ctx.GetTargetRef(), m_current_pc,
892 *unwind_plan_sp))
893 return unwind_plan_sp;
894 else
895 unwind_plan_sp.reset();
896 }
897
898 CallFrameInfo *object_file_unwind =
899 pc_module_sp->GetUnwindTable().GetObjectFileUnwindInfo();
900 if (object_file_unwind) {
901 unwind_plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
902 if (object_file_unwind->GetUnwindPlan(m_current_pc, *unwind_plan_sp))
903 return unwind_plan_sp;
904 else
905 unwind_plan_sp.reset();
906 }
907
908 return arch_default_unwind_plan_sp;
909 }
910
911 if (m_frame_type == eTrapHandlerFrame && process) {
912 m_fast_unwind_plan_sp.reset();
913
914 // On some platforms the unwind information for signal handlers is not
915 // present or correct. Give the platform plugins a chance to provide
916 // substitute plan. Otherwise, use eh_frame.
917 if (m_sym_ctx_valid) {
918 lldb::PlatformSP platform = process->GetTarget().GetPlatform();
919 unwind_plan_sp = platform->GetTrapHandlerUnwindPlan(
920 process->GetTarget().GetArchitecture().GetTriple(),
922
923 if (unwind_plan_sp)
924 return unwind_plan_sp;
925 }
926
927 unwind_plan_sp =
928 func_unwinders_sp->GetEHFrameUnwindPlan(process->GetTarget());
929 if (!unwind_plan_sp)
930 unwind_plan_sp =
931 func_unwinders_sp->GetObjectFileUnwindPlan(process->GetTarget());
932 if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc) &&
933 unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolYes) {
934 return unwind_plan_sp;
935 }
936 }
937
938 // Ask the DynamicLoader if the eh_frame CFI should be trusted in this frame
939 // even when it's frame zero This comes up if we have hand-written functions
940 // in a Module and hand-written eh_frame. The assembly instruction
941 // inspection may fail and the eh_frame CFI were probably written with some
942 // care to do the right thing. It'd be nice if there was a way to ask the
943 // eh_frame directly if it is asynchronous (can be trusted at every
944 // instruction point) or synchronous (the normal case - only at call sites).
945 // But there is not.
946 if (process && process->GetDynamicLoader() &&
948 // We must specifically call the GetEHFrameUnwindPlan() method here --
949 // normally we would call GetUnwindPlanAtCallSite() -- because CallSite may
950 // return an unwind plan sourced from either eh_frame (that's what we
951 // intend) or compact unwind (this won't work)
952 unwind_plan_sp =
953 func_unwinders_sp->GetEHFrameUnwindPlan(process->GetTarget());
954 if (!unwind_plan_sp)
955 unwind_plan_sp =
956 func_unwinders_sp->GetObjectFileUnwindPlan(process->GetTarget());
957 if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
958 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because the "
959 "DynamicLoader suggested we prefer it",
960 unwind_plan_sp->GetSourceName().GetCString());
961 return unwind_plan_sp;
962 }
963 }
964
965 // Typically the NonCallSite UnwindPlan is the unwind created by inspecting
966 // the assembly language instructions
967 if (m_behaves_like_zeroth_frame && process) {
968 unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite(
969 process->GetTarget(), m_thread);
970 if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
971 if (unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
972 // We probably have an UnwindPlan created by inspecting assembly
973 // instructions. The assembly profilers work really well with compiler-
974 // generated functions but hand- written assembly can be problematic.
975 // We set the eh_frame based unwind plan as our fallback unwind plan if
976 // instruction emulation doesn't work out even for non call sites if it
977 // is available and use the architecture default unwind plan if it is
978 // not available. The eh_frame unwind plan is more reliable even on non
979 // call sites then the architecture default plan and for hand written
980 // assembly code it is often written in a way that it valid at all
981 // location what helps in the most common cases when the instruction
982 // emulation fails.
983 UnwindPlanSP call_site_unwind_plan =
984 func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget(),
985 m_thread);
986 if (call_site_unwind_plan &&
987 call_site_unwind_plan.get() != unwind_plan_sp.get() &&
988 call_site_unwind_plan->GetSourceName() !=
989 unwind_plan_sp->GetSourceName()) {
990 m_fallback_unwind_plan_sp = call_site_unwind_plan;
991 } else {
992 m_fallback_unwind_plan_sp = arch_default_unwind_plan_sp;
993 }
994 }
995 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because this "
996 "is the non-call site unwind plan and this is a "
997 "zeroth frame",
998 unwind_plan_sp->GetSourceName().GetCString());
999 return unwind_plan_sp;
1000 }
1001
1002 // If we're on the first instruction of a function, and we have an
1003 // architectural default UnwindPlan for the initial instruction of a
1004 // function, use that.
1005 if (m_current_offset == 0) {
1006 unwind_plan_sp =
1007 func_unwinders_sp->GetUnwindPlanArchitectureDefaultAtFunctionEntry(
1008 m_thread);
1009 if (unwind_plan_sp) {
1010 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because we are at "
1011 "the first instruction of a function",
1012 unwind_plan_sp->GetSourceName().GetCString());
1013 return unwind_plan_sp;
1014 }
1015 }
1016 }
1017
1018 // Typically this is unwind info from an eh_frame section intended for
1019 // exception handling; only valid at call sites
1020 if (process) {
1021 unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtCallSite(
1022 process->GetTarget(), m_thread);
1023 }
1024 if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp)) {
1025 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because this "
1026 "is the call-site unwind plan",
1027 unwind_plan_sp->GetSourceName().GetCString());
1028 return unwind_plan_sp;
1029 }
1030
1031 // We'd prefer to use an UnwindPlan intended for call sites when we're at a
1032 // call site but if we've struck out on that, fall back to using the non-
1033 // call-site assembly inspection UnwindPlan if possible.
1034 if (process) {
1035 unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite(
1036 process->GetTarget(), m_thread);
1037 }
1038 if (unwind_plan_sp &&
1039 unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
1040 // We probably have an UnwindPlan created by inspecting assembly
1041 // instructions. The assembly profilers work really well with compiler-
1042 // generated functions but hand- written assembly can be problematic. We
1043 // set the eh_frame based unwind plan as our fallback unwind plan if
1044 // instruction emulation doesn't work out even for non call sites if it is
1045 // available and use the architecture default unwind plan if it is not
1046 // available. The eh_frame unwind plan is more reliable even on non call
1047 // sites then the architecture default plan and for hand written assembly
1048 // code it is often written in a way that it valid at all location what
1049 // helps in the most common cases when the instruction emulation fails.
1050 UnwindPlanSP call_site_unwind_plan =
1051 func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget(),
1052 m_thread);
1053 if (call_site_unwind_plan &&
1054 call_site_unwind_plan.get() != unwind_plan_sp.get() &&
1055 call_site_unwind_plan->GetSourceName() !=
1056 unwind_plan_sp->GetSourceName()) {
1057 m_fallback_unwind_plan_sp = call_site_unwind_plan;
1058 } else {
1059 m_fallback_unwind_plan_sp = arch_default_unwind_plan_sp;
1060 }
1061 }
1062
1063 if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp)) {
1064 UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because we "
1065 "failed to find a call-site unwind plan that would work",
1066 unwind_plan_sp->GetSourceName().GetCString());
1067 return unwind_plan_sp;
1068 }
1069
1070 // If nothing else, use the architectural default UnwindPlan and hope that
1071 // does the job.
1072 if (arch_default_unwind_plan_sp)
1074 "frame uses %s for full UnwindPlan because we are falling back "
1075 "to the arch default plan",
1076 arch_default_unwind_plan_sp->GetSourceName().GetCString());
1077 else
1079 "Unable to find any UnwindPlan for full unwind of this frame.");
1080
1081 return arch_default_unwind_plan_sp;
1082}
1083
1086}
1087
1089 return m_thread.GetRegisterContext()->GetRegisterCount();
1090}
1091
1093 return m_thread.GetRegisterContext()->GetRegisterInfoAtIndex(reg);
1094}
1095
1097 return m_thread.GetRegisterContext()->GetRegisterSetCount();
1098}
1099
1101 return m_thread.GetRegisterContext()->GetRegisterSet(reg_set);
1102}
1103
1105 lldb::RegisterKind kind, uint32_t num) {
1106 return m_thread.GetRegisterContext()->ConvertRegisterKindToRegisterNumber(
1107 kind, num);
1108}
1109
1112 const RegisterInfo *reg_info, RegisterValue &value) {
1113 if (!IsValid())
1114 return false;
1115 bool success = false;
1116
1117 switch (regloc.type) {
1119 const RegisterInfo *other_reg_info =
1121
1122 if (!other_reg_info)
1123 return false;
1124
1125 success =
1126 m_thread.GetRegisterContext()->ReadRegister(other_reg_info, value);
1127 } break;
1129 const RegisterInfo *other_reg_info =
1131
1132 if (!other_reg_info)
1133 return false;
1134
1135 if (IsFrameZero()) {
1136 success =
1137 m_thread.GetRegisterContext()->ReadRegister(other_reg_info, value);
1138 } else {
1139 success = GetNextFrame()->ReadRegister(other_reg_info, value);
1140 }
1141 } break;
1143 success =
1144 value.SetUInt(regloc.location.inferred_value, reg_info->byte_size);
1145 break;
1146
1148 break;
1150 llvm_unreachable("FIXME debugger inferior function call unwind");
1153 reg_info, regloc.location.target_memory_location, reg_info->byte_size,
1154 value));
1155 success = error.Success();
1156 } break;
1157 default:
1158 llvm_unreachable("Unknown RegisterLocation type.");
1159 }
1160 return success;
1161}
1162
1165 const RegisterInfo *reg_info, const RegisterValue &value) {
1166 if (!IsValid())
1167 return false;
1168
1169 bool success = false;
1170
1171 switch (regloc.type) {
1173 const RegisterInfo *other_reg_info =
1175 success =
1176 m_thread.GetRegisterContext()->WriteRegister(other_reg_info, value);
1177 } break;
1179 const RegisterInfo *other_reg_info =
1181 if (IsFrameZero()) {
1182 success =
1183 m_thread.GetRegisterContext()->WriteRegister(other_reg_info, value);
1184 } else {
1185 success = GetNextFrame()->WriteRegister(other_reg_info, value);
1186 }
1187 } break;
1190 break;
1192 llvm_unreachable("FIXME debugger inferior function call unwind");
1195 reg_info, regloc.location.target_memory_location, reg_info->byte_size,
1196 value));
1197 success = error.Success();
1198 } break;
1199 default:
1200 llvm_unreachable("Unknown RegisterLocation type.");
1201 }
1202 return success;
1203}
1204
1206 return m_frame_type != eNotAValidFrame;
1207}
1208
1209// After the final stack frame in a stack walk we'll get one invalid
1210// (eNotAValidFrame) stack frame -- one past the end of the stack walk. But
1211// higher-level code will need to tell the difference between "the unwind plan
1212// below this frame failed" versus "we successfully completed the stack walk"
1213// so this method helps to disambiguate that.
1214
1217}
1218
1219// A skip frame is a bogus frame on the stack -- but one where we're likely to
1220// find a real frame farther
1221// up the stack if we keep looking. It's always the second frame in an unwind
1222// (i.e. the first frame after frame zero) where unwinding can be the
1223// trickiest. Ideally we'll mark up this frame in some way so the user knows
1224// we're displaying bad data and we may have skipped one frame of their real
1225// program in the process of getting back on track.
1226
1228 return m_frame_type == eSkipFrame;
1229}
1230
1232 lldb_private::Process *process,
1233 const lldb_private::SymbolContext &m_sym_ctx) const {
1234 PlatformSP platform_sp(process->GetTarget().GetPlatform());
1235 if (platform_sp) {
1236 const std::vector<ConstString> trap_handler_names(
1237 platform_sp->GetTrapHandlerSymbolNames());
1238 for (ConstString name : trap_handler_names) {
1239 if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
1240 (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name)) {
1241 return true;
1242 }
1243 }
1244 }
1245 const std::vector<ConstString> user_specified_trap_handler_names(
1247 for (ConstString name : user_specified_trap_handler_names) {
1248 if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
1249 (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name)) {
1250 return true;
1251 }
1252 }
1253
1254 return false;
1255}
1256
1257// Answer the question: Where did THIS frame save the CALLER frame ("previous"
1258// frame)'s register value?
1259
1262 uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc) {
1263 RegisterNumber regnum(m_thread, eRegisterKindLLDB, lldb_regnum);
1264 Log *log = GetLog(LLDBLog::Unwind);
1265
1266 // Have we already found this register location?
1267 if (!m_registers.empty()) {
1268 std::map<uint32_t,
1270 iterator;
1271 iterator = m_registers.find(regnum.GetAsKind(eRegisterKindLLDB));
1272 if (iterator != m_registers.end()) {
1273 regloc = iterator->second;
1274 UnwindLogMsg("supplying caller's saved %s (%d)'s location, cached",
1275 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1277 }
1278 }
1279
1280 // Look through the available UnwindPlans for the register location.
1281
1282 UnwindPlan::Row::RegisterLocation unwindplan_regloc;
1283 bool have_unwindplan_regloc = false;
1284 RegisterKind unwindplan_registerkind = kNumRegisterKinds;
1285
1287 UnwindPlan::RowSP active_row =
1288 m_fast_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1289 unwindplan_registerkind = m_fast_unwind_plan_sp->GetRegisterKind();
1290 if (regnum.GetAsKind(unwindplan_registerkind) == LLDB_INVALID_REGNUM) {
1291 UnwindLogMsg("could not convert lldb regnum %s (%d) into %d RegisterKind "
1292 "reg numbering scheme",
1293 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1294 (int)unwindplan_registerkind);
1296 }
1297 // The architecture default unwind plan marks unknown registers as
1298 // Undefined so that we don't forward them up the stack when a
1299 // jitted stack frame may have overwritten them. But when the
1300 // arch default unwind plan is used as the Fast Unwind Plan, we
1301 // need to recognize this & switch over to the Full Unwind Plan
1302 // to see what unwind rule that (more knoweldgeable, probably)
1303 // UnwindPlan has. If the full UnwindPlan says the register
1304 // location is Undefined, then it really is.
1305 if (active_row->GetRegisterInfo(regnum.GetAsKind(unwindplan_registerkind),
1306 unwindplan_regloc) &&
1307 !unwindplan_regloc.IsUndefined()) {
1309 "supplying caller's saved %s (%d)'s location using FastUnwindPlan",
1310 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1311 have_unwindplan_regloc = true;
1312 }
1313 }
1314
1315 if (!have_unwindplan_regloc) {
1316 // m_full_unwind_plan_sp being NULL means that we haven't tried to find a
1317 // full UnwindPlan yet
1318 bool got_new_full_unwindplan = false;
1319 if (!m_full_unwind_plan_sp) {
1321 got_new_full_unwindplan = true;
1322 }
1323
1327
1328 UnwindPlan::RowSP active_row =
1329 m_full_unwind_plan_sp->GetRowForFunctionOffset(
1331 unwindplan_registerkind = m_full_unwind_plan_sp->GetRegisterKind();
1332
1333 if (got_new_full_unwindplan && active_row.get() && log) {
1334 StreamString active_row_strm;
1335 ExecutionContext exe_ctx(m_thread.shared_from_this());
1336 active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(),
1337 &m_thread,
1339 UnwindLogMsg("Using full unwind plan '%s'",
1340 m_full_unwind_plan_sp->GetSourceName().AsCString());
1341 UnwindLogMsg("active row: %s", active_row_strm.GetData());
1342 }
1343 RegisterNumber return_address_reg;
1344
1345 // If we're fetching the saved pc and this UnwindPlan defines a
1346 // ReturnAddress register (e.g. lr on arm), look for the return address
1347 // register number in the UnwindPlan's row.
1348 if (pc_regnum.IsValid() && pc_regnum == regnum &&
1349 m_full_unwind_plan_sp->GetReturnAddressRegister() !=
1351 // If this is a trap handler frame, we should have access to
1352 // the complete register context when the interrupt/async
1353 // signal was received, we should fetch the actual saved $pc
1354 // value instead of the Return Address register.
1355 // If $pc is not available, fall back to the RA reg.
1358 active_row->GetRegisterInfo
1359 (pc_regnum.GetAsKind (unwindplan_registerkind), scratch)) {
1360 UnwindLogMsg("Providing pc register instead of rewriting to "
1361 "RA reg because this is a trap handler and there is "
1362 "a location for the saved pc register value.");
1363 } else {
1364 return_address_reg.init(
1365 m_thread, m_full_unwind_plan_sp->GetRegisterKind(),
1366 m_full_unwind_plan_sp->GetReturnAddressRegister());
1367 regnum = return_address_reg;
1368 UnwindLogMsg("requested caller's saved PC but this UnwindPlan uses a "
1369 "RA reg; getting %s (%d) instead",
1370 return_address_reg.GetName(),
1371 return_address_reg.GetAsKind(eRegisterKindLLDB));
1372 }
1373 } else {
1374 if (regnum.GetAsKind(unwindplan_registerkind) == LLDB_INVALID_REGNUM) {
1375 if (unwindplan_registerkind == eRegisterKindGeneric) {
1376 UnwindLogMsg("could not convert lldb regnum %s (%d) into "
1377 "eRegisterKindGeneric reg numbering scheme",
1378 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1379 } else {
1380 UnwindLogMsg("could not convert lldb regnum %s (%d) into %d "
1381 "RegisterKind reg numbering scheme",
1382 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1383 (int)unwindplan_registerkind);
1384 }
1386 }
1387 }
1388
1389 if (regnum.IsValid() &&
1390 active_row->GetRegisterInfo(regnum.GetAsKind(unwindplan_registerkind),
1391 unwindplan_regloc)) {
1392 have_unwindplan_regloc = true;
1394 "supplying caller's saved %s (%d)'s location using %s UnwindPlan",
1395 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1396 m_full_unwind_plan_sp->GetSourceName().GetCString());
1397 }
1398
1399 // This is frame 0 and we're retrieving the PC and it's saved in a Return
1400 // Address register and it hasn't been saved anywhere yet -- that is,
1401 // it's still live in the actual register. Handle this specially.
1402
1403 if (!have_unwindplan_regloc && return_address_reg.IsValid() &&
1405 if (return_address_reg.GetAsKind(eRegisterKindLLDB) !=
1408 new_regloc.type =
1410 new_regloc.location.register_number =
1411 return_address_reg.GetAsKind(eRegisterKindLLDB);
1412 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc;
1413 regloc = new_regloc;
1414 UnwindLogMsg("supplying caller's register %s (%d) from the live "
1415 "RegisterContext at frame 0, saved in %d",
1416 return_address_reg.GetName(),
1417 return_address_reg.GetAsKind(eRegisterKindLLDB),
1418 return_address_reg.GetAsKind(eRegisterKindLLDB));
1420 }
1421 }
1422
1423 // If this architecture stores the return address in a register (it
1424 // defines a Return Address register) and we're on a non-zero stack frame
1425 // and the Full UnwindPlan says that the pc is stored in the
1426 // RA registers (e.g. lr on arm), then we know that the full unwindplan is
1427 // not trustworthy -- this
1428 // is an impossible situation and the instruction emulation code has
1429 // likely been misled. If this stack frame meets those criteria, we need
1430 // to throw away the Full UnwindPlan that the instruction emulation came
1431 // up with and fall back to the architecture's Default UnwindPlan so the
1432 // stack walk can get past this point.
1433
1434 // Special note: If the Full UnwindPlan was generated from the compiler,
1435 // don't second-guess it when we're at a call site location.
1436
1437 // arch_default_ra_regnum is the return address register # in the Full
1438 // UnwindPlan register numbering
1439 RegisterNumber arch_default_ra_regnum(m_thread, eRegisterKindGeneric,
1441
1442 if (arch_default_ra_regnum.GetAsKind(unwindplan_registerkind) !=
1444 pc_regnum == regnum && unwindplan_regloc.IsInOtherRegister() &&
1445 unwindplan_regloc.GetRegisterNumber() ==
1446 arch_default_ra_regnum.GetAsKind(unwindplan_registerkind) &&
1447 m_full_unwind_plan_sp->GetSourcedFromCompiler() != eLazyBoolYes &&
1449 UnwindLogMsg("%s UnwindPlan tried to restore the pc from the link "
1450 "register but this is a non-zero frame",
1451 m_full_unwind_plan_sp->GetSourceName().GetCString());
1452
1453 // Throw away the full unwindplan; install the arch default unwindplan
1455 // Update for the possibly new unwind plan
1456 unwindplan_registerkind = m_full_unwind_plan_sp->GetRegisterKind();
1457 UnwindPlan::RowSP active_row =
1458 m_full_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1459
1460 // Sanity check: Verify that we can fetch a pc value and CFA value
1461 // with this unwind plan
1462
1463 RegisterNumber arch_default_pc_reg(m_thread, eRegisterKindGeneric,
1465 bool can_fetch_pc_value = false;
1466 bool can_fetch_cfa = false;
1467 addr_t cfa_value;
1468 if (active_row) {
1469 if (arch_default_pc_reg.GetAsKind(unwindplan_registerkind) !=
1471 active_row->GetRegisterInfo(
1472 arch_default_pc_reg.GetAsKind(unwindplan_registerkind),
1473 unwindplan_regloc)) {
1474 can_fetch_pc_value = true;
1475 }
1476 if (ReadFrameAddress(unwindplan_registerkind,
1477 active_row->GetCFAValue(), cfa_value)) {
1478 can_fetch_cfa = true;
1479 }
1480 }
1481
1482 have_unwindplan_regloc = can_fetch_pc_value && can_fetch_cfa;
1483 } else {
1484 // We were unable to fall back to another unwind plan
1485 have_unwindplan_regloc = false;
1486 }
1487 }
1488 }
1489 }
1490
1491 ExecutionContext exe_ctx(m_thread.shared_from_this());
1492 Process *process = exe_ctx.GetProcessPtr();
1493 if (!have_unwindplan_regloc) {
1494 // If the UnwindPlan failed to give us an unwind location for this
1495 // register, we may be able to fall back to some ABI-defined default. For
1496 // example, some ABIs allow to determine the caller's SP via the CFA. Also,
1497 // the ABI may set volatile registers to the undefined state.
1498 ABI *abi = process ? process->GetABI().get() : nullptr;
1499 if (abi) {
1500 const RegisterInfo *reg_info =
1502 if (reg_info &&
1503 abi->GetFallbackRegisterLocation(reg_info, unwindplan_regloc)) {
1505 "supplying caller's saved %s (%d)'s location using ABI default",
1506 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1507 have_unwindplan_regloc = true;
1508 }
1509 }
1510 }
1511
1512 if (!have_unwindplan_regloc) {
1513 if (IsFrameZero()) {
1514 // This is frame 0 - we should return the actual live register context
1515 // value
1517 new_regloc.type =
1520 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc;
1521 regloc = new_regloc;
1522 UnwindLogMsg("supplying caller's register %s (%d) from the live "
1523 "RegisterContext at frame 0",
1524 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1526 } else {
1527 std::string unwindplan_name;
1529 unwindplan_name += "via '";
1530 unwindplan_name += m_full_unwind_plan_sp->GetSourceName().AsCString();
1531 unwindplan_name += "'";
1532 }
1533 UnwindLogMsg("no save location for %s (%d) %s", regnum.GetName(),
1535 unwindplan_name.c_str());
1536 }
1538 }
1539
1540 // unwindplan_regloc has valid contents about where to retrieve the register
1541 if (unwindplan_regloc.IsUnspecified()) {
1544 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc;
1545 UnwindLogMsg("save location for %s (%d) is unspecified, continue searching",
1546 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1548 }
1549
1550 if (unwindplan_regloc.IsUndefined()) {
1552 "did not supply reg location for %s (%d) because it is volatile",
1553 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1555 }
1556
1557 if (unwindplan_regloc.IsSame()) {
1561 UnwindLogMsg("register %s (%d) is marked as 'IsSame' - it is a pc or "
1562 "return address reg on a frame which does not have all "
1563 "registers available -- treat as if we have no information",
1564 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1566 } else {
1569 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1571 "supplying caller's register %s (%d), saved in register %s (%d)",
1572 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1573 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1575 }
1576 }
1577
1578 if (unwindplan_regloc.IsCFAPlusOffset()) {
1579 int offset = unwindplan_regloc.GetOffset();
1581 regloc.location.inferred_value = m_cfa + offset;
1582 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1583 UnwindLogMsg("supplying caller's register %s (%d), value is CFA plus "
1584 "offset %d [value is 0x%" PRIx64 "]",
1585 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1586 regloc.location.inferred_value);
1588 }
1589
1590 if (unwindplan_regloc.IsAtCFAPlusOffset()) {
1591 int offset = unwindplan_regloc.GetOffset();
1593 regloc.location.target_memory_location = m_cfa + offset;
1594 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1595 UnwindLogMsg("supplying caller's register %s (%d) from the stack, saved at "
1596 "CFA plus offset %d [saved at 0x%" PRIx64 "]",
1597 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1600 }
1601
1602 if (unwindplan_regloc.IsAFAPlusOffset()) {
1605
1606 int offset = unwindplan_regloc.GetOffset();
1608 regloc.location.inferred_value = m_afa + offset;
1609 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1610 UnwindLogMsg("supplying caller's register %s (%d), value is AFA plus "
1611 "offset %d [value is 0x%" PRIx64 "]",
1612 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1613 regloc.location.inferred_value);
1615 }
1616
1617 if (unwindplan_regloc.IsAtAFAPlusOffset()) {
1620
1621 int offset = unwindplan_regloc.GetOffset();
1623 regloc.location.target_memory_location = m_afa + offset;
1624 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1625 UnwindLogMsg("supplying caller's register %s (%d) from the stack, saved at "
1626 "AFA plus offset %d [saved at 0x%" PRIx64 "]",
1627 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1630 }
1631
1632 if (unwindplan_regloc.IsInOtherRegister()) {
1633 uint32_t unwindplan_regnum = unwindplan_regloc.GetRegisterNumber();
1634 RegisterNumber row_regnum(m_thread, unwindplan_registerkind,
1635 unwindplan_regnum);
1636 if (row_regnum.GetAsKind(eRegisterKindLLDB) == LLDB_INVALID_REGNUM) {
1637 UnwindLogMsg("could not supply caller's %s (%d) location - was saved in "
1638 "another reg but couldn't convert that regnum",
1639 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1641 }
1644 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1646 "supplying caller's register %s (%d), saved in register %s (%d)",
1647 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1648 row_regnum.GetName(), row_regnum.GetAsKind(eRegisterKindLLDB));
1650 }
1651
1652 if (unwindplan_regloc.IsDWARFExpression() ||
1653 unwindplan_regloc.IsAtDWARFExpression()) {
1654 DataExtractor dwarfdata(unwindplan_regloc.GetDWARFExpressionBytes(),
1655 unwindplan_regloc.GetDWARFExpressionLength(),
1656 process->GetByteOrder(),
1657 process->GetAddressByteSize());
1658 ModuleSP opcode_ctx;
1659 DWARFExpressionList dwarfexpr(opcode_ctx, dwarfdata, nullptr);
1661 unwindplan_registerkind);
1662 Value cfa_val = Scalar(m_cfa);
1664 llvm::Expected<Value> result =
1665 dwarfexpr.Evaluate(&exe_ctx, this, 0, &cfa_val, nullptr);
1666 if (!result) {
1667 LLDB_LOG_ERROR(log, result.takeError(),
1668 "DWARF expression failed to evaluate: {0}");
1669 } else {
1670 addr_t val;
1671 val = result->GetScalar().ULongLong();
1672 if (unwindplan_regloc.IsDWARFExpression()) {
1674 regloc.location.inferred_value = val;
1675 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1676 UnwindLogMsg("supplying caller's register %s (%d) via DWARF expression "
1677 "(IsDWARFExpression)",
1678 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1680 } else {
1681 regloc.type =
1683 regloc.location.target_memory_location = val;
1684 m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1685 UnwindLogMsg("supplying caller's register %s (%d) via DWARF expression "
1686 "(IsAtDWARFExpression)",
1687 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1689 }
1690 }
1691 UnwindLogMsg("tried to use IsDWARFExpression or IsAtDWARFExpression for %s "
1692 "(%d) but failed",
1693 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1695 }
1696
1697 UnwindLogMsg("no save location for %s (%d) in this stack frame",
1698 regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1699
1700 // FIXME UnwindPlan::Row types atDWARFExpression and isDWARFExpression are
1701 // unsupported.
1702
1704}
1705
1706// TryFallbackUnwindPlan() -- this method is a little tricky.
1707//
1708// When this is called, the frame above -- the caller frame, the "previous"
1709// frame -- is invalid or bad.
1710//
1711// Instead of stopping the stack walk here, we'll try a different UnwindPlan
1712// and see if we can get a valid frame above us.
1713//
1714// This most often happens when an unwind plan based on assembly instruction
1715// inspection is not correct -- mostly with hand-written assembly functions or
1716// functions where the stack frame is set up "out of band", e.g. the kernel
1717// saved the register context and then called an asynchronous trap handler like
1718// _sigtramp.
1719//
1720// Often in these cases, if we just do a dumb stack walk we'll get past this
1721// tricky frame and our usual techniques can continue to be used.
1722
1724 if (m_fallback_unwind_plan_sp.get() == nullptr)
1725 return false;
1726
1727 if (m_full_unwind_plan_sp.get() == nullptr)
1728 return false;
1729
1731 m_full_unwind_plan_sp->GetSourceName() ==
1732 m_fallback_unwind_plan_sp->GetSourceName()) {
1733 return false;
1734 }
1735
1736 // If a compiler generated unwind plan failed, trying the arch default
1737 // unwindplan isn't going to do any better.
1738 if (m_full_unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolYes)
1739 return false;
1740
1741 // Get the caller's pc value and our own CFA value. Swap in the fallback
1742 // unwind plan, re-fetch the caller's pc value and CFA value. If they're the
1743 // same, then the fallback unwind plan provides no benefit.
1744
1747
1748 addr_t old_caller_pc_value = LLDB_INVALID_ADDRESS;
1749 addr_t new_caller_pc_value = LLDB_INVALID_ADDRESS;
1750 UnwindLLDB::RegisterLocation regloc = {};
1752 regloc) ==
1754 const RegisterInfo *reg_info =
1756 if (reg_info) {
1757 RegisterValue reg_value;
1758 if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
1759 old_caller_pc_value = reg_value.GetAsUInt64();
1760 if (ProcessSP process_sp = m_thread.GetProcess()) {
1761 if (ABISP abi_sp = process_sp->GetABI())
1762 old_caller_pc_value = abi_sp->FixCodeAddress(old_caller_pc_value);
1763 }
1764 }
1765 }
1766 }
1767
1768 // This is a tricky wrinkle! If SavedLocationForRegister() detects a really
1769 // impossible register location for the full unwind plan, it may call
1770 // ForceSwitchToFallbackUnwindPlan() which in turn replaces the full
1771 // unwindplan with the fallback... in short, we're done, we're using the
1772 // fallback UnwindPlan. We checked if m_fallback_unwind_plan_sp was nullptr
1773 // at the top -- the only way it became nullptr since then is via
1774 // SavedLocationForRegister().
1775 if (m_fallback_unwind_plan_sp.get() == nullptr)
1776 return true;
1777
1778 // Switch the full UnwindPlan to be the fallback UnwindPlan. If we decide
1779 // this isn't working, we need to restore. We'll also need to save & restore
1780 // the value of the m_cfa ivar. Save is down below a bit in 'old_cfa'.
1781 UnwindPlanSP original_full_unwind_plan_sp = m_full_unwind_plan_sp;
1782 addr_t old_cfa = m_cfa;
1783 addr_t old_afa = m_afa;
1784
1785 m_registers.clear();
1786
1788
1789 UnwindPlan::RowSP active_row =
1790 m_fallback_unwind_plan_sp->GetRowForFunctionOffset(
1792
1793 if (active_row &&
1794 active_row->GetCFAValue().GetValueType() !=
1796 addr_t new_cfa;
1797 if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1798 active_row->GetCFAValue(), new_cfa) ||
1799 new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1800 UnwindLogMsg("failed to get cfa with fallback unwindplan");
1802 m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1803 return false;
1804 }
1805 m_cfa = new_cfa;
1806
1808 active_row->GetAFAValue(), m_afa);
1809
1811 regloc) ==
1813 const RegisterInfo *reg_info =
1815 if (reg_info) {
1816 RegisterValue reg_value;
1817 if (ReadRegisterValueFromRegisterLocation(regloc, reg_info,
1818 reg_value)) {
1819 new_caller_pc_value = reg_value.GetAsUInt64();
1820 if (ProcessSP process_sp = m_thread.GetProcess()) {
1821 if (ABISP abi_sp = process_sp->GetABI())
1822 new_caller_pc_value = abi_sp->FixCodeAddress(new_caller_pc_value);
1823 }
1824 }
1825 }
1826 }
1827
1828 if (new_caller_pc_value == LLDB_INVALID_ADDRESS) {
1829 UnwindLogMsg("failed to get a pc value for the caller frame with the "
1830 "fallback unwind plan");
1832 m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1833 m_cfa = old_cfa;
1834 m_afa = old_afa;
1835 return false;
1836 }
1837
1838 if (old_caller_pc_value == new_caller_pc_value &&
1839 m_cfa == old_cfa &&
1840 m_afa == old_afa) {
1841 UnwindLogMsg("fallback unwind plan got the same values for this frame "
1842 "CFA and caller frame pc, not using");
1844 m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1845 return false;
1846 }
1847
1848 UnwindLogMsg("trying to unwind from this function with the UnwindPlan '%s' "
1849 "because UnwindPlan '%s' failed.",
1850 m_fallback_unwind_plan_sp->GetSourceName().GetCString(),
1851 original_full_unwind_plan_sp->GetSourceName().GetCString());
1852
1853 // We've copied the fallback unwind plan into the full - now clear the
1854 // fallback.
1857 }
1858
1859 return true;
1860}
1861
1863 if (m_fallback_unwind_plan_sp.get() == nullptr)
1864 return false;
1865
1866 if (m_full_unwind_plan_sp.get() == nullptr)
1867 return false;
1868
1870 m_full_unwind_plan_sp->GetSourceName() ==
1871 m_fallback_unwind_plan_sp->GetSourceName()) {
1872 return false;
1873 }
1874
1875 UnwindPlan::RowSP active_row =
1876 m_fallback_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1877
1878 if (active_row &&
1879 active_row->GetCFAValue().GetValueType() !=
1881 addr_t new_cfa;
1882 if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1883 active_row->GetCFAValue(), new_cfa) ||
1884 new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1885 UnwindLogMsg("failed to get cfa with fallback unwindplan");
1887 return false;
1888 }
1889
1891 active_row->GetAFAValue(), m_afa);
1892
1895
1896 m_registers.clear();
1897
1898 m_cfa = new_cfa;
1899
1901
1902 UnwindLogMsg("switched unconditionally to the fallback unwindplan %s",
1903 m_full_unwind_plan_sp->GetSourceName().GetCString());
1904 return true;
1905 }
1906 return false;
1907}
1908
1910 lldb::UnwindPlanSP unwind_plan) {
1911 if (unwind_plan->GetUnwindPlanForSignalTrap() != eLazyBoolYes) {
1912 // Unwind plan does not indicate trap handler. Do nothing. We may
1913 // already be flagged as trap handler flag due to the symbol being
1914 // in the trap handler symbol list, and that should take precedence.
1915 return;
1916 } else if (m_frame_type != eNormalFrame) {
1917 // If this is already a trap handler frame, nothing to do.
1918 // If this is a skip or debug or invalid frame, don't override that.
1919 return;
1920 }
1921
1923
1925 // We backed up the pc by 1 to compute the symbol context, but
1926 // now need to undo that because the pc of the trap handler
1927 // frame may in fact be the first instruction of a signal return
1928 // trampoline, rather than the instruction after a call. This
1929 // happens on systems where the signal handler dispatch code, rather
1930 // than calling the handler and being returned to, jumps to the
1931 // handler after pushing the address of a return trampoline on the
1932 // stack -- on these systems, when the handler returns, control will
1933 // be transferred to the return trampoline, so that's the best
1934 // symbol we can present in the callstack.
1935 UnwindLogMsg("Resetting current offset and re-doing symbol lookup; "
1936 "old symbol was %s",
1937 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
1939
1940 AddressRange addr_range;
1942
1943 UnwindLogMsg("Symbol is now %s",
1944 GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
1945
1946 ExecutionContext exe_ctx(m_thread.shared_from_this());
1947 Process *process = exe_ctx.GetProcessPtr();
1948 Target *target = &process->GetTarget();
1949
1950 m_start_pc = addr_range.GetBaseAddress();
1953 }
1954}
1955
1957 lldb::RegisterKind row_register_kind, UnwindPlan::Row::FAValue &fa,
1958 addr_t &address) {
1959 RegisterValue reg_value;
1960
1961 address = LLDB_INVALID_ADDRESS;
1962 addr_t cfa_reg_contents;
1963 ABISP abi_sp = m_thread.GetProcess()->GetABI();
1964
1965 switch (fa.GetValueType()) {
1967 RegisterNumber cfa_reg(m_thread, row_register_kind,
1968 fa.GetRegisterNumber());
1969 if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
1970 const RegisterInfo *reg_info =
1972 RegisterValue reg_value;
1973 if (reg_info) {
1974 if (abi_sp)
1975 cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
1977 reg_info, cfa_reg_contents, reg_info->byte_size, reg_value);
1978 if (error.Success()) {
1979 address = reg_value.GetAsUInt64();
1980 if (abi_sp)
1981 address = abi_sp->FixCodeAddress(address);
1983 "CFA value via dereferencing reg %s (%d): reg has val 0x%" PRIx64
1984 ", CFA value is 0x%" PRIx64,
1985 cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
1986 cfa_reg_contents, address);
1987 return true;
1988 } else {
1989 UnwindLogMsg("Tried to deref reg %s (%d) [0x%" PRIx64
1990 "] but memory read failed.",
1991 cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
1992 cfa_reg_contents);
1993 }
1994 }
1995 }
1996 break;
1997 }
1999 RegisterNumber cfa_reg(m_thread, row_register_kind,
2000 fa.GetRegisterNumber());
2001 if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
2002 if (abi_sp)
2003 cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
2004 if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
2005 cfa_reg_contents == 1) {
2007 "Got an invalid CFA register value - reg %s (%d), value 0x%" PRIx64,
2008 cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
2009 cfa_reg_contents);
2010 cfa_reg_contents = LLDB_INVALID_ADDRESS;
2011 return false;
2012 }
2013 address = cfa_reg_contents + fa.GetOffset();
2015 "CFA is 0x%" PRIx64 ": Register %s (%d) contents are 0x%" PRIx64
2016 ", offset is %d",
2017 address, cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
2018 cfa_reg_contents, fa.GetOffset());
2019 return true;
2020 }
2021 break;
2022 }
2024 ExecutionContext exe_ctx(m_thread.shared_from_this());
2025 Process *process = exe_ctx.GetProcessPtr();
2028 process->GetByteOrder(),
2029 process->GetAddressByteSize());
2030 ModuleSP opcode_ctx;
2031 DWARFExpressionList dwarfexpr(opcode_ctx, dwarfdata, nullptr);
2033 row_register_kind);
2034 llvm::Expected<Value> result =
2035 dwarfexpr.Evaluate(&exe_ctx, this, 0, nullptr, nullptr);
2036 if (result) {
2037 address = result->GetScalar().ULongLong();
2038 if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2039 address = abi_sp->FixCodeAddress(address);
2040
2041 UnwindLogMsg("CFA value set by DWARF expression is 0x%" PRIx64,
2042 address);
2043 return true;
2044 }
2045 UnwindLogMsg("Failed to set CFA value via DWARF expression: %s",
2046 llvm::toString(result.takeError()).c_str());
2047 break;
2048 }
2050 Process &process = *m_thread.GetProcess();
2051 lldb::addr_t return_address_hint = GetReturnAddressHint(fa.GetOffset());
2052 if (return_address_hint == LLDB_INVALID_ADDRESS)
2053 return false;
2054 const unsigned max_iterations = 256;
2055 for (unsigned i = 0; i < max_iterations; ++i) {
2056 Status st;
2057 lldb::addr_t candidate_addr =
2058 return_address_hint + i * process.GetAddressByteSize();
2059 lldb::addr_t candidate =
2060 process.ReadPointerFromMemory(candidate_addr, st);
2061 if (st.Fail()) {
2062 UnwindLogMsg("Cannot read memory at 0x%" PRIx64 ": %s", candidate_addr,
2063 st.AsCString());
2064 return false;
2065 }
2066 Address addr;
2067 uint32_t permissions;
2068 if (process.GetLoadAddressPermissions(candidate, permissions) &&
2069 permissions & lldb::ePermissionsExecutable) {
2070 address = candidate_addr;
2071 UnwindLogMsg("Heuristically found CFA: 0x%" PRIx64, address);
2072 return true;
2073 }
2074 }
2075 UnwindLogMsg("No suitable CFA found");
2076 break;
2077 }
2078 default:
2079 return false;
2080 }
2081 return false;
2082}
2083
2085 addr_t hint;
2087 return LLDB_INVALID_ADDRESS;
2089 return LLDB_INVALID_ADDRESS;
2090 if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2091 hint = abi_sp->FixCodeAddress(hint);
2092
2093 hint += plan_offset;
2094
2095 if (auto next = GetNextFrame()) {
2096 if (!next->m_sym_ctx.module_sp || !next->m_sym_ctx.symbol)
2097 return LLDB_INVALID_ADDRESS;
2098 if (auto expected_size =
2099 next->m_sym_ctx.module_sp->GetSymbolFile()->GetParameterStackSize(
2100 *next->m_sym_ctx.symbol))
2101 hint += *expected_size;
2102 else {
2103 UnwindLogMsgVerbose("Could not retrieve parameter size: %s",
2104 llvm::toString(expected_size.takeError()).c_str());
2105 return LLDB_INVALID_ADDRESS;
2106 }
2107 }
2108 return hint;
2109}
2110
2111// Retrieve a general purpose register value for THIS frame, as saved by the
2112// NEXT frame, i.e. the frame that
2113// this frame called. e.g.
2114//
2115// foo () { }
2116// bar () { foo (); }
2117// main () { bar (); }
2118//
2119// stopped in foo() so
2120// frame 0 - foo
2121// frame 1 - bar
2122// frame 2 - main
2123// and this RegisterContext is for frame 1 (bar) - if we want to get the pc
2124// value for frame 1, we need to ask
2125// where frame 0 (the "next" frame) saved that and retrieve the value.
2126
2128 uint32_t regnum, addr_t &value) {
2129 if (!IsValid())
2130 return false;
2131
2132 uint32_t lldb_regnum;
2133 if (register_kind == eRegisterKindLLDB) {
2134 lldb_regnum = regnum;
2135 } else if (!m_thread.GetRegisterContext()->ConvertBetweenRegisterKinds(
2136 register_kind, regnum, eRegisterKindLLDB, lldb_regnum)) {
2137 return false;
2138 }
2139
2140 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(lldb_regnum);
2141 assert(reg_info);
2142 if (!reg_info) {
2144 "Could not find RegisterInfo definition for lldb register number %d",
2145 lldb_regnum);
2146 return false;
2147 }
2148
2149 uint32_t generic_regnum = LLDB_INVALID_REGNUM;
2150 if (register_kind == eRegisterKindGeneric)
2151 generic_regnum = regnum;
2152 else
2153 m_thread.GetRegisterContext()->ConvertBetweenRegisterKinds(
2154 register_kind, regnum, eRegisterKindGeneric, generic_regnum);
2155 ABISP abi_sp = m_thread.GetProcess()->GetABI();
2156
2157 RegisterValue reg_value;
2158 // if this is frame 0 (currently executing frame), get the requested reg
2159 // contents from the actual thread registers
2160 if (IsFrameZero()) {
2161 if (m_thread.GetRegisterContext()->ReadRegister(reg_info, reg_value)) {
2162 value = reg_value.GetAsUInt64();
2163 if (abi_sp && generic_regnum != LLDB_INVALID_REGNUM) {
2164 if (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
2165 generic_regnum == LLDB_REGNUM_GENERIC_RA)
2166 value = abi_sp->FixCodeAddress(value);
2167 if (generic_regnum == LLDB_REGNUM_GENERIC_SP ||
2168 generic_regnum == LLDB_REGNUM_GENERIC_FP)
2169 value = abi_sp->FixDataAddress(value);
2170 }
2171 return true;
2172 }
2173 return false;
2174 }
2175
2176 bool pc_register = false;
2177 if (generic_regnum != LLDB_INVALID_REGNUM &&
2178 (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
2179 generic_regnum == LLDB_REGNUM_GENERIC_RA))
2180 pc_register = true;
2181
2184 lldb_regnum, regloc, m_frame_number - 1, pc_register)) {
2185 return false;
2186 }
2187 if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
2188 value = reg_value.GetAsUInt64();
2189 if (pc_register) {
2190 if (ABISP abi_sp = m_thread.GetProcess()->GetABI()) {
2191 value = abi_sp->FixCodeAddress(value);
2192 }
2193 }
2194 return true;
2195 }
2196 return false;
2197}
2198
2200 addr_t &value) {
2201 return ReadGPRValue(regnum.GetRegisterKind(), regnum.GetRegisterNumber(),
2202 value);
2203}
2204
2205// Find the value of a register in THIS frame
2206
2208 RegisterValue &value) {
2209 if (!IsValid())
2210 return false;
2211
2212 const uint32_t lldb_regnum = reg_info->kinds[eRegisterKindLLDB];
2213 UnwindLogMsgVerbose("looking for register saved location for reg %d",
2214 lldb_regnum);
2215
2216 // If this is the 0th frame, hand this over to the live register context
2217 if (IsFrameZero()) {
2218 UnwindLogMsgVerbose("passing along to the live register context for reg %d",
2219 lldb_regnum);
2220 return m_thread.GetRegisterContext()->ReadRegister(reg_info, value);
2221 }
2222
2223 bool is_pc_regnum = false;
2226 is_pc_regnum = true;
2227 }
2228
2230 // Find out where the NEXT frame saved THIS frame's register contents
2232 lldb_regnum, regloc, m_frame_number - 1, is_pc_regnum))
2233 return false;
2234
2235 bool result = ReadRegisterValueFromRegisterLocation(regloc, reg_info, value);
2236 if (result) {
2237 if (is_pc_regnum && value.GetType() == RegisterValue::eTypeUInt64) {
2238 addr_t reg_value = value.GetAsUInt64(LLDB_INVALID_ADDRESS);
2239 if (reg_value != LLDB_INVALID_ADDRESS) {
2240 if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2241 value = abi_sp->FixCodeAddress(reg_value);
2242 }
2243 }
2244 }
2245 return result;
2246}
2247
2249 const RegisterValue &value) {
2250 if (!IsValid())
2251 return false;
2252
2253 const uint32_t lldb_regnum = reg_info->kinds[eRegisterKindLLDB];
2254 UnwindLogMsgVerbose("looking for register saved location for reg %d",
2255 lldb_regnum);
2256
2257 // If this is the 0th frame, hand this over to the live register context
2258 if (IsFrameZero()) {
2259 UnwindLogMsgVerbose("passing along to the live register context for reg %d",
2260 lldb_regnum);
2261 return m_thread.GetRegisterContext()->WriteRegister(reg_info, value);
2262 }
2263
2265 // Find out where the NEXT frame saved THIS frame's register contents
2267 lldb_regnum, regloc, m_frame_number - 1, false))
2268 return false;
2269
2270 return WriteRegisterValueToRegisterLocation(regloc, reg_info, value);
2271}
2272
2273// Don't need to implement this one
2275 lldb::WritableDataBufferSP &data_sp) {
2276 return false;
2277}
2278
2279// Don't need to implement this one
2281 const lldb::DataBufferSP &data_sp) {
2282 return false;
2283}
2284
2285// Retrieve the pc value for THIS from
2286
2288 if (!IsValid()) {
2289 return false;
2290 }
2291 if (m_cfa == LLDB_INVALID_ADDRESS) {
2292 return false;
2293 }
2294 cfa = m_cfa;
2295 return true;
2296}
2297
2300 if (m_frame_number == 0)
2301 return regctx;
2303}
2304
2308}
2309
2310// Retrieve the address of the start of the function of THIS frame
2311
2313 if (!IsValid())
2314 return false;
2315
2316 if (!m_start_pc.IsValid()) {
2317 bool read_successfully = ReadPC (start_pc);
2318 if (read_successfully)
2319 {
2320 ProcessSP process_sp (m_thread.GetProcess());
2321 if (process_sp)
2322 {
2323 if (ABISP abi_sp = process_sp->GetABI())
2324 start_pc = abi_sp->FixCodeAddress(start_pc);
2325 }
2326 }
2327 return read_successfully;
2328 }
2329 start_pc = m_start_pc.GetLoadAddress(CalculateTarget().get());
2330 return true;
2331}
2332
2333// Retrieve the current pc value for THIS frame, as saved by the NEXT frame.
2334
2336 if (!IsValid())
2337 return false;
2338
2339 bool above_trap_handler = false;
2340 if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
2342 above_trap_handler = true;
2343
2345 // A pc value of 0 or 1 is impossible in the middle of the stack -- it
2346 // indicates the end of a stack walk.
2347 // On the currently executing frame (or such a frame interrupted
2348 // asynchronously by sigtramp et al) this may occur if code has jumped
2349 // through a NULL pointer -- we want to be able to unwind past that frame
2350 // to help find the bug.
2351
2352 if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2353 pc = abi_sp->FixCodeAddress(pc);
2354
2355 return !(m_all_registers_available == false &&
2356 above_trap_handler == false && (pc == 0 || pc == 1));
2357 } else {
2358 return false;
2359 }
2360}
2361
2362void RegisterContextUnwind::UnwindLogMsg(const char *fmt, ...) {
2363 Log *log = GetLog(LLDBLog::Unwind);
2364 if (!log)
2365 return;
2366
2367 va_list args;
2368 va_start(args, fmt);
2369
2370 llvm::SmallString<0> logmsg;
2371 if (VASprintf(logmsg, fmt, args)) {
2372 LLDB_LOGF(log, "%*sth%d/fr%u %s",
2373 m_frame_number < 100 ? m_frame_number : 100, "",
2374 m_thread.GetIndexID(), m_frame_number, logmsg.c_str());
2375 }
2376 va_end(args);
2377}
2378
2380 Log *log = GetLog(LLDBLog::Unwind);
2381 if (!log || !log->GetVerbose())
2382 return;
2383
2384 va_list args;
2385 va_start(args, fmt);
2386
2387 llvm::SmallString<0> logmsg;
2388 if (VASprintf(logmsg, fmt, args)) {
2389 LLDB_LOGF(log, "%*sth%d/fr%u %s",
2390 m_frame_number < 100 ? m_frame_number : 100, "",
2391 m_thread.GetIndexID(), m_frame_number, logmsg.c_str());
2392 }
2393 va_end(args);
2394}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:366
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:382
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 bool GetFallbackRegisterLocation(const RegisterInfo *reg_info, UnwindPlan::Row::RegisterLocation &unwind_regloc)
Definition: ABI.cpp:211
virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan)=0
virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan)=0
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:313
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition: Address.cpp:1047
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:439
bool ResolveFunctionScope(lldb_private::SymbolContext &sym_ctx, lldb_private::AddressRange *addr_range_ptr=nullptr)
Resolve this address to its containing function and optionally get that function's address range.
Definition: Address.cpp:268
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:285
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:329
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Definition: Address.h:448
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
bool GetUnwindPlan(Target &target, const Address &addr, UnwindPlan &unwind_plan)
virtual bool GetUnwindPlan(const Address &addr, UnwindPlan &unwind_plan)=0
A uniqued constant string class.
Definition: ConstString.h:40
bool GetUnwindPlan(const Address &addr, UnwindPlan &unwind_plan)
Return an UnwindPlan based on the call frame information encoded in the FDE of this DWARFCallFrameInf...
"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.
Definition: DataExtractor.h:48
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:693
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:314
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
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:2570
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3589
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition: Process.cpp:2256
lldb::addr_t FixCodeAddress(lldb::addr_t pc)
Some targets might use bits in a code address to indicate a mode switch, ARM uses bit zero to signify...
Definition: Process.cpp:5935
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3593
virtual DynamicLoader * GetDynamicLoader()
Get the dynamic loader plug-in for this process.
Definition: Process.cpp:2843
const lldb::ABISP & GetABI()
Definition: Process.cpp:1528
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1279
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
void UnwindLogMsg(const char *fmt,...) __attribute__((format(printf
bool WriteRegisterValueToRegisterLocation(lldb_private::UnwindLLDB::RegisterLocation regloc, const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value)
bool ReadRegisterValueFromRegisterLocation(lldb_private::UnwindLLDB::RegisterLocation regloc, const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value)
void void UnwindLogMsgVerbose(const char *fmt,...) __attribute__((format(printf
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) override
std::shared_ptr< RegisterContextUnwind > SharedPtr
void PropagateTrapHandlerFlagFromUnwindPlan(lldb::UnwindPlanSP unwind_plan)
Check if the given unwind plan indicates a signal trap handler, and update frame type and symbol cont...
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)
lldb_private::UnwindLLDB::RegisterSearchResult SavedLocationForRegister(uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc)
bool ForceSwitchToFallbackUnwindPlan()
Switch to the fallback unwind plan unconditionally without any safety checks that it is providing bet...
std::map< uint32_t, lldb_private::UnwindLLDB::RegisterLocation > m_registers
bool ReadGPRValue(lldb::RegisterKind register_kind, uint32_t regnum, lldb::addr_t &value)
lldb_private::UnwindLLDB & m_parent_unwind
void void bool IsUnwindPlanValidForCurrentPC(lldb::UnwindPlanSP unwind_plan_sp)
bool TryFallbackUnwindPlan()
If the unwind has to the caller frame has failed, try something else.
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value) override
bool ReadFrameAddress(lldb::RegisterKind register_kind, UnwindPlan::Row::FAValue &fa, lldb::addr_t &address)
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.
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...
virtual Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value)
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
Definition: RegisterValue.h:91
An error handling class.
Definition: Status.h:44
bool Fail() const
Test for error condition.
Definition: Status.cpp:180
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:129
const char * GetData() const
Definition: StreamString.h:45
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
void Clear(bool clear_target)
Clear the object's state.
Symbol * symbol
The Symbol for a given query.
ConstString GetName() const
Definition: Symbol.cpp:548
lldb::PlatformSP GetPlatform()
Definition: Target.h:1444
const ArchSpec & GetArchitecture() const
Definition: Target.h:1023
virtual lldb::RegisterContextSP GetRegisterContext()=0
uint32_t GetIndexID() const
Definition: Thread.cpp:1388
lldb::TargetSP CalculateTarget() override
Definition: Thread.cpp:1390
lldb::ProcessSP GetProcess() const
Definition: Thread.h:155
const std::vector< ConstString > & GetUserSpecifiedTrapHandlerFunctionNames()
Provide the list of user-specified trap handler functions.
Definition: UnwindLLDB.h:106
RegisterContextLLDBSP GetRegisterContextForFrameNum(uint32_t frame_num)
Definition: UnwindLLDB.cpp:469
bool SearchForSavedLocationForRegister(uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num, bool pc_register)
Definition: UnwindLLDB.cpp:476
const uint8_t * GetDWARFExpressionBytes()
Definition: UnwindPlan.h:289
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:395
@ LoadAddress
A load address value.
void SetValueType(ValueType value_type)
Definition: Value.h:89
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:59
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:57
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:87
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:56
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:58
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:331
bool VASprintf(llvm::SmallVectorImpl< char > &buf, const char *fmt, va_list args)
Definition: VASprintf.cpp:19
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:314
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:385
std::shared_ptr< lldb_private::FuncUnwinders > FuncUnwindersSP
Definition: lldb-forward.h:353
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:386
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
Definition: lldb-forward.h:478
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:333
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:334
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Definition: lldb-forward.h:391
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:370
RegisterKind
Register numbering types.
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ kNumRegisterKinds
@ 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.
union lldb_private::UnwindLLDB::RegisterLocation::@37 location