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"
20#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:
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:
55
56 std::unique_ptr<SearchFilter> 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 /// Return the preferred language runtime instance, which in most cases will
71 /// be the current instance.
73 return nullptr;
74 }
75
76 virtual llvm::Error GetObjectDescription(Stream &str,
77 ValueObject &object) = 0;
78
79 virtual llvm::Error
81 ExecutionContextScope *exe_scope) = 0;
82
83 struct VTableInfo {
84 Address addr; /// Address of the vtable's virtual function table
85 Symbol *symbol; /// The vtable symbol from the symbol table
86 };
87 /// Get the vtable information for a given value.
88 ///
89 /// \param[in] in_value
90 /// The value object to try and extract the VTableInfo from.
91 ///
92 /// \param[in] check_type
93 /// If true, the compiler type of \a in_value will be checked to see if
94 /// it is an instance to, or pointer or reference to a class or struct
95 /// that has a vtable. If the type doesn't meet the requirements, an
96 /// error will be returned explaining why the type isn't suitable.
97 ///
98 /// \return
99 /// An error if anything goes wrong while trying to extract the vtable
100 /// or if \a check_type is true and the type doesn't have a vtable.
101 virtual llvm::Expected<VTableInfo> GetVTableInfo(ValueObject &in_value,
102 bool check_type) {
103 return llvm::createStringError(
104 std::errc::invalid_argument,
105 "language doesn't support getting vtable information");
106 }
107
108 /// This call should return true if it could set the name and/or the type
109 /// Sets address to the address of the dynamic type if value_type is set to
110 /// a file or load address. Sets local_buffer to a buffer containing the data
111 /// of the dynamic type if value_type is set to a host address. Callers should
112 /// copy local_buffer over into their own buffer if they want to keep the data
113 /// alive.
115 ValueObject &in_value, lldb::DynamicValueType use_dynamic,
116 TypeAndOrName &class_type_or_name, Address &address,
117 Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) = 0;
118
119 // This call should return a CompilerType given a generic type name and an
120 // ExecutionContextScope in which one can actually fetch any specialization
121 // information required.
123 llvm::StringRef abstract_type_name) {
124 return CompilerType();
125 }
126
127 // This should be a fast test to determine whether it is likely that this
128 // value would have a dynamic type.
129 virtual bool CouldHaveDynamicValue(ValueObject &in_value) = 0;
130
131 // The contract for GetDynamicTypeAndAddress() is to return a "bare-bones"
132 // dynamic type For instance, given a Base* pointer,
133 // GetDynamicTypeAndAddress() will return the type of Derived, not Derived*.
134 // The job of this API is to correct this misalignment between the static
135 // type and the discovered dynamic type
136 virtual TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
137 ValueObject &static_value) = 0;
138
139 /// This allows a language runtime to adjust the location of \p variable
140 /// computed from its debug info, for storage whose indirection is only
141 /// known at runtime.
142 virtual llvm::Error FixupVariableLocation(Variable &variable, Value &value) {
143 return llvm::Error::success();
144 }
145
146 /// This allows a language runtime to evaluate
147 /// DW_OP_entry_value(\p entry_value) in \p frame without call site
148 /// information from the caller, when the runtime knows the value the
149 /// register had on entry. For example, a runtime that unwinds the frame
150 /// with GetRuntimeUnwindPlan() may know how that value relates to the CFA.
151 ///
152 /// \param[in,out] following
153 /// The operations after the DW_OP_entry_value. The runtime may
154 /// evaluate the first of them together with the entry value, and
155 /// consume them from the front, when it knows their combined result
156 /// but not the entry value alone.
157 ///
158 /// \return
159 /// The entry value, or std::nullopt to look it up in the call site
160 /// parameters of the caller.
161 virtual std::optional<Value>
162 EvaluateEntryValue(StackFrame &frame, llvm::ArrayRef<uint8_t> entry_value,
163 llvm::ArrayRef<uint8_t> &following) {
164 return std::nullopt;
165 }
166
167 virtual void SetExceptionBreakpoints() {}
168
170
171 virtual bool ExceptionBreakpointsAreSet() { return false; }
172
174 return false;
175 }
176
177 /// Create a breakpoint that catches an error escaping an expression
178 /// that runs as top-level code, such as a REPL line, where no
179 /// handler encloses it.
181
182 /// Return the error value that reached the breakpoint from
183 /// CreateErrorBackstopBreakpoint, with \p frame stopped there.
185 return {};
186 }
187
188 static lldb::BreakpointSP
190 bool catch_bp, bool throw_bp,
191 bool is_internal = false);
192
194 GetExceptionPrecondition(lldb::LanguageType language, bool throw_bp);
195
200
205
206 virtual DeclVendor *GetDeclVendor() { return nullptr; }
207
210 bool catch_bp, bool throw_bp) = 0;
211
213 return m_process->GetTarget().GetSearchFilterForModule(nullptr);
214 }
215
216 virtual std::optional<uint64_t>
217 GetTypeBitSize(const CompilerType &compiler_type) {
218 return {};
219 }
220
221 virtual void SymbolsDidLoad(const ModuleList &module_list) {}
222
224 bool stop_others) = 0;
225
226 /// Identify whether a name is a runtime value that should not be hidden by
227 /// from the user interface.
228 virtual bool IsAllowedRuntimeValue(llvm::StringRef name) { return false; }
229
230 virtual std::optional<CompilerType> GetRuntimeType(CompilerType base_type) {
231 return std::nullopt;
232 }
233
234 void ModulesDidLoad(const ModuleList &module_list) override {}
235
236 // Called by ClangExpressionParser::PrepareForExecution to query for any
237 // custom LLVM IR passes that need to be run before an expression is
238 // assembled and run.
239 virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes) {
240 return false;
241 }
242
243 virtual bool IsSymbolARuntimeThunk(const Symbol &symbol) { return false; }
244
245 // Given the name of a runtime symbol (e.g. in Objective-C, an ivar offset
246 // symbol), try to determine from the runtime what the value of that symbol
247 // would be. Useful when the underlying binary is stripped.
248 virtual lldb::addr_t LookupRuntimeSymbol(llvm::StringRef name) {
250 }
251
252 virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
253 static char ID;
254
255 /// A language runtime may be able to provide a special UnwindPlan for
256 /// the frame represented by the register contents \a regctx when that
257 /// frame is not following the normal ABI conventions.
258 /// Instead of using the normal UnwindPlan for the function, we will use
259 /// this special UnwindPlan for this one backtrace.
260 /// One example of this would be a language that has asynchronous functions,
261 /// functions that may not be currently-executing, while waiting on other
262 /// asynchronous calls they made, but are part of a logical backtrace that
263 /// we want to show the developer because that's how they think of the
264 /// program flow.
265 ///
266 /// \param[in] thread
267 /// The thread that the unwind is happening on.
268 ///
269 /// \param[in] regctx
270 /// The RegisterContext for the frame we need to create an UnwindPlan.
271 /// We don't yet have a StackFrame when we're selecting the UnwindPlan.
272 ///
273 /// \param[out] behaves_like_zeroth_frame
274 /// With normal ABI calls, all stack frames except the zeroth frame need
275 /// to have the return-pc value backed up by 1 for symbolication purposes.
276 /// For these LanguageRuntime unwind plans, they may not follow normal ABI
277 /// calling conventions and the return pc may need to be symbolicated
278 /// as-is.
279 ///
280 /// \return
281 /// Returns an UnwindPlan to find the caller frame if it should be used,
282 /// instead of the UnwindPlan that would normally be used for this
283 /// function.
284 static lldb::UnwindPlanSP
287 bool &behaves_like_zeroth_frame);
288
289 /// Language runtime plugins can use this API to report
290 /// language-specific runtime information about this compile unit,
291 /// such as additional language version details or feature flags.
293
294protected:
295 // The static GetRuntimeUnwindPlan method above is only implemented in the
296 // base class; subclasses may override this protected member if they can
297 // provide one of these UnwindPlans.
298 virtual lldb::UnwindPlanSP
301 bool &behaves_like_zeroth_frame) {
302 return lldb::UnwindPlanSP();
303 }
304
305 LanguageRuntime(Process *process);
306};
307
308} // namespace lldb_private
309
310#endif // LLDB_TARGET_LANGUAGERUNTIME_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
Generic representation of a type in a programming language.
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.
ExceptionSearchFilter(const lldb::TargetSP &target_sp, lldb::LanguageType language, bool update_module_list=true)
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
~ExceptionSearchFilter() override=default
std::unique_ptr< SearchFilter > DoCreateCopy() override
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 llvm::Error FixupVariableLocation(Variable &variable, Value &value)
This allows a language runtime to adjust the location of variable computed from its debug info,...
virtual StructuredData::ObjectSP GetLanguageSpecificData(SymbolContext sc)
Language runtime plugins can use this API to report language-specific runtime information about this ...
virtual bool IsSymbolARuntimeThunk(const Symbol &symbol)
virtual std::optional< CompilerType > GetRuntimeType(CompilerType base_type)
virtual lldb::LanguageType GetLanguageType() const =0
virtual TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, ValueObject &static_value)=0
virtual lldb::ThreadSP GetBacktraceThreadFromException(lldb::ValueObjectSP thread_sp)
virtual bool GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, Address &address, Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer)=0
This call should return true if it could set the name and/or the type Sets address to the address of ...
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 lldb::ValueObjectSP GetErrorValueAtBackstop(StackFrame &frame)
Return the error value that reached the breakpoint from CreateErrorBackstopBreakpoint,...
virtual bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason)
virtual bool IsAllowedRuntimeValue(llvm::StringRef name)
Identify whether a name is a runtime value that should not be hidden by from the user interface.
virtual LanguageRuntime * GetPreferredLanguageRuntime(ValueObject &in_value)
Return the preferred language runtime instance, which in most cases will be the current instance.
virtual lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop_others)=0
virtual bool isA(const void *ClassID) const
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...
virtual llvm::Expected< VTableInfo > GetVTableInfo(ValueObject &in_value, bool check_type)
Get the vtable information for a given value.
void ModulesDidLoad(const ModuleList &module_list) override
Called when modules have been loaded in the process.
virtual DeclVendor * GetDeclVendor()
virtual lldb::addr_t LookupRuntimeSymbol(llvm::StringRef name)
virtual void SymbolsDidLoad(const ModuleList &module_list)
virtual std::optional< uint64_t > GetTypeBitSize(const CompilerType &compiler_type)
virtual lldb::BreakpointSP CreateErrorBackstopBreakpoint()
Create a breakpoint that catches an error escaping an expression that runs as top-level code,...
static lldb::BreakpointSP CreateExceptionBreakpoint(Target &target, lldb::LanguageType language, bool catch_bp, bool throw_bp, bool is_internal=false)
virtual bool GetIRPasses(LLVMUserExpression::IRPasses &custom_passes)
static void InitializeCommands(CommandObject *parent)
virtual bool CouldHaveDynamicValue(ValueObject &in_value)=0
virtual llvm::Error GetObjectDescription(Stream &str, Value &value, ExecutionContextScope *exe_scope)=0
virtual llvm::Error GetObjectDescription(Stream &str, ValueObject &object)=0
virtual std::optional< Value > EvaluateEntryValue(StackFrame &frame, llvm::ArrayRef< uint8_t > entry_value, llvm::ArrayRef< uint8_t > &following)
This allows a language runtime to evaluate DW_OP_entry_value(entry_value) in frame without call site ...
virtual lldb::SearchFilterSP CreateExceptionSearchFilter()
virtual CompilerType GetConcreteType(ExecutionContextScope *exe_scope, llvm::StringRef abstract_type_name)
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:127
A plug-in interface definition class for debugging a process.
Definition Process.h:369
Process * m_process
Definition Runtime.h:29
Runtime(Process *process)
Definition Runtime.h:17
SearchFilter(const lldb::TargetSP &target_sp)
The basic constructor takes a Target, which gives the space to search.
General Outline: Provides the callback and search depth for the SearchFilter search.
This base class provides an interface to stack frames.
Definition StackFrame.h:44
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
ValueType
Type that describes Value::m_value.
Definition Value.h:42
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::SearchFilter > SearchFilterSP
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::BreakpointPrecondition > BreakpointPreconditionSP
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
Symbol * symbol
Address of the vtable's virtual function table.