1 //===-- LanguageRuntime.h ---------------------------------------------------*-
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef liblldb_LanguageRuntime_h_
12 #define liblldb_LanguageRuntime_h_
14 #include "lldb/Breakpoint/BreakpointResolver.h"
15 #include "lldb/Breakpoint/BreakpointResolverName.h"
16 #include "lldb/Core/PluginInterface.h"
17 #include "lldb/Core/Value.h"
18 #include "lldb/Core/ValueObject.h"
19 #include "lldb/Expression/LLVMUserExpression.h"
20 #include "lldb/Target/ExecutionContextScope.h"
21 #include "lldb/lldb-private.h"
22 #include "lldb/lldb-public.h"
24 #include "clang/Basic/TargetOptions.h"
26 namespace lldb_private {
28 class ExceptionSearchFilter : public SearchFilter {
30 ExceptionSearchFilter(const lldb::TargetSP &target_sp,
31 lldb::LanguageType language,
32 bool update_module_list = true);
34 ~ExceptionSearchFilter() override = default;
36 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
38 bool ModulePasses(const FileSpec &spec) override;
40 void Search(Searcher &searcher) override;
42 void GetDescription(Stream *s) override;
45 CreateFromStructuredData(Target &target,
46 const StructuredData::Dictionary &data_dict,
49 StructuredData::ObjectSP SerializeToStructuredData() override;
52 lldb::LanguageType m_language;
53 LanguageRuntime *m_language_runtime;
54 lldb::SearchFilterSP m_filter_sp;
56 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
58 void UpdateModuleListIfNeeded();
61 class LanguageRuntime : public PluginInterface {
63 ~LanguageRuntime() override;
65 static LanguageRuntime *FindPlugin(Process *process,
66 lldb::LanguageType language);
68 static void InitializeCommands(CommandObject *parent);
70 virtual lldb::LanguageType GetLanguageType() const = 0;
72 virtual bool GetObjectDescription(Stream &str, ValueObject &object) = 0;
74 virtual bool GetObjectDescription(Stream &str, Value &value,
75 ExecutionContextScope *exe_scope) = 0;
77 // this call should return true if it could set the name and/or the type
78 virtual bool GetDynamicTypeAndAddress(ValueObject &in_value,
79 lldb::DynamicValueType use_dynamic,
80 TypeAndOrName &class_type_or_name,
82 Value::ValueType &value_type) = 0;
84 // This call should return a CompilerType given a generic type name and an
85 // ExecutionContextScope in which one can actually fetch any specialization
86 // information required.
87 virtual CompilerType GetConcreteType(ExecutionContextScope *exe_scope,
88 ConstString abstract_type_name) {
89 return CompilerType();
92 // This should be a fast test to determine whether it is likely that this
93 // value would have a dynamic type.
94 virtual bool CouldHaveDynamicValue(ValueObject &in_value) = 0;
96 // The contract for GetDynamicTypeAndAddress() is to return a "bare-bones"
97 // dynamic type For instance, given a Base* pointer,
98 // GetDynamicTypeAndAddress() will return the type of Derived, not Derived*.
99 // The job of this API is to correct this misalignment between the static
100 // type and the discovered dynamic type
101 virtual TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
102 ValueObject &static_value) = 0;
104 virtual void SetExceptionBreakpoints() {}
106 virtual void ClearExceptionBreakpoints() {}
108 virtual bool ExceptionBreakpointsAreSet() { return false; }
110 virtual bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason) {
114 static lldb::BreakpointSP
115 CreateExceptionBreakpoint(Target &target, lldb::LanguageType language,
116 bool catch_bp, bool throw_bp,
117 bool is_internal = false);
119 static Breakpoint::BreakpointPreconditionSP
120 CreateExceptionPrecondition(lldb::LanguageType language, bool catch_bp,
123 virtual lldb::ValueObjectSP GetExceptionObjectForThread(
124 lldb::ThreadSP thread_sp) {
125 return lldb::ValueObjectSP();
128 virtual lldb::ThreadSP GetBacktraceThreadFromException(
129 lldb::ValueObjectSP thread_sp) {
130 return lldb::ThreadSP();
133 Process *GetProcess() { return m_process; }
135 Target &GetTargetRef() { return m_process->GetTarget(); }
137 virtual lldb::BreakpointResolverSP
138 CreateExceptionResolver(Breakpoint *bkpt, bool catch_bp, bool throw_bp) = 0;
140 virtual lldb::SearchFilterSP CreateExceptionSearchFilter();
142 virtual bool GetTypeBitSize(const CompilerType &compiler_type,
147 virtual bool IsRuntimeSupportValue(ValueObject &valobj) { return false; }
149 virtual void ModulesDidLoad(const ModuleList &module_list) {}
151 // Called by the Clang expression evaluation engine to allow runtimes to
152 // alter the set of target options provided to the compiler. If the options
153 // prototype is modified, runtimes must return true, false otherwise.
154 virtual bool GetOverrideExprOptions(clang::TargetOptions &prototype) {
158 // Called by ClangExpressionParser::PrepareForExecution to query for any
159 // custom LLVM IR passes that need to be run before an expression is
160 // assembled and run.
161 virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes) {
166 //------------------------------------------------------------------
167 // Classes that inherit from LanguageRuntime can see and modify these
168 //------------------------------------------------------------------
170 LanguageRuntime(Process *process);
174 DISALLOW_COPY_AND_ASSIGN(LanguageRuntime);
177 } // namespace lldb_private
179 #endif // liblldb_LanguageRuntime_h_