blob: 54fe8ea62a8de0d71c268c2e63be5fce5f1aafe9 [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,
41 lldb::RunMode stop_others,
42 bool okay_to_discard
43) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000044 ThreadPlanStepRange (ThreadPlan::eKindStepOverRange, "Step range stepping over", thread, range, addr_context, stop_others)
Chris Lattner24943d22010-06-08 16:52:24 +000045{
46 SetOkayToDiscard (okay_to_discard);
47}
48
49ThreadPlanStepOverRange::~ThreadPlanStepOverRange ()
50{
51}
52
53void
54ThreadPlanStepOverRange::GetDescription (Stream *s, lldb::DescriptionLevel level)
55{
56 if (level == lldb::eDescriptionLevelBrief)
57 s->Printf("step over");
58 else
59 {
60 s->Printf ("stepping through range (stepping over functions): ");
Jim Ingham76e55f72011-10-15 00:24:48 +000061 DumpRanges(s);
Chris Lattner24943d22010-06-08 16:52:24 +000062 }
63}
64
65bool
66ThreadPlanStepOverRange::ShouldStop (Event *event_ptr)
67{
Greg Claytone005f2c2010-11-06 01:53:30 +000068 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +000069
70 if (log)
71 {
72 StreamString s;
Greg Clayton395fc332011-02-15 21:59:32 +000073 s.Address (m_thread.GetRegisterContext()->GetPC(),
Greg Claytonf4124de2012-02-21 00:09:25 +000074 m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +000075 log->Printf("ThreadPlanStepOverRange reached %s.", s.GetData());
76 }
77
Chris Lattner24943d22010-06-08 16:52:24 +000078 // If we're out of the range but in the same frame or in our caller's frame
79 // then we should stop.
80 // When stepping out we only step if we are forcing running one thread.
81 bool stop_others;
82 if (m_stop_others == lldb::eOnlyThisThread)
83 stop_others = true;
84 else
85 stop_others = false;
86
87 ThreadPlan* new_plan = NULL;
Jim Ingham441e3b92012-03-01 00:50:50 +000088
89 FrameComparison frame_order = CompareCurrentFrameToStartFrame();
90
91 if (frame_order == eFrameCompareOlder)
Jim Ingham4f385f12010-11-05 00:18:21 +000092 {
93 // If we're in an older frame then we should stop.
94 //
95 // A caveat to this is if we think the frame is older but we're actually in a trampoline.
96 // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are
97 // in a trampoline we think the frame is older because the trampoline confused the backtracer.
98 // As below, we step through first, and then try to figure out how to get back out again.
99
100 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
101
102 if (new_plan != NULL && log)
103 log->Printf("Thought I stepped out, but in fact arrived at a trampoline.");
104 }
Jim Ingham441e3b92012-03-01 00:50:50 +0000105 else if (frame_order == eFrameCompareYounger)
Chris Lattner24943d22010-06-08 16:52:24 +0000106 {
Jim Ingham441e3b92012-03-01 00:50:50 +0000107 // Make sure we really are in a new frame. Do that by unwinding and seeing if the
108 // start function really is our start function...
109 StackFrameSP older_frame_sp = m_thread.GetStackFrameAtIndex(1);
110
111 // But if we can't even unwind one frame we should just get out of here & stop...
112 if (older_frame_sp)
113 {
114 const SymbolContext &older_context = older_frame_sp->GetSymbolContext(eSymbolContextEverything);
115 if (older_context == m_addr_context)
116 {
117 new_plan = m_thread.QueueThreadPlanForStepOut (false,
118 NULL,
119 true,
120 stop_others,
121 eVoteNo,
122 eVoteNoOpinion,
123 0);
124 }
125 else
126 {
127 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
128
129 }
130 }
Chris Lattner24943d22010-06-08 16:52:24 +0000131 }
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000132 else
Chris Lattner24943d22010-06-08 16:52:24 +0000133 {
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000134 // If we're still in the range, keep going.
135 if (InRange())
136 {
137 SetNextBranchBreakpoint();
138 return false;
139 }
140
141
142 if (!InSymbol())
143 {
144 // This one is a little tricky. Sometimes we may be in a stub or something similar,
145 // in which case we need to get out of there. But if we are in a stub then it's
146 // likely going to be hard to get out from here. It is probably easiest to step into the
147 // stub, and then it will be straight-forward to step out.
148 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
149 }
Chris Lattner24943d22010-06-08 16:52:24 +0000150 }
151
Jim Inghamb2cf58a2012-03-09 04:10:47 +0000152 // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it:
153 ClearNextBranchBreakpoint();
154
Chris Lattner24943d22010-06-08 16:52:24 +0000155 if (new_plan == NULL)
156 m_no_more_plans = true;
157 else
158 m_no_more_plans = false;
159
160 if (new_plan == NULL)
161 {
162 // For efficiencies sake, we know we're done here so we don't have to do this
163 // calculation again in MischiefManaged.
164 SetPlanComplete();
165 return true;
166 }
167 else
168 return false;
169}