Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/Symbol.h" |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/Function.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Process.h" |
| 23 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Thread.h" |
| 26 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 27 | #include "lldb/Target/ThreadPlanStepThrough.h" |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 28 | #include "lldb/Core/RegularExpression.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
| 33 | uint32_t ThreadPlanStepInRange::s_default_flag_values = ThreadPlanShouldStopHere::eAvoidNoDebug; |
| 34 | |
| 35 | //---------------------------------------------------------------------- |
| 36 | // ThreadPlanStepInRange: Step through a stack range, either stepping over or into |
| 37 | // based on the value of \a type. |
| 38 | //---------------------------------------------------------------------- |
| 39 | |
| 40 | ThreadPlanStepInRange::ThreadPlanStepInRange |
| 41 | ( |
| 42 | Thread &thread, |
| 43 | const AddressRange &range, |
| 44 | const SymbolContext &addr_context, |
| 45 | lldb::RunMode stop_others |
| 46 | ) : |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 47 | ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others), |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 48 | ThreadPlanShouldStopHere (this, ThreadPlanStepInRange::DefaultShouldStopHereCallback, NULL), |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 49 | m_step_past_prologue (true), |
| 50 | m_virtual_step (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | { |
| 52 | SetFlagsToDefault (); |
| 53 | } |
| 54 | |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 55 | ThreadPlanStepInRange::ThreadPlanStepInRange |
| 56 | ( |
| 57 | Thread &thread, |
| 58 | const AddressRange &range, |
| 59 | const SymbolContext &addr_context, |
| 60 | const char *step_into_target, |
| 61 | lldb::RunMode stop_others |
| 62 | ) : |
| 63 | ThreadPlanStepRange (ThreadPlan::eKindStepInRange, "Step Range stepping in", thread, range, addr_context, stop_others), |
| 64 | ThreadPlanShouldStopHere (this, ThreadPlanStepInRange::DefaultShouldStopHereCallback, NULL), |
| 65 | m_step_past_prologue (true), |
| 66 | m_virtual_step (false), |
| 67 | m_step_into_target (step_into_target) |
| 68 | { |
| 69 | SetFlagsToDefault (); |
| 70 | } |
| 71 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | ThreadPlanStepInRange::~ThreadPlanStepInRange () |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | ThreadPlanStepInRange::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 78 | { |
| 79 | if (level == lldb::eDescriptionLevelBrief) |
| 80 | s->Printf("step in"); |
| 81 | else |
| 82 | { |
| 83 | s->Printf ("Stepping through range (stepping into functions): "); |
Jim Ingham | c4c9fed | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 84 | DumpRanges(s); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 85 | const char *step_into_target = m_step_into_target.AsCString(); |
| 86 | if (step_into_target && step_into_target[0] != '\0') |
| 87 | s->Printf (" targeting %s.", m_step_into_target.AsCString()); |
| 88 | else |
| 89 | s->PutChar('.'); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | bool |
| 94 | ThreadPlanStepInRange::ShouldStop (Event *event_ptr) |
| 95 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 96 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | |
| 98 | if (log) |
| 99 | { |
| 100 | StreamString s; |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 101 | s.Address (m_thread.GetRegisterContext()->GetPC(), |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 102 | m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | log->Printf("ThreadPlanStepInRange reached %s.", s.GetData()); |
| 104 | } |
| 105 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 106 | if (IsPlanComplete()) |
| 107 | return true; |
| 108 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 109 | m_no_more_plans = false; |
| 110 | if (m_sub_plan_sp && m_sub_plan_sp->IsPlanComplete()) |
| 111 | { |
| 112 | if (!m_sub_plan_sp->PlanSucceeded()) |
| 113 | { |
| 114 | SetPlanComplete(); |
| 115 | m_no_more_plans = true; |
| 116 | return true; |
| 117 | } |
| 118 | else |
| 119 | m_sub_plan_sp.reset(); |
| 120 | } |
| 121 | |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 122 | if (m_virtual_step) |
Jim Ingham | 5822173 | 2010-11-05 00:18:21 +0000 | [diff] [blame] | 123 | { |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 124 | // If we've just completed a virtual step, all we need to do is check for a ShouldStopHere plan, and otherwise |
| 125 | // we're done. |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 126 | m_sub_plan_sp = InvokeShouldStopHereCallback(); |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 127 | } |
| 128 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | { |
Jim Ingham | 4a58e96 | 2012-10-25 22:30:09 +0000 | [diff] [blame] | 130 | // Stepping through should be done running other threads in general, since we're setting a breakpoint and |
| 131 | // continuing. So only stop others if we are explicitly told to do so. |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 132 | |
| 133 | bool stop_others; |
Jim Ingham | 4a58e96 | 2012-10-25 22:30:09 +0000 | [diff] [blame] | 134 | if (m_stop_others == lldb::eOnlyThisThread) |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 135 | stop_others = false; |
Jim Ingham | 4a58e96 | 2012-10-25 22:30:09 +0000 | [diff] [blame] | 136 | else |
| 137 | stop_others = true; |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 138 | |
| 139 | FrameComparison frame_order = CompareCurrentFrameToStartFrame(); |
| 140 | |
| 141 | if (frame_order == eFrameCompareOlder) |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 142 | { |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 143 | // If we're in an older frame then we should stop. |
| 144 | // |
| 145 | // A caveat to this is if we think the frame is older but we're actually in a trampoline. |
| 146 | // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are |
| 147 | // in a trampoline we think the frame is older because the trampoline confused the backtracer. |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 148 | m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others); |
| 149 | if (!m_sub_plan_sp) |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 150 | return true; |
| 151 | else if (log) |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 152 | { |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 153 | log->Printf("Thought I stepped out, but in fact arrived at a trampoline."); |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 154 | } |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 155 | |
| 156 | } |
| 157 | else if (frame_order == eFrameCompareEqual && InSymbol()) |
| 158 | { |
| 159 | // If we are not in a place we should step through, we're done. |
| 160 | // One tricky bit here is that some stubs don't push a frame, so we have to check |
| 161 | // both the case of a frame that is younger, or the same as this frame. |
| 162 | // However, if the frame is the same, and we are still in the symbol we started |
| 163 | // in, the we don't need to do this. This first check isn't strictly necessary, |
| 164 | // but it is more efficient. |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 165 | |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 166 | // If we're still in the range, keep going, either by running to the next branch breakpoint, or by |
| 167 | // stepping. |
| 168 | if (InRange()) |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 169 | { |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 170 | SetNextBranchBreakpoint(); |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | SetPlanComplete(); |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 175 | m_no_more_plans = true; |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 176 | return true; |
| 177 | } |
| 178 | |
| 179 | // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it: |
| 180 | ClearNextBranchBreakpoint(); |
| 181 | |
| 182 | // We may have set the plan up above in the FrameIsOlder section: |
| 183 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 184 | if (!m_sub_plan_sp) |
| 185 | m_sub_plan_sp = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others); |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 186 | |
| 187 | if (log) |
| 188 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 189 | if (m_sub_plan_sp) |
| 190 | log->Printf ("Found a step through plan: %s", m_sub_plan_sp->GetName()); |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 191 | else |
| 192 | log->Printf ("No step through plan found."); |
| 193 | } |
| 194 | |
| 195 | // If not, give the "should_stop" callback a chance to push a plan to get us out of here. |
| 196 | // But only do that if we actually have stepped in. |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 197 | if (!m_sub_plan_sp && frame_order == eFrameCompareYounger) |
| 198 | m_sub_plan_sp = InvokeShouldStopHereCallback(); |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 199 | |
| 200 | // If we've stepped in and we are going to stop here, check to see if we were asked to |
| 201 | // run past the prologue, and if so do that. |
| 202 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 203 | if (!m_sub_plan_sp && frame_order == eFrameCompareYounger && m_step_past_prologue) |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 204 | { |
| 205 | lldb::StackFrameSP curr_frame = m_thread.GetStackFrameAtIndex(0); |
| 206 | if (curr_frame) |
| 207 | { |
| 208 | size_t bytes_to_skip = 0; |
| 209 | lldb::addr_t curr_addr = m_thread.GetRegisterContext()->GetPC(); |
| 210 | Address func_start_address; |
| 211 | |
| 212 | SymbolContext sc = curr_frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextSymbol); |
| 213 | |
| 214 | if (sc.function) |
| 215 | { |
| 216 | func_start_address = sc.function->GetAddressRange().GetBaseAddress(); |
| 217 | if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get())) |
| 218 | bytes_to_skip = sc.function->GetPrologueByteSize(); |
| 219 | } |
| 220 | else if (sc.symbol) |
| 221 | { |
| 222 | func_start_address = sc.symbol->GetAddress(); |
| 223 | if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get())) |
| 224 | bytes_to_skip = sc.symbol->GetPrologueByteSize(); |
| 225 | } |
| 226 | |
| 227 | if (bytes_to_skip != 0) |
| 228 | { |
| 229 | func_start_address.Slide (bytes_to_skip); |
| 230 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP); |
| 231 | if (log) |
| 232 | log->Printf ("Pushing past prologue "); |
| 233 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 234 | m_sub_plan_sp = m_thread.QueueThreadPlanForRunToAddress(false, func_start_address,true); |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 235 | } |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 236 | } |
| 237 | } |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 238 | } |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 239 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 240 | if (!m_sub_plan_sp) |
Jim Ingham | 7ce490c | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 241 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | m_no_more_plans = true; |
| 243 | SetPlanComplete(); |
| 244 | return true; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | m_no_more_plans = false; |
| 249 | return false; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void |
| 254 | ThreadPlanStepInRange::SetFlagsToDefault () |
| 255 | { |
| 256 | GetFlags().Set(ThreadPlanStepInRange::s_default_flag_values); |
| 257 | } |
| 258 | |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 259 | void |
| 260 | ThreadPlanStepInRange::SetAvoidRegexp(const char *name) |
| 261 | { |
| 262 | if (m_avoid_regexp_ap.get() == NULL) |
| 263 | m_avoid_regexp_ap.reset (new RegularExpression(name)); |
| 264 | |
| 265 | m_avoid_regexp_ap->Compile (name); |
| 266 | } |
| 267 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | void |
| 269 | ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value) |
| 270 | { |
| 271 | // TODO: Should we test this for sanity? |
| 272 | ThreadPlanStepInRange::s_default_flag_values = new_value; |
| 273 | } |
| 274 | |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 275 | bool |
| 276 | ThreadPlanStepInRange::FrameMatchesAvoidRegexp () |
| 277 | { |
| 278 | StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get(); |
| 279 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 280 | const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get(); |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 281 | if (avoid_regexp_to_use == NULL) |
| 282 | avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp(); |
| 283 | |
| 284 | if (avoid_regexp_to_use != NULL) |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 285 | { |
Greg Clayton | 4592cbc | 2012-07-13 00:19:40 +0000 | [diff] [blame] | 286 | SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol); |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 287 | if (sc.symbol != NULL) |
| 288 | { |
Greg Clayton | 4592cbc | 2012-07-13 00:19:40 +0000 | [diff] [blame] | 289 | const char *frame_function_name = sc.GetFunctionName().GetCString(); |
| 290 | if (frame_function_name) |
Jim Ingham | 3101ba3 | 2013-03-14 21:44:36 +0000 | [diff] [blame] | 291 | { |
Jim Ingham | cf2667c | 2013-03-14 22:00:18 +0000 | [diff] [blame] | 292 | size_t num_matches = 0; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 293 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | cf2667c | 2013-03-14 22:00:18 +0000 | [diff] [blame] | 294 | if (log) |
| 295 | num_matches = 1; |
Greg Clayton | bc43cab | 2013-04-03 21:37:16 +0000 | [diff] [blame] | 296 | |
| 297 | RegularExpression::Match regex_match(num_matches); |
| 298 | |
| 299 | bool return_value = avoid_regexp_to_use->Execute(frame_function_name, ®ex_match); |
Jim Ingham | 3101ba3 | 2013-03-14 21:44:36 +0000 | [diff] [blame] | 300 | if (return_value) |
| 301 | { |
Jim Ingham | 3101ba3 | 2013-03-14 21:44:36 +0000 | [diff] [blame] | 302 | if (log) |
Jim Ingham | cf2667c | 2013-03-14 22:00:18 +0000 | [diff] [blame] | 303 | { |
| 304 | std::string match; |
Greg Clayton | bc43cab | 2013-04-03 21:37:16 +0000 | [diff] [blame] | 305 | regex_match.GetMatchAtIndex(frame_function_name,0, match); |
Jim Ingham | cf2667c | 2013-03-14 22:00:18 +0000 | [diff] [blame] | 306 | log->Printf ("Stepping out of function \"%s\" because it matches the avoid regexp \"%s\" - match substring: \"%s\".", |
Jim Ingham | 3101ba3 | 2013-03-14 21:44:36 +0000 | [diff] [blame] | 307 | frame_function_name, |
Jim Ingham | cf2667c | 2013-03-14 22:00:18 +0000 | [diff] [blame] | 308 | avoid_regexp_to_use->GetText(), |
| 309 | match.c_str()); |
| 310 | } |
Jim Ingham | 3101ba3 | 2013-03-14 21:44:36 +0000 | [diff] [blame] | 311 | |
| 312 | } |
| 313 | return return_value; |
| 314 | } |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | return false; |
| 318 | } |
| 319 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 320 | ThreadPlanSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 321 | ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan, Flags &flags, void *baton) |
| 322 | { |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 323 | bool should_step_out = false; |
| 324 | StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get(); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 325 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 326 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 327 | if (flags.Test(eAvoidNoDebug)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | if (!frame->HasDebugInformation()) |
Jim Ingham | af0f175 | 2010-09-15 00:06:51 +0000 | [diff] [blame] | 330 | { |
| 331 | if (log) |
| 332 | log->Printf ("Stepping out of frame with no debug info"); |
| 333 | |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 334 | should_step_out = true; |
Jim Ingham | af0f175 | 2010-09-15 00:06:51 +0000 | [diff] [blame] | 335 | } |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 338 | if (current_plan->GetKind() == eKindStepInRange) |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 339 | { |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 340 | ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan); |
| 341 | if (step_in_range_plan->m_step_into_target) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 342 | { |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 343 | SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock|eSymbolContextSymbol); |
| 344 | if (sc.symbol != NULL) |
| 345 | { |
| 346 | // First try an exact match, since that's cheap with ConstStrings. Then do a strstr compare. |
| 347 | if (step_in_range_plan->m_step_into_target == sc.GetFunctionName()) |
| 348 | { |
| 349 | should_step_out = false; |
| 350 | } |
| 351 | else |
| 352 | { |
| 353 | const char *target_name = step_in_range_plan->m_step_into_target.AsCString(); |
| 354 | const char *function_name = sc.GetFunctionName().AsCString(); |
| 355 | |
| 356 | if (function_name == NULL) |
| 357 | should_step_out = true; |
| 358 | else if (strstr (function_name, target_name) == NULL) |
| 359 | should_step_out = true; |
| 360 | } |
Jim Ingham | 3101ba3 | 2013-03-14 21:44:36 +0000 | [diff] [blame] | 361 | if (log && should_step_out) |
| 362 | log->Printf("Stepping out of frame %s which did not match step into target %s.", |
| 363 | sc.GetFunctionName().AsCString(), |
| 364 | step_in_range_plan->m_step_into_target.AsCString()); |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
| 368 | if (!should_step_out) |
| 369 | { |
Jim Ingham | 3101ba3 | 2013-03-14 21:44:36 +0000 | [diff] [blame] | 370 | ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan); |
| 371 | // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidRegexp. |
| 372 | should_step_out = step_in_range_plan->FrameMatchesAvoidRegexp (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 375 | |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 376 | |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 377 | if (should_step_out) |
| 378 | { |
| 379 | // FIXME: Make sure the ThreadPlanForStepOut does the right thing with inlined functions. |
Jim Ingham | 4a58e96 | 2012-10-25 22:30:09 +0000 | [diff] [blame] | 380 | // We really should have all plans take the tri-state for "stop others" so we can do the right |
| 381 | // thing. For now let's be safe and always run others when we are likely to run arbitrary code. |
| 382 | const bool stop_others = false; |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 383 | return current_plan->GetThread().QueueThreadPlanForStepOut (false, |
| 384 | NULL, |
| 385 | true, |
Jim Ingham | 4a58e96 | 2012-10-25 22:30:09 +0000 | [diff] [blame] | 386 | stop_others, |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 387 | eVoteNo, |
| 388 | eVoteNoOpinion, |
| 389 | 0); // Frame index |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 390 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame^] | 392 | return ThreadPlanSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | } |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 394 | |
| 395 | bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 396 | ThreadPlanStepInRange::DoPlanExplainsStop (Event *event_ptr) |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 397 | { |
| 398 | // We always explain a stop. Either we've just done a single step, in which |
| 399 | // case we'll do our ordinary processing, or we stopped for some |
| 400 | // reason that isn't handled by our sub-plans, in which case we want to just stop right |
| 401 | // away. |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 402 | // In general, we don't want to mark the plan as complete for unexplained stops. |
| 403 | // For instance, if you step in to some code with no debug info, so you step out |
| 404 | // and in the course of that hit a breakpoint, then you want to stop & show the user |
| 405 | // the breakpoint, but not unship the step in plan, since you still may want to complete that |
| 406 | // plan when you continue. This is particularly true when doing "step in to target function." |
| 407 | // stepping. |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 408 | // |
| 409 | // The only variation is that if we are doing "step by running to next branch" in which case |
| 410 | // if we hit our branch breakpoint we don't set the plan to complete. |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 411 | |
| 412 | bool return_value; |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 413 | |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 414 | if (m_virtual_step) |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 415 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 416 | return_value = true; |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 417 | } |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 418 | else |
| 419 | { |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 420 | StopInfoSP stop_info_sp = GetPrivateStopInfo (); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 421 | if (stop_info_sp) |
| 422 | { |
| 423 | StopReason reason = stop_info_sp->GetStopReason(); |
| 424 | |
| 425 | switch (reason) |
| 426 | { |
| 427 | case eStopReasonBreakpoint: |
| 428 | if (NextRangeBreakpointExplainsStop(stop_info_sp)) |
| 429 | { |
| 430 | return_value = true; |
| 431 | break; |
| 432 | } |
| 433 | case eStopReasonWatchpoint: |
| 434 | case eStopReasonSignal: |
| 435 | case eStopReasonException: |
| 436 | case eStopReasonExec: |
| 437 | case eStopReasonThreadExiting: |
| 438 | { |
| 439 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 440 | if (log) |
| 441 | log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step."); |
| 442 | } |
| 443 | return_value = false; |
| 444 | break; |
| 445 | default: |
| 446 | return_value = true; |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | else |
| 451 | return_value = true; |
| 452 | } |
| 453 | |
| 454 | return return_value; |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 455 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 456 | |
| 457 | bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 458 | ThreadPlanStepInRange::DoWillResume (lldb::StateType resume_state, bool current_plan) |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 459 | { |
| 460 | if (resume_state == eStateStepping && current_plan) |
| 461 | { |
| 462 | // See if we are about to step over a virtual inlined call. |
| 463 | bool step_without_resume = m_thread.DecrementCurrentInlinedDepth(); |
| 464 | if (step_without_resume) |
| 465 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 466 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 467 | if (log) |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 468 | log->Printf ("ThreadPlanStepInRange::DoWillResume: returning false, inline_depth: %d", |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 469 | m_thread.GetCurrentInlinedDepth()); |
| 470 | SetStopInfo(StopInfo::CreateStopReasonToTrace(m_thread)); |
Jim Ingham | f02a2e9 | 2012-09-07 01:11:44 +0000 | [diff] [blame] | 471 | |
| 472 | // FIXME: Maybe it would be better to create a InlineStep stop reason, but then |
| 473 | // the whole rest of the world would have to handle that stop reason. |
| 474 | m_virtual_step = true; |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 475 | } |
| 476 | return !step_without_resume; |
| 477 | } |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 478 | return true; |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 479 | } |
Daniel Malea | 246cb61 | 2013-05-14 15:20:12 +0000 | [diff] [blame] | 480 | |
| 481 | bool |
| 482 | ThreadPlanStepInRange::IsVirtualStep() |
| 483 | { |
| 484 | return m_virtual_step; |
| 485 | } |