blob: aead3091b08ef0205b06fa256f3af5d4283a487b [file] [log] [blame]
Jim Inghamf48169b2010-11-30 02:22:11 +00001//===-- 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
Jim Ingham46d005d2014-04-02 22:53:21 +000015
Jim Inghamf48169b2010-11-30 02:22:11 +000016// Project includes
17#include "lldb/lldb-private-log.h"
18#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"
23#include "lldb/Expression/ClangUserExpression.h"
Zachary Turner93749ab2015-03-03 21:51:25 +000024#include "lldb/Expression/IRDynamicChecks.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
41ThreadPlanCallUserExpression::ThreadPlanCallUserExpression (Thread &thread,
42 Address &function,
Sean Callanana464f3d2013-11-08 01:14:26 +000043 llvm::ArrayRef<lldb::addr_t> args,
Jim Ingham6fbc48b2013-11-07 00:11:47 +000044 const EvaluateExpressionOptions &options,
Jim Inghamf48169b2010-11-30 02:22:11 +000045 ClangUserExpression::ClangUserExpressionSP &user_expression_sp) :
Sean Callanana464f3d2013-11-08 01:14:26 +000046 ThreadPlanCallFunction (thread, function, ClangASTType(), args, options),
Jim Inghamf48169b2010-11-30 02:22:11 +000047 m_user_expression_sp (user_expression_sp)
48{
Jim Ingham923886c2012-05-11 18:43:38 +000049 // User expressions are generally "User generated" so we should set them up to stop when done.
50 SetIsMasterPlan (true);
51 SetOkayToDiscard(false);
Jim Inghamf48169b2010-11-30 02:22:11 +000052}
53
54ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression ()
55{
56}
57
58void
59ThreadPlanCallUserExpression::GetDescription (Stream *s, lldb::DescriptionLevel level)
Jim Inghamce553d82011-11-01 02:46:54 +000060{
Jim Ingham30fadaf2014-07-08 01:07:32 +000061 if (level == eDescriptionLevelBrief)
62 s->Printf("User Expression thread plan");
63 else
64 ThreadPlanCallFunction::GetDescription (s, level);
65}
66
67void
68ThreadPlanCallUserExpression::WillPop ()
69{
70 ThreadPlanCallFunction::WillPop();
71 if (m_user_expression_sp)
72 m_user_expression_sp.reset();
73}
74
75bool
76ThreadPlanCallUserExpression::MischiefManaged ()
77{
78 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
79
80 if (IsPlanComplete())
81 {
82 if (log)
83 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
84 static_cast<void*>(this));
85
86 if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp)
87 {
88 lldb::addr_t function_stack_top;
89 lldb::addr_t function_stack_bottom;
90 lldb::addr_t function_stack_pointer = GetFunctionStackPointer();
91
Zachary Turner97a14e62014-08-19 17:18:29 +000092 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
Jim Ingham30fadaf2014-07-08 01:07:32 +000093 function_stack_top = function_stack_pointer;
94
95 StreamString error_stream;
96
97 ExecutionContext exe_ctx(GetThread());
98
99 m_user_expression_sp->FinalizeJITExecution(error_stream, exe_ctx, m_result_var_sp, function_stack_bottom, function_stack_top);
100 }
101
102 ThreadPlan::MischiefManaged ();
103 return true;
104 }
105 else
106 {
107 return false;
108 }
Jim Inghamf48169b2010-11-30 02:22:11 +0000109}
Jim Inghamce553d82011-11-01 02:46:54 +0000110
111StopInfoSP
112ThreadPlanCallUserExpression::GetRealStopInfo()
113{
114 StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();
Jim Inghamce553d82011-11-01 02:46:54 +0000115
Jim Ingham60c41182013-06-04 01:40:51 +0000116 if (stop_info_sp)
117 {
118 lldb::addr_t addr = GetStopAddress();
119 DynamicCheckerFunctions *checkers = m_thread.GetProcess()->GetDynamicCheckers();
120 StreamString s;
121
122 if (checkers && checkers->DoCheckersExplainStop(addr, s))
123 stop_info_sp->SetDescription(s.GetData());
124 }
Jim Inghamce553d82011-11-01 02:46:54 +0000125
126 return stop_info_sp;
127}