blob: bf2a2ac2ea97295945b0f935da651ab748ad26c3 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- ThreadPlanCallFunction.cpp ------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:563// 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
Chris Lattner30fdc8d2010-06-08 16:52:246//
7//===----------------------------------------------------------------------===//
8
Eugene Zelenkoe65b2cf2015-12-15 01:33:199#include "lldb/Target/ThreadPlanCallFunction.h"
Jim Ingham40d871f2010-10-26 00:27:4510#include "lldb/Breakpoint/Breakpoint.h"
11#include "lldb/Breakpoint/BreakpointLocation.h"
Chris Lattner30fdc8d2010-06-08 16:52:2412#include "lldb/Core/Address.h"
Pavel Labathe03334c2018-07-24 15:48:1313#include "lldb/Core/DumpRegisterValue.h"
Greg Clayton1f746072012-08-29 21:13:0614#include "lldb/Core/Module.h"
Greg Clayton1f746072012-08-29 21:13:0615#include "lldb/Symbol/ObjectFile.h"
Zachary Turner32abc6e2015-03-03 19:23:0916#include "lldb/Target/ABI.h"
Sean Callananf2115102010-11-03 22:19:3817#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:2418#include "lldb/Target/Process.h"
19#include "lldb/Target/RegisterContext.h"
Jim Ingham40d871f2010-10-26 00:27:4520#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:2421#include "lldb/Target/Target.h"
22#include "lldb/Target/Thread.h"
23#include "lldb/Target/ThreadPlanRunToAddress.h"
Zachary Turner6f9e6902017-03-03 20:56:2824#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:5025#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:2426
27using namespace lldb;
28using namespace lldb_private;
29
30//----------------------------------------------------------------------
31// ThreadPlanCallFunction: Plan to call a single function
32//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:5033bool ThreadPlanCallFunction::ConstructorSetup(
34 Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr,
35 lldb::addr_t &function_load_addr) {
36 SetIsMasterPlan(true);
37 SetOkayToDiscard(false);
38 SetPrivate(true);
Jim Ingham0092c8e2012-04-13 20:38:1339
Kate Stoneb9c1b512016-09-06 20:57:5040 ProcessSP process_sp(thread.GetProcess());
41 if (!process_sp)
42 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1043
Kate Stoneb9c1b512016-09-06 20:57:5044 abi = process_sp->GetABI().get();
Saleem Abdulrasool324a1032014-04-04 04:06:1045
Kate Stoneb9c1b512016-09-06 20:57:5046 if (!abi)
47 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1048
Kate Stoneb9c1b512016-09-06 20:57:5049 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:1050
Kate Stoneb9c1b512016-09-06 20:57:5051 SetBreakpoints();
Saleem Abdulrasool324a1032014-04-04 04:06:1052
Kate Stoneb9c1b512016-09-06 20:57:5053 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
54 // If we can't read memory at the point of the process where we are planning
Adrian Prantl05097242018-04-30 16:49:0455 // to put our function, we're not going to get any further...
Zachary Turner97206d52017-05-12 04:51:5556 Status error;
Kate Stoneb9c1b512016-09-06 20:57:5057 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
58 if (!error.Success()) {
59 m_constructor_errors.Printf(
60 "Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".",
61 m_function_sp);
62 if (log)
63 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
64 m_constructor_errors.GetData());
65 return false;
66 }
67
68 Module *exe_module = GetTarget().GetExecutableModulePointer();
69
70 if (exe_module == nullptr) {
71 m_constructor_errors.Printf(
72 "Can't execute code without an executable module.");
73 if (log)
74 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
75 m_constructor_errors.GetData());
76 return false;
77 } else {
78 ObjectFile *objectFile = exe_module->GetObjectFile();
79 if (!objectFile) {
80 m_constructor_errors.Printf(
81 "Could not find object file for module \"%s\".",
82 exe_module->GetFileSpec().GetFilename().AsCString());
83
84 if (log)
85 log->Printf("ThreadPlanCallFunction(%p): %s.",
86 static_cast<void *>(this), m_constructor_errors.GetData());
87 return false;
Jim Ingham0092c8e2012-04-13 20:38:1388 }
Saleem Abdulrasool324a1032014-04-04 04:06:1089
Kate Stoneb9c1b512016-09-06 20:57:5090 m_start_addr = objectFile->GetEntryPointAddress();
91 if (!m_start_addr.IsValid()) {
92 m_constructor_errors.Printf(
93 "Could not find entry point address for executable module \"%s\".",
94 exe_module->GetFileSpec().GetFilename().AsCString());
95 if (log)
96 log->Printf("ThreadPlanCallFunction(%p): %s.",
97 static_cast<void *>(this), m_constructor_errors.GetData());
98 return false;
Jim Ingham0092c8e2012-04-13 20:38:1399 }
Kate Stoneb9c1b512016-09-06 20:57:50100 }
Jim Inghamea06f3b2013-03-28 00:04:05101
Kate Stoneb9c1b512016-09-06 20:57:50102 start_load_addr = m_start_addr.GetLoadAddress(&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:10103
Kate Stoneb9c1b512016-09-06 20:57:50104 // Checkpoint the thread state so we can restore it later.
105 if (log && log->GetVerbose())
106 ReportRegisterState("About to checkpoint thread before function call. "
107 "Original register state was:");
108
109 if (!thread.CheckpointThreadState(m_stored_thread_state)) {
110 m_constructor_errors.Printf("Setting up ThreadPlanCallFunction, failed to "
111 "checkpoint thread state.");
112 if (log)
113 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
114 m_constructor_errors.GetData());
115 return false;
116 }
117 function_load_addr = m_function_addr.GetLoadAddress(&GetTarget());
118
119 return true;
120}
121
122ThreadPlanCallFunction::ThreadPlanCallFunction(
123 Thread &thread, const Address &function, const CompilerType &return_type,
124 llvm::ArrayRef<addr_t> args, const EvaluateExpressionOptions &options)
125 : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
126 eVoteNoOpinion, eVoteNoOpinion),
127 m_valid(false), m_stop_other_threads(options.GetStopOthers()),
128 m_unwind_on_error(options.DoesUnwindOnError()),
129 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
130 m_debug_execution(options.GetDebug()),
131 m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
132 m_function_sp(0), m_takedown_done(false),
133 m_should_clear_objc_exception_bp(false),
134 m_should_clear_cxx_exception_bp(false),
135 m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(return_type) {
136 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
137 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
138 ABI *abi = nullptr;
139
140 if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
141 return;
142
143 if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
144 start_load_addr, args))
145 return;
146
147 ReportRegisterState("Function call was set up. Register state was:");
148
149 m_valid = true;
150}
151
152ThreadPlanCallFunction::ThreadPlanCallFunction(
153 Thread &thread, const Address &function,
154 const EvaluateExpressionOptions &options)
155 : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
156 eVoteNoOpinion, eVoteNoOpinion),
157 m_valid(false), m_stop_other_threads(options.GetStopOthers()),
158 m_unwind_on_error(options.DoesUnwindOnError()),
159 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
160 m_debug_execution(options.GetDebug()),
161 m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
162 m_function_sp(0), m_takedown_done(false),
163 m_should_clear_objc_exception_bp(false),
164 m_should_clear_cxx_exception_bp(false),
165 m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {}
166
167ThreadPlanCallFunction::~ThreadPlanCallFunction() {
168 DoTakedown(PlanSucceeded());
169}
170
171void ThreadPlanCallFunction::ReportRegisterState(const char *message) {
Pavel Labath3b7e1982017-02-05 00:44:54172 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
173 if (log && log->GetVerbose()) {
Kate Stoneb9c1b512016-09-06 20:57:50174 StreamString strm;
175 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
176
177 log->PutCString(message);
178
179 RegisterValue reg_value;
180
181 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
182 reg_idx < num_registers; ++reg_idx) {
183 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
184 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
Pavel Labathe03334c2018-07-24 15:48:13185 DumpRegisterValue(reg_value, &strm, reg_info, true, false,
186 eFormatDefault);
Kate Stoneb9c1b512016-09-06 20:57:50187 strm.EOL();
188 }
Jim Ingham0092c8e2012-04-13 20:38:13189 }
Zachary Turnerc1564272016-11-16 21:15:24190 log->PutString(strm.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50191 }
192}
Saleem Abdulrasool324a1032014-04-04 04:06:10193
Kate Stoneb9c1b512016-09-06 20:57:50194void ThreadPlanCallFunction::DoTakedown(bool success) {
195 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10196
Kate Stoneb9c1b512016-09-06 20:57:50197 if (!m_valid) {
198 // Don't call DoTakedown if we were never valid to begin with.
199 if (log)
200 log->Printf("ThreadPlanCallFunction(%p): Log called on "
201 "ThreadPlanCallFunction that was never valid.",
202 static_cast<void *>(this));
203 return;
204 }
205
206 if (!m_takedown_done) {
207 if (success) {
208 SetReturnValue();
209 }
210 if (log)
211 log->Printf("ThreadPlanCallFunction(%p): DoTakedown called for thread "
212 "0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
213 static_cast<void *>(this), m_thread.GetID(), m_valid,
214 IsPlanComplete());
215 m_takedown_done = true;
216 m_stop_address =
217 m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
218 m_real_stop_info_sp = GetPrivateStopInfo();
219 if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) {
220 if (log)
221 log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore "
222 "register state",
223 static_cast<void *>(this));
224 }
225 SetPlanComplete(success);
226 ClearBreakpoints();
Jim Ingham0092c8e2012-04-13 20:38:13227 if (log && log->GetVerbose())
Kate Stoneb9c1b512016-09-06 20:57:50228 ReportRegisterState("Restoring thread state after function call. "
229 "Restored register state:");
230 } else {
Sean Callananece96492010-11-08 03:49:50231 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50232 log->Printf("ThreadPlanCallFunction(%p): DoTakedown called as no-op for "
233 "thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
234 static_cast<void *>(this), m_thread.GetID(), m_valid,
235 IsPlanComplete());
236 }
Sean Callanan10af7c42010-11-04 01:51:38237}
238
Kate Stoneb9c1b512016-09-06 20:57:50239void ThreadPlanCallFunction::WillPop() { DoTakedown(PlanSucceeded()); }
Saleem Abdulrasool324a1032014-04-04 04:06:10240
Kate Stoneb9c1b512016-09-06 20:57:50241void ThreadPlanCallFunction::GetDescription(Stream *s, DescriptionLevel level) {
242 if (level == eDescriptionLevelBrief) {
243 s->Printf("Function call thread plan");
244 } else {
245 TargetSP target_sp(m_thread.CalculateTarget());
246 s->Printf("Thread plan to call 0x%" PRIx64,
247 m_function_addr.GetLoadAddress(target_sp.get()));
248 }
Chris Lattner30fdc8d2010-06-08 16:52:24249}
250
Kate Stoneb9c1b512016-09-06 20:57:50251bool ThreadPlanCallFunction::ValidatePlan(Stream *error) {
252 if (!m_valid) {
253 if (error) {
254 if (m_constructor_errors.GetSize() > 0)
Zachary Turnerc1564272016-11-16 21:15:24255 error->PutCString(m_constructor_errors.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50256 else
257 error->PutCString("Unknown error");
258 }
259 return false;
260 }
261
262 return true;
Jim Inghambda4e5eb2011-01-18 01:58:06263}
264
Kate Stoneb9c1b512016-09-06 20:57:50265Vote ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) {
266 if (m_takedown_done || IsPlanComplete())
267 return eVoteYes;
268 else
269 return ThreadPlan::ShouldReportStop(event_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24270}
271
Kate Stoneb9c1b512016-09-06 20:57:50272bool ThreadPlanCallFunction::DoPlanExplainsStop(Event *event_ptr) {
273 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP |
274 LIBLLDB_LOG_PROCESS));
275 m_real_stop_info_sp = GetPrivateStopInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24276
Adrian Prantl05097242018-04-30 16:49:04277 // If our subplan knows why we stopped, even if it's done (which would
278 // forward the question to us) we answer yes.
Kate Stoneb9c1b512016-09-06 20:57:50279 if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr)) {
280 SetPlanComplete();
Chris Lattner30fdc8d2010-06-08 16:52:24281 return true;
Kate Stoneb9c1b512016-09-06 20:57:50282 }
Chris Lattner30fdc8d2010-06-08 16:52:24283
Kate Stoneb9c1b512016-09-06 20:57:50284 // Check if the breakpoint is one of ours.
Jim Ingham0161b492013-02-09 01:29:05285
Kate Stoneb9c1b512016-09-06 20:57:50286 StopReason stop_reason;
287 if (!m_real_stop_info_sp)
288 stop_reason = eStopReasonNone;
289 else
290 stop_reason = m_real_stop_info_sp->GetStopReason();
291 if (log)
292 log->Printf(
293 "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.",
294 Thread::StopReasonAsCString(stop_reason));
295
296 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
297 return true;
298
299 // One more quirk here. If this event was from Halt interrupting the target,
Adrian Prantl05097242018-04-30 16:49:04300 // then we should not consider ourselves complete. Return true to
301 // acknowledge the stop.
Kate Stoneb9c1b512016-09-06 20:57:50302 if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr)) {
Jim Ingham0161b492013-02-09 01:29:05303 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50304 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: The event is an "
305 "Interrupt, returning true.");
306 return true;
307 }
308 // We control breakpoints separately from other "stop reasons." So first,
309 // check the case where we stopped for an internal breakpoint, in that case,
Adrian Prantl05097242018-04-30 16:49:04310 // continue on. If it is not an internal breakpoint, consult
311 // m_ignore_breakpoints.
Jim Ingham18de2fd2012-05-10 01:35:39312
Kate Stoneb9c1b512016-09-06 20:57:50313 if (stop_reason == eStopReasonBreakpoint) {
314 ProcessSP process_sp(m_thread.CalculateProcess());
315 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
316 BreakpointSiteSP bp_site_sp;
317 if (process_sp)
318 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
319 if (bp_site_sp) {
320 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
321 bool is_internal = true;
322 for (uint32_t i = 0; i < num_owners; i++) {
323 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Jim Ingham35878c42014-04-08 21:33:21324 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50325 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: hit "
326 "breakpoint %d while calling function",
327 bp.GetID());
Eugene Zelenkoe65b2cf2015-12-15 01:33:19328
Kate Stoneb9c1b512016-09-06 20:57:50329 if (!bp.IsInternal()) {
330 is_internal = false;
331 break;
Jim Ingham40d871f2010-10-26 00:27:45332 }
Kate Stoneb9c1b512016-09-06 20:57:50333 }
334 if (is_internal) {
335 if (log)
336 log->Printf("ThreadPlanCallFunction::PlanExplainsStop hit an "
337 "internal breakpoint, not stopping.");
Jim Ingham0161b492013-02-09 01:29:05338 return false;
Kate Stoneb9c1b512016-09-06 20:57:50339 }
Jim Ingham40d871f2010-10-26 00:27:45340 }
Kate Stoneb9c1b512016-09-06 20:57:50341
342 if (m_ignore_breakpoints) {
343 if (log)
344 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring "
345 "breakpoints, overriding breakpoint stop info ShouldStop, "
346 "returning true");
347 m_real_stop_info_sp->OverrideShouldStop(false);
348 return true;
349 } else {
350 if (log)
351 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not "
352 "ignoring breakpoints, overriding breakpoint stop info "
353 "ShouldStop, returning true");
354 m_real_stop_info_sp->OverrideShouldStop(true);
355 return false;
Jim Ingham40d871f2010-10-26 00:27:45356 }
Kate Stoneb9c1b512016-09-06 20:57:50357 } else if (!m_unwind_on_error) {
358 // If we don't want to discard this plan, than any stop we don't understand
359 // should be propagated up the stack.
360 return false;
361 } else {
Adrian Prantl05097242018-04-30 16:49:04362 // If the subplan is running, any crashes are attributable to us. If we
363 // want to discard the plan, then we say we explain the stop but if we are
364 // going to be discarded, let whoever is above us explain the stop. But
365 // don't discard the plan if the stop would restart itself (for instance if
366 // it is a signal that is set not to stop. Check that here first. We just
367 // say we explain the stop but aren't done and everything will continue on
368 // from there.
Kate Stoneb9c1b512016-09-06 20:57:50369
370 if (m_real_stop_info_sp &&
371 m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) {
372 SetPlanComplete(false);
373 return m_subplan_sp ? m_unwind_on_error : false;
374 } else
375 return true;
376 }
Chris Lattner30fdc8d2010-06-08 16:52:24377}
378
Kate Stoneb9c1b512016-09-06 20:57:50379bool ThreadPlanCallFunction::ShouldStop(Event *event_ptr) {
380 // We do some computation in DoPlanExplainsStop that may or may not set the
Adrian Prantl05097242018-04-30 16:49:04381 // plan as complete. We need to do that here to make sure our state is
382 // correct.
Kate Stoneb9c1b512016-09-06 20:57:50383 DoPlanExplainsStop(event_ptr);
384
385 if (IsPlanComplete()) {
386 ReportRegisterState("Function completed. Register state was:");
387 return true;
388 } else {
389 return false;
390 }
Chris Lattner30fdc8d2010-06-08 16:52:24391}
392
Kate Stoneb9c1b512016-09-06 20:57:50393bool ThreadPlanCallFunction::StopOthers() { return m_stop_other_threads; }
Chris Lattner30fdc8d2010-06-08 16:52:24394
Kate Stoneb9c1b512016-09-06 20:57:50395StateType ThreadPlanCallFunction::GetPlanRunState() { return eStateRunning; }
Chris Lattner30fdc8d2010-06-08 16:52:24396
Kate Stoneb9c1b512016-09-06 20:57:50397void ThreadPlanCallFunction::DidPush() {
398 //#define SINGLE_STEP_EXPRESSIONS
399
400 // Now set the thread state to "no reason" so we don't run with whatever
Adrian Prantl05097242018-04-30 16:49:04401 // signal was outstanding... Wait till the plan is pushed so we aren't
402 // changing the stop info till we're about to run.
Kate Stoneb9c1b512016-09-06 20:57:50403
404 GetThread().SetStopInfoToNothing();
405
Sean Callananbe3a1b12010-10-26 00:31:56406#ifndef SINGLE_STEP_EXPRESSIONS
Kate Stoneb9c1b512016-09-06 20:57:50407 m_subplan_sp.reset(
408 new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
409
410 m_thread.QueueThreadPlan(m_subplan_sp, false);
411 m_subplan_sp->SetPrivate(true);
Sean Callananbe3a1b12010-10-26 00:31:56412#endif
Chris Lattner30fdc8d2010-06-08 16:52:24413}
414
Kate Stoneb9c1b512016-09-06 20:57:50415bool ThreadPlanCallFunction::WillStop() { return true; }
416
417bool ThreadPlanCallFunction::MischiefManaged() {
418 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
419
420 if (IsPlanComplete()) {
421 if (log)
422 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
423 static_cast<void *>(this));
424
425 ThreadPlan::MischiefManaged();
Chris Lattner30fdc8d2010-06-08 16:52:24426 return true;
Kate Stoneb9c1b512016-09-06 20:57:50427 } else {
Sean Callananc98aca62010-11-03 19:36:28428 return false;
Kate Stoneb9c1b512016-09-06 20:57:50429 }
Sean Callananc98aca62010-11-03 19:36:28430}
Jim Ingham8559a352012-11-26 23:52:18431
Kate Stoneb9c1b512016-09-06 20:57:50432void ThreadPlanCallFunction::SetBreakpoints() {
433 ProcessSP process_sp(m_thread.CalculateProcess());
434 if (m_trap_exceptions && process_sp) {
435 m_cxx_language_runtime =
436 process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
437 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Jim Ingham0ff099f2014-03-07 11:16:37438
Kate Stoneb9c1b512016-09-06 20:57:50439 if (m_cxx_language_runtime) {
440 m_should_clear_cxx_exception_bp =
441 !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
442 m_cxx_language_runtime->SetExceptionBreakpoints();
Ewan Crawford90ff7912015-07-14 10:56:58443 }
Kate Stoneb9c1b512016-09-06 20:57:50444 if (m_objc_language_runtime) {
445 m_should_clear_objc_exception_bp =
446 !m_objc_language_runtime->ExceptionBreakpointsAreSet();
447 m_objc_language_runtime->SetExceptionBreakpoints();
448 }
449 }
450}
451
452void ThreadPlanCallFunction::ClearBreakpoints() {
453 if (m_trap_exceptions) {
454 if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
455 m_cxx_language_runtime->ClearExceptionBreakpoints();
456 if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
457 m_objc_language_runtime->ClearExceptionBreakpoints();
458 }
459}
460
461bool ThreadPlanCallFunction::BreakpointsExplainStop() {
462 StopInfoSP stop_info_sp = GetPrivateStopInfo();
463
464 if (m_trap_exceptions) {
465 if ((m_cxx_language_runtime &&
466 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(
467 stop_info_sp)) ||
468 (m_objc_language_runtime &&
469 m_objc_language_runtime->ExceptionBreakpointsExplainStop(
470 stop_info_sp))) {
471 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
472 if (log)
473 log->Printf("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an "
474 "exception breakpoint, setting plan complete.");
475
476 SetPlanComplete(false);
477
Adrian Prantl05097242018-04-30 16:49:04478 // If the user has set the ObjC language breakpoint, it would normally
479 // get priority over our internal catcher breakpoint, but in this case we
480 // can't let that happen, so force the ShouldStop here.
Kate Stoneb9c1b512016-09-06 20:57:50481 stop_info_sp->OverrideShouldStop(true);
482 return true;
483 }
484 }
485
486 return false;
487}
488
489void ThreadPlanCallFunction::SetStopOthers(bool new_value) {
490 m_subplan_sp->SetStopOthers(new_value);
491}
492
493bool ThreadPlanCallFunction::RestoreThreadState() {
494 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
495}
496
497void ThreadPlanCallFunction::SetReturnValue() {
498 ProcessSP process_sp(m_thread.GetProcess());
499 const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr;
500 if (abi && m_return_type.IsValid()) {
501 const bool persistent = false;
502 m_return_valobj_sp =
503 abi->GetReturnValueObject(m_thread, m_return_type, persistent);
504 }
Ewan Crawford90ff7912015-07-14 10:56:58505}