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"
21#include "lldb/Target/Runtime.h"
22#include "lldb/lldb-private.h"
23#include "lldb/lldb-public.h"
24#include <optional>
25
26namespace lldb_private {
27
29public:
30 ExceptionSearchFilter(const lldb::TargetSP &target_sp,
31 lldb::LanguageType language,
32 bool update_module_list = true);
33
34 ~ExceptionSearchFilter() override = default;
35
36 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
37
38 bool ModulePasses(const FileSpec &spec) override;
39
40 void Search(Searcher &searcher) override;
41
42 void GetDescription(Stream *s) override;
43
44 static SearchFilter *
46 const StructuredData::Dictionary &data_dict,
47 Status &error);
48
50
51protected:
54 lldb::SearchFilterSP m_filter_sp;
55
56 lldb::SearchFilterSP DoCreateCopy() override;
57
59};
60
61class LanguageRuntime : public Runtime, public PluginInterface {
62public:
63 static LanguageRuntime *FindPlugin(Process *process,
64 lldb::LanguageType language);
65
66 static void InitializeCommands(CommandObject *parent);
67
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.
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
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
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 virtual DeclVendor *GetDeclVendor() { return nullptr; }
131
132 virtual lldb::BreakpointResolverSP
133 CreateExceptionResolver(const lldb::BreakpointSP &bkpt,
134 bool catch_bp, bool throw_bp) = 0;
135
136 virtual lldb::SearchFilterSP CreateExceptionSearchFilter() {
138 }
139
140 virtual bool GetTypeBitSize(const CompilerType &compiler_type,
141 uint64_t &size) {
142 return false;
143 }
144
145 virtual void SymbolsDidLoad(const ModuleList &module_list) {}
146
147 virtual lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
148 bool stop_others) = 0;
149
150 /// Identify whether a name is a runtime value that should not be hidden by
151 /// from the user interface.
152 virtual bool IsAllowedRuntimeValue(ConstString name) { return false; }
153
154 virtual std::optional<CompilerType> GetRuntimeType(CompilerType base_type) {
155 return std::nullopt;
156 }
157
158 void ModulesDidLoad(const ModuleList &module_list) override {}
159
160 // Called by ClangExpressionParser::PrepareForExecution to query for any
161 // custom LLVM IR passes that need to be run before an expression is
162 // assembled and run.
163 virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes) {
164 return false;
165 }
166
167 // Given the name of a runtime symbol (e.g. in Objective-C, an ivar offset
168 // symbol), try to determine from the runtime what the value of that symbol
169 // would be. Useful when the underlying binary is stripped.
172 }
173
174 virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
175 static char ID;
176
177 /// A language runtime may be able to provide a special UnwindPlan for
178 /// the frame represented by the register contents \a regctx when that
179 /// frame is not following the normal ABI conventions.
180 /// Instead of using the normal UnwindPlan for the function, we will use
181 /// this special UnwindPlan for this one backtrace.
182 /// One example of this would be a language that has asynchronous functions,
183 /// functions that may not be currently-executing, while waiting on other
184 /// asynchronous calls they made, but are part of a logical backtrace that
185 /// we want to show the developer because that's how they think of the
186 /// program flow.
187 ///
188 /// \param[in] thread
189 /// The thread that the unwind is happening on.
190 ///
191 /// \param[in] regctx
192 /// The RegisterContext for the frame we need to create an UnwindPlan.
193 /// We don't yet have a StackFrame when we're selecting the UnwindPlan.
194 ///
195 /// \param[out] behaves_like_zeroth_frame
196 /// With normal ABI calls, all stack frames except the zeroth frame need
197 /// to have the return-pc value backed up by 1 for symbolication purposes.
198 /// For these LanguageRuntime unwind plans, they may not follow normal ABI
199 /// calling conventions and the return pc may need to be symbolicated
200 /// as-is.
201 ///
202 /// \return
203 /// Returns an UnwindPlan to find the caller frame if it should be used,
204 /// instead of the UnwindPlan that would normally be used for this
205 /// function.
206 static lldb::UnwindPlanSP
209 bool &behaves_like_zeroth_frame);
210
211protected:
212 // The static GetRuntimeUnwindPlan method above is only implemented in the
213 // base class; subclasses may override this protected member if they can
214 // provide one of these UnwindPlans.
215 virtual lldb::UnwindPlanSP
216 GetRuntimeUnwindPlan(lldb::ProcessSP process_sp,
218 bool &behaves_like_zeroth_frame) {
219 return lldb::UnwindPlanSP();
220 }
221
222 LanguageRuntime(Process *process);
223};
224
225} // namespace lldb_private
226
227#endif // LLDB_TARGET_LANGUAGERUNTIME_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition: Address.h:59
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:39
static SearchFilter * CreateFromStructuredData(Target &target, const StructuredData::Dictionary &data_dict, Status &error)
bool ModulePasses(const lldb::ModuleSP &module_sp) override
Call this method with a Module to see if that module passes the filter.
lldb::SearchFilterSP DoCreateCopy() override
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
~ExceptionSearchFilter() override=default
StructuredData::ObjectSP SerializeToStructuredData() override
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
A file utility class.
Definition: FileSpec.h:56
virtual bool IsAllowedRuntimeValue(ConstString name)
Identify whether a name is a runtime value that should not be hidden by from the user interface.
virtual std::optional< CompilerType > GetRuntimeType(CompilerType base_type)
virtual void SetExceptionBreakpoints()
virtual lldb::LanguageType GetLanguageType() const =0
virtual CompilerType GetConcreteType(ExecutionContextScope *exe_scope, ConstString abstract_type_name)
virtual TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, ValueObject &static_value)=0
virtual lldb::ThreadSP GetBacktraceThreadFromException(lldb::ValueObjectSP thread_sp)
virtual lldb::UnwindPlanSP GetRuntimeUnwindPlan(lldb::ProcessSP process_sp, lldb_private::RegisterContext *regctx, bool &behaves_like_zeroth_frame)
virtual lldb::ValueObjectSP GetExceptionObjectForThread(lldb::ThreadSP thread_sp)
static LanguageRuntime * FindPlugin(Process *process, lldb::LanguageType language)
virtual bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason)
virtual void ClearExceptionBreakpoints()
virtual bool GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, Address &address, Value::ValueType &value_type)=0
virtual lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop_others)=0
virtual bool isA(const void *ClassID) const
virtual lldb::addr_t LookupRuntimeSymbol(ConstString name)
virtual bool ExceptionBreakpointsAreSet()
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...
void ModulesDidLoad(const ModuleList &module_list) override
Called when modules have been loaded in the process.
virtual DeclVendor * GetDeclVendor()
virtual void SymbolsDidLoad(const ModuleList &module_list)
static lldb::BreakpointSP CreateExceptionBreakpoint(Target &target, lldb::LanguageType language, bool catch_bp, bool throw_bp, bool is_internal=false)
virtual bool GetTypeBitSize(const CompilerType &compiler_type, uint64_t &size)
virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes)
static void InitializeCommands(CommandObject *parent)
virtual bool CouldHaveDynamicValue(ValueObject &in_value)=0
virtual bool GetObjectDescription(Stream &str, Value &value, ExecutionContextScope *exe_scope)=0
virtual bool GetObjectDescription(Stream &str, ValueObject &object)=0
virtual lldb::SearchFilterSP CreateExceptionSearchFilter()
virtual lldb::BreakpointResolverSP CreateExceptionResolver(const lldb::BreakpointSP &bkpt, bool catch_bp, bool throw_bp)=0
static lldb::BreakpointPreconditionSP GetExceptionPrecondition(lldb::LanguageType language, bool throw_bp)
A collection class for Module objects.
Definition: ModuleList.h:82
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1220
Process * m_process
Definition: Runtime.h:29
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:42
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
std::shared_ptr< Object > ObjectSP
lldb::SearchFilterSP GetSearchFilterForModule(const FileSpec *containingModule)
Definition: Target.cpp:531
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
Definition: Type.h:410
ValueType
Type that describes Value::m_value.
Definition: Value.h:41
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
LanguageType
Programming language type.
uint64_t addr_t
Definition: lldb-types.h:83