LLDB  mainline
ThreadPlanShouldStopHere.cpp
Go to the documentation of this file.
1 //===-- ThreadPlanShouldStopHere.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/Symbol/Symbol.h"
12 #include "lldb/Target/Thread.h"
13 #include "lldb/Utility/Log.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 // ThreadPlanShouldStopHere constructor
19 ThreadPlanShouldStopHere::ThreadPlanShouldStopHere(ThreadPlan *owner)
20  : m_callbacks(), m_baton(nullptr), m_owner(owner),
21  m_flags(ThreadPlanShouldStopHere::eNone) {
26 }
27 
29  ThreadPlan *owner, const ThreadPlanShouldStopHereCallbacks *callbacks,
30  void *baton)
31  : m_callbacks(), m_baton(), m_owner(owner),
32  m_flags(ThreadPlanShouldStopHere::eNone) {
33  SetShouldStopHereCallbacks(callbacks, baton);
34 }
35 
37 
39  FrameComparison operation, Status &status) {
40  bool should_stop_here = true;
42  should_stop_here = m_callbacks.should_stop_here_callback(
43  m_owner, m_flags, operation, status, m_baton);
45  if (log) {
46  lldb::addr_t current_addr =
47  m_owner->GetThread().GetRegisterContext()->GetPC(0);
48 
49  LLDB_LOGF(log, "ShouldStopHere callback returned %u from 0x%" PRIx64 ".",
50  should_stop_here, current_addr);
51  }
52  }
53 
54  return should_stop_here;
55 }
56 
58  ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
59  Status &status, void *baton) {
60  bool should_stop_here = true;
61  StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
62  if (!frame)
63  return true;
64 
66 
67  if ((operation == eFrameCompareOlder && flags.Test(eStepOutAvoidNoDebug)) ||
68  (operation == eFrameCompareYounger && flags.Test(eStepInAvoidNoDebug)) ||
69  (operation == eFrameCompareSameParent &&
70  flags.Test(eStepInAvoidNoDebug))) {
71  if (!frame->HasDebugInformation()) {
72  LLDB_LOGF(log, "Stepping out of frame with no debug info");
73 
74  should_stop_here = false;
75  }
76  }
77 
78  // Always avoid code with line number 0.
79  // FIXME: At present the ShouldStop and the StepFromHere calculate this
80  // independently. If this ever
81  // becomes expensive (this one isn't) we can try to have this set a state
82  // that the StepFromHere can use.
83  if (frame) {
84  SymbolContext sc;
85  sc = frame->GetSymbolContext(eSymbolContextLineEntry);
86  if (sc.line_entry.line == 0)
87  should_stop_here = false;
88  }
89 
90  return should_stop_here;
91 }
92 
94  ThreadPlan *current_plan, Flags &flags, FrameComparison operation,
95  Status &status, void *baton) {
96  const bool stop_others = false;
97  const size_t frame_index = 0;
98  ThreadPlanSP return_plan_sp;
99  // If we are stepping through code at line number 0, then we need to step
100  // over this range. Otherwise we will step out.
102 
103  StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
104  if (!frame)
105  return return_plan_sp;
106  SymbolContext sc;
107  sc = frame->GetSymbolContext(eSymbolContextLineEntry | eSymbolContextSymbol);
108 
109  if (sc.line_entry.line == 0) {
110  AddressRange range = sc.line_entry.range;
111 
112  // If the whole function is marked line 0 just step out, that's easier &
113  // faster than continuing to step through it.
114  bool just_step_out = false;
115  if (sc.symbol && sc.symbol->ValueIsAddress()) {
116  Address symbol_end = sc.symbol->GetAddress();
117  symbol_end.Slide(sc.symbol->GetByteSize() - 1);
118  if (range.ContainsFileAddress(sc.symbol->GetAddress()) &&
119  range.ContainsFileAddress(symbol_end)) {
120  LLDB_LOGF(log, "Stopped in a function with only line 0 lines, just "
121  "stepping out.");
122  just_step_out = true;
123  }
124  }
125  if (!just_step_out) {
126  LLDB_LOGF(log, "ThreadPlanShouldStopHere::DefaultStepFromHereCallback "
127  "Queueing StepInRange plan to step through line 0 code.");
128 
129  return_plan_sp = current_plan->GetThread().QueueThreadPlanForStepInRange(
130  false, range, sc, nullptr, eOnlyDuringStepping, status,
132  }
133  }
134 
135  if (!return_plan_sp)
136  return_plan_sp =
138  false, nullptr, true, stop_others, eVoteNo, eVoteNoOpinion,
139  frame_index, status, true);
140  return return_plan_sp;
141 }
142 
144  lldb_private::Flags &flags, lldb::FrameComparison operation,
145  Status &status) {
146  ThreadPlanSP return_plan_sp;
148  return_plan_sp = m_callbacks.step_from_here_callback(
149  m_owner, flags, operation, status, m_baton);
150  }
151  return return_plan_sp;
152 }
153 
155  lldb::FrameComparison operation, Status &status) {
156  if (!InvokeShouldStopHereCallback(operation, status))
157  return QueueStepOutFromHerePlan(m_flags, operation, status);
158  else
159  return ThreadPlanSP();
160 }
lldb_private::ThreadPlan::GetThread
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:41
lldb::FrameComparison
FrameComparison
This is the return value for frame comparisons.
Definition: lldb-enumerations.h:860
lldb_private::Symbol::ValueIsAddress
bool ValueIsAddress() const
Definition: Symbol.cpp:117
lldb_private::ThreadPlanShouldStopHere::DefaultShouldStopHereCallback
static bool DefaultShouldStopHereCallback(ThreadPlan *current_plan, Flags &flags, lldb::FrameComparison operation, Status &status, void *baton)
Definition: ThreadPlanShouldStopHere.cpp:57
lldb_private::ThreadPlanShouldStopHere::m_flags
lldb_private::Flags m_flags
Definition: ThreadPlanShouldStopHere.h:130
lldb_private::Thread::QueueThreadPlanForStepOutNoShouldStop
virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop(bool abort_other_plans, SymbolContext *addr_context, bool first_insn, bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx, Status &status, bool continue_to_next_branch=false)
Queue the plan used to step out of the function at the current PC of a thread.
Definition: Thread.cpp:1317
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::ThreadPlanShouldStopHere::m_owner
ThreadPlan * m_owner
Definition: ThreadPlanShouldStopHere.h:129
lldb_private::Flags
Definition: Flags.h:22
lldb_private::Flags::Test
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
lldb_private::eVoteNoOpinion
@ eVoteNoOpinion
Definition: lldb-private-enumerations.h:59
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::StackFrame::HasDebugInformation
bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
Definition: StackFrame.cpp:1133
lldb_private::SymbolContext::symbol
Symbol * symbol
The Symbol for a given query.
Definition: SymbolContext.h:323
lldb_private::ThreadPlan
Definition: ThreadPlan.h:282
lldb_private::eVoteNo
@ eVoteNo
Definition: lldb-private-enumerations.h:59
Log.h
lldb_private::ThreadPlanShouldStopHere::eStepOutAvoidNoDebug
@ eStepOutAvoidNoDebug
Definition: ThreadPlanShouldStopHere.h:62
lldb::eFrameCompareSameParent
@ eFrameCompareSameParent
Definition: lldb-enumerations.h:864
lldb_private::AddressRange
Definition: AddressRange.h:25
lldb_private::Thread::QueueThreadPlanForStepInRange
virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange(bool abort_other_plans, const AddressRange &range, const SymbolContext &addr_context, const char *step_in_target, lldb::RunMode stop_other_threads, Status &status, LazyBool step_in_avoids_code_without_debug_info=eLazyBoolCalculate, LazyBool step_out_avoids_code_without_debug_info=eLazyBoolCalculate)
Queues the plan used to step through an address range, stepping into functions.
Definition: Thread.cpp:1274
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::ThreadPlanShouldStopHere::QueueStepOutFromHerePlan
virtual lldb::ThreadPlanSP QueueStepOutFromHerePlan(Flags &flags, lldb::FrameComparison operation, Status &status)
Definition: ThreadPlanShouldStopHere.cpp:143
lldb::eFrameCompareYounger
@ eFrameCompareYounger
Definition: lldb-enumerations.h:865
lldb_private::ThreadPlanShouldStopHere
Definition: ThreadPlanShouldStopHere.h:34
Thread.h
lldb_private::ThreadPlanShouldStopHere::ThreadPlanShouldStopHere
ThreadPlanShouldStopHere(ThreadPlan *owner)
Definition: ThreadPlanShouldStopHere.cpp:19
lldb_private::ThreadPlanShouldStopHere::ThreadPlanShouldStopHereCallbacks::should_stop_here_callback
ThreadPlanShouldStopHereCallback should_stop_here_callback
Definition: ThreadPlanShouldStopHere.h:54
lldb_private::ThreadPlanShouldStopHere::DefaultStepFromHereCallback
static lldb::ThreadPlanSP DefaultStepFromHereCallback(ThreadPlan *current_plan, Flags &flags, lldb::FrameComparison operation, Status &status, void *baton)
Definition: ThreadPlanShouldStopHere.cpp:93
lldb_private::LineEntry::line
uint32_t line
The source line number, or zero if there is no line number information.
Definition: LineEntry.h:143
lldb_private::AddressRange::ContainsFileAddress
bool ContainsFileAddress(const Address &so_addr) const
Check if a section offset address is contained in this range.
Definition: AddressRange.cpp:71
lldb_private::ThreadPlanShouldStopHere::~ThreadPlanShouldStopHere
virtual ~ThreadPlanShouldStopHere()
lldb_private::ThreadPlanShouldStopHere::ThreadPlanShouldStopHereCallbacks
Definition: ThreadPlanShouldStopHere.h:36
Symbol.h
lldb_private::Status
Definition: Status.h:44
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
lldb_private::Address
Definition: Address.h:59
lldb::eOnlyDuringStepping
@ eOnlyDuringStepping
Definition: lldb-enumerations.h:135
lldb_private::ThreadPlanShouldStopHere::ThreadPlanShouldStopHereCallbacks::step_from_here_callback
ThreadPlanStepFromHereCallback step_from_here_callback
Definition: ThreadPlanShouldStopHere.h:55
lldb_private::ThreadPlanShouldStopHere::eStepInAvoidNoDebug
@ eStepInAvoidNoDebug
Definition: ThreadPlanShouldStopHere.h:61
lldb_private::Symbol::GetByteSize
lldb::addr_t GetByteSize() const
Definition: Symbol.cpp:414
lldb_private::LineEntry::range
AddressRange range
The section offset address range for this line entry.
Definition: LineEntry.h:139
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ThreadPlanShouldStopHere::m_baton
void * m_baton
Definition: ThreadPlanShouldStopHere.h:128
lldb_private::ThreadPlanShouldStopHere::InvokeShouldStopHereCallback
bool InvokeShouldStopHereCallback(lldb::FrameComparison operation, Status &status)
Definition: ThreadPlanShouldStopHere.cpp:38
lldb_private::eLazyBoolCalculate
@ eLazyBoolCalculate
Definition: lldb-private-enumerations.h:115
lldb_private::ThreadPlanShouldStopHere::SetShouldStopHereCallbacks
void SetShouldStopHereCallbacks(const ThreadPlanShouldStopHereCallbacks *callbacks, void *baton)
Definition: ThreadPlanShouldStopHere.h:79
LIBLLDB_LOG_STEP
#define LIBLLDB_LOG_STEP
Definition: Logging.h:21
lldb_private::ThreadPlanShouldStopHere::m_callbacks
ThreadPlanShouldStopHereCallbacks m_callbacks
Definition: ThreadPlanShouldStopHere.h:127
lldb_private::Log
Definition: Log.h:49
lldb_private::Thread::GetStackFrameAtIndex
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:399
lldb_private::SymbolContext::line_entry
LineEntry line_entry
The LineEntry for a given query.
Definition: SymbolContext.h:322
lldb_private::Thread::GetRegisterContext
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::Address::Slide
bool Slide(int64_t offset)
Definition: Address.h:440
lldb
Definition: SBAddress.h:15
RegisterContext.h
lldb_private::ThreadPlanShouldStopHere::CheckShouldStopHereAndQueueStepOut
lldb::ThreadPlanSP CheckShouldStopHereAndQueueStepOut(lldb::FrameComparison operation, Status &status)
Definition: ThreadPlanShouldStopHere.cpp:154
lldb_private::StackFrame::GetSymbolContext
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:298
lldb::eFrameCompareOlder
@ eFrameCompareOlder
Definition: lldb-enumerations.h:866
ThreadPlanShouldStopHere.h
lldb_private::Symbol::GetAddress
Address GetAddress() const
Definition: Symbol.h:73