Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanStepOverRange.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/ThreadPlanStepOverRange.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | |
| 17 | #include "lldb/lldb-private-log.h" |
| 18 | #include "lldb/Core/Log.h" |
| 19 | #include "lldb/Core/Stream.h" |
| 20 | #include "lldb/Target/Process.h" |
| 21 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 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" |
| 26 | |
| 27 | using namespace lldb_private; |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 28 | using namespace lldb; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | |
| 30 | |
| 31 | //---------------------------------------------------------------------- |
| 32 | // ThreadPlanStepOverRange: Step through a stack range, either stepping over or into |
| 33 | // based on the value of \a type. |
| 34 | //---------------------------------------------------------------------- |
| 35 | |
| 36 | ThreadPlanStepOverRange::ThreadPlanStepOverRange |
| 37 | ( |
| 38 | Thread &thread, |
| 39 | const AddressRange &range, |
| 40 | const SymbolContext &addr_context, |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 41 | lldb::RunMode stop_others |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | ) : |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 43 | ThreadPlanStepRange (ThreadPlan::eKindStepOverRange, "Step range stepping over", thread, range, addr_context, stop_others) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ThreadPlanStepOverRange::~ThreadPlanStepOverRange () |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | ThreadPlanStepOverRange::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 53 | { |
| 54 | if (level == lldb::eDescriptionLevelBrief) |
| 55 | s->Printf("step over"); |
| 56 | else |
| 57 | { |
| 58 | s->Printf ("stepping through range (stepping over functions): "); |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 59 | DumpRanges(s); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | bool |
| 64 | ThreadPlanStepOverRange::ShouldStop (Event *event_ptr) |
| 65 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 66 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | |
| 68 | if (log) |
| 69 | { |
| 70 | StreamString s; |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 71 | s.Address (m_thread.GetRegisterContext()->GetPC(), |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 72 | m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | log->Printf("ThreadPlanStepOverRange reached %s.", s.GetData()); |
| 74 | } |
| 75 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | // If we're out of the range but in the same frame or in our caller's frame |
| 77 | // then we should stop. |
| 78 | // When stepping out we only step if we are forcing running one thread. |
| 79 | bool stop_others; |
| 80 | if (m_stop_others == lldb::eOnlyThisThread) |
| 81 | stop_others = true; |
| 82 | else |
| 83 | stop_others = false; |
| 84 | |
| 85 | ThreadPlan* new_plan = NULL; |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 86 | |
| 87 | FrameComparison frame_order = CompareCurrentFrameToStartFrame(); |
| 88 | |
| 89 | if (frame_order == eFrameCompareOlder) |
Jim Ingham | 4f385f1 | 2010-11-05 00:18:21 +0000 | [diff] [blame] | 90 | { |
| 91 | // If we're in an older frame then we should stop. |
| 92 | // |
| 93 | // A caveat to this is if we think the frame is older but we're actually in a trampoline. |
| 94 | // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are |
| 95 | // in a trampoline we think the frame is older because the trampoline confused the backtracer. |
| 96 | // As below, we step through first, and then try to figure out how to get back out again. |
| 97 | |
Jim Ingham | 038fa8e | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 98 | new_plan = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others); |
Jim Ingham | 4f385f1 | 2010-11-05 00:18:21 +0000 | [diff] [blame] | 99 | |
| 100 | if (new_plan != NULL && log) |
| 101 | log->Printf("Thought I stepped out, but in fact arrived at a trampoline."); |
| 102 | } |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 103 | else if (frame_order == eFrameCompareYounger) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 105 | // Make sure we really are in a new frame. Do that by unwinding and seeing if the |
| 106 | // start function really is our start function... |
| 107 | StackFrameSP older_frame_sp = m_thread.GetStackFrameAtIndex(1); |
| 108 | |
| 109 | // But if we can't even unwind one frame we should just get out of here & stop... |
| 110 | if (older_frame_sp) |
| 111 | { |
| 112 | const SymbolContext &older_context = older_frame_sp->GetSymbolContext(eSymbolContextEverything); |
Jim Ingham | c3ba2af | 2012-07-26 18:23:21 +0000 | [diff] [blame] | 113 | |
| 114 | // Match as much as is specified in the m_addr_context: |
| 115 | // This is a fairly loose sanity check. Note, sometimes the target doesn't get filled |
| 116 | // in so I left out the target check. And sometimes the module comes in as the .o file from the |
| 117 | // inlined range, so I left that out too... |
| 118 | |
| 119 | bool older_ctx_is_equivalent = false; |
| 120 | if (m_addr_context.comp_unit) |
| 121 | { |
| 122 | if (m_addr_context.comp_unit == older_context.comp_unit) |
| 123 | { |
| 124 | if (m_addr_context.function && m_addr_context.function == older_context.function) |
| 125 | { |
| 126 | if (m_addr_context.block && m_addr_context.block == older_context.block) |
| 127 | { |
| 128 | older_ctx_is_equivalent = true; |
| 129 | if (m_addr_context.line_entry.IsValid() && LineEntry::Compare(m_addr_context.line_entry, older_context.line_entry) != 0) |
| 130 | { |
| 131 | older_ctx_is_equivalent = false; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | else if (m_addr_context.symbol && m_addr_context.symbol == older_context.symbol) |
| 138 | { |
| 139 | older_ctx_is_equivalent = true; |
| 140 | } |
| 141 | |
| 142 | if (older_ctx_is_equivalent) |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 143 | { |
| 144 | new_plan = m_thread.QueueThreadPlanForStepOut (false, |
| 145 | NULL, |
| 146 | true, |
| 147 | stop_others, |
| 148 | eVoteNo, |
| 149 | eVoteNoOpinion, |
| 150 | 0); |
| 151 | } |
| 152 | else |
| 153 | { |
Jim Ingham | 038fa8e | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 154 | new_plan = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others); |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 155 | |
| 156 | } |
| 157 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | } |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 159 | else |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | { |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 161 | // If we're still in the range, keep going. |
| 162 | if (InRange()) |
| 163 | { |
| 164 | SetNextBranchBreakpoint(); |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | |
| 169 | if (!InSymbol()) |
| 170 | { |
| 171 | // This one is a little tricky. Sometimes we may be in a stub or something similar, |
| 172 | // in which case we need to get out of there. But if we are in a stub then it's |
| 173 | // likely going to be hard to get out from here. It is probably easiest to step into the |
| 174 | // stub, and then it will be straight-forward to step out. |
Jim Ingham | 038fa8e | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 175 | new_plan = m_thread.QueueThreadPlanForStepThrough (m_stack_id, false, stop_others); |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 176 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 179 | // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it: |
| 180 | ClearNextBranchBreakpoint(); |
| 181 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | if (new_plan == NULL) |
| 183 | m_no_more_plans = true; |
| 184 | else |
| 185 | m_no_more_plans = false; |
| 186 | |
| 187 | if (new_plan == NULL) |
| 188 | { |
| 189 | // For efficiencies sake, we know we're done here so we don't have to do this |
| 190 | // calculation again in MischiefManaged. |
| 191 | SetPlanComplete(); |
| 192 | return true; |
| 193 | } |
| 194 | else |
| 195 | return false; |
| 196 | } |
Jim Ingham | 707b7a8 | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 197 | |
| 198 | bool |
| 199 | ThreadPlanStepOverRange::PlanExplainsStop () |
| 200 | { |
| 201 | // For crashes, breakpoint hits, signals, etc, let the base plan (or some plan above us) |
| 202 | // handle the stop. That way the user can see the stop, step around, and then when they |
| 203 | // are done, continue and have their step complete. The exception is if we've hit our |
| 204 | // "run to next branch" breakpoint. |
| 205 | // Note, unlike the step in range plan, we don't mark ourselves complete if we hit an |
| 206 | // unexplained breakpoint/crash. |
| 207 | |
| 208 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 209 | StopInfoSP stop_info_sp = GetPrivateStopReason(); |
| 210 | if (stop_info_sp) |
| 211 | { |
| 212 | StopReason reason = stop_info_sp->GetStopReason(); |
| 213 | |
| 214 | switch (reason) |
| 215 | { |
| 216 | case eStopReasonBreakpoint: |
| 217 | if (NextRangeBreakpointExplainsStop(stop_info_sp)) |
| 218 | return true; |
| 219 | else |
| 220 | return false; |
| 221 | break; |
| 222 | case eStopReasonWatchpoint: |
| 223 | case eStopReasonSignal: |
| 224 | case eStopReasonException: |
| 225 | if (log) |
| 226 | log->PutCString ("ThreadPlanStepInRange got asked if it explains the stop for some reason other than step."); |
| 227 | return false; |
| 228 | break; |
| 229 | default: |
| 230 | break; |
| 231 | } |
| 232 | } |
| 233 | return true; |
| 234 | } |