blob: 3699a507d05893cb47dd04ef815df05d40f79a55 [file] [log] [blame]
Raphael Isemann80814282020-01-24 07:23:271//===-- ThreadPlanCallFunction.cpp ----------------------------------------===//
Chris Lattner30fdc8d2010-06-08 16:52:242//
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
Jonas Devlieghere796ac802019-02-11 23:13:0827#include <memory>
28
Chris Lattner30fdc8d2010-06-08 16:52:2429using namespace lldb;
30using namespace lldb_private;
31
Chris Lattner30fdc8d2010-06-08 16:52:2432// ThreadPlanCallFunction: Plan to call a single function
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);
Jonas Devlieghere63e5fb72019-07-24 17:56:1062 LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
63 m_constructor_errors.GetData());
Kate Stoneb9c1b512016-09-06 20:57:5064 return false;
65 }
66
Jonas Devlieghere0288c262019-07-19 00:52:0867 llvm::Expected<Address> start_address = GetTarget().GetEntryPointAddress();
68 if (!start_address) {
69 m_constructor_errors.Printf(
70 "%s", llvm::toString(start_address.takeError()).c_str());
Jonas Devlieghere63e5fb72019-07-24 17:56:1071 LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
72 m_constructor_errors.GetData());
Kate Stoneb9c1b512016-09-06 20:57:5073 return false;
Jason Molenda956761a2019-07-18 20:55:2474 }
Kate Stoneb9c1b512016-09-06 20:57:5075
Jonas Devlieghere0288c262019-07-19 00:52:0876 m_start_addr = *start_address;
Kate Stoneb9c1b512016-09-06 20:57:5077 start_load_addr = m_start_addr.GetLoadAddress(&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:1078
Kate Stoneb9c1b512016-09-06 20:57:5079 // Checkpoint the thread state so we can restore it later.
80 if (log && log->GetVerbose())
81 ReportRegisterState("About to checkpoint thread before function call. "
82 "Original register state was:");
83
84 if (!thread.CheckpointThreadState(m_stored_thread_state)) {
85 m_constructor_errors.Printf("Setting up ThreadPlanCallFunction, failed to "
86 "checkpoint thread state.");
Jonas Devlieghere63e5fb72019-07-24 17:56:1087 LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
88 m_constructor_errors.GetData());
Kate Stoneb9c1b512016-09-06 20:57:5089 return false;
90 }
91 function_load_addr = m_function_addr.GetLoadAddress(&GetTarget());
92
93 return true;
94}
95
96ThreadPlanCallFunction::ThreadPlanCallFunction(
97 Thread &thread, const Address &function, const CompilerType &return_type,
98 llvm::ArrayRef<addr_t> args, const EvaluateExpressionOptions &options)
99 : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
100 eVoteNoOpinion, eVoteNoOpinion),
101 m_valid(false), m_stop_other_threads(options.GetStopOthers()),
102 m_unwind_on_error(options.DoesUnwindOnError()),
103 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
104 m_debug_execution(options.GetDebug()),
105 m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
106 m_function_sp(0), m_takedown_done(false),
107 m_should_clear_objc_exception_bp(false),
108 m_should_clear_cxx_exception_bp(false),
109 m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(return_type) {
110 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
111 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
112 ABI *abi = nullptr;
113
114 if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
115 return;
116
117 if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
118 start_load_addr, args))
119 return;
120
121 ReportRegisterState("Function call was set up. Register state was:");
122
123 m_valid = true;
124}
125
126ThreadPlanCallFunction::ThreadPlanCallFunction(
127 Thread &thread, const Address &function,
128 const EvaluateExpressionOptions &options)
129 : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
130 eVoteNoOpinion, eVoteNoOpinion),
131 m_valid(false), m_stop_other_threads(options.GetStopOthers()),
132 m_unwind_on_error(options.DoesUnwindOnError()),
133 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
134 m_debug_execution(options.GetDebug()),
135 m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
136 m_function_sp(0), m_takedown_done(false),
137 m_should_clear_objc_exception_bp(false),
138 m_should_clear_cxx_exception_bp(false),
139 m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {}
140
141ThreadPlanCallFunction::~ThreadPlanCallFunction() {
142 DoTakedown(PlanSucceeded());
143}
144
145void ThreadPlanCallFunction::ReportRegisterState(const char *message) {
Pavel Labath3b7e1982017-02-05 00:44:54146 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
147 if (log && log->GetVerbose()) {
Kate Stoneb9c1b512016-09-06 20:57:50148 StreamString strm;
Jim Inghame4598dc2020-03-10 21:03:53149 RegisterContext *reg_ctx = GetThread().GetRegisterContext().get();
Kate Stoneb9c1b512016-09-06 20:57:50150
151 log->PutCString(message);
152
153 RegisterValue reg_value;
154
155 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
156 reg_idx < num_registers; ++reg_idx) {
157 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
158 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
Pavel Labathe03334c2018-07-24 15:48:13159 DumpRegisterValue(reg_value, &strm, reg_info, true, false,
160 eFormatDefault);
Kate Stoneb9c1b512016-09-06 20:57:50161 strm.EOL();
162 }
Jim Ingham0092c8e2012-04-13 20:38:13163 }
Zachary Turnerc1564272016-11-16 21:15:24164 log->PutString(strm.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50165 }
166}
Saleem Abdulrasool324a1032014-04-04 04:06:10167
Kate Stoneb9c1b512016-09-06 20:57:50168void ThreadPlanCallFunction::DoTakedown(bool success) {
169 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10170
Kate Stoneb9c1b512016-09-06 20:57:50171 if (!m_valid) {
172 // Don't call DoTakedown if we were never valid to begin with.
Jonas Devlieghere63e5fb72019-07-24 17:56:10173 LLDB_LOGF(log,
174 "ThreadPlanCallFunction(%p): Log called on "
175 "ThreadPlanCallFunction that was never valid.",
176 static_cast<void *>(this));
Kate Stoneb9c1b512016-09-06 20:57:50177 return;
178 }
179
180 if (!m_takedown_done) {
Jim Inghame4598dc2020-03-10 21:03:53181 Thread &thread = GetThread();
Kate Stoneb9c1b512016-09-06 20:57:50182 if (success) {
183 SetReturnValue();
184 }
Jonas Devlieghere63e5fb72019-07-24 17:56:10185 LLDB_LOGF(log,
186 "ThreadPlanCallFunction(%p): DoTakedown called for thread "
187 "0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
Jim Inghame4598dc2020-03-10 21:03:53188 static_cast<void *>(this), m_tid, m_valid, IsPlanComplete());
Kate Stoneb9c1b512016-09-06 20:57:50189 m_takedown_done = true;
190 m_stop_address =
Jim Inghame4598dc2020-03-10 21:03:53191 thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Kate Stoneb9c1b512016-09-06 20:57:50192 m_real_stop_info_sp = GetPrivateStopInfo();
Jim Inghame4598dc2020-03-10 21:03:53193 if (!thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) {
Jonas Devlieghere63e5fb72019-07-24 17:56:10194 LLDB_LOGF(log,
195 "ThreadPlanCallFunction(%p): DoTakedown failed to restore "
196 "register state",
197 static_cast<void *>(this));
Kate Stoneb9c1b512016-09-06 20:57:50198 }
199 SetPlanComplete(success);
200 ClearBreakpoints();
Jim Ingham0092c8e2012-04-13 20:38:13201 if (log && log->GetVerbose())
Kate Stoneb9c1b512016-09-06 20:57:50202 ReportRegisterState("Restoring thread state after function call. "
203 "Restored register state:");
204 } else {
Jonas Devlieghere63e5fb72019-07-24 17:56:10205 LLDB_LOGF(log,
206 "ThreadPlanCallFunction(%p): DoTakedown called as no-op for "
207 "thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
Jim Inghame4598dc2020-03-10 21:03:53208 static_cast<void *>(this), m_tid, m_valid, IsPlanComplete());
Kate Stoneb9c1b512016-09-06 20:57:50209 }
Sean Callanan10af7c42010-11-04 01:51:38210}
211
Kate Stoneb9c1b512016-09-06 20:57:50212void ThreadPlanCallFunction::WillPop() { DoTakedown(PlanSucceeded()); }
Saleem Abdulrasool324a1032014-04-04 04:06:10213
Kate Stoneb9c1b512016-09-06 20:57:50214void ThreadPlanCallFunction::GetDescription(Stream *s, DescriptionLevel level) {
215 if (level == eDescriptionLevelBrief) {
216 s->Printf("Function call thread plan");
217 } else {
Kate Stoneb9c1b512016-09-06 20:57:50218 s->Printf("Thread plan to call 0x%" PRIx64,
Jim Inghame4598dc2020-03-10 21:03:53219 m_function_addr.GetLoadAddress(&GetTarget()));
Kate Stoneb9c1b512016-09-06 20:57:50220 }
Chris Lattner30fdc8d2010-06-08 16:52:24221}
222
Kate Stoneb9c1b512016-09-06 20:57:50223bool ThreadPlanCallFunction::ValidatePlan(Stream *error) {
224 if (!m_valid) {
225 if (error) {
226 if (m_constructor_errors.GetSize() > 0)
Zachary Turnerc1564272016-11-16 21:15:24227 error->PutCString(m_constructor_errors.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50228 else
229 error->PutCString("Unknown error");
230 }
231 return false;
232 }
233
234 return true;
Jim Inghambda4e5eb2011-01-18 01:58:06235}
236
Kate Stoneb9c1b512016-09-06 20:57:50237Vote ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) {
238 if (m_takedown_done || IsPlanComplete())
239 return eVoteYes;
240 else
241 return ThreadPlan::ShouldReportStop(event_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24242}
243
Kate Stoneb9c1b512016-09-06 20:57:50244bool ThreadPlanCallFunction::DoPlanExplainsStop(Event *event_ptr) {
245 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP |
246 LIBLLDB_LOG_PROCESS));
247 m_real_stop_info_sp = GetPrivateStopInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24248
Adrian Prantl05097242018-04-30 16:49:04249 // If our subplan knows why we stopped, even if it's done (which would
250 // forward the question to us) we answer yes.
Kate Stoneb9c1b512016-09-06 20:57:50251 if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr)) {
252 SetPlanComplete();
Chris Lattner30fdc8d2010-06-08 16:52:24253 return true;
Kate Stoneb9c1b512016-09-06 20:57:50254 }
Chris Lattner30fdc8d2010-06-08 16:52:24255
Kate Stoneb9c1b512016-09-06 20:57:50256 // Check if the breakpoint is one of ours.
Jim Ingham0161b492013-02-09 01:29:05257
Kate Stoneb9c1b512016-09-06 20:57:50258 StopReason stop_reason;
259 if (!m_real_stop_info_sp)
260 stop_reason = eStopReasonNone;
261 else
262 stop_reason = m_real_stop_info_sp->GetStopReason();
Raphael Isemanna4a08442020-07-30 09:50:53263 LLDB_LOG(log,
264 "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - {0}.",
265 Thread::StopReasonAsString(stop_reason));
Kate Stoneb9c1b512016-09-06 20:57:50266
267 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
268 return true;
269
270 // One more quirk here. If this event was from Halt interrupting the target,
Adrian Prantl05097242018-04-30 16:49:04271 // then we should not consider ourselves complete. Return true to
272 // acknowledge the stop.
Kate Stoneb9c1b512016-09-06 20:57:50273 if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr)) {
Jonas Devlieghere63e5fb72019-07-24 17:56:10274 LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop: The event is an "
275 "Interrupt, returning true.");
Kate Stoneb9c1b512016-09-06 20:57:50276 return true;
277 }
278 // We control breakpoints separately from other "stop reasons." So first,
279 // check the case where we stopped for an internal breakpoint, in that case,
Adrian Prantl05097242018-04-30 16:49:04280 // continue on. If it is not an internal breakpoint, consult
281 // m_ignore_breakpoints.
Jim Ingham18de2fd2012-05-10 01:35:39282
Kate Stoneb9c1b512016-09-06 20:57:50283 if (stop_reason == eStopReasonBreakpoint) {
Kate Stoneb9c1b512016-09-06 20:57:50284 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
285 BreakpointSiteSP bp_site_sp;
Jim Inghame4598dc2020-03-10 21:03:53286 bp_site_sp = m_process.GetBreakpointSiteList().FindByID(break_site_id);
Kate Stoneb9c1b512016-09-06 20:57:50287 if (bp_site_sp) {
288 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
289 bool is_internal = true;
290 for (uint32_t i = 0; i < num_owners; i++) {
291 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Jonas Devlieghere63e5fb72019-07-24 17:56:10292 LLDB_LOGF(log,
293 "ThreadPlanCallFunction::PlanExplainsStop: hit "
294 "breakpoint %d while calling function",
295 bp.GetID());
Eugene Zelenkoe65b2cf2015-12-15 01:33:19296
Kate Stoneb9c1b512016-09-06 20:57:50297 if (!bp.IsInternal()) {
298 is_internal = false;
299 break;
Jim Ingham40d871f2010-10-26 00:27:45300 }
Kate Stoneb9c1b512016-09-06 20:57:50301 }
302 if (is_internal) {
Jonas Devlieghere63e5fb72019-07-24 17:56:10303 LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop hit an "
304 "internal breakpoint, not stopping.");
Jim Ingham0161b492013-02-09 01:29:05305 return false;
Kate Stoneb9c1b512016-09-06 20:57:50306 }
Jim Ingham40d871f2010-10-26 00:27:45307 }
Kate Stoneb9c1b512016-09-06 20:57:50308
309 if (m_ignore_breakpoints) {
Jonas Devlieghere63e5fb72019-07-24 17:56:10310 LLDB_LOGF(log,
311 "ThreadPlanCallFunction::PlanExplainsStop: we are ignoring "
312 "breakpoints, overriding breakpoint stop info ShouldStop, "
313 "returning true");
Kate Stoneb9c1b512016-09-06 20:57:50314 m_real_stop_info_sp->OverrideShouldStop(false);
315 return true;
316 } else {
Jonas Devlieghere63e5fb72019-07-24 17:56:10317 LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop: we are not "
318 "ignoring breakpoints, overriding breakpoint stop info "
319 "ShouldStop, returning true");
Kate Stoneb9c1b512016-09-06 20:57:50320 m_real_stop_info_sp->OverrideShouldStop(true);
321 return false;
Jim Ingham40d871f2010-10-26 00:27:45322 }
Kate Stoneb9c1b512016-09-06 20:57:50323 } else if (!m_unwind_on_error) {
324 // If we don't want to discard this plan, than any stop we don't understand
325 // should be propagated up the stack.
326 return false;
327 } else {
Adrian Prantl05097242018-04-30 16:49:04328 // If the subplan is running, any crashes are attributable to us. If we
329 // want to discard the plan, then we say we explain the stop but if we are
330 // going to be discarded, let whoever is above us explain the stop. But
331 // don't discard the plan if the stop would restart itself (for instance if
332 // it is a signal that is set not to stop. Check that here first. We just
333 // say we explain the stop but aren't done and everything will continue on
334 // from there.
Kate Stoneb9c1b512016-09-06 20:57:50335
336 if (m_real_stop_info_sp &&
337 m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) {
338 SetPlanComplete(false);
339 return m_subplan_sp ? m_unwind_on_error : false;
340 } else
341 return true;
342 }
Chris Lattner30fdc8d2010-06-08 16:52:24343}
344
Kate Stoneb9c1b512016-09-06 20:57:50345bool ThreadPlanCallFunction::ShouldStop(Event *event_ptr) {
346 // We do some computation in DoPlanExplainsStop that may or may not set the
Adrian Prantl05097242018-04-30 16:49:04347 // plan as complete. We need to do that here to make sure our state is
348 // correct.
Kate Stoneb9c1b512016-09-06 20:57:50349 DoPlanExplainsStop(event_ptr);
350
351 if (IsPlanComplete()) {
352 ReportRegisterState("Function completed. Register state was:");
353 return true;
354 } else {
355 return false;
356 }
Chris Lattner30fdc8d2010-06-08 16:52:24357}
358
Kate Stoneb9c1b512016-09-06 20:57:50359bool ThreadPlanCallFunction::StopOthers() { return m_stop_other_threads; }
Chris Lattner30fdc8d2010-06-08 16:52:24360
Kate Stoneb9c1b512016-09-06 20:57:50361StateType ThreadPlanCallFunction::GetPlanRunState() { return eStateRunning; }
Chris Lattner30fdc8d2010-06-08 16:52:24362
Kate Stoneb9c1b512016-09-06 20:57:50363void ThreadPlanCallFunction::DidPush() {
364 //#define SINGLE_STEP_EXPRESSIONS
365
366 // Now set the thread state to "no reason" so we don't run with whatever
Adrian Prantl05097242018-04-30 16:49:04367 // signal was outstanding... Wait till the plan is pushed so we aren't
368 // changing the stop info till we're about to run.
Kate Stoneb9c1b512016-09-06 20:57:50369
370 GetThread().SetStopInfoToNothing();
371
Sean Callananbe3a1b12010-10-26 00:31:56372#ifndef SINGLE_STEP_EXPRESSIONS
Jim Inghame4598dc2020-03-10 21:03:53373 Thread &thread = GetThread();
374 m_subplan_sp = std::make_shared<ThreadPlanRunToAddress>(thread, m_start_addr,
375 m_stop_other_threads);
Kate Stoneb9c1b512016-09-06 20:57:50376
Jim Inghame4598dc2020-03-10 21:03:53377 thread.QueueThreadPlan(m_subplan_sp, false);
Kate Stoneb9c1b512016-09-06 20:57:50378 m_subplan_sp->SetPrivate(true);
Sean Callananbe3a1b12010-10-26 00:31:56379#endif
Chris Lattner30fdc8d2010-06-08 16:52:24380}
381
Kate Stoneb9c1b512016-09-06 20:57:50382bool ThreadPlanCallFunction::WillStop() { return true; }
383
384bool ThreadPlanCallFunction::MischiefManaged() {
385 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
386
387 if (IsPlanComplete()) {
Jonas Devlieghere63e5fb72019-07-24 17:56:10388 LLDB_LOGF(log, "ThreadPlanCallFunction(%p): Completed call function plan.",
389 static_cast<void *>(this));
Kate Stoneb9c1b512016-09-06 20:57:50390
391 ThreadPlan::MischiefManaged();
Chris Lattner30fdc8d2010-06-08 16:52:24392 return true;
Kate Stoneb9c1b512016-09-06 20:57:50393 } else {
Sean Callananc98aca62010-11-03 19:36:28394 return false;
Kate Stoneb9c1b512016-09-06 20:57:50395 }
Sean Callananc98aca62010-11-03 19:36:28396}
Jim Ingham8559a352012-11-26 23:52:18397
Kate Stoneb9c1b512016-09-06 20:57:50398void ThreadPlanCallFunction::SetBreakpoints() {
Jim Inghame4598dc2020-03-10 21:03:53399 if (m_trap_exceptions) {
Kate Stoneb9c1b512016-09-06 20:57:50400 m_cxx_language_runtime =
Jim Inghame4598dc2020-03-10 21:03:53401 m_process.GetLanguageRuntime(eLanguageTypeC_plus_plus);
402 m_objc_language_runtime = m_process.GetLanguageRuntime(eLanguageTypeObjC);
Jim Ingham0ff099f2014-03-07 11:16:37403
Kate Stoneb9c1b512016-09-06 20:57:50404 if (m_cxx_language_runtime) {
405 m_should_clear_cxx_exception_bp =
406 !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
407 m_cxx_language_runtime->SetExceptionBreakpoints();
Ewan Crawford90ff7912015-07-14 10:56:58408 }
Kate Stoneb9c1b512016-09-06 20:57:50409 if (m_objc_language_runtime) {
410 m_should_clear_objc_exception_bp =
411 !m_objc_language_runtime->ExceptionBreakpointsAreSet();
412 m_objc_language_runtime->SetExceptionBreakpoints();
413 }
414 }
415}
416
417void ThreadPlanCallFunction::ClearBreakpoints() {
418 if (m_trap_exceptions) {
419 if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
420 m_cxx_language_runtime->ClearExceptionBreakpoints();
421 if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
422 m_objc_language_runtime->ClearExceptionBreakpoints();
423 }
424}
425
426bool ThreadPlanCallFunction::BreakpointsExplainStop() {
427 StopInfoSP stop_info_sp = GetPrivateStopInfo();
428
429 if (m_trap_exceptions) {
430 if ((m_cxx_language_runtime &&
431 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(
432 stop_info_sp)) ||
433 (m_objc_language_runtime &&
434 m_objc_language_runtime->ExceptionBreakpointsExplainStop(
435 stop_info_sp))) {
436 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
Jonas Devlieghere63e5fb72019-07-24 17:56:10437 LLDB_LOGF(log, "ThreadPlanCallFunction::BreakpointsExplainStop - Hit an "
438 "exception breakpoint, setting plan complete.");
Kate Stoneb9c1b512016-09-06 20:57:50439
440 SetPlanComplete(false);
441
Adrian Prantl05097242018-04-30 16:49:04442 // If the user has set the ObjC language breakpoint, it would normally
443 // get priority over our internal catcher breakpoint, but in this case we
444 // can't let that happen, so force the ShouldStop here.
Kate Stoneb9c1b512016-09-06 20:57:50445 stop_info_sp->OverrideShouldStop(true);
446 return true;
447 }
448 }
449
450 return false;
451}
452
453void ThreadPlanCallFunction::SetStopOthers(bool new_value) {
454 m_subplan_sp->SetStopOthers(new_value);
455}
456
Dave Lee65d91b42021-02-15 06:49:16457void ThreadPlanCallFunction::RestoreThreadState() {
458 GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
Kate Stoneb9c1b512016-09-06 20:57:50459}
460
461void ThreadPlanCallFunction::SetReturnValue() {
Jim Inghame4598dc2020-03-10 21:03:53462 const ABI *abi = m_process.GetABI().get();
Kate Stoneb9c1b512016-09-06 20:57:50463 if (abi && m_return_type.IsValid()) {
464 const bool persistent = false;
465 m_return_valobj_sp =
Jim Inghame4598dc2020-03-10 21:03:53466 abi->GetReturnValueObject(GetThread(), m_return_type, persistent);
Kate Stoneb9c1b512016-09-06 20:57:50467 }
Ewan Crawford90ff7912015-07-14 10:56:58468}