1dda28197Spatrick //===-- ThreadPlanCallFunction.cpp ----------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick
9061da546Spatrick #include "lldb/Target/ThreadPlanCallFunction.h"
10061da546Spatrick #include "lldb/Breakpoint/Breakpoint.h"
11061da546Spatrick #include "lldb/Breakpoint/BreakpointLocation.h"
12061da546Spatrick #include "lldb/Core/Address.h"
13061da546Spatrick #include "lldb/Core/DumpRegisterValue.h"
14061da546Spatrick #include "lldb/Core/Module.h"
15061da546Spatrick #include "lldb/Symbol/ObjectFile.h"
16061da546Spatrick #include "lldb/Target/ABI.h"
17061da546Spatrick #include "lldb/Target/LanguageRuntime.h"
18061da546Spatrick #include "lldb/Target/Process.h"
19061da546Spatrick #include "lldb/Target/RegisterContext.h"
20061da546Spatrick #include "lldb/Target/StopInfo.h"
21061da546Spatrick #include "lldb/Target/Target.h"
22061da546Spatrick #include "lldb/Target/Thread.h"
23061da546Spatrick #include "lldb/Target/ThreadPlanRunToAddress.h"
24*f6aab3d8Srobert #include "lldb/Utility/LLDBLog.h"
25061da546Spatrick #include "lldb/Utility/Log.h"
26061da546Spatrick #include "lldb/Utility/Stream.h"
27061da546Spatrick
28061da546Spatrick #include <memory>
29061da546Spatrick
30061da546Spatrick using namespace lldb;
31061da546Spatrick using namespace lldb_private;
32061da546Spatrick
33061da546Spatrick // ThreadPlanCallFunction: Plan to call a single function
ConstructorSetup(Thread & thread,ABI * & abi,lldb::addr_t & start_load_addr,lldb::addr_t & function_load_addr)34061da546Spatrick bool ThreadPlanCallFunction::ConstructorSetup(
35061da546Spatrick Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr,
36061da546Spatrick lldb::addr_t &function_load_addr) {
37*f6aab3d8Srobert SetIsControllingPlan(true);
38061da546Spatrick SetOkayToDiscard(false);
39061da546Spatrick SetPrivate(true);
40061da546Spatrick
41061da546Spatrick ProcessSP process_sp(thread.GetProcess());
42061da546Spatrick if (!process_sp)
43061da546Spatrick return false;
44061da546Spatrick
45061da546Spatrick abi = process_sp->GetABI().get();
46061da546Spatrick
47061da546Spatrick if (!abi)
48061da546Spatrick return false;
49061da546Spatrick
50*f6aab3d8Srobert Log *log = GetLog(LLDBLog::Step);
51061da546Spatrick
52061da546Spatrick SetBreakpoints();
53061da546Spatrick
54061da546Spatrick m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
55061da546Spatrick // If we can't read memory at the point of the process where we are planning
56061da546Spatrick // to put our function, we're not going to get any further...
57061da546Spatrick Status error;
58061da546Spatrick process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
59061da546Spatrick if (!error.Success()) {
60061da546Spatrick m_constructor_errors.Printf(
61061da546Spatrick "Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".",
62061da546Spatrick m_function_sp);
63061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
64061da546Spatrick m_constructor_errors.GetData());
65061da546Spatrick return false;
66061da546Spatrick }
67061da546Spatrick
68061da546Spatrick llvm::Expected<Address> start_address = GetTarget().GetEntryPointAddress();
69061da546Spatrick if (!start_address) {
70061da546Spatrick m_constructor_errors.Printf(
71061da546Spatrick "%s", llvm::toString(start_address.takeError()).c_str());
72061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
73061da546Spatrick m_constructor_errors.GetData());
74061da546Spatrick return false;
75061da546Spatrick }
76061da546Spatrick
77061da546Spatrick m_start_addr = *start_address;
78061da546Spatrick start_load_addr = m_start_addr.GetLoadAddress(&GetTarget());
79061da546Spatrick
80061da546Spatrick // Checkpoint the thread state so we can restore it later.
81061da546Spatrick if (log && log->GetVerbose())
82061da546Spatrick ReportRegisterState("About to checkpoint thread before function call. "
83061da546Spatrick "Original register state was:");
84061da546Spatrick
85061da546Spatrick if (!thread.CheckpointThreadState(m_stored_thread_state)) {
86061da546Spatrick m_constructor_errors.Printf("Setting up ThreadPlanCallFunction, failed to "
87061da546Spatrick "checkpoint thread state.");
88061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
89061da546Spatrick m_constructor_errors.GetData());
90061da546Spatrick return false;
91061da546Spatrick }
92061da546Spatrick function_load_addr = m_function_addr.GetLoadAddress(&GetTarget());
93061da546Spatrick
94061da546Spatrick return true;
95061da546Spatrick }
96061da546Spatrick
ThreadPlanCallFunction(Thread & thread,const Address & function,const CompilerType & return_type,llvm::ArrayRef<addr_t> args,const EvaluateExpressionOptions & options)97061da546Spatrick ThreadPlanCallFunction::ThreadPlanCallFunction(
98061da546Spatrick Thread &thread, const Address &function, const CompilerType &return_type,
99061da546Spatrick llvm::ArrayRef<addr_t> args, const EvaluateExpressionOptions &options)
100061da546Spatrick : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
101061da546Spatrick eVoteNoOpinion, eVoteNoOpinion),
102061da546Spatrick m_valid(false), m_stop_other_threads(options.GetStopOthers()),
103061da546Spatrick m_unwind_on_error(options.DoesUnwindOnError()),
104061da546Spatrick m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
105061da546Spatrick m_debug_execution(options.GetDebug()),
106061da546Spatrick m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
107*f6aab3d8Srobert m_start_addr(), m_function_sp(0), m_subplan_sp(),
108*f6aab3d8Srobert m_cxx_language_runtime(nullptr), m_objc_language_runtime(nullptr),
109*f6aab3d8Srobert m_stored_thread_state(), m_real_stop_info_sp(), m_constructor_errors(),
110*f6aab3d8Srobert m_return_valobj_sp(), m_takedown_done(false),
111061da546Spatrick m_should_clear_objc_exception_bp(false),
112061da546Spatrick m_should_clear_cxx_exception_bp(false),
113061da546Spatrick m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(return_type) {
114061da546Spatrick lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
115061da546Spatrick lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
116061da546Spatrick ABI *abi = nullptr;
117061da546Spatrick
118061da546Spatrick if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
119061da546Spatrick return;
120061da546Spatrick
121061da546Spatrick if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
122061da546Spatrick start_load_addr, args))
123061da546Spatrick return;
124061da546Spatrick
125061da546Spatrick ReportRegisterState("Function call was set up. Register state was:");
126061da546Spatrick
127061da546Spatrick m_valid = true;
128061da546Spatrick }
129061da546Spatrick
ThreadPlanCallFunction(Thread & thread,const Address & function,const EvaluateExpressionOptions & options)130061da546Spatrick ThreadPlanCallFunction::ThreadPlanCallFunction(
131061da546Spatrick Thread &thread, const Address &function,
132061da546Spatrick const EvaluateExpressionOptions &options)
133061da546Spatrick : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
134061da546Spatrick eVoteNoOpinion, eVoteNoOpinion),
135061da546Spatrick m_valid(false), m_stop_other_threads(options.GetStopOthers()),
136061da546Spatrick m_unwind_on_error(options.DoesUnwindOnError()),
137061da546Spatrick m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
138061da546Spatrick m_debug_execution(options.GetDebug()),
139061da546Spatrick m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
140*f6aab3d8Srobert m_start_addr(), m_function_sp(0), m_subplan_sp(),
141*f6aab3d8Srobert m_cxx_language_runtime(nullptr), m_objc_language_runtime(nullptr),
142*f6aab3d8Srobert m_stored_thread_state(), m_real_stop_info_sp(), m_constructor_errors(),
143*f6aab3d8Srobert m_return_valobj_sp(), m_takedown_done(false),
144061da546Spatrick m_should_clear_objc_exception_bp(false),
145061da546Spatrick m_should_clear_cxx_exception_bp(false),
146061da546Spatrick m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {}
147061da546Spatrick
~ThreadPlanCallFunction()148061da546Spatrick ThreadPlanCallFunction::~ThreadPlanCallFunction() {
149061da546Spatrick DoTakedown(PlanSucceeded());
150061da546Spatrick }
151061da546Spatrick
ReportRegisterState(const char * message)152061da546Spatrick void ThreadPlanCallFunction::ReportRegisterState(const char *message) {
153*f6aab3d8Srobert Log *log = GetLog(LLDBLog::Step);
154061da546Spatrick if (log && log->GetVerbose()) {
155061da546Spatrick StreamString strm;
156dda28197Spatrick RegisterContext *reg_ctx = GetThread().GetRegisterContext().get();
157061da546Spatrick
158061da546Spatrick log->PutCString(message);
159061da546Spatrick
160061da546Spatrick RegisterValue reg_value;
161061da546Spatrick
162061da546Spatrick for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
163061da546Spatrick reg_idx < num_registers; ++reg_idx) {
164061da546Spatrick const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
165061da546Spatrick if (reg_ctx->ReadRegister(reg_info, reg_value)) {
166061da546Spatrick DumpRegisterValue(reg_value, &strm, reg_info, true, false,
167061da546Spatrick eFormatDefault);
168061da546Spatrick strm.EOL();
169061da546Spatrick }
170061da546Spatrick }
171061da546Spatrick log->PutString(strm.GetString());
172061da546Spatrick }
173061da546Spatrick }
174061da546Spatrick
DoTakedown(bool success)175061da546Spatrick void ThreadPlanCallFunction::DoTakedown(bool success) {
176*f6aab3d8Srobert Log *log = GetLog(LLDBLog::Step);
177061da546Spatrick
178061da546Spatrick if (!m_valid) {
179061da546Spatrick // Don't call DoTakedown if we were never valid to begin with.
180061da546Spatrick LLDB_LOGF(log,
181061da546Spatrick "ThreadPlanCallFunction(%p): Log called on "
182061da546Spatrick "ThreadPlanCallFunction that was never valid.",
183061da546Spatrick static_cast<void *>(this));
184061da546Spatrick return;
185061da546Spatrick }
186061da546Spatrick
187061da546Spatrick if (!m_takedown_done) {
188dda28197Spatrick Thread &thread = GetThread();
189061da546Spatrick if (success) {
190061da546Spatrick SetReturnValue();
191061da546Spatrick }
192061da546Spatrick LLDB_LOGF(log,
193061da546Spatrick "ThreadPlanCallFunction(%p): DoTakedown called for thread "
194061da546Spatrick "0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
195dda28197Spatrick static_cast<void *>(this), m_tid, m_valid, IsPlanComplete());
196061da546Spatrick m_takedown_done = true;
197061da546Spatrick m_stop_address =
198dda28197Spatrick thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
199061da546Spatrick m_real_stop_info_sp = GetPrivateStopInfo();
200dda28197Spatrick if (!thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) {
201061da546Spatrick LLDB_LOGF(log,
202061da546Spatrick "ThreadPlanCallFunction(%p): DoTakedown failed to restore "
203061da546Spatrick "register state",
204061da546Spatrick static_cast<void *>(this));
205061da546Spatrick }
206061da546Spatrick SetPlanComplete(success);
207061da546Spatrick ClearBreakpoints();
208061da546Spatrick if (log && log->GetVerbose())
209061da546Spatrick ReportRegisterState("Restoring thread state after function call. "
210061da546Spatrick "Restored register state:");
211061da546Spatrick } else {
212061da546Spatrick LLDB_LOGF(log,
213061da546Spatrick "ThreadPlanCallFunction(%p): DoTakedown called as no-op for "
214061da546Spatrick "thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
215dda28197Spatrick static_cast<void *>(this), m_tid, m_valid, IsPlanComplete());
216061da546Spatrick }
217061da546Spatrick }
218061da546Spatrick
DidPop()219*f6aab3d8Srobert void ThreadPlanCallFunction::DidPop() { DoTakedown(PlanSucceeded()); }
220061da546Spatrick
GetDescription(Stream * s,DescriptionLevel level)221061da546Spatrick void ThreadPlanCallFunction::GetDescription(Stream *s, DescriptionLevel level) {
222061da546Spatrick if (level == eDescriptionLevelBrief) {
223061da546Spatrick s->Printf("Function call thread plan");
224061da546Spatrick } else {
225061da546Spatrick s->Printf("Thread plan to call 0x%" PRIx64,
226dda28197Spatrick m_function_addr.GetLoadAddress(&GetTarget()));
227061da546Spatrick }
228061da546Spatrick }
229061da546Spatrick
ValidatePlan(Stream * error)230061da546Spatrick bool ThreadPlanCallFunction::ValidatePlan(Stream *error) {
231061da546Spatrick if (!m_valid) {
232061da546Spatrick if (error) {
233061da546Spatrick if (m_constructor_errors.GetSize() > 0)
234061da546Spatrick error->PutCString(m_constructor_errors.GetString());
235061da546Spatrick else
236061da546Spatrick error->PutCString("Unknown error");
237061da546Spatrick }
238061da546Spatrick return false;
239061da546Spatrick }
240061da546Spatrick
241061da546Spatrick return true;
242061da546Spatrick }
243061da546Spatrick
ShouldReportStop(Event * event_ptr)244061da546Spatrick Vote ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) {
245061da546Spatrick if (m_takedown_done || IsPlanComplete())
246061da546Spatrick return eVoteYes;
247061da546Spatrick else
248061da546Spatrick return ThreadPlan::ShouldReportStop(event_ptr);
249061da546Spatrick }
250061da546Spatrick
DoPlanExplainsStop(Event * event_ptr)251061da546Spatrick bool ThreadPlanCallFunction::DoPlanExplainsStop(Event *event_ptr) {
252*f6aab3d8Srobert Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
253061da546Spatrick m_real_stop_info_sp = GetPrivateStopInfo();
254061da546Spatrick
255061da546Spatrick // If our subplan knows why we stopped, even if it's done (which would
256061da546Spatrick // forward the question to us) we answer yes.
257061da546Spatrick if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr)) {
258061da546Spatrick SetPlanComplete();
259061da546Spatrick return true;
260061da546Spatrick }
261061da546Spatrick
262061da546Spatrick // Check if the breakpoint is one of ours.
263061da546Spatrick
264061da546Spatrick StopReason stop_reason;
265061da546Spatrick if (!m_real_stop_info_sp)
266061da546Spatrick stop_reason = eStopReasonNone;
267061da546Spatrick else
268061da546Spatrick stop_reason = m_real_stop_info_sp->GetStopReason();
269be691f3bSpatrick LLDB_LOG(log,
270be691f3bSpatrick "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - {0}.",
271be691f3bSpatrick Thread::StopReasonAsString(stop_reason));
272061da546Spatrick
273061da546Spatrick if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
274061da546Spatrick return true;
275061da546Spatrick
276061da546Spatrick // One more quirk here. If this event was from Halt interrupting the target,
277061da546Spatrick // then we should not consider ourselves complete. Return true to
278061da546Spatrick // acknowledge the stop.
279061da546Spatrick if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr)) {
280061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop: The event is an "
281061da546Spatrick "Interrupt, returning true.");
282061da546Spatrick return true;
283061da546Spatrick }
284061da546Spatrick // We control breakpoints separately from other "stop reasons." So first,
285061da546Spatrick // check the case where we stopped for an internal breakpoint, in that case,
286061da546Spatrick // continue on. If it is not an internal breakpoint, consult
287061da546Spatrick // m_ignore_breakpoints.
288061da546Spatrick
289061da546Spatrick if (stop_reason == eStopReasonBreakpoint) {
290061da546Spatrick uint64_t break_site_id = m_real_stop_info_sp->GetValue();
291061da546Spatrick BreakpointSiteSP bp_site_sp;
292dda28197Spatrick bp_site_sp = m_process.GetBreakpointSiteList().FindByID(break_site_id);
293061da546Spatrick if (bp_site_sp) {
294061da546Spatrick uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
295061da546Spatrick bool is_internal = true;
296061da546Spatrick for (uint32_t i = 0; i < num_owners; i++) {
297061da546Spatrick Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
298061da546Spatrick LLDB_LOGF(log,
299061da546Spatrick "ThreadPlanCallFunction::PlanExplainsStop: hit "
300061da546Spatrick "breakpoint %d while calling function",
301061da546Spatrick bp.GetID());
302061da546Spatrick
303061da546Spatrick if (!bp.IsInternal()) {
304061da546Spatrick is_internal = false;
305061da546Spatrick break;
306061da546Spatrick }
307061da546Spatrick }
308061da546Spatrick if (is_internal) {
309061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop hit an "
310061da546Spatrick "internal breakpoint, not stopping.");
311061da546Spatrick return false;
312061da546Spatrick }
313061da546Spatrick }
314061da546Spatrick
315061da546Spatrick if (m_ignore_breakpoints) {
316061da546Spatrick LLDB_LOGF(log,
317061da546Spatrick "ThreadPlanCallFunction::PlanExplainsStop: we are ignoring "
318061da546Spatrick "breakpoints, overriding breakpoint stop info ShouldStop, "
319061da546Spatrick "returning true");
320061da546Spatrick m_real_stop_info_sp->OverrideShouldStop(false);
321061da546Spatrick return true;
322061da546Spatrick } else {
323061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop: we are not "
324061da546Spatrick "ignoring breakpoints, overriding breakpoint stop info "
325061da546Spatrick "ShouldStop, returning true");
326061da546Spatrick m_real_stop_info_sp->OverrideShouldStop(true);
327061da546Spatrick return false;
328061da546Spatrick }
329061da546Spatrick } else if (!m_unwind_on_error) {
330061da546Spatrick // If we don't want to discard this plan, than any stop we don't understand
331061da546Spatrick // should be propagated up the stack.
332061da546Spatrick return false;
333061da546Spatrick } else {
334061da546Spatrick // If the subplan is running, any crashes are attributable to us. If we
335061da546Spatrick // want to discard the plan, then we say we explain the stop but if we are
336061da546Spatrick // going to be discarded, let whoever is above us explain the stop. But
337061da546Spatrick // don't discard the plan if the stop would restart itself (for instance if
338061da546Spatrick // it is a signal that is set not to stop. Check that here first. We just
339061da546Spatrick // say we explain the stop but aren't done and everything will continue on
340061da546Spatrick // from there.
341061da546Spatrick
342061da546Spatrick if (m_real_stop_info_sp &&
343061da546Spatrick m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) {
344061da546Spatrick SetPlanComplete(false);
345061da546Spatrick return m_subplan_sp ? m_unwind_on_error : false;
346061da546Spatrick } else
347061da546Spatrick return true;
348061da546Spatrick }
349061da546Spatrick }
350061da546Spatrick
ShouldStop(Event * event_ptr)351061da546Spatrick bool ThreadPlanCallFunction::ShouldStop(Event *event_ptr) {
352061da546Spatrick // We do some computation in DoPlanExplainsStop that may or may not set the
353061da546Spatrick // plan as complete. We need to do that here to make sure our state is
354061da546Spatrick // correct.
355061da546Spatrick DoPlanExplainsStop(event_ptr);
356061da546Spatrick
357061da546Spatrick if (IsPlanComplete()) {
358061da546Spatrick ReportRegisterState("Function completed. Register state was:");
359061da546Spatrick return true;
360061da546Spatrick } else {
361061da546Spatrick return false;
362061da546Spatrick }
363061da546Spatrick }
364061da546Spatrick
StopOthers()365061da546Spatrick bool ThreadPlanCallFunction::StopOthers() { return m_stop_other_threads; }
366061da546Spatrick
GetPlanRunState()367061da546Spatrick StateType ThreadPlanCallFunction::GetPlanRunState() { return eStateRunning; }
368061da546Spatrick
DidPush()369061da546Spatrick void ThreadPlanCallFunction::DidPush() {
370061da546Spatrick //#define SINGLE_STEP_EXPRESSIONS
371061da546Spatrick
372061da546Spatrick // Now set the thread state to "no reason" so we don't run with whatever
373061da546Spatrick // signal was outstanding... Wait till the plan is pushed so we aren't
374061da546Spatrick // changing the stop info till we're about to run.
375061da546Spatrick
376061da546Spatrick GetThread().SetStopInfoToNothing();
377061da546Spatrick
378061da546Spatrick #ifndef SINGLE_STEP_EXPRESSIONS
379dda28197Spatrick Thread &thread = GetThread();
380dda28197Spatrick m_subplan_sp = std::make_shared<ThreadPlanRunToAddress>(thread, m_start_addr,
381dda28197Spatrick m_stop_other_threads);
382061da546Spatrick
383dda28197Spatrick thread.QueueThreadPlan(m_subplan_sp, false);
384061da546Spatrick m_subplan_sp->SetPrivate(true);
385061da546Spatrick #endif
386061da546Spatrick }
387061da546Spatrick
WillStop()388061da546Spatrick bool ThreadPlanCallFunction::WillStop() { return true; }
389061da546Spatrick
MischiefManaged()390061da546Spatrick bool ThreadPlanCallFunction::MischiefManaged() {
391*f6aab3d8Srobert Log *log = GetLog(LLDBLog::Step);
392061da546Spatrick
393061da546Spatrick if (IsPlanComplete()) {
394061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction(%p): Completed call function plan.",
395061da546Spatrick static_cast<void *>(this));
396061da546Spatrick
397061da546Spatrick ThreadPlan::MischiefManaged();
398061da546Spatrick return true;
399061da546Spatrick } else {
400061da546Spatrick return false;
401061da546Spatrick }
402061da546Spatrick }
403061da546Spatrick
SetBreakpoints()404061da546Spatrick void ThreadPlanCallFunction::SetBreakpoints() {
405dda28197Spatrick if (m_trap_exceptions) {
406061da546Spatrick m_cxx_language_runtime =
407dda28197Spatrick m_process.GetLanguageRuntime(eLanguageTypeC_plus_plus);
408dda28197Spatrick m_objc_language_runtime = m_process.GetLanguageRuntime(eLanguageTypeObjC);
409061da546Spatrick
410061da546Spatrick if (m_cxx_language_runtime) {
411061da546Spatrick m_should_clear_cxx_exception_bp =
412061da546Spatrick !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
413061da546Spatrick m_cxx_language_runtime->SetExceptionBreakpoints();
414061da546Spatrick }
415061da546Spatrick if (m_objc_language_runtime) {
416061da546Spatrick m_should_clear_objc_exception_bp =
417061da546Spatrick !m_objc_language_runtime->ExceptionBreakpointsAreSet();
418061da546Spatrick m_objc_language_runtime->SetExceptionBreakpoints();
419061da546Spatrick }
420061da546Spatrick }
421061da546Spatrick }
422061da546Spatrick
ClearBreakpoints()423061da546Spatrick void ThreadPlanCallFunction::ClearBreakpoints() {
424061da546Spatrick if (m_trap_exceptions) {
425061da546Spatrick if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
426061da546Spatrick m_cxx_language_runtime->ClearExceptionBreakpoints();
427061da546Spatrick if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
428061da546Spatrick m_objc_language_runtime->ClearExceptionBreakpoints();
429061da546Spatrick }
430061da546Spatrick }
431061da546Spatrick
BreakpointsExplainStop()432061da546Spatrick bool ThreadPlanCallFunction::BreakpointsExplainStop() {
433061da546Spatrick StopInfoSP stop_info_sp = GetPrivateStopInfo();
434061da546Spatrick
435061da546Spatrick if (m_trap_exceptions) {
436061da546Spatrick if ((m_cxx_language_runtime &&
437061da546Spatrick m_cxx_language_runtime->ExceptionBreakpointsExplainStop(
438061da546Spatrick stop_info_sp)) ||
439061da546Spatrick (m_objc_language_runtime &&
440061da546Spatrick m_objc_language_runtime->ExceptionBreakpointsExplainStop(
441061da546Spatrick stop_info_sp))) {
442*f6aab3d8Srobert Log *log = GetLog(LLDBLog::Step);
443061da546Spatrick LLDB_LOGF(log, "ThreadPlanCallFunction::BreakpointsExplainStop - Hit an "
444061da546Spatrick "exception breakpoint, setting plan complete.");
445061da546Spatrick
446061da546Spatrick SetPlanComplete(false);
447061da546Spatrick
448061da546Spatrick // If the user has set the ObjC language breakpoint, it would normally
449061da546Spatrick // get priority over our internal catcher breakpoint, but in this case we
450061da546Spatrick // can't let that happen, so force the ShouldStop here.
451061da546Spatrick stop_info_sp->OverrideShouldStop(true);
452061da546Spatrick return true;
453061da546Spatrick }
454061da546Spatrick }
455061da546Spatrick
456061da546Spatrick return false;
457061da546Spatrick }
458061da546Spatrick
SetStopOthers(bool new_value)459061da546Spatrick void ThreadPlanCallFunction::SetStopOthers(bool new_value) {
460061da546Spatrick m_subplan_sp->SetStopOthers(new_value);
461061da546Spatrick }
462061da546Spatrick
RestoreThreadState()463be691f3bSpatrick void ThreadPlanCallFunction::RestoreThreadState() {
464be691f3bSpatrick GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
465061da546Spatrick }
466061da546Spatrick
SetReturnValue()467061da546Spatrick void ThreadPlanCallFunction::SetReturnValue() {
468dda28197Spatrick const ABI *abi = m_process.GetABI().get();
469061da546Spatrick if (abi && m_return_type.IsValid()) {
470061da546Spatrick const bool persistent = false;
471061da546Spatrick m_return_valobj_sp =
472dda28197Spatrick abi->GetReturnValueObject(GetThread(), m_return_type, persistent);
473061da546Spatrick }
474061da546Spatrick }
475