1 //===-- ThreadPlanCallUserExpression.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/ThreadPlanCallUserExpression.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 16 // Project includes 17 #include "lldb/Breakpoint/Breakpoint.h" 18 #include "lldb/Breakpoint/BreakpointLocation.h" 19 #include "lldb/Core/Address.h" 20 #include "lldb/Expression/DiagnosticManager.h" 21 #include "lldb/Expression/IRDynamicChecks.h" 22 #include "lldb/Expression/UserExpression.h" 23 #include "lldb/Host/HostInfo.h" 24 #include "lldb/Target/LanguageRuntime.h" 25 #include "lldb/Target/Process.h" 26 #include "lldb/Target/RegisterContext.h" 27 #include "lldb/Target/StopInfo.h" 28 #include "lldb/Target/Target.h" 29 #include "lldb/Target/Thread.h" 30 #include "lldb/Target/ThreadPlanRunToAddress.h" 31 #include "lldb/Utility/Log.h" 32 #include "lldb/Utility/Stream.h" 33 34 using namespace lldb; 35 using namespace lldb_private; 36 37 //---------------------------------------------------------------------- 38 // ThreadPlanCallUserExpression: Plan to call a single function 39 //---------------------------------------------------------------------- 40 41 ThreadPlanCallUserExpression::ThreadPlanCallUserExpression( 42 Thread &thread, Address &function, llvm::ArrayRef<lldb::addr_t> args, 43 const EvaluateExpressionOptions &options, 44 lldb::UserExpressionSP &user_expression_sp) 45 : ThreadPlanCallFunction(thread, function, CompilerType(), args, options), 46 m_user_expression_sp(user_expression_sp) { 47 // User expressions are generally "User generated" so we should set them up 48 // to stop when done. 49 SetIsMasterPlan(true); 50 SetOkayToDiscard(false); 51 } 52 53 ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression() {} 54 55 void ThreadPlanCallUserExpression::GetDescription( 56 Stream *s, lldb::DescriptionLevel level) { 57 if (level == eDescriptionLevelBrief) 58 s->Printf("User Expression thread plan"); 59 else 60 ThreadPlanCallFunction::GetDescription(s, level); 61 } 62 63 void ThreadPlanCallUserExpression::DidPush() { 64 ThreadPlanCallFunction::DidPush(); 65 if (m_user_expression_sp) 66 m_user_expression_sp->WillStartExecuting(); 67 } 68 69 void ThreadPlanCallUserExpression::WillPop() { 70 ThreadPlanCallFunction::WillPop(); 71 if (m_user_expression_sp) 72 m_user_expression_sp.reset(); 73 } 74 75 bool ThreadPlanCallUserExpression::MischiefManaged() { 76 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 77 78 if (IsPlanComplete()) { 79 if (log) 80 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", 81 static_cast<void *>(this)); 82 83 if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) { 84 lldb::addr_t function_stack_top; 85 lldb::addr_t function_stack_bottom; 86 lldb::addr_t function_stack_pointer = GetFunctionStackPointer(); 87 88 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); 89 function_stack_top = function_stack_pointer; 90 91 DiagnosticManager diagnostics; 92 93 ExecutionContext exe_ctx(GetThread()); 94 95 m_user_expression_sp->FinalizeJITExecution( 96 diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom, 97 function_stack_top); 98 } 99 100 ThreadPlan::MischiefManaged(); 101 return true; 102 } else { 103 return false; 104 } 105 } 106 107 StopInfoSP ThreadPlanCallUserExpression::GetRealStopInfo() { 108 StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo(); 109 110 if (stop_info_sp) { 111 lldb::addr_t addr = GetStopAddress(); 112 DynamicCheckerFunctions *checkers = 113 m_thread.GetProcess()->GetDynamicCheckers(); 114 StreamString s; 115 116 if (checkers && checkers->DoCheckersExplainStop(addr, s)) 117 stop_info_sp->SetDescription(s.GetData()); 118 } 119 120 return stop_info_sp; 121 } 122 123 void ThreadPlanCallUserExpression::DoTakedown(bool success) { 124 ThreadPlanCallFunction::DoTakedown(success); 125 m_user_expression_sp->DidFinishExecuting(); 126 } 127