LLDB  mainline
ThreadPlanCallUserExpression.cpp
Go to the documentation of this file.
1 //===-- ThreadPlanCallUserExpression.cpp -------------------------*- C++-*-===//
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 
58  if (m_user_expression_sp)
59  m_user_expression_sp->WillStartExecuting();
60 }
61 
64  if (m_user_expression_sp)
65  m_user_expression_sp.reset();
66 }
67 
70 
71  if (IsPlanComplete()) {
72  if (log)
73  log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
74  static_cast<void *>(this));
75 
76  if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) {
77  lldb::addr_t function_stack_top;
78  lldb::addr_t function_stack_bottom;
79  lldb::addr_t function_stack_pointer = GetFunctionStackPointer();
80 
81  function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
82  function_stack_top = function_stack_pointer;
83 
84  DiagnosticManager diagnostics;
85 
86  ExecutionContext exe_ctx(GetThread());
87 
88  m_user_expression_sp->FinalizeJITExecution(
89  diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom,
90  function_stack_top);
91  }
92 
94  return true;
95  } else {
96  return false;
97  }
98 }
99 
101  StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();
102 
103  if (stop_info_sp) {
104  lldb::addr_t addr = GetStopAddress();
105  DynamicCheckerFunctions *checkers =
106  m_thread.GetProcess()->GetDynamicCheckers();
107  StreamString s;
108 
109  if (checkers && checkers->DoCheckersExplainStop(addr, s))
110  stop_info_sp->SetDescription(s.GetData());
111  }
112 
113  return stop_info_sp;
114 }
115 
118  m_user_expression_sp->DidFinishExecuting();
119 }
void SetOkayToDiscard(bool value)
Definition: ThreadPlan.h:444
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const char * GetData() const
Definition: StreamString.h:43
bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message)
"lldb/Expression/IRDynamicChecks.h" Encapsulates dynamic check functions used by expressions.
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:57
virtual bool MischiefManaged()
Definition: ThreadPlan.cpp:57
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
A section + offset based address class.
Definition: Address.h:80
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
uint64_t addr_t
Definition: lldb-types.h:83
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
lldb::StopInfoSP GetRealStopInfo() override
Definition: SBAddress.h:15
bool SetIsMasterPlan(bool value)
Definition: ThreadPlan.h:436
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.h:372
#define LIBLLDB_LOG_STEP
Definition: Logging.h:21
void Printf(const char *format,...) __attribute__((format(printf
Definition: Log.cpp:113