blob: 370db076a3a7a7b945511ed4496c8a32d8762ed6 [file] [log] [blame]
Chris Lattner24943d22010-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 Callanan07f3d8d2010-11-03 01:37:52 +000015#include "llvm/Support/MachO.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016// Project includes
17#include "lldb/lldb-private-log.h"
Jim Ingham988ddbc2010-10-26 00:27:45 +000018#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/Address.h"
21#include "lldb/Core/Log.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000022#include "lldb/Core/Module.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Stream.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000024#include "lldb/Symbol/ObjectFile.h"
Sean Callanan29756d42010-11-03 22:19:38 +000025#include "lldb/Target/LanguageRuntime.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Target/Process.h"
27#include "lldb/Target/RegisterContext.h"
Jim Ingham988ddbc2010-10-26 00:27:45 +000028#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-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 Ingham1e58cef2012-04-13 20:38:13 +000039bool
40ThreadPlanCallFunction::ConstructorSetup (Thread &thread,
Jim Ingham1e58cef2012-04-13 20:38:13 +000041 ABI *& abi,
42 lldb::addr_t &start_load_addr,
43 lldb::addr_t &function_load_addr)
44{
Jim Ingham1e58cef2012-04-13 20:38:13 +000045 SetIsMasterPlan (true);
Jim Ingham110b55f2012-05-11 18:43:38 +000046 SetOkayToDiscard (false);
Jim Ingham1e58cef2012-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 Inghama8d26eb2012-04-13 23:11:52 +000059 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham1e58cef2012-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)
Jim Inghama8d26eb2012-04-13 23:11:52 +000071 log->Printf ("ThreadPlanCallFunction(%p): Trying to put the stack in unreadable memory at: 0x%llx.", this, m_function_sp);
Jim Ingham1e58cef2012-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 Inghama8d26eb2012-04-13 23:11:52 +000080 log->Printf ("ThreadPlanCallFunction(%p): Can't execute code without an executable module.", this);
Jim Ingham1e58cef2012-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 Inghama8d26eb2012-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 Ingham1e58cef2012-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 Inghama8d26eb2012-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 Ingham1e58cef2012-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 Inghama8d26eb2012-04-13 23:11:52 +0000112 log->Printf ("ThreadPlanCallFunction(%p): Setting up ThreadPlanCallFunction, failed to checkpoint thread state.", this);
Jim Ingham1e58cef2012-04-13 20:38:13 +0000113 return false;
114 }
115 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
116 thread.SetStopInfoToNothing();
117
118 function_load_addr = m_function_addr.GetLoadAddress (target_sp.get());
119
120 return true;
121}
Chris Lattner24943d22010-06-08 16:52:24 +0000122
123ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
124 Address &function,
Jim Ingham016ef882011-12-22 19:12:40 +0000125 const ClangASTType &return_type,
Greg Clayton989816b2011-05-14 01:50:35 +0000126 addr_t arg,
Chris Lattner24943d22010-06-08 16:52:24 +0000127 bool stop_other_threads,
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000128 bool discard_on_error,
Greg Clayton989816b2011-05-14 01:50:35 +0000129 addr_t *this_arg,
130 addr_t *cmd_arg) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000131 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer36a08102010-07-16 12:32:33 +0000132 m_valid (false),
133 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000134 m_function_addr (function),
Filipe Cabecinhas5ebd51f2012-09-11 18:11:07 +0000135 m_function_sp (0),
Jim Ingham016ef882011-12-22 19:12:40 +0000136 m_return_type (return_type),
Jim Inghamba560cc2011-11-01 02:46:54 +0000137 m_takedown_done (false),
Jim Ingham110b55f2012-05-11 18:43:38 +0000138 m_stop_address (LLDB_INVALID_ADDRESS),
139 m_discard_on_error (discard_on_error)
Chris Lattner24943d22010-06-08 16:52:24 +0000140{
Jim Ingham1e58cef2012-04-13 20:38:13 +0000141 lldb::addr_t start_load_addr;
142 ABI *abi;
143 lldb::addr_t function_load_addr;
Jim Ingham110b55f2012-05-11 18:43:38 +0000144 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Claytonf4124de2012-02-21 00:09:25 +0000145 return;
Chris Lattner24943d22010-06-08 16:52:24 +0000146
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000147 if (this_arg && cmd_arg)
148 {
149 if (!abi->PrepareTrivialCall (thread,
150 m_function_sp,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000151 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000152 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000153 this_arg,
154 cmd_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000155 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000156 return;
157 }
158 else if (this_arg)
159 {
160 if (!abi->PrepareTrivialCall (thread,
161 m_function_sp,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000162 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000163 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000164 this_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000165 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000166 return;
167 }
168 else
169 {
170 if (!abi->PrepareTrivialCall (thread,
171 m_function_sp,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000172 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000173 start_load_addr,
174 &arg))
175 return;
176 }
177
178 ReportRegisterState ("Function call was set up. Register state was:");
179
180 m_valid = true;
181}
182
183
184ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
185 Address &function,
Jim Ingham016ef882011-12-22 19:12:40 +0000186 const ClangASTType &return_type,
Greg Clayton989816b2011-05-14 01:50:35 +0000187 bool stop_other_threads,
188 bool discard_on_error,
189 addr_t *arg1_ptr,
190 addr_t *arg2_ptr,
191 addr_t *arg3_ptr,
192 addr_t *arg4_ptr,
193 addr_t *arg5_ptr,
194 addr_t *arg6_ptr) :
195 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
196 m_valid (false),
197 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000198 m_function_addr (function),
Filipe Cabecinhas5ebd51f2012-09-11 18:11:07 +0000199 m_function_sp(0),
Jim Ingham016ef882011-12-22 19:12:40 +0000200 m_return_type (return_type),
Jim Ingham1e58cef2012-04-13 20:38:13 +0000201 m_takedown_done (false),
202 m_stop_address (LLDB_INVALID_ADDRESS)
Greg Clayton989816b2011-05-14 01:50:35 +0000203{
Jim Ingham1e58cef2012-04-13 20:38:13 +0000204 lldb::addr_t start_load_addr;
205 ABI *abi;
206 lldb::addr_t function_load_addr;
Jim Ingham110b55f2012-05-11 18:43:38 +0000207 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Claytonf4124de2012-02-21 00:09:25 +0000208 return;
209
Greg Clayton989816b2011-05-14 01:50:35 +0000210 if (!abi->PrepareTrivialCall (thread,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000211 m_function_sp,
212 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000213 start_load_addr,
214 arg1_ptr,
215 arg2_ptr,
216 arg3_ptr,
217 arg4_ptr,
218 arg5_ptr,
219 arg6_ptr))
220 {
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000221 return;
222 }
Chris Lattner24943d22010-06-08 16:52:24 +0000223
Jim Ingham2f6267f2011-01-22 01:27:23 +0000224 ReportRegisterState ("Function call was set up. Register state was:");
225
226 m_valid = true;
227}
228
229ThreadPlanCallFunction::~ThreadPlanCallFunction ()
230{
Jim Ingham038fa8e2012-05-10 01:35:39 +0000231 DoTakedown(true);
Jim Ingham2f6267f2011-01-22 01:27:23 +0000232}
233
234void
235ThreadPlanCallFunction::ReportRegisterState (const char *message)
236{
Greg Clayton628cead2011-05-19 03:54:16 +0000237 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callanan6dff8272010-11-08 03:49:50 +0000238 if (log)
239 {
Greg Clayton628cead2011-05-19 03:54:16 +0000240 StreamString strm;
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000241 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000242
243 log->PutCString(message);
244
Greg Clayton628cead2011-05-19 03:54:16 +0000245 RegisterValue reg_value;
246
247 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
248 reg_idx < num_registers;
249 ++reg_idx)
Sean Callanan6dff8272010-11-08 03:49:50 +0000250 {
Greg Clayton628cead2011-05-19 03:54:16 +0000251 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
252 if (reg_ctx->ReadRegister(reg_info, reg_value))
253 {
254 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
255 strm.EOL();
256 }
Sean Callanan6dff8272010-11-08 03:49:50 +0000257 }
Greg Clayton628cead2011-05-19 03:54:16 +0000258 log->PutCString(strm.GetData());
Sean Callanan6dff8272010-11-08 03:49:50 +0000259 }
Sean Callanan14a97ff2010-11-04 01:51:38 +0000260}
261
262void
Jim Ingham038fa8e2012-05-10 01:35:39 +0000263ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan14a97ff2010-11-04 01:51:38 +0000264{
Jim Inghama8d26eb2012-04-13 23:11:52 +0000265 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
266
267 if (!m_valid)
268 {
269 //Don't call DoTakedown if we were never valid to begin with.
270 if (log)
271 log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.", this);
272 return;
273 }
274
Jim Ingham2f6267f2011-01-22 01:27:23 +0000275 if (!m_takedown_done)
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000276 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000277 if (success)
Greg Clayton2f085c62011-05-15 01:25:55 +0000278 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000279 ProcessSP process_sp (m_thread.GetProcess());
280 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
281 if (abi && m_return_type.IsValid())
282 {
283 const bool persistent = false;
284 m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent);
285 }
Greg Clayton2f085c62011-05-15 01:25:55 +0000286 }
Jim Ingham2f6267f2011-01-22 01:27:23 +0000287 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000288 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called for thread 0x%4.4llx, m_valid: %d complete: %d.\n", this, m_thread.GetID(), m_valid, IsPlanComplete());
Jim Ingham2f6267f2011-01-22 01:27:23 +0000289 m_takedown_done = true;
Jim Inghamba560cc2011-11-01 02:46:54 +0000290 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham2370a972011-05-17 01:10:11 +0000291 m_real_stop_info_sp = GetPrivateStopReason();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000292 m_thread.RestoreThreadStateFromCheckpoint(m_stored_thread_state);
Jim Ingham038fa8e2012-05-10 01:35:39 +0000293 SetPlanComplete(success);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000294 ClearBreakpoints();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000295 if (log && log->GetVerbose())
296 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham78108e62011-01-26 19:13:09 +0000297
Jim Ingham2f6267f2011-01-22 01:27:23 +0000298 }
299 else
300 {
301 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000302 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called as no-op for thread 0x%4.4llx, m_valid: %d complete: %d.\n", this, m_thread.GetID(), m_valid, IsPlanComplete());
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000303 }
Chris Lattner24943d22010-06-08 16:52:24 +0000304}
305
306void
Jim Ingham6c9662e2011-01-18 01:58:06 +0000307ThreadPlanCallFunction::WillPop ()
308{
Jim Ingham038fa8e2012-05-10 01:35:39 +0000309 DoTakedown(true);
Jim Ingham6c9662e2011-01-18 01:58:06 +0000310}
311
312void
Greg Clayton989816b2011-05-14 01:50:35 +0000313ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +0000314{
Greg Clayton989816b2011-05-14 01:50:35 +0000315 if (level == eDescriptionLevelBrief)
Chris Lattner24943d22010-06-08 16:52:24 +0000316 {
317 s->Printf("Function call thread plan");
318 }
319 else
320 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000321 TargetSP target_sp (m_thread.CalculateTarget());
322 s->Printf("Thread plan to call 0x%llx", m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner24943d22010-06-08 16:52:24 +0000323 }
324}
325
326bool
327ThreadPlanCallFunction::ValidatePlan (Stream *error)
328{
329 if (!m_valid)
330 return false;
331
332 return true;
333}
334
335bool
336ThreadPlanCallFunction::PlanExplainsStop ()
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000337{
Jim Ingham2370a972011-05-17 01:10:11 +0000338 m_real_stop_info_sp = GetPrivateStopReason();
339
Jim Ingham988ddbc2010-10-26 00:27:45 +0000340 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
341 // we answer yes.
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000342 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000343 return true;
Sean Callananba8547d2010-10-19 22:24:06 +0000344
Sean Callanan94fb5432010-11-03 19:36:28 +0000345 // Check if the breakpoint is one of ours.
346
Jim Ingham038fa8e2012-05-10 01:35:39 +0000347 StopReason stop_reason;
348 if (!m_real_stop_info_sp)
349 stop_reason = eStopReasonNone;
350 else
351 stop_reason = m_real_stop_info_sp->GetStopReason();
352
353 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
Sean Callanan94fb5432010-11-03 19:36:28 +0000354 return true;
355
Jim Ingham988ddbc2010-10-26 00:27:45 +0000356 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
Jim Ingham110b55f2012-05-11 18:43:38 +0000357 if (!m_discard_on_error)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000358 return false;
359
360 // Otherwise, check the case where we stopped for an internal breakpoint, in that case, continue on.
361 // If it is not an internal breakpoint, consult OkayToDiscard.
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000362
Jim Ingham038fa8e2012-05-10 01:35:39 +0000363
364 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000365 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000366 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham2370a972011-05-17 01:10:11 +0000367 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Claytonf4124de2012-02-21 00:09:25 +0000368 BreakpointSiteSP bp_site_sp;
369 if (process_sp)
370 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham988ddbc2010-10-26 00:27:45 +0000371 if (bp_site_sp)
372 {
373 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
374 bool is_internal = true;
375 for (uint32_t i = 0; i < num_owners; i++)
376 {
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000377 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000378
379 if (!bp.IsInternal())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000380 {
381 is_internal = false;
382 break;
383 }
384 }
385 if (is_internal)
386 return false;
387 }
388
Jim Ingham110b55f2012-05-11 18:43:38 +0000389 if (m_discard_on_error)
390 {
391 DoTakedown(false);
392 return true;
393 }
394 else
395 return false;
Jim Ingham988ddbc2010-10-26 00:27:45 +0000396 }
397 else
398 {
399 // If the subplan is running, any crashes are attributable to us.
Jim Ingham78108e62011-01-26 19:13:09 +0000400 // If we want to discard the plan, then we say we explain the stop
401 // but if we are going to be discarded, let whoever is above us
402 // explain the stop.
Sean Callananb386d822012-08-09 00:50:26 +0000403 if (m_subplan_sp)
Jim Ingham038fa8e2012-05-10 01:35:39 +0000404 {
Jim Ingham110b55f2012-05-11 18:43:38 +0000405 if (m_discard_on_error)
Jim Ingham038fa8e2012-05-10 01:35:39 +0000406 {
407 DoTakedown(false);
408 return true;
409 }
410 else
411 return false;
412 }
413 else
414 return false;
Jim Ingham988ddbc2010-10-26 00:27:45 +0000415 }
Chris Lattner24943d22010-06-08 16:52:24 +0000416}
417
418bool
419ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
420{
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000421 if (IsPlanComplete() || PlanExplainsStop())
Chris Lattner24943d22010-06-08 16:52:24 +0000422 {
Jim Ingham2f6267f2011-01-22 01:27:23 +0000423 ReportRegisterState ("Function completed. Register state was:");
Sean Callananf5857a02010-07-31 01:32:05 +0000424
Jim Ingham038fa8e2012-05-10 01:35:39 +0000425 DoTakedown(true);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000426
Chris Lattner24943d22010-06-08 16:52:24 +0000427 return true;
428 }
429 else
430 {
431 return false;
432 }
433}
434
435bool
436ThreadPlanCallFunction::StopOthers ()
437{
438 return m_stop_other_threads;
439}
440
441void
442ThreadPlanCallFunction::SetStopOthers (bool new_value)
443{
444 if (m_subplan_sp)
445 {
446 ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get());
447 address_plan->SetStopOthers(new_value);
448 }
449 m_stop_other_threads = new_value;
450}
451
452StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000453ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000454{
455 return eStateRunning;
456}
457
458void
459ThreadPlanCallFunction::DidPush ()
460{
Sean Callananc2c6f772010-10-26 00:31:56 +0000461//#define SINGLE_STEP_EXPRESSIONS
462
463#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner24943d22010-06-08 16:52:24 +0000464 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
465
466 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000467 m_subplan_sp->SetPrivate (true);
Sean Callananc2c6f772010-10-26 00:31:56 +0000468#endif
Chris Lattner24943d22010-06-08 16:52:24 +0000469}
470
471bool
472ThreadPlanCallFunction::WillStop ()
473{
474 return true;
475}
476
477bool
478ThreadPlanCallFunction::MischiefManaged ()
479{
480 if (IsPlanComplete())
481 {
Greg Claytone005f2c2010-11-06 01:53:30 +0000482 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000483
484 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000485 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this);
Chris Lattner24943d22010-06-08 16:52:24 +0000486
487 ThreadPlan::MischiefManaged ();
488 return true;
489 }
490 else
491 {
492 return false;
493 }
494}
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000495
496void
497ThreadPlanCallFunction::SetBreakpoints ()
498{
Greg Claytonf4124de2012-02-21 00:09:25 +0000499 ProcessSP process_sp (m_thread.CalculateProcess());
500 if (process_sp)
501 {
502 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
503 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000504
Greg Claytonf4124de2012-02-21 00:09:25 +0000505 if (m_cxx_language_runtime)
506 m_cxx_language_runtime->SetExceptionBreakpoints();
507 if (m_objc_language_runtime)
508 m_objc_language_runtime->SetExceptionBreakpoints();
509 }
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000510}
511
512void
513ThreadPlanCallFunction::ClearBreakpoints ()
514{
Sean Callanan29756d42010-11-03 22:19:38 +0000515 if (m_cxx_language_runtime)
516 m_cxx_language_runtime->ClearExceptionBreakpoints();
517 if (m_objc_language_runtime)
518 m_objc_language_runtime->ClearExceptionBreakpoints();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000519}
Sean Callanan94fb5432010-11-03 19:36:28 +0000520
521bool
522ThreadPlanCallFunction::BreakpointsExplainStop()
523{
Greg Clayton989816b2011-05-14 01:50:35 +0000524 StopInfoSP stop_info_sp = GetPrivateStopReason();
Sean Callanan94fb5432010-11-03 19:36:28 +0000525
Sean Callanan29756d42010-11-03 22:19:38 +0000526 if (m_cxx_language_runtime &&
527 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
528 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000529
Sean Callanan29756d42010-11-03 22:19:38 +0000530 if (m_objc_language_runtime &&
531 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
532 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000533
534 return false;
535}