blob: 9f6c18e5bd84ea69cf84346f08bb314634e44f5b [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{
Jim Ingham2bcbaf62012-04-09 22:37:39 +000055 // Call function thread plans need to be master plans so that they can potentially stay on the stack when
56 // a breakpoint is hit during the function call.
57 SetIsMasterPlan (true);
Chris Lattner24943d22010-06-08 16:52:24 +000058 SetOkayToDiscard (discard_on_error);
59
Greg Claytonf4124de2012-02-21 00:09:25 +000060 ProcessSP process_sp (thread.GetProcess());
61 if (!process_sp)
62 return;
63
64 const ABI *abi = process_sp->GetABI().get();
Sean Callanan07f3d8d2010-11-03 01:37:52 +000065
Chris Lattner24943d22010-06-08 16:52:24 +000066 if (!abi)
67 return;
Sean Callanan07f3d8d2010-11-03 01:37:52 +000068
Greg Claytonf4124de2012-02-21 00:09:25 +000069 TargetSP target_sp (thread.CalculateTarget());
70
Jim Ingham15dcb7c2011-01-20 02:03:18 +000071 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
72
Sean Callanan07f3d8d2010-11-03 01:37:52 +000073 SetBreakpoints();
74
Sean Callanan0ddf8062011-05-09 22:04:36 +000075 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
Chris Lattner24943d22010-06-08 16:52:24 +000076
Greg Claytonf4124de2012-02-21 00:09:25 +000077 Module *exe_module = target_sp->GetExecutableModulePointer();
Chris Lattner24943d22010-06-08 16:52:24 +000078
Greg Clayton5beb99d2011-08-11 02:48:45 +000079 if (exe_module == NULL)
Jim Ingham28775942011-03-07 23:44:08 +000080 {
Johnny Chen9d56ba92011-08-10 17:58:11 +000081 if (log)
82 log->Printf ("Can't execute code without an executable module.");
Chris Lattner24943d22010-06-08 16:52:24 +000083 return;
Jim Ingham28775942011-03-07 23:44:08 +000084 }
85 else
86 {
Greg Clayton5beb99d2011-08-11 02:48:45 +000087 ObjectFile *objectFile = exe_module->GetObjectFile();
Jim Ingham28775942011-03-07 23:44:08 +000088 if (!objectFile)
89 {
Johnny Chen9d56ba92011-08-10 17:58:11 +000090 if (log)
91 log->Printf ("Could not find object file for module \"%s\".",
Greg Claytonb01760c2011-08-11 04:30:39 +000092 exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham28775942011-03-07 23:44:08 +000093 return;
94 }
95 m_start_addr = objectFile->GetEntryPointAddress();
96 if (!m_start_addr.IsValid())
97 {
Johnny Chen9d56ba92011-08-10 17:58:11 +000098 if (log)
99 log->Printf ("Could not find entry point address for executable module \"%s\".",
Greg Claytonb01760c2011-08-11 04:30:39 +0000100 exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham28775942011-03-07 23:44:08 +0000101 return;
102 }
103 }
Chris Lattner24943d22010-06-08 16:52:24 +0000104
Greg Claytonf4124de2012-02-21 00:09:25 +0000105 addr_t start_load_addr = m_start_addr.GetLoadAddress (target_sp.get());
Jim Ingham28775942011-03-07 23:44:08 +0000106
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000107 // Checkpoint the thread state so we can restore it later.
Jim Ingham2f6267f2011-01-22 01:27:23 +0000108 if (log && log->GetVerbose())
109 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
110
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000111 if (!thread.CheckpointThreadState (m_stored_thread_state))
112 {
113 if (log)
114 log->Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
Chris Lattner24943d22010-06-08 16:52:24 +0000115 return;
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000116 }
117 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
118 thread.SetStopInfoToNothing();
119
Greg Claytonf4124de2012-02-21 00:09:25 +0000120 addr_t FunctionLoadAddr = m_function_addr.GetLoadAddress (target_sp.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000121
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000122 if (this_arg && cmd_arg)
123 {
124 if (!abi->PrepareTrivialCall (thread,
125 m_function_sp,
126 FunctionLoadAddr,
Greg Clayton989816b2011-05-14 01:50:35 +0000127 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000128 this_arg,
129 cmd_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000130 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000131 return;
132 }
133 else if (this_arg)
134 {
135 if (!abi->PrepareTrivialCall (thread,
136 m_function_sp,
137 FunctionLoadAddr,
Greg Clayton989816b2011-05-14 01:50:35 +0000138 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000139 this_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000140 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000141 return;
142 }
143 else
144 {
145 if (!abi->PrepareTrivialCall (thread,
146 m_function_sp,
147 FunctionLoadAddr,
Greg Clayton989816b2011-05-14 01:50:35 +0000148 start_load_addr,
149 &arg))
150 return;
151 }
152
153 ReportRegisterState ("Function call was set up. Register state was:");
154
155 m_valid = true;
156}
157
158
159ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
160 Address &function,
Jim Ingham016ef882011-12-22 19:12:40 +0000161 const ClangASTType &return_type,
Greg Clayton989816b2011-05-14 01:50:35 +0000162 bool stop_other_threads,
163 bool discard_on_error,
164 addr_t *arg1_ptr,
165 addr_t *arg2_ptr,
166 addr_t *arg3_ptr,
167 addr_t *arg4_ptr,
168 addr_t *arg5_ptr,
169 addr_t *arg6_ptr) :
170 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
171 m_valid (false),
172 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000173 m_function_addr (function),
Peter Collingbourneabb53e52011-06-03 20:41:09 +0000174 m_function_sp(NULL),
Jim Ingham016ef882011-12-22 19:12:40 +0000175 m_return_type (return_type),
Peter Collingbourneabb53e52011-06-03 20:41:09 +0000176 m_takedown_done (false)
Greg Clayton989816b2011-05-14 01:50:35 +0000177{
Jim Ingham2bcbaf62012-04-09 22:37:39 +0000178 // Call function thread plans need to be master plans so that they can potentially stay on the stack when
179 // a breakpoint is hit during the function call.
180 SetIsMasterPlan (true);
Greg Clayton989816b2011-05-14 01:50:35 +0000181 SetOkayToDiscard (discard_on_error);
182
Greg Claytonf4124de2012-02-21 00:09:25 +0000183 ProcessSP process_sp (thread.GetProcess());
184 if (!process_sp)
185 return;
186
187 const ABI *abi = process_sp->GetABI().get();
Greg Clayton989816b2011-05-14 01:50:35 +0000188
189 if (!abi)
190 return;
Greg Claytonf4124de2012-02-21 00:09:25 +0000191
192 TargetSP target_sp (thread.CalculateTarget());
193
Greg Clayton989816b2011-05-14 01:50:35 +0000194 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
195
196 SetBreakpoints();
197
198 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
199
Greg Claytonf4124de2012-02-21 00:09:25 +0000200 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton989816b2011-05-14 01:50:35 +0000201
Greg Clayton5beb99d2011-08-11 02:48:45 +0000202 if (exe_module == NULL)
Greg Clayton989816b2011-05-14 01:50:35 +0000203 {
Johnny Chen9d56ba92011-08-10 17:58:11 +0000204 if (log)
205 log->Printf ("Can't execute code without an executable module.");
Greg Clayton989816b2011-05-14 01:50:35 +0000206 return;
207 }
208 else
209 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000210 ObjectFile *objectFile = exe_module->GetObjectFile();
Greg Clayton989816b2011-05-14 01:50:35 +0000211 if (!objectFile)
212 {
Johnny Chen9d56ba92011-08-10 17:58:11 +0000213 if (log)
214 log->Printf ("Could not find object file for module \"%s\".",
Greg Claytonb01760c2011-08-11 04:30:39 +0000215 exe_module->GetFileSpec().GetFilename().AsCString());
Greg Clayton989816b2011-05-14 01:50:35 +0000216 return;
217 }
218 m_start_addr = objectFile->GetEntryPointAddress();
219 if (!m_start_addr.IsValid())
220 {
Greg Clayton628cead2011-05-19 03:54:16 +0000221 if (log)
222 log->Printf ("Could not find entry point address for executable module \"%s\".",
Greg Clayton5beb99d2011-08-11 02:48:45 +0000223 exe_module->GetFileSpec().GetFilename().AsCString());
Greg Clayton989816b2011-05-14 01:50:35 +0000224 return;
225 }
226 }
227
Greg Claytonf4124de2012-02-21 00:09:25 +0000228 addr_t start_load_addr = m_start_addr.GetLoadAddress(target_sp.get());
Greg Clayton989816b2011-05-14 01:50:35 +0000229
230 // Checkpoint the thread state so we can restore it later.
231 if (log && log->GetVerbose())
232 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
233
234 if (!thread.CheckpointThreadState (m_stored_thread_state))
235 {
236 if (log)
237 log->Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
238 return;
239 }
240 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
241 thread.SetStopInfoToNothing();
242
Greg Claytonf4124de2012-02-21 00:09:25 +0000243 addr_t FunctionLoadAddr = m_function_addr.GetLoadAddress(target_sp.get());
Greg Clayton989816b2011-05-14 01:50:35 +0000244
245 if (!abi->PrepareTrivialCall (thread,
246 m_function_sp,
247 FunctionLoadAddr,
248 start_load_addr,
249 arg1_ptr,
250 arg2_ptr,
251 arg3_ptr,
252 arg4_ptr,
253 arg5_ptr,
254 arg6_ptr))
255 {
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000256 return;
257 }
Chris Lattner24943d22010-06-08 16:52:24 +0000258
Jim Ingham2f6267f2011-01-22 01:27:23 +0000259 ReportRegisterState ("Function call was set up. Register state was:");
260
261 m_valid = true;
262}
263
264ThreadPlanCallFunction::~ThreadPlanCallFunction ()
265{
266}
267
268void
269ThreadPlanCallFunction::ReportRegisterState (const char *message)
270{
Greg Clayton628cead2011-05-19 03:54:16 +0000271 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callanan6dff8272010-11-08 03:49:50 +0000272 if (log)
273 {
Greg Clayton628cead2011-05-19 03:54:16 +0000274 StreamString strm;
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000275 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000276
277 log->PutCString(message);
278
Greg Clayton628cead2011-05-19 03:54:16 +0000279 RegisterValue reg_value;
280
281 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
282 reg_idx < num_registers;
283 ++reg_idx)
Sean Callanan6dff8272010-11-08 03:49:50 +0000284 {
Greg Clayton628cead2011-05-19 03:54:16 +0000285 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
286 if (reg_ctx->ReadRegister(reg_info, reg_value))
287 {
288 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
289 strm.EOL();
290 }
Sean Callanan6dff8272010-11-08 03:49:50 +0000291 }
Greg Clayton628cead2011-05-19 03:54:16 +0000292 log->PutCString(strm.GetData());
Sean Callanan6dff8272010-11-08 03:49:50 +0000293 }
Sean Callanan14a97ff2010-11-04 01:51:38 +0000294}
295
296void
297ThreadPlanCallFunction::DoTakedown ()
298{
Jim Ingham2f6267f2011-01-22 01:27:23 +0000299 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
300 if (!m_takedown_done)
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000301 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000302 ProcessSP process_sp (m_thread.GetProcess());
303 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
Jim Ingham016ef882011-12-22 19:12:40 +0000304 if (abi && m_return_type.IsValid())
Greg Clayton2f085c62011-05-15 01:25:55 +0000305 {
Jim Ingham016ef882011-12-22 19:12:40 +0000306 m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type);
Greg Clayton2f085c62011-05-15 01:25:55 +0000307 }
Jim Ingham016ef882011-12-22 19:12:40 +0000308
Jim Ingham2f6267f2011-01-22 01:27:23 +0000309 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000310 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 +0000311 m_takedown_done = true;
Jim Inghamba560cc2011-11-01 02:46:54 +0000312 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham2370a972011-05-17 01:10:11 +0000313 m_real_stop_info_sp = GetPrivateStopReason();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000314 m_thread.RestoreThreadStateFromCheckpoint(m_stored_thread_state);
315 SetPlanComplete();
316 ClearBreakpoints();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000317 if (log && log->GetVerbose())
318 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham78108e62011-01-26 19:13:09 +0000319
Jim Ingham2f6267f2011-01-22 01:27:23 +0000320 }
321 else
322 {
323 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000324 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 +0000325 }
Chris Lattner24943d22010-06-08 16:52:24 +0000326}
327
328void
Jim Ingham6c9662e2011-01-18 01:58:06 +0000329ThreadPlanCallFunction::WillPop ()
330{
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000331 DoTakedown();
Jim Ingham6c9662e2011-01-18 01:58:06 +0000332}
333
334void
Greg Clayton989816b2011-05-14 01:50:35 +0000335ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +0000336{
Greg Clayton989816b2011-05-14 01:50:35 +0000337 if (level == eDescriptionLevelBrief)
Chris Lattner24943d22010-06-08 16:52:24 +0000338 {
339 s->Printf("Function call thread plan");
340 }
341 else
342 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000343 TargetSP target_sp (m_thread.CalculateTarget());
344 s->Printf("Thread plan to call 0x%llx", m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner24943d22010-06-08 16:52:24 +0000345 }
346}
347
348bool
349ThreadPlanCallFunction::ValidatePlan (Stream *error)
350{
351 if (!m_valid)
352 return false;
353
354 return true;
355}
356
357bool
358ThreadPlanCallFunction::PlanExplainsStop ()
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000359{
Jim Ingham2370a972011-05-17 01:10:11 +0000360 m_real_stop_info_sp = GetPrivateStopReason();
361
Jim Ingham988ddbc2010-10-26 00:27:45 +0000362 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
363 // we answer yes.
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000364 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000365 return true;
Sean Callananba8547d2010-10-19 22:24:06 +0000366
Sean Callanan94fb5432010-11-03 19:36:28 +0000367 // Check if the breakpoint is one of ours.
368
369 if (BreakpointsExplainStop())
370 return true;
371
Jim Ingham988ddbc2010-10-26 00:27:45 +0000372 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
373 if (!OkayToDiscard())
374 return false;
375
376 // Otherwise, check the case where we stopped for an internal breakpoint, in that case, continue on.
377 // If it is not an internal breakpoint, consult OkayToDiscard.
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000378
Jim Ingham2370a972011-05-17 01:10:11 +0000379 if (m_real_stop_info_sp && m_real_stop_info_sp->GetStopReason() == eStopReasonBreakpoint)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000380 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000381 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham2370a972011-05-17 01:10:11 +0000382 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Claytonf4124de2012-02-21 00:09:25 +0000383 BreakpointSiteSP bp_site_sp;
384 if (process_sp)
385 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham988ddbc2010-10-26 00:27:45 +0000386 if (bp_site_sp)
387 {
388 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
389 bool is_internal = true;
390 for (uint32_t i = 0; i < num_owners; i++)
391 {
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000392 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000393
394 if (!bp.IsInternal())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000395 {
396 is_internal = false;
397 break;
398 }
399 }
400 if (is_internal)
401 return false;
402 }
403
404 return OkayToDiscard();
405 }
406 else
407 {
408 // If the subplan is running, any crashes are attributable to us.
Jim Ingham78108e62011-01-26 19:13:09 +0000409 // If we want to discard the plan, then we say we explain the stop
410 // but if we are going to be discarded, let whoever is above us
411 // explain the stop.
412 return ((m_subplan_sp.get() != NULL) && !OkayToDiscard());
Jim Ingham988ddbc2010-10-26 00:27:45 +0000413 }
Chris Lattner24943d22010-06-08 16:52:24 +0000414}
415
416bool
417ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
418{
419 if (PlanExplainsStop())
420 {
Jim Ingham2f6267f2011-01-22 01:27:23 +0000421 ReportRegisterState ("Function completed. Register state was:");
Sean Callananf5857a02010-07-31 01:32:05 +0000422
Sean Callanan14a97ff2010-11-04 01:51:38 +0000423 DoTakedown();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000424
Chris Lattner24943d22010-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 Ingham745ac7a2010-11-11 19:26:09 +0000451ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000452{
453 return eStateRunning;
454}
455
456void
457ThreadPlanCallFunction::DidPush ()
458{
Sean Callananc2c6f772010-10-26 00:31:56 +0000459//#define SINGLE_STEP_EXPRESSIONS
460
461#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner24943d22010-06-08 16:52:24 +0000462 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
463
464 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000465 m_subplan_sp->SetPrivate (true);
Sean Callananc2c6f772010-10-26 00:31:56 +0000466#endif
Chris Lattner24943d22010-06-08 16:52:24 +0000467}
468
469bool
470ThreadPlanCallFunction::WillStop ()
471{
472 return true;
473}
474
475bool
476ThreadPlanCallFunction::MischiefManaged ()
477{
478 if (IsPlanComplete())
479 {
Greg Claytone005f2c2010-11-06 01:53:30 +0000480 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000481
482 if (log)
483 log->Printf("Completed call function plan.");
484
485 ThreadPlan::MischiefManaged ();
486 return true;
487 }
488 else
489 {
490 return false;
491 }
492}
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000493
494void
495ThreadPlanCallFunction::SetBreakpoints ()
496{
Greg Claytonf4124de2012-02-21 00:09:25 +0000497 ProcessSP process_sp (m_thread.CalculateProcess());
498 if (process_sp)
499 {
500 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
501 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000502
Greg Claytonf4124de2012-02-21 00:09:25 +0000503 if (m_cxx_language_runtime)
504 m_cxx_language_runtime->SetExceptionBreakpoints();
505 if (m_objc_language_runtime)
506 m_objc_language_runtime->SetExceptionBreakpoints();
507 }
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000508}
509
510void
511ThreadPlanCallFunction::ClearBreakpoints ()
512{
Sean Callanan29756d42010-11-03 22:19:38 +0000513 if (m_cxx_language_runtime)
514 m_cxx_language_runtime->ClearExceptionBreakpoints();
515 if (m_objc_language_runtime)
516 m_objc_language_runtime->ClearExceptionBreakpoints();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000517}
Sean Callanan94fb5432010-11-03 19:36:28 +0000518
519bool
520ThreadPlanCallFunction::BreakpointsExplainStop()
521{
Greg Clayton989816b2011-05-14 01:50:35 +0000522 StopInfoSP stop_info_sp = GetPrivateStopReason();
Sean Callanan94fb5432010-11-03 19:36:28 +0000523
Sean Callanan29756d42010-11-03 22:19:38 +0000524 if (m_cxx_language_runtime &&
525 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
526 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000527
Sean Callanan29756d42010-11-03 22:19:38 +0000528 if (m_objc_language_runtime &&
529 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
530 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000531
532 return false;
533}