blob: dcd5c8c6eb8c06811e613a84d37120d9c886558b [file] [log] [blame]
Kate Stoneb9c1b512016-09-06 20:57:50 +00001//===-- ThreadPlanCallUserExpression.cpp ------------------------------*- C++
2//-*-===//
Jim Inghamf48169b2010-11-30 02:22:11 +00003//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#include "lldb/Target/ThreadPlanCallUserExpression.h"
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
Jim Ingham46d005d2014-04-02 22:53:21 +000016
Jim Inghamf48169b2010-11-30 02:22:11 +000017// Project includes
Jim Inghamf48169b2010-11-30 02:22:11 +000018#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
20#include "lldb/Core/Address.h"
21#include "lldb/Core/Log.h"
22#include "lldb/Core/Stream.h"
Sean Callanan579e70c2016-03-19 00:03:59 +000023#include "lldb/Expression/DiagnosticManager.h"
Zachary Turner93749ab2015-03-03 21:51:25 +000024#include "lldb/Expression/IRDynamicChecks.h"
Sean Callanan579e70c2016-03-19 00:03:59 +000025#include "lldb/Expression/UserExpression.h"
Zachary Turner97a14e62014-08-19 17:18:29 +000026#include "lldb/Host/HostInfo.h"
Jim Inghamf48169b2010-11-30 02:22:11 +000027#include "lldb/Target/LanguageRuntime.h"
28#include "lldb/Target/Process.h"
29#include "lldb/Target/RegisterContext.h"
30#include "lldb/Target/StopInfo.h"
31#include "lldb/Target/Target.h"
32#include "lldb/Target/Thread.h"
33#include "lldb/Target/ThreadPlanRunToAddress.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38//----------------------------------------------------------------------
39// ThreadPlanCallUserExpression: Plan to call a single function
40//----------------------------------------------------------------------
41
Kate Stoneb9c1b512016-09-06 20:57:50 +000042ThreadPlanCallUserExpression::ThreadPlanCallUserExpression(
43 Thread &thread, Address &function, llvm::ArrayRef<lldb::addr_t> args,
44 const EvaluateExpressionOptions &options,
45 lldb::UserExpressionSP &user_expression_sp)
46 : ThreadPlanCallFunction(thread, function, CompilerType(), args, options),
47 m_user_expression_sp(user_expression_sp) {
48 // User expressions are generally "User generated" so we should set them up to
49 // stop when done.
50 SetIsMasterPlan(true);
51 SetOkayToDiscard(false);
Jim Inghamf48169b2010-11-30 02:22:11 +000052}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression() {}
55
56void ThreadPlanCallUserExpression::GetDescription(
57 Stream *s, lldb::DescriptionLevel level) {
58 if (level == eDescriptionLevelBrief)
59 s->Printf("User Expression thread plan");
60 else
61 ThreadPlanCallFunction::GetDescription(s, level);
Jim Inghamf48169b2010-11-30 02:22:11 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064void ThreadPlanCallUserExpression::WillPop() {
65 ThreadPlanCallFunction::WillPop();
66 if (m_user_expression_sp)
67 m_user_expression_sp.reset();
Jim Ingham30fadaf2014-07-08 01:07:32 +000068}
69
Kate Stoneb9c1b512016-09-06 20:57:50 +000070bool ThreadPlanCallUserExpression::MischiefManaged() {
71 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
Jim Ingham30fadaf2014-07-08 01:07:32 +000072
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 if (IsPlanComplete()) {
74 if (log)
75 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
76 static_cast<void *>(this));
Jim Ingham30fadaf2014-07-08 01:07:32 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) {
79 lldb::addr_t function_stack_top;
80 lldb::addr_t function_stack_bottom;
81 lldb::addr_t function_stack_pointer = GetFunctionStackPointer();
Jim Ingham30fadaf2014-07-08 01:07:32 +000082
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
84 function_stack_top = function_stack_pointer;
Jim Ingham30fadaf2014-07-08 01:07:32 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 DiagnosticManager diagnostics;
Sean Callanan579e70c2016-03-19 00:03:59 +000087
Kate Stoneb9c1b512016-09-06 20:57:50 +000088 ExecutionContext exe_ctx(GetThread());
Sean Callanan579e70c2016-03-19 00:03:59 +000089
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 m_user_expression_sp->FinalizeJITExecution(
91 diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom,
92 function_stack_top);
Jim Ingham60c41182013-06-04 01:40:51 +000093 }
Jim Inghamce553d82011-11-01 02:46:54 +000094
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 ThreadPlan::MischiefManaged();
96 return true;
97 } else {
98 return false;
99 }
100}
101
102StopInfoSP ThreadPlanCallUserExpression::GetRealStopInfo() {
103 StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();
104
105 if (stop_info_sp) {
106 lldb::addr_t addr = GetStopAddress();
107 DynamicCheckerFunctions *checkers =
108 m_thread.GetProcess()->GetDynamicCheckers();
109 StreamString s;
110
111 if (checkers && checkers->DoCheckersExplainStop(addr, s))
112 stop_info_sp->SetDescription(s.GetData());
113 }
114
115 return stop_info_sp;
Jim Inghamce553d82011-11-01 02:46:54 +0000116}