Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanTestCondition.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/ThreadPlanTestCondition.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/Breakpoint/BreakpointLocation.h" |
| 19 | #include "lldb/Core/Log.h" |
| 20 | #include "lldb/Core/Stream.h" |
| 21 | #include "lldb/Core/Value.h" |
| 22 | #include "lldb/Core/ValueObject.h" |
| 23 | #include "lldb/Symbol/Function.h" |
| 24 | #include "lldb/Symbol/Symbol.h" |
| 25 | #include "lldb/Target/Process.h" |
| 26 | #include "lldb/Target/RegisterContext.h" |
| 27 | #include "lldb/Target/StopInfo.h" |
| 28 | #include "lldb/Target/Thread.h" |
| 29 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
| 33 | |
| 34 | //---------------------------------------------------------------------- |
| 35 | // ThreadPlanTestCondition: Step through a stack range, either stepping over or into |
| 36 | // based on the value of \a type. |
| 37 | //---------------------------------------------------------------------- |
| 38 | |
| 39 | ThreadPlanTestCondition::ThreadPlanTestCondition ( |
| 40 | Thread& thread, |
| 41 | ExecutionContext &exe_ctx, |
| 42 | ClangUserExpression *expression, |
| 43 | lldb::BreakpointLocationSP break_loc_sp, |
| 44 | bool stop_others) : |
| 45 | ThreadPlan (ThreadPlan::eKindTestCondition, "test condition", thread, eVoteNoOpinion, eVoteNoOpinion), |
| 46 | m_exe_ctx (exe_ctx), |
| 47 | m_expression (expression), |
| 48 | m_break_loc_sp (break_loc_sp), |
| 49 | m_did_stop (false), |
| 50 | m_stop_others (stop_others) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | ThreadPlanTestCondition::~ThreadPlanTestCondition () |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | bool |
| 59 | ThreadPlanTestCondition::ValidatePlan (Stream *error) |
| 60 | { |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | ThreadPlanTestCondition::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 66 | { |
Jim Ingham | 360f53f | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 67 | if (m_expression) |
| 68 | s->Printf("Thread plan to test condition: \"%s\".", m_expression->GetUserText()); |
| 69 | else |
| 70 | s->Printf("Thread plan to test unspecified condition."); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | bool |
| 74 | ThreadPlanTestCondition::ShouldStop (Event *event_ptr) |
| 75 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 76 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 77 | if (m_thread.IsThreadPlanDone(m_expression_plan_sp.get())) |
| 78 | { |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 79 | lldb::ClangExpressionVariableSP expr_result; |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 80 | StreamString error_stream; |
| 81 | m_expression->FinalizeJITExecution(error_stream, m_exe_ctx, expr_result); |
| 82 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 83 | ValueObjectSP result_sp (expr_result->GetValueObject()); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 84 | if (result_sp) |
| 85 | { |
| 86 | // FIXME: This is not the right answer, we should have a "GetValueAsBoolean..." |
| 87 | Scalar scalar_value = result_sp->GetValue().ResolveValue (&m_exe_ctx, result_sp->GetClangAST()); |
| 88 | if (scalar_value.IsValid()) |
| 89 | { |
| 90 | if (scalar_value.ULongLong(1) == 0) |
| 91 | m_did_stop = false; |
| 92 | else |
| 93 | m_did_stop = true; |
| 94 | } |
| 95 | if (log) |
| 96 | log->Printf("Condition successfully evaluated, result is %s.\n", m_did_stop ? "true" : "false"); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | if (log) |
| 101 | log->Printf("Failed to get a result from the expression, error: \"%s\"\n", error_stream.GetData()); |
| 102 | m_did_stop = true; |
| 103 | } |
| 104 | } |
| 105 | else if (m_exe_ctx.thread->WasThreadPlanDiscarded (m_expression_plan_sp.get())) |
| 106 | { |
| 107 | if (log) |
| 108 | log->Printf("ExecuteExpression thread plan was discarded.\n"); |
| 109 | m_did_stop = true; |
| 110 | } |
| 111 | |
| 112 | // Now we have to change the event to a breakpoint event and mark it up appropriately: |
| 113 | Process::ProcessEventData *new_data = new Process::ProcessEventData (m_thread.GetProcess().GetSP(), eStateStopped); |
| 114 | event_ptr->SetData(new_data); |
| 115 | event_ptr->SetType(Process::eBroadcastBitStateChanged); |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 116 | SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID (m_thread, |
| 117 | m_break_loc_sp->GetBreakpointSite()->GetID(), |
| 118 | m_did_stop)); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 119 | if (m_did_stop) |
| 120 | { |
| 121 | Process::ProcessEventData::SetRestartedInEvent (event_ptr, false); |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | Process::ProcessEventData::SetRestartedInEvent (event_ptr, true); |
| 126 | } |
| 127 | |
| 128 | SetPlanComplete(); |
| 129 | return m_did_stop; |
| 130 | } |
| 131 | |
| 132 | bool |
| 133 | ThreadPlanTestCondition::PlanExplainsStop () |
| 134 | { |
| 135 | // We explain all stops, and we just can the execution and return true if we stop for any |
| 136 | // reason other than that our expression execution is done. |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | Vote |
| 141 | ThreadPlanTestCondition::ShouldReportStop (Event *event_ptr) |
| 142 | { |
| 143 | if (m_did_stop) |
| 144 | { |
| 145 | return eVoteYes; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | return eVoteNo; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void |
| 154 | ThreadPlanTestCondition::DidPush() |
| 155 | { |
| 156 | StreamString error_stream; |
| 157 | m_expression_plan_sp.reset(m_expression->GetThreadPlanToExecuteJITExpression (error_stream, m_exe_ctx)); |
| 158 | m_thread.QueueThreadPlan (m_expression_plan_sp, false); |
| 159 | } |
| 160 | |
| 161 | bool |
| 162 | ThreadPlanTestCondition::StopOthers () |
| 163 | { |
| 164 | return m_stop_others; |
| 165 | } |
| 166 | |
| 167 | bool |
| 168 | ThreadPlanTestCondition::WillStop () |
| 169 | { |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | StateType |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 174 | ThreadPlanTestCondition::GetPlanRunState () |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 175 | { |
| 176 | return eStateRunning; |
| 177 | } |
| 178 | |
| 179 | bool |
| 180 | ThreadPlanTestCondition::MischiefManaged () |
| 181 | { |
| 182 | // If we get a stop we're done, we don't puase in the middle of |
| 183 | // condition execution. |
| 184 | return true; |
| 185 | } |