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/Target/Runtime.h" 22 #include "lldb/lldb-private.h" 23 #include "lldb/lldb-public.h" 24 25 namespace lldb_private { 26 27 class ExceptionSearchFilter : public SearchFilter { 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 * 44 CreateFromStructuredData(Target &target, 45 const StructuredData::Dictionary &data_dict, 46 Status &error); 47 48 StructuredData::ObjectSP SerializeToStructuredData() override; 49 50 protected: 51 lldb::LanguageType m_language; 52 LanguageRuntime *m_language_runtime; 53 lldb::SearchFilterSP m_filter_sp; 54 55 lldb::SearchFilterSP DoCreateCopy() override; 56 57 void UpdateModuleListIfNeeded(); 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. 84 virtual CompilerType GetConcreteType(ExecutionContextScope *exe_scope, 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 112 CreateExceptionBreakpoint(Target &target, lldb::LanguageType language, 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. 169 virtual lldb::addr_t LookupRuntimeSymbol(ConstString name) { 170 return LLDB_INVALID_ADDRESS; 171 } 172 173 virtual bool isA(const void *ClassID) const { return ClassID == &ID; } 174 static char ID; 175 176 protected: 177 LanguageRuntime(Process *process); 178 }; 179 180 } // namespace lldb_private 181 182 #endif // LLDB_TARGET_LANGUAGERUNTIME_H 183