blob: 08d9e4c721014a52c65cd2a174deffa09815728c [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
Jim Ingham038fa8e2012-05-10 01:35:39 +000098 new_plan = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
Jim Ingham4f385f12010-11-05 00:18:21 +000099
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);
Jim Inghamc3ba2af2012-07-26 18:23:21 +0000113
114 // Match as much as is specified in the m_addr_context:
115 // This is a fairly loose sanity check. Note, sometimes the target doesn't get filled
116 // in so I left out the target check. And sometimes the module comes in as the .o file from the
117 // inlined range, so I left that out too...
118
119 bool older_ctx_is_equivalent = false;
120 if (m_addr_context.comp_unit)
121 {
122 if (m_addr_context.comp_unit == older_context.comp_unit)
123 {
124 if (m_addr_context.function && m_addr_context.function == older_context.function)
125 {
126 if (m_addr_context.block && m_addr_context.block == older_context.block)
127 {
128 older_ctx_is_equivalent = true;
129 if (m_addr_context.line_entry.IsValid() && LineEntry::Compare(m_addr_context.line_entry, older_context.line_entry) != 0)
130 {
131 older_ctx_is_equivalent = false;
132 }
133 }
134 }
135 }
136 }
137 else if (m_addr_context.symbol && m_addr_context.symbol == older_context.symbol)
138 {
139 older_ctx_is_equivalent = true;
140 }
141
142 if (older_ctx_is_equivalent)
Jim Ingham441e3b92012-03-01 00:50:50 +0000143 {
144 new_plan = m_thread.QueueThreadPlanForStepOut (false,
145 NULL,
146 true,
147 stop_others,
148 eVoteNo,
149 eVoteNoOpinion,
150 0);
151 }
152 else
153 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000154 new_plan = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
Jim Ingham441e3b92012-03-01 00:50:50 +0000155
156 }
157 }
Chris Lattner24943d22010-06-08 16:52:24 +0000158 }
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000159 else
Chris Lattner24943d22010-06-08 16:52:24 +0000160 {
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000161 // If we're still in the range, keep going.
162 if (InRange())
163 {
164 SetNextBranchBreakpoint();
165 return false;
166 }
167
168
169 if (!InSymbol())
170 {
171 // This one is a little tricky. Sometimes we may be in a stub or something similar,
172 // in which case we need to get out of there. But if we are in a stub then it's
173 // likely going to be hard to get out from here. It is probably easiest to step into the
174 // stub, and then it will be straight-forward to step out.
Jim Ingham038fa8e2012-05-10 01:35:39 +0000175 new_plan = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others);
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000176 }
Chris Lattner24943d22010-06-08 16:52:24 +0000177 }
178
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000179 // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
180 ClearNextBranchBreakpoint();
181
Chris Lattner24943d22010-06-08 16:52:24 +0000182 if (new_plan == NULL)
183 m_no_more_plans = true;
184 else
185 m_no_more_plans = false;
186
187 if (new_plan == NULL)
188 {
189 // For efficiencies sake, we know we're done here so we don't have to do this
190 // calculation again in MischiefManaged.
191 SetPlanComplete();
192 return true;
193 }
194 else
195 return false;
196}
Jim Ingham707b7a82012-05-01 18:38:37 +0000197
198bool
199ThreadPlanStepOverRange::PlanExplainsStop ()
200{
201 // For crashes, breakpoint hits, signals, etc, let the base plan (or some plan above us)
202 // handle the stop. That way the user can see the stop, step around, and then when they
203 // are done, continue and have their step complete. The exception is if we've hit our
204 // "run to next branch" breakpoint.
205 // Note, unlike the step in range plan, we don't mark ourselves complete if we hit an
206 // unexplained breakpoint/crash.
207
208 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
209 StopInfoSP stop_info_sp = GetPrivateStopReason();
210 if (stop_info_sp)
211 {
212 StopReason reason = stop_info_sp->GetStopReason();
213
214 switch (reason)
215 {
216 case eStopReasonBreakpoint:
217 if (NextRangeBreakpointExplainsStop(stop_info_sp))
218 return true;
219 else
220 return false;
221 break;
222 case eStopReasonWatchpoint:
223 case eStopReasonSignal:
224 case eStopReasonException:
225 if (log)
226 log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step.");
227 return false;
228 break;
229 default:
230 break;
231 }
232 }
233 return true;
234}