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