blob: 9e768641f05a25ea3ee5a979a86b7d551c0cdf51 [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);
Andrew Kaylorae0f59c2012-12-07 17:56:31 +000047 SetPrivate (true);
Jim Ingham1e58cef2012-04-13 20:38:13 +000048
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
58 TargetSP target_sp (thread.CalculateTarget());
59
Jim Inghama8d26eb2012-04-13 23:11:52 +000060 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham1e58cef2012-04-13 20:38:13 +000061
62 SetBreakpoints();
63
64 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
65 // If we can't read memory at the point of the process where we are planning to put our function, we're
66 // not going to get any further...
67 Error error;
68 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
69 if (!error.Success())
70 {
71 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +000072 log->Printf ("ThreadPlanCallFunction(%p): Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", this, m_function_sp);
Jim Ingham1e58cef2012-04-13 20:38:13 +000073 return false;
74 }
75
76 Module *exe_module = target_sp->GetExecutableModulePointer();
77
78 if (exe_module == NULL)
79 {
80 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +000081 log->Printf ("ThreadPlanCallFunction(%p): Can't execute code without an executable module.", this);
Jim Ingham1e58cef2012-04-13 20:38:13 +000082 return false;
83 }
84 else
85 {
86 ObjectFile *objectFile = exe_module->GetObjectFile();
87 if (!objectFile)
88 {
89 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +000090 log->Printf ("ThreadPlanCallFunction(%p): Could not find object file for module \"%s\".",
91 this, exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham1e58cef2012-04-13 20:38:13 +000092 return false;
93 }
94 m_start_addr = objectFile->GetEntryPointAddress();
95 if (!m_start_addr.IsValid())
96 {
97 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +000098 log->Printf ("ThreadPlanCallFunction(%p): Could not find entry point address for executable module \"%s\".",
99 this, exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham1e58cef2012-04-13 20:38:13 +0000100 return false;
101 }
102 }
103
104 start_load_addr = m_start_addr.GetLoadAddress (target_sp.get());
105
106 // Checkpoint the thread state so we can restore it later.
107 if (log && log->GetVerbose())
108 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
109
110 if (!thread.CheckpointThreadState (m_stored_thread_state))
111 {
112 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000113 log->Printf ("ThreadPlanCallFunction(%p): Setting up ThreadPlanCallFunction, failed to checkpoint thread state.", this);
Jim Ingham1e58cef2012-04-13 20:38:13 +0000114 return false;
115 }
Jim Ingham1e58cef2012-04-13 20:38:13 +0000116 function_load_addr = m_function_addr.GetLoadAddress (target_sp.get());
117
118 return true;
119}
Chris Lattner24943d22010-06-08 16:52:24 +0000120
121ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
122 Address &function,
Jim Ingham016ef882011-12-22 19:12:40 +0000123 const ClangASTType &return_type,
Greg Clayton989816b2011-05-14 01:50:35 +0000124 addr_t arg,
Chris Lattner24943d22010-06-08 16:52:24 +0000125 bool stop_other_threads,
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000126 bool discard_on_error,
Greg Clayton989816b2011-05-14 01:50:35 +0000127 addr_t *this_arg,
128 addr_t *cmd_arg) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000129 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer36a08102010-07-16 12:32:33 +0000130 m_valid (false),
131 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000132 m_function_addr (function),
Filipe Cabecinhas5ebd51f2012-09-11 18:11:07 +0000133 m_function_sp (0),
Jim Ingham016ef882011-12-22 19:12:40 +0000134 m_return_type (return_type),
Jim Inghamba560cc2011-11-01 02:46:54 +0000135 m_takedown_done (false),
Jim Ingham110b55f2012-05-11 18:43:38 +0000136 m_stop_address (LLDB_INVALID_ADDRESS),
137 m_discard_on_error (discard_on_error)
Chris Lattner24943d22010-06-08 16:52:24 +0000138{
Jim Ingham1e58cef2012-04-13 20:38:13 +0000139 lldb::addr_t start_load_addr;
140 ABI *abi;
141 lldb::addr_t function_load_addr;
Jim Ingham110b55f2012-05-11 18:43:38 +0000142 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Claytonf4124de2012-02-21 00:09:25 +0000143 return;
Chris Lattner24943d22010-06-08 16:52:24 +0000144
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000145 if (this_arg && cmd_arg)
146 {
147 if (!abi->PrepareTrivialCall (thread,
148 m_function_sp,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000149 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000150 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000151 this_arg,
152 cmd_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000153 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000154 return;
155 }
156 else if (this_arg)
157 {
158 if (!abi->PrepareTrivialCall (thread,
159 m_function_sp,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000160 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000161 start_load_addr,
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000162 this_arg,
Greg Clayton989816b2011-05-14 01:50:35 +0000163 &arg))
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000164 return;
165 }
166 else
167 {
168 if (!abi->PrepareTrivialCall (thread,
169 m_function_sp,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000170 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000171 start_load_addr,
172 &arg))
173 return;
174 }
175
176 ReportRegisterState ("Function call was set up. Register state was:");
177
178 m_valid = true;
179}
180
181
182ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
183 Address &function,
Jim Ingham016ef882011-12-22 19:12:40 +0000184 const ClangASTType &return_type,
Greg Clayton989816b2011-05-14 01:50:35 +0000185 bool stop_other_threads,
186 bool discard_on_error,
187 addr_t *arg1_ptr,
188 addr_t *arg2_ptr,
189 addr_t *arg3_ptr,
190 addr_t *arg4_ptr,
191 addr_t *arg5_ptr,
192 addr_t *arg6_ptr) :
193 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
194 m_valid (false),
195 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000196 m_function_addr (function),
Jim Ingham76b258d2012-11-26 23:52:18 +0000197 m_function_sp (0),
Jim Ingham016ef882011-12-22 19:12:40 +0000198 m_return_type (return_type),
Jim Ingham1e58cef2012-04-13 20:38:13 +0000199 m_takedown_done (false),
Jim Ingham76b258d2012-11-26 23:52:18 +0000200 m_stop_address (LLDB_INVALID_ADDRESS),
201 m_discard_on_error (discard_on_error)
Greg Clayton989816b2011-05-14 01:50:35 +0000202{
Jim Ingham1e58cef2012-04-13 20:38:13 +0000203 lldb::addr_t start_load_addr;
204 ABI *abi;
205 lldb::addr_t function_load_addr;
Jim Ingham110b55f2012-05-11 18:43:38 +0000206 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Claytonf4124de2012-02-21 00:09:25 +0000207 return;
208
Greg Clayton989816b2011-05-14 01:50:35 +0000209 if (!abi->PrepareTrivialCall (thread,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000210 m_function_sp,
211 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000212 start_load_addr,
213 arg1_ptr,
214 arg2_ptr,
215 arg3_ptr,
216 arg4_ptr,
217 arg5_ptr,
218 arg6_ptr))
219 {
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000220 return;
221 }
Chris Lattner24943d22010-06-08 16:52:24 +0000222
Jim Ingham2f6267f2011-01-22 01:27:23 +0000223 ReportRegisterState ("Function call was set up. Register state was:");
224
225 m_valid = true;
226}
227
228ThreadPlanCallFunction::~ThreadPlanCallFunction ()
229{
Jim Ingham038fa8e2012-05-10 01:35:39 +0000230 DoTakedown(true);
Jim Ingham2f6267f2011-01-22 01:27:23 +0000231}
232
233void
234ThreadPlanCallFunction::ReportRegisterState (const char *message)
235{
Greg Clayton628cead2011-05-19 03:54:16 +0000236 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callanan6dff8272010-11-08 03:49:50 +0000237 if (log)
238 {
Greg Clayton628cead2011-05-19 03:54:16 +0000239 StreamString strm;
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000240 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000241
242 log->PutCString(message);
243
Greg Clayton628cead2011-05-19 03:54:16 +0000244 RegisterValue reg_value;
245
246 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
247 reg_idx < num_registers;
248 ++reg_idx)
Sean Callanan6dff8272010-11-08 03:49:50 +0000249 {
Greg Clayton628cead2011-05-19 03:54:16 +0000250 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
251 if (reg_ctx->ReadRegister(reg_info, reg_value))
252 {
253 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
254 strm.EOL();
255 }
Sean Callanan6dff8272010-11-08 03:49:50 +0000256 }
Greg Clayton628cead2011-05-19 03:54:16 +0000257 log->PutCString(strm.GetData());
Sean Callanan6dff8272010-11-08 03:49:50 +0000258 }
Sean Callanan14a97ff2010-11-04 01:51:38 +0000259}
260
261void
Jim Ingham038fa8e2012-05-10 01:35:39 +0000262ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan14a97ff2010-11-04 01:51:38 +0000263{
Jim Inghama8d26eb2012-04-13 23:11:52 +0000264 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
265
266 if (!m_valid)
267 {
268 //Don't call DoTakedown if we were never valid to begin with.
269 if (log)
270 log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.", this);
271 return;
272 }
273
Jim Ingham2f6267f2011-01-22 01:27:23 +0000274 if (!m_takedown_done)
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000275 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000276 if (success)
Greg Clayton2f085c62011-05-15 01:25:55 +0000277 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000278 ProcessSP process_sp (m_thread.GetProcess());
279 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
280 if (abi && m_return_type.IsValid())
281 {
282 const bool persistent = false;
283 m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent);
284 }
Greg Clayton2f085c62011-05-15 01:25:55 +0000285 }
Jim Ingham2f6267f2011-01-22 01:27:23 +0000286 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000287 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 Ingham2f6267f2011-01-22 01:27:23 +0000288 m_takedown_done = true;
Jim Inghamba560cc2011-11-01 02:46:54 +0000289 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham2370a972011-05-17 01:10:11 +0000290 m_real_stop_info_sp = GetPrivateStopReason();
Jim Ingham76b258d2012-11-26 23:52:18 +0000291 m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state);
Jim Ingham038fa8e2012-05-10 01:35:39 +0000292 SetPlanComplete(success);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000293 ClearBreakpoints();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000294 if (log && log->GetVerbose())
295 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham78108e62011-01-26 19:13:09 +0000296
Jim Ingham2f6267f2011-01-22 01:27:23 +0000297 }
298 else
299 {
300 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000301 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 Ingham15dcb7c2011-01-20 02:03:18 +0000302 }
Chris Lattner24943d22010-06-08 16:52:24 +0000303}
304
305void
Jim Ingham6c9662e2011-01-18 01:58:06 +0000306ThreadPlanCallFunction::WillPop ()
307{
Jim Ingham038fa8e2012-05-10 01:35:39 +0000308 DoTakedown(true);
Jim Ingham6c9662e2011-01-18 01:58:06 +0000309}
310
311void
Greg Clayton989816b2011-05-14 01:50:35 +0000312ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +0000313{
Greg Clayton989816b2011-05-14 01:50:35 +0000314 if (level == eDescriptionLevelBrief)
Chris Lattner24943d22010-06-08 16:52:24 +0000315 {
316 s->Printf("Function call thread plan");
317 }
318 else
319 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000320 TargetSP target_sp (m_thread.CalculateTarget());
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000321 s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner24943d22010-06-08 16:52:24 +0000322 }
323}
324
325bool
326ThreadPlanCallFunction::ValidatePlan (Stream *error)
327{
328 if (!m_valid)
329 return false;
330
331 return true;
332}
333
334bool
335ThreadPlanCallFunction::PlanExplainsStop ()
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000336{
Jim Ingham2370a972011-05-17 01:10:11 +0000337 m_real_stop_info_sp = GetPrivateStopReason();
338
Jim Ingham988ddbc2010-10-26 00:27:45 +0000339 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
340 // we answer yes.
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000341 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000342 return true;
Sean Callananba8547d2010-10-19 22:24:06 +0000343
Sean Callanan94fb5432010-11-03 19:36:28 +0000344 // Check if the breakpoint is one of ours.
345
Jim Ingham038fa8e2012-05-10 01:35:39 +0000346 StopReason stop_reason;
347 if (!m_real_stop_info_sp)
348 stop_reason = eStopReasonNone;
349 else
350 stop_reason = m_real_stop_info_sp->GetStopReason();
351
352 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
Sean Callanan94fb5432010-11-03 19:36:28 +0000353 return true;
354
Jim Ingham988ddbc2010-10-26 00:27:45 +0000355 // 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 +0000356 if (!m_discard_on_error)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000357 return false;
358
359 // Otherwise, check the case where we stopped for an internal breakpoint, in that case, continue on.
360 // If it is not an internal breakpoint, consult OkayToDiscard.
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000361
Jim Ingham038fa8e2012-05-10 01:35:39 +0000362
363 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000364 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000365 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham2370a972011-05-17 01:10:11 +0000366 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Claytonf4124de2012-02-21 00:09:25 +0000367 BreakpointSiteSP bp_site_sp;
368 if (process_sp)
369 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham988ddbc2010-10-26 00:27:45 +0000370 if (bp_site_sp)
371 {
372 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
373 bool is_internal = true;
374 for (uint32_t i = 0; i < num_owners; i++)
375 {
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000376 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000377
378 if (!bp.IsInternal())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000379 {
380 is_internal = false;
381 break;
382 }
383 }
384 if (is_internal)
385 return false;
386 }
387
Jim Ingham110b55f2012-05-11 18:43:38 +0000388 if (m_discard_on_error)
389 {
390 DoTakedown(false);
391 return true;
392 }
393 else
394 return false;
Jim Ingham988ddbc2010-10-26 00:27:45 +0000395 }
396 else
397 {
398 // If the subplan is running, any crashes are attributable to us.
Jim Ingham78108e62011-01-26 19:13:09 +0000399 // If we want to discard the plan, then we say we explain the stop
400 // but if we are going to be discarded, let whoever is above us
401 // explain the stop.
Sean Callananb386d822012-08-09 00:50:26 +0000402 if (m_subplan_sp)
Jim Ingham038fa8e2012-05-10 01:35:39 +0000403 {
Jim Ingham110b55f2012-05-11 18:43:38 +0000404 if (m_discard_on_error)
Jim Ingham038fa8e2012-05-10 01:35:39 +0000405 {
406 DoTakedown(false);
407 return true;
408 }
409 else
410 return false;
411 }
412 else
413 return false;
Jim Ingham988ddbc2010-10-26 00:27:45 +0000414 }
Chris Lattner24943d22010-06-08 16:52:24 +0000415}
416
417bool
418ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
419{
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000420 if (IsPlanComplete() || PlanExplainsStop())
Chris Lattner24943d22010-06-08 16:52:24 +0000421 {
Jim Ingham2f6267f2011-01-22 01:27:23 +0000422 ReportRegisterState ("Function completed. Register state was:");
Sean Callananf5857a02010-07-31 01:32:05 +0000423
Jim Ingham038fa8e2012-05-10 01:35:39 +0000424 DoTakedown(true);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000425
Chris Lattner24943d22010-06-08 16:52:24 +0000426 return true;
427 }
428 else
429 {
430 return false;
431 }
432}
433
434bool
435ThreadPlanCallFunction::StopOthers ()
436{
437 return m_stop_other_threads;
438}
439
440void
441ThreadPlanCallFunction::SetStopOthers (bool new_value)
442{
443 if (m_subplan_sp)
444 {
445 ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get());
446 address_plan->SetStopOthers(new_value);
447 }
448 m_stop_other_threads = new_value;
449}
450
451StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000452ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000453{
454 return eStateRunning;
455}
456
457void
458ThreadPlanCallFunction::DidPush ()
459{
Sean Callananc2c6f772010-10-26 00:31:56 +0000460//#define SINGLE_STEP_EXPRESSIONS
461
Jim Ingham76b258d2012-11-26 23:52:18 +0000462 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
463 // Wait till the plan is pushed so we aren't changing the stop info till we're about to run.
464
465 GetThread().SetStopInfoToNothing();
466
Sean Callananc2c6f772010-10-26 00:31:56 +0000467#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner24943d22010-06-08 16:52:24 +0000468 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
469
470 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000471 m_subplan_sp->SetPrivate (true);
Sean Callananc2c6f772010-10-26 00:31:56 +0000472#endif
Chris Lattner24943d22010-06-08 16:52:24 +0000473}
474
475bool
476ThreadPlanCallFunction::WillStop ()
477{
478 return true;
479}
480
481bool
482ThreadPlanCallFunction::MischiefManaged ()
483{
484 if (IsPlanComplete())
485 {
Greg Claytone005f2c2010-11-06 01:53:30 +0000486 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000487
488 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000489 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this);
Chris Lattner24943d22010-06-08 16:52:24 +0000490
491 ThreadPlan::MischiefManaged ();
492 return true;
493 }
494 else
495 {
496 return false;
497 }
498}
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000499
500void
501ThreadPlanCallFunction::SetBreakpoints ()
502{
Greg Claytonf4124de2012-02-21 00:09:25 +0000503 ProcessSP process_sp (m_thread.CalculateProcess());
504 if (process_sp)
505 {
506 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
507 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000508
Greg Claytonf4124de2012-02-21 00:09:25 +0000509 if (m_cxx_language_runtime)
510 m_cxx_language_runtime->SetExceptionBreakpoints();
511 if (m_objc_language_runtime)
512 m_objc_language_runtime->SetExceptionBreakpoints();
513 }
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000514}
515
516void
517ThreadPlanCallFunction::ClearBreakpoints ()
518{
Sean Callanan29756d42010-11-03 22:19:38 +0000519 if (m_cxx_language_runtime)
520 m_cxx_language_runtime->ClearExceptionBreakpoints();
521 if (m_objc_language_runtime)
522 m_objc_language_runtime->ClearExceptionBreakpoints();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000523}
Sean Callanan94fb5432010-11-03 19:36:28 +0000524
525bool
526ThreadPlanCallFunction::BreakpointsExplainStop()
527{
Greg Clayton989816b2011-05-14 01:50:35 +0000528 StopInfoSP stop_info_sp = GetPrivateStopReason();
Sean Callanan94fb5432010-11-03 19:36:28 +0000529
Sean Callanan29756d42010-11-03 22:19:38 +0000530 if (m_cxx_language_runtime &&
531 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
532 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000533
Sean Callanan29756d42010-11-03 22:19:38 +0000534 if (m_objc_language_runtime &&
535 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
536 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000537
538 return false;
539}
Jim Ingham76b258d2012-11-26 23:52:18 +0000540
541bool
542ThreadPlanCallFunction::RestoreThreadState()
543{
544 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
545}
546