blob: 260118c31e1115cdea3c6839c375c3512aad0875 [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
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
Jim Ingham46d005d2014-04-02 22:53:21 +000015
Jim Inghamf48169b2010-11-30 02:22:11 +000016// Project includes
Jim Inghamf48169b2010-11-30 02:22:11 +000017#include "lldb/Breakpoint/Breakpoint.h"
18#include "lldb/Breakpoint/BreakpointLocation.h"
19#include "lldb/Core/Address.h"
20#include "lldb/Core/Log.h"
21#include "lldb/Core/Stream.h"
Sean Callanan579e70c2016-03-19 00:03:59 +000022#include "lldb/Expression/DiagnosticManager.h"
Zachary Turner93749ab2015-03-03 21:51:25 +000023#include "lldb/Expression/IRDynamicChecks.h"
Sean Callanan579e70c2016-03-19 00:03:59 +000024#include "lldb/Expression/UserExpression.h"
Zachary Turner97a14e62014-08-19 17:18:29 +000025#include "lldb/Host/HostInfo.h"
Jim Inghamf48169b2010-11-30 02:22:11 +000026#include "lldb/Target/LanguageRuntime.h"
27#include "lldb/Target/Process.h"
28#include "lldb/Target/RegisterContext.h"
29#include "lldb/Target/StopInfo.h"
30#include "lldb/Target/Target.h"
31#include "lldb/Target/Thread.h"
32#include "lldb/Target/ThreadPlanRunToAddress.h"
33
34using namespace lldb;
35using namespace lldb_private;
36
37//----------------------------------------------------------------------
38// ThreadPlanCallUserExpression: Plan to call a single function
39//----------------------------------------------------------------------
40
Kate Stoneb9c1b512016-09-06 20:57:50 +000041ThreadPlanCallUserExpression::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
48 // stop when done.
49 SetIsMasterPlan(true);
50 SetOkayToDiscard(false);
Jim Inghamf48169b2010-11-30 02:22:11 +000051}
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression() {}
54
55void 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);
Jim Inghamf48169b2010-11-30 02:22:11 +000061}
62
Kate Stoneb9c1b512016-09-06 20:57:50 +000063void ThreadPlanCallUserExpression::WillPop() {
64 ThreadPlanCallFunction::WillPop();
65 if (m_user_expression_sp)
66 m_user_expression_sp.reset();
Jim Ingham30fadaf2014-07-08 01:07:32 +000067}
68
Kate Stoneb9c1b512016-09-06 20:57:50 +000069bool ThreadPlanCallUserExpression::MischiefManaged() {
70 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
Jim Ingham30fadaf2014-07-08 01:07:32 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 if (IsPlanComplete()) {
73 if (log)
74 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
75 static_cast<void *>(this));
Jim Ingham30fadaf2014-07-08 01:07:32 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) {
78 lldb::addr_t function_stack_top;
79 lldb::addr_t function_stack_bottom;
80 lldb::addr_t function_stack_pointer = GetFunctionStackPointer();
Jim Ingham30fadaf2014-07-08 01:07:32 +000081
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
83 function_stack_top = function_stack_pointer;
Jim Ingham30fadaf2014-07-08 01:07:32 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 DiagnosticManager diagnostics;
Sean Callanan579e70c2016-03-19 00:03:59 +000086
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 ExecutionContext exe_ctx(GetThread());
Sean Callanan579e70c2016-03-19 00:03:59 +000088
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 m_user_expression_sp->FinalizeJITExecution(
90 diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom,
91 function_stack_top);
Jim Ingham60c41182013-06-04 01:40:51 +000092 }
Jim Inghamce553d82011-11-01 02:46:54 +000093
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 ThreadPlan::MischiefManaged();
95 return true;
96 } else {
97 return false;
98 }
99}
100
101StopInfoSP ThreadPlanCallUserExpression::GetRealStopInfo() {
102 StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();
103
104 if (stop_info_sp) {
105 lldb::addr_t addr = GetStopAddress();
106 DynamicCheckerFunctions *checkers =
107 m_thread.GetProcess()->GetDynamicCheckers();
108 StreamString s;
109
110 if (checkers && checkers->DoCheckersExplainStop(addr, s))
111 stop_info_sp->SetDescription(s.GetData());
112 }
113
114 return stop_info_sp;
Jim Inghamce553d82011-11-01 02:46:54 +0000115}