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 13 #include "lldb/Breakpoint/BreakpointResolver.h" 14 #include "lldb/Breakpoint/BreakpointResolverName.h" 15 #include "lldb/Core/PluginInterface.h" 16 #include "lldb/Core/Value.h" 17 #include "lldb/Core/ValueObject.h" 18 #include "lldb/Expression/LLVMUserExpression.h" 19 #include "lldb/Symbol/DeclVendor.h" 20 #include "lldb/Target/ExecutionContextScope.h" 21 #include "lldb/lldb-private.h" 22 #include "lldb/lldb-public.h" 23 24 namespace lldb_private { 25 26 class ExceptionSearchFilter : public SearchFilter { 27 public: 28 ExceptionSearchFilter(const lldb::TargetSP &target_sp, 29 lldb::LanguageType language, 30 bool update_module_list = true); 31 32 ~ExceptionSearchFilter() override = default; 33 34 bool ModulePasses(const lldb::ModuleSP &module_sp) override; 35 36 bool ModulePasses(const FileSpec &spec) override; 37 38 void Search(Searcher &searcher) override; 39 40 void GetDescription(Stream *s) override; 41 42 static SearchFilter * 43 CreateFromStructuredData(Target &target, 44 const StructuredData::Dictionary &data_dict, 45 Status &error); 46 47 StructuredData::ObjectSP SerializeToStructuredData() override; 48 49 protected: 50 lldb::LanguageType m_language; 51 LanguageRuntime *m_language_runtime; 52 lldb::SearchFilterSP m_filter_sp; 53 54 lldb::SearchFilterSP DoCreateCopy() override; 55 56 void UpdateModuleListIfNeeded(); 57 }; 58 59 class LanguageRuntime : public PluginInterface { 60 public: 61 ~LanguageRuntime() override; 62 63 static LanguageRuntime *FindPlugin(Process *process, 64 lldb::LanguageType language); 65 66 static void InitializeCommands(CommandObject *parent); 67 68 virtual lldb::LanguageType GetLanguageType() const = 0; 69 70 virtual bool GetObjectDescription(Stream &str, ValueObject &object) = 0; 71 72 virtual bool GetObjectDescription(Stream &str, Value &value, 73 ExecutionContextScope *exe_scope) = 0; 74 75 // this call should return true if it could set the name and/or the type 76 virtual bool GetDynamicTypeAndAddress(ValueObject &in_value, 77 lldb::DynamicValueType use_dynamic, 78 TypeAndOrName &class_type_or_name, 79 Address &address, 80 Value::ValueType &value_type) = 0; 81 82 // This call should return a CompilerType given a generic type name and an 83 // ExecutionContextScope in which one can actually fetch any specialization 84 // information required. 85 virtual CompilerType GetConcreteType(ExecutionContextScope *exe_scope, 86 ConstString abstract_type_name) { 87 return CompilerType(); 88 } 89 90 // This should be a fast test to determine whether it is likely that this 91 // value would have a dynamic type. 92 virtual bool CouldHaveDynamicValue(ValueObject &in_value) = 0; 93 94 // The contract for GetDynamicTypeAndAddress() is to return a "bare-bones" 95 // dynamic type For instance, given a Base* pointer, 96 // GetDynamicTypeAndAddress() will return the type of Derived, not Derived*. 97 // The job of this API is to correct this misalignment between the static 98 // type and the discovered dynamic type 99 virtual TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, 100 ValueObject &static_value) = 0; 101 102 virtual void SetExceptionBreakpoints() {} 103 104 virtual void ClearExceptionBreakpoints() {} 105 106 virtual bool ExceptionBreakpointsAreSet() { return false; } 107 108 virtual bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason) { 109 return false; 110 } 111 112 static lldb::BreakpointSP 113 CreateExceptionBreakpoint(Target &target, lldb::LanguageType language, 114 bool catch_bp, bool throw_bp, 115 bool is_internal = false); 116 117 static lldb::BreakpointPreconditionSP 118 GetExceptionPrecondition(lldb::LanguageType language, bool throw_bp); 119 120 virtual lldb::ValueObjectSP GetExceptionObjectForThread( 121 lldb::ThreadSP thread_sp) { 122 return lldb::ValueObjectSP(); 123 } 124 125 virtual lldb::ThreadSP GetBacktraceThreadFromException( 126 lldb::ValueObjectSP thread_sp) { 127 return lldb::ThreadSP(); 128 } 129 130 Process *GetProcess() { return m_process; } 131 132 Target &GetTargetRef() { return m_process->GetTarget(); } 133 134 virtual DeclVendor *GetDeclVendor() { return nullptr; } 135 136 virtual lldb::BreakpointResolverSP 137 CreateExceptionResolver(const lldb::BreakpointSP &bkpt, 138 bool catch_bp, bool throw_bp) = 0; 139 140 virtual lldb::SearchFilterSP CreateExceptionSearchFilter() { 141 return m_process->GetTarget().GetSearchFilterForModule(nullptr); 142 } 143 144 virtual bool GetTypeBitSize(const CompilerType &compiler_type, 145 uint64_t &size) { 146 return false; 147 } 148 149 virtual void SymbolsDidLoad(const ModuleList &module_list) { return; } 150 151 virtual lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, 152 bool stop_others) = 0; 153 154 /// Identify whether a name is a runtime value that should not be hidden by 155 /// from the user interface. 156 virtual bool IsAllowedRuntimeValue(ConstString name) { return false; } 157 158 virtual llvm::Optional<CompilerType> GetRuntimeType(CompilerType base_type) { 159 return llvm::None; 160 } 161 162 virtual void ModulesDidLoad(const ModuleList &module_list) {} 163 164 // Called by ClangExpressionParser::PrepareForExecution to query for any 165 // custom LLVM IR passes that need to be run before an expression is 166 // assembled and run. 167 virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes) { 168 return false; 169 } 170 171 // Given the name of a runtime symbol (e.g. in Objective-C, an ivar offset 172 // symbol), try to determine from the runtime what the value of that symbol 173 // would be. Useful when the underlying binary is stripped. 174 virtual lldb::addr_t LookupRuntimeSymbol(ConstString name) { 175 return LLDB_INVALID_ADDRESS; 176 } 177 178 virtual bool isA(const void *ClassID) const { return ClassID == &ID; } 179 static char ID; 180 181 protected: 182 // Classes that inherit from LanguageRuntime can see and modify these 183 184 LanguageRuntime(Process *process); 185 Process *m_process; 186 187 private: 188 LanguageRuntime(const LanguageRuntime &) = delete; 189 const LanguageRuntime &operator=(const LanguageRuntime &) = delete; 190 }; 191 192 } // namespace lldb_private 193 194 #endif // LLDB_TARGET_LANGUAGERUNTIME_H 195