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, |
| 41 | lldb::RunMode stop_others, |
| 42 | bool okay_to_discard |
| 43 | ) : |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 44 | 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] | 45 | { |
Jim Ingham | 2bcbaf6 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 46 | // Step over range plans can be master plans, since you could hit a breakpoint while stepping over, step around |
| 47 | // a bit, then continue to finish up the step over. |
| 48 | SetIsMasterPlan (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | SetOkayToDiscard (okay_to_discard); |
| 50 | } |
| 51 | |
| 52 | ThreadPlanStepOverRange::~ThreadPlanStepOverRange () |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | ThreadPlanStepOverRange::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 58 | { |
| 59 | if (level == lldb::eDescriptionLevelBrief) |
| 60 | s->Printf("step over"); |
| 61 | else |
| 62 | { |
| 63 | s->Printf ("stepping through range (stepping over functions): "); |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 64 | DumpRanges(s); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | bool |
| 69 | ThreadPlanStepOverRange::ShouldStop (Event *event_ptr) |
| 70 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 71 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | |
| 73 | if (log) |
| 74 | { |
| 75 | StreamString s; |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 76 | s.Address (m_thread.GetRegisterContext()->GetPC(), |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 77 | m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | log->Printf("ThreadPlanStepOverRange reached %s.", s.GetData()); |
| 79 | } |
| 80 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | // If we're out of the range but in the same frame or in our caller's frame |
| 82 | // then we should stop. |
| 83 | // When stepping out we only step if we are forcing running one thread. |
| 84 | bool stop_others; |
| 85 | if (m_stop_others == lldb::eOnlyThisThread) |
| 86 | stop_others = true; |
| 87 | else |
| 88 | stop_others = false; |
| 89 | |
| 90 | ThreadPlan* new_plan = NULL; |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 91 | |
| 92 | FrameComparison frame_order = CompareCurrentFrameToStartFrame(); |
| 93 | |
| 94 | if (frame_order == eFrameCompareOlder) |
Jim Ingham | 4f385f1 | 2010-11-05 00:18:21 +0000 | [diff] [blame] | 95 | { |
| 96 | // If we're in an older frame then we should stop. |
| 97 | // |
| 98 | // A caveat to this is if we think the frame is older but we're actually in a trampoline. |
| 99 | // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are |
| 100 | // in a trampoline we think the frame is older because the trampoline confused the backtracer. |
| 101 | // As below, we step through first, and then try to figure out how to get back out again. |
| 102 | |
| 103 | new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others); |
| 104 | |
| 105 | if (new_plan != NULL && log) |
| 106 | log->Printf("Thought I stepped out, but in fact arrived at a trampoline."); |
| 107 | } |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 108 | else if (frame_order == eFrameCompareYounger) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 110 | // Make sure we really are in a new frame. Do that by unwinding and seeing if the |
| 111 | // start function really is our start function... |
| 112 | StackFrameSP older_frame_sp = m_thread.GetStackFrameAtIndex(1); |
| 113 | |
| 114 | // But if we can't even unwind one frame we should just get out of here & stop... |
| 115 | if (older_frame_sp) |
| 116 | { |
| 117 | const SymbolContext &older_context = older_frame_sp->GetSymbolContext(eSymbolContextEverything); |
| 118 | if (older_context == m_addr_context) |
| 119 | { |
| 120 | new_plan = m_thread.QueueThreadPlanForStepOut (false, |
| 121 | NULL, |
| 122 | true, |
| 123 | stop_others, |
| 124 | eVoteNo, |
| 125 | eVoteNoOpinion, |
| 126 | 0); |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others); |
| 131 | |
| 132 | } |
| 133 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | } |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 135 | else |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | { |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 137 | // If we're still in the range, keep going. |
| 138 | if (InRange()) |
| 139 | { |
| 140 | SetNextBranchBreakpoint(); |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | if (!InSymbol()) |
| 146 | { |
| 147 | // This one is a little tricky. Sometimes we may be in a stub or something similar, |
| 148 | // in which case we need to get out of there. But if we are in a stub then it's |
| 149 | // likely going to be hard to get out from here. It is probably easiest to step into the |
| 150 | // stub, and then it will be straight-forward to step out. |
| 151 | new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others); |
| 152 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 155 | // If we get to this point, we're not going to use a previously set "next branch" breakpoint, so delete it: |
| 156 | ClearNextBranchBreakpoint(); |
| 157 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | if (new_plan == NULL) |
| 159 | m_no_more_plans = true; |
| 160 | else |
| 161 | m_no_more_plans = false; |
| 162 | |
| 163 | if (new_plan == NULL) |
| 164 | { |
| 165 | // For efficiencies sake, we know we're done here so we don't have to do this |
| 166 | // calculation again in MischiefManaged. |
| 167 | SetPlanComplete(); |
| 168 | return true; |
| 169 | } |
| 170 | else |
| 171 | return false; |
| 172 | } |