blob: 3771e210c1a4239b8ba45c4ab8ed7f762277cb3d [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ThreadPlanStepInRange.cpp -------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000014#include "lldb/Target/ThreadPlanStepInRange.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Core/Log.h"
Jim Ingham4da62062014-01-23 21:52:47 +000016#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/Stream.h"
Jim Inghama56c8002010-07-10 02:27:39 +000018#include "lldb/Symbol/Symbol.h"
Jim Ingham7ce490c2010-09-16 00:58:09 +000019#include "lldb/Symbol/Function.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Target/Process.h"
21#include "lldb/Target/RegisterContext.h"
Greg Clayton514487e2011-02-15 21:59:32 +000022#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Target/Thread.h"
24#include "lldb/Target/ThreadPlanStepOut.h"
25#include "lldb/Target/ThreadPlanStepThrough.h"
Jim Inghama56c8002010-07-10 02:27:39 +000026#include "lldb/Core/RegularExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027
28using namespace lldb;
29using namespace lldb_private;
30
Jim Ingham4b4b2472014-03-13 02:47:14 +000031uint32_t ThreadPlanStepInRange::s_default_flag_values = ThreadPlanShouldStopHere::eStepInAvoidNoDebug;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
33//----------------------------------------------------------------------
34// ThreadPlanStepInRange: Step through a stack range, either stepping over or into
35// based on the value of \a type.
36//----------------------------------------------------------------------
37
38ThreadPlanStepInRange::ThreadPlanStepInRange
39(
40 Thread &thread,
41 const AddressRange &range,
42 const SymbolContext &addr_context,
Jim Ingham4b4b2472014-03-13 02:47:14 +000043 lldb::RunMode stop_others,
44 LazyBool step_in_avoids_code_without_debug_info,
45 LazyBool step_out_avoids_code_without_debug_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046) :
Jim Inghamb01e7422010-06-19 04:45:32 +000047 ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others),
Jim Ingham4b4b2472014-03-13 02:47:14 +000048 ThreadPlanShouldStopHere (this),
Jim Inghamf02a2e92012-09-07 01:11:44 +000049 m_step_past_prologue (true),
50 m_virtual_step (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051{
Jim Ingham4b4b2472014-03-13 02:47:14 +000052 SetCallbacks();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053 SetFlagsToDefault ();
Jim Ingham4b4b2472014-03-13 02:47:14 +000054 SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055}
56
Jim Inghamc6276822012-12-12 19:58:40 +000057ThreadPlanStepInRange::ThreadPlanStepInRange
58(
59 Thread &thread,
60 const AddressRange &range,
61 const SymbolContext &addr_context,
62 const char *step_into_target,
Jim Ingham4b4b2472014-03-13 02:47:14 +000063 lldb::RunMode stop_others,
64 LazyBool step_in_avoids_code_without_debug_info,
65 LazyBool step_out_avoids_code_without_debug_info
Jim Inghamc6276822012-12-12 19:58:40 +000066) :
67 ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others),
Jim Ingham4b4b2472014-03-13 02:47:14 +000068 ThreadPlanShouldStopHere (this),
Jim Inghamc6276822012-12-12 19:58:40 +000069 m_step_past_prologue (true),
70 m_virtual_step (false),
71 m_step_into_target (step_into_target)
72{
Jim Ingham4b4b2472014-03-13 02:47:14 +000073 SetCallbacks();
Jim Inghamc6276822012-12-12 19:58:40 +000074 SetFlagsToDefault ();
Jim Ingham4b4b2472014-03-13 02:47:14 +000075 SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info);
Jim Inghamc6276822012-12-12 19:58:40 +000076}
77
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000078ThreadPlanStepInRange::~ThreadPlanStepInRange() = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079
80void
Jim Ingham4b4b2472014-03-13 02:47:14 +000081ThreadPlanStepInRange::SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,
82 LazyBool step_out_avoids_code_without_debug_info)
83{
84 bool avoid_nodebug = true;
85
86 switch (step_in_avoids_code_without_debug_info)
87 {
88 case eLazyBoolYes:
89 avoid_nodebug = true;
90 break;
91 case eLazyBoolNo:
92 avoid_nodebug = false;
93 break;
94 case eLazyBoolCalculate:
95 avoid_nodebug = m_thread.GetStepInAvoidsNoDebug();
96 break;
97 }
98 if (avoid_nodebug)
99 GetFlags().Set (ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
100 else
101 GetFlags().Clear (ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
102
Jim Ingham4b4b2472014-03-13 02:47:14 +0000103 switch (step_out_avoids_code_without_debug_info)
104 {
105 case eLazyBoolYes:
106 avoid_nodebug = true;
107 break;
108 case eLazyBoolNo:
109 avoid_nodebug = false;
110 break;
111 case eLazyBoolCalculate:
112 avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug();
113 break;
114 }
115 if (avoid_nodebug)
116 GetFlags().Set (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
117 else
118 GetFlags().Clear (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
119}
120
121void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122ThreadPlanStepInRange::GetDescription (Stream *s, lldb::DescriptionLevel level)
123{
124 if (level == lldb::eDescriptionLevelBrief)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125 {
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000126 s->Printf("step in");
127 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128 }
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000129
130 s->Printf ("Stepping in");
131 bool printed_line_info = false;
132 if (m_addr_context.line_entry.IsValid())
133 {
134 s->Printf (" through line ");
135 m_addr_context.line_entry.DumpStopContext (s, false);
136 printed_line_info = true;
137 }
138
139 const char *step_into_target = m_step_into_target.AsCString();
140 if (step_into_target && step_into_target[0] != '\0')
141 s->Printf (" targeting %s", m_step_into_target.AsCString());
142
143 if (!printed_line_info || level == eDescriptionLevelVerbose)
144 {
145 s->Printf (" using ranges:");
146 DumpRanges(s);
147 }
148
149 s->PutChar('.');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150}
151
152bool
153ThreadPlanStepInRange::ShouldStop (Event *event_ptr)
154{
Greg Clayton5160ce52013-03-27 23:08:40 +0000155 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156
157 if (log)
158 {
159 StreamString s;
Greg Clayton514487e2011-02-15 21:59:32 +0000160 s.Address (m_thread.GetRegisterContext()->GetPC(),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000161 m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162 log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
163 }
164
Jim Ingham25f66702011-12-03 01:52:59 +0000165 if (IsPlanComplete())
166 return true;
167
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000168 m_no_more_plans = false;
169 if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete())
170 {
171 if (!m_sub_plan_sp->PlanSucceeded())
172 {
173 SetPlanComplete();
174 m_no_more_plans = true;
175 return true;
176 }
177 else
178 m_sub_plan_sp.reset();
179 }
180
Jim Inghamf02a2e92012-09-07 01:11:44 +0000181 if (m_virtual_step)
Jim Ingham58221732010-11-05 00:18:21 +0000182 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000183 // If we've just completed a virtual step, all we need to do is check for a ShouldStopHere plan, and otherwise
184 // we're done.
Jim Ingham4b4b2472014-03-13 02:47:14 +0000185 // FIXME - This can be both a step in and a step out. Probably should record which in the m_virtual_step.
186 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000187 }
188 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189 {
Jim Ingham4a58e962012-10-25 22:30:09 +0000190 // Stepping through should be done running other threads in general, since we're setting a breakpoint and
191 // continuing. So only stop others if we are explicitly told to do so.
Jim Inghamf02a2e92012-09-07 01:11:44 +0000192
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000193 bool stop_others = (m_stop_others == lldb::eOnlyThisThread);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000194
195 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
196
Jim Ingham862d1bb2014-08-06 01:49:59 +0000197 if (frame_order == eFrameCompareOlder || frame_order == eFrameCompareSameParent)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000198 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000199 // If we're in an older frame then we should stop.
200 //
201 // A caveat to this is if we think the frame is older but we're actually in a trampoline.
202 // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are
203 // in a trampoline we think the frame is older because the trampoline confused the backtracer.
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000204 m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
205 if (!m_sub_plan_sp)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000206 {
207 // Otherwise check the ShouldStopHere for step out:
Jim Ingham862d1bb2014-08-06 01:49:59 +0000208 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
Jim Ingham4b4b2472014-03-13 02:47:14 +0000209 if (log)
210 log->Printf ("ShouldStopHere says we should step out of this frame.");
211 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000212 else if (log)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000213 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000214 log->Printf("Thought I stepped out, but in fact arrived at a trampoline.");
Jim Ingham7ce490c2010-09-16 00:58:09 +0000215 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000216 }
217 else if (frame_order == eFrameCompareEqual && InSymbol())
218 {
219 // If we are not in a place we should step through, we're done.
220 // One tricky bit here is that some stubs don't push a frame, so we have to check
221 // both the case of a frame that is younger, or the same as this frame.
222 // However, if the frame is the same, and we are still in the symbol we started
223 // in, the we don't need to do this. This first check isn't strictly necessary,
224 // but it is more efficient.
Jim Ingham7ce490c2010-09-16 00:58:09 +0000225
Jim Inghamf02a2e92012-09-07 01:11:44 +0000226 // If we're still in the range, keep going, either by running to the next branch breakpoint, or by
227 // stepping.
228 if (InRange())
Jim Ingham7ce490c2010-09-16 00:58:09 +0000229 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000230 SetNextBranchBreakpoint();
231 return false;
232 }
233
234 SetPlanComplete();
Jim Inghamc6276822012-12-12 19:58:40 +0000235 m_no_more_plans = true;
Jim Inghamf02a2e92012-09-07 01:11:44 +0000236 return true;
237 }
238
239 // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
240 ClearNextBranchBreakpoint();
241
242 // We may have set the plan up above in the FrameIsOlder section:
243
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000244 if (!m_sub_plan_sp)
245 m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000246
247 if (log)
248 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000249 if (m_sub_plan_sp)
250 log->Printf ("Found a step through plan: %s", m_sub_plan_sp->GetName());
Jim Inghamf02a2e92012-09-07 01:11:44 +0000251 else
252 log->Printf ("No step through plan found.");
253 }
254
255 // If not, give the "should_stop" callback a chance to push a plan to get us out of here.
256 // But only do that if we actually have stepped in.
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000257 if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000258 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000259
260 // If we've stepped in and we are going to stop here, check to see if we were asked to
261 // run past the prologue, and if so do that.
262
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000263 if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && m_step_past_prologue)
Jim Inghamf02a2e92012-09-07 01:11:44 +0000264 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000265 lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000266 if (curr_frame)
267 {
268 size_t bytes_to_skip = 0;
269 lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC();
270 Address func_start_address;
271
272 SymbolContext sc = curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextSymbol);
273
274 if (sc.function)
275 {
276 func_start_address = sc.function->GetAddressRange().GetBaseAddress();
277 if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
278 bytes_to_skip = sc.function->GetPrologueByteSize();
279 }
280 else if (sc.symbol)
281 {
282 func_start_address = sc.symbol->GetAddress();
283 if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
284 bytes_to_skip = sc.symbol->GetPrologueByteSize();
285 }
286
287 if (bytes_to_skip != 0)
288 {
289 func_start_address.Slide (bytes_to_skip);
290 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
291 if (log)
292 log->Printf ("Pushing past prologue ");
293
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000294 m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(false, func_start_address,true);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000295 }
Jim Ingham7ce490c2010-09-16 00:58:09 +0000296 }
297 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000298 }
Jim Ingham7ce490c2010-09-16 00:58:09 +0000299
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000300 if (!m_sub_plan_sp)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000301 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302 m_no_more_plans = true;
303 SetPlanComplete();
304 return true;
305 }
306 else
307 {
308 m_no_more_plans = false;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000309 m_sub_plan_sp->SetPrivate(true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310 return false;
311 }
312}
313
Jim Inghama56c8002010-07-10 02:27:39 +0000314void
315ThreadPlanStepInRange::SetAvoidRegexp(const char *name)
316{
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000317 if (!m_avoid_regexp_ap)
Jim Inghama56c8002010-07-10 02:27:39 +0000318 m_avoid_regexp_ap.reset (new RegularExpression(name));
319
320 m_avoid_regexp_ap->Compile (name);
321}
322
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323void
324ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value)
325{
326 // TODO: Should we test this for sanity?
327 ThreadPlanStepInRange::s_default_flag_values = new_value;
328}
329
Jim Inghama56c8002010-07-10 02:27:39 +0000330bool
Jim Ingham4da62062014-01-23 21:52:47 +0000331ThreadPlanStepInRange::FrameMatchesAvoidCriteria ()
Jim Inghama56c8002010-07-10 02:27:39 +0000332{
Jason Molendab57e4a12013-11-04 09:33:30 +0000333 StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
Jim Ingham4da62062014-01-23 21:52:47 +0000334
335 // Check the library list first, as that's cheapest:
Jim Inghama786e532014-01-23 21:57:53 +0000336 bool libraries_say_avoid = false;
337
Jim Ingham4da62062014-01-23 21:52:47 +0000338 FileSpecList libraries_to_avoid (GetThread().GetLibrariesToAvoid());
339 size_t num_libraries = libraries_to_avoid.GetSize();
Jim Inghama786e532014-01-23 21:57:53 +0000340 if (num_libraries > 0)
Jim Ingham4da62062014-01-23 21:52:47 +0000341 {
Jim Inghama786e532014-01-23 21:57:53 +0000342 SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
343 FileSpec frame_library(sc.module_sp->GetFileSpec());
344
345 if (frame_library)
Jim Ingham4da62062014-01-23 21:52:47 +0000346 {
Jim Inghama786e532014-01-23 21:57:53 +0000347 for (size_t i = 0; i < num_libraries; i++)
Jim Ingham4da62062014-01-23 21:52:47 +0000348 {
Jim Inghama786e532014-01-23 21:57:53 +0000349 const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
350 if (FileSpec::Equal (file_spec, frame_library, false))
351 {
352 libraries_say_avoid = true;
353 break;
354 }
Jim Ingham4da62062014-01-23 21:52:47 +0000355 }
356 }
357 }
358 if (libraries_say_avoid)
359 return true;
360
Greg Clayton67cc0632012-08-22 17:17:09 +0000361 const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000362 if (avoid_regexp_to_use == nullptr)
Jim Inghamee8aea12010-09-08 03:14:33 +0000363 avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
364
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000365 if (avoid_regexp_to_use != nullptr)
Jim Inghama56c8002010-07-10 02:27:39 +0000366 {
Greg Clayton4592cbc2012-07-13 00:19:40 +0000367 SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000368 if (sc.symbol != nullptr)
Jim Inghama56c8002010-07-10 02:27:39 +0000369 {
Tamas Berghammer5aa27e12015-07-24 08:54:22 +0000370 const char *frame_function_name = sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments).GetCString();
Greg Clayton4592cbc2012-07-13 00:19:40 +0000371 if (frame_function_name)
Jim Ingham3101ba32013-03-14 21:44:36 +0000372 {
Jim Inghamcf2667c2013-03-14 22:00:18 +0000373 size_t num_matches = 0;
Greg Clayton5160ce52013-03-27 23:08:40 +0000374 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamcf2667c2013-03-14 22:00:18 +0000375 if (log)
376 num_matches = 1;
Greg Claytonbc43cab2013-04-03 21:37:16 +0000377
378 RegularExpression::Match regex_match(num_matches);
379
380 bool return_value = avoid_regexp_to_use->Execute(frame_function_name, &regex_match);
Jim Ingham3101ba32013-03-14 21:44:36 +0000381 if (return_value)
382 {
Jim Ingham3101ba32013-03-14 21:44:36 +0000383 if (log)
Jim Inghamcf2667c2013-03-14 22:00:18 +0000384 {
385 std::string match;
Greg Claytonbc43cab2013-04-03 21:37:16 +0000386 regex_match.GetMatchAtIndex(frame_function_name,0, match);
Jim Inghamcf2667c2013-03-14 22:00:18 +0000387 log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".",
Jim Ingham3101ba32013-03-14 21:44:36 +0000388 frame_function_name,
Jim Inghamcf2667c2013-03-14 22:00:18 +0000389 avoid_regexp_to_use->GetText(),
390 match.c_str());
391 }
Jim Ingham3101ba32013-03-14 21:44:36 +0000392
393 }
394 return return_value;
395 }
Jim Inghama56c8002010-07-10 02:27:39 +0000396 }
397 }
398 return false;
399}
400
Jim Ingham4b4b2472014-03-13 02:47:14 +0000401bool
402ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, FrameComparison operation, void *baton)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000404 bool should_stop_here = true;
Jason Molendab57e4a12013-11-04 09:33:30 +0000405 StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
Greg Clayton5160ce52013-03-27 23:08:40 +0000406 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghama56c8002010-07-10 02:27:39 +0000407
Jim Ingham0c2b9d22014-08-08 01:27:01 +0000408 // First see if the ThreadPlanShouldStopHere default implementation thinks we should get out of here:
409 should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback (current_plan, flags, operation, baton);
410 if (!should_stop_here)
411 return should_stop_here;
Jim Inghama56c8002010-07-10 02:27:39 +0000412
Jim Ingham4b4b2472014-03-13 02:47:14 +0000413 if (should_stop_here && current_plan->GetKind() == eKindStepInRange && operation == eFrameCompareYounger)
Jim Inghama56c8002010-07-10 02:27:39 +0000414 {
Jim Inghamc6276822012-12-12 19:58:40 +0000415 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
416 if (step_in_range_plan->m_step_into_target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 {
Jim Inghamc6276822012-12-12 19:58:40 +0000418 SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000419 if (sc.symbol != nullptr)
Jim Inghamc6276822012-12-12 19:58:40 +0000420 {
421 // First try an exact match, since that's cheap with ConstStrings. Then do a strstr compare.
422 if (step_in_range_plan->m_step_into_target == sc.GetFunctionName())
423 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000424 should_stop_here = true;
Jim Inghamc6276822012-12-12 19:58:40 +0000425 }
426 else
427 {
428 const char *target_name = step_in_range_plan->m_step_into_target.AsCString();
429 const char *function_name = sc.GetFunctionName().AsCString();
430
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000431 if (function_name == nullptr)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000432 should_stop_here = false;
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000433 else if (strstr(function_name, target_name) == nullptr)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000434 should_stop_here = false;
Jim Inghamc6276822012-12-12 19:58:40 +0000435 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000436 if (log && !should_stop_here)
Jim Ingham3101ba32013-03-14 21:44:36 +0000437 log->Printf("Stepping out of frame %s which did not match step into target %s.",
438 sc.GetFunctionName().AsCString(),
439 step_in_range_plan->m_step_into_target.AsCString());
Jim Inghamc6276822012-12-12 19:58:40 +0000440 }
441 }
442
Jim Ingham4b4b2472014-03-13 02:47:14 +0000443 if (should_stop_here)
Jim Inghamc6276822012-12-12 19:58:40 +0000444 {
Jim Ingham3101ba32013-03-14 21:44:36 +0000445 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
Jim Ingham4da62062014-01-23 21:52:47 +0000446 // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidCriteria.
Jim Ingham4b4b2472014-03-13 02:47:14 +0000447 should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448 }
449 }
Jim Inghama56c8002010-07-10 02:27:39 +0000450
Jim Ingham4b4b2472014-03-13 02:47:14 +0000451 return should_stop_here;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452}
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000453
454bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000455ThreadPlanStepInRange::DoPlanExplainsStop (Event *event_ptr)
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000456{
457 // We always explain a stop. Either we've just done a single step, in which
458 // case we'll do our ordinary processing, or we stopped for some
459 // reason that isn't handled by our sub-plans, in which case we want to just stop right
460 // away.
Jim Inghamc6276822012-12-12 19:58:40 +0000461 // In general, we don't want to mark the plan as complete for unexplained stops.
462 // For instance, if you step in to some code with no debug info, so you step out
463 // and in the course of that hit a breakpoint, then you want to stop & show the user
464 // the breakpoint, but not unship the step in plan, since you still may want to complete that
465 // plan when you continue. This is particularly true when doing "step in to target function."
466 // stepping.
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000467 //
468 // The only variation is that if we are doing "step by running to next branch" in which case
469 // if we hit our branch breakpoint we don't set the plan to complete.
Jim Ingham221d51c2013-05-08 00:35:16 +0000470
Jim Ingham9b03fa02015-07-23 19:55:02 +0000471 bool return_value = false;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000472
Jim Inghamf02a2e92012-09-07 01:11:44 +0000473 if (m_virtual_step)
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000474 {
Jim Ingham221d51c2013-05-08 00:35:16 +0000475 return_value = true;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000476 }
Jim Ingham221d51c2013-05-08 00:35:16 +0000477 else
478 {
Jim Ingham60c41182013-06-04 01:40:51 +0000479 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Jim Ingham221d51c2013-05-08 00:35:16 +0000480 if (stop_info_sp)
481 {
482 StopReason reason = stop_info_sp->GetStopReason();
Jim Ingham9b03fa02015-07-23 19:55:02 +0000483
484 if (reason == eStopReasonBreakpoint)
Jim Ingham221d51c2013-05-08 00:35:16 +0000485 {
Jim Ingham221d51c2013-05-08 00:35:16 +0000486 if (NextRangeBreakpointExplainsStop(stop_info_sp))
487 {
488 return_value = true;
Jim Ingham221d51c2013-05-08 00:35:16 +0000489 }
Jim Ingham9b03fa02015-07-23 19:55:02 +0000490 }
491 else if (IsUsuallyUnexplainedStopReason(reason))
492 {
493 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
494 if (log)
495 log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step.");
Jim Ingham221d51c2013-05-08 00:35:16 +0000496 return_value = false;
Jim Ingham9b03fa02015-07-23 19:55:02 +0000497 }
498 else
499 {
Jim Ingham221d51c2013-05-08 00:35:16 +0000500 return_value = true;
Jim Ingham221d51c2013-05-08 00:35:16 +0000501 }
502 }
503 else
504 return_value = true;
505 }
506
507 return return_value;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000508}
Jim Ingham513c6bb2012-09-01 01:02:41 +0000509
510bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000511ThreadPlanStepInRange::DoWillResume (lldb::StateType resume_state, bool current_plan)
Jim Ingham513c6bb2012-09-01 01:02:41 +0000512{
Tamas Berghammer69fc2982015-05-15 10:14:15 +0000513 m_virtual_step = false;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000514 if (resume_state == eStateStepping && current_plan)
515 {
516 // See if we are about to step over a virtual inlined call.
517 bool step_without_resume = m_thread.DecrementCurrentInlinedDepth();
518 if (step_without_resume)
519 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000520 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham513c6bb2012-09-01 01:02:41 +0000521 if (log)
Jim Ingham221d51c2013-05-08 00:35:16 +0000522 log->Printf ("ThreadPlanStepInRange::DoWillResume: returning false, inline_depth: %d",
Jim Ingham513c6bb2012-09-01 01:02:41 +0000523 m_thread.GetCurrentInlinedDepth());
524 SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread));
Jim Inghamf02a2e92012-09-07 01:11:44 +0000525
526 // FIXME: Maybe it would be better to create a InlineStep stop reason, but then
527 // the whole rest of the world would have to handle that stop reason.
528 m_virtual_step = true;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000529 }
530 return !step_without_resume;
531 }
Jim Ingham221d51c2013-05-08 00:35:16 +0000532 return true;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000533}
Daniel Malea246cb612013-05-14 15:20:12 +0000534
535bool
536ThreadPlanStepInRange::IsVirtualStep()
537{
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000538 return m_virtual_step;
Daniel Malea246cb612013-05-14 15:20:12 +0000539}