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 | { |
| 46 | SetOkayToDiscard (okay_to_discard); |
| 47 | } |
| 48 | |
| 49 | ThreadPlanStepOverRange::~ThreadPlanStepOverRange () |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | ThreadPlanStepOverRange::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 55 | { |
| 56 | if (level == lldb::eDescriptionLevelBrief) |
| 57 | s->Printf("step over"); |
| 58 | else |
| 59 | { |
| 60 | s->Printf ("stepping through range (stepping over functions): "); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 61 | m_address_range.Dump (s, &m_thread.GetProcess().GetTarget(), Address::DumpStyleLoadAddress); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | bool |
| 66 | ThreadPlanStepOverRange::ShouldStop (Event *event_ptr) |
| 67 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 68 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | |
| 70 | if (log) |
| 71 | { |
| 72 | StreamString s; |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 73 | s.Address (m_thread.GetRegisterContext()->GetPC(), |
| 74 | m_thread.GetProcess().GetTarget().GetArchitecture().GetAddressByteSize()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | log->Printf("ThreadPlanStepOverRange reached %s.", s.GetData()); |
| 76 | } |
| 77 | |
| 78 | // If we're still in the range, keep going. |
| 79 | if (InRange()) |
| 80 | return false; |
| 81 | |
| 82 | // If we're out of the range but in the same frame or in our caller's frame |
| 83 | // then we should stop. |
| 84 | // When stepping out we only step if we are forcing running one thread. |
| 85 | bool stop_others; |
| 86 | if (m_stop_others == lldb::eOnlyThisThread) |
| 87 | stop_others = true; |
| 88 | else |
| 89 | stop_others = false; |
| 90 | |
| 91 | ThreadPlan* new_plan = NULL; |
| 92 | |
| 93 | if (FrameIsOlder()) |
Jim Ingham | 4f385f1 | 2010-11-05 00:18:21 +0000 | [diff] [blame] | 94 | { |
| 95 | // If we're in an older frame then we should stop. |
| 96 | // |
| 97 | // A caveat to this is if we think the frame is older but we're actually in a trampoline. |
| 98 | // I'm going to make the assumption that you wouldn't RETURN to a trampoline. So if we are |
| 99 | // in a trampoline we think the frame is older because the trampoline confused the backtracer. |
| 100 | // As below, we step through first, and then try to figure out how to get back out again. |
| 101 | |
| 102 | new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others); |
| 103 | |
| 104 | if (new_plan != NULL && log) |
| 105 | log->Printf("Thought I stepped out, but in fact arrived at a trampoline."); |
| 106 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | else if (FrameIsYounger()) |
| 108 | { |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 109 | new_plan = m_thread.QueueThreadPlanForStepOut (false, |
| 110 | NULL, |
| 111 | true, |
| 112 | stop_others, |
| 113 | lldb::eVoteNo, |
| 114 | lldb::eVoteNoOpinion, |
| 115 | 0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | } |
| 117 | else if (!InSymbol()) |
| 118 | { |
| 119 | // This one is a little tricky. Sometimes we may be in a stub or something similar, |
| 120 | // in which case we need to get out of there. But if we are in a stub then it's |
| 121 | // likely going to be hard to get out from here. It is probably easiest to step into the |
| 122 | // stub, and then it will be straight-forward to step out. |
| 123 | new_plan = m_thread.QueueThreadPlanForStepThrough (false, stop_others); |
| 124 | } |
| 125 | |
| 126 | if (new_plan == NULL) |
| 127 | m_no_more_plans = true; |
| 128 | else |
| 129 | m_no_more_plans = false; |
| 130 | |
| 131 | if (new_plan == NULL) |
| 132 | { |
| 133 | // For efficiencies sake, we know we're done here so we don't have to do this |
| 134 | // calculation again in MischiefManaged. |
| 135 | SetPlanComplete(); |
| 136 | return true; |
| 137 | } |
| 138 | else |
| 139 | return false; |
| 140 | } |