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