blob: 2d6f0309b91662f9057a9e1cbbb136184aaa53ac [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"
22#include "lldb/Target/Thread.h"
23#include "lldb/Target/ThreadPlanStepOut.h"
24#include "lldb/Target/ThreadPlanStepThrough.h"
25
26using namespace lldb_private;
Greg Claytone005f2c2010-11-06 01:53:30 +000027using namespace lldb;
Chris Lattner24943d22010-06-08 16:52:24 +000028
29
30//----------------------------------------------------------------------
31// ThreadPlanStepOverRange: Step through a stack range, either stepping over or into
32// based on the value of \a type.
33//----------------------------------------------------------------------
34
35ThreadPlanStepOverRange::ThreadPlanStepOverRange
36(
37 Thread &thread,
38 const AddressRange &range,
39 const SymbolContext &addr_context,
40 lldb::RunMode stop_others,
41 bool okay_to_discard
42) :
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{
45 SetOkayToDiscard (okay_to_discard);
46}
47
48ThreadPlanStepOverRange::~ThreadPlanStepOverRange ()
49{
50}
51
52void
53ThreadPlanStepOverRange::GetDescription (Stream *s, lldb::DescriptionLevel level)
54{
55 if (level == lldb::eDescriptionLevelBrief)
56 s->Printf("step over");
57 else
58 {
59 s->Printf ("stepping through range (stepping over functions): ");
Greg Claytoneea26402010-09-14 23:36:40 +000060 m_address_range.Dump (s, &m_thread.GetProcess().GetTarget(), Address::DumpStyleLoadAddress);
Chris Lattner24943d22010-06-08 16:52:24 +000061 }
62}
63
64bool
65ThreadPlanStepOverRange::ShouldStop (Event *event_ptr)
66{
Greg Claytone005f2c2010-11-06 01:53:30 +000067 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +000068
69 if (log)
70 {
71 StreamString s;
72 s.Address (m_thread.GetRegisterContext()->GetPC(), m_thread.GetProcess().GetAddressByteSize());
73 log->Printf("ThreadPlanStepOverRange reached %s.", s.GetData());
74 }
75
76 // If we're still in the range, keep going.
77 if (InRange())
78 return false;
79
80 // If we're out of the range but in the same frame or in our caller's frame
81 // then we should stop.
82 // When stepping out we only step if we are forcing running one thread.
83 bool stop_others;
84 if (m_stop_others == lldb::eOnlyThisThread)
85 stop_others = true;
86 else
87 stop_others = false;
88
89 ThreadPlan* new_plan = NULL;
90
91 if (FrameIsOlder())
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 }
Chris Lattner24943d22010-06-08 16:52:24 +0000105 else if (FrameIsYounger())
106 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000107 new_plan = m_thread.QueueThreadPlanForStepOut (false,
108 NULL,
109 true,
110 stop_others,
111 lldb::eVoteNo,
112 lldb::eVoteNoOpinion,
113 0);
Chris Lattner24943d22010-06-08 16:52:24 +0000114 }
115 else if (!InSymbol())
116 {
117 // This one is a little tricky. Sometimes we may be in a stub or something similar,
118 // in which case we need to get out of there. But if we are in a stub then it's
119 // likely going to be hard to get out from here. It is probably easiest to step into the
120 // stub, and then it will be straight-forward to step out.
121 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
122 }
123
124 if (new_plan == NULL)
125 m_no_more_plans = true;
126 else
127 m_no_more_plans = false;
128
129 if (new_plan == NULL)
130 {
131 // For efficiencies sake, we know we're done here so we don't have to do this
132 // calculation again in MischiefManaged.
133 SetPlanComplete();
134 return true;
135 }
136 else
137 return false;
138}