LLDB mainline
LanguageRuntime.cpp
Go to the documentation of this file.
1//===-- LanguageRuntime.cpp -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
14#include "lldb/Target/Target.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19char LanguageRuntime::ID = 0;
20
22 lldb::LanguageType language,
23 bool update_module_list)
24 : SearchFilter(target_sp, FilterTy::Exception), m_language(language),
26 if (update_module_list)
28}
29
32 if (m_filter_sp)
33 return m_filter_sp->ModulePasses(module_sp);
34 return false;
35}
36
39 if (m_filter_sp)
40 return m_filter_sp->ModulePasses(spec);
41 return false;
42}
43
46 if (m_filter_sp)
47 m_filter_sp->Search(searcher);
48}
49
55
57 ProcessSP process_sp(m_target_sp->GetProcessSP());
58 if (process_sp) {
59 bool refreash_filter = !m_filter_sp;
60 if (m_language_runtime == nullptr) {
61 m_language_runtime = process_sp->GetLanguageRuntime(m_language);
62 refreash_filter = true;
63 } else {
64 LanguageRuntime *language_runtime =
65 process_sp->GetLanguageRuntime(m_language);
66 if (m_language_runtime != language_runtime) {
67 m_language_runtime = language_runtime;
68 refreash_filter = true;
69 }
70 }
71
72 if (refreash_filter && m_language_runtime) {
73 m_filter_sp = m_language_runtime->CreateExceptionSearchFilter();
74 }
75 } else {
76 m_filter_sp.reset();
77 m_language_runtime = nullptr;
78 }
79}
80
81std::unique_ptr<SearchFilter> ExceptionSearchFilter::DoCreateCopy() {
82 return std::make_unique<ExceptionSearchFilter>(TargetSP(), m_language, false);
83}
84
86 Target &target, const StructuredData::Dictionary &data_dict,
87 Status &error) {
88 SearchFilter *result = nullptr;
89 return result;
90}
91
97
98// The Target is the one that knows how to create breakpoints, so this function
99// is meant to be used either by the target or internally in
100// Set/ClearExceptionBreakpoints.
102public:
104 bool throw_bp)
106 m_language(language), m_catch_bp(catch_bp), m_throw_bp(throw_bp) {}
107
108 ~ExceptionBreakpointResolver() override = default;
109
111 SymbolContext &context,
112 Address *addr) override {
113
114 if (SetActualResolver())
115 return m_actual_resolver_sp->SearchCallback(filter, context, addr);
116 else
117 return eCallbackReturnStop;
118 }
119
121 if (SetActualResolver())
122 return m_actual_resolver_sp->GetDepth();
123 else
125 }
126
127 void GetDescription(Stream *s) override {
128 Language *language_plugin = Language::FindPlugin(m_language);
129 if (language_plugin)
131 *s);
132 else
134 *s);
135
138 s->Printf(" using: ");
139 m_actual_resolver_sp->GetDescription(s);
140 } else
141 s->Printf(" the correct runtime exception handler will be determined "
142 "when you run");
143 }
144
145 void Dump(Stream *s) const override {}
146
147 /// Methods for support type inquiry through isa, cast, and dyn_cast:
148 static inline bool classof(const BreakpointResolverName *) { return true; }
149 static inline bool classof(const BreakpointResolver *V) {
151 }
152
153protected:
157 ret_sp->SetBreakpoint(breakpoint);
158 return ret_sp;
159 }
160
162 BreakpointSP breakpoint_sp = GetBreakpoint();
163 if (breakpoint_sp) {
164 ProcessSP process_sp = breakpoint_sp->GetTarget().GetProcessSP();
165 if (process_sp) {
166 bool refreash_resolver = !m_actual_resolver_sp;
167 if (m_language_runtime == nullptr) {
168 m_language_runtime = process_sp->GetLanguageRuntime(m_language);
169 refreash_resolver = true;
170 } else {
171 LanguageRuntime *language_runtime =
172 process_sp->GetLanguageRuntime(m_language);
173 if (m_language_runtime != language_runtime) {
174 m_language_runtime = language_runtime;
175 refreash_resolver = true;
176 }
177 }
178
179 if (refreash_resolver && m_language_runtime) {
180 m_actual_resolver_sp = m_language_runtime->CreateExceptionResolver(
181 breakpoint_sp, m_catch_bp, m_throw_bp);
182 }
183 } else {
184 m_actual_resolver_sp.reset();
185 m_language_runtime = nullptr;
186 }
187 } else {
188 m_actual_resolver_sp.reset();
189 m_language_runtime = nullptr;
190 }
191 return (bool)m_actual_resolver_sp;
192 }
193
199};
200
202 lldb::LanguageType language) {
204 if (LanguageRuntime *runtime = cbs.create_callback(process, language))
205 return runtime;
206 }
207 return nullptr;
208}
209
211
214 bool throw_bp) {
216 if (cbs.precondition_callback) {
217 if (BreakpointPreconditionSP precond =
218 cbs.precondition_callback(language, throw_bp))
219 return precond;
220 }
221 }
223}
224
226 Target &target, lldb::LanguageType language, bool catch_bp, bool throw_bp,
227 bool is_internal) {
228 BreakpointResolverSP resolver_sp(
229 new ExceptionBreakpointResolver(language, catch_bp, throw_bp));
230 SearchFilterSP filter_sp(
231 new ExceptionSearchFilter(target.shared_from_this(), language));
232 bool hardware = false;
233 bool resolve_indirect_functions = false;
234 BreakpointSP exc_breakpt_sp(
235 target.CreateBreakpoint(filter_sp, resolver_sp, is_internal, hardware,
236 resolve_indirect_functions));
237 if (exc_breakpt_sp) {
238 if (auto precond = GetExceptionPrecondition(language, throw_bp))
239 exc_breakpt_sp->SetPrecondition(precond);
240
241 if (is_internal)
242 exc_breakpt_sp->SetBreakpointKind("exception");
243 }
244
245 return exc_breakpt_sp;
246}
247
250 bool &behaves_like_zeroth_frame) {
251 ProcessSP process_sp = thread.GetProcess();
252 if (!process_sp.get())
253 return UnwindPlanSP();
254 if (process_sp->GetDisableLangRuntimeUnwindPlans() == true)
255 return UnwindPlanSP();
256 for (const lldb::LanguageType lang_type : Language::GetSupportedLanguages()) {
257 if (LanguageRuntime *runtime = process_sp->GetLanguageRuntime(lang_type)) {
258 UnwindPlanSP plan_sp = runtime->GetRuntimeUnwindPlan(
259 process_sp, regctx, behaves_like_zeroth_frame);
260 if (plan_sp.get())
261 return plan_sp;
262 }
263 }
264 return UnwindPlanSP();
265}
266
271
273 if (!parent)
274 return;
275
276 if (!parent->IsMultiwordObject())
277 return;
278
280 if (cbs.command_callback) {
281 CommandObjectSP command =
282 cbs.command_callback(parent->GetCommandInterpreter());
283 if (command) {
284 // the CommandObject vended by a Language plugin cannot be created once
285 // and cached because we may create multiple debuggers and need one
286 // instance of the command each - the implementing function is meant to
287 // create a new instance of the command each time it is invoked.
288 parent->LoadSubCommand(command->GetCommandName().str().c_str(), command);
289 }
290 }
291 }
292}
static llvm::raw_ostream & error(Stream &strm)
static bool classof(const BreakpointResolver *V)
void GetDescription(Stream *s) override
Prints a canonical description for the breakpoint to the stream s.
static bool classof(const BreakpointResolverName *)
Methods for support type inquiry through isa, cast, and dyn_cast:
lldb::BreakpointResolverSP m_actual_resolver_sp
LanguageRuntime * m_language_runtime
ExceptionBreakpointResolver(lldb::LanguageType language, bool catch_bp, bool throw_bp)
lldb::SearchDepth GetDepth() override
BreakpointResolverSP CopyForBreakpoint(BreakpointSP &breakpoint) override
Searcher::CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr) override
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
~ExceptionBreakpointResolver() override=default
A section + offset based address class.
Definition Address.h:62
"lldb/Breakpoint/BreakpointResolverName.h" This class sets breakpoints on a given function name,...
lldb::BreakpointSP GetBreakpoint() const
This gets the breakpoint for this resolver.
unsigned getResolverID() const
getResolverID - Return an ID for the concrete type of this object.
BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType, lldb::addr_t offset=0, bool offset_is_insn_count=false)
The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint to make sense.
CommandInterpreter & GetCommandInterpreter()
virtual bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj)
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.
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.
A file utility class.
Definition FileSpec.h:57
virtual StructuredData::ObjectSP GetLanguageSpecificData(SymbolContext sc)
Language runtime plugins can use this API to report language-specific runtime information about this ...
static LanguageRuntime * FindPlugin(Process *process, lldb::LanguageType language)
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...
static lldb::BreakpointSP CreateExceptionBreakpoint(Target &target, lldb::LanguageType language, bool catch_bp, bool throw_bp, bool is_internal=false)
static void InitializeCommands(CommandObject *parent)
static lldb::BreakpointPreconditionSP GetExceptionPrecondition(lldb::LanguageType language, bool throw_bp)
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:84
static void GetDefaultExceptionResolverDescription(bool catch_on, bool throw_on, Stream &s)
Definition Language.cpp:568
virtual void GetExceptionResolverDescription(bool catch_on, bool throw_on, Stream &s)
Definition Language.cpp:563
static std::set< lldb::LanguageType > GetSupportedLanguages()
Definition Language.cpp:458
static llvm::SmallVector< LanguageRuntimeCallbacks > GetLanguageRuntimeCallbacks()
A plug-in interface definition class for debugging a process.
Definition Process.h:357
Runtime(Process *process)
Definition Runtime.h:17
General Outline: Provides the callback and search depth for the SearchFilter search.
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.
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
Definition Target.cpp:504
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::SearchFilter > SearchFilterSP
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
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::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP