LLDB  mainline
LanguageRuntime.h
Go to the documentation of this file.
1 //===-- LanguageRuntime.h ---------------------------------------------------*-
2 // C++ -*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_TARGET_LANGUAGERUNTIME_H
11 #define LLDB_TARGET_LANGUAGERUNTIME_H
12 
16 #include "lldb/Core/Value.h"
17 #include "lldb/Core/ValueObject.h"
19 #include "lldb/Symbol/DeclVendor.h"
21 #include "lldb/Target/Runtime.h"
22 #include "lldb/lldb-private.h"
23 #include "lldb/lldb-public.h"
24 
25 namespace lldb_private {
26 
28 public:
29  ExceptionSearchFilter(const lldb::TargetSP &target_sp,
30  lldb::LanguageType language,
31  bool update_module_list = true);
32 
33  ~ExceptionSearchFilter() override = default;
34 
35  bool ModulePasses(const lldb::ModuleSP &module_sp) override;
36 
37  bool ModulePasses(const FileSpec &spec) override;
38 
39  void Search(Searcher &searcher) override;
40 
41  void GetDescription(Stream *s) override;
42 
43  static SearchFilter *
45  const StructuredData::Dictionary &data_dict,
46  Status &error);
47 
49 
50 protected:
53  lldb::SearchFilterSP m_filter_sp;
54 
55  lldb::SearchFilterSP DoCreateCopy() override;
56 
58 };
59 
60 class LanguageRuntime : public Runtime, public PluginInterface {
61 public:
62  static LanguageRuntime *FindPlugin(Process *process,
63  lldb::LanguageType language);
64 
65  static void InitializeCommands(CommandObject *parent);
66 
67  virtual lldb::LanguageType GetLanguageType() const = 0;
68 
69  virtual bool GetObjectDescription(Stream &str, ValueObject &object) = 0;
70 
71  virtual bool GetObjectDescription(Stream &str, Value &value,
72  ExecutionContextScope *exe_scope) = 0;
73 
74  // this call should return true if it could set the name and/or the type
75  virtual bool GetDynamicTypeAndAddress(ValueObject &in_value,
76  lldb::DynamicValueType use_dynamic,
77  TypeAndOrName &class_type_or_name,
78  Address &address,
79  Value::ValueType &value_type) = 0;
80 
81  // This call should return a CompilerType given a generic type name and an
82  // ExecutionContextScope in which one can actually fetch any specialization
83  // information required.
85  ConstString abstract_type_name) {
86  return CompilerType();
87  }
88 
89  // This should be a fast test to determine whether it is likely that this
90  // value would have a dynamic type.
91  virtual bool CouldHaveDynamicValue(ValueObject &in_value) = 0;
92 
93  // The contract for GetDynamicTypeAndAddress() is to return a "bare-bones"
94  // dynamic type For instance, given a Base* pointer,
95  // GetDynamicTypeAndAddress() will return the type of Derived, not Derived*.
96  // The job of this API is to correct this misalignment between the static
97  // type and the discovered dynamic type
98  virtual TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
99  ValueObject &static_value) = 0;
100 
101  virtual void SetExceptionBreakpoints() {}
102 
103  virtual void ClearExceptionBreakpoints() {}
104 
105  virtual bool ExceptionBreakpointsAreSet() { return false; }
106 
107  virtual bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason) {
108  return false;
109  }
110 
111  static lldb::BreakpointSP
113  bool catch_bp, bool throw_bp,
114  bool is_internal = false);
115 
116  static lldb::BreakpointPreconditionSP
117  GetExceptionPrecondition(lldb::LanguageType language, bool throw_bp);
118 
119  virtual lldb::ValueObjectSP GetExceptionObjectForThread(
120  lldb::ThreadSP thread_sp) {
121  return lldb::ValueObjectSP();
122  }
123 
124  virtual lldb::ThreadSP GetBacktraceThreadFromException(
125  lldb::ValueObjectSP thread_sp) {
126  return lldb::ThreadSP();
127  }
128 
129  virtual DeclVendor *GetDeclVendor() { return nullptr; }
130 
131  virtual lldb::BreakpointResolverSP
132  CreateExceptionResolver(const lldb::BreakpointSP &bkpt,
133  bool catch_bp, bool throw_bp) = 0;
134 
135  virtual lldb::SearchFilterSP CreateExceptionSearchFilter() {
136  return m_process->GetTarget().GetSearchFilterForModule(nullptr);
137  }
138 
139  virtual bool GetTypeBitSize(const CompilerType &compiler_type,
140  uint64_t &size) {
141  return false;
142  }
143 
144  virtual void SymbolsDidLoad(const ModuleList &module_list) { return; }
145 
146  virtual lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
147  bool stop_others) = 0;
148 
149  /// Identify whether a name is a runtime value that should not be hidden by
150  /// from the user interface.
151  virtual bool IsAllowedRuntimeValue(ConstString name) { return false; }
152 
153  virtual llvm::Optional<CompilerType> GetRuntimeType(CompilerType base_type) {
154  return llvm::None;
155  }
156 
157  virtual void ModulesDidLoad(const ModuleList &module_list) override {}
158 
159  // Called by ClangExpressionParser::PrepareForExecution to query for any
160  // custom LLVM IR passes that need to be run before an expression is
161  // assembled and run.
162  virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes) {
163  return false;
164  }
165 
166  // Given the name of a runtime symbol (e.g. in Objective-C, an ivar offset
167  // symbol), try to determine from the runtime what the value of that symbol
168  // would be. Useful when the underlying binary is stripped.
170  return LLDB_INVALID_ADDRESS;
171  }
172 
173  virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
174  static char ID;
175 
176  /// A language runtime may be able to provide a special UnwindPlan for
177  /// the frame represented by the register contents \a regctx when that
178  /// frame is not following the normal ABI conventions.
179  /// Instead of using the normal UnwindPlan for the function, we will use
180  /// this special UnwindPlan for this one backtrace.
181  /// One example of this would be a language that has asynchronous functions,
182  /// functions that may not be currently-executing, while waiting on other
183  /// asynchronous calls they made, but are part of a logical backtrace that
184  /// we want to show the developer because that's how they think of the
185  /// program flow.
186  ///
187  /// \param[in] thread
188  /// The thread that the unwind is happening on.
189  ///
190  /// \param[in] regctx
191  /// The RegisterContext for the frame we need to create an UnwindPlan.
192  /// We don't yet have a StackFrame when we're selecting the UnwindPlan.
193  ///
194  /// \param[out] behaves_like_zeroth_frame
195  /// With normal ABI calls, all stack frames except the zeroth frame need
196  /// to have the return-pc value backed up by 1 for symbolication purposes.
197  /// For these LanguageRuntime unwind plans, they may not follow normal ABI
198  /// calling conventions and the return pc may need to be symbolicated
199  /// as-is.
200  ///
201  /// \return
202  /// Returns an UnwindPlan to find the caller frame if it should be used,
203  /// instead of the UnwindPlan that would normally be used for this
204  /// function.
205  static lldb::UnwindPlanSP
208  bool &behaves_like_zeroth_frame);
209 
210 protected:
211  // The static GetRuntimeUnwindPlan method above is only implemented in the
212  // base class; subclasses may override this protected member if they can
213  // provide one of these UnwindPlans.
214  virtual lldb::UnwindPlanSP
215  GetRuntimeUnwindPlan(lldb::ProcessSP process_sp,
217  bool &behaves_like_zeroth_frame) {
218  return lldb::UnwindPlanSP();
219  }
220 
221  LanguageRuntime(Process *process);
222 };
223 
224 } // namespace lldb_private
225 
226 #endif // LLDB_TARGET_LANGUAGERUNTIME_H
Runtime.h
lldb-public.h
lldb_private::StructuredData::Dictionary
Definition: StructuredData.h:352
lldb_private::LanguageRuntime::IsAllowedRuntimeValue
virtual bool IsAllowedRuntimeValue(ConstString name)
Identify whether a name is a runtime value that should not be hidden by from the user interface.
Definition: LanguageRuntime.h:151
lldb_private::ExceptionSearchFilter::Search
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
Definition: LanguageRuntime.cpp:44
lldb_private::Value
Definition: Value.h:38
lldb_private::LanguageRuntime::FindPlugin
static LanguageRuntime * FindPlugin(Process *process, lldb::LanguageType language)
Definition: LanguageRuntime.cpp:203
lldb_private::LanguageRuntime::GetIRPasses
virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes)
Definition: LanguageRuntime.h:162
lldb_private::PluginInterface
Definition: PluginInterface.h:16
DeclVendor.h
lldb_private::ExceptionSearchFilter::SerializeToStructuredData
StructuredData::ObjectSP SerializeToStructuredData() override
Definition: LanguageRuntime.cpp:93
lldb_private::LanguageRuntime::GetObjectDescription
virtual bool GetObjectDescription(Stream &str, ValueObject &object)=0
lldb_private::LanguageRuntime::CreateExceptionBreakpoint
static lldb::BreakpointSP CreateExceptionBreakpoint(Target &target, lldb::LanguageType language, bool catch_bp, bool throw_bp, bool is_internal=false)
Definition: LanguageRuntime.cpp:239
lldb_private::LanguageRuntime::GetDynamicTypeAndAddress
virtual bool GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, Address &address, Value::ValueType &value_type)=0
lldb_private::Process
Definition: Process.h:341
lldb_private::LanguageRuntime::GetRuntimeType
virtual llvm::Optional< CompilerType > GetRuntimeType(CompilerType base_type)
Definition: LanguageRuntime.h:153
lldb_private::LanguageRuntime::GetStepThroughTrampolinePlan
virtual lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop_others)=0
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1194
lldb_private::LanguageRuntime::CouldHaveDynamicValue
virtual bool CouldHaveDynamicValue(ValueObject &in_value)=0
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::LanguageRuntime::GetLanguageType
virtual lldb::LanguageType GetLanguageType() const =0
BreakpointResolver.h
lldb_private::Stream
Definition: Stream.h:28
lldb_private::LanguageRuntime::CreateExceptionResolver
virtual lldb::BreakpointResolverSP CreateExceptionResolver(const lldb::BreakpointSP &bkpt, bool catch_bp, bool throw_bp)=0
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::LanguageRuntime::isA
virtual bool isA(const void *ClassID) const
Definition: LanguageRuntime.h:173
lldb_private::ExceptionSearchFilter::ExceptionSearchFilter
ExceptionSearchFilter(const lldb::TargetSP &target_sp, lldb::LanguageType language, bool update_module_list=true)
Definition: LanguageRuntime.cpp:21
lldb_private::Target
Definition: Target.h:445
lldb_private::LanguageRuntime::ClearExceptionBreakpoints
virtual void ClearExceptionBreakpoints()
Definition: LanguageRuntime.h:103
lldb_private::LanguageRuntime::CreateExceptionSearchFilter
virtual lldb::SearchFilterSP CreateExceptionSearchFilter()
Definition: LanguageRuntime.h:135
lldb_private::LanguageRuntime::SetExceptionBreakpoints
virtual void SetExceptionBreakpoints()
Definition: LanguageRuntime.h:101
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Target::GetSearchFilterForModule
lldb::SearchFilterSP GetSearchFilterForModule(const FileSpec *containingModule)
Definition: Target.cpp:508
lldb_private::LanguageRuntime::GetRuntimeUnwindPlan
static lldb::UnwindPlanSP GetRuntimeUnwindPlan(lldb_private::Thread &thread, lldb_private::RegisterContext *regctx, bool &behaves_like_zeroth_frame)
A language runtime may be able to provide a special UnwindPlan for the frame represented by the regis...
Definition: LanguageRuntime.cpp:263
lldb_private::LanguageRuntime::GetTypeBitSize
virtual bool GetTypeBitSize(const CompilerType &compiler_type, uint64_t &size)
Definition: LanguageRuntime.h:139
lldb_private::ExceptionSearchFilter::UpdateModuleListIfNeeded
void UpdateModuleListIfNeeded()
Definition: LanguageRuntime.cpp:56
lldb_private::LLVMUserExpression::IRPasses
Definition: LLVMUserExpression.h:48
lldb_private::LanguageRuntime::GetRuntimeUnwindPlan
virtual lldb::UnwindPlanSP GetRuntimeUnwindPlan(lldb::ProcessSP process_sp, lldb_private::RegisterContext *regctx, bool &behaves_like_zeroth_frame)
Definition: LanguageRuntime.h:215
lldb_private::ExceptionSearchFilter::m_language
lldb::LanguageType m_language
Definition: LanguageRuntime.h:51
lldb_private::ModuleList
Definition: ModuleList.h:71
lldb_private::SearchFilter
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::Thread
Definition: Thread.h:62
lldb_private::Runtime::m_process
Process * m_process
Definition: Runtime.h:29
lldb_private::LanguageRuntime::FixUpDynamicType
virtual TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, ValueObject &static_value)=0
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::LanguageRuntime::GetExceptionPrecondition
static lldb::BreakpointPreconditionSP GetExceptionPrecondition(lldb::LanguageType language, bool throw_bp)
Definition: LanguageRuntime.cpp:220
lldb_private::ExceptionSearchFilter::ModulePasses
bool ModulePasses(const lldb::ModuleSP &module_sp) override
Call this method with a Module to see if that module passes the filter.
Definition: LanguageRuntime.cpp:30
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::LanguageRuntime::InitializeCommands
static void InitializeCommands(CommandObject *parent)
Definition: LanguageRuntime.cpp:281
lldb_private::ExceptionSearchFilter
Definition: LanguageRuntime.h:27
PluginInterface.h
lldb_private::Value::ValueType
ValueType
Type that describes Value::m_value.
Definition: Value.h:41
lldb_private::ExceptionSearchFilter::DoCreateCopy
lldb::SearchFilterSP DoCreateCopy() override
Definition: LanguageRuntime.cpp:81
lldb_private::LanguageRuntime::ExceptionBreakpointsExplainStop
virtual bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason)
Definition: LanguageRuntime.h:107
lldb::DynamicValueType
DynamicValueType
Definition: lldb-enumerations.h:494
lldb_private::LanguageRuntime
Definition: LanguageRuntime.h:60
lldb_private::LanguageRuntime::ModulesDidLoad
virtual void ModulesDidLoad(const ModuleList &module_list) override
Called when modules have been loaded in the process.
Definition: LanguageRuntime.h:157
lldb_private::LanguageRuntime::GetDeclVendor
virtual DeclVendor * GetDeclVendor()
Definition: LanguageRuntime.h:129
lldb_private::Runtime
Definition: Runtime.h:15
lldb_private::LanguageRuntime::SymbolsDidLoad
virtual void SymbolsDidLoad(const ModuleList &module_list)
Definition: LanguageRuntime.h:144
lldb_private::RegisterContext
Definition: RegisterContext.h:17
ValueObject.h
lldb-private.h
lldb_private::LanguageRuntime::GetBacktraceThreadFromException
virtual lldb::ThreadSP GetBacktraceThreadFromException(lldb::ValueObjectSP thread_sp)
Definition: LanguageRuntime.h:124
lldb_private::CommandObject
Definition: CommandObject.h:67
lldb_private::Status
Definition: Status.h:44
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::DeclVendor
Definition: DeclVendor.h:20
lldb_private::Address
Definition: Address.h:59
lldb_private::ExceptionSearchFilter::~ExceptionSearchFilter
~ExceptionSearchFilter() override=default
ExecutionContextScope.h
lldb_private::LanguageRuntime::GetExceptionObjectForThread
virtual lldb::ValueObjectSP GetExceptionObjectForThread(lldb::ThreadSP thread_sp)
Definition: LanguageRuntime.h:119
lldb_private::LanguageRuntime::ID
static char ID
Definition: LanguageRuntime.h:174
lldb_private::LanguageRuntime::GetConcreteType
virtual CompilerType GetConcreteType(ExecutionContextScope *exe_scope, ConstString abstract_type_name)
Definition: LanguageRuntime.h:84
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::ExceptionSearchFilter::GetDescription
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
Definition: LanguageRuntime.cpp:50
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::ExceptionSearchFilter::m_filter_sp
lldb::SearchFilterSP m_filter_sp
Definition: LanguageRuntime.h:53
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
BreakpointResolverName.h
lldb_private::LanguageRuntime::LanguageRuntime
LanguageRuntime(Process *process)
Definition: LanguageRuntime.cpp:217
lldb_private::Searcher
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:42
lldb_private::ExceptionSearchFilter::CreateFromStructuredData
static SearchFilter * CreateFromStructuredData(Target &target, const StructuredData::Dictionary &data_dict, Status &error)
Definition: LanguageRuntime.cpp:86
lldb_private::TypeAndOrName
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
Definition: Type.h:394
lldb_private::LanguageRuntime::ExceptionBreakpointsAreSet
virtual bool ExceptionBreakpointsAreSet()
Definition: LanguageRuntime.h:105
LLVMUserExpression.h
Value.h
lldb_private::LanguageRuntime::LookupRuntimeSymbol
virtual lldb::addr_t LookupRuntimeSymbol(ConstString name)
Definition: LanguageRuntime.h:169
lldb_private::ExceptionSearchFilter::m_language_runtime
LanguageRuntime * m_language_runtime
Definition: LanguageRuntime.h:52