blob: a00087fee27e49007b5403d94ac3f6cc43600c86 [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
Adrian Prantl05097242018-04-30 16:49:0459 // to put our function, we're not going to get any further...
Zachary Turner97206d52017-05-12 04:51:5560 Status error;
Kate Stoneb9c1b512016-09-06 20:57:5061 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
62 if (!error.Success()) {
63 m_constructor_errors.Printf(
64 "Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".",
65 m_function_sp);
66 if (log)
67 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
68 m_constructor_errors.GetData());
69 return false;
70 }
71
72 Module *exe_module = GetTarget().GetExecutableModulePointer();
73
74 if (exe_module == nullptr) {
75 m_constructor_errors.Printf(
76 "Can't execute code without an executable module.");
77 if (log)
78 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
79 m_constructor_errors.GetData());
80 return false;
81 } else {
82 ObjectFile *objectFile = exe_module->GetObjectFile();
83 if (!objectFile) {
84 m_constructor_errors.Printf(
85 "Could not find object file for module \"%s\".",
86 exe_module->GetFileSpec().GetFilename().AsCString());
87
88 if (log)
89 log->Printf("ThreadPlanCallFunction(%p): %s.",
90 static_cast<void *>(this), m_constructor_errors.GetData());
91 return false;
Jim Ingham0092c8e2012-04-13 20:38:1392 }
Saleem Abdulrasool324a1032014-04-04 04:06:1093
Kate Stoneb9c1b512016-09-06 20:57:5094 m_start_addr = objectFile->GetEntryPointAddress();
95 if (!m_start_addr.IsValid()) {
96 m_constructor_errors.Printf(
97 "Could not find entry point address for executable module \"%s\".",
98 exe_module->GetFileSpec().GetFilename().AsCString());
99 if (log)
100 log->Printf("ThreadPlanCallFunction(%p): %s.",
101 static_cast<void *>(this), m_constructor_errors.GetData());
102 return false;
Jim Ingham0092c8e2012-04-13 20:38:13103 }
Kate Stoneb9c1b512016-09-06 20:57:50104 }
Jim Inghamea06f3b2013-03-28 00:04:05105
Kate Stoneb9c1b512016-09-06 20:57:50106 start_load_addr = m_start_addr.GetLoadAddress(&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:10107
Kate Stoneb9c1b512016-09-06 20:57:50108 // Checkpoint the thread state so we can restore it later.
109 if (log && log->GetVerbose())
110 ReportRegisterState("About to checkpoint thread before function call. "
111 "Original register state was:");
112
113 if (!thread.CheckpointThreadState(m_stored_thread_state)) {
114 m_constructor_errors.Printf("Setting up ThreadPlanCallFunction, failed to "
115 "checkpoint thread state.");
116 if (log)
117 log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
118 m_constructor_errors.GetData());
119 return false;
120 }
121 function_load_addr = m_function_addr.GetLoadAddress(&GetTarget());
122
123 return true;
124}
125
126ThreadPlanCallFunction::ThreadPlanCallFunction(
127 Thread &thread, const Address &function, const CompilerType &return_type,
128 llvm::ArrayRef<addr_t> args, 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(return_type) {
140 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
141 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
142 ABI *abi = nullptr;
143
144 if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
145 return;
146
147 if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
148 start_load_addr, args))
149 return;
150
151 ReportRegisterState("Function call was set up. Register state was:");
152
153 m_valid = true;
154}
155
156ThreadPlanCallFunction::ThreadPlanCallFunction(
157 Thread &thread, const Address &function,
158 const EvaluateExpressionOptions &options)
159 : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
160 eVoteNoOpinion, eVoteNoOpinion),
161 m_valid(false), m_stop_other_threads(options.GetStopOthers()),
162 m_unwind_on_error(options.DoesUnwindOnError()),
163 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
164 m_debug_execution(options.GetDebug()),
165 m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
166 m_function_sp(0), m_takedown_done(false),
167 m_should_clear_objc_exception_bp(false),
168 m_should_clear_cxx_exception_bp(false),
169 m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {}
170
171ThreadPlanCallFunction::~ThreadPlanCallFunction() {
172 DoTakedown(PlanSucceeded());
173}
174
175void ThreadPlanCallFunction::ReportRegisterState(const char *message) {
Pavel Labath3b7e1982017-02-05 00:44:54176 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
177 if (log && log->GetVerbose()) {
Kate Stoneb9c1b512016-09-06 20:57:50178 StreamString strm;
179 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
180
181 log->PutCString(message);
182
183 RegisterValue reg_value;
184
185 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
186 reg_idx < num_registers; ++reg_idx) {
187 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
188 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
189 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
190 strm.EOL();
191 }
Jim Ingham0092c8e2012-04-13 20:38:13192 }
Zachary Turnerc1564272016-11-16 21:15:24193 log->PutString(strm.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50194 }
195}
Saleem Abdulrasool324a1032014-04-04 04:06:10196
Kate Stoneb9c1b512016-09-06 20:57:50197void ThreadPlanCallFunction::DoTakedown(bool success) {
198 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10199
Kate Stoneb9c1b512016-09-06 20:57:50200 if (!m_valid) {
201 // Don't call DoTakedown if we were never valid to begin with.
202 if (log)
203 log->Printf("ThreadPlanCallFunction(%p): Log called on "
204 "ThreadPlanCallFunction that was never valid.",
205 static_cast<void *>(this));
206 return;
207 }
208
209 if (!m_takedown_done) {
210 if (success) {
211 SetReturnValue();
212 }
213 if (log)
214 log->Printf("ThreadPlanCallFunction(%p): DoTakedown called for thread "
215 "0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
216 static_cast<void *>(this), m_thread.GetID(), m_valid,
217 IsPlanComplete());
218 m_takedown_done = true;
219 m_stop_address =
220 m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
221 m_real_stop_info_sp = GetPrivateStopInfo();
222 if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) {
223 if (log)
224 log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore "
225 "register state",
226 static_cast<void *>(this));
227 }
228 SetPlanComplete(success);
229 ClearBreakpoints();
Jim Ingham0092c8e2012-04-13 20:38:13230 if (log && log->GetVerbose())
Kate Stoneb9c1b512016-09-06 20:57:50231 ReportRegisterState("Restoring thread state after function call. "
232 "Restored register state:");
233 } else {
Sean Callananece96492010-11-08 03:49:50234 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50235 log->Printf("ThreadPlanCallFunction(%p): DoTakedown called as no-op for "
236 "thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
237 static_cast<void *>(this), m_thread.GetID(), m_valid,
238 IsPlanComplete());
239 }
Sean Callanan10af7c42010-11-04 01:51:38240}
241
Kate Stoneb9c1b512016-09-06 20:57:50242void ThreadPlanCallFunction::WillPop() { DoTakedown(PlanSucceeded()); }
Saleem Abdulrasool324a1032014-04-04 04:06:10243
Kate Stoneb9c1b512016-09-06 20:57:50244void ThreadPlanCallFunction::GetDescription(Stream *s, DescriptionLevel level) {
245 if (level == eDescriptionLevelBrief) {
246 s->Printf("Function call thread plan");
247 } else {
248 TargetSP target_sp(m_thread.CalculateTarget());
249 s->Printf("Thread plan to call 0x%" PRIx64,
250 m_function_addr.GetLoadAddress(target_sp.get()));
251 }
Chris Lattner30fdc8d2010-06-08 16:52:24252}
253
Kate Stoneb9c1b512016-09-06 20:57:50254bool ThreadPlanCallFunction::ValidatePlan(Stream *error) {
255 if (!m_valid) {
256 if (error) {
257 if (m_constructor_errors.GetSize() > 0)
Zachary Turnerc1564272016-11-16 21:15:24258 error->PutCString(m_constructor_errors.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50259 else
260 error->PutCString("Unknown error");
261 }
262 return false;
263 }
264
265 return true;
Jim Inghambda4e5eb2011-01-18 01:58:06266}
267
Kate Stoneb9c1b512016-09-06 20:57:50268Vote ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) {
269 if (m_takedown_done || IsPlanComplete())
270 return eVoteYes;
271 else
272 return ThreadPlan::ShouldReportStop(event_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24273}
274
Kate Stoneb9c1b512016-09-06 20:57:50275bool ThreadPlanCallFunction::DoPlanExplainsStop(Event *event_ptr) {
276 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP |
277 LIBLLDB_LOG_PROCESS));
278 m_real_stop_info_sp = GetPrivateStopInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24279
Adrian Prantl05097242018-04-30 16:49:04280 // If our subplan knows why we stopped, even if it's done (which would
281 // forward the question to us) we answer yes.
Kate Stoneb9c1b512016-09-06 20:57:50282 if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr)) {
283 SetPlanComplete();
Chris Lattner30fdc8d2010-06-08 16:52:24284 return true;
Kate Stoneb9c1b512016-09-06 20:57:50285 }
Chris Lattner30fdc8d2010-06-08 16:52:24286
Kate Stoneb9c1b512016-09-06 20:57:50287 // Check if the breakpoint is one of ours.
Jim Ingham0161b492013-02-09 01:29:05288
Kate Stoneb9c1b512016-09-06 20:57:50289 StopReason stop_reason;
290 if (!m_real_stop_info_sp)
291 stop_reason = eStopReasonNone;
292 else
293 stop_reason = m_real_stop_info_sp->GetStopReason();
294 if (log)
295 log->Printf(
296 "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.",
297 Thread::StopReasonAsCString(stop_reason));
298
299 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
300 return true;
301
302 // One more quirk here. If this event was from Halt interrupting the target,
Adrian Prantl05097242018-04-30 16:49:04303 // then we should not consider ourselves complete. Return true to
304 // acknowledge the stop.
Kate Stoneb9c1b512016-09-06 20:57:50305 if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr)) {
Jim Ingham0161b492013-02-09 01:29:05306 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50307 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: The event is an "
308 "Interrupt, returning true.");
309 return true;
310 }
311 // We control breakpoints separately from other "stop reasons." So first,
312 // check the case where we stopped for an internal breakpoint, in that case,
Adrian Prantl05097242018-04-30 16:49:04313 // continue on. If it is not an internal breakpoint, consult
314 // m_ignore_breakpoints.
Jim Ingham18de2fd2012-05-10 01:35:39315
Kate Stoneb9c1b512016-09-06 20:57:50316 if (stop_reason == eStopReasonBreakpoint) {
317 ProcessSP process_sp(m_thread.CalculateProcess());
318 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
319 BreakpointSiteSP bp_site_sp;
320 if (process_sp)
321 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
322 if (bp_site_sp) {
323 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
324 bool is_internal = true;
325 for (uint32_t i = 0; i < num_owners; i++) {
326 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Jim Ingham35878c42014-04-08 21:33:21327 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50328 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: hit "
329 "breakpoint %d while calling function",
330 bp.GetID());
Eugene Zelenkoe65b2cf2015-12-15 01:33:19331
Kate Stoneb9c1b512016-09-06 20:57:50332 if (!bp.IsInternal()) {
333 is_internal = false;
334 break;
Jim Ingham40d871f2010-10-26 00:27:45335 }
Kate Stoneb9c1b512016-09-06 20:57:50336 }
337 if (is_internal) {
338 if (log)
339 log->Printf("ThreadPlanCallFunction::PlanExplainsStop hit an "
340 "internal breakpoint, not stopping.");
Jim Ingham0161b492013-02-09 01:29:05341 return false;
Kate Stoneb9c1b512016-09-06 20:57:50342 }
Jim Ingham40d871f2010-10-26 00:27:45343 }
Kate Stoneb9c1b512016-09-06 20:57:50344
345 if (m_ignore_breakpoints) {
346 if (log)
347 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring "
348 "breakpoints, overriding breakpoint stop info ShouldStop, "
349 "returning true");
350 m_real_stop_info_sp->OverrideShouldStop(false);
351 return true;
352 } else {
353 if (log)
354 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not "
355 "ignoring breakpoints, overriding breakpoint stop info "
356 "ShouldStop, returning true");
357 m_real_stop_info_sp->OverrideShouldStop(true);
358 return false;
Jim Ingham40d871f2010-10-26 00:27:45359 }
Kate Stoneb9c1b512016-09-06 20:57:50360 } else if (!m_unwind_on_error) {
361 // If we don't want to discard this plan, than any stop we don't understand
362 // should be propagated up the stack.
363 return false;
364 } else {
Adrian Prantl05097242018-04-30 16:49:04365 // If the subplan is running, any crashes are attributable to us. If we
366 // want to discard the plan, then we say we explain the stop but if we are
367 // going to be discarded, let whoever is above us explain the stop. But
368 // don't discard the plan if the stop would restart itself (for instance if
369 // it is a signal that is set not to stop. Check that here first. We just
370 // say we explain the stop but aren't done and everything will continue on
371 // from there.
Kate Stoneb9c1b512016-09-06 20:57:50372
373 if (m_real_stop_info_sp &&
374 m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) {
375 SetPlanComplete(false);
376 return m_subplan_sp ? m_unwind_on_error : false;
377 } else
378 return true;
379 }
Chris Lattner30fdc8d2010-06-08 16:52:24380}
381
Kate Stoneb9c1b512016-09-06 20:57:50382bool ThreadPlanCallFunction::ShouldStop(Event *event_ptr) {
383 // We do some computation in DoPlanExplainsStop that may or may not set the
Adrian Prantl05097242018-04-30 16:49:04384 // plan as complete. We need to do that here to make sure our state is
385 // correct.
Kate Stoneb9c1b512016-09-06 20:57:50386 DoPlanExplainsStop(event_ptr);
387
388 if (IsPlanComplete()) {
389 ReportRegisterState("Function completed. Register state was:");
390 return true;
391 } else {
392 return false;
393 }
Chris Lattner30fdc8d2010-06-08 16:52:24394}
395
Kate Stoneb9c1b512016-09-06 20:57:50396bool ThreadPlanCallFunction::StopOthers() { return m_stop_other_threads; }
Chris Lattner30fdc8d2010-06-08 16:52:24397
Kate Stoneb9c1b512016-09-06 20:57:50398StateType ThreadPlanCallFunction::GetPlanRunState() { return eStateRunning; }
Chris Lattner30fdc8d2010-06-08 16:52:24399
Kate Stoneb9c1b512016-09-06 20:57:50400void ThreadPlanCallFunction::DidPush() {
401 //#define SINGLE_STEP_EXPRESSIONS
402
403 // Now set the thread state to "no reason" so we don't run with whatever
Adrian Prantl05097242018-04-30 16:49:04404 // signal was outstanding... Wait till the plan is pushed so we aren't
405 // changing the stop info till we're about to run.
Kate Stoneb9c1b512016-09-06 20:57:50406
407 GetThread().SetStopInfoToNothing();
408
Sean Callananbe3a1b12010-10-26 00:31:56409#ifndef SINGLE_STEP_EXPRESSIONS
Kate Stoneb9c1b512016-09-06 20:57:50410 m_subplan_sp.reset(
411 new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
412
413 m_thread.QueueThreadPlan(m_subplan_sp, false);
414 m_subplan_sp->SetPrivate(true);
Sean Callananbe3a1b12010-10-26 00:31:56415#endif
Chris Lattner30fdc8d2010-06-08 16:52:24416}
417
Kate Stoneb9c1b512016-09-06 20:57:50418bool ThreadPlanCallFunction::WillStop() { return true; }
419
420bool ThreadPlanCallFunction::MischiefManaged() {
421 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
422
423 if (IsPlanComplete()) {
424 if (log)
425 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
426 static_cast<void *>(this));
427
428 ThreadPlan::MischiefManaged();
Chris Lattner30fdc8d2010-06-08 16:52:24429 return true;
Kate Stoneb9c1b512016-09-06 20:57:50430 } else {
Sean Callananc98aca62010-11-03 19:36:28431 return false;
Kate Stoneb9c1b512016-09-06 20:57:50432 }
Sean Callananc98aca62010-11-03 19:36:28433}
Jim Ingham8559a352012-11-26 23:52:18434
Kate Stoneb9c1b512016-09-06 20:57:50435void ThreadPlanCallFunction::SetBreakpoints() {
436 ProcessSP process_sp(m_thread.CalculateProcess());
437 if (m_trap_exceptions && process_sp) {
438 m_cxx_language_runtime =
439 process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
440 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Jim Ingham0ff099f2014-03-07 11:16:37441
Kate Stoneb9c1b512016-09-06 20:57:50442 if (m_cxx_language_runtime) {
443 m_should_clear_cxx_exception_bp =
444 !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
445 m_cxx_language_runtime->SetExceptionBreakpoints();
Ewan Crawford90ff7912015-07-14 10:56:58446 }
Kate Stoneb9c1b512016-09-06 20:57:50447 if (m_objc_language_runtime) {
448 m_should_clear_objc_exception_bp =
449 !m_objc_language_runtime->ExceptionBreakpointsAreSet();
450 m_objc_language_runtime->SetExceptionBreakpoints();
451 }
452 }
453}
454
455void ThreadPlanCallFunction::ClearBreakpoints() {
456 if (m_trap_exceptions) {
457 if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
458 m_cxx_language_runtime->ClearExceptionBreakpoints();
459 if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
460 m_objc_language_runtime->ClearExceptionBreakpoints();
461 }
462}
463
464bool ThreadPlanCallFunction::BreakpointsExplainStop() {
465 StopInfoSP stop_info_sp = GetPrivateStopInfo();
466
467 if (m_trap_exceptions) {
468 if ((m_cxx_language_runtime &&
469 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(
470 stop_info_sp)) ||
471 (m_objc_language_runtime &&
472 m_objc_language_runtime->ExceptionBreakpointsExplainStop(
473 stop_info_sp))) {
474 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP));
475 if (log)
476 log->Printf("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an "
477 "exception breakpoint, setting plan complete.");
478
479 SetPlanComplete(false);
480
Adrian Prantl05097242018-04-30 16:49:04481 // If the user has set the ObjC language breakpoint, it would normally
482 // get priority over our internal catcher breakpoint, but in this case we
483 // can't let that happen, so force the ShouldStop here.
Kate Stoneb9c1b512016-09-06 20:57:50484 stop_info_sp->OverrideShouldStop(true);
485 return true;
486 }
487 }
488
489 return false;
490}
491
492void ThreadPlanCallFunction::SetStopOthers(bool new_value) {
493 m_subplan_sp->SetStopOthers(new_value);
494}
495
496bool ThreadPlanCallFunction::RestoreThreadState() {
497 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
498}
499
500void ThreadPlanCallFunction::SetReturnValue() {
501 ProcessSP process_sp(m_thread.GetProcess());
502 const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr;
503 if (abi && m_return_type.IsValid()) {
504 const bool persistent = false;
505 m_return_valobj_sp =
506 abi->GetReturnValueObject(m_thread, m_return_type, persistent);
507 }
Ewan Crawford90ff7912015-07-14 10:56:58508}