LLDB  mainline
RegisterContextLLDB.cpp
Go to the documentation of this file.
1 //===-- RegisterContextLLDB.cpp --------------------------------*- C++ -*-===//
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 
9 #include "lldb/Core/Address.h"
10 #include "lldb/Core/AddressRange.h"
11 #include "lldb/Core/Module.h"
12 #include "lldb/Core/Value.h"
17 #include "lldb/Symbol/Function.h"
18 #include "lldb/Symbol/ObjectFile.h"
19 #include "lldb/Symbol/Symbol.h"
21 #include "lldb/Target/ABI.h"
24 #include "lldb/Target/Platform.h"
25 #include "lldb/Target/Process.h"
27 #include "lldb/Target/StackFrame.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Target/Thread.h"
31 #include "lldb/Utility/Log.h"
33 #include "lldb/lldb-private.h"
34 
35 #include "RegisterContextLLDB.h"
36 
37 #include <memory>
38 
39 using namespace lldb;
40 using namespace lldb_private;
41 
43  if (sym_ctx.symbol)
44  return sym_ctx.symbol->GetName();
45  else if (sym_ctx.function)
46  return sym_ctx.function->GetName();
47  return ConstString();
48 }
49 
50 RegisterContextLLDB::RegisterContextLLDB(Thread &thread,
51  const SharedPtr &next_frame,
52  SymbolContext &sym_ctx,
53  uint32_t frame_number,
54  UnwindLLDB &unwind_lldb)
55  : RegisterContext(thread, frame_number), m_thread(thread),
56  m_fast_unwind_plan_sp(), m_full_unwind_plan_sp(),
57  m_fallback_unwind_plan_sp(), m_all_registers_available(false),
58  m_frame_type(-1), m_cfa(LLDB_INVALID_ADDRESS),
59  m_afa(LLDB_INVALID_ADDRESS), m_start_pc(),
60  m_current_pc(), m_current_offset(0), m_current_offset_backed_up_one(0),
61  m_sym_ctx(sym_ctx), m_sym_ctx_valid(false), m_frame_number(frame_number),
62  m_registers(), m_parent_unwind(unwind_lldb) {
63  m_sym_ctx.Clear(false);
64  m_sym_ctx_valid = false;
65 
66  if (IsFrameZero()) {
67  InitializeZerothFrame();
68  } else {
69  InitializeNonZerothFrame();
70  }
71 
72  // This same code exists over in the GetFullUnwindPlanForFrame() but it may
73  // not have been executed yet
74  if (IsFrameZero() || next_frame->m_frame_type == eTrapHandlerFrame ||
75  next_frame->m_frame_type == eDebuggerFrame) {
76  m_all_registers_available = true;
77  }
78 }
79 
80 bool RegisterContextLLDB::IsUnwindPlanValidForCurrentPC(
81  lldb::UnwindPlanSP unwind_plan_sp, int &valid_pc_offset) {
82  if (!unwind_plan_sp)
83  return false;
84 
85  // check if m_current_pc is valid
86  if (unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
87  // yes - current offset can be used as is
88  valid_pc_offset = m_current_offset;
89  return true;
90  }
91 
92  // if m_current_offset <= 0, we've got nothing else to try
93  if (m_current_offset <= 0)
94  return false;
95 
96  // check pc - 1 to see if it's valid
97  Address pc_minus_one(m_current_pc);
98  pc_minus_one.SetOffset(m_current_pc.GetOffset() - 1);
99  if (unwind_plan_sp->PlanValidAtAddress(pc_minus_one)) {
100  // *valid_pc_offset = m_current_offset - 1;
101  valid_pc_offset = m_current_pc.GetOffset() - 1;
102  return true;
103  }
104 
105  return false;
106 }
107 
108 // Initialize a RegisterContextLLDB which is the first frame of a stack -- the
109 // zeroth frame or currently executing frame.
110 
111 void RegisterContextLLDB::InitializeZerothFrame() {
113  ExecutionContext exe_ctx(m_thread.shared_from_this());
114  RegisterContextSP reg_ctx_sp = m_thread.GetRegisterContext();
115 
116  if (reg_ctx_sp.get() == NULL) {
117  m_frame_type = eNotAValidFrame;
118  UnwindLogMsg("frame does not have a register context");
119  return;
120  }
121 
122  addr_t current_pc = reg_ctx_sp->GetPC();
123 
124  if (current_pc == LLDB_INVALID_ADDRESS) {
125  m_frame_type = eNotAValidFrame;
126  UnwindLogMsg("frame does not have a pc");
127  return;
128  }
129 
130  Process *process = exe_ctx.GetProcessPtr();
131 
132  // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
133  // this will strip bit zero in case we read a PC from memory or from the LR.
134  // (which would be a no-op in frame 0 where we get it from the register set,
135  // but still a good idea to make the call here for other ABIs that may
136  // exist.)
137  ABI *abi = process->GetABI().get();
138  if (abi)
139  current_pc = abi->FixCodeAddress(current_pc);
140 
141  // Initialize m_current_pc, an Address object, based on current_pc, an
142  // addr_t.
143  m_current_pc.SetLoadAddress(current_pc, &process->GetTarget());
144 
145  // If we don't have a Module for some reason, we're not going to find
146  // symbol/function information - just stick in some reasonable defaults and
147  // hope we can unwind past this frame.
148  ModuleSP pc_module_sp(m_current_pc.GetModule());
149  if (!m_current_pc.IsValid() || !pc_module_sp) {
150  UnwindLogMsg("using architectural default unwind method");
151  }
152 
153  // We require either a symbol or function in the symbols context to be
154  // successfully filled in or this context is of no use to us.
155  const SymbolContextItem resolve_scope =
156  eSymbolContextFunction | eSymbolContextSymbol;
157  if (pc_module_sp.get() && (pc_module_sp->ResolveSymbolContextForAddress(
158  m_current_pc, resolve_scope, m_sym_ctx) &
159  resolve_scope)) {
160  m_sym_ctx_valid = true;
161  }
162 
163  if (m_sym_ctx.symbol) {
164  UnwindLogMsg("with pc value of 0x%" PRIx64 ", symbol name is '%s'",
165  current_pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
166  } else if (m_sym_ctx.function) {
167  UnwindLogMsg("with pc value of 0x%" PRIx64 ", function name is '%s'",
168  current_pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
169  } else {
170  UnwindLogMsg("with pc value of 0x%" PRIx64
171  ", no symbol/function name is known.",
172  current_pc);
173  }
174 
175  AddressRange addr_range;
176  m_sym_ctx.GetAddressRange(resolve_scope, 0, false, addr_range);
177 
178  if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
179  m_frame_type = eTrapHandlerFrame;
180  } else {
181  // FIXME: Detect eDebuggerFrame here.
182  m_frame_type = eNormalFrame;
183  }
184 
185  // If we were able to find a symbol/function, set addr_range to the bounds of
186  // that symbol/function. else treat the current pc value as the start_pc and
187  // record no offset.
188  if (addr_range.GetBaseAddress().IsValid()) {
189  m_start_pc = addr_range.GetBaseAddress();
190  if (m_current_pc.GetSection() == m_start_pc.GetSection()) {
191  m_current_offset = m_current_pc.GetOffset() - m_start_pc.GetOffset();
192  } else if (m_current_pc.GetModule() == m_start_pc.GetModule()) {
193  // This means that whatever symbol we kicked up isn't really correct ---
194  // we should not cross section boundaries ... We really should NULL out
195  // the function/symbol in this case unless there is a bad assumption here
196  // due to inlined functions?
197  m_current_offset =
198  m_current_pc.GetFileAddress() - m_start_pc.GetFileAddress();
199  }
200  m_current_offset_backed_up_one = m_current_offset;
201  } else {
202  m_start_pc = m_current_pc;
203  m_current_offset = -1;
204  m_current_offset_backed_up_one = -1;
205  }
206 
207  // We've set m_frame_type and m_sym_ctx before these calls.
208 
209  m_fast_unwind_plan_sp = GetFastUnwindPlanForFrame();
210  m_full_unwind_plan_sp = GetFullUnwindPlanForFrame();
211 
212  UnwindPlan::RowSP active_row;
213  lldb::RegisterKind row_register_kind = eRegisterKindGeneric;
214  if (m_full_unwind_plan_sp &&
215  m_full_unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
216  active_row =
217  m_full_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
218  row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
219  if (active_row.get() && log) {
220  StreamString active_row_strm;
221  active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread,
222  m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
223  UnwindLogMsg("%s", active_row_strm.GetData());
224  }
225  }
226 
227  if (!active_row.get()) {
228  UnwindLogMsg("could not find an unwindplan row for this frame's pc");
229  m_frame_type = eNotAValidFrame;
230  return;
231  }
232 
233  if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(), m_cfa)) {
234  // Try the fall back unwind plan since the
235  // full unwind plan failed.
236  FuncUnwindersSP func_unwinders_sp;
237  UnwindPlanSP call_site_unwind_plan;
238  bool cfa_status = false;
239 
240  if (m_sym_ctx_valid) {
241  func_unwinders_sp =
242  pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
243  m_current_pc, m_sym_ctx);
244  }
245 
246  if (func_unwinders_sp.get() != nullptr)
247  call_site_unwind_plan =
248  func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget());
249 
250  if (call_site_unwind_plan.get() != nullptr) {
251  m_fallback_unwind_plan_sp = call_site_unwind_plan;
252  if (TryFallbackUnwindPlan())
253  cfa_status = true;
254  }
255  if (!cfa_status) {
256  UnwindLogMsg("could not read CFA value for first frame.");
257  m_frame_type = eNotAValidFrame;
258  return;
259  }
260  } else
261  ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
262 
263  UnwindLogMsg("initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64
264  " afa is 0x%" PRIx64 " using %s UnwindPlan",
265  (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
266  (uint64_t)m_cfa,
267  (uint64_t)m_afa,
268  m_full_unwind_plan_sp->GetSourceName().GetCString());
269 }
270 
271 // Initialize a RegisterContextLLDB for the non-zeroth frame -- rely on the
272 // RegisterContextLLDB "below" it to provide things like its current pc value.
273 
274 void RegisterContextLLDB::InitializeNonZerothFrame() {
276  if (IsFrameZero()) {
277  m_frame_type = eNotAValidFrame;
278  UnwindLogMsg("non-zeroth frame tests positive for IsFrameZero -- that "
279  "shouldn't happen.");
280  return;
281  }
282 
283  if (!GetNextFrame().get() || !GetNextFrame()->IsValid()) {
284  m_frame_type = eNotAValidFrame;
285  UnwindLogMsg("Could not get next frame, marking this frame as invalid.");
286  return;
287  }
288  if (!m_thread.GetRegisterContext()) {
289  m_frame_type = eNotAValidFrame;
290  UnwindLogMsg("Could not get register context for this thread, marking this "
291  "frame as invalid.");
292  return;
293  }
294 
295  addr_t pc;
296  if (!ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, pc)) {
297  UnwindLogMsg("could not get pc value");
298  m_frame_type = eNotAValidFrame;
299  return;
300  }
301 
302  ExecutionContext exe_ctx(m_thread.shared_from_this());
303  Process *process = exe_ctx.GetProcessPtr();
304  // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
305  // this will strip bit zero in case we read a PC from memory or from the LR.
306  ABI *abi = process->GetABI().get();
307  if (abi)
308  pc = abi->FixCodeAddress(pc);
309 
310  if (log) {
311  UnwindLogMsg("pc = 0x%" PRIx64, pc);
312  addr_t reg_val;
313  if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, reg_val))
314  UnwindLogMsg("fp = 0x%" PRIx64, reg_val);
315  if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, reg_val))
316  UnwindLogMsg("sp = 0x%" PRIx64, reg_val);
317  }
318 
319  // A pc of 0x0 means it's the end of the stack crawl unless we're above a trap
320  // handler function
321  bool above_trap_handler = false;
322  if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
323  GetNextFrame()->IsTrapHandlerFrame())
324  above_trap_handler = true;
325 
326  if (pc == 0 || pc == 0x1) {
327  if (!above_trap_handler) {
328  m_frame_type = eNotAValidFrame;
329  UnwindLogMsg("this frame has a pc of 0x0");
330  return;
331  }
332  }
333 
334  const bool allow_section_end = true;
335  m_current_pc.SetLoadAddress(pc, &process->GetTarget(), allow_section_end);
336 
337  // If we don't have a Module for some reason, we're not going to find
338  // symbol/function information - just stick in some reasonable defaults and
339  // hope we can unwind past this frame.
340  ModuleSP pc_module_sp(m_current_pc.GetModule());
341  if (!m_current_pc.IsValid() || !pc_module_sp) {
342  UnwindLogMsg("using architectural default unwind method");
343 
344  // Test the pc value to see if we know it's in an unmapped/non-executable
345  // region of memory.
346  uint32_t permissions;
347  if (process->GetLoadAddressPermissions(pc, permissions) &&
348  (permissions & ePermissionsExecutable) == 0) {
349  // If this is the second frame off the stack, we may have unwound the
350  // first frame incorrectly. But using the architecture default unwind
351  // plan may get us back on track -- albeit possibly skipping a real
352  // frame. Give this frame a clearly-invalid pc and see if we can get any
353  // further.
354  if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
355  GetNextFrame()->IsFrameZero()) {
356  UnwindLogMsg("had a pc of 0x%" PRIx64 " which is not in executable "
357  "memory but on frame 1 -- "
358  "allowing it once.",
359  (uint64_t)pc);
360  m_frame_type = eSkipFrame;
361  } else {
362  // anywhere other than the second frame, a non-executable pc means
363  // we're off in the weeds -- stop now.
364  m_frame_type = eNotAValidFrame;
365  UnwindLogMsg("pc is in a non-executable section of memory and this "
366  "isn't the 2nd frame in the stack walk.");
367  return;
368  }
369  }
370 
371  if (abi) {
372  m_fast_unwind_plan_sp.reset();
373  m_full_unwind_plan_sp =
374  std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
375  abi->CreateDefaultUnwindPlan(*m_full_unwind_plan_sp);
376  if (m_frame_type != eSkipFrame) // don't override eSkipFrame
377  {
378  m_frame_type = eNormalFrame;
379  }
380  m_all_registers_available = false;
381  m_current_offset = -1;
382  m_current_offset_backed_up_one = -1;
383  RegisterKind row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
384  UnwindPlan::RowSP row = m_full_unwind_plan_sp->GetRowForFunctionOffset(0);
385  if (row.get()) {
386  if (!ReadFrameAddress(row_register_kind, row->GetCFAValue(), m_cfa)) {
387  UnwindLogMsg("failed to get cfa value");
388  if (m_frame_type != eSkipFrame) // don't override eSkipFrame
389  {
390  m_frame_type = eNotAValidFrame;
391  }
392  return;
393  }
394 
395  ReadFrameAddress(row_register_kind, row->GetAFAValue(), m_afa);
396 
397  // A couple of sanity checks..
398  if (m_cfa == LLDB_INVALID_ADDRESS || m_cfa == 0 || m_cfa == 1) {
399  UnwindLogMsg("could not find a valid cfa address");
400  m_frame_type = eNotAValidFrame;
401  return;
402  }
403 
404  // m_cfa should point into the stack memory; if we can query memory
405  // region permissions, see if the memory is allocated & readable.
406  if (process->GetLoadAddressPermissions(m_cfa, permissions) &&
407  (permissions & ePermissionsReadable) == 0) {
408  m_frame_type = eNotAValidFrame;
409  UnwindLogMsg(
410  "the CFA points to a region of memory that is not readable");
411  return;
412  }
413  } else {
414  UnwindLogMsg("could not find a row for function offset zero");
415  m_frame_type = eNotAValidFrame;
416  return;
417  }
418 
419  if (CheckIfLoopingStack()) {
420  TryFallbackUnwindPlan();
421  if (CheckIfLoopingStack()) {
422  UnwindLogMsg("same CFA address as next frame, assuming the unwind is "
423  "looping - stopping");
424  m_frame_type = eNotAValidFrame;
425  return;
426  }
427  }
428 
429  UnwindLogMsg("initialized frame cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
430  (uint64_t)m_cfa, (uint64_t)m_afa);
431  return;
432  }
433  m_frame_type = eNotAValidFrame;
434  UnwindLogMsg("could not find any symbol for this pc, or a default unwind "
435  "plan, to continue unwind.");
436  return;
437  }
438 
439  bool resolve_tail_call_address = false; // m_current_pc can be one past the
440  // address range of the function...
441  // If the saved pc does not point to a function/symbol because it is beyond
442  // the bounds of the correct function and there's no symbol there, we do
443  // *not* want ResolveSymbolContextForAddress to back up the pc by 1, because
444  // then we might not find the correct unwind information later. Instead, let
445  // ResolveSymbolContextForAddress fail, and handle the case via
446  // decr_pc_and_recompute_addr_range below.
447  const SymbolContextItem resolve_scope =
448  eSymbolContextFunction | eSymbolContextSymbol;
449  uint32_t resolved_scope = pc_module_sp->ResolveSymbolContextForAddress(
450  m_current_pc, resolve_scope, m_sym_ctx, resolve_tail_call_address);
451 
452  // We require either a symbol or function in the symbols context to be
453  // successfully filled in or this context is of no use to us.
454  if (resolve_scope & resolved_scope) {
455  m_sym_ctx_valid = true;
456  }
457 
458  if (m_sym_ctx.symbol) {
459  UnwindLogMsg("with pc value of 0x%" PRIx64 ", symbol name is '%s'", pc,
460  GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
461  } else if (m_sym_ctx.function) {
462  UnwindLogMsg("with pc value of 0x%" PRIx64 ", function name is '%s'", pc,
463  GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
464  } else {
465  UnwindLogMsg("with pc value of 0x%" PRIx64
466  ", no symbol/function name is known.",
467  pc);
468  }
469 
470  AddressRange addr_range;
471  if (!m_sym_ctx.GetAddressRange(resolve_scope, 0, false, addr_range)) {
472  m_sym_ctx_valid = false;
473  }
474 
475  bool decr_pc_and_recompute_addr_range = false;
476 
477  // If the symbol lookup failed...
478  if (!m_sym_ctx_valid)
479  decr_pc_and_recompute_addr_range = true;
480 
481  // Or if we're in the middle of the stack (and not "above" an asynchronous
482  // event like sigtramp), and our "current" pc is the start of a function...
483  if (GetNextFrame()->m_frame_type != eTrapHandlerFrame &&
484  GetNextFrame()->m_frame_type != eDebuggerFrame &&
485  (!m_sym_ctx_valid ||
486  (addr_range.GetBaseAddress().IsValid() &&
487  addr_range.GetBaseAddress().GetSection() == m_current_pc.GetSection() &&
488  addr_range.GetBaseAddress().GetOffset() == m_current_pc.GetOffset()))) {
489  decr_pc_and_recompute_addr_range = true;
490  }
491 
492  // We need to back up the pc by 1 byte and re-search for the Symbol to handle
493  // the case where the "saved pc" value is pointing to the next function, e.g.
494  // if a function ends with a CALL instruction.
495  // FIXME this may need to be an architectural-dependent behavior; if so we'll
496  // need to add a member function
497  // to the ABI plugin and consult that.
498  if (decr_pc_and_recompute_addr_range) {
499  UnwindLogMsg("Backing up the pc value of 0x%" PRIx64
500  " by 1 and re-doing symbol lookup; old symbol was %s",
501  pc, GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
502  Address temporary_pc;
503  temporary_pc.SetLoadAddress(pc - 1, &process->GetTarget());
504  m_sym_ctx.Clear(false);
505  m_sym_ctx_valid = false;
506  SymbolContextItem resolve_scope =
507  eSymbolContextFunction | eSymbolContextSymbol;
508 
509  ModuleSP temporary_module_sp = temporary_pc.GetModule();
510  if (temporary_module_sp &&
511  temporary_module_sp->ResolveSymbolContextForAddress(
512  temporary_pc, resolve_scope, m_sym_ctx) &
513  resolve_scope) {
514  if (m_sym_ctx.GetAddressRange(resolve_scope, 0, false, addr_range))
515  m_sym_ctx_valid = true;
516  }
517  UnwindLogMsg("Symbol is now %s",
518  GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
519  }
520 
521  // If we were able to find a symbol/function, set addr_range_ptr to the
522  // bounds of that symbol/function. else treat the current pc value as the
523  // start_pc and record no offset.
524  if (addr_range.GetBaseAddress().IsValid()) {
525  m_start_pc = addr_range.GetBaseAddress();
526  m_current_offset = pc - m_start_pc.GetLoadAddress(&process->GetTarget());
527  m_current_offset_backed_up_one = m_current_offset;
528  if (decr_pc_and_recompute_addr_range &&
529  m_current_offset_backed_up_one > 0) {
530  m_current_offset_backed_up_one--;
531  if (m_sym_ctx_valid) {
532  m_current_pc.SetLoadAddress(pc - 1, &process->GetTarget());
533  }
534  }
535  } else {
536  m_start_pc = m_current_pc;
537  m_current_offset = -1;
538  m_current_offset_backed_up_one = -1;
539  }
540 
541  if (IsTrapHandlerSymbol(process, m_sym_ctx)) {
542  m_frame_type = eTrapHandlerFrame;
543  } else {
544  // FIXME: Detect eDebuggerFrame here.
545  if (m_frame_type != eSkipFrame) // don't override eSkipFrame
546  {
547  m_frame_type = eNormalFrame;
548  }
549  }
550 
551  // We've set m_frame_type and m_sym_ctx before this call.
552  m_fast_unwind_plan_sp = GetFastUnwindPlanForFrame();
553 
554  UnwindPlan::RowSP active_row;
555  RegisterKind row_register_kind = eRegisterKindGeneric;
556 
557  // Try to get by with just the fast UnwindPlan if possible - the full
558  // UnwindPlan may be expensive to get (e.g. if we have to parse the entire
559  // eh_frame section of an ObjectFile for the first time.)
560 
561  if (m_fast_unwind_plan_sp &&
562  m_fast_unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
563  active_row =
564  m_fast_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
565  row_register_kind = m_fast_unwind_plan_sp->GetRegisterKind();
566  if (active_row.get() && log) {
567  StreamString active_row_strm;
568  active_row->Dump(active_row_strm, m_fast_unwind_plan_sp.get(), &m_thread,
569  m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
570  UnwindLogMsg("active row: %s", active_row_strm.GetData());
571  }
572  } else {
573  m_full_unwind_plan_sp = GetFullUnwindPlanForFrame();
574  int valid_offset = -1;
575  if (IsUnwindPlanValidForCurrentPC(m_full_unwind_plan_sp, valid_offset)) {
576  active_row = m_full_unwind_plan_sp->GetRowForFunctionOffset(valid_offset);
577  row_register_kind = m_full_unwind_plan_sp->GetRegisterKind();
578  if (active_row.get() && log) {
579  StreamString active_row_strm;
580  active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(),
581  &m_thread,
582  m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
583  UnwindLogMsg("active row: %s", active_row_strm.GetData());
584  }
585  }
586  }
587 
588  if (!active_row.get()) {
589  m_frame_type = eNotAValidFrame;
590  UnwindLogMsg("could not find unwind row for this pc");
591  return;
592  }
593 
594  if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(), m_cfa)) {
595  UnwindLogMsg("failed to get cfa");
596  m_frame_type = eNotAValidFrame;
597  return;
598  }
599 
600  ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
601 
602  UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
603 
604  if (CheckIfLoopingStack()) {
605  TryFallbackUnwindPlan();
606  if (CheckIfLoopingStack()) {
607  UnwindLogMsg("same CFA address as next frame, assuming the unwind is "
608  "looping - stopping");
609  m_frame_type = eNotAValidFrame;
610  return;
611  }
612  }
613 
614  UnwindLogMsg("initialized 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,
618  (uint64_t)m_afa);
619 }
620 
621 bool RegisterContextLLDB::CheckIfLoopingStack() {
622  // If we have a bad stack setup, we can get the same CFA value multiple times
623  // -- or even more devious, we can actually oscillate between two CFA values.
624  // Detect that here and break out to avoid a possible infinite loop in lldb
625  // trying to unwind the stack. To detect when we have the same CFA value
626  // multiple times, we compare the
627  // CFA of the current
628  // frame with the 2nd next frame because in some specail case (e.g. signal
629  // hanlders, hand written assembly without ABI compiance) we can have 2
630  // frames with the same
631  // CFA (in theory we
632  // can have arbitrary number of frames with the same CFA, but more then 2 is
633  // very very unlikely)
634 
635  RegisterContextLLDB::SharedPtr next_frame = GetNextFrame();
636  if (next_frame) {
637  RegisterContextLLDB::SharedPtr next_next_frame = next_frame->GetNextFrame();
638  addr_t next_next_frame_cfa = LLDB_INVALID_ADDRESS;
639  if (next_next_frame && next_next_frame->GetCFA(next_next_frame_cfa)) {
640  if (next_next_frame_cfa == m_cfa) {
641  // We have a loop in the stack unwind
642  return true;
643  }
644  }
645  }
646  return false;
647 }
648 
649 bool RegisterContextLLDB::IsFrameZero() const { return m_frame_number == 0; }
650 
651 // Find a fast unwind plan for this frame, if possible.
652 //
653 // On entry to this method,
654 //
655 // 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame
656 // if either of those are correct,
657 // 2. m_sym_ctx should already be filled in, and
658 // 3. m_current_pc should have the current pc value for this frame
659 // 4. m_current_offset_backed_up_one should have the current byte offset into
660 // the function, maybe backed up by 1, -1 if unknown
661 
662 UnwindPlanSP RegisterContextLLDB::GetFastUnwindPlanForFrame() {
663  UnwindPlanSP unwind_plan_sp;
664  ModuleSP pc_module_sp(m_current_pc.GetModule());
665 
666  if (!m_current_pc.IsValid() || !pc_module_sp ||
667  pc_module_sp->GetObjectFile() == NULL)
668  return unwind_plan_sp;
669 
670  if (IsFrameZero())
671  return unwind_plan_sp;
672 
673  FuncUnwindersSP func_unwinders_sp(
674  pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
675  m_current_pc, m_sym_ctx));
676  if (!func_unwinders_sp)
677  return unwind_plan_sp;
678 
679  // If we're in _sigtramp(), unwinding past this frame requires special
680  // knowledge.
681  if (m_frame_type == eTrapHandlerFrame || m_frame_type == eDebuggerFrame)
682  return unwind_plan_sp;
683 
684  unwind_plan_sp = func_unwinders_sp->GetUnwindPlanFastUnwind(
685  *m_thread.CalculateTarget(), m_thread);
686  if (unwind_plan_sp) {
687  if (unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
689  if (log && log->GetVerbose()) {
690  if (m_fast_unwind_plan_sp)
691  UnwindLogMsgVerbose("frame, and has a fast UnwindPlan");
692  else
693  UnwindLogMsgVerbose("frame");
694  }
695  m_frame_type = eNormalFrame;
696  return unwind_plan_sp;
697  } else {
698  unwind_plan_sp.reset();
699  }
700  }
701  return unwind_plan_sp;
702 }
703 
704 // On entry to this method,
705 //
706 // 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame
707 // if either of those are correct,
708 // 2. m_sym_ctx should already be filled in, and
709 // 3. m_current_pc should have the current pc value for this frame
710 // 4. m_current_offset_backed_up_one should have the current byte offset into
711 // the function, maybe backed up by 1, -1 if unknown
712 
713 UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
714  UnwindPlanSP unwind_plan_sp;
715  UnwindPlanSP arch_default_unwind_plan_sp;
716  ExecutionContext exe_ctx(m_thread.shared_from_this());
717  Process *process = exe_ctx.GetProcessPtr();
718  ABI *abi = process ? process->GetABI().get() : NULL;
719  if (abi) {
720  arch_default_unwind_plan_sp =
721  std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
722  abi->CreateDefaultUnwindPlan(*arch_default_unwind_plan_sp);
723  } else {
724  UnwindLogMsg(
725  "unable to get architectural default UnwindPlan from ABI plugin");
726  }
727 
728  bool behaves_like_zeroth_frame = false;
729  if (IsFrameZero() || GetNextFrame()->m_frame_type == eTrapHandlerFrame ||
730  GetNextFrame()->m_frame_type == eDebuggerFrame) {
731  behaves_like_zeroth_frame = true;
732  // If this frame behaves like a 0th frame (currently executing or
733  // interrupted asynchronously), all registers can be retrieved.
734  m_all_registers_available = true;
735  }
736 
737  // If we've done a jmp 0x0 / bl 0x0 (called through a null function pointer)
738  // so the pc is 0x0 in the zeroth frame, we need to use the "unwind at first
739  // instruction" arch default UnwindPlan Also, if this Process can report on
740  // memory region attributes, any non-executable region means we jumped
741  // through a bad function pointer - handle the same way as 0x0. Note, if we
742  // have a symbol context & a symbol, we don't want to follow this code path.
743  // This is for jumping to memory regions without any information available.
744 
745  if ((!m_sym_ctx_valid ||
746  (m_sym_ctx.function == NULL && m_sym_ctx.symbol == NULL)) &&
747  behaves_like_zeroth_frame && m_current_pc.IsValid()) {
748  uint32_t permissions;
749  addr_t current_pc_addr =
750  m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr());
751  if (current_pc_addr == 0 ||
752  (process &&
753  process->GetLoadAddressPermissions(current_pc_addr, permissions) &&
754  (permissions & ePermissionsExecutable) == 0)) {
755  if (abi) {
756  unwind_plan_sp =
757  std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
758  abi->CreateFunctionEntryUnwindPlan(*unwind_plan_sp);
759  m_frame_type = eNormalFrame;
760  return unwind_plan_sp;
761  }
762  }
763  }
764 
765  // No Module for the current pc, try using the architecture default unwind.
766  ModuleSP pc_module_sp(m_current_pc.GetModule());
767  if (!m_current_pc.IsValid() || !pc_module_sp ||
768  pc_module_sp->GetObjectFile() == NULL) {
769  m_frame_type = eNormalFrame;
770  return arch_default_unwind_plan_sp;
771  }
772 
773  FuncUnwindersSP func_unwinders_sp;
774  if (m_sym_ctx_valid) {
775  func_unwinders_sp =
776  pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
777  m_current_pc, m_sym_ctx);
778  }
779 
780  // No FuncUnwinders available for this pc (stripped function symbols, lldb
781  // could not augment its function table with another source, like
782  // LC_FUNCTION_STARTS or eh_frame in ObjectFileMachO). See if eh_frame or the
783  // .ARM.exidx tables have unwind information for this address, else fall back
784  // to the architectural default unwind.
785  if (!func_unwinders_sp) {
786  m_frame_type = eNormalFrame;
787 
788  if (!pc_module_sp || !pc_module_sp->GetObjectFile() ||
789  !m_current_pc.IsValid())
790  return arch_default_unwind_plan_sp;
791 
792  // Even with -fomit-frame-pointer, we can try eh_frame to get back on
793  // track.
794  DWARFCallFrameInfo *eh_frame =
795  pc_module_sp->GetUnwindTable().GetEHFrameInfo();
796  if (eh_frame) {
797  unwind_plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
798  if (eh_frame->GetUnwindPlan(m_current_pc, *unwind_plan_sp))
799  return unwind_plan_sp;
800  else
801  unwind_plan_sp.reset();
802  }
803 
804  ArmUnwindInfo *arm_exidx =
805  pc_module_sp->GetUnwindTable().GetArmUnwindInfo();
806  if (arm_exidx) {
807  unwind_plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
808  if (arm_exidx->GetUnwindPlan(exe_ctx.GetTargetRef(), m_current_pc,
809  *unwind_plan_sp))
810  return unwind_plan_sp;
811  else
812  unwind_plan_sp.reset();
813  }
814 
815  return arch_default_unwind_plan_sp;
816  }
817 
818  // If we're in _sigtramp(), unwinding past this frame requires special
819  // knowledge. On Mac OS X this knowledge is properly encoded in the eh_frame
820  // section, so prefer that if available. On other platforms we may need to
821  // provide a platform-specific UnwindPlan which encodes the details of how to
822  // unwind out of sigtramp.
823  if (m_frame_type == eTrapHandlerFrame && process) {
824  m_fast_unwind_plan_sp.reset();
825  unwind_plan_sp =
826  func_unwinders_sp->GetEHFrameUnwindPlan(process->GetTarget());
827  if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc) &&
828  unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolYes) {
829  return unwind_plan_sp;
830  }
831  }
832 
833  // Ask the DynamicLoader if the eh_frame CFI should be trusted in this frame
834  // even when it's frame zero This comes up if we have hand-written functions
835  // in a Module and hand-written eh_frame. The assembly instruction
836  // inspection may fail and the eh_frame CFI were probably written with some
837  // care to do the right thing. It'd be nice if there was a way to ask the
838  // eh_frame directly if it is asynchronous (can be trusted at every
839  // instruction point) or synchronous (the normal case - only at call sites).
840  // But there is not.
841  if (process && process->GetDynamicLoader() &&
842  process->GetDynamicLoader()->AlwaysRelyOnEHUnwindInfo(m_sym_ctx)) {
843  // We must specifically call the GetEHFrameUnwindPlan() method here --
844  // normally we would call GetUnwindPlanAtCallSite() -- because CallSite may
845  // return an unwind plan sourced from either eh_frame (that's what we
846  // intend) or compact unwind (this won't work)
847  unwind_plan_sp =
848  func_unwinders_sp->GetEHFrameUnwindPlan(process->GetTarget());
849  if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
850  UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because the "
851  "DynamicLoader suggested we prefer it",
852  unwind_plan_sp->GetSourceName().GetCString());
853  return unwind_plan_sp;
854  }
855  }
856 
857  // Typically the NonCallSite UnwindPlan is the unwind created by inspecting
858  // the assembly language instructions
859  if (behaves_like_zeroth_frame && process) {
860  unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite(
861  process->GetTarget(), m_thread);
862  if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
863  if (unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
864  // We probably have an UnwindPlan created by inspecting assembly
865  // instructions. The assembly profilers work really well with compiler-
866  // generated functions but hand- written assembly can be problematic.
867  // We set the eh_frame based unwind plan as our fallback unwind plan if
868  // instruction emulation doesn't work out even for non call sites if it
869  // is available and use the architecture default unwind plan if it is
870  // not available. The eh_frame unwind plan is more reliable even on non
871  // call sites then the architecture default plan and for hand written
872  // assembly code it is often written in a way that it valid at all
873  // location what helps in the most common cases when the instruction
874  // emulation fails.
875  UnwindPlanSP call_site_unwind_plan =
876  func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget());
877  if (call_site_unwind_plan &&
878  call_site_unwind_plan.get() != unwind_plan_sp.get() &&
879  call_site_unwind_plan->GetSourceName() !=
880  unwind_plan_sp->GetSourceName()) {
881  m_fallback_unwind_plan_sp = call_site_unwind_plan;
882  } else {
883  m_fallback_unwind_plan_sp = arch_default_unwind_plan_sp;
884  }
885  }
886  UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because this "
887  "is the non-call site unwind plan and this is a "
888  "zeroth frame",
889  unwind_plan_sp->GetSourceName().GetCString());
890  return unwind_plan_sp;
891  }
892 
893  // If we're on the first instruction of a function, and we have an
894  // architectural default UnwindPlan for the initial instruction of a
895  // function, use that.
896  if (m_current_offset == 0) {
897  unwind_plan_sp =
898  func_unwinders_sp->GetUnwindPlanArchitectureDefaultAtFunctionEntry(
899  m_thread);
900  if (unwind_plan_sp) {
901  UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because we are at "
902  "the first instruction of a function",
903  unwind_plan_sp->GetSourceName().GetCString());
904  return unwind_plan_sp;
905  }
906  }
907  }
908 
909  // Typically this is unwind info from an eh_frame section intended for
910  // exception handling; only valid at call sites
911  if (process) {
912  unwind_plan_sp =
913  func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget());
914  }
915  int valid_offset = -1;
916  if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp, valid_offset)) {
917  UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because this "
918  "is the call-site unwind plan",
919  unwind_plan_sp->GetSourceName().GetCString());
920  return unwind_plan_sp;
921  }
922 
923  // We'd prefer to use an UnwindPlan intended for call sites when we're at a
924  // call site but if we've struck out on that, fall back to using the non-
925  // call-site assembly inspection UnwindPlan if possible.
926  if (process) {
927  unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite(
928  process->GetTarget(), m_thread);
929  }
930  if (unwind_plan_sp &&
931  unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
932  // We probably have an UnwindPlan created by inspecting assembly
933  // instructions. The assembly profilers work really well with compiler-
934  // generated functions but hand- written assembly can be problematic. We
935  // set the eh_frame based unwind plan as our fallback unwind plan if
936  // instruction emulation doesn't work out even for non call sites if it is
937  // available and use the architecture default unwind plan if it is not
938  // available. The eh_frame unwind plan is more reliable even on non call
939  // sites then the architecture default plan and for hand written assembly
940  // code it is often written in a way that it valid at all location what
941  // helps in the most common cases when the instruction emulation fails.
942  UnwindPlanSP call_site_unwind_plan =
943  func_unwinders_sp->GetUnwindPlanAtCallSite(process->GetTarget());
944  if (call_site_unwind_plan &&
945  call_site_unwind_plan.get() != unwind_plan_sp.get() &&
946  call_site_unwind_plan->GetSourceName() !=
947  unwind_plan_sp->GetSourceName()) {
948  m_fallback_unwind_plan_sp = call_site_unwind_plan;
949  } else {
950  m_fallback_unwind_plan_sp = arch_default_unwind_plan_sp;
951  }
952  }
953 
954  if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp, valid_offset)) {
955  UnwindLogMsgVerbose("frame uses %s for full UnwindPlan because we "
956  "failed to find a call-site unwind plan that would work",
957  unwind_plan_sp->GetSourceName().GetCString());
958  return unwind_plan_sp;
959  }
960 
961  // If nothing else, use the architectural default UnwindPlan and hope that
962  // does the job.
963  if (arch_default_unwind_plan_sp)
964  UnwindLogMsgVerbose(
965  "frame uses %s for full UnwindPlan because we are falling back "
966  "to the arch default plan",
967  arch_default_unwind_plan_sp->GetSourceName().GetCString());
968  else
969  UnwindLogMsg(
970  "Unable to find any UnwindPlan for full unwind of this frame.");
971 
972  return arch_default_unwind_plan_sp;
973 }
974 
976  m_frame_type = eNotAValidFrame;
977 }
978 
980  return m_thread.GetRegisterContext()->GetRegisterCount();
981 }
982 
983 const RegisterInfo *RegisterContextLLDB::GetRegisterInfoAtIndex(size_t reg) {
984  return m_thread.GetRegisterContext()->GetRegisterInfoAtIndex(reg);
985 }
986 
988  return m_thread.GetRegisterContext()->GetRegisterSetCount();
989 }
990 
991 const RegisterSet *RegisterContextLLDB::GetRegisterSet(size_t reg_set) {
992  return m_thread.GetRegisterContext()->GetRegisterSet(reg_set);
993 }
994 
996  lldb::RegisterKind kind, uint32_t num) {
997  return m_thread.GetRegisterContext()->ConvertRegisterKindToRegisterNumber(
998  kind, num);
999 }
1000 
1001 bool RegisterContextLLDB::ReadRegisterValueFromRegisterLocation(
1003  const RegisterInfo *reg_info, RegisterValue &value) {
1004  if (!IsValid())
1005  return false;
1006  bool success = false;
1007 
1008  switch (regloc.type) {
1010  const RegisterInfo *other_reg_info =
1012 
1013  if (!other_reg_info)
1014  return false;
1015 
1016  success =
1017  m_thread.GetRegisterContext()->ReadRegister(other_reg_info, value);
1018  } break;
1020  const RegisterInfo *other_reg_info =
1022 
1023  if (!other_reg_info)
1024  return false;
1025 
1026  if (IsFrameZero()) {
1027  success =
1028  m_thread.GetRegisterContext()->ReadRegister(other_reg_info, value);
1029  } else {
1030  success = GetNextFrame()->ReadRegister(other_reg_info, value);
1031  }
1032  } break;
1034  success =
1035  value.SetUInt(regloc.location.inferred_value, reg_info->byte_size);
1036  break;
1037 
1039  break;
1041  llvm_unreachable("FIXME debugger inferior function call unwind");
1044  reg_info, regloc.location.target_memory_location, reg_info->byte_size,
1045  value));
1046  success = error.Success();
1047  } break;
1048  default:
1049  llvm_unreachable("Unknown RegisterLocation type.");
1050  }
1051  return success;
1052 }
1053 
1054 bool RegisterContextLLDB::WriteRegisterValueToRegisterLocation(
1056  const RegisterInfo *reg_info, const RegisterValue &value) {
1057  if (!IsValid())
1058  return false;
1059 
1060  bool success = false;
1061 
1062  switch (regloc.type) {
1064  const RegisterInfo *other_reg_info =
1066  success =
1067  m_thread.GetRegisterContext()->WriteRegister(other_reg_info, value);
1068  } break;
1070  const RegisterInfo *other_reg_info =
1072  if (IsFrameZero()) {
1073  success =
1074  m_thread.GetRegisterContext()->WriteRegister(other_reg_info, value);
1075  } else {
1076  success = GetNextFrame()->WriteRegister(other_reg_info, value);
1077  }
1078  } break;
1081  break;
1083  llvm_unreachable("FIXME debugger inferior function call unwind");
1086  reg_info, regloc.location.target_memory_location, reg_info->byte_size,
1087  value));
1088  success = error.Success();
1089  } break;
1090  default:
1091  llvm_unreachable("Unknown RegisterLocation type.");
1092  }
1093  return success;
1094 }
1095 
1097  return m_frame_type != eNotAValidFrame;
1098 }
1099 
1100 // After the final stack frame in a stack walk we'll get one invalid
1101 // (eNotAValidFrame) stack frame -- one past the end of the stack walk. But
1102 // higher-level code will need to tell the differnece between "the unwind plan
1103 // below this frame failed" versus "we successfully completed the stack walk"
1104 // so this method helps to disambiguate that.
1105 
1107  return m_frame_type == eTrapHandlerFrame;
1108 }
1109 
1110 // A skip frame is a bogus frame on the stack -- but one where we're likely to
1111 // find a real frame farther
1112 // up the stack if we keep looking. It's always the second frame in an unwind
1113 // (i.e. the first frame after frame zero) where unwinding can be the
1114 // trickiest. Ideally we'll mark up this frame in some way so the user knows
1115 // we're displaying bad data and we may have skipped one frame of their real
1116 // program in the process of getting back on track.
1117 
1118 bool RegisterContextLLDB::IsSkipFrame() const {
1119  return m_frame_type == eSkipFrame;
1120 }
1121 
1122 bool RegisterContextLLDB::IsTrapHandlerSymbol(
1123  lldb_private::Process *process,
1124  const lldb_private::SymbolContext &m_sym_ctx) const {
1125  PlatformSP platform_sp(process->GetTarget().GetPlatform());
1126  if (platform_sp) {
1127  const std::vector<ConstString> trap_handler_names(
1128  platform_sp->GetTrapHandlerSymbolNames());
1129  for (ConstString name : trap_handler_names) {
1130  if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
1131  (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name)) {
1132  return true;
1133  }
1134  }
1135  }
1136  const std::vector<ConstString> user_specified_trap_handler_names(
1137  m_parent_unwind.GetUserSpecifiedTrapHandlerFunctionNames());
1138  for (ConstString name : user_specified_trap_handler_names) {
1139  if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
1140  (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name)) {
1141  return true;
1142  }
1143  }
1144 
1145  return false;
1146 }
1147 
1148 // Answer the question: Where did THIS frame save the CALLER frame ("previous"
1149 // frame)'s register value?
1150 
1152 RegisterContextLLDB::SavedLocationForRegister(
1154  RegisterNumber regnum(m_thread, eRegisterKindLLDB, lldb_regnum);
1155 
1156  // Have we already found this register location?
1157  if (!m_registers.empty()) {
1158  std::map<uint32_t,
1160  iterator;
1161  iterator = m_registers.find(regnum.GetAsKind(eRegisterKindLLDB));
1162  if (iterator != m_registers.end()) {
1163  regloc = iterator->second;
1164  UnwindLogMsg("supplying caller's saved %s (%d)'s location, cached",
1165  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1166  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1167  }
1168  }
1169 
1170  // Look through the available UnwindPlans for the register location.
1171 
1172  UnwindPlan::Row::RegisterLocation unwindplan_regloc;
1173  bool have_unwindplan_regloc = false;
1174  RegisterKind unwindplan_registerkind = kNumRegisterKinds;
1175 
1176  if (m_fast_unwind_plan_sp) {
1177  UnwindPlan::RowSP active_row =
1178  m_fast_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1179  unwindplan_registerkind = m_fast_unwind_plan_sp->GetRegisterKind();
1180  if (regnum.GetAsKind(unwindplan_registerkind) == LLDB_INVALID_REGNUM) {
1181  UnwindLogMsg("could not convert lldb regnum %s (%d) into %d RegisterKind "
1182  "reg numbering scheme",
1183  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1184  (int)unwindplan_registerkind);
1185  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1186  }
1187  if (active_row->GetRegisterInfo(regnum.GetAsKind(unwindplan_registerkind),
1188  unwindplan_regloc)) {
1189  UnwindLogMsg(
1190  "supplying caller's saved %s (%d)'s location using FastUnwindPlan",
1191  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1192  have_unwindplan_regloc = true;
1193  }
1194  }
1195 
1196  if (!have_unwindplan_regloc) {
1197  // m_full_unwind_plan_sp being NULL means that we haven't tried to find a
1198  // full UnwindPlan yet
1199  if (!m_full_unwind_plan_sp)
1200  m_full_unwind_plan_sp = GetFullUnwindPlanForFrame();
1201 
1202  if (m_full_unwind_plan_sp) {
1203  RegisterNumber pc_regnum(m_thread, eRegisterKindGeneric,
1205 
1206  UnwindPlan::RowSP active_row =
1207  m_full_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1208  unwindplan_registerkind = m_full_unwind_plan_sp->GetRegisterKind();
1209 
1210  RegisterNumber return_address_reg;
1211 
1212  // If we're fetching the saved pc and this UnwindPlan defines a
1213  // ReturnAddress register (e.g. lr on arm), look for the return address
1214  // register number in the UnwindPlan's row.
1215  if (pc_regnum.IsValid() && pc_regnum == regnum &&
1216  m_full_unwind_plan_sp->GetReturnAddressRegister() !=
1218 
1219  return_address_reg.init(
1220  m_thread, m_full_unwind_plan_sp->GetRegisterKind(),
1221  m_full_unwind_plan_sp->GetReturnAddressRegister());
1222  regnum = return_address_reg;
1223  UnwindLogMsg("requested caller's saved PC but this UnwindPlan uses a "
1224  "RA reg; getting %s (%d) instead",
1225  return_address_reg.GetName(),
1226  return_address_reg.GetAsKind(eRegisterKindLLDB));
1227  } else {
1228  if (regnum.GetAsKind(unwindplan_registerkind) == LLDB_INVALID_REGNUM) {
1229  if (unwindplan_registerkind == eRegisterKindGeneric) {
1230  UnwindLogMsg("could not convert lldb regnum %s (%d) into "
1231  "eRegisterKindGeneric reg numbering scheme",
1232  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1233  } else {
1234  UnwindLogMsg("could not convert lldb regnum %s (%d) into %d "
1235  "RegisterKind reg numbering scheme",
1236  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1237  (int)unwindplan_registerkind);
1238  }
1239  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1240  }
1241  }
1242 
1243  if (regnum.IsValid() &&
1244  active_row->GetRegisterInfo(regnum.GetAsKind(unwindplan_registerkind),
1245  unwindplan_regloc)) {
1246  have_unwindplan_regloc = true;
1247  UnwindLogMsg(
1248  "supplying caller's saved %s (%d)'s location using %s UnwindPlan",
1249  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1250  m_full_unwind_plan_sp->GetSourceName().GetCString());
1251  }
1252 
1253  // This is frame 0 and we're retrieving the PC and it's saved in a Return
1254  // Address register and it hasn't been saved anywhere yet -- that is,
1255  // it's still live in the actual register. Handle this specially.
1256 
1257  if (!have_unwindplan_regloc && return_address_reg.IsValid() &&
1258  IsFrameZero()) {
1259  if (return_address_reg.GetAsKind(eRegisterKindLLDB) !=
1262  new_regloc.type =
1264  new_regloc.location.register_number =
1265  return_address_reg.GetAsKind(eRegisterKindLLDB);
1266  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc;
1267  regloc = new_regloc;
1268  UnwindLogMsg("supplying caller's register %s (%d) from the live "
1269  "RegisterContext at frame 0, saved in %d",
1270  return_address_reg.GetName(),
1271  return_address_reg.GetAsKind(eRegisterKindLLDB),
1272  return_address_reg.GetAsKind(eRegisterKindLLDB));
1273  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1274  }
1275  }
1276 
1277  // If this architecture stores the return address in a register (it
1278  // defines a Return Address register) and we're on a non-zero stack frame
1279  // and the Full UnwindPlan says that the pc is stored in the
1280  // RA registers (e.g. lr on arm), then we know that the full unwindplan is
1281  // not trustworthy -- this
1282  // is an impossible situation and the instruction emulation code has
1283  // likely been misled. If this stack frame meets those criteria, we need
1284  // to throw away the Full UnwindPlan that the instruction emulation came
1285  // up with and fall back to the architecture's Default UnwindPlan so the
1286  // stack walk can get past this point.
1287 
1288  // Special note: If the Full UnwindPlan was generated from the compiler,
1289  // don't second-guess it when we're at a call site location.
1290 
1291  // arch_default_ra_regnum is the return address register # in the Full
1292  // UnwindPlan register numbering
1293  RegisterNumber arch_default_ra_regnum(m_thread, eRegisterKindGeneric,
1295 
1296  if (arch_default_ra_regnum.GetAsKind(unwindplan_registerkind) !=
1298  pc_regnum == regnum && unwindplan_regloc.IsInOtherRegister() &&
1299  unwindplan_regloc.GetRegisterNumber() ==
1300  arch_default_ra_regnum.GetAsKind(unwindplan_registerkind) &&
1301  m_full_unwind_plan_sp->GetSourcedFromCompiler() != eLazyBoolYes &&
1302  !m_all_registers_available) {
1303  UnwindLogMsg("%s UnwindPlan tried to restore the pc from the link "
1304  "register but this is a non-zero frame",
1305  m_full_unwind_plan_sp->GetSourceName().GetCString());
1306 
1307  // Throw away the full unwindplan; install the arch default unwindplan
1308  if (ForceSwitchToFallbackUnwindPlan()) {
1309  // Update for the possibly new unwind plan
1310  unwindplan_registerkind = m_full_unwind_plan_sp->GetRegisterKind();
1311  UnwindPlan::RowSP active_row =
1312  m_full_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1313 
1314  // Sanity check: Verify that we can fetch a pc value and CFA value
1315  // with this unwind plan
1316 
1317  RegisterNumber arch_default_pc_reg(m_thread, eRegisterKindGeneric,
1319  bool can_fetch_pc_value = false;
1320  bool can_fetch_cfa = false;
1321  addr_t cfa_value;
1322  if (active_row) {
1323  if (arch_default_pc_reg.GetAsKind(unwindplan_registerkind) !=
1325  active_row->GetRegisterInfo(
1326  arch_default_pc_reg.GetAsKind(unwindplan_registerkind),
1327  unwindplan_regloc)) {
1328  can_fetch_pc_value = true;
1329  }
1330  if (ReadFrameAddress(unwindplan_registerkind,
1331  active_row->GetCFAValue(), cfa_value)) {
1332  can_fetch_cfa = true;
1333  }
1334  }
1335 
1336  have_unwindplan_regloc = can_fetch_pc_value && can_fetch_cfa;
1337  } else {
1338  // We were unable to fall back to another unwind plan
1339  have_unwindplan_regloc = false;
1340  }
1341  }
1342  }
1343  }
1344 
1345  ExecutionContext exe_ctx(m_thread.shared_from_this());
1346  Process *process = exe_ctx.GetProcessPtr();
1347  if (!have_unwindplan_regloc) {
1348  // If the UnwindPlan failed to give us an unwind location for this
1349  // register, we may be able to fall back to some ABI-defined default. For
1350  // example, some ABIs allow to determine the caller's SP via the CFA. Also,
1351  // the ABI may set volatile registers to the undefined state.
1352  ABI *abi = process ? process->GetABI().get() : NULL;
1353  if (abi) {
1354  const RegisterInfo *reg_info =
1356  if (reg_info &&
1357  abi->GetFallbackRegisterLocation(reg_info, unwindplan_regloc)) {
1358  UnwindLogMsg(
1359  "supplying caller's saved %s (%d)'s location using ABI default",
1360  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1361  have_unwindplan_regloc = true;
1362  }
1363  }
1364  }
1365 
1366  if (!have_unwindplan_regloc) {
1367  if (IsFrameZero()) {
1368  // This is frame 0 - we should return the actual live register context
1369  // value
1371  new_regloc.type =
1373  new_regloc.location.register_number = regnum.GetAsKind(eRegisterKindLLDB);
1374  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc;
1375  regloc = new_regloc;
1376  UnwindLogMsg("supplying caller's register %s (%d) from the live "
1377  "RegisterContext at frame 0",
1378  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1379  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1380  } else {
1381  std::string unwindplan_name("");
1382  if (m_full_unwind_plan_sp) {
1383  unwindplan_name += "via '";
1384  unwindplan_name += m_full_unwind_plan_sp->GetSourceName().AsCString();
1385  unwindplan_name += "'";
1386  }
1387  UnwindLogMsg("no save location for %s (%d) %s", regnum.GetName(),
1388  regnum.GetAsKind(eRegisterKindLLDB),
1389  unwindplan_name.c_str());
1390  }
1391  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1392  }
1393 
1394  // unwindplan_regloc has valid contents about where to retrieve the register
1395  if (unwindplan_regloc.IsUnspecified()) {
1398  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc;
1399  UnwindLogMsg("save location for %s (%d) is unspecified, continue searching",
1400  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1401  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1402  }
1403 
1404  if (unwindplan_regloc.IsUndefined()) {
1405  UnwindLogMsg(
1406  "did not supply reg location for %s (%d) because it is volatile",
1407  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1408  return UnwindLLDB::RegisterSearchResult::eRegisterIsVolatile;
1409  }
1410 
1411  if (unwindplan_regloc.IsSame()) {
1412  if (!IsFrameZero() &&
1415  UnwindLogMsg("register %s (%d) is marked as 'IsSame' - it is a pc or "
1416  "return address reg on a non-zero frame -- treat as if we "
1417  "have no information",
1418  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1419  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1420  } else {
1423  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1424  UnwindLogMsg(
1425  "supplying caller's register %s (%d), saved in register %s (%d)",
1426  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1427  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1428  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1429  }
1430  }
1431 
1432  if (unwindplan_regloc.IsCFAPlusOffset()) {
1433  int offset = unwindplan_regloc.GetOffset();
1435  regloc.location.inferred_value = m_cfa + offset;
1436  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1437  UnwindLogMsg("supplying caller's register %s (%d), value is CFA plus "
1438  "offset %d [value is 0x%" PRIx64 "]",
1439  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1440  regloc.location.inferred_value);
1441  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1442  }
1443 
1444  if (unwindplan_regloc.IsAtCFAPlusOffset()) {
1445  int offset = unwindplan_regloc.GetOffset();
1447  regloc.location.target_memory_location = m_cfa + offset;
1448  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1449  UnwindLogMsg("supplying caller's register %s (%d) from the stack, saved at "
1450  "CFA plus offset %d [saved at 0x%" PRIx64 "]",
1451  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1453  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1454  }
1455 
1456  if (unwindplan_regloc.IsAFAPlusOffset()) {
1457  if (m_afa == LLDB_INVALID_ADDRESS)
1458  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1459 
1460  int offset = unwindplan_regloc.GetOffset();
1462  regloc.location.inferred_value = m_afa + offset;
1463  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1464  UnwindLogMsg("supplying caller's register %s (%d), value is AFA plus "
1465  "offset %d [value is 0x%" PRIx64 "]",
1466  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1467  regloc.location.inferred_value);
1468  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1469  }
1470 
1471  if (unwindplan_regloc.IsAtAFAPlusOffset()) {
1472  if (m_afa == LLDB_INVALID_ADDRESS)
1473  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1474 
1475  int offset = unwindplan_regloc.GetOffset();
1477  regloc.location.target_memory_location = m_afa + offset;
1478  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1479  UnwindLogMsg("supplying caller's register %s (%d) from the stack, saved at "
1480  "AFA plus offset %d [saved at 0x%" PRIx64 "]",
1481  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB), offset,
1483  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1484  }
1485 
1486  if (unwindplan_regloc.IsInOtherRegister()) {
1487  uint32_t unwindplan_regnum = unwindplan_regloc.GetRegisterNumber();
1488  RegisterNumber row_regnum(m_thread, unwindplan_registerkind,
1489  unwindplan_regnum);
1490  if (row_regnum.GetAsKind(eRegisterKindLLDB) == LLDB_INVALID_REGNUM) {
1491  UnwindLogMsg("could not supply caller's %s (%d) location - was saved in "
1492  "another reg but couldn't convert that regnum",
1493  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1494  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1495  }
1497  regloc.location.register_number = row_regnum.GetAsKind(eRegisterKindLLDB);
1498  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1499  UnwindLogMsg(
1500  "supplying caller's register %s (%d), saved in register %s (%d)",
1501  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB),
1502  row_regnum.GetName(), row_regnum.GetAsKind(eRegisterKindLLDB));
1503  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1504  }
1505 
1506  if (unwindplan_regloc.IsDWARFExpression() ||
1507  unwindplan_regloc.IsAtDWARFExpression()) {
1508  DataExtractor dwarfdata(unwindplan_regloc.GetDWARFExpressionBytes(),
1509  unwindplan_regloc.GetDWARFExpressionLength(),
1510  process->GetByteOrder(),
1511  process->GetAddressByteSize());
1512  ModuleSP opcode_ctx;
1513  DWARFExpression dwarfexpr(opcode_ctx, dwarfdata, nullptr, 0,
1514  unwindplan_regloc.GetDWARFExpressionLength());
1515  dwarfexpr.SetRegisterKind(unwindplan_registerkind);
1516  Value result;
1517  Status error;
1518  if (dwarfexpr.Evaluate(&exe_ctx, this, 0, nullptr, nullptr, result,
1519  &error)) {
1520  addr_t val;
1521  val = result.GetScalar().ULongLong();
1522  if (unwindplan_regloc.IsDWARFExpression()) {
1524  regloc.location.inferred_value = val;
1525  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1526  UnwindLogMsg("supplying caller's register %s (%d) via DWARF expression "
1527  "(IsDWARFExpression)",
1528  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1529  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1530  } else {
1531  regloc.type =
1533  regloc.location.target_memory_location = val;
1534  m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1535  UnwindLogMsg("supplying caller's register %s (%d) via DWARF expression "
1536  "(IsAtDWARFExpression)",
1537  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1538  return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1539  }
1540  }
1541  UnwindLogMsg("tried to use IsDWARFExpression or IsAtDWARFExpression for %s "
1542  "(%d) but failed",
1543  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1544  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1545  }
1546 
1547  UnwindLogMsg("no save location for %s (%d) in this stack frame",
1548  regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1549 
1550  // FIXME UnwindPlan::Row types atDWARFExpression and isDWARFExpression are
1551  // unsupported.
1552 
1553  return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
1554 }
1555 
1556 // TryFallbackUnwindPlan() -- this method is a little tricky.
1557 //
1558 // When this is called, the frame above -- the caller frame, the "previous"
1559 // frame -- is invalid or bad.
1560 //
1561 // Instead of stopping the stack walk here, we'll try a different UnwindPlan
1562 // and see if we can get a valid frame above us.
1563 //
1564 // This most often happens when an unwind plan based on assembly instruction
1565 // inspection is not correct -- mostly with hand-written assembly functions or
1566 // functions where the stack frame is set up "out of band", e.g. the kernel
1567 // saved the register context and then called an asynchronous trap handler like
1568 // _sigtramp.
1569 //
1570 // Often in these cases, if we just do a dumb stack walk we'll get past this
1571 // tricky frame and our usual techniques can continue to be used.
1572 
1573 bool RegisterContextLLDB::TryFallbackUnwindPlan() {
1574  if (m_fallback_unwind_plan_sp.get() == nullptr)
1575  return false;
1576 
1577  if (m_full_unwind_plan_sp.get() == nullptr)
1578  return false;
1579 
1580  if (m_full_unwind_plan_sp.get() == m_fallback_unwind_plan_sp.get() ||
1581  m_full_unwind_plan_sp->GetSourceName() ==
1582  m_fallback_unwind_plan_sp->GetSourceName()) {
1583  return false;
1584  }
1585 
1586  // If a compiler generated unwind plan failed, trying the arch default
1587  // unwindplan isn't going to do any better.
1588  if (m_full_unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolYes)
1589  return false;
1590 
1591  // Get the caller's pc value and our own CFA value. Swap in the fallback
1592  // unwind plan, re-fetch the caller's pc value and CFA value. If they're the
1593  // same, then the fallback unwind plan provides no benefit.
1594 
1595  RegisterNumber pc_regnum(m_thread, eRegisterKindGeneric,
1597 
1598  addr_t old_caller_pc_value = LLDB_INVALID_ADDRESS;
1599  addr_t new_caller_pc_value = LLDB_INVALID_ADDRESS;
1601  if (SavedLocationForRegister(pc_regnum.GetAsKind(eRegisterKindLLDB),
1602  regloc) ==
1603  UnwindLLDB::RegisterSearchResult::eRegisterFound) {
1604  const RegisterInfo *reg_info =
1606  if (reg_info) {
1607  RegisterValue reg_value;
1608  if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
1609  old_caller_pc_value = reg_value.GetAsUInt64();
1610  }
1611  }
1612  }
1613 
1614  // This is a tricky wrinkle! If SavedLocationForRegister() detects a really
1615  // impossible register location for the full unwind plan, it may call
1616  // ForceSwitchToFallbackUnwindPlan() which in turn replaces the full
1617  // unwindplan with the fallback... in short, we're done, we're using the
1618  // fallback UnwindPlan. We checked if m_fallback_unwind_plan_sp was nullptr
1619  // at the top -- the only way it became nullptr since then is via
1620  // SavedLocationForRegister().
1621  if (m_fallback_unwind_plan_sp.get() == nullptr)
1622  return true;
1623 
1624  // Switch the full UnwindPlan to be the fallback UnwindPlan. If we decide
1625  // this isn't working, we need to restore. We'll also need to save & restore
1626  // the value of the m_cfa ivar. Save is down below a bit in 'old_cfa'.
1627  UnwindPlanSP original_full_unwind_plan_sp = m_full_unwind_plan_sp;
1628  addr_t old_cfa = m_cfa;
1629  addr_t old_afa = m_afa;
1630 
1631  m_registers.clear();
1632 
1633  m_full_unwind_plan_sp = m_fallback_unwind_plan_sp;
1634 
1635  UnwindPlan::RowSP active_row =
1636  m_fallback_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1637 
1638  if (active_row &&
1639  active_row->GetCFAValue().GetValueType() !=
1641  addr_t new_cfa;
1642  if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1643  active_row->GetCFAValue(), new_cfa) ||
1644  new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1645  UnwindLogMsg("failed to get cfa with fallback unwindplan");
1646  m_fallback_unwind_plan_sp.reset();
1647  m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1648  return false;
1649  }
1650  m_cfa = new_cfa;
1651 
1652  ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1653  active_row->GetAFAValue(), m_afa);
1654 
1655  if (SavedLocationForRegister(pc_regnum.GetAsKind(eRegisterKindLLDB),
1656  regloc) ==
1657  UnwindLLDB::RegisterSearchResult::eRegisterFound) {
1658  const RegisterInfo *reg_info =
1660  if (reg_info) {
1661  RegisterValue reg_value;
1662  if (ReadRegisterValueFromRegisterLocation(regloc, reg_info,
1663  reg_value)) {
1664  new_caller_pc_value = reg_value.GetAsUInt64();
1665  }
1666  }
1667  }
1668 
1669  if (new_caller_pc_value == LLDB_INVALID_ADDRESS) {
1670  UnwindLogMsg("failed to get a pc value for the caller frame with the "
1671  "fallback unwind plan");
1672  m_fallback_unwind_plan_sp.reset();
1673  m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1674  m_cfa = old_cfa;
1675  m_afa = old_afa;
1676  return false;
1677  }
1678 
1679  if (old_caller_pc_value == new_caller_pc_value &&
1680  m_cfa == old_cfa &&
1681  m_afa == old_afa) {
1682  UnwindLogMsg("fallback unwind plan got the same values for this frame "
1683  "CFA and caller frame pc, not using");
1684  m_fallback_unwind_plan_sp.reset();
1685  m_full_unwind_plan_sp = original_full_unwind_plan_sp;
1686  return false;
1687  }
1688 
1689  UnwindLogMsg("trying to unwind from this function with the UnwindPlan '%s' "
1690  "because UnwindPlan '%s' failed.",
1691  m_fallback_unwind_plan_sp->GetSourceName().GetCString(),
1692  original_full_unwind_plan_sp->GetSourceName().GetCString());
1693 
1694  // We've copied the fallback unwind plan into the full - now clear the
1695  // fallback.
1696  m_fallback_unwind_plan_sp.reset();
1697  }
1698 
1699  return true;
1700 }
1701 
1702 bool RegisterContextLLDB::ForceSwitchToFallbackUnwindPlan() {
1703  if (m_fallback_unwind_plan_sp.get() == NULL)
1704  return false;
1705 
1706  if (m_full_unwind_plan_sp.get() == NULL)
1707  return false;
1708 
1709  if (m_full_unwind_plan_sp.get() == m_fallback_unwind_plan_sp.get() ||
1710  m_full_unwind_plan_sp->GetSourceName() ==
1711  m_fallback_unwind_plan_sp->GetSourceName()) {
1712  return false;
1713  }
1714 
1715  UnwindPlan::RowSP active_row =
1716  m_fallback_unwind_plan_sp->GetRowForFunctionOffset(m_current_offset);
1717 
1718  if (active_row &&
1719  active_row->GetCFAValue().GetValueType() !=
1721  addr_t new_cfa;
1722  if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1723  active_row->GetCFAValue(), new_cfa) ||
1724  new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1725  UnwindLogMsg("failed to get cfa with fallback unwindplan");
1726  m_fallback_unwind_plan_sp.reset();
1727  return false;
1728  }
1729 
1730  ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1731  active_row->GetAFAValue(), m_afa);
1732 
1733  m_full_unwind_plan_sp = m_fallback_unwind_plan_sp;
1734  m_fallback_unwind_plan_sp.reset();
1735 
1736  m_registers.clear();
1737 
1738  m_cfa = new_cfa;
1739 
1740  UnwindLogMsg("switched unconditionally to the fallback unwindplan %s",
1741  m_full_unwind_plan_sp->GetSourceName().GetCString());
1742  return true;
1743  }
1744  return false;
1745 }
1746 
1747 bool RegisterContextLLDB::ReadFrameAddress(
1748  lldb::RegisterKind row_register_kind, UnwindPlan::Row::FAValue &fa,
1749  addr_t &address) {
1750  RegisterValue reg_value;
1751 
1752  address = LLDB_INVALID_ADDRESS;
1753  addr_t cfa_reg_contents;
1754 
1755  switch (fa.GetValueType()) {
1757  RegisterNumber cfa_reg(m_thread, row_register_kind,
1758  fa.GetRegisterNumber());
1759  if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
1760  const RegisterInfo *reg_info =
1761  GetRegisterInfoAtIndex(cfa_reg.GetAsKind(eRegisterKindLLDB));
1762  RegisterValue reg_value;
1763  if (reg_info) {
1765  reg_info, cfa_reg_contents, reg_info->byte_size, reg_value);
1766  if (error.Success()) {
1767  address = reg_value.GetAsUInt64();
1768  UnwindLogMsg(
1769  "CFA value via dereferencing reg %s (%d): reg has val 0x%" PRIx64
1770  ", CFA value is 0x%" PRIx64,
1771  cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
1772  cfa_reg_contents, address);
1773  return true;
1774  } else {
1775  UnwindLogMsg("Tried to deref reg %s (%d) [0x%" PRIx64
1776  "] but memory read failed.",
1777  cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
1778  cfa_reg_contents);
1779  }
1780  }
1781  }
1782  break;
1783  }
1785  RegisterNumber cfa_reg(m_thread, row_register_kind,
1786  fa.GetRegisterNumber());
1787  if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
1788  if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
1789  cfa_reg_contents == 1) {
1790  UnwindLogMsg(
1791  "Got an invalid CFA register value - reg %s (%d), value 0x%" PRIx64,
1792  cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
1793  cfa_reg_contents);
1794  cfa_reg_contents = LLDB_INVALID_ADDRESS;
1795  return false;
1796  }
1797  address = cfa_reg_contents + fa.GetOffset();
1798  UnwindLogMsg(
1799  "CFA is 0x%" PRIx64 ": Register %s (%d) contents are 0x%" PRIx64
1800  ", offset is %d",
1801  address, cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
1802  cfa_reg_contents, fa.GetOffset());
1803  return true;
1804  }
1805  break;
1806  }
1808  ExecutionContext exe_ctx(m_thread.shared_from_this());
1809  Process *process = exe_ctx.GetProcessPtr();
1810  DataExtractor dwarfdata(fa.GetDWARFExpressionBytes(),
1812  process->GetByteOrder(),
1813  process->GetAddressByteSize());
1814  ModuleSP opcode_ctx;
1815  DWARFExpression dwarfexpr(opcode_ctx, dwarfdata, nullptr, 0,
1817  dwarfexpr.SetRegisterKind(row_register_kind);
1818  Value result;
1819  Status error;
1820  if (dwarfexpr.Evaluate(&exe_ctx, this, 0, nullptr, nullptr, result,
1821  &error)) {
1822  address = result.GetScalar().ULongLong();
1823 
1824  UnwindLogMsg("CFA value set by DWARF expression is 0x%" PRIx64,
1825  address);
1826  return true;
1827  }
1828  UnwindLogMsg("Failed to set CFA value via DWARF expression: %s",
1829  error.AsCString());
1830  break;
1831  }
1832  default:
1833  return false;
1834  }
1835  return false;
1836 }
1837 
1838 // Retrieve a general purpose register value for THIS frame, as saved by the
1839 // NEXT frame, i.e. the frame that
1840 // this frame called. e.g.
1841 //
1842 // foo () { }
1843 // bar () { foo (); }
1844 // main () { bar (); }
1845 //
1846 // stopped in foo() so
1847 // frame 0 - foo
1848 // frame 1 - bar
1849 // frame 2 - main
1850 // and this RegisterContext is for frame 1 (bar) - if we want to get the pc
1851 // value for frame 1, we need to ask
1852 // where frame 0 (the "next" frame) saved that and retrieve the value.
1853 
1854 bool RegisterContextLLDB::ReadGPRValue(lldb::RegisterKind register_kind,
1855  uint32_t regnum, addr_t &value) {
1856  if (!IsValid())
1857  return false;
1858 
1859  uint32_t lldb_regnum;
1860  if (register_kind == eRegisterKindLLDB) {
1861  lldb_regnum = regnum;
1862  } else if (!m_thread.GetRegisterContext()->ConvertBetweenRegisterKinds(
1863  register_kind, regnum, eRegisterKindLLDB, lldb_regnum)) {
1864  return false;
1865  }
1866 
1867  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(lldb_regnum);
1868  RegisterValue reg_value;
1869  // if this is frame 0 (currently executing frame), get the requested reg
1870  // contents from the actual thread registers
1871  if (IsFrameZero()) {
1872  if (m_thread.GetRegisterContext()->ReadRegister(reg_info, reg_value)) {
1873  value = reg_value.GetAsUInt64();
1874  return true;
1875  }
1876  return false;
1877  }
1878 
1879  bool pc_register = false;
1880  uint32_t generic_regnum;
1881  if (register_kind == eRegisterKindGeneric &&
1882  (regnum == LLDB_REGNUM_GENERIC_PC || regnum == LLDB_REGNUM_GENERIC_RA)) {
1883  pc_register = true;
1884  } else if (m_thread.GetRegisterContext()->ConvertBetweenRegisterKinds(
1885  register_kind, regnum, eRegisterKindGeneric, generic_regnum) &&
1886  (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
1887  generic_regnum == LLDB_REGNUM_GENERIC_RA)) {
1888  pc_register = true;
1889  }
1890 
1892  if (!m_parent_unwind.SearchForSavedLocationForRegister(
1893  lldb_regnum, regloc, m_frame_number - 1, pc_register)) {
1894  return false;
1895  }
1896  if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
1897  value = reg_value.GetAsUInt64();
1898  return true;
1899  }
1900  return false;
1901 }
1902 
1903 bool RegisterContextLLDB::ReadGPRValue(const RegisterNumber &regnum,
1904  addr_t &value) {
1905  return ReadGPRValue(regnum.GetRegisterKind(), regnum.GetRegisterNumber(),
1906  value);
1907 }
1908 
1909 // Find the value of a register in THIS frame
1910 
1911 bool RegisterContextLLDB::ReadRegister(const RegisterInfo *reg_info,
1912  RegisterValue &value) {
1913  if (!IsValid())
1914  return false;
1915 
1916  const uint32_t lldb_regnum = reg_info->kinds[eRegisterKindLLDB];
1917  UnwindLogMsgVerbose("looking for register saved location for reg %d",
1918  lldb_regnum);
1919 
1920  // If this is the 0th frame, hand this over to the live register context
1921  if (IsFrameZero()) {
1922  UnwindLogMsgVerbose("passing along to the live register context for reg %d",
1923  lldb_regnum);
1924  return m_thread.GetRegisterContext()->ReadRegister(reg_info, value);
1925  }
1926 
1927  bool is_pc_regnum = false;
1928  if (reg_info->kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_PC ||
1929  reg_info->kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_RA) {
1930  is_pc_regnum = true;
1931  }
1932 
1934  // Find out where the NEXT frame saved THIS frame's register contents
1935  if (!m_parent_unwind.SearchForSavedLocationForRegister(
1936  lldb_regnum, regloc, m_frame_number - 1, is_pc_regnum))
1937  return false;
1938 
1939  return ReadRegisterValueFromRegisterLocation(regloc, reg_info, value);
1940 }
1941 
1942 bool RegisterContextLLDB::WriteRegister(const RegisterInfo *reg_info,
1943  const RegisterValue &value) {
1944  if (!IsValid())
1945  return false;
1946 
1947  const uint32_t lldb_regnum = reg_info->kinds[eRegisterKindLLDB];
1948  UnwindLogMsgVerbose("looking for register saved location for reg %d",
1949  lldb_regnum);
1950 
1951  // If this is the 0th frame, hand this over to the live register context
1952  if (IsFrameZero()) {
1953  UnwindLogMsgVerbose("passing along to the live register context for reg %d",
1954  lldb_regnum);
1955  return m_thread.GetRegisterContext()->WriteRegister(reg_info, value);
1956  }
1957 
1959  // Find out where the NEXT frame saved THIS frame's register contents
1960  if (!m_parent_unwind.SearchForSavedLocationForRegister(
1961  lldb_regnum, regloc, m_frame_number - 1, false))
1962  return false;
1963 
1964  return WriteRegisterValueToRegisterLocation(regloc, reg_info, value);
1965 }
1966 
1967 // Don't need to implement this one
1968 bool RegisterContextLLDB::ReadAllRegisterValues(lldb::DataBufferSP &data_sp) {
1969  return false;
1970 }
1971 
1972 // Don't need to implement this one
1974  const lldb::DataBufferSP &data_sp) {
1975  return false;
1976 }
1977 
1978 // Retrieve the pc value for THIS from
1979 
1981  if (!IsValid()) {
1982  return false;
1983  }
1984  if (m_cfa == LLDB_INVALID_ADDRESS) {
1985  return false;
1986  }
1987  cfa = m_cfa;
1988  return true;
1989 }
1990 
1991 RegisterContextLLDB::SharedPtr RegisterContextLLDB::GetNextFrame() const {
1993  if (m_frame_number == 0)
1994  return regctx;
1995  return m_parent_unwind.GetRegisterContextForFrameNum(m_frame_number - 1);
1996 }
1997 
1998 RegisterContextLLDB::SharedPtr RegisterContextLLDB::GetPrevFrame() const {
2000  return m_parent_unwind.GetRegisterContextForFrameNum(m_frame_number + 1);
2001 }
2002 
2003 // Retrieve the address of the start of the function of THIS frame
2004 
2006  if (!IsValid())
2007  return false;
2008 
2009  if (!m_start_pc.IsValid()) {
2010  bool read_successfully = ReadPC (start_pc);
2011  if (read_successfully)
2012  {
2013  ProcessSP process_sp (m_thread.GetProcess());
2014  if (process_sp)
2015  {
2016  ABI *abi = process_sp->GetABI().get();
2017  if (abi)
2018  start_pc = abi->FixCodeAddress(start_pc);
2019  }
2020  }
2021  return read_successfully;
2022  }
2023  start_pc = m_start_pc.GetLoadAddress(CalculateTarget().get());
2024  return true;
2025 }
2026 
2027 // Retrieve the current pc value for THIS frame, as saved by the NEXT frame.
2028 
2030  if (!IsValid())
2031  return false;
2032 
2033  bool above_trap_handler = false;
2034  if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
2035  GetNextFrame()->IsTrapHandlerFrame())
2036  above_trap_handler = true;
2037 
2038  if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, pc)) {
2039  // A pc value of 0 or 1 is impossible in the middle of the stack -- it
2040  // indicates the end of a stack walk.
2041  // On the currently executing frame (or such a frame interrupted
2042  // asynchronously by sigtramp et al) this may occur if code has jumped
2043  // through a NULL pointer -- we want to be able to unwind past that frame
2044  // to help find the bug.
2045 
2046  ProcessSP process_sp (m_thread.GetProcess());
2047  if (process_sp)
2048  {
2049  ABI *abi = process_sp->GetABI().get();
2050  if (abi)
2051  pc = abi->FixCodeAddress(pc);
2052  }
2053 
2054  return !(m_all_registers_available == false &&
2055  above_trap_handler == false && (pc == 0 || pc == 1));
2056  } else {
2057  return false;
2058  }
2059 }
2060 
2061 void RegisterContextLLDB::UnwindLogMsg(const char *fmt, ...) {
2063  if (log) {
2064  va_list args;
2065  va_start(args, fmt);
2066 
2067  char *logmsg;
2068  if (vasprintf(&logmsg, fmt, args) == -1 || logmsg == NULL) {
2069  if (logmsg)
2070  free(logmsg);
2071  va_end(args);
2072  return;
2073  }
2074  va_end(args);
2075 
2076  log->Printf("%*sth%d/fr%u %s", m_frame_number < 100 ? m_frame_number : 100,
2077  "", m_thread.GetIndexID(), m_frame_number, logmsg);
2078  free(logmsg);
2079  }
2080 }
2081 
2082 void RegisterContextLLDB::UnwindLogMsgVerbose(const char *fmt, ...) {
2084  if (log && log->GetVerbose()) {
2085  va_list args;
2086  va_start(args, fmt);
2087 
2088  char *logmsg;
2089  if (vasprintf(&logmsg, fmt, args) == -1 || logmsg == NULL) {
2090  if (logmsg)
2091  free(logmsg);
2092  va_end(args);
2093  return;
2094  }
2095  va_end(args);
2096 
2097  log->Printf("%*sth%d/fr%u %s", m_frame_number < 100 ? m_frame_number : 100,
2098  "", m_thread.GetIndexID(), m_frame_number, logmsg);
2099  free(logmsg);
2100  }
2101 }
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:63
An data extractor class.
Definition: DataExtractor.h:47
lldb::RegisterKind GetRegisterKind() const
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
const uint8_t * GetDWARFExpressionBytes()
Definition: UnwindPlan.h:278
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan)=0
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:66
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:292
uint32_t GetRegisterNumber() const
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it...
lldb::TargetSP CalculateTarget() override
virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan)=0
bool ReadPC(lldb::addr_t &start_pc)
bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override
uint32_t GetAsKind(lldb::RegisterKind kind)
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:272
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
union lldb_private::UnwindLLDB::RegisterLocation::@144 location
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:64
#define LIBLLDB_LOG_UNWIND
Definition: Logging.h:29
const char * GetData() const
Definition: StreamString.h:43
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition: Address.cpp:998
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Definition: Address.h:419
static ConstString GetSymbolOrFunctionName(const SymbolContext &sym_ctx)
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value)
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
Symbol * symbol
The Symbol for a given query.
virtual Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value)
bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override
Function * function
The Function for a given query.
bool SetUInt(uint64_t uint, uint32_t byte_size)
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:317
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:65
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) override
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:57
void Clear(bool clear_target)
Clear the object&#39;s state.
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value) override
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:366
lldb::TargetSP CalculateTarget() override
Definition: Thread.cpp:1584
std::shared_ptr< RegisterContextLLDB > SharedPtr
ConstString GetName() const
Definition: Function.cpp:598
const lldb::ABISP & GetABI()
Definition: Process.cpp:1541
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition: Scalar.cpp:1566
virtual lldb::RegisterContextSP GetRegisterContext()=0
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
bool GetVerbose() const
Definition: Log.cpp:250
bool Success() const
Test for success condition.
Definition: Status.cpp:287
bool IsValid() const
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:343
A section + offset based address class.
Definition: Address.h:80
bool SearchForSavedLocationForRegister(uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num, bool pc_register)
Definition: UnwindLLDB.cpp:456
bool GetStartPC(lldb::addr_t &start_pc)
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
bool GetUnwindPlan(const Address &addr, UnwindPlan &unwind_plan)
Return an UnwindPlan based on the call frame information encoded in the FDE of this DWARFCallFrameInf...
void init(lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num)
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1194
uint64_t addr_t
Definition: lldb-types.h:83
const std::vector< ConstString > & GetUserSpecifiedTrapHandlerFunctionNames()
Provide the list of user-specified trap handler functions.
Definition: UnwindLLDB.h:106
virtual bool GetFallbackRegisterLocation(const RegisterInfo *reg_info, UnwindPlan::Row::RegisterLocation &unwind_regloc)
Definition: ABI.cpp:191
lldb::PlatformSP GetPlatform()
Definition: Target.h:1214
A uniqued constant string class.
Definition: ConstString.h:38
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:264
RegisterContextLLDBSP GetRegisterContextForFrameNum(uint32_t frame_num)
Definition: UnwindLLDB.cpp:449
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
const char * GetName()
Definition: SBAddress.h:15
ConstString GetName() const
Definition: Symbol.cpp:494
A class to represent register numbers, and able to convert between different register numbering schem...
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
int vasprintf(char **ret, const char *fmt, va_list ap)
Definition: Windows.cpp:45
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:220
const Scalar & GetScalar() const
Definition: Value.h:178
uint32_t GetIndexID() const
Definition: Thread.cpp:1515
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc)
Definition: ABI.h:120
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:410
void Printf(const char *format,...) __attribute__((format(printf
Definition: Log.cpp:113
A section + offset based address range class.
Definition: AddressRange.h:32
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
An error handling class.
Definition: Status.h:44
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90
bool GetUnwindPlan(Target &target, const Address &addr, UnwindPlan &unwind_plan)