blob: 1e7b0458981d3e9f66b1e2d6e34bc6e486f16c06 [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
10#include "lldb/Target/ThreadPlanStepInRange.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16
17#include "lldb/lldb-private-log.h"
18#include "lldb/Core/Log.h"
Jim Ingham4da62062014-01-23 21:52:47 +000019#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Stream.h"
Jim Inghama56c8002010-07-10 02:27:39 +000021#include "lldb/Symbol/Symbol.h"
Jim Ingham7ce490c2010-09-16 00:58:09 +000022#include "lldb/Symbol/Function.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Target/Process.h"
24#include "lldb/Target/RegisterContext.h"
Greg Clayton514487e2011-02-15 21:59:32 +000025#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Target/Thread.h"
27#include "lldb/Target/ThreadPlanStepOut.h"
28#include "lldb/Target/ThreadPlanStepThrough.h"
Jim Inghama56c8002010-07-10 02:27:39 +000029#include "lldb/Core/RegularExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
31using namespace lldb;
32using namespace lldb_private;
33
Jim Ingham4b4b2472014-03-13 02:47:14 +000034uint32_t ThreadPlanStepInRange::s_default_flag_values = ThreadPlanShouldStopHere::eStepInAvoidNoDebug;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
36//----------------------------------------------------------------------
37// ThreadPlanStepInRange: Step through a stack range, either stepping over or into
38// based on the value of \a type.
39//----------------------------------------------------------------------
40
41ThreadPlanStepInRange::ThreadPlanStepInRange
42(
43 Thread &thread,
44 const AddressRange &range,
45 const SymbolContext &addr_context,
Jim Ingham4b4b2472014-03-13 02:47:14 +000046 lldb::RunMode stop_others,
47 LazyBool step_in_avoids_code_without_debug_info,
48 LazyBool step_out_avoids_code_without_debug_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049) :
Jim Inghamb01e7422010-06-19 04:45:32 +000050 ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others),
Jim Ingham4b4b2472014-03-13 02:47:14 +000051 ThreadPlanShouldStopHere (this),
Jim Inghamf02a2e92012-09-07 01:11:44 +000052 m_step_past_prologue (true),
53 m_virtual_step (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054{
Jim Ingham4b4b2472014-03-13 02:47:14 +000055 SetCallbacks();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056 SetFlagsToDefault ();
Jim Ingham4b4b2472014-03-13 02:47:14 +000057 SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058}
59
Jim Inghamc6276822012-12-12 19:58:40 +000060ThreadPlanStepInRange::ThreadPlanStepInRange
61(
62 Thread &thread,
63 const AddressRange &range,
64 const SymbolContext &addr_context,
65 const char *step_into_target,
Jim Ingham4b4b2472014-03-13 02:47:14 +000066 lldb::RunMode stop_others,
67 LazyBool step_in_avoids_code_without_debug_info,
68 LazyBool step_out_avoids_code_without_debug_info
Jim Inghamc6276822012-12-12 19:58:40 +000069) :
70 ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others),
Jim Ingham4b4b2472014-03-13 02:47:14 +000071 ThreadPlanShouldStopHere (this),
Jim Inghamc6276822012-12-12 19:58:40 +000072 m_step_past_prologue (true),
73 m_virtual_step (false),
74 m_step_into_target (step_into_target)
75{
Jim Ingham4b4b2472014-03-13 02:47:14 +000076 SetCallbacks();
Jim Inghamc6276822012-12-12 19:58:40 +000077 SetFlagsToDefault ();
Jim Ingham4b4b2472014-03-13 02:47:14 +000078 SetupAvoidNoDebug(step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info);
Jim Inghamc6276822012-12-12 19:58:40 +000079}
80
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081ThreadPlanStepInRange::~ThreadPlanStepInRange ()
82{
83}
84
85void
Jim Ingham4b4b2472014-03-13 02:47:14 +000086ThreadPlanStepInRange::SetupAvoidNoDebug(LazyBool step_in_avoids_code_without_debug_info,
87 LazyBool step_out_avoids_code_without_debug_info)
88{
89 bool avoid_nodebug = true;
90
91 switch (step_in_avoids_code_without_debug_info)
92 {
93 case eLazyBoolYes:
94 avoid_nodebug = true;
95 break;
96 case eLazyBoolNo:
97 avoid_nodebug = false;
98 break;
99 case eLazyBoolCalculate:
100 avoid_nodebug = m_thread.GetStepInAvoidsNoDebug();
101 break;
102 }
103 if (avoid_nodebug)
104 GetFlags().Set (ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
105 else
106 GetFlags().Clear (ThreadPlanShouldStopHere::eStepInAvoidNoDebug);
107
108 avoid_nodebug = true;
109 switch (step_out_avoids_code_without_debug_info)
110 {
111 case eLazyBoolYes:
112 avoid_nodebug = true;
113 break;
114 case eLazyBoolNo:
115 avoid_nodebug = false;
116 break;
117 case eLazyBoolCalculate:
118 avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug();
119 break;
120 }
121 if (avoid_nodebug)
122 GetFlags().Set (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
123 else
124 GetFlags().Clear (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
125}
126
127void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128ThreadPlanStepInRange::GetDescription (Stream *s, lldb::DescriptionLevel level)
129{
130 if (level == lldb::eDescriptionLevelBrief)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131 {
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000132 s->Printf("step in");
133 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134 }
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000135
136 s->Printf ("Stepping in");
137 bool printed_line_info = false;
138 if (m_addr_context.line_entry.IsValid())
139 {
140 s->Printf (" through line ");
141 m_addr_context.line_entry.DumpStopContext (s, false);
142 printed_line_info = true;
143 }
144
145 const char *step_into_target = m_step_into_target.AsCString();
146 if (step_into_target && step_into_target[0] != '\0')
147 s->Printf (" targeting %s", m_step_into_target.AsCString());
148
149 if (!printed_line_info || level == eDescriptionLevelVerbose)
150 {
151 s->Printf (" using ranges:");
152 DumpRanges(s);
153 }
154
155 s->PutChar('.');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156}
157
158bool
159ThreadPlanStepInRange::ShouldStop (Event *event_ptr)
160{
Greg Clayton5160ce52013-03-27 23:08:40 +0000161 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162
163 if (log)
164 {
165 StreamString s;
Greg Clayton514487e2011-02-15 21:59:32 +0000166 s.Address (m_thread.GetRegisterContext()->GetPC(),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000167 m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168 log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
169 }
170
Jim Ingham25f66702011-12-03 01:52:59 +0000171 if (IsPlanComplete())
172 return true;
173
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000174 m_no_more_plans = false;
175 if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete())
176 {
177 if (!m_sub_plan_sp->PlanSucceeded())
178 {
179 SetPlanComplete();
180 m_no_more_plans = true;
181 return true;
182 }
183 else
184 m_sub_plan_sp.reset();
185 }
186
Jim Inghamf02a2e92012-09-07 01:11:44 +0000187 if (m_virtual_step)
Jim Ingham58221732010-11-05 00:18:21 +0000188 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000189 // If we've just completed a virtual step, all we need to do is check for a ShouldStopHere plan, and otherwise
190 // we're done.
Jim Ingham4b4b2472014-03-13 02:47:14 +0000191 // FIXME - This can be both a step in and a step out. Probably should record which in the m_virtual_step.
192 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000193 }
194 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 {
Jim Ingham4a58e962012-10-25 22:30:09 +0000196 // Stepping through should be done running other threads in general, since we're setting a breakpoint and
197 // continuing. So only stop others if we are explicitly told to do so.
Jim Inghamf02a2e92012-09-07 01:11:44 +0000198
199 bool stop_others;
Jim Ingham4a58e962012-10-25 22:30:09 +0000200 if (m_stop_others == lldb::eOnlyThisThread)
Jim Ingham4a58e962012-10-25 22:30:09 +0000201 stop_others = true;
Ed Maste6cf5b8f2013-11-25 16:36:47 +0000202 else
203 stop_others = false;
Jim Inghamf02a2e92012-09-07 01:11:44 +0000204
205 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
206
Jim Ingham862d1bb2014-08-06 01:49:59 +0000207 if (frame_order == eFrameCompareOlder || frame_order == eFrameCompareSameParent)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000208 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000209 // If we're in an older frame then we should stop.
210 //
211 // A caveat to this is if we think the frame is older but we're actually in a trampoline.
212 // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are
213 // in a trampoline we think the frame is older because the trampoline confused the backtracer.
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000214 m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
215 if (!m_sub_plan_sp)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000216 {
217 // Otherwise check the ShouldStopHere for step out:
Jim Ingham862d1bb2014-08-06 01:49:59 +0000218 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
Jim Ingham4b4b2472014-03-13 02:47:14 +0000219 if (log)
220 log->Printf ("ShouldStopHere says we should step out of this frame.");
221 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000222 else if (log)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000223 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000224 log->Printf("Thought I stepped out, but in fact arrived at a trampoline.");
Jim Ingham7ce490c2010-09-16 00:58:09 +0000225 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000226
227 }
228 else if (frame_order == eFrameCompareEqual && InSymbol())
229 {
230 // If we are not in a place we should step through, we're done.
231 // One tricky bit here is that some stubs don't push a frame, so we have to check
232 // both the case of a frame that is younger, or the same as this frame.
233 // However, if the frame is the same, and we are still in the symbol we started
234 // in, the we don't need to do this. This first check isn't strictly necessary,
235 // but it is more efficient.
Jim Ingham7ce490c2010-09-16 00:58:09 +0000236
Jim Inghamf02a2e92012-09-07 01:11:44 +0000237 // If we're still in the range, keep going, either by running to the next branch breakpoint, or by
238 // stepping.
239 if (InRange())
Jim Ingham7ce490c2010-09-16 00:58:09 +0000240 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000241 SetNextBranchBreakpoint();
242 return false;
243 }
244
245 SetPlanComplete();
Jim Inghamc6276822012-12-12 19:58:40 +0000246 m_no_more_plans = true;
Jim Inghamf02a2e92012-09-07 01:11:44 +0000247 return true;
248 }
249
250 // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
251 ClearNextBranchBreakpoint();
252
253 // We may have set the plan up above in the FrameIsOlder section:
254
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000255 if (!m_sub_plan_sp)
256 m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000257
258 if (log)
259 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000260 if (m_sub_plan_sp)
261 log->Printf ("Found a step through plan: %s", m_sub_plan_sp->GetName());
Jim Inghamf02a2e92012-09-07 01:11:44 +0000262 else
263 log->Printf ("No step through plan found.");
264 }
265
266 // If not, give the "should_stop" callback a chance to push a plan to get us out of here.
267 // But only do that if we actually have stepped in.
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000268 if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000269 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000270
271 // If we've stepped in and we are going to stop here, check to see if we were asked to
272 // run past the prologue, and if so do that.
273
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000274 if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && m_step_past_prologue)
Jim Inghamf02a2e92012-09-07 01:11:44 +0000275 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000276 lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000277 if (curr_frame)
278 {
279 size_t bytes_to_skip = 0;
280 lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC();
281 Address func_start_address;
282
283 SymbolContext sc = curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextSymbol);
284
285 if (sc.function)
286 {
287 func_start_address = sc.function->GetAddressRange().GetBaseAddress();
288 if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
289 bytes_to_skip = sc.function->GetPrologueByteSize();
290 }
291 else if (sc.symbol)
292 {
293 func_start_address = sc.symbol->GetAddress();
294 if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
295 bytes_to_skip = sc.symbol->GetPrologueByteSize();
296 }
297
298 if (bytes_to_skip != 0)
299 {
300 func_start_address.Slide (bytes_to_skip);
301 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
302 if (log)
303 log->Printf ("Pushing past prologue ");
304
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000305 m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(false, func_start_address,true);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000306 }
Jim Ingham7ce490c2010-09-16 00:58:09 +0000307 }
308 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000309 }
Jim Ingham7ce490c2010-09-16 00:58:09 +0000310
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000311 if (!m_sub_plan_sp)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000312 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313 m_no_more_plans = true;
314 SetPlanComplete();
315 return true;
316 }
317 else
318 {
319 m_no_more_plans = false;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000320 m_sub_plan_sp->SetPrivate(true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 return false;
322 }
323}
324
Jim Inghama56c8002010-07-10 02:27:39 +0000325void
326ThreadPlanStepInRange::SetAvoidRegexp(const char *name)
327{
328 if (m_avoid_regexp_ap.get() == NULL)
329 m_avoid_regexp_ap.reset (new RegularExpression(name));
330
331 m_avoid_regexp_ap->Compile (name);
332}
333
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000334void
335ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value)
336{
337 // TODO: Should we test this for sanity?
338 ThreadPlanStepInRange::s_default_flag_values = new_value;
339}
340
Jim Inghama56c8002010-07-10 02:27:39 +0000341bool
Jim Ingham4da62062014-01-23 21:52:47 +0000342ThreadPlanStepInRange::FrameMatchesAvoidCriteria ()
Jim Inghama56c8002010-07-10 02:27:39 +0000343{
Jason Molendab57e4a12013-11-04 09:33:30 +0000344 StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
Jim Ingham4da62062014-01-23 21:52:47 +0000345
346 // Check the library list first, as that's cheapest:
Jim Inghama786e532014-01-23 21:57:53 +0000347 bool libraries_say_avoid = false;
348
Jim Ingham4da62062014-01-23 21:52:47 +0000349 FileSpecList libraries_to_avoid (GetThread().GetLibrariesToAvoid());
350 size_t num_libraries = libraries_to_avoid.GetSize();
Jim Inghama786e532014-01-23 21:57:53 +0000351 if (num_libraries > 0)
Jim Ingham4da62062014-01-23 21:52:47 +0000352 {
Jim Inghama786e532014-01-23 21:57:53 +0000353 SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
354 FileSpec frame_library(sc.module_sp->GetFileSpec());
355
356 if (frame_library)
Jim Ingham4da62062014-01-23 21:52:47 +0000357 {
Jim Inghama786e532014-01-23 21:57:53 +0000358 for (size_t i = 0; i < num_libraries; i++)
Jim Ingham4da62062014-01-23 21:52:47 +0000359 {
Jim Inghama786e532014-01-23 21:57:53 +0000360 const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
361 if (FileSpec::Equal (file_spec, frame_library, false))
362 {
363 libraries_say_avoid = true;
364 break;
365 }
Jim Ingham4da62062014-01-23 21:52:47 +0000366 }
367 }
368 }
369 if (libraries_say_avoid)
370 return true;
371
Greg Clayton67cc0632012-08-22 17:17:09 +0000372 const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
Jim Inghamee8aea12010-09-08 03:14:33 +0000373 if (avoid_regexp_to_use == NULL)
374 avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
375
376 if (avoid_regexp_to_use != NULL)
Jim Inghama56c8002010-07-10 02:27:39 +0000377 {
Greg Clayton4592cbc2012-07-13 00:19:40 +0000378 SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
Jim Inghama56c8002010-07-10 02:27:39 +0000379 if (sc.symbol != NULL)
380 {
Greg Clayton4592cbc2012-07-13 00:19:40 +0000381 const char *frame_function_name = sc.GetFunctionName().GetCString();
382 if (frame_function_name)
Jim Ingham3101ba32013-03-14 21:44:36 +0000383 {
Jim Inghamcf2667c2013-03-14 22:00:18 +0000384 size_t num_matches = 0;
Greg Clayton5160ce52013-03-27 23:08:40 +0000385 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamcf2667c2013-03-14 22:00:18 +0000386 if (log)
387 num_matches = 1;
Greg Claytonbc43cab2013-04-03 21:37:16 +0000388
389 RegularExpression::Match regex_match(num_matches);
390
391 bool return_value = avoid_regexp_to_use->Execute(frame_function_name, &regex_match);
Jim Ingham3101ba32013-03-14 21:44:36 +0000392 if (return_value)
393 {
Jim Ingham3101ba32013-03-14 21:44:36 +0000394 if (log)
Jim Inghamcf2667c2013-03-14 22:00:18 +0000395 {
396 std::string match;
Greg Claytonbc43cab2013-04-03 21:37:16 +0000397 regex_match.GetMatchAtIndex(frame_function_name,0, match);
Jim Inghamcf2667c2013-03-14 22:00:18 +0000398 log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".",
Jim Ingham3101ba32013-03-14 21:44:36 +0000399 frame_function_name,
Jim Inghamcf2667c2013-03-14 22:00:18 +0000400 avoid_regexp_to_use->GetText(),
401 match.c_str());
402 }
Jim Ingham3101ba32013-03-14 21:44:36 +0000403
404 }
405 return return_value;
406 }
Jim Inghama56c8002010-07-10 02:27:39 +0000407 }
408 }
409 return false;
410}
411
Jim Ingham4b4b2472014-03-13 02:47:14 +0000412bool
413ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, FrameComparison operation, void *baton)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000415 bool should_stop_here = true;
Jason Molendab57e4a12013-11-04 09:33:30 +0000416 StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
Greg Clayton5160ce52013-03-27 23:08:40 +0000417 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghama56c8002010-07-10 02:27:39 +0000418
Jim Ingham0c2b9d22014-08-08 01:27:01 +0000419 // First see if the ThreadPlanShouldStopHere default implementation thinks we should get out of here:
420 should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback (current_plan, flags, operation, baton);
421 if (!should_stop_here)
422 return should_stop_here;
Jim Inghama56c8002010-07-10 02:27:39 +0000423
Jim Ingham4b4b2472014-03-13 02:47:14 +0000424 if (should_stop_here && current_plan->GetKind() == eKindStepInRange && operation == eFrameCompareYounger)
Jim Inghama56c8002010-07-10 02:27:39 +0000425 {
Jim Inghamc6276822012-12-12 19:58:40 +0000426 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
427 if (step_in_range_plan->m_step_into_target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 {
Jim Inghamc6276822012-12-12 19:58:40 +0000429 SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
430 if (sc.symbol != NULL)
431 {
432 // First try an exact match, since that's cheap with ConstStrings. Then do a strstr compare.
433 if (step_in_range_plan->m_step_into_target == sc.GetFunctionName())
434 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000435 should_stop_here = true;
Jim Inghamc6276822012-12-12 19:58:40 +0000436 }
437 else
438 {
439 const char *target_name = step_in_range_plan->m_step_into_target.AsCString();
440 const char *function_name = sc.GetFunctionName().AsCString();
441
442 if (function_name == NULL)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000443 should_stop_here = false;
Jim Inghamc6276822012-12-12 19:58:40 +0000444 else if (strstr (function_name, target_name) == NULL)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000445 should_stop_here = false;
Jim Inghamc6276822012-12-12 19:58:40 +0000446 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000447 if (log && !should_stop_here)
Jim Ingham3101ba32013-03-14 21:44:36 +0000448 log->Printf("Stepping out of frame %s which did not match step into target %s.",
449 sc.GetFunctionName().AsCString(),
450 step_in_range_plan->m_step_into_target.AsCString());
Jim Inghamc6276822012-12-12 19:58:40 +0000451 }
452 }
453
Jim Ingham4b4b2472014-03-13 02:47:14 +0000454 if (should_stop_here)
Jim Inghamc6276822012-12-12 19:58:40 +0000455 {
Jim Ingham3101ba32013-03-14 21:44:36 +0000456 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
Jim Ingham4da62062014-01-23 21:52:47 +0000457 // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidCriteria.
Jim Ingham4b4b2472014-03-13 02:47:14 +0000458 should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 }
460 }
Jim Inghama56c8002010-07-10 02:27:39 +0000461
Jim Ingham4b4b2472014-03-13 02:47:14 +0000462 return should_stop_here;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463}
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000464
465bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000466ThreadPlanStepInRange::DoPlanExplainsStop (Event *event_ptr)
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000467{
468 // We always explain a stop. Either we've just done a single step, in which
469 // case we'll do our ordinary processing, or we stopped for some
470 // reason that isn't handled by our sub-plans, in which case we want to just stop right
471 // away.
Jim Inghamc6276822012-12-12 19:58:40 +0000472 // In general, we don't want to mark the plan as complete for unexplained stops.
473 // For instance, if you step in to some code with no debug info, so you step out
474 // and in the course of that hit a breakpoint, then you want to stop & show the user
475 // the breakpoint, but not unship the step in plan, since you still may want to complete that
476 // plan when you continue. This is particularly true when doing "step in to target function."
477 // stepping.
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000478 //
479 // The only variation is that if we are doing "step by running to next branch" in which case
480 // if we hit our branch breakpoint we don't set the plan to complete.
Jim Ingham221d51c2013-05-08 00:35:16 +0000481
482 bool return_value;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000483
Jim Inghamf02a2e92012-09-07 01:11:44 +0000484 if (m_virtual_step)
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000485 {
Jim Ingham221d51c2013-05-08 00:35:16 +0000486 return_value = true;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000487 }
Jim Ingham221d51c2013-05-08 00:35:16 +0000488 else
489 {
Jim Ingham60c41182013-06-04 01:40:51 +0000490 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Jim Ingham221d51c2013-05-08 00:35:16 +0000491 if (stop_info_sp)
492 {
493 StopReason reason = stop_info_sp->GetStopReason();
494
495 switch (reason)
496 {
497 case eStopReasonBreakpoint:
498 if (NextRangeBreakpointExplainsStop(stop_info_sp))
499 {
500 return_value = true;
501 break;
502 }
503 case eStopReasonWatchpoint:
504 case eStopReasonSignal:
505 case eStopReasonException:
506 case eStopReasonExec:
507 case eStopReasonThreadExiting:
508 {
509 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
510 if (log)
511 log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step.");
512 }
513 return_value = false;
514 break;
515 default:
516 return_value = true;
517 break;
518 }
519 }
520 else
521 return_value = true;
522 }
523
524 return return_value;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000525}
Jim Ingham513c6bb2012-09-01 01:02:41 +0000526
527bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000528ThreadPlanStepInRange::DoWillResume (lldb::StateType resume_state, bool current_plan)
Jim Ingham513c6bb2012-09-01 01:02:41 +0000529{
530 if (resume_state == eStateStepping && current_plan)
531 {
532 // See if we are about to step over a virtual inlined call.
533 bool step_without_resume = m_thread.DecrementCurrentInlinedDepth();
534 if (step_without_resume)
535 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000536 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham513c6bb2012-09-01 01:02:41 +0000537 if (log)
Jim Ingham221d51c2013-05-08 00:35:16 +0000538 log->Printf ("ThreadPlanStepInRange::DoWillResume: returning false, inline_depth: %d",
Jim Ingham513c6bb2012-09-01 01:02:41 +0000539 m_thread.GetCurrentInlinedDepth());
540 SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread));
Jim Inghamf02a2e92012-09-07 01:11:44 +0000541
542 // FIXME: Maybe it would be better to create a InlineStep stop reason, but then
543 // the whole rest of the world would have to handle that stop reason.
544 m_virtual_step = true;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000545 }
546 return !step_without_resume;
547 }
Jim Ingham221d51c2013-05-08 00:35:16 +0000548 return true;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000549}
Daniel Malea246cb612013-05-14 15:20:12 +0000550
551bool
552ThreadPlanStepInRange::IsVirtualStep()
553{
554 return m_virtual_step;
555}