LLDB  mainline
ThreadPlanCallUserExpression.cpp
Go to the documentation of this file.
1 //===-- ThreadPlanCallUserExpression.cpp ----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 
14 #include "lldb/Core/Address.h"
18 #include "lldb/Host/HostInfo.h"
20 #include "lldb/Target/Process.h"
22 #include "lldb/Target/StopInfo.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Target/Thread.h"
26 #include "lldb/Utility/Log.h"
27 #include "lldb/Utility/Stream.h"
28 
29 using namespace lldb;
30 using namespace lldb_private;
31 
32 // ThreadPlanCallUserExpression: Plan to call a single function
33 
34 ThreadPlanCallUserExpression::ThreadPlanCallUserExpression(
35  Thread &thread, Address &function, llvm::ArrayRef<lldb::addr_t> args,
36  const EvaluateExpressionOptions &options,
37  lldb::UserExpressionSP &user_expression_sp)
38  : ThreadPlanCallFunction(thread, function, CompilerType(), args, options),
39  m_user_expression_sp(user_expression_sp) {
40  // User expressions are generally "User generated" so we should set them up
41  // to stop when done.
42  SetIsMasterPlan(true);
43  SetOkayToDiscard(false);
44 }
45 
47 
49  Stream *s, lldb::DescriptionLevel level) {
50  if (level == eDescriptionLevelBrief)
51  s->Printf("User Expression thread plan");
52  else
54 }
55 
59  m_user_expression_sp->WillStartExecuting();
60 }
61 
65  m_user_expression_sp.reset();
66 }
67 
70 
71  if (IsPlanComplete()) {
72  LLDB_LOGF(log, "ThreadPlanCallFunction(%p): Completed call function plan.",
73  static_cast<void *>(this));
74 
76  lldb::addr_t function_stack_top;
77  lldb::addr_t function_stack_bottom;
78  lldb::addr_t function_stack_pointer = GetFunctionStackPointer();
79 
80  function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
81  function_stack_top = function_stack_pointer;
82 
83  DiagnosticManager diagnostics;
84 
85  ExecutionContext exe_ctx(GetThread());
86 
87  m_user_expression_sp->FinalizeJITExecution(
88  diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom,
89  function_stack_top);
90  }
91 
93  return true;
94  } else {
95  return false;
96  }
97 }
98 
100  StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();
101 
102  if (stop_info_sp) {
103  lldb::addr_t addr = GetStopAddress();
105  StreamString s;
106 
107  if (checkers && checkers->DoCheckersExplainStop(addr, s))
108  stop_info_sp->SetDescription(s.GetData());
109  }
110 
111  return stop_info_sp;
112 }
113 
116  m_user_expression_sp->DidFinishExecuting();
117 }
lldb_private::ThreadPlanCallFunction::DidPop
void DidPop() override
Definition: ThreadPlanCallFunction.cpp:212
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::ThreadPlan::GetThread
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:41
lldb_private::ThreadPlan::IsPlanComplete
bool IsPlanComplete()
Definition: ThreadPlan.cpp:60
lldb_private::ThreadPlanCallUserExpression::DoTakedown
void DoTakedown(bool success) override
Definition: ThreadPlanCallUserExpression.cpp:114
lldb_private::ThreadPlan::SetOkayToDiscard
void SetOkayToDiscard(bool value)
Definition: ThreadPlan.h:399
lldb_private::ThreadPlanCallFunction::GetStopAddress
lldb::addr_t GetStopAddress()
Definition: ThreadPlanCallFunction.h:91
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::ThreadPlan::PlanSucceeded
bool PlanSucceeded()
Definition: ThreadPlan.h:426
BreakpointLocation.h
lldb_private::EvaluateExpressionOptions
Definition: Target.h:262
UserExpression.h
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ThreadPlanCallUserExpression::m_user_expression_sp
lldb::UserExpressionSP m_user_expression_sp
Definition: ThreadPlanCallUserExpression.h:51
Process.h
lldb_private::ThreadPlanCallUserExpression::DidPush
void DidPush() override
Definition: ThreadPlanCallUserExpression.cpp:56
lldb_private::ThreadPlanCallFunction
Definition: ThreadPlanCallFunction.h:20
lldb_private::ThreadPlan::SetIsMasterPlan
bool SetIsMasterPlan(bool value)
Definition: ThreadPlan.h:391
Target.h
lldb_private::ThreadPlanCallUserExpression::GetRealStopInfo
lldb::StopInfoSP GetRealStopInfo() override
Definition: ThreadPlanCallUserExpression.cpp:99
lldb_private::ThreadPlanCallUserExpression::MischiefManaged
bool MischiefManaged() override
Definition: ThreadPlanCallUserExpression.cpp:68
lldb_private::Process::GetDynamicCheckers
DynamicCheckerFunctions * GetDynamicCheckers()
Definition: Process.h:2260
Log.h
lldb_private::ThreadPlan::MischiefManaged
virtual bool MischiefManaged()
Definition: ThreadPlan.cpp:71
lldb_private::Thread
Definition: Thread.h:62
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::ThreadPlanCallFunction::DidPush
void DidPush() override
Definition: ThreadPlanCallFunction.cpp:363
HostInfo.h
ThreadPlanRunToAddress.h
lldb_private::ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression
~ThreadPlanCallUserExpression() override
lldb_private::ThreadPlanCallUserExpression::m_result_var_sp
lldb::ExpressionVariableSP m_result_var_sp
Definition: ThreadPlanCallUserExpression.h:56
lldb_private::ThreadPlanCallUserExpression::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Definition: ThreadPlanCallUserExpression.cpp:48
Thread.h
Address.h
DynamicCheckerFunctions.h
lldb_private::DynamicCheckerFunctions::DoCheckersExplainStop
virtual bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message)=0
lldb_private::Address
Definition: Address.h:59
lldb_private::ThreadPlanCallUserExpression::DidPop
void DidPop() override
Definition: ThreadPlanCallUserExpression.cpp:62
ThreadPlanCallUserExpression.h
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
lldb_private::ThreadPlanCallFunction::GetRealStopInfo
virtual lldb::StopInfoSP GetRealStopInfo()
Definition: ThreadPlanCallFunction.h:84
StopInfo.h
lldb_private::ThreadPlanCallUserExpression::m_manage_materialization
bool m_manage_materialization
Definition: ThreadPlanCallUserExpression.h:54
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
LanguageRuntime.h
DiagnosticManager.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Breakpoint.h
LIBLLDB_LOG_STEP
#define LIBLLDB_LOG_STEP
Definition: Logging.h:21
Stream.h
lldb_private::Log
Definition: Log.h:49
lldb_private::ThreadPlanCallFunction::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Definition: ThreadPlanCallFunction.cpp:214
lldb_private::DynamicCheckerFunctions
Encapsulates dynamic check functions used by expressions.
Definition: DynamicCheckerFunctions.h:30
lldb_private::ThreadPlanCallFunction::GetFunctionStackPointer
lldb::addr_t GetFunctionStackPointer()
Definition: ThreadPlanCallFunction.h:69
lldb_private::ThreadPlan::m_process
Process & m_process
Definition: ThreadPlan.h:523
lldb
Definition: SBAddress.h:15
RegisterContext.h
lldb::eDescriptionLevelBrief
@ eDescriptionLevelBrief
Definition: lldb-enumerations.h:208
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb_private::ThreadPlanCallFunction::DoTakedown
virtual void DoTakedown(bool success)
Definition: ThreadPlanCallFunction.cpp:168