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 LLDB_TARGET_THREADPLANCALLFUNCTION_H
10 #define LLDB_TARGET_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 DidPop
72  // methods should call this so that the thread state gets restored if the
73  // plan gets discarded.
74  void DidPop() 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  virtual lldb::StopInfoSP GetRealStopInfo() {
86  return m_real_stop_info_sp;
87  else
88  return GetPrivateStopInfo();
89  }
90 
92 
93  void 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:
150  const ThreadPlanCallFunction &
151  operator=(const ThreadPlanCallFunction &) = delete;
152 };
153 
154 } // namespace lldb_private
155 
156 #endif // LLDB_TARGET_THREADPLANCALLFUNCTION_H
lldb_private::ThreadPlanCallFunction::DidPop
void DidPop() override
Definition: ThreadPlanCallFunction.cpp:212
lldb_private::ThreadPlanCallFunction::m_return_type
CompilerType m_return_type
Definition: ThreadPlanCallFunction.h:148
lldb_private::ThreadPlanCallFunction::operator=
const ThreadPlanCallFunction & operator=(const ThreadPlanCallFunction &)=delete
lldb_private::ThreadPlanCallFunction::ShouldReportStop
Vote ShouldReportStop(Event *event_ptr) override
Definition: ThreadPlanCallFunction.cpp:237
lldb_private::ThreadPlanCallFunction::SetReturnValue
virtual void SetReturnValue()
Definition: ThreadPlanCallFunction.cpp:461
lldb_private::ABI
Definition: ABI.h:27
lldb_private::Event
Definition: Event.h:180
lldb_private::ThreadPlanCallFunction::ThreadPlanCallFunction
ThreadPlanCallFunction(Thread &thread, const Address &function, const CompilerType &return_type, llvm::ArrayRef< lldb::addr_t > args, const EvaluateExpressionOptions &options)
lldb_private::ThreadPlanCallFunction::GetStopAddress
lldb::addr_t GetStopAddress()
Definition: ThreadPlanCallFunction.h:91
lldb_private::ThreadPlanCallFunction::m_trap_exceptions
bool m_trap_exceptions
Definition: ThreadPlanCallFunction.h:123
lldb_private::EvaluateExpressionOptions
Definition: Target.h:259
lldb_private::ThreadPlanCallFunction::m_cxx_language_runtime
LanguageRuntime * m_cxx_language_runtime
Definition: ThreadPlanCallFunction.h:128
lldb_private::ThreadPlanCallFunction::m_function_addr
Address m_function_addr
Definition: ThreadPlanCallFunction.h:124
lldb_private::ThreadPlanCallFunction::m_should_clear_cxx_exception_bp
bool m_should_clear_cxx_exception_bp
Definition: ThreadPlanCallFunction.h:143
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ThreadPlanCallFunction::GetReturnValueObject
lldb::ValueObjectSP GetReturnValueObject() override
Definition: ThreadPlanCallFunction.h:62
lldb_private::ThreadPlanCallFunction::m_subplan_sp
lldb::ThreadPlanSP m_subplan_sp
Definition: ThreadPlanCallFunction.h:127
lldb_private::ThreadPlanCallFunction
Definition: ThreadPlanCallFunction.h:20
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ThreadPlan
Definition: ThreadPlan.h:282
lldb_private::ThreadPlanCallFunction::m_takedown_done
bool m_takedown_done
Definition: ThreadPlanCallFunction.h:140
lldb_private::ThreadPlanCallFunction::m_function_sp
lldb::addr_t m_function_sp
Definition: ThreadPlanCallFunction.h:126
lldb_private::Thread
Definition: Thread.h:60
lldb_private::ThreadPlanCallFunction::GetPlanRunState
lldb::StateType GetPlanRunState() override
Definition: ThreadPlanCallFunction.cpp:361
lldb_private::ThreadPlanCallFunction::DoPlanExplainsStop
bool DoPlanExplainsStop(Event *event_ptr) override
Definition: ThreadPlanCallFunction.cpp:244
lldb_private::ThreadPlanCallFunction::ClearBreakpoints
void ClearBreakpoints()
Definition: ThreadPlanCallFunction.cpp:417
lldb_private::ThreadPlanCallFunction::BreakpointsExplainStop
bool BreakpointsExplainStop()
Definition: ThreadPlanCallFunction.cpp:426
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::ThreadPlanCallFunction::MischiefManaged
bool MischiefManaged() override
Definition: ThreadPlanCallFunction.cpp:384
lldb_private::ThreadPlanCallFunction::m_real_stop_info_sp
lldb::StopInfoSP m_real_stop_info_sp
Definition: ThreadPlanCallFunction.h:132
lldb_private::ThreadPlanCallFunction::DidPush
void DidPush() override
Definition: ThreadPlanCallFunction.cpp:363
lldb_private::ThreadPlanCallFunction::ReportRegisterState
void ReportRegisterState(const char *message)
Definition: ThreadPlanCallFunction.cpp:145
lldb_private::LanguageRuntime
Definition: LanguageRuntime.h:60
lldb_private::ThreadPlanCallFunction::m_valid
bool m_valid
Definition: ThreadPlanCallFunction.h:118
Thread.h
lldb_private::ThreadPlanCallFunction::m_stop_address
lldb::addr_t m_stop_address
Definition: ThreadPlanCallFunction.h:144
lldb_private::ThreadPlanCallFunction::WillStop
bool WillStop() override
Definition: ThreadPlanCallFunction.cpp:382
lldb-private.h
ThreadPlan.h
lldb_private::ThreadPlanCallFunction::RestoreThreadState
void RestoreThreadState() override
Definition: ThreadPlanCallFunction.cpp:457
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
lldb_private::ThreadPlanCallFunction::ConstructorSetup
bool ConstructorSetup(Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr, lldb::addr_t &function_load_addr)
Definition: ThreadPlanCallFunction.cpp:33
lldb_private::ThreadPlanCallFunction::StopOthers
bool StopOthers() override
Definition: ThreadPlanCallFunction.cpp:359
lldb_private::Address
Definition: Address.h:59
lldb_private::ThreadPlanCallFunction::ShouldStop
bool ShouldStop(Event *event_ptr) override
Definition: ThreadPlanCallFunction.cpp:345
lldb_private::ThreadPlanCallFunction::ThreadDestroyed
void ThreadDestroyed() override
Definition: ThreadPlanCallFunction.h:95
lldb_private::ThreadPlanCallFunction::m_unwind_on_error
bool m_unwind_on_error
Definition: ThreadPlanCallFunction.h:120
lldb_private::ThreadPlanCallFunction::GetRealStopInfo
virtual lldb::StopInfoSP GetRealStopInfo()
Definition: ThreadPlanCallFunction.h:84
lldb_private::Vote
Vote
Definition: lldb-private-enumerations.h:59
lldb_private::Thread::ThreadStateCheckpoint
Definition: Thread.h:119
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::ThreadPlanCallFunction::m_objc_language_runtime
LanguageRuntime * m_objc_language_runtime
Definition: ThreadPlanCallFunction.h:129
lldb_private::ThreadPlanCallFunction::m_return_valobj_sp
lldb::ValueObjectSP m_return_valobj_sp
Definition: ThreadPlanCallFunction.h:137
lldb_private::ThreadPlanCallFunction::m_debug_execution
bool m_debug_execution
Definition: ThreadPlanCallFunction.h:122
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ThreadPlanCallFunction::SetStopOthers
void SetStopOthers(bool new_value) override
Definition: ThreadPlanCallFunction.cpp:453
lldb_private::ThreadPlanCallFunction::m_stop_other_threads
bool m_stop_other_threads
Definition: ThreadPlanCallFunction.h:119
lldb_private::ThreadPlanCallFunction::~ThreadPlanCallFunction
~ThreadPlanCallFunction() override
Definition: ThreadPlanCallFunction.cpp:141
lldb_private::ThreadPlanCallFunction::m_constructor_errors
StreamString m_constructor_errors
Definition: ThreadPlanCallFunction.h:136
lldb_private::ThreadPlanCallFunction::m_start_addr
Address m_start_addr
Definition: ThreadPlanCallFunction.h:125
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
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::ThreadPlanCallFunction::m_ignore_breakpoints
bool m_ignore_breakpoints
Definition: ThreadPlanCallFunction.h:121
lldb_private::ThreadPlanCallFunction::m_should_clear_objc_exception_bp
bool m_should_clear_objc_exception_bp
Definition: ThreadPlanCallFunction.h:142
lldb_private::ThreadPlan::GetPrivateStopInfo
lldb::StopInfoSP GetPrivateStopInfo()
Definition: ThreadPlan.h:510
lldb_private::ThreadPlanCallFunction::GetFunctionStackPointer
lldb::addr_t GetFunctionStackPointer()
Definition: ThreadPlanCallFunction.h:69
lldb_private::ThreadPlanCallFunction::ValidatePlan
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
Definition: ThreadPlanCallFunction.cpp:223
lldb_private::ThreadPlanCallFunction::SetBreakpoints
void SetBreakpoints()
Definition: ThreadPlanCallFunction.cpp:398
lldb_private::ThreadPlanCallFunction::m_stored_thread_state
Thread::ThreadStateCheckpoint m_stored_thread_state
Definition: ThreadPlanCallFunction.h:130
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