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