Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanShouldStopHere.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 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 10 | #include "lldb/Target/RegisterContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "lldb/Target/Thread.h" |
| 12 | #include "lldb/Target/ThreadPlanShouldStopHere.h" |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace lldb; |
| 16 | using namespace lldb_private; |
| 17 | |
| 18 | // C Includes |
| 19 | // C++ Includes |
| 20 | // Other libraries and framework includes |
| 21 | // Project includes |
| 22 | |
| 23 | //---------------------------------------------------------------------- |
| 24 | // ThreadPlanShouldStopHere constructor |
| 25 | //---------------------------------------------------------------------- |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 26 | ThreadPlanShouldStopHere::ThreadPlanShouldStopHere(ThreadPlan *owner) : |
| 27 | m_callbacks (), |
| 28 | m_baton (NULL), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | m_owner (owner), |
| 30 | m_flags (ThreadPlanShouldStopHere::eNone) |
| 31 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 32 | m_callbacks.should_stop_here_callback = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback; |
| 33 | m_callbacks.step_from_here_callback = ThreadPlanShouldStopHere::DefaultStepFromHereCallback; |
| 34 | } |
| 35 | |
| 36 | ThreadPlanShouldStopHere::ThreadPlanShouldStopHere(ThreadPlan *owner, const ThreadPlanShouldStopHereCallbacks *callbacks, void *baton) : |
| 37 | m_callbacks (), |
| 38 | m_baton (), |
| 39 | m_owner (owner), |
| 40 | m_flags (ThreadPlanShouldStopHere::eNone) |
| 41 | { |
| 42 | SetShouldStopHereCallbacks(callbacks, baton); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | //---------------------------------------------------------------------- |
| 46 | // Destructor |
| 47 | //---------------------------------------------------------------------- |
| 48 | ThreadPlanShouldStopHere::~ThreadPlanShouldStopHere() |
| 49 | { |
| 50 | } |
| 51 | |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 52 | bool |
| 53 | ThreadPlanShouldStopHere::InvokeShouldStopHereCallback (FrameComparison operation) |
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 | bool should_stop_here = true; |
| 56 | if (m_callbacks.should_stop_here_callback) |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 57 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 58 | should_stop_here = m_callbacks.should_stop_here_callback (m_owner, m_flags, operation, m_baton); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 59 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 60 | if (log) |
| 61 | { |
| 62 | lldb::addr_t current_addr = m_owner->GetThread().GetRegisterContext()->GetPC(0); |
| 63 | |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 64 | log->Printf ("ShouldStopHere callback returned %u from 0x%" PRIx64 ".", should_stop_here, current_addr); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 65 | } |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 66 | } |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 67 | |
| 68 | return should_stop_here; |
| 69 | } |
| 70 | |
| 71 | bool |
| 72 | ThreadPlanShouldStopHere::DefaultShouldStopHereCallback (ThreadPlan *current_plan, |
| 73 | Flags &flags, |
| 74 | FrameComparison operation, |
| 75 | void *baton) |
| 76 | { |
| 77 | bool should_stop_here = true; |
| 78 | StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get(); |
Jim Ingham | 0eed738 | 2014-03-17 23:03:34 +0000 | [diff] [blame] | 79 | if (!frame) |
| 80 | return true; |
| 81 | |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 82 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 83 | |
| 84 | if ((operation == eFrameCompareOlder && flags.Test(eStepOutAvoidNoDebug)) |
Jim Ingham | 862d1bb | 2014-08-06 01:49:59 +0000 | [diff] [blame] | 85 | || (operation == eFrameCompareYounger && flags.Test(eStepInAvoidNoDebug)) |
| 86 | || (operation == eFrameCompareSameParent && flags.Test(eStepInAvoidNoDebug))) |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 87 | { |
| 88 | if (!frame->HasDebugInformation()) |
| 89 | { |
| 90 | if (log) |
| 91 | log->Printf ("Stepping out of frame with no debug info"); |
| 92 | |
| 93 | should_stop_here = false; |
| 94 | } |
| 95 | } |
| 96 | |
Jim Ingham | 0eed738 | 2014-03-17 23:03:34 +0000 | [diff] [blame] | 97 | // Always avoid code with line number 0. |
| 98 | // FIXME: At present the ShouldStop and the StepFromHere calculate this independently. If this ever |
| 99 | // becomes expensive (this one isn't) we can try to have this set a state that the StepFromHere can use. |
| 100 | if (frame) |
| 101 | { |
| 102 | SymbolContext sc; |
| 103 | sc = frame->GetSymbolContext (eSymbolContextLineEntry); |
| 104 | if (sc.line_entry.line == 0) |
| 105 | should_stop_here = false; |
| 106 | } |
| 107 | |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 108 | return should_stop_here; |
| 109 | } |
| 110 | |
| 111 | ThreadPlanSP |
| 112 | ThreadPlanShouldStopHere::DefaultStepFromHereCallback (ThreadPlan *current_plan, |
| 113 | Flags &flags, |
| 114 | FrameComparison operation, |
| 115 | void *baton) |
| 116 | { |
Jim Ingham | 0eed738 | 2014-03-17 23:03:34 +0000 | [diff] [blame] | 117 | const bool stop_others = false; |
| 118 | const size_t frame_index = 0; |
| 119 | ThreadPlanSP return_plan_sp; |
| 120 | // If we are stepping through code at line number 0, then we need to step over this range. Otherwise |
| 121 | // we will step out. |
| 122 | StackFrame *frame = current_plan->GetThread().GetStackFrameAtIndex(0).get(); |
| 123 | if (!frame) |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 124 | return return_plan_sp; |
Jim Ingham | 0eed738 | 2014-03-17 23:03:34 +0000 | [diff] [blame] | 125 | SymbolContext sc; |
| 126 | sc = frame->GetSymbolContext (eSymbolContextLineEntry); |
| 127 | if (sc.line_entry.line == 0) |
| 128 | { |
| 129 | AddressRange range = sc.line_entry.range; |
| 130 | return_plan_sp = current_plan->GetThread().QueueThreadPlanForStepOverRange(false, |
| 131 | range, |
| 132 | sc, |
| 133 | eOnlyDuringStepping, |
| 134 | eLazyBoolNo); |
| 135 | } |
| 136 | |
| 137 | if (!return_plan_sp) |
| 138 | return_plan_sp = current_plan->GetThread().QueueThreadPlanForStepOutNoShouldStop (false, |
| 139 | NULL, |
| 140 | true, |
| 141 | stop_others, |
| 142 | eVoteNo, |
| 143 | eVoteNoOpinion, |
| 144 | frame_index); |
| 145 | return return_plan_sp; |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | ThreadPlanSP |
| 149 | ThreadPlanShouldStopHere::QueueStepOutFromHerePlan(lldb_private::Flags &flags, lldb::FrameComparison operation) |
| 150 | { |
| 151 | ThreadPlanSP return_plan_sp; |
| 152 | if (m_callbacks.step_from_here_callback) |
| 153 | { |
| 154 | return_plan_sp = m_callbacks.step_from_here_callback (m_owner, flags, operation, m_baton); |
| 155 | } |
| 156 | return return_plan_sp; |
| 157 | |
| 158 | } |
| 159 | |
| 160 | lldb::ThreadPlanSP |
| 161 | ThreadPlanShouldStopHere::CheckShouldStopHereAndQueueStepOut (lldb::FrameComparison operation) |
| 162 | { |
| 163 | if (!InvokeShouldStopHereCallback(operation)) |
| 164 | return QueueStepOutFromHerePlan(m_flags, operation); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | else |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 166 | return ThreadPlanSP(); |
Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 167 | } |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 168 | |