blob: a17b3b6ce720cb6ab4cd1bba7326178c37085b33 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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:52 +000015#include "llvm/Support/MachO.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016// Project includes
17#include "lldb/lldb-private-log.h"
Jim Ingham40d871f2010-10-26 00:27:45 +000018#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Address.h"
21#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000022#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/Stream.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Symbol/ObjectFile.h"
Sean Callananf2115102010-11-03 22:19:38 +000025#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Target/Process.h"
27#include "lldb/Target/RegisterContext.h"
Jim Ingham40d871f2010-10-26 00:27:45 +000028#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#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:13 +000039bool
40ThreadPlanCallFunction::ConstructorSetup (Thread &thread,
Jim Ingham0092c8e2012-04-13 20:38:13 +000041 ABI *& abi,
42 lldb::addr_t &start_load_addr,
43 lldb::addr_t &function_load_addr)
44{
Jim Ingham0092c8e2012-04-13 20:38:13 +000045 SetIsMasterPlan (true);
Jim Ingham923886c2012-05-11 18:43:38 +000046 SetOkayToDiscard (false);
Jim Ingham0092c8e2012-04-13 20:38:13 +000047
48 ProcessSP process_sp (thread.GetProcess());
49 if (!process_sp)
50 return false;
51
52 abi = process_sp->GetABI().get();
53
54 if (!abi)
55 return false;
56
57 TargetSP target_sp (thread.CalculateTarget());
58
Jim Ingham87d0e612012-04-13 23:11:52 +000059 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham0092c8e2012-04-13 20:38:13 +000060
61 SetBreakpoints();
62
63 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
64 // If we can't read memory at the point of the process where we are planning to put our function, we're
65 // not going to get any further...
66 Error error;
67 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
68 if (!error.Success())
69 {
70 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +000071 log->Printf ("ThreadPlanCallFunction(%p): Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", this, m_function_sp);
Jim Ingham0092c8e2012-04-13 20:38:13 +000072 return false;
73 }
74
75 Module *exe_module = target_sp->GetExecutableModulePointer();
76
77 if (exe_module == NULL)
78 {
79 if (log)
Jim Ingham87d0e612012-04-13 23:11:52 +000080 log->Printf ("ThreadPlanCallFunction(%p): Can't execute code without an executable module.", this);
Jim Ingham0092c8e2012-04-13 20:38:13 +000081 return false;
82 }
83 else
84 {
85 ObjectFile *objectFile = exe_module->GetObjectFile();
86 if (!objectFile)
87 {
88 if (log)
Jim Ingham87d0e612012-04-13 23:11:52 +000089 log->Printf ("ThreadPlanCallFunction(%p): Could not find object file for module \"%s\".",
90 this, exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham0092c8e2012-04-13 20:38:13 +000091 return false;
92 }
93 m_start_addr = objectFile->GetEntryPointAddress();
94 if (!m_start_addr.IsValid())
95 {
96 if (log)
Jim Ingham87d0e612012-04-13 23:11:52 +000097 log->Printf ("ThreadPlanCallFunction(%p): Could not find entry point address for executable module \"%s\".",
98 this, exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham0092c8e2012-04-13 20:38:13 +000099 return false;
100 }
101 }
102
103 start_load_addr = m_start_addr.GetLoadAddress (target_sp.get());
104
105 // Checkpoint the thread state so we can restore it later.
106 if (log && log->GetVerbose())
107 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
108
109 if (!thread.CheckpointThreadState (m_stored_thread_state))
110 {
111 if (log)
Jim Ingham87d0e612012-04-13 23:11:52 +0000112 log->Printf ("ThreadPlanCallFunction(%p): Setting up ThreadPlanCallFunction, failed to checkpoint thread state.", this);
Jim Ingham0092c8e2012-04-13 20:38:13 +0000113 return false;
114 }
Jim Ingham0092c8e2012-04-13 20:38:13 +0000115 function_load_addr = m_function_addr.GetLoadAddress (target_sp.get());
116
117 return true;
118}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119
120ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
121 Address &function,
Jim Inghamef651602011-12-22 19:12:40 +0000122 const ClangASTType &return_type,
Greg Clayton2a48f522011-05-14 01:50:35 +0000123 addr_t arg,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124 bool stop_other_threads,
Sean Callananfc55f5d2010-09-21 00:44:12 +0000125 bool discard_on_error,
Greg Clayton2a48f522011-05-14 01:50:35 +0000126 addr_t *this_arg,
127 addr_t *cmd_arg) :
Jim Inghamb01e7422010-06-19 04:45:32 +0000128 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer1ee0d4f2010-07-16 12:32:33 +0000129 m_valid (false),
130 m_stop_other_threads (stop_other_threads),
Jim Ingham16e0c682011-08-12 23:34:31 +0000131 m_function_addr (function),
Filipe Cabecinhasb4cb0be2012-09-11 18:11:07 +0000132 m_function_sp (0),
Jim Inghamef651602011-12-22 19:12:40 +0000133 m_return_type (return_type),
Jim Inghamce553d82011-11-01 02:46:54 +0000134 m_takedown_done (false),
Jim Ingham923886c2012-05-11 18:43:38 +0000135 m_stop_address (LLDB_INVALID_ADDRESS),
136 m_discard_on_error (discard_on_error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137{
Jim Ingham0092c8e2012-04-13 20:38:13 +0000138 lldb::addr_t start_load_addr;
139 ABI *abi;
140 lldb::addr_t function_load_addr;
Jim Ingham923886c2012-05-11 18:43:38 +0000141 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Clayton1ac04c32012-02-21 00:09:25 +0000142 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143
Greg Claytonfdeb1562011-05-12 02:14:56 +0000144 if (this_arg && cmd_arg)
145 {
146 if (!abi->PrepareTrivialCall (thread,
147 m_function_sp,
Jim Ingham0092c8e2012-04-13 20:38:13 +0000148 function_load_addr,
Greg Clayton2a48f522011-05-14 01:50:35 +0000149 start_load_addr,
Greg Claytonfdeb1562011-05-12 02:14:56 +0000150 this_arg,
151 cmd_arg,
Greg Clayton2a48f522011-05-14 01:50:35 +0000152 &arg))
Greg Claytonfdeb1562011-05-12 02:14:56 +0000153 return;
154 }
155 else if (this_arg)
156 {
157 if (!abi->PrepareTrivialCall (thread,
158 m_function_sp,
Jim Ingham0092c8e2012-04-13 20:38:13 +0000159 function_load_addr,
Greg Clayton2a48f522011-05-14 01:50:35 +0000160 start_load_addr,
Greg Claytonfdeb1562011-05-12 02:14:56 +0000161 this_arg,
Greg Clayton2a48f522011-05-14 01:50:35 +0000162 &arg))
Greg Claytonfdeb1562011-05-12 02:14:56 +0000163 return;
164 }
165 else
166 {
167 if (!abi->PrepareTrivialCall (thread,
168 m_function_sp,
Jim Ingham0092c8e2012-04-13 20:38:13 +0000169 function_load_addr,
Greg Clayton2a48f522011-05-14 01:50:35 +0000170 start_load_addr,
171 &arg))
172 return;
173 }
174
175 ReportRegisterState ("Function call was set up. Register state was:");
176
177 m_valid = true;
178}
179
180
181ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
182 Address &function,
Jim Inghamef651602011-12-22 19:12:40 +0000183 const ClangASTType &return_type,
Greg Clayton2a48f522011-05-14 01:50:35 +0000184 bool stop_other_threads,
185 bool discard_on_error,
186 addr_t *arg1_ptr,
187 addr_t *arg2_ptr,
188 addr_t *arg3_ptr,
189 addr_t *arg4_ptr,
190 addr_t *arg5_ptr,
191 addr_t *arg6_ptr) :
192 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
193 m_valid (false),
194 m_stop_other_threads (stop_other_threads),
Jim Ingham16e0c682011-08-12 23:34:31 +0000195 m_function_addr (function),
Jim Ingham8559a352012-11-26 23:52:18 +0000196 m_function_sp (0),
Jim Inghamef651602011-12-22 19:12:40 +0000197 m_return_type (return_type),
Jim Ingham0092c8e2012-04-13 20:38:13 +0000198 m_takedown_done (false),
Jim Ingham8559a352012-11-26 23:52:18 +0000199 m_stop_address (LLDB_INVALID_ADDRESS),
200 m_discard_on_error (discard_on_error)
Greg Clayton2a48f522011-05-14 01:50:35 +0000201{
Jim Ingham0092c8e2012-04-13 20:38:13 +0000202 lldb::addr_t start_load_addr;
203 ABI *abi;
204 lldb::addr_t function_load_addr;
Jim Ingham923886c2012-05-11 18:43:38 +0000205 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Clayton1ac04c32012-02-21 00:09:25 +0000206 return;
207
Greg Clayton2a48f522011-05-14 01:50:35 +0000208 if (!abi->PrepareTrivialCall (thread,
Jim Ingham0092c8e2012-04-13 20:38:13 +0000209 m_function_sp,
210 function_load_addr,
Greg Clayton2a48f522011-05-14 01:50:35 +0000211 start_load_addr,
212 arg1_ptr,
213 arg2_ptr,
214 arg3_ptr,
215 arg4_ptr,
216 arg5_ptr,
217 arg6_ptr))
218 {
Greg Claytonfdeb1562011-05-12 02:14:56 +0000219 return;
220 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221
Jim Ingham9da36832011-01-22 01:27:23 +0000222 ReportRegisterState ("Function call was set up. Register state was:");
223
224 m_valid = true;
225}
226
227ThreadPlanCallFunction::~ThreadPlanCallFunction ()
228{
Jim Ingham18de2fd2012-05-10 01:35:39 +0000229 DoTakedown(true);
Jim Ingham9da36832011-01-22 01:27:23 +0000230}
231
232void
233ThreadPlanCallFunction::ReportRegisterState (const char *message)
234{
Greg Claytonaf247d72011-05-19 03:54:16 +0000235 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callananece96492010-11-08 03:49:50 +0000236 if (log)
237 {
Greg Claytonaf247d72011-05-19 03:54:16 +0000238 StreamString strm;
Greg Clayton5ccbd292011-01-06 22:15:06 +0000239 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham9da36832011-01-22 01:27:23 +0000240
241 log->PutCString(message);
242
Greg Claytonaf247d72011-05-19 03:54:16 +0000243 RegisterValue reg_value;
244
245 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
246 reg_idx < num_registers;
247 ++reg_idx)
Sean Callananece96492010-11-08 03:49:50 +0000248 {
Greg Claytonaf247d72011-05-19 03:54:16 +0000249 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
250 if (reg_ctx->ReadRegister(reg_info, reg_value))
251 {
252 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
253 strm.EOL();
254 }
Sean Callananece96492010-11-08 03:49:50 +0000255 }
Greg Claytonaf247d72011-05-19 03:54:16 +0000256 log->PutCString(strm.GetData());
Sean Callananece96492010-11-08 03:49:50 +0000257 }
Sean Callanan10af7c42010-11-04 01:51:38 +0000258}
259
260void
Jim Ingham18de2fd2012-05-10 01:35:39 +0000261ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan10af7c42010-11-04 01:51:38 +0000262{
Jim Ingham87d0e612012-04-13 23:11:52 +0000263 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
264
265 if (!m_valid)
266 {
267 //Don't call DoTakedown if we were never valid to begin with.
268 if (log)
269 log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.", this);
270 return;
271 }
272
Jim Ingham9da36832011-01-22 01:27:23 +0000273 if (!m_takedown_done)
Jim Ingham77787032011-01-20 02:03:18 +0000274 {
Jim Ingham18de2fd2012-05-10 01:35:39 +0000275 if (success)
Greg Clayton70b57652011-05-15 01:25:55 +0000276 {
Jim Ingham18de2fd2012-05-10 01:35:39 +0000277 ProcessSP process_sp (m_thread.GetProcess());
278 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
279 if (abi && m_return_type.IsValid())
280 {
281 const bool persistent = false;
282 m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent);
283 }
Greg Clayton70b57652011-05-15 01:25:55 +0000284 }
Jim Ingham9da36832011-01-22 01:27:23 +0000285 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000286 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:23 +0000287 m_takedown_done = true;
Jim Inghamce553d82011-11-01 02:46:54 +0000288 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham160f78c2011-05-17 01:10:11 +0000289 m_real_stop_info_sp = GetPrivateStopReason();
Jim Ingham8559a352012-11-26 23:52:18 +0000290 m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state);
Jim Ingham18de2fd2012-05-10 01:35:39 +0000291 SetPlanComplete(success);
Jim Ingham77787032011-01-20 02:03:18 +0000292 ClearBreakpoints();
Jim Ingham9da36832011-01-22 01:27:23 +0000293 if (log && log->GetVerbose())
294 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham2c364392011-01-26 19:13:09 +0000295
Jim Ingham9da36832011-01-22 01:27:23 +0000296 }
297 else
298 {
299 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000300 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:18 +0000301 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302}
303
304void
Jim Inghambda4e5eb2011-01-18 01:58:06 +0000305ThreadPlanCallFunction::WillPop ()
306{
Jim Ingham18de2fd2012-05-10 01:35:39 +0000307 DoTakedown(true);
Jim Inghambda4e5eb2011-01-18 01:58:06 +0000308}
309
310void
Greg Clayton2a48f522011-05-14 01:50:35 +0000311ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312{
Greg Clayton2a48f522011-05-14 01:50:35 +0000313 if (level == eDescriptionLevelBrief)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314 {
315 s->Printf("Function call thread plan");
316 }
317 else
318 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000319 TargetSP target_sp (m_thread.CalculateTarget());
Daniel Malead01b2952012-11-29 21:49:15 +0000320 s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 }
322}
323
324bool
325ThreadPlanCallFunction::ValidatePlan (Stream *error)
326{
327 if (!m_valid)
328 return false;
329
330 return true;
331}
332
333bool
334ThreadPlanCallFunction::PlanExplainsStop ()
Sean Callanan6db73ca2010-11-03 01:37:52 +0000335{
Jim Ingham160f78c2011-05-17 01:10:11 +0000336 m_real_stop_info_sp = GetPrivateStopReason();
337
Jim Ingham40d871f2010-10-26 00:27:45 +0000338 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
339 // we answer yes.
Enrico Granata20edcdb2011-07-19 18:03:25 +0000340 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop())
Jim Ingham40d871f2010-10-26 00:27:45 +0000341 return true;
Sean Callanan3e6fedc2010-10-19 22:24:06 +0000342
Sean Callananc98aca62010-11-03 19:36:28 +0000343 // Check if the breakpoint is one of ours.
344
Jim Ingham18de2fd2012-05-10 01:35:39 +0000345 StopReason stop_reason;
346 if (!m_real_stop_info_sp)
347 stop_reason = eStopReasonNone;
348 else
349 stop_reason = m_real_stop_info_sp->GetStopReason();
350
351 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
Sean Callananc98aca62010-11-03 19:36:28 +0000352 return true;
353
Jim Ingham40d871f2010-10-26 00:27:45 +0000354 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
Jim Ingham923886c2012-05-11 18:43:38 +0000355 if (!m_discard_on_error)
Jim Ingham40d871f2010-10-26 00:27:45 +0000356 return false;
357
358 // Otherwise, check the case where we stopped for an internal breakpoint, in that case, continue on.
359 // If it is not an internal breakpoint, consult OkayToDiscard.
Sean Callanan6db73ca2010-11-03 01:37:52 +0000360
Jim Ingham18de2fd2012-05-10 01:35:39 +0000361
362 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham40d871f2010-10-26 00:27:45 +0000363 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000364 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham160f78c2011-05-17 01:10:11 +0000365 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Clayton1ac04c32012-02-21 00:09:25 +0000366 BreakpointSiteSP bp_site_sp;
367 if (process_sp)
368 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham40d871f2010-10-26 00:27:45 +0000369 if (bp_site_sp)
370 {
371 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
372 bool is_internal = true;
373 for (uint32_t i = 0; i < num_owners; i++)
374 {
Sean Callanan6db73ca2010-11-03 01:37:52 +0000375 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Sean Callanan6db73ca2010-11-03 01:37:52 +0000376
377 if (!bp.IsInternal())
Jim Ingham40d871f2010-10-26 00:27:45 +0000378 {
379 is_internal = false;
380 break;
381 }
382 }
383 if (is_internal)
384 return false;
385 }
386
Jim Ingham923886c2012-05-11 18:43:38 +0000387 if (m_discard_on_error)
388 {
389 DoTakedown(false);
390 return true;
391 }
392 else
393 return false;
Jim Ingham40d871f2010-10-26 00:27:45 +0000394 }
395 else
396 {
397 // If the subplan is running, any crashes are attributable to us.
Jim Ingham2c364392011-01-26 19:13:09 +0000398 // If we want to discard the plan, then we say we explain the stop
399 // but if we are going to be discarded, let whoever is above us
400 // explain the stop.
Sean Callanan9a028512012-08-09 00:50:26 +0000401 if (m_subplan_sp)
Jim Ingham18de2fd2012-05-10 01:35:39 +0000402 {
Jim Ingham923886c2012-05-11 18:43:38 +0000403 if (m_discard_on_error)
Jim Ingham18de2fd2012-05-10 01:35:39 +0000404 {
405 DoTakedown(false);
406 return true;
407 }
408 else
409 return false;
410 }
411 else
412 return false;
Jim Ingham40d871f2010-10-26 00:27:45 +0000413 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414}
415
416bool
417ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
418{
Jim Ingham7ba6e992012-05-11 23:47:32 +0000419 if (IsPlanComplete() || PlanExplainsStop())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 {
Jim Ingham9da36832011-01-22 01:27:23 +0000421 ReportRegisterState ("Function completed. Register state was:");
Sean Callanan5300d372010-07-31 01:32:05 +0000422
Jim Ingham18de2fd2012-05-10 01:35:39 +0000423 DoTakedown(true);
Sean Callanan6db73ca2010-11-03 01:37:52 +0000424
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 return true;
426 }
427 else
428 {
429 return false;
430 }
431}
432
433bool
434ThreadPlanCallFunction::StopOthers ()
435{
436 return m_stop_other_threads;
437}
438
439void
440ThreadPlanCallFunction::SetStopOthers (bool new_value)
441{
442 if (m_subplan_sp)
443 {
444 ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get());
445 address_plan->SetStopOthers(new_value);
446 }
447 m_stop_other_threads = new_value;
448}
449
450StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000451ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452{
453 return eStateRunning;
454}
455
456void
457ThreadPlanCallFunction::DidPush ()
458{
Sean Callananbe3a1b12010-10-26 00:31:56 +0000459//#define SINGLE_STEP_EXPRESSIONS
460
Jim Ingham8559a352012-11-26 23:52:18 +0000461 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
462 // Wait till the plan is pushed so we aren't changing the stop info till we're about to run.
463
464 GetThread().SetStopInfoToNothing();
465
Sean Callananbe3a1b12010-10-26 00:31:56 +0000466#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
468
469 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham77787032011-01-20 02:03:18 +0000470 m_subplan_sp->SetPrivate (true);
Sean Callananbe3a1b12010-10-26 00:31:56 +0000471#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472}
473
474bool
475ThreadPlanCallFunction::WillStop ()
476{
477 return true;
478}
479
480bool
481ThreadPlanCallFunction::MischiefManaged ()
482{
483 if (IsPlanComplete())
484 {
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000485 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486
487 if (log)
Jim Ingham87d0e612012-04-13 23:11:52 +0000488 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489
490 ThreadPlan::MischiefManaged ();
491 return true;
492 }
493 else
494 {
495 return false;
496 }
497}
Sean Callanan6db73ca2010-11-03 01:37:52 +0000498
499void
500ThreadPlanCallFunction::SetBreakpoints ()
501{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000502 ProcessSP process_sp (m_thread.CalculateProcess());
503 if (process_sp)
504 {
505 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
506 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan6db73ca2010-11-03 01:37:52 +0000507
Greg Clayton1ac04c32012-02-21 00:09:25 +0000508 if (m_cxx_language_runtime)
509 m_cxx_language_runtime->SetExceptionBreakpoints();
510 if (m_objc_language_runtime)
511 m_objc_language_runtime->SetExceptionBreakpoints();
512 }
Sean Callanan6db73ca2010-11-03 01:37:52 +0000513}
514
515void
516ThreadPlanCallFunction::ClearBreakpoints ()
517{
Sean Callananf2115102010-11-03 22:19:38 +0000518 if (m_cxx_language_runtime)
519 m_cxx_language_runtime->ClearExceptionBreakpoints();
520 if (m_objc_language_runtime)
521 m_objc_language_runtime->ClearExceptionBreakpoints();
Sean Callanan6db73ca2010-11-03 01:37:52 +0000522}
Sean Callananc98aca62010-11-03 19:36:28 +0000523
524bool
525ThreadPlanCallFunction::BreakpointsExplainStop()
526{
Greg Clayton2a48f522011-05-14 01:50:35 +0000527 StopInfoSP stop_info_sp = GetPrivateStopReason();
Sean Callananc98aca62010-11-03 19:36:28 +0000528
Sean Callananf2115102010-11-03 22:19:38 +0000529 if (m_cxx_language_runtime &&
530 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
531 return true;
Sean Callananc98aca62010-11-03 19:36:28 +0000532
Sean Callananf2115102010-11-03 22:19:38 +0000533 if (m_objc_language_runtime &&
534 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
535 return true;
Sean Callananc98aca62010-11-03 19:36:28 +0000536
537 return false;
538}
Jim Ingham8559a352012-11-26 23:52:18 +0000539
540bool
541ThreadPlanCallFunction::RestoreThreadState()
542{
543 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
544}
545