blob: 58f61977ccdfe71fa894539a9604c842a64fa5fe [file] [log] [blame]
Chris Lattner24943d22010-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"
19#include "lldb/Core/Stream.h"
Jim Ingham809ab9b2010-07-10 02:27:39 +000020#include "lldb/Symbol/Symbol.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Target/Process.h"
22#include "lldb/Target/RegisterContext.h"
23#include "lldb/Target/Thread.h"
24#include "lldb/Target/ThreadPlanStepOut.h"
25#include "lldb/Target/ThreadPlanStepThrough.h"
Jim Ingham809ab9b2010-07-10 02:27:39 +000026#include "lldb/Core/RegularExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027
28using namespace lldb;
29using namespace lldb_private;
30
31uint32_t ThreadPlanStepInRange::s_default_flag_values = ThreadPlanShouldStopHere::eAvoidNoDebug;
32
33//----------------------------------------------------------------------
34// ThreadPlanStepInRange: Step through a stack range, either stepping over or into
35// based on the value of \a type.
36//----------------------------------------------------------------------
37
38ThreadPlanStepInRange::ThreadPlanStepInRange
39(
40 Thread &thread,
41 const AddressRange &range,
42 const SymbolContext &addr_context,
43 lldb::RunMode stop_others
44) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000045 ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others),
Chris Lattner24943d22010-06-08 16:52:24 +000046 ThreadPlanShouldStopHere (this, ThreadPlanStepInRange::DefaultShouldStopHereCallback, NULL)
47{
48 SetFlagsToDefault ();
Jim Ingham809ab9b2010-07-10 02:27:39 +000049 // SetAvoidRegexp("^std\\:\\:.*");
Chris Lattner24943d22010-06-08 16:52:24 +000050}
51
52ThreadPlanStepInRange::~ThreadPlanStepInRange ()
53{
54}
55
56void
57ThreadPlanStepInRange::GetDescription (Stream *s, lldb::DescriptionLevel level)
58{
59 if (level == lldb::eDescriptionLevelBrief)
60 s->Printf("step in");
61 else
62 {
63 s->Printf ("Stepping through range (stepping into functions): ");
64 m_address_range.Dump (s, &m_thread.GetProcess(), Address::DumpStyleLoadAddress);
65 }
66}
67
68bool
69ThreadPlanStepInRange::ShouldStop (Event *event_ptr)
70{
71 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
72 m_no_more_plans = false;
73
74 if (log)
75 {
76 StreamString s;
77 s.Address (m_thread.GetRegisterContext()->GetPC(), m_thread.GetProcess().GetAddressByteSize());
78 log->Printf("ThreadPlanStepInRange reached %s.", s.GetData());
79 }
80
81 // If we're still in the range, keep going.
82 if (InRange())
83 return false;
84
85 // If we're in an older frame then we should stop.
86 if (FrameIsOlder())
87 return true;
88
89 // See if we are in a place we should step through (i.e. a trampoline of some sort):
90 // One tricky bit here is that some stubs don't push a frame, so we have to check
91 // both the case of a frame that is younger, or the same as this frame.
92 // However, if the frame is the same, and we are still in the symbol we started
93 // in, the we don't need to do this. This first check isn't strictly necessary,
94 // but it is more efficient.
95
96 if (!FrameIsYounger() && InSymbol())
97 {
98 SetPlanComplete();
99 return true;
100 }
101
102 ThreadPlan* new_plan = NULL;
103
104 bool stop_others;
105 if (m_stop_others == lldb::eOnlyThisThread)
106 stop_others = true;
107 else
108 stop_others = false;
109
110 new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others);
111 // If not, give the "should_stop" callback a chance to push a plan to get us out of here.
112 // But only do that if we actually have stepped in.
113 if (!new_plan && FrameIsYounger())
114 new_plan = InvokeShouldStopHereCallback();
115
116 if (new_plan == NULL)
117 {
118 m_no_more_plans = true;
119 SetPlanComplete();
120 return true;
121 }
122 else
123 {
124 m_no_more_plans = false;
125 return false;
126 }
127}
128
129void
130ThreadPlanStepInRange::SetFlagsToDefault ()
131{
132 GetFlags().Set(ThreadPlanStepInRange::s_default_flag_values);
133}
134
Jim Ingham809ab9b2010-07-10 02:27:39 +0000135void
136ThreadPlanStepInRange::SetAvoidRegexp(const char *name)
137{
138 if (m_avoid_regexp_ap.get() == NULL)
139 m_avoid_regexp_ap.reset (new RegularExpression(name));
140
141 m_avoid_regexp_ap->Compile (name);
142}
143
Chris Lattner24943d22010-06-08 16:52:24 +0000144void
145ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value)
146{
147 // TODO: Should we test this for sanity?
148 ThreadPlanStepInRange::s_default_flag_values = new_value;
149}
150
Jim Ingham809ab9b2010-07-10 02:27:39 +0000151bool
152ThreadPlanStepInRange::FrameMatchesAvoidRegexp ()
153{
154 StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
155
156 if (m_avoid_regexp_ap.get() != NULL)
157 {
158 SymbolContext sc = frame->GetSymbolContext(eSymbolContextSymbol);
159 if (sc.symbol != NULL)
160 {
161 const char *unnamed_symbol = "<UNKNOWN>";
162 const char *sym_name = sc.symbol->GetMangled().GetName().AsCString(unnamed_symbol);
163 if (strcmp (sym_name, unnamed_symbol) != 0)
164 return m_avoid_regexp_ap->Execute(sym_name);
165 }
166 }
167 return false;
168}
169
Chris Lattner24943d22010-06-08 16:52:24 +0000170ThreadPlan *
171ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, void *baton)
172{
Jim Ingham809ab9b2010-07-10 02:27:39 +0000173 bool should_step_out = false;
174 StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get();
175
Chris Lattner24943d22010-06-08 16:52:24 +0000176 if (flags.IsSet(eAvoidNoDebug))
177 {
Chris Lattner24943d22010-06-08 16:52:24 +0000178 if (!frame->HasDebugInformation())
Jim Ingham809ab9b2010-07-10 02:27:39 +0000179 should_step_out = true;
180 }
181
182 if (!should_step_out)
183 {
184 if (current_plan->GetKind() == eKindStepInRange)
Chris Lattner24943d22010-06-08 16:52:24 +0000185 {
Jim Ingham809ab9b2010-07-10 02:27:39 +0000186 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
187 should_step_out = step_in_range_plan->FrameMatchesAvoidRegexp ();
Chris Lattner24943d22010-06-08 16:52:24 +0000188 }
189 }
Jim Ingham809ab9b2010-07-10 02:27:39 +0000190
191 if (should_step_out)
192 {
193 // FIXME: Make sure the ThreadPlanForStepOut does the right thing with inlined functions.
194 return current_plan->GetThread().QueueThreadPlanForStepOut (false, NULL, true,
195 current_plan->StopOthers(),
196 eVoteNo, eVoteNoOpinion);
197 }
Chris Lattner24943d22010-06-08 16:52:24 +0000198
199 return NULL;
200}