blob: 35826ec16d0daa168a27151aa8bb9f7aea1e2573 [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)
131 s->Printf("step in");
132 else
133 {
134 s->Printf ("Stepping through range (stepping into functions): ");
Jim Inghamc4c9fed2011-10-15 00:24:48 +0000135 DumpRanges(s);
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000136 const char *step_into_target = m_step_into_target.AsCString();
137 if (step_into_target && step_into_target[0] != '\0')
138 s->Printf (" targeting %s.", m_step_into_target.AsCString());
139 else
140 s->PutChar('.');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141 }
142}
143
144bool
145ThreadPlanStepInRange::ShouldStop (Event *event_ptr)
146{
Greg Clayton5160ce52013-03-27 23:08:40 +0000147 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148
149 if (log)
150 {
151 StreamString s;
Greg Clayton514487e2011-02-15 21:59:32 +0000152 s.Address (m_thread.GetRegisterContext()->GetPC(),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000153 m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000154 log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
155 }
156
Jim Ingham25f66702011-12-03 01:52:59 +0000157 if (IsPlanComplete())
158 return true;
159
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000160 m_no_more_plans = false;
161 if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete())
162 {
163 if (!m_sub_plan_sp->PlanSucceeded())
164 {
165 SetPlanComplete();
166 m_no_more_plans = true;
167 return true;
168 }
169 else
170 m_sub_plan_sp.reset();
171 }
172
Jim Inghamf02a2e92012-09-07 01:11:44 +0000173 if (m_virtual_step)
Jim Ingham58221732010-11-05 00:18:21 +0000174 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000175 // If we've just completed a virtual step, all we need to do is check for a ShouldStopHere plan, and otherwise
176 // we're done.
Jim Ingham4b4b2472014-03-13 02:47:14 +0000177 // FIXME - This can be both a step in and a step out. Probably should record which in the m_virtual_step.
178 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(eFrameCompareYounger);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000179 }
180 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181 {
Jim Ingham4a58e962012-10-25 22:30:09 +0000182 // Stepping through should be done running other threads in general, since we're setting a breakpoint and
183 // continuing. So only stop others if we are explicitly told to do so.
Jim Inghamf02a2e92012-09-07 01:11:44 +0000184
185 bool stop_others;
Jim Ingham4a58e962012-10-25 22:30:09 +0000186 if (m_stop_others == lldb::eOnlyThisThread)
Jim Ingham4a58e962012-10-25 22:30:09 +0000187 stop_others = true;
Ed Maste6cf5b8f2013-11-25 16:36:47 +0000188 else
189 stop_others = false;
Jim Inghamf02a2e92012-09-07 01:11:44 +0000190
191 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
192
Jim Ingham862d1bb2014-08-06 01:49:59 +0000193 if (frame_order == eFrameCompareOlder || frame_order == eFrameCompareSameParent)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000194 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000195 // If we're in an older frame then we should stop.
196 //
197 // A caveat to this is if we think the frame is older but we're actually in a trampoline.
198 // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are
199 // in a trampoline we think the frame is older because the trampoline confused the backtracer.
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000200 m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
201 if (!m_sub_plan_sp)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000202 {
203 // Otherwise check the ShouldStopHere for step out:
Jim Ingham862d1bb2014-08-06 01:49:59 +0000204 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
Jim Ingham4b4b2472014-03-13 02:47:14 +0000205 if (log)
206 log->Printf ("ShouldStopHere says we should step out of this frame.");
207 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000208 else if (log)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000209 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000210 log->Printf("Thought I stepped out, but in fact arrived at a trampoline.");
Jim Ingham7ce490c2010-09-16 00:58:09 +0000211 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000212
213 }
214 else if (frame_order == eFrameCompareEqual && InSymbol())
215 {
216 // If we are not in a place we should step through, we're done.
217 // One tricky bit here is that some stubs don't push a frame, so we have to check
218 // both the case of a frame that is younger, or the same as this frame.
219 // However, if the frame is the same, and we are still in the symbol we started
220 // in, the we don't need to do this. This first check isn't strictly necessary,
221 // but it is more efficient.
Jim Ingham7ce490c2010-09-16 00:58:09 +0000222
Jim Inghamf02a2e92012-09-07 01:11:44 +0000223 // If we're still in the range, keep going, either by running to the next branch breakpoint, or by
224 // stepping.
225 if (InRange())
Jim Ingham7ce490c2010-09-16 00:58:09 +0000226 {
Jim Inghamf02a2e92012-09-07 01:11:44 +0000227 SetNextBranchBreakpoint();
228 return false;
229 }
230
231 SetPlanComplete();
Jim Inghamc6276822012-12-12 19:58:40 +0000232 m_no_more_plans = true;
Jim Inghamf02a2e92012-09-07 01:11:44 +0000233 return true;
234 }
235
236 // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
237 ClearNextBranchBreakpoint();
238
239 // We may have set the plan up above in the FrameIsOlder section:
240
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000241 if (!m_sub_plan_sp)
242 m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000243
244 if (log)
245 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000246 if (m_sub_plan_sp)
247 log->Printf ("Found a step through plan: %s", m_sub_plan_sp->GetName());
Jim Inghamf02a2e92012-09-07 01:11:44 +0000248 else
249 log->Printf ("No step through plan found.");
250 }
251
252 // If not, give the "should_stop" callback a chance to push a plan to get us out of here.
253 // But only do that if we actually have stepped in.
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000254 if (!m_sub_plan_sp && frame_order == eFrameCompareYounger)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000255 m_sub_plan_sp = CheckShouldStopHereAndQueueStepOut(frame_order);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000256
257 // If we've stepped in and we are going to stop here, check to see if we were asked to
258 // run past the prologue, and if so do that.
259
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000260 if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && m_step_past_prologue)
Jim Inghamf02a2e92012-09-07 01:11:44 +0000261 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000262 lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000263 if (curr_frame)
264 {
265 size_t bytes_to_skip = 0;
266 lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC();
267 Address func_start_address;
268
269 SymbolContext sc = curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextSymbol);
270
271 if (sc.function)
272 {
273 func_start_address = sc.function->GetAddressRange().GetBaseAddress();
274 if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
275 bytes_to_skip = sc.function->GetPrologueByteSize();
276 }
277 else if (sc.symbol)
278 {
279 func_start_address = sc.symbol->GetAddress();
280 if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
281 bytes_to_skip = sc.symbol->GetPrologueByteSize();
282 }
283
284 if (bytes_to_skip != 0)
285 {
286 func_start_address.Slide (bytes_to_skip);
287 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
288 if (log)
289 log->Printf ("Pushing past prologue ");
290
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000291 m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(false, func_start_address,true);
Jim Inghamf02a2e92012-09-07 01:11:44 +0000292 }
Jim Ingham7ce490c2010-09-16 00:58:09 +0000293 }
294 }
Jim Inghamf02a2e92012-09-07 01:11:44 +0000295 }
Jim Ingham7ce490c2010-09-16 00:58:09 +0000296
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000297 if (!m_sub_plan_sp)
Jim Ingham7ce490c2010-09-16 00:58:09 +0000298 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000299 m_no_more_plans = true;
300 SetPlanComplete();
301 return true;
302 }
303 else
304 {
305 m_no_more_plans = false;
306 return false;
307 }
308}
309
Jim Inghama56c8002010-07-10 02:27:39 +0000310void
311ThreadPlanStepInRange::SetAvoidRegexp(const char *name)
312{
313 if (m_avoid_regexp_ap.get() == NULL)
314 m_avoid_regexp_ap.reset (new RegularExpression(name));
315
316 m_avoid_regexp_ap->Compile (name);
317}
318
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319void
320ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value)
321{
322 // TODO: Should we test this for sanity?
323 ThreadPlanStepInRange::s_default_flag_values = new_value;
324}
325
Jim Inghama56c8002010-07-10 02:27:39 +0000326bool
Jim Ingham4da62062014-01-23 21:52:47 +0000327ThreadPlanStepInRange::FrameMatchesAvoidCriteria ()
Jim Inghama56c8002010-07-10 02:27:39 +0000328{
Jason Molendab57e4a12013-11-04 09:33:30 +0000329 StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
Jim Ingham4da62062014-01-23 21:52:47 +0000330
331 // Check the library list first, as that's cheapest:
Jim Inghama786e532014-01-23 21:57:53 +0000332 bool libraries_say_avoid = false;
333
Jim Ingham4da62062014-01-23 21:52:47 +0000334 FileSpecList libraries_to_avoid (GetThread().GetLibrariesToAvoid());
335 size_t num_libraries = libraries_to_avoid.GetSize();
Jim Inghama786e532014-01-23 21:57:53 +0000336 if (num_libraries > 0)
Jim Ingham4da62062014-01-23 21:52:47 +0000337 {
Jim Inghama786e532014-01-23 21:57:53 +0000338 SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
339 FileSpec frame_library(sc.module_sp->GetFileSpec());
340
341 if (frame_library)
Jim Ingham4da62062014-01-23 21:52:47 +0000342 {
Jim Inghama786e532014-01-23 21:57:53 +0000343 for (size_t i = 0; i < num_libraries; i++)
Jim Ingham4da62062014-01-23 21:52:47 +0000344 {
Jim Inghama786e532014-01-23 21:57:53 +0000345 const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
346 if (FileSpec::Equal (file_spec, frame_library, false))
347 {
348 libraries_say_avoid = true;
349 break;
350 }
Jim Ingham4da62062014-01-23 21:52:47 +0000351 }
352 }
353 }
354 if (libraries_say_avoid)
355 return true;
356
Greg Clayton67cc0632012-08-22 17:17:09 +0000357 const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
Jim Inghamee8aea12010-09-08 03:14:33 +0000358 if (avoid_regexp_to_use == NULL)
359 avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
360
361 if (avoid_regexp_to_use != NULL)
Jim Inghama56c8002010-07-10 02:27:39 +0000362 {
Greg Clayton4592cbc2012-07-13 00:19:40 +0000363 SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
Jim Inghama56c8002010-07-10 02:27:39 +0000364 if (sc.symbol != NULL)
365 {
Greg Clayton4592cbc2012-07-13 00:19:40 +0000366 const char *frame_function_name = sc.GetFunctionName().GetCString();
367 if (frame_function_name)
Jim Ingham3101ba32013-03-14 21:44:36 +0000368 {
Jim Inghamcf2667c2013-03-14 22:00:18 +0000369 size_t num_matches = 0;
Greg Clayton5160ce52013-03-27 23:08:40 +0000370 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamcf2667c2013-03-14 22:00:18 +0000371 if (log)
372 num_matches = 1;
Greg Claytonbc43cab2013-04-03 21:37:16 +0000373
374 RegularExpression::Match regex_match(num_matches);
375
376 bool return_value = avoid_regexp_to_use->Execute(frame_function_name, &regex_match);
Jim Ingham3101ba32013-03-14 21:44:36 +0000377 if (return_value)
378 {
Jim Ingham3101ba32013-03-14 21:44:36 +0000379 if (log)
Jim Inghamcf2667c2013-03-14 22:00:18 +0000380 {
381 std::string match;
Greg Claytonbc43cab2013-04-03 21:37:16 +0000382 regex_match.GetMatchAtIndex(frame_function_name,0, match);
Jim Inghamcf2667c2013-03-14 22:00:18 +0000383 log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".",
Jim Ingham3101ba32013-03-14 21:44:36 +0000384 frame_function_name,
Jim Inghamcf2667c2013-03-14 22:00:18 +0000385 avoid_regexp_to_use->GetText(),
386 match.c_str());
387 }
Jim Ingham3101ba32013-03-14 21:44:36 +0000388
389 }
390 return return_value;
391 }
Jim Inghama56c8002010-07-10 02:27:39 +0000392 }
393 }
394 return false;
395}
396
Jim Ingham4b4b2472014-03-13 02:47:14 +0000397bool
398ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, FrameComparison operation, void *baton)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000400 bool should_stop_here = true;
Jason Molendab57e4a12013-11-04 09:33:30 +0000401 StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
Greg Clayton5160ce52013-03-27 23:08:40 +0000402 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghama56c8002010-07-10 02:27:39 +0000403
Jim Ingham4b4b2472014-03-13 02:47:14 +0000404 if ((operation == eFrameCompareYounger && flags.Test(eStepInAvoidNoDebug))
Jim Ingham862d1bb2014-08-06 01:49:59 +0000405 || (operation == eFrameCompareSameParent && flags.Test(eStepOutAvoidNoDebug))
Jim Ingham4b4b2472014-03-13 02:47:14 +0000406 || (operation == eFrameCompareOlder && flags.Test(eStepOutAvoidNoDebug)))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 if (!frame->HasDebugInformation())
Jim Inghamaf0f1752010-09-15 00:06:51 +0000409 {
410 if (log)
411 log->Printf ("Stepping out of frame with no debug info");
412
Jim Ingham4b4b2472014-03-13 02:47:14 +0000413 should_stop_here = false;
Jim Inghamaf0f1752010-09-15 00:06:51 +0000414 }
Jim Inghama56c8002010-07-10 02:27:39 +0000415 }
416
Jim Ingham4b4b2472014-03-13 02:47:14 +0000417 if (should_stop_here && current_plan->GetKind() == eKindStepInRange && operation == eFrameCompareYounger)
Jim Inghama56c8002010-07-10 02:27:39 +0000418 {
Jim Inghamc6276822012-12-12 19:58:40 +0000419 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
420 if (step_in_range_plan->m_step_into_target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 {
Jim Inghamc6276822012-12-12 19:58:40 +0000422 SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol);
423 if (sc.symbol != NULL)
424 {
425 // First try an exact match, since that's cheap with ConstStrings. Then do a strstr compare.
426 if (step_in_range_plan->m_step_into_target == sc.GetFunctionName())
427 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000428 should_stop_here = true;
Jim Inghamc6276822012-12-12 19:58:40 +0000429 }
430 else
431 {
432 const char *target_name = step_in_range_plan->m_step_into_target.AsCString();
433 const char *function_name = sc.GetFunctionName().AsCString();
434
435 if (function_name == NULL)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000436 should_stop_here = false;
Jim Inghamc6276822012-12-12 19:58:40 +0000437 else if (strstr (function_name, target_name) == NULL)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000438 should_stop_here = false;
Jim Inghamc6276822012-12-12 19:58:40 +0000439 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000440 if (log && !should_stop_here)
Jim Ingham3101ba32013-03-14 21:44:36 +0000441 log->Printf("Stepping out of frame %s which did not match step into target %s.",
442 sc.GetFunctionName().AsCString(),
443 step_in_range_plan->m_step_into_target.AsCString());
Jim Inghamc6276822012-12-12 19:58:40 +0000444 }
445 }
446
Jim Ingham4b4b2472014-03-13 02:47:14 +0000447 if (should_stop_here)
Jim Inghamc6276822012-12-12 19:58:40 +0000448 {
Jim Ingham3101ba32013-03-14 21:44:36 +0000449 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
Jim Ingham4da62062014-01-23 21:52:47 +0000450 // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidCriteria.
Jim Ingham4b4b2472014-03-13 02:47:14 +0000451 should_stop_here = !step_in_range_plan->FrameMatchesAvoidCriteria ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 }
453 }
Jim Inghama56c8002010-07-10 02:27:39 +0000454
Jim Ingham4b4b2472014-03-13 02:47:14 +0000455 return should_stop_here;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456}
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000457
458bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000459ThreadPlanStepInRange::DoPlanExplainsStop (Event *event_ptr)
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000460{
461 // We always explain a stop. Either we've just done a single step, in which
462 // case we'll do our ordinary processing, or we stopped for some
463 // reason that isn't handled by our sub-plans, in which case we want to just stop right
464 // away.
Jim Inghamc6276822012-12-12 19:58:40 +0000465 // In general, we don't want to mark the plan as complete for unexplained stops.
466 // For instance, if you step in to some code with no debug info, so you step out
467 // and in the course of that hit a breakpoint, then you want to stop & show the user
468 // the breakpoint, but not unship the step in plan, since you still may want to complete that
469 // plan when you continue. This is particularly true when doing "step in to target function."
470 // stepping.
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000471 //
472 // The only variation is that if we are doing "step by running to next branch" in which case
473 // if we hit our branch breakpoint we don't set the plan to complete.
Jim Ingham221d51c2013-05-08 00:35:16 +0000474
475 bool return_value;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000476
Jim Inghamf02a2e92012-09-07 01:11:44 +0000477 if (m_virtual_step)
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000478 {
Jim Ingham221d51c2013-05-08 00:35:16 +0000479 return_value = true;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000480 }
Jim Ingham221d51c2013-05-08 00:35:16 +0000481 else
482 {
Jim Ingham60c41182013-06-04 01:40:51 +0000483 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Jim Ingham221d51c2013-05-08 00:35:16 +0000484 if (stop_info_sp)
485 {
486 StopReason reason = stop_info_sp->GetStopReason();
487
488 switch (reason)
489 {
490 case eStopReasonBreakpoint:
491 if (NextRangeBreakpointExplainsStop(stop_info_sp))
492 {
493 return_value = true;
494 break;
495 }
496 case eStopReasonWatchpoint:
497 case eStopReasonSignal:
498 case eStopReasonException:
499 case eStopReasonExec:
500 case eStopReasonThreadExiting:
501 {
502 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
503 if (log)
504 log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step.");
505 }
506 return_value = false;
507 break;
508 default:
509 return_value = true;
510 break;
511 }
512 }
513 else
514 return_value = true;
515 }
516
517 return return_value;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000518}
Jim Ingham513c6bb2012-09-01 01:02:41 +0000519
520bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000521ThreadPlanStepInRange::DoWillResume (lldb::StateType resume_state, bool current_plan)
Jim Ingham513c6bb2012-09-01 01:02:41 +0000522{
523 if (resume_state == eStateStepping && current_plan)
524 {
525 // See if we are about to step over a virtual inlined call.
526 bool step_without_resume = m_thread.DecrementCurrentInlinedDepth();
527 if (step_without_resume)
528 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000529 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham513c6bb2012-09-01 01:02:41 +0000530 if (log)
Jim Ingham221d51c2013-05-08 00:35:16 +0000531 log->Printf ("ThreadPlanStepInRange::DoWillResume: returning false, inline_depth: %d",
Jim Ingham513c6bb2012-09-01 01:02:41 +0000532 m_thread.GetCurrentInlinedDepth());
533 SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread));
Jim Inghamf02a2e92012-09-07 01:11:44 +0000534
535 // FIXME: Maybe it would be better to create a InlineStep stop reason, but then
536 // the whole rest of the world would have to handle that stop reason.
537 m_virtual_step = true;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000538 }
539 return !step_without_resume;
540 }
Jim Ingham221d51c2013-05-08 00:35:16 +0000541 return true;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000542}
Daniel Malea246cb612013-05-14 15:20:12 +0000543
544bool
545ThreadPlanStepInRange::IsVirtualStep()
546{
547 return m_virtual_step;
548}