blob: e3b9ae15dc95e9ad2084ade24931157390c23a14 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- ThreadPlanCallFunction.cpp ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Chris Lattner30fdc8d2010-06-08 16:52:2410// C Includes
11// C++ Includes
12// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:2413// Project includes
Eugene Zelenkoe65b2cf2015-12-15 01:33:1914#include "lldb/Target/ThreadPlanCallFunction.h"
Jim Ingham40d871f2010-10-26 00:27:4515#include "lldb/Breakpoint/Breakpoint.h"
16#include "lldb/Breakpoint/BreakpointLocation.h"
Chris Lattner30fdc8d2010-06-08 16:52:2417#include "lldb/Core/Address.h"
Greg Clayton1f746072012-08-29 21:13:0618#include "lldb/Core/Module.h"
Greg Clayton1f746072012-08-29 21:13:0619#include "lldb/Symbol/ObjectFile.h"
Zachary Turner32abc6e2015-03-03 19:23:0920#include "lldb/Target/ABI.h"
Sean Callananf2115102010-11-03 22:19:3821#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:2422#include "lldb/Target/Process.h"
23#include "lldb/Target/RegisterContext.h"
Jim Ingham40d871f2010-10-26 00:27:4524#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:2425#include "lldb/Target/Target.h"
26#include "lldb/Target/Thread.h"
27#include "lldb/Target/ThreadPlanRunToAddress.h"
Zachary Turner6f9e6902017-03-03 20:56:2828#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:5029#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:2430
31using namespace lldb;
32using namespace lldb_private;
33
34//----------------------------------------------------------------------
35// ThreadPlanCallFunction: Plan to call a single function
36//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:5037bool ThreadPlanCallFunction::ConstructorSetup(
38 Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr,
39 lldb::addr_t &function_load_addr) {
40 SetIsMasterPlan(true);
41 SetOkayToDiscard(false);
42 SetPrivate(true);
Jim Ingham0092c8e2012-04-13 20:38:1343
Kate Stoneb9c1b512016-09-06 20:57:5044 ProcessSP process_sp(thread.GetProcess());
45 if (!process_sp)
46 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1047
Kate Stoneb9c1b512016-09-06 20:57:5048 abi = process_sp->GetABI().get();
Saleem Abdulrasool324a1032014-04-04 04:06:1049
Kate Stoneb9c1b512016-09-06 20:57:5050 if (!abi)
51 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1052
Kate Stoneb9c1b512016-09-06 20:57:5053 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:1054
Kate Stoneb9c1b512016-09-06 20:57:5055 SetBreakpoints();
Saleem Abdulrasool324a1032014-04-04 04:06:1056
Kate Stoneb9c1b512016-09-06 20:57:5057 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
58 // If we can't read memory at the point of the process where we are planning
59 // to put our function, we're
60 // not going to get any further...
Zachary Turner97206d52017-05-12 04:51:5561 Status error;
Kate Stoneb9c1b512016-09-06 20:57:5062 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
63 if (!error.Success()) {
64 m_constructor_errors.Printf(
65 "Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".",
66 m_function_sp);
67 if (log)
68 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
69 m_constructor_errors.GetData());
70 return false;
71 }
72
73 Module *exe_module = GetTarget().GetExecutableModulePointer();
74
75 if (exe_module == nullptr) {
76 m_constructor_errors.Printf(
77 "Can't execute code without an executable module.");
78 if (log)
79 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
80 m_constructor_errors.GetData());
81 return false;
82 } else {
83 ObjectFile *objectFile = exe_module->GetObjectFile();
84 if (!objectFile) {
85 m_constructor_errors.Printf(
86 "Could not find object file for module \"%s\".",
87 exe_module->GetFileSpec().GetFilename().AsCString());
88
89 if (log)
90 log->Printf("ThreadPlanCallFunction(%p): %s.",
91 static_cast<void *>(this), m_constructor_errors.GetData());
92 return false;
Jim Ingham0092c8e2012-04-13 20:38:1393 }
Saleem Abdulrasool324a1032014-04-04 04:06:1094
Kate Stoneb9c1b512016-09-06 20:57:5095 m_start_addr = objectFile->GetEntryPointAddress();
96 if (!m_start_addr.IsValid()) {
97 m_constructor_errors.Printf(
98 "Could not find entry point address for executable module \"%s\".",
99 exe_module->GetFileSpec().GetFilename().AsCString());
100 if (log)
101 log->Printf("ThreadPlanCallFunction(%p): %s.",
102 static_cast<void *>(this), m_constructor_errors.GetData());
103 return false;
Jim Ingham0092c8e2012-04-13 20:38:13104 }
Kate Stoneb9c1b512016-09-06 20:57:50105 }
Jim Inghamea06f3b2013-03-28 00:04:05106
Kate Stoneb9c1b512016-09-06 20:57:50107 start_load_addr = m_start_addr.GetLoadAddress(&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:10108
Kate Stoneb9c1b512016-09-06 20:57:50109 // Checkpoint the thread state so we can restore it later.
110 if (log && log->GetVerbose())
111 ReportRegisterState("About to checkpoint thread before function call. "
112 "Original register state was:");
113
114 if (!thread.CheckpointThreadState(m_stored_thread_state)) {
115 m_constructor_errors.Printf("Setting up ThreadPlanCallFunction, failed to "
116 "checkpoint thread state.");
117 if (log)
118 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
119 m_constructor_errors.GetData());
120 return false;
121 }
122 function_load_addr = m_function_addr.GetLoadAddress(&GetTarget());
123
124 return true;
125}
126
127ThreadPlanCallFunction::ThreadPlanCallFunction(
128 Thread &thread, const Address &function, const CompilerType &return_type,
129 llvm::ArrayRef<addr_t> args, const EvaluateExpressionOptions &options)
130 : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
131 eVoteNoOpinion, eVoteNoOpinion),
132 m_valid(false), m_stop_other_threads(options.GetStopOthers()),
133 m_unwind_on_error(options.DoesUnwindOnError()),
134 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
135 m_debug_execution(options.GetDebug()),
136 m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
137 m_function_sp(0), m_takedown_done(false),
138 m_should_clear_objc_exception_bp(false),
139 m_should_clear_cxx_exception_bp(false),
140 m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(return_type) {
141 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
142 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
143 ABI *abi = nullptr;
144
145 if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
146 return;
147
148 if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
149 start_load_addr, args))
150 return;
151
152 ReportRegisterState("Function call was set up. Register state was:");
153
154 m_valid = true;
155}
156
157ThreadPlanCallFunction::ThreadPlanCallFunction(
158 Thread &thread, const Address &function,
159 const EvaluateExpressionOptions &options)
160 : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
161 eVoteNoOpinion, eVoteNoOpinion),
162 m_valid(false), m_stop_other_threads(options.GetStopOthers()),
163 m_unwind_on_error(options.DoesUnwindOnError()),
164 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
165 m_debug_execution(options.GetDebug()),
166 m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
167 m_function_sp(0), m_takedown_done(false),
168 m_should_clear_objc_exception_bp(false),
169 m_should_clear_cxx_exception_bp(false),
170 m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {}
171
172ThreadPlanCallFunction::~ThreadPlanCallFunction() {
173 DoTakedown(PlanSucceeded());
174}
175
176void ThreadPlanCallFunction::ReportRegisterState(const char *message) {
Pavel Labath3b7e1982017-02-05 00:44:54177 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
178 if (log && log->GetVerbose()) {
Kate Stoneb9c1b512016-09-06 20:57:50179 StreamString strm;
180 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
181
182 log->PutCString(message);
183
184 RegisterValue reg_value;
185
186 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
187 reg_idx < num_registers; ++reg_idx) {
188 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
189 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
190 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
191 strm.EOL();
192 }
Jim Ingham0092c8e2012-04-13 20:38:13193 }
Zachary Turnerc1564272016-11-16 21:15:24194 log->PutString(strm.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50195 }
196}
Saleem Abdulrasool324a1032014-04-04 04:06:10197
Kate Stoneb9c1b512016-09-06 20:57:50198void ThreadPlanCallFunction::DoTakedown(bool success) {
199 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10200
Kate Stoneb9c1b512016-09-06 20:57:50201 if (!m_valid) {
202 // Don't call DoTakedown if we were never valid to begin with.
203 if (log)
204 log->Printf("ThreadPlanCallFunction(%p): Log called on "
205 "ThreadPlanCallFunction that was never valid.",
206 static_cast<void *>(this));
207 return;
208 }
209
210 if (!m_takedown_done) {
211 if (success) {
212 SetReturnValue();
213 }
214 if (log)
215 log->Printf("ThreadPlanCallFunction(%p): DoTakedown called for thread "
216 "0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
217 static_cast<void *>(this), m_thread.GetID(), m_valid,
218 IsPlanComplete());
219 m_takedown_done = true;
220 m_stop_address =
221 m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
222 m_real_stop_info_sp = GetPrivateStopInfo();
223 if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) {
224 if (log)
225 log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore "
226 "register state",
227 static_cast<void *>(this));
228 }
229 SetPlanComplete(success);
230 ClearBreakpoints();
Jim Ingham0092c8e2012-04-13 20:38:13231 if (log && log->GetVerbose())
Kate Stoneb9c1b512016-09-06 20:57:50232 ReportRegisterState("Restoring thread state after function call. "
233 "Restored register state:");
234 } else {
Sean Callananece96492010-11-08 03:49:50235 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50236 log->Printf("ThreadPlanCallFunction(%p): DoTakedown called as no-op for "
237 "thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
238 static_cast<void *>(this), m_thread.GetID(), m_valid,
239 IsPlanComplete());
240 }
Sean Callanan10af7c42010-11-04 01:51:38241}
242
Kate Stoneb9c1b512016-09-06 20:57:50243void ThreadPlanCallFunction::WillPop() { DoTakedown(PlanSucceeded()); }
Saleem Abdulrasool324a1032014-04-04 04:06:10244
Kate Stoneb9c1b512016-09-06 20:57:50245void ThreadPlanCallFunction::GetDescription(Stream *s, DescriptionLevel level) {
246 if (level == eDescriptionLevelBrief) {
247 s->Printf("Function call thread plan");
248 } else {
249 TargetSP target_sp(m_thread.CalculateTarget());
250 s->Printf("Thread plan to call 0x%" PRIx64,
251 m_function_addr.GetLoadAddress(target_sp.get()));
252 }
Chris Lattner30fdc8d2010-06-08 16:52:24253}
254
Kate Stoneb9c1b512016-09-06 20:57:50255bool ThreadPlanCallFunction::ValidatePlan(Stream *error) {
256 if (!m_valid) {
257 if (error) {
258 if (m_constructor_errors.GetSize() > 0)
Zachary Turnerc1564272016-11-16 21:15:24259 error->PutCString(m_constructor_errors.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50260 else
261 error->PutCString("Unknown error");
262 }
263 return false;
264 }
265
266 return true;
Jim Inghambda4e5eb2011-01-18 01:58:06267}
268
Kate Stoneb9c1b512016-09-06 20:57:50269Vote ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) {
270 if (m_takedown_done || IsPlanComplete())
271 return eVoteYes;
272 else
273 return ThreadPlan::ShouldReportStop(event_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24274}
275
Kate Stoneb9c1b512016-09-06 20:57:50276bool ThreadPlanCallFunction::DoPlanExplainsStop(Event *event_ptr) {
277 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP |
278 LIBLLDB_LOG_PROCESS));
279 m_real_stop_info_sp = GetPrivateStopInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24280
Kate Stoneb9c1b512016-09-06 20:57:50281 // If our subplan knows why we stopped, even if it's done (which would forward
282 // the question to us)
283 // we answer yes.
284 if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr)) {
285 SetPlanComplete();
Chris Lattner30fdc8d2010-06-08 16:52:24286 return true;
Kate Stoneb9c1b512016-09-06 20:57:50287 }
Chris Lattner30fdc8d2010-06-08 16:52:24288
Kate Stoneb9c1b512016-09-06 20:57:50289 // Check if the breakpoint is one of ours.
Jim Ingham0161b492013-02-09 01:29:05290
Kate Stoneb9c1b512016-09-06 20:57:50291 StopReason stop_reason;
292 if (!m_real_stop_info_sp)
293 stop_reason = eStopReasonNone;
294 else
295 stop_reason = m_real_stop_info_sp->GetStopReason();
296 if (log)
297 log->Printf(
298 "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.",
299 Thread::StopReasonAsCString(stop_reason));
300
301 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
302 return true;
303
304 // One more quirk here. If this event was from Halt interrupting the target,
305 // then we should not consider
306 // ourselves complete. Return true to acknowledge the stop.
307 if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr)) {
Jim Ingham0161b492013-02-09 01:29:05308 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50309 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: The event is an "
310 "Interrupt, returning true.");
311 return true;
312 }
313 // We control breakpoints separately from other "stop reasons." So first,
314 // check the case where we stopped for an internal breakpoint, in that case,
315 // continue on.
316 // If it is not an internal breakpoint, consult m_ignore_breakpoints.
Jim Ingham18de2fd2012-05-10 01:35:39317
Kate Stoneb9c1b512016-09-06 20:57:50318 if (stop_reason == eStopReasonBreakpoint) {
319 ProcessSP process_sp(m_thread.CalculateProcess());
320 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
321 BreakpointSiteSP bp_site_sp;
322 if (process_sp)
323 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
324 if (bp_site_sp) {
325 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
326 bool is_internal = true;
327 for (uint32_t i = 0; i < num_owners; i++) {
328 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Jim Ingham35878c42014-04-08 21:33:21329 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50330 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: hit "
331 "breakpoint %d while calling function",
332 bp.GetID());
Eugene Zelenkoe65b2cf2015-12-15 01:33:19333
Kate Stoneb9c1b512016-09-06 20:57:50334 if (!bp.IsInternal()) {
335 is_internal = false;
336 break;
Jim Ingham40d871f2010-10-26 00:27:45337 }
Kate Stoneb9c1b512016-09-06 20:57:50338 }
339 if (is_internal) {
340 if (log)
341 log->Printf("ThreadPlanCallFunction::PlanExplainsStop hit an "
342 "internal breakpoint, not stopping.");
Jim Ingham0161b492013-02-09 01:29:05343 return false;
Kate Stoneb9c1b512016-09-06 20:57:50344 }
Jim Ingham40d871f2010-10-26 00:27:45345 }
Kate Stoneb9c1b512016-09-06 20:57:50346
347 if (m_ignore_breakpoints) {
348 if (log)
349 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring "
350 "breakpoints, overriding breakpoint stop info ShouldStop, "
351 "returning true");
352 m_real_stop_info_sp->OverrideShouldStop(false);
353 return true;
354 } else {
355 if (log)
356 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not "
357 "ignoring breakpoints, overriding breakpoint stop info "
358 "ShouldStop, returning true");
359 m_real_stop_info_sp->OverrideShouldStop(true);
360 return false;
Jim Ingham40d871f2010-10-26 00:27:45361 }
Kate Stoneb9c1b512016-09-06 20:57:50362 } else if (!m_unwind_on_error) {
363 // If we don't want to discard this plan, than any stop we don't understand
364 // should be propagated up the stack.
365 return false;
366 } else {
367 // If the subplan is running, any crashes are attributable to us.
368 // If we want to discard the plan, then we say we explain the stop
369 // but if we are going to be discarded, let whoever is above us
370 // explain the stop.
371 // But don't discard the plan if the stop would restart itself (for instance
372 // if it is a
373 // signal that is set not to stop. Check that here first. We just say we
374 // explain the stop
375 // but aren't done and everything will continue on from there.
376
377 if (m_real_stop_info_sp &&
378 m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) {
379 SetPlanComplete(false);
380 return m_subplan_sp ? m_unwind_on_error : false;
381 } else
382 return true;
383 }
Chris Lattner30fdc8d2010-06-08 16:52:24384}
385
Kate Stoneb9c1b512016-09-06 20:57:50386bool ThreadPlanCallFunction::ShouldStop(Event *event_ptr) {
387 // We do some computation in DoPlanExplainsStop that may or may not set the
388 // plan as complete.
389 // We need to do that here to make sure our state is correct.
390 DoPlanExplainsStop(event_ptr);
391
392 if (IsPlanComplete()) {
393 ReportRegisterState("Function completed. Register state was:");
394 return true;
395 } else {
396 return false;
397 }
Chris Lattner30fdc8d2010-06-08 16:52:24398}
399
Kate Stoneb9c1b512016-09-06 20:57:50400bool ThreadPlanCallFunction::StopOthers() { return m_stop_other_threads; }
Chris Lattner30fdc8d2010-06-08 16:52:24401
Kate Stoneb9c1b512016-09-06 20:57:50402StateType ThreadPlanCallFunction::GetPlanRunState() { return eStateRunning; }
Chris Lattner30fdc8d2010-06-08 16:52:24403
Kate Stoneb9c1b512016-09-06 20:57:50404void ThreadPlanCallFunction::DidPush() {
405 //#define SINGLE_STEP_EXPRESSIONS
406
407 // Now set the thread state to "no reason" so we don't run with whatever
408 // signal was outstanding...
409 // Wait till the plan is pushed so we aren't changing the stop info till we're
410 // about to run.
411
412 GetThread().SetStopInfoToNothing();
413
Sean Callananbe3a1b12010-10-26 00:31:56414#ifndef SINGLE_STEP_EXPRESSIONS
Kate Stoneb9c1b512016-09-06 20:57:50415 m_subplan_sp.reset(
416 new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
417
418 m_thread.QueueThreadPlan(m_subplan_sp, false);
419 m_subplan_sp->SetPrivate(true);
Sean Callananbe3a1b12010-10-26 00:31:56420#endif
Chris Lattner30fdc8d2010-06-08 16:52:24421}
422
Kate Stoneb9c1b512016-09-06 20:57:50423bool ThreadPlanCallFunction::WillStop() { return true; }
424
425bool ThreadPlanCallFunction::MischiefManaged() {
426 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
427
428 if (IsPlanComplete()) {
429 if (log)
430 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
431 static_cast<void *>(this));
432
433 ThreadPlan::MischiefManaged();
Chris Lattner30fdc8d2010-06-08 16:52:24434 return true;
Kate Stoneb9c1b512016-09-06 20:57:50435 } else {
Sean Callananc98aca62010-11-03 19:36:28436 return false;
Kate Stoneb9c1b512016-09-06 20:57:50437 }
Sean Callananc98aca62010-11-03 19:36:28438}
Jim Ingham8559a352012-11-26 23:52:18439
Kate Stoneb9c1b512016-09-06 20:57:50440void ThreadPlanCallFunction::SetBreakpoints() {
441 ProcessSP process_sp(m_thread.CalculateProcess());
442 if (m_trap_exceptions && process_sp) {
443 m_cxx_language_runtime =
444 process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
445 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Jim Ingham0ff099f2014-03-07 11:16:37446
Kate Stoneb9c1b512016-09-06 20:57:50447 if (m_cxx_language_runtime) {
448 m_should_clear_cxx_exception_bp =
449 !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
450 m_cxx_language_runtime->SetExceptionBreakpoints();
Ewan Crawford90ff7912015-07-14 10:56:58451 }
Kate Stoneb9c1b512016-09-06 20:57:50452 if (m_objc_language_runtime) {
453 m_should_clear_objc_exception_bp =
454 !m_objc_language_runtime->ExceptionBreakpointsAreSet();
455 m_objc_language_runtime->SetExceptionBreakpoints();
456 }
457 }
458}
459
460void ThreadPlanCallFunction::ClearBreakpoints() {
461 if (m_trap_exceptions) {
462 if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
463 m_cxx_language_runtime->ClearExceptionBreakpoints();
464 if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
465 m_objc_language_runtime->ClearExceptionBreakpoints();
466 }
467}
468
469bool ThreadPlanCallFunction::BreakpointsExplainStop() {
470 StopInfoSP stop_info_sp = GetPrivateStopInfo();
471
472 if (m_trap_exceptions) {
473 if ((m_cxx_language_runtime &&
474 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(
475 stop_info_sp)) ||
476 (m_objc_language_runtime &&
477 m_objc_language_runtime->ExceptionBreakpointsExplainStop(
478 stop_info_sp))) {
479 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
480 if (log)
481 log->Printf("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an "
482 "exception breakpoint, setting plan complete.");
483
484 SetPlanComplete(false);
485
486 // If the user has set the ObjC language breakpoint, it would normally get
487 // priority over our internal
488 // catcher breakpoint, but in this case we can't let that happen, so force
489 // the ShouldStop here.
490 stop_info_sp->OverrideShouldStop(true);
491 return true;
492 }
493 }
494
495 return false;
496}
497
498void ThreadPlanCallFunction::SetStopOthers(bool new_value) {
499 m_subplan_sp->SetStopOthers(new_value);
500}
501
502bool ThreadPlanCallFunction::RestoreThreadState() {
503 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
504}
505
506void ThreadPlanCallFunction::SetReturnValue() {
507 ProcessSP process_sp(m_thread.GetProcess());
508 const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr;
509 if (abi && m_return_type.IsValid()) {
510 const bool persistent = false;
511 m_return_valobj_sp =
512 abi->GetReturnValueObject(m_thread, m_return_type, persistent);
513 }
Ewan Crawford90ff7912015-07-14 10:56:58514}