LLDB  mainline
ThreadPlanCallFunction.h
Go to the documentation of this file.
1 //===-- ThreadPlanCallFunction.h --------------------------------*- 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 
9 #ifndef liblldb_ThreadPlanCallFunction_h_
10 #define liblldb_ThreadPlanCallFunction_h_
11 
12 #include "lldb/Target/Thread.h"
13 #include "lldb/Target/ThreadPlan.h"
14 #include "lldb/lldb-private.h"
15 
16 #include "llvm/ADT/ArrayRef.h"
17 
18 namespace lldb_private {
19 
21  // Create a thread plan to call a function at the address passed in the
22  // "function" argument. If you plan to call GetReturnValueObject, then pass
23  // in the return type, otherwise just pass in an invalid CompilerType.
24 public:
25  ThreadPlanCallFunction(Thread &thread, const Address &function,
26  const CompilerType &return_type,
27  llvm::ArrayRef<lldb::addr_t> args,
28  const EvaluateExpressionOptions &options);
29 
30  ThreadPlanCallFunction(Thread &thread, const Address &function,
31  const EvaluateExpressionOptions &options);
32 
33  ~ThreadPlanCallFunction() override;
34 
35  void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
36 
37  bool ValidatePlan(Stream *error) override;
38 
39  bool ShouldStop(Event *event_ptr) override;
40 
41  Vote ShouldReportStop(Event *event_ptr) override;
42 
43  bool StopOthers() override;
44 
46 
47  void DidPush() override;
48 
49  bool WillStop() override;
50 
51  bool MischiefManaged() override;
52 
53  // To get the return value from a function call you must create a
54  // lldb::ValueSP that contains a valid clang type in its context and call
55  // RequestReturnValue. The ValueSP will be stored and when the function is
56  // done executing, the object will check if there is a requested return
57  // value. If there is, the return value will be retrieved using the
58  // ABI::GetReturnValue() for the ABI in the process. Then after the thread
59  // plan is complete, you can call "GetReturnValue()" to retrieve the value
60  // that was extracted.
61 
62  lldb::ValueObjectSP GetReturnValueObject() override {
63  return m_return_valobj_sp;
64  }
65 
66  // Return the stack pointer that the function received on entry. Any stack
67  // address below this should be considered invalid after the function has
68  // been cleaned up.
70 
71  // Classes that derive from FunctionCaller, and implement their own WillPop
72  // methods should call this so that the thread state gets restored if the
73  // plan gets discarded.
74  void WillPop() override;
75 
76  // If the thread plan stops mid-course, this will be the stop reason that
77  // interrupted us. Once DoTakedown is called, this will be the real stop
78  // reason at the end of the function call. If it hasn't been set for one or
79  // the other of these reasons, we'll return the PrivateStopReason. This is
80  // needed because we want the CallFunction thread plans not to show up as the
81  // stop reason. But if something bad goes wrong, it is nice to be able to
82  // tell the user what really happened.
83 
84  lldb::StopInfoSP GetRealStopInfo() override {
86  return m_real_stop_info_sp;
87  else
88  return GetPrivateStopInfo();
89  }
90 
92 
93  bool RestoreThreadState() override;
94 
95  void ThreadDestroyed() override { m_takedown_done = true; }
96 
97  void SetStopOthers(bool new_value) override;
98 
99 protected:
100  void ReportRegisterState(const char *message);
101 
102  bool DoPlanExplainsStop(Event *event_ptr) override;
103 
104  virtual void SetReturnValue();
105 
106  bool ConstructorSetup(Thread &thread, ABI *&abi,
107  lldb::addr_t &start_load_addr,
108  lldb::addr_t &function_load_addr);
109 
110  virtual void DoTakedown(bool success);
111 
112  void SetBreakpoints();
113 
114  void ClearBreakpoints();
115 
116  bool BreakpointsExplainStop();
117 
118  bool m_valid;
127  lldb::ThreadPlanSP m_subplan_sp;
131  lldb::StopInfoSP
132  m_real_stop_info_sp; // In general we want to hide call function
133  // thread plans, but for reporting purposes, it's
134  // nice to know the real stop reason. This gets set
135  // in DoTakedown.
137  lldb::ValueObjectSP m_return_valobj_sp; // If this contains a valid pointer,
138  // use the ABI to extract values when
139  // complete
140  bool m_takedown_done; // We want to ensure we only do the takedown once. This
141  // ensures that.
144  lldb::addr_t m_stop_address; // This is the address we stopped at. Also set
145  // in DoTakedown;
146 
147 private:
148  CompilerType m_return_type;
149  DISALLOW_COPY_AND_ASSIGN(ThreadPlanCallFunction);
150 };
151 
152 } // namespace lldb_private
153 
154 #endif // liblldb_ThreadPlanCallFunction_h_
lldb::StopInfoSP GetPrivateStopInfo()
Definition: ThreadPlan.h:564
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
Thread::ThreadStateCheckpoint m_stored_thread_state
lldb::ValueObjectSP GetReturnValueObject() override
void SetStopOthers(bool new_value) override
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
ThreadPlanCallFunction(Thread &thread, const Address &function, const CompilerType &return_type, llvm::ArrayRef< lldb::addr_t > args, const EvaluateExpressionOptions &options)
Vote ShouldReportStop(Event *event_ptr) override
A section + offset based address class.
Definition: Address.h:80
bool ShouldStop(Event *event_ptr) override
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
bool ConstructorSetup(Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr, lldb::addr_t &function_load_addr)
bool DoPlanExplainsStop(Event *event_ptr) override