blob: 09bdd3d73c06a448b8fe61eaccab8364c15df8c7 [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"
22#include "lldb/Core/Stream.h"
Sean Callanan29756d42010-11-03 22:19:38 +000023#include "lldb/Target/LanguageRuntime.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Target/Process.h"
25#include "lldb/Target/RegisterContext.h"
Jim Ingham988ddbc2010-10-26 00:27:45 +000026#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/Target.h"
28#include "lldb/Target/Thread.h"
29#include "lldb/Target/ThreadPlanRunToAddress.h"
30
31using namespace lldb;
32using namespace lldb_private;
33
34//----------------------------------------------------------------------
35// ThreadPlanCallFunction: Plan to call a single function
36//----------------------------------------------------------------------
37
38ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
39 Address &function,
Jim Ingham016ef882011-12-22 19:12:40 +000040 const ClangASTType &return_type,
Greg Clayton989816b2011-05-14 01:50:35 +000041 addr_t arg,
Chris Lattner24943d22010-06-08 16:52:24 +000042 bool stop_other_threads,
Sean Callanan3c9c5eb2010-09-21 00:44:12 +000043 bool discard_on_error,
Greg Clayton989816b2011-05-14 01:50:35 +000044 addr_t *this_arg,
45 addr_t *cmd_arg) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000046 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer36a08102010-07-16 12:32:33 +000047 m_valid (false),
48 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +000049 m_function_addr (function),
Peter Collingbourneabb53e52011-06-03 20:41:09 +000050 m_function_sp (NULL),
Jim Ingham016ef882011-12-22 19:12:40 +000051 m_return_type (return_type),
Jim Inghamba560cc2011-11-01 02:46:54 +000052 m_takedown_done (false),
53 m_stop_address (LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +000054{
Chris Lattner24943d22010-06-08 16:52:24 +000055 SetOkayToDiscard (discard_on_error);
56
Greg Claytonf4124de2012-02-21 00:09:25 +000057 ProcessSP process_sp (thread.GetProcess());
58 if (!process_sp)
59 return;
60
61 const ABI *abi = process_sp->GetABI().get();
Sean Callanan07f3d8d2010-11-03 01:37:52 +000062
Chris Lattner24943d22010-06-08 16:52:24 +000063 if (!abi)
64 return;
Sean Callanan07f3d8d2010-11-03 01:37:52 +000065
Greg Claytonf4124de2012-02-21 00:09:25 +000066 TargetSP target_sp (thread.CalculateTarget());
67
Jim Ingham15dcb7c2011-01-20 02:03:18 +000068 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
69
Sean Callanan07f3d8d2010-11-03 01:37:52 +000070 SetBreakpoints();
71
Sean Callanan0ddf8062011-05-09 22:04:36 +000072 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
Chris Lattner24943d22010-06-08 16:52:24 +000073
Greg Claytonf4124de2012-02-21 00:09:25 +000074 Module *exe_module = target_sp->GetExecutableModulePointer();
Chris Lattner24943d22010-06-08 16:52:24 +000075
Greg Clayton5beb99d2011-08-11 02:48:45 +000076 if (exe_module == NULL)
Jim Ingham28775942011-03-07 23:44:08 +000077 {
Johnny Chen9d56ba92011-08-10 17:58:11 +000078 if (log)
79 log->Printf ("Can't execute code without an executable module.");
Chris Lattner24943d22010-06-08 16:52:24 +000080 return;
Jim Ingham28775942011-03-07 23:44:08 +000081 }
82 else
83 {
Greg Clayton5beb99d2011-08-11 02:48:45 +000084 ObjectFile *objectFile = exe_module->GetObjectFile();
Jim Ingham28775942011-03-07 23:44:08 +000085 if (!objectFile)
86 {
Johnny Chen9d56ba92011-08-10 17:58:11 +000087 if (log)
88 log->Printf ("Could not find object file for module \"%s\".",
Greg Claytonb01760c2011-08-11 04:30:39 +000089 exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham28775942011-03-07 23:44:08 +000090 return;
91 }
92 m_start_addr = objectFile->GetEntryPointAddress();
93 if (!m_start_addr.IsValid())
94 {
Johnny Chen9d56ba92011-08-10 17:58:11 +000095 if (log)
96 log->Printf ("Could not find entry point address for executable module \"%s\".",
Greg Claytonb01760c2011-08-11 04:30:39 +000097 exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham28775942011-03-07 23:44:08 +000098 return;
99 }
100 }
Chris Lattner24943d22010-06-08 16:52:24 +0000101
Greg Claytonf4124de2012-02-21 00:09:25 +0000102 addr_t start_load_addr = m_start_addr.GetLoadAddress (target_sp.get());
Jim Ingham28775942011-03-07 23:44:08 +0000103
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000104 // Checkpoint the thread state so we can restore it later.
Jim Ingham2f6267f2011-01-22 01:27:23 +0000105 if (log && log->GetVerbose())
106 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
107
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000108 if (!thread.CheckpointThreadState (m_stored_thread_state))
109 {
110 if (log)
111 log->Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
Chris Lattner24943d22010-06-08 16:52:24 +0000112 return;
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000113 }
114 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
115 thread.SetStopInfoToNothing();
116
Greg Claytonf4124de2012-02-21 00:09:25 +0000117 addr_t FunctionLoadAddr = m_function_addr.GetLoadAddress (target_sp.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000118
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000119 if (this_arg && cmd_arg)
120 {
121 if (!abi->PrepareTrivialCall (thread,
122 m_function_sp,
123 FunctionLoadAddr,
Greg Clayton989816b2011-05-14 01:50:35 +0000124 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000125 this_arg,
126 cmd_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000127 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000128 return;
129 }
130 else if (this_arg)
131 {
132 if (!abi->PrepareTrivialCall (thread,
133 m_function_sp,
134 FunctionLoadAddr,
Greg Clayton989816b2011-05-14 01:50:35 +0000135 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000136 this_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000137 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000138 return;
139 }
140 else
141 {
142 if (!abi->PrepareTrivialCall (thread,
143 m_function_sp,
144 FunctionLoadAddr,
Greg Clayton989816b2011-05-14 01:50:35 +0000145 start_load_addr,
146 &arg))
147 return;
148 }
149
150 ReportRegisterState ("Function call was set up. Register state was:");
151
152 m_valid = true;
153}
154
155
156ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
157 Address &function,
Jim Ingham016ef882011-12-22 19:12:40 +0000158 const ClangASTType &return_type,
Greg Clayton989816b2011-05-14 01:50:35 +0000159 bool stop_other_threads,
160 bool discard_on_error,
161 addr_t *arg1_ptr,
162 addr_t *arg2_ptr,
163 addr_t *arg3_ptr,
164 addr_t *arg4_ptr,
165 addr_t *arg5_ptr,
166 addr_t *arg6_ptr) :
167 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
168 m_valid (false),
169 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000170 m_function_addr (function),
Peter Collingbourneabb53e52011-06-03 20:41:09 +0000171 m_function_sp(NULL),
Jim Ingham016ef882011-12-22 19:12:40 +0000172 m_return_type (return_type),
Peter Collingbourneabb53e52011-06-03 20:41:09 +0000173 m_takedown_done (false)
Greg Clayton989816b2011-05-14 01:50:35 +0000174{
175 SetOkayToDiscard (discard_on_error);
176
Greg Claytonf4124de2012-02-21 00:09:25 +0000177 ProcessSP process_sp (thread.GetProcess());
178 if (!process_sp)
179 return;
180
181 const ABI *abi = process_sp->GetABI().get();
Greg Clayton989816b2011-05-14 01:50:35 +0000182
183 if (!abi)
184 return;
Greg Claytonf4124de2012-02-21 00:09:25 +0000185
186 TargetSP target_sp (thread.CalculateTarget());
187
Greg Clayton989816b2011-05-14 01:50:35 +0000188 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
189
190 SetBreakpoints();
191
192 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
193
Greg Claytonf4124de2012-02-21 00:09:25 +0000194 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton989816b2011-05-14 01:50:35 +0000195
Greg Clayton5beb99d2011-08-11 02:48:45 +0000196 if (exe_module == NULL)
Greg Clayton989816b2011-05-14 01:50:35 +0000197 {
Johnny Chen9d56ba92011-08-10 17:58:11 +0000198 if (log)
199 log->Printf ("Can't execute code without an executable module.");
Greg Clayton989816b2011-05-14 01:50:35 +0000200 return;
201 }
202 else
203 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000204 ObjectFile *objectFile = exe_module->GetObjectFile();
Greg Clayton989816b2011-05-14 01:50:35 +0000205 if (!objectFile)
206 {
Johnny Chen9d56ba92011-08-10 17:58:11 +0000207 if (log)
208 log->Printf ("Could not find object file for module \"%s\".",
Greg Claytonb01760c2011-08-11 04:30:39 +0000209 exe_module->GetFileSpec().GetFilename().AsCString());
Greg Clayton989816b2011-05-14 01:50:35 +0000210 return;
211 }
212 m_start_addr = objectFile->GetEntryPointAddress();
213 if (!m_start_addr.IsValid())
214 {
Greg Clayton628cead2011-05-19 03:54:16 +0000215 if (log)
216 log->Printf ("Could not find entry point address for executable module \"%s\".",
Greg Clayton5beb99d2011-08-11 02:48:45 +0000217 exe_module->GetFileSpec().GetFilename().AsCString());
Greg Clayton989816b2011-05-14 01:50:35 +0000218 return;
219 }
220 }
221
Greg Claytonf4124de2012-02-21 00:09:25 +0000222 addr_t start_load_addr = m_start_addr.GetLoadAddress(target_sp.get());
Greg Clayton989816b2011-05-14 01:50:35 +0000223
224 // Checkpoint the thread state so we can restore it later.
225 if (log && log->GetVerbose())
226 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
227
228 if (!thread.CheckpointThreadState (m_stored_thread_state))
229 {
230 if (log)
231 log->Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
232 return;
233 }
234 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
235 thread.SetStopInfoToNothing();
236
Greg Claytonf4124de2012-02-21 00:09:25 +0000237 addr_t FunctionLoadAddr = m_function_addr.GetLoadAddress(target_sp.get());
Greg Clayton989816b2011-05-14 01:50:35 +0000238
239 if (!abi->PrepareTrivialCall (thread,
240 m_function_sp,
241 FunctionLoadAddr,
242 start_load_addr,
243 arg1_ptr,
244 arg2_ptr,
245 arg3_ptr,
246 arg4_ptr,
247 arg5_ptr,
248 arg6_ptr))
249 {
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000250 return;
251 }
Chris Lattner24943d22010-06-08 16:52:24 +0000252
Jim Ingham2f6267f2011-01-22 01:27:23 +0000253 ReportRegisterState ("Function call was set up. Register state was:");
254
255 m_valid = true;
256}
257
258ThreadPlanCallFunction::~ThreadPlanCallFunction ()
259{
260}
261
262void
263ThreadPlanCallFunction::ReportRegisterState (const char *message)
264{
Greg Clayton628cead2011-05-19 03:54:16 +0000265 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callanan6dff8272010-11-08 03:49:50 +0000266 if (log)
267 {
Greg Clayton628cead2011-05-19 03:54:16 +0000268 StreamString strm;
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000269 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000270
271 log->PutCString(message);
272
Greg Clayton628cead2011-05-19 03:54:16 +0000273 RegisterValue reg_value;
274
275 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
276 reg_idx < num_registers;
277 ++reg_idx)
Sean Callanan6dff8272010-11-08 03:49:50 +0000278 {
Greg Clayton628cead2011-05-19 03:54:16 +0000279 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
280 if (reg_ctx->ReadRegister(reg_info, reg_value))
281 {
282 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
283 strm.EOL();
284 }
Sean Callanan6dff8272010-11-08 03:49:50 +0000285 }
Greg Clayton628cead2011-05-19 03:54:16 +0000286 log->PutCString(strm.GetData());
Sean Callanan6dff8272010-11-08 03:49:50 +0000287 }
Sean Callanan14a97ff2010-11-04 01:51:38 +0000288}
289
290void
291ThreadPlanCallFunction::DoTakedown ()
292{
Jim Ingham2f6267f2011-01-22 01:27:23 +0000293 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
294 if (!m_takedown_done)
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000295 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000296 ProcessSP process_sp (m_thread.GetProcess());
297 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
Jim Ingham016ef882011-12-22 19:12:40 +0000298 if (abi && m_return_type.IsValid())
Greg Clayton2f085c62011-05-15 01:25:55 +0000299 {
Jim Ingham016ef882011-12-22 19:12:40 +0000300 m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type);
Greg Clayton2f085c62011-05-15 01:25:55 +0000301 }
Jim Ingham016ef882011-12-22 19:12:40 +0000302
Jim Ingham2f6267f2011-01-22 01:27:23 +0000303 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000304 log->Printf ("DoTakedown called for thread 0x%4.4llx, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete());
Jim Ingham2f6267f2011-01-22 01:27:23 +0000305 m_takedown_done = true;
Jim Inghamba560cc2011-11-01 02:46:54 +0000306 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham2370a972011-05-17 01:10:11 +0000307 m_real_stop_info_sp = GetPrivateStopReason();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000308 m_thread.RestoreThreadStateFromCheckpoint(m_stored_thread_state);
309 SetPlanComplete();
310 ClearBreakpoints();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000311 if (log && log->GetVerbose())
312 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham78108e62011-01-26 19:13:09 +0000313
Jim Ingham2f6267f2011-01-22 01:27:23 +0000314 }
315 else
316 {
317 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000318 log->Printf ("DoTakedown called as no-op for thread 0x%4.4llx, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete());
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000319 }
Chris Lattner24943d22010-06-08 16:52:24 +0000320}
321
322void
Jim Ingham6c9662e2011-01-18 01:58:06 +0000323ThreadPlanCallFunction::WillPop ()
324{
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000325 DoTakedown();
Jim Ingham6c9662e2011-01-18 01:58:06 +0000326}
327
328void
Greg Clayton989816b2011-05-14 01:50:35 +0000329ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +0000330{
Greg Clayton989816b2011-05-14 01:50:35 +0000331 if (level == eDescriptionLevelBrief)
Chris Lattner24943d22010-06-08 16:52:24 +0000332 {
333 s->Printf("Function call thread plan");
334 }
335 else
336 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000337 TargetSP target_sp (m_thread.CalculateTarget());
338 s->Printf("Thread plan to call 0x%llx", m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner24943d22010-06-08 16:52:24 +0000339 }
340}
341
342bool
343ThreadPlanCallFunction::ValidatePlan (Stream *error)
344{
345 if (!m_valid)
346 return false;
347
348 return true;
349}
350
351bool
352ThreadPlanCallFunction::PlanExplainsStop ()
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000353{
Jim Ingham2370a972011-05-17 01:10:11 +0000354 m_real_stop_info_sp = GetPrivateStopReason();
355
Jim Ingham988ddbc2010-10-26 00:27:45 +0000356 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
357 // we answer yes.
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000358 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000359 return true;
Sean Callananba8547d2010-10-19 22:24:06 +0000360
Sean Callanan94fb5432010-11-03 19:36:28 +0000361 // Check if the breakpoint is one of ours.
362
363 if (BreakpointsExplainStop())
364 return true;
365
Jim Ingham988ddbc2010-10-26 00:27:45 +0000366 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
367 if (!OkayToDiscard())
368 return false;
369
370 // Otherwise, check the case where we stopped for an internal breakpoint, in that case, continue on.
371 // If it is not an internal breakpoint, consult OkayToDiscard.
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000372
Jim Ingham2370a972011-05-17 01:10:11 +0000373 if (m_real_stop_info_sp && m_real_stop_info_sp->GetStopReason() == eStopReasonBreakpoint)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000374 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000375 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham2370a972011-05-17 01:10:11 +0000376 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Claytonf4124de2012-02-21 00:09:25 +0000377 BreakpointSiteSP bp_site_sp;
378 if (process_sp)
379 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham988ddbc2010-10-26 00:27:45 +0000380 if (bp_site_sp)
381 {
382 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
383 bool is_internal = true;
384 for (uint32_t i = 0; i < num_owners; i++)
385 {
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000386 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000387
388 if (!bp.IsInternal())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000389 {
390 is_internal = false;
391 break;
392 }
393 }
394 if (is_internal)
395 return false;
396 }
397
398 return OkayToDiscard();
399 }
400 else
401 {
402 // If the subplan is running, any crashes are attributable to us.
Jim Ingham78108e62011-01-26 19:13:09 +0000403 // If we want to discard the plan, then we say we explain the stop
404 // but if we are going to be discarded, let whoever is above us
405 // explain the stop.
406 return ((m_subplan_sp.get() != NULL) && !OkayToDiscard());
Jim Ingham988ddbc2010-10-26 00:27:45 +0000407 }
Chris Lattner24943d22010-06-08 16:52:24 +0000408}
409
410bool
411ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
412{
413 if (PlanExplainsStop())
414 {
Jim Ingham2f6267f2011-01-22 01:27:23 +0000415 ReportRegisterState ("Function completed. Register state was:");
Sean Callananf5857a02010-07-31 01:32:05 +0000416
Sean Callanan14a97ff2010-11-04 01:51:38 +0000417 DoTakedown();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000418
Chris Lattner24943d22010-06-08 16:52:24 +0000419 return true;
420 }
421 else
422 {
423 return false;
424 }
425}
426
427bool
428ThreadPlanCallFunction::StopOthers ()
429{
430 return m_stop_other_threads;
431}
432
433void
434ThreadPlanCallFunction::SetStopOthers (bool new_value)
435{
436 if (m_subplan_sp)
437 {
438 ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get());
439 address_plan->SetStopOthers(new_value);
440 }
441 m_stop_other_threads = new_value;
442}
443
444StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000445ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000446{
447 return eStateRunning;
448}
449
450void
451ThreadPlanCallFunction::DidPush ()
452{
Sean Callananc2c6f772010-10-26 00:31:56 +0000453//#define SINGLE_STEP_EXPRESSIONS
454
455#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner24943d22010-06-08 16:52:24 +0000456 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
457
458 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000459 m_subplan_sp->SetPrivate (true);
Sean Callananc2c6f772010-10-26 00:31:56 +0000460#endif
Chris Lattner24943d22010-06-08 16:52:24 +0000461}
462
463bool
464ThreadPlanCallFunction::WillStop ()
465{
466 return true;
467}
468
469bool
470ThreadPlanCallFunction::MischiefManaged ()
471{
472 if (IsPlanComplete())
473 {
Greg Claytone005f2c2010-11-06 01:53:30 +0000474 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000475
476 if (log)
477 log->Printf("Completed call function plan.");
478
479 ThreadPlan::MischiefManaged ();
480 return true;
481 }
482 else
483 {
484 return false;
485 }
486}
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000487
488void
489ThreadPlanCallFunction::SetBreakpoints ()
490{
Greg Claytonf4124de2012-02-21 00:09:25 +0000491 ProcessSP process_sp (m_thread.CalculateProcess());
492 if (process_sp)
493 {
494 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
495 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000496
Greg Claytonf4124de2012-02-21 00:09:25 +0000497 if (m_cxx_language_runtime)
498 m_cxx_language_runtime->SetExceptionBreakpoints();
499 if (m_objc_language_runtime)
500 m_objc_language_runtime->SetExceptionBreakpoints();
501 }
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000502}
503
504void
505ThreadPlanCallFunction::ClearBreakpoints ()
506{
Sean Callanan29756d42010-11-03 22:19:38 +0000507 if (m_cxx_language_runtime)
508 m_cxx_language_runtime->ClearExceptionBreakpoints();
509 if (m_objc_language_runtime)
510 m_objc_language_runtime->ClearExceptionBreakpoints();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000511}
Sean Callanan94fb5432010-11-03 19:36:28 +0000512
513bool
514ThreadPlanCallFunction::BreakpointsExplainStop()
515{
Greg Clayton989816b2011-05-14 01:50:35 +0000516 StopInfoSP stop_info_sp = GetPrivateStopReason();
Sean Callanan94fb5432010-11-03 19:36:28 +0000517
Sean Callanan29756d42010-11-03 22:19:38 +0000518 if (m_cxx_language_runtime &&
519 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
520 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000521
Sean Callanan29756d42010-11-03 22:19:38 +0000522 if (m_objc_language_runtime &&
523 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
524 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000525
526 return false;
527}