1 //===-- ThreadPlanCallUserExpression.cpp -------------------------*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Target/ThreadPlanCallUserExpression.h"
14 // Other libraries and framework 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"
35 using namespace lldb_private;
37 //----------------------------------------------------------------------
38 // ThreadPlanCallUserExpression: Plan to call a single function
39 //----------------------------------------------------------------------
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 to
49 SetIsMasterPlan(true);
50 SetOkayToDiscard(false);
53 ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression() {}
55 void ThreadPlanCallUserExpression::GetDescription(
56 Stream *s, lldb::DescriptionLevel level) {
57 if (level == eDescriptionLevelBrief)
58 s->Printf("User Expression thread plan");
60 ThreadPlanCallFunction::GetDescription(s, level);
63 void ThreadPlanCallUserExpression::DidPush() {
64 ThreadPlanCallFunction::DidPush();
65 if (m_user_expression_sp)
66 m_user_expression_sp->WillStartExecuting();
69 void ThreadPlanCallUserExpression::WillPop() {
70 ThreadPlanCallFunction::WillPop();
71 if (m_user_expression_sp)
72 m_user_expression_sp.reset();
75 bool ThreadPlanCallUserExpression::MischiefManaged() {
76 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
78 if (IsPlanComplete()) {
80 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
81 static_cast<void *>(this));
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();
88 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
89 function_stack_top = function_stack_pointer;
91 DiagnosticManager diagnostics;
93 ExecutionContext exe_ctx(GetThread());
95 m_user_expression_sp->FinalizeJITExecution(
96 diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom,
100 ThreadPlan::MischiefManaged();
107 StopInfoSP ThreadPlanCallUserExpression::GetRealStopInfo() {
108 StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();
111 lldb::addr_t addr = GetStopAddress();
112 DynamicCheckerFunctions *checkers =
113 m_thread.GetProcess()->GetDynamicCheckers();
116 if (checkers && checkers->DoCheckersExplainStop(addr, s))
117 stop_info_sp->SetDescription(s.GetData());
123 void ThreadPlanCallUserExpression::DoTakedown(bool success) {
124 ThreadPlanCallFunction::DoTakedown(success);
125 m_user_expression_sp->DidFinishExecuting();