blob: 1fbd346feeead473972ec26731547e11d96a6be1 [file] [log] [blame]
Zachary Turnerc1564272016-11-16 21:15:24 +00001//===-- ThreadPlanCallUserExpression.cpp -------------------------*- C++-*-===//
Jim Inghamf48169b2010-11-30 02:22:11 +00002//
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
Jim Ingham46d005d2014-04-02 22:53:21 +000012
Jim Inghamf48169b2010-11-30 02:22:11 +000013#include "lldb/Breakpoint/Breakpoint.h"
14#include "lldb/Breakpoint/BreakpointLocation.h"
15#include "lldb/Core/Address.h"
Sean Callanan579e70c2016-03-19 00:03:59 +000016#include "lldb/Expression/DiagnosticManager.h"
Zachary Turner93749ab2015-03-03 21:51:25 +000017#include "lldb/Expression/IRDynamicChecks.h"
Sean Callanan579e70c2016-03-19 00:03:59 +000018#include "lldb/Expression/UserExpression.h"
Zachary Turner97a14e62014-08-19 17:18:29 +000019#include "lldb/Host/HostInfo.h"
Jim Inghamf48169b2010-11-30 02:22:11 +000020#include "lldb/Target/LanguageRuntime.h"
21#include "lldb/Target/Process.h"
22#include "lldb/Target/RegisterContext.h"
23#include "lldb/Target/StopInfo.h"
24#include "lldb/Target/Target.h"
25#include "lldb/Target/Thread.h"
26#include "lldb/Target/ThreadPlanRunToAddress.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000027#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000028#include "lldb/Utility/Stream.h"
Jim Inghamf48169b2010-11-30 02:22:11 +000029
30using namespace lldb;
31using namespace lldb_private;
32
33//----------------------------------------------------------------------
34// ThreadPlanCallUserExpression: Plan to call a single function
35//----------------------------------------------------------------------
36
Kate Stoneb9c1b512016-09-06 20:57:50 +000037ThreadPlanCallUserExpression::ThreadPlanCallUserExpression(
38 Thread &thread, Address &function, llvm::ArrayRef<lldb::addr_t> args,
39 const EvaluateExpressionOptions &options,
40 lldb::UserExpressionSP &user_expression_sp)
41 : ThreadPlanCallFunction(thread, function, CompilerType(), args, options),
42 m_user_expression_sp(user_expression_sp) {
Adrian Prantl05097242018-04-30 16:49:04 +000043 // User expressions are generally "User generated" so we should set them up
44 // to stop when done.
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 SetIsMasterPlan(true);
46 SetOkayToDiscard(false);
Jim Inghamf48169b2010-11-30 02:22:11 +000047}
48
Kate Stoneb9c1b512016-09-06 20:57:50 +000049ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression() {}
50
51void ThreadPlanCallUserExpression::GetDescription(
52 Stream *s, lldb::DescriptionLevel level) {
53 if (level == eDescriptionLevelBrief)
54 s->Printf("User Expression thread plan");
55 else
56 ThreadPlanCallFunction::GetDescription(s, level);
Jim Inghamf48169b2010-11-30 02:22:11 +000057}
58
Lang Hames8b385652017-05-05 22:42:13 +000059void ThreadPlanCallUserExpression::DidPush() {
60 ThreadPlanCallFunction::DidPush();
61 if (m_user_expression_sp)
62 m_user_expression_sp->WillStartExecuting();
63}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065void ThreadPlanCallUserExpression::WillPop() {
66 ThreadPlanCallFunction::WillPop();
67 if (m_user_expression_sp)
68 m_user_expression_sp.reset();
Jim Ingham30fadaf2014-07-08 01:07:32 +000069}
70
Kate Stoneb9c1b512016-09-06 20:57:50 +000071bool ThreadPlanCallUserExpression::MischiefManaged() {
72 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
Jim Ingham30fadaf2014-07-08 01:07:32 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 if (IsPlanComplete()) {
75 if (log)
76 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
77 static_cast<void *>(this));
Jim Ingham30fadaf2014-07-08 01:07:32 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) {
80 lldb::addr_t function_stack_top;
81 lldb::addr_t function_stack_bottom;
82 lldb::addr_t function_stack_pointer = GetFunctionStackPointer();
Jim Ingham30fadaf2014-07-08 01:07:32 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
85 function_stack_top = function_stack_pointer;
Jim Ingham30fadaf2014-07-08 01:07:32 +000086
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 DiagnosticManager diagnostics;
Sean Callanan579e70c2016-03-19 00:03:59 +000088
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 ExecutionContext exe_ctx(GetThread());
Sean Callanan579e70c2016-03-19 00:03:59 +000090
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 m_user_expression_sp->FinalizeJITExecution(
92 diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom,
93 function_stack_top);
Jim Ingham60c41182013-06-04 01:40:51 +000094 }
Jim Inghamce553d82011-11-01 02:46:54 +000095
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 ThreadPlan::MischiefManaged();
97 return true;
98 } else {
99 return false;
100 }
101}
102
103StopInfoSP ThreadPlanCallUserExpression::GetRealStopInfo() {
104 StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();
105
106 if (stop_info_sp) {
107 lldb::addr_t addr = GetStopAddress();
108 DynamicCheckerFunctions *checkers =
109 m_thread.GetProcess()->GetDynamicCheckers();
110 StreamString s;
111
112 if (checkers && checkers->DoCheckersExplainStop(addr, s))
113 stop_info_sp->SetDescription(s.GetData());
114 }
115
116 return stop_info_sp;
Jim Inghamce553d82011-11-01 02:46:54 +0000117}
Lang Hames8b385652017-05-05 22:42:13 +0000118
119void ThreadPlanCallUserExpression::DoTakedown(bool success) {
120 ThreadPlanCallFunction::DoTakedown(success);
121 m_user_expression_sp->DidFinishExecuting();
122}