blob: e465dcf21d7a28478f441be8ec66233fc4f1ad3b [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
10#include "lldb/Target/ThreadPlanCallFunction.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
Sean Callanan6db73ca2010-11-03 01:37:5215#include "llvm/Support/MachO.h"
Chris Lattner30fdc8d2010-06-08 16:52:2416// Project includes
17#include "lldb/lldb-private-log.h"
Jim Ingham40d871f2010-10-26 00:27:4518#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
Chris Lattner30fdc8d2010-06-08 16:52:2420#include "lldb/Core/Address.h"
21#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:0622#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:2423#include "lldb/Core/Stream.h"
Greg Clayton1f746072012-08-29 21:13:0624#include "lldb/Symbol/ObjectFile.h"
Sean Callananf2115102010-11-03 22:19:3825#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:2426#include "lldb/Target/Process.h"
27#include "lldb/Target/RegisterContext.h"
Jim Ingham40d871f2010-10-26 00:27:4528#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:2429#include "lldb/Target/Target.h"
30#include "lldb/Target/Thread.h"
31#include "lldb/Target/ThreadPlanRunToAddress.h"
32
33using namespace lldb;
34using namespace lldb_private;
35
36//----------------------------------------------------------------------
37// ThreadPlanCallFunction: Plan to call a single function
38//----------------------------------------------------------------------
Jim Ingham0092c8e2012-04-13 20:38:1339bool
40ThreadPlanCallFunction::ConstructorSetup (Thread &thread,
Jim Ingham0092c8e2012-04-13 20:38:1341 ABI *& abi,
42 lldb::addr_t &start_load_addr,
43 lldb::addr_t &function_load_addr)
44{
Jim Ingham0092c8e2012-04-13 20:38:1345 SetIsMasterPlan (true);
Jim Ingham923886c2012-05-11 18:43:3846 SetOkayToDiscard (false);
Andrew Kaylor327c2672012-12-07 17:56:3147 SetPrivate (true);
Jim Ingham0092c8e2012-04-13 20:38:1348
49 ProcessSP process_sp (thread.GetProcess());
50 if (!process_sp)
51 return false;
52
53 abi = process_sp->GetABI().get();
54
55 if (!abi)
56 return false;
57
Greg Clayton5160ce52013-03-27 23:08:4058 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham0092c8e2012-04-13 20:38:1359
60 SetBreakpoints();
61
62 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
63 // If we can't read memory at the point of the process where we are planning to put our function, we're
64 // not going to get any further...
65 Error error;
66 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
67 if (!error.Success())
68 {
Jim Inghamea06f3b2013-03-28 00:04:0569 m_constructor_errors.Printf ("Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", m_function_sp);
Jim Ingham0092c8e2012-04-13 20:38:1370 if (log)
Jim Inghamea06f3b2013-03-28 00:04:0571 log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1372 return false;
73 }
74
Jim Ingham6fbc48b2013-11-07 00:11:4775 Module *exe_module = GetTarget().GetExecutableModulePointer();
Jim Ingham0092c8e2012-04-13 20:38:1376
77 if (exe_module == NULL)
78 {
Jim Inghamea06f3b2013-03-28 00:04:0579 m_constructor_errors.Printf ("Can't execute code without an executable module.");
Jim Ingham0092c8e2012-04-13 20:38:1380 if (log)
Jim Inghamea06f3b2013-03-28 00:04:0581 log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1382 return false;
83 }
84 else
85 {
86 ObjectFile *objectFile = exe_module->GetObjectFile();
87 if (!objectFile)
88 {
Jim Inghamea06f3b2013-03-28 00:04:0589 m_constructor_errors.Printf ("Could not find object file for module \"%s\".",
90 exe_module->GetFileSpec().GetFilename().AsCString());
91
Jim Ingham0092c8e2012-04-13 20:38:1392 if (log)
Jim Inghamea06f3b2013-03-28 00:04:0593 log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1394 return false;
95 }
Jim Inghamea06f3b2013-03-28 00:04:0596
Jim Ingham0092c8e2012-04-13 20:38:1397 m_start_addr = objectFile->GetEntryPointAddress();
98 if (!m_start_addr.IsValid())
99 {
Jim Inghamea06f3b2013-03-28 00:04:05100 m_constructor_errors.Printf ("Could not find entry point address for executable module \"%s\".",
101 exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham0092c8e2012-04-13 20:38:13102 if (log)
Jim Inghamea06f3b2013-03-28 00:04:05103 log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:13104 return false;
105 }
106 }
107
Jim Ingham6fbc48b2013-11-07 00:11:47108 start_load_addr = m_start_addr.GetLoadAddress (&GetTarget());
Jim Ingham0092c8e2012-04-13 20:38:13109
110 // Checkpoint the thread state so we can restore it later.
111 if (log && log->GetVerbose())
112 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
113
114 if (!thread.CheckpointThreadState (m_stored_thread_state))
115 {
Jim Inghamea06f3b2013-03-28 00:04:05116 m_constructor_errors.Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
Jim Ingham0092c8e2012-04-13 20:38:13117 if (log)
Jim Inghamea06f3b2013-03-28 00:04:05118 log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:13119 return false;
120 }
Jim Ingham6fbc48b2013-11-07 00:11:47121 function_load_addr = m_function_addr.GetLoadAddress (&GetTarget());
Jim Ingham0092c8e2012-04-13 20:38:13122
123 return true;
124}
Chris Lattner30fdc8d2010-06-08 16:52:24125
126ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
Matt Kopec00049b82013-02-27 20:13:38127 const Address &function,
Jim Inghamef651602011-12-22 19:12:40128 const ClangASTType &return_type,
Sean Callanana464f3d2013-11-08 01:14:26129 llvm::ArrayRef<addr_t> args,
130 const EvaluateExpressionOptions &options) :
Jim Inghamb01e742a2010-06-19 04:45:32131 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer1ee0d4f2010-07-16 12:32:33132 m_valid (false),
Jim Ingham6fbc48b2013-11-07 00:11:47133 m_stop_other_threads (options.GetStopOthers()),
134 m_unwind_on_error (options.DoesUnwindOnError()),
135 m_ignore_breakpoints (options.DoesIgnoreBreakpoints()),
136 m_debug_execution (options.GetDebug()),
137 m_trap_exceptions (options.GetTrapExceptions()),
Jim Ingham16e0c682011-08-12 23:34:31138 m_function_addr (function),
Filipe Cabecinhasb4cb0be2012-09-11 18:11:07139 m_function_sp (0),
Jim Inghamef651602011-12-22 19:12:40140 m_return_type (return_type),
Jim Inghamce553d82011-11-01 02:46:54141 m_takedown_done (false),
Jim Ingham6fbc48b2013-11-07 00:11:47142 m_should_clear_objc_exception_bp(false),
143 m_should_clear_cxx_exception_bp (false),
144 m_stop_address (LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24145{
Jim Ingham0092c8e2012-04-13 20:38:13146 lldb::addr_t start_load_addr;
147 ABI *abi;
148 lldb::addr_t function_load_addr;
Jim Ingham923886c2012-05-11 18:43:38149 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Clayton1ac04c32012-02-21 00:09:25150 return;
Greg Clayton2a48f522011-05-14 01:50:35151
Sean Callanana464f3d2013-11-08 01:14:26152 if (!abi->PrepareTrivialCall(thread,
153 m_function_sp,
154 function_load_addr,
155 start_load_addr,
156 args))
Greg Clayton1ac04c32012-02-21 00:09:25157 return;
158
Jim Ingham9da36832011-01-22 01:27:23159 ReportRegisterState ("Function call was set up. Register state was:");
160
161 m_valid = true;
162}
163
164ThreadPlanCallFunction::~ThreadPlanCallFunction ()
165{
Jim Ingham0161b492013-02-09 01:29:05166 DoTakedown(PlanSucceeded());
Jim Ingham9da36832011-01-22 01:27:23167}
168
169void
170ThreadPlanCallFunction::ReportRegisterState (const char *message)
171{
Greg Clayton5160ce52013-03-27 23:08:40172 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callananece96492010-11-08 03:49:50173 if (log)
174 {
Greg Claytonaf247d72011-05-19 03:54:16175 StreamString strm;
Greg Clayton5ccbd292011-01-06 22:15:06176 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham9da36832011-01-22 01:27:23177
178 log->PutCString(message);
179
Greg Claytonaf247d72011-05-19 03:54:16180 RegisterValue reg_value;
181
182 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
183 reg_idx < num_registers;
184 ++reg_idx)
Sean Callananece96492010-11-08 03:49:50185 {
Greg Claytonaf247d72011-05-19 03:54:16186 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
187 if (reg_ctx->ReadRegister(reg_info, reg_value))
188 {
189 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
190 strm.EOL();
191 }
Sean Callananece96492010-11-08 03:49:50192 }
Greg Claytonaf247d72011-05-19 03:54:16193 log->PutCString(strm.GetData());
Sean Callananece96492010-11-08 03:49:50194 }
Sean Callanan10af7c42010-11-04 01:51:38195}
196
197void
Jim Ingham18de2fd2012-05-10 01:35:39198ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan10af7c42010-11-04 01:51:38199{
Greg Clayton5160ce52013-03-27 23:08:40200 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham87d0e612012-04-13 23:11:52201
202 if (!m_valid)
203 {
204 //Don't call DoTakedown if we were never valid to begin with.
205 if (log)
206 log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.", this);
207 return;
208 }
209
Jim Ingham9da36832011-01-22 01:27:23210 if (!m_takedown_done)
Jim Ingham77787032011-01-20 02:03:18211 {
Jim Ingham18de2fd2012-05-10 01:35:39212 if (success)
Greg Clayton70b57652011-05-15 01:25:55213 {
Jim Ingham18de2fd2012-05-10 01:35:39214 ProcessSP process_sp (m_thread.GetProcess());
215 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
216 if (abi && m_return_type.IsValid())
217 {
218 const bool persistent = false;
219 m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent);
220 }
Greg Clayton70b57652011-05-15 01:25:55221 }
Jim Ingham9da36832011-01-22 01:27:23222 if (log)
Daniel Malead01b2952012-11-29 21:49:15223 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n", this, m_thread.GetID(), m_valid, IsPlanComplete());
Jim Ingham9da36832011-01-22 01:27:23224 m_takedown_done = true;
Jim Inghamce553d82011-11-01 02:46:54225 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham60c41182013-06-04 01:40:51226 m_real_stop_info_sp = GetPrivateStopInfo ();
Ed Maste7b24e952013-11-12 16:47:08227 if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state))
228 {
229 if (log)
230 log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore register state", this);
231 }
Jim Ingham18de2fd2012-05-10 01:35:39232 SetPlanComplete(success);
Jim Ingham77787032011-01-20 02:03:18233 ClearBreakpoints();
Jim Ingham9da36832011-01-22 01:27:23234 if (log && log->GetVerbose())
235 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham2c364392011-01-26 19:13:09236
Jim Ingham9da36832011-01-22 01:27:23237 }
238 else
239 {
240 if (log)
Daniel Malead01b2952012-11-29 21:49:15241 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called as no-op for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n", this, m_thread.GetID(), m_valid, IsPlanComplete());
Jim Ingham77787032011-01-20 02:03:18242 }
Chris Lattner30fdc8d2010-06-08 16:52:24243}
244
245void
Jim Inghambda4e5eb2011-01-18 01:58:06246ThreadPlanCallFunction::WillPop ()
247{
Jim Ingham0161b492013-02-09 01:29:05248 DoTakedown(PlanSucceeded());
Jim Inghambda4e5eb2011-01-18 01:58:06249}
250
251void
Greg Clayton2a48f522011-05-14 01:50:35252ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24253{
Greg Clayton2a48f522011-05-14 01:50:35254 if (level == eDescriptionLevelBrief)
Chris Lattner30fdc8d2010-06-08 16:52:24255 {
256 s->Printf("Function call thread plan");
257 }
258 else
259 {
Greg Clayton1ac04c32012-02-21 00:09:25260 TargetSP target_sp (m_thread.CalculateTarget());
Daniel Malead01b2952012-11-29 21:49:15261 s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24262 }
263}
264
265bool
266ThreadPlanCallFunction::ValidatePlan (Stream *error)
267{
268 if (!m_valid)
Jim Inghamea06f3b2013-03-28 00:04:05269 {
270 if (error)
271 {
272 if (m_constructor_errors.GetSize() > 0)
273 error->PutCString (m_constructor_errors.GetData());
274 else
275 error->PutCString ("Unknown error");
276 }
Chris Lattner30fdc8d2010-06-08 16:52:24277 return false;
Jim Inghamea06f3b2013-03-28 00:04:05278 }
Chris Lattner30fdc8d2010-06-08 16:52:24279
280 return true;
281}
282
Jim Ingham0161b492013-02-09 01:29:05283
284Vote
285ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr)
286{
287 if (m_takedown_done || IsPlanComplete())
288 return eVoteYes;
289 else
290 return ThreadPlan::ShouldReportStop(event_ptr);
291}
292
Chris Lattner30fdc8d2010-06-08 16:52:24293bool
Jim Ingham221d51c2013-05-08 00:35:16294ThreadPlanCallFunction::DoPlanExplainsStop (Event *event_ptr)
Sean Callanan6db73ca2010-11-03 01:37:52295{
Greg Clayton5160ce52013-03-27 23:08:40296 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP|LIBLLDB_LOG_PROCESS));
Jim Ingham60c41182013-06-04 01:40:51297 m_real_stop_info_sp = GetPrivateStopInfo ();
Jim Ingham160f78c2011-05-17 01:10:11298
Jim Ingham40d871f2010-10-26 00:27:45299 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
300 // we answer yes.
Jim Ingham0161b492013-02-09 01:29:05301 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop(event_ptr))
Jim Ingham184e9812013-01-15 02:47:48302 {
303 SetPlanComplete();
Jim Ingham40d871f2010-10-26 00:27:45304 return true;
Jim Ingham184e9812013-01-15 02:47:48305 }
Sean Callanan3e6fedc2010-10-19 22:24:06306
Sean Callananc98aca62010-11-03 19:36:28307 // Check if the breakpoint is one of ours.
308
Jim Ingham18de2fd2012-05-10 01:35:39309 StopReason stop_reason;
310 if (!m_real_stop_info_sp)
311 stop_reason = eStopReasonNone;
312 else
313 stop_reason = m_real_stop_info_sp->GetStopReason();
Jim Ingham0161b492013-02-09 01:29:05314 if (log)
315 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.", Thread::StopReasonAsCString(stop_reason));
Jim Ingham18de2fd2012-05-10 01:35:39316
317 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
Sean Callananc98aca62010-11-03 19:36:28318 return true;
319
Jim Ingham0161b492013-02-09 01:29:05320 // We control breakpoints separately from other "stop reasons." So first,
321 // check the case where we stopped for an internal breakpoint, in that case, continue on.
322 // If it is not an internal breakpoint, consult m_ignore_breakpoints.
Sean Callanan6db73ca2010-11-03 01:37:52323
Jim Ingham18de2fd2012-05-10 01:35:39324
325 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham40d871f2010-10-26 00:27:45326 {
Greg Clayton1ac04c32012-02-21 00:09:25327 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham160f78c2011-05-17 01:10:11328 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Clayton1ac04c32012-02-21 00:09:25329 BreakpointSiteSP bp_site_sp;
330 if (process_sp)
331 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham40d871f2010-10-26 00:27:45332 if (bp_site_sp)
333 {
334 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
335 bool is_internal = true;
336 for (uint32_t i = 0; i < num_owners; i++)
337 {
Sean Callanan6db73ca2010-11-03 01:37:52338 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Jim Ingham0161b492013-02-09 01:29:05339 if (log)
340 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: hit breakpoint %d while calling function", bp.GetID());
Sean Callanan6db73ca2010-11-03 01:37:52341
342 if (!bp.IsInternal())
Jim Ingham40d871f2010-10-26 00:27:45343 {
344 is_internal = false;
345 break;
346 }
347 }
348 if (is_internal)
Jim Ingham0161b492013-02-09 01:29:05349 {
350 if (log)
351 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop hit an internal breakpoint, not stopping.");
Jim Ingham40d871f2010-10-26 00:27:45352 return false;
Jim Ingham0161b492013-02-09 01:29:05353 }
Jim Ingham40d871f2010-10-26 00:27:45354 }
Jim Ingham0161b492013-02-09 01:29:05355
Jim Ingham184e9812013-01-15 02:47:48356 if (m_ignore_breakpoints)
Jim Ingham923886c2012-05-11 18:43:38357 {
Jim Ingham0161b492013-02-09 01:29:05358 if (log)
359 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true");
360 m_real_stop_info_sp->OverrideShouldStop(false);
Jim Ingham923886c2012-05-11 18:43:38361 return true;
362 }
363 else
Jim Ingham0161b492013-02-09 01:29:05364 {
365 if (log)
366 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true");
367 m_real_stop_info_sp->OverrideShouldStop(true);
Jim Ingham923886c2012-05-11 18:43:38368 return false;
Jim Ingham0161b492013-02-09 01:29:05369 }
370 }
371 else if (!m_unwind_on_error)
372 {
373 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
374 return false;
Jim Ingham40d871f2010-10-26 00:27:45375 }
376 else
377 {
378 // If the subplan is running, any crashes are attributable to us.
Jim Ingham2c364392011-01-26 19:13:09379 // If we want to discard the plan, then we say we explain the stop
380 // but if we are going to be discarded, let whoever is above us
381 // explain the stop.
Jim Ingham0161b492013-02-09 01:29:05382 // But don't discard the plan if the stop would restart itself (for instance if it is a
383 // signal that is set not to stop. Check that here first. We just say we explain the stop
384 // but aren't done and everything will continue on from there.
385
386 if (m_real_stop_info_sp->ShouldStopSynchronous(event_ptr))
Jim Ingham18de2fd2012-05-10 01:35:39387 {
Jim Ingham0161b492013-02-09 01:29:05388 SetPlanComplete(false);
389 if (m_subplan_sp)
Jim Ingham18de2fd2012-05-10 01:35:39390 {
Jim Ingham0161b492013-02-09 01:29:05391 if (m_unwind_on_error)
392 return true;
393 else
394 return false;
Jim Ingham18de2fd2012-05-10 01:35:39395 }
396 else
397 return false;
398 }
399 else
Jim Ingham0161b492013-02-09 01:29:05400 return true;
Jim Ingham40d871f2010-10-26 00:27:45401 }
Chris Lattner30fdc8d2010-06-08 16:52:24402}
403
404bool
405ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
406{
Jim Ingham221d51c2013-05-08 00:35:16407 // We do some computation in DoPlanExplainsStop that may or may not set the plan as complete.
Jim Ingham184e9812013-01-15 02:47:48408 // We need to do that here to make sure our state is correct.
Jim Ingham221d51c2013-05-08 00:35:16409 DoPlanExplainsStop(event_ptr);
Jim Ingham184e9812013-01-15 02:47:48410
411 if (IsPlanComplete())
Chris Lattner30fdc8d2010-06-08 16:52:24412 {
Jim Ingham9da36832011-01-22 01:27:23413 ReportRegisterState ("Function completed. Register state was:");
Chris Lattner30fdc8d2010-06-08 16:52:24414 return true;
415 }
416 else
417 {
418 return false;
419 }
420}
421
422bool
423ThreadPlanCallFunction::StopOthers ()
424{
425 return m_stop_other_threads;
426}
427
Chris Lattner30fdc8d2010-06-08 16:52:24428StateType
Jim Ingham06e827c2010-11-11 19:26:09429ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24430{
431 return eStateRunning;
432}
433
434void
435ThreadPlanCallFunction::DidPush ()
436{
Sean Callananbe3a1b12010-10-26 00:31:56437//#define SINGLE_STEP_EXPRESSIONS
438
Jim Ingham8559a352012-11-26 23:52:18439 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
440 // Wait till the plan is pushed so we aren't changing the stop info till we're about to run.
441
442 GetThread().SetStopInfoToNothing();
443
Sean Callananbe3a1b12010-10-26 00:31:56444#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner30fdc8d2010-06-08 16:52:24445 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
446
447 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham77787032011-01-20 02:03:18448 m_subplan_sp->SetPrivate (true);
Sean Callananbe3a1b12010-10-26 00:31:56449#endif
Chris Lattner30fdc8d2010-06-08 16:52:24450}
451
452bool
453ThreadPlanCallFunction::WillStop ()
454{
455 return true;
456}
457
458bool
459ThreadPlanCallFunction::MischiefManaged ()
460{
Greg Clayton5160ce52013-03-27 23:08:40461 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham184e9812013-01-15 02:47:48462
Chris Lattner30fdc8d2010-06-08 16:52:24463 if (IsPlanComplete())
464 {
Chris Lattner30fdc8d2010-06-08 16:52:24465 if (log)
Jim Ingham87d0e612012-04-13 23:11:52466 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this);
Chris Lattner30fdc8d2010-06-08 16:52:24467
468 ThreadPlan::MischiefManaged ();
469 return true;
470 }
471 else
472 {
473 return false;
474 }
475}
Sean Callanan6db73ca2010-11-03 01:37:52476
477void
478ThreadPlanCallFunction::SetBreakpoints ()
479{
Greg Clayton1ac04c32012-02-21 00:09:25480 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham6fbc48b2013-11-07 00:11:47481 if (m_trap_exceptions && process_sp)
Greg Clayton1ac04c32012-02-21 00:09:25482 {
483 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
484 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan6db73ca2010-11-03 01:37:52485
Greg Clayton1ac04c32012-02-21 00:09:25486 if (m_cxx_language_runtime)
Jim Ingham6fbc48b2013-11-07 00:11:47487 {
488 m_should_clear_cxx_exception_bp = !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
Greg Clayton1ac04c32012-02-21 00:09:25489 m_cxx_language_runtime->SetExceptionBreakpoints();
Jim Ingham6fbc48b2013-11-07 00:11:47490 }
Greg Clayton1ac04c32012-02-21 00:09:25491 if (m_objc_language_runtime)
Jim Ingham6fbc48b2013-11-07 00:11:47492 {
493 m_should_clear_objc_exception_bp = !m_objc_language_runtime->ExceptionBreakpointsAreSet();
Greg Clayton1ac04c32012-02-21 00:09:25494 m_objc_language_runtime->SetExceptionBreakpoints();
Jim Ingham6fbc48b2013-11-07 00:11:47495 }
Greg Clayton1ac04c32012-02-21 00:09:25496 }
Sean Callanan6db73ca2010-11-03 01:37:52497}
498
499void
500ThreadPlanCallFunction::ClearBreakpoints ()
501{
Jim Ingham6fbc48b2013-11-07 00:11:47502 if (m_trap_exceptions)
503 {
504 if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
505 m_cxx_language_runtime->ClearExceptionBreakpoints();
506 if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
507 m_objc_language_runtime->ClearExceptionBreakpoints();
508 }
Sean Callanan6db73ca2010-11-03 01:37:52509}
Sean Callananc98aca62010-11-03 19:36:28510
511bool
512ThreadPlanCallFunction::BreakpointsExplainStop()
513{
Jim Ingham60c41182013-06-04 01:40:51514 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Sean Callananc98aca62010-11-03 19:36:28515
Jim Ingham6fbc48b2013-11-07 00:11:47516 if (m_trap_exceptions)
Jim Ingham184e9812013-01-15 02:47:48517 {
Jim Ingham6fbc48b2013-11-07 00:11:47518 if ((m_cxx_language_runtime &&
519 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
520 ||(m_objc_language_runtime &&
521 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)))
522 {
523 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
524 if (log)
525 log->Printf ("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an exception breakpoint, setting plan complete.");
526
527 SetPlanComplete(false);
528
529 // If the user has set the ObjC language breakpoint, it would normally get priority over our internal
530 // catcher breakpoint, but in this case we can't let that happen, so force the ShouldStop here.
531 stop_info_sp->OverrideShouldStop (true);
532 return true;
533 }
Jim Ingham184e9812013-01-15 02:47:48534 }
Sean Callananc98aca62010-11-03 19:36:28535
Sean Callananc98aca62010-11-03 19:36:28536 return false;
537}
Jim Ingham8559a352012-11-26 23:52:18538
539bool
540ThreadPlanCallFunction::RestoreThreadState()
541{
542 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
543}
544