blob: 1bbbfb3cb5a1d8563ef82e8d717817b1bc59e53d [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- ThreadPlanStepOverRange.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/ThreadPlanStepOverRange.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"
19#include "lldb/Core/Stream.h"
20#include "lldb/Target/Process.h"
21#include "lldb/Target/RegisterContext.h"
Greg Clayton395fc332011-02-15 21:59:32 +000022#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Target/Thread.h"
24#include "lldb/Target/ThreadPlanStepOut.h"
25#include "lldb/Target/ThreadPlanStepThrough.h"
26
27using namespace lldb_private;
Greg Claytone005f2c2010-11-06 01:53:30 +000028using namespace lldb;
Chris Lattner24943d22010-06-08 16:52:24 +000029
30
31//----------------------------------------------------------------------
32// ThreadPlanStepOverRange: Step through a stack range, either stepping over or into
33// based on the value of \a type.
34//----------------------------------------------------------------------
35
36ThreadPlanStepOverRange::ThreadPlanStepOverRange
37(
38 Thread &thread,
39 const AddressRange &range,
40 const SymbolContext &addr_context,
Jim Ingham88e3de22012-05-03 21:19:36 +000041 lldb::RunMode stop_others
Chris Lattner24943d22010-06-08 16:52:24 +000042) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000043 ThreadPlanStepRange (ThreadPlan::eKindStepOverRange, "Step range stepping over", thread, range, addr_context, stop_others)
Chris Lattner24943d22010-06-08 16:52:24 +000044{
Chris Lattner24943d22010-06-08 16:52:24 +000045}
46
47ThreadPlanStepOverRange::~ThreadPlanStepOverRange ()
48{
49}
50
51void
52ThreadPlanStepOverRange::GetDescription (Stream *s, lldb::DescriptionLevel level)
53{
54 if (level == lldb::eDescriptionLevelBrief)
55 s->Printf("step over");
56 else
57 {
58 s->Printf ("stepping through range (stepping over functions): ");
Jim Ingham76e55f72011-10-15 00:24:48 +000059 DumpRanges(s);
Chris Lattner24943d22010-06-08 16:52:24 +000060 }
61}
62
63bool
64ThreadPlanStepOverRange::ShouldStop (Event *event_ptr)
65{
Greg Claytone005f2c2010-11-06 01:53:30 +000066 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +000067
68 if (log)
69 {
70 StreamString s;
Greg Clayton395fc332011-02-15 21:59:32 +000071 s.Address (m_thread.GetRegisterContext()->GetPC(),
Greg Claytonf4124de2012-02-21 00:09:25 +000072 m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +000073 log->Printf("ThreadPlanStepOverRange reached %s.", s.GetData());
74 }
75
Chris Lattner24943d22010-06-08 16:52:24 +000076 // If we're out of the range but in the same frame or in our caller's frame
77 // then we should stop.
78 // When stepping out we only step if we are forcing running one thread.
79 bool stop_others;
80 if (m_stop_others == lldb::eOnlyThisThread)
81 stop_others = true;
82 else
83 stop_others = false;
84
85 ThreadPlan* new_plan = NULL;
Jim Ingham441e3b92012-03-01 00:50:50 +000086
87 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
88
89 if (frame_order == eFrameCompareOlder)
Jim Ingham4f385f12010-11-05 00:18:21 +000090 {
91 // If we're in an older frame then we should stop.
92 //
93 // A caveat to this is if we think the frame is older but we're actually in a trampoline.
94 // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are
95 // in a trampoline we think the frame is older because the trampoline confused the backtracer.
96 // As below, we step through first, and then try to figure out how to get back out again.
97
98 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
99
100 if (new_plan != NULL && log)
101 log->Printf("Thought I stepped out, but in fact arrived at a trampoline.");
102 }
Jim Ingham441e3b92012-03-01 00:50:50 +0000103 else if (frame_order == eFrameCompareYounger)
Chris Lattner24943d22010-06-08 16:52:24 +0000104 {
Jim Ingham441e3b92012-03-01 00:50:50 +0000105 // Make sure we really are in a new frame. Do that by unwinding and seeing if the
106 // start function really is our start function...
107 StackFrameSP older_frame_sp = m_thread.GetStackFrameAtIndex(1);
108
109 // But if we can't even unwind one frame we should just get out of here & stop...
110 if (older_frame_sp)
111 {
112 const SymbolContext &older_context = older_frame_sp->GetSymbolContext(eSymbolContextEverything);
113 if (older_context == m_addr_context)
114 {
115 new_plan = m_thread.QueueThreadPlanForStepOut (false,
116 NULL,
117 true,
118 stop_others,
119 eVoteNo,
120 eVoteNoOpinion,
121 0);
122 }
123 else
124 {
125 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
126
127 }
128 }
Chris Lattner24943d22010-06-08 16:52:24 +0000129 }
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000130 else
Chris Lattner24943d22010-06-08 16:52:24 +0000131 {
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000132 // If we're still in the range, keep going.
133 if (InRange())
134 {
135 SetNextBranchBreakpoint();
136 return false;
137 }
138
139
140 if (!InSymbol())
141 {
142 // This one is a little tricky. Sometimes we may be in a stub or something similar,
143 // in which case we need to get out of there. But if we are in a stub then it's
144 // likely going to be hard to get out from here. It is probably easiest to step into the
145 // stub, and then it will be straight-forward to step out.
146 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
147 }
Chris Lattner24943d22010-06-08 16:52:24 +0000148 }
149
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000150 // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
151 ClearNextBranchBreakpoint();
152
Chris Lattner24943d22010-06-08 16:52:24 +0000153 if (new_plan == NULL)
154 m_no_more_plans = true;
155 else
156 m_no_more_plans = false;
157
158 if (new_plan == NULL)
159 {
160 // For efficiencies sake, we know we're done here so we don't have to do this
161 // calculation again in MischiefManaged.
162 SetPlanComplete();
163 return true;
164 }
165 else
166 return false;
167}
Jim Ingham707b7a82012-05-01 18:38:37 +0000168
169bool
170ThreadPlanStepOverRange::PlanExplainsStop ()
171{
172 // For crashes, breakpoint hits, signals, etc, let the base plan (or some plan above us)
173 // handle the stop. That way the user can see the stop, step around, and then when they
174 // are done, continue and have their step complete. The exception is if we've hit our
175 // "run to next branch" breakpoint.
176 // Note, unlike the step in range plan, we don't mark ourselves complete if we hit an
177 // unexplained breakpoint/crash.
178
179 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
180 StopInfoSP stop_info_sp = GetPrivateStopReason();
181 if (stop_info_sp)
182 {
183 StopReason reason = stop_info_sp->GetStopReason();
184
185 switch (reason)
186 {
187 case eStopReasonBreakpoint:
188 if (NextRangeBreakpointExplainsStop(stop_info_sp))
189 return true;
190 else
191 return false;
192 break;
193 case eStopReasonWatchpoint:
194 case eStopReasonSignal:
195 case eStopReasonException:
196 if (log)
197 log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step.");
198 return false;
199 break;
200 default:
201 break;
202 }
203 }
204 return true;
205}