blob: 8e91e8b35d637de030ceedaad60992d528c4c175 [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//----------------------------------------------------------------------
Jim Ingham1e58cef2012-04-13 20:38:13 +000037bool
38ThreadPlanCallFunction::ConstructorSetup (Thread &thread,
Jim Ingham1e58cef2012-04-13 20:38:13 +000039 ABI *& abi,
40 lldb::addr_t &start_load_addr,
41 lldb::addr_t &function_load_addr)
42{
Jim Ingham1e58cef2012-04-13 20:38:13 +000043 SetIsMasterPlan (true);
Jim Ingham110b55f2012-05-11 18:43:38 +000044 SetOkayToDiscard (false);
Jim Ingham1e58cef2012-04-13 20:38:13 +000045
46 ProcessSP process_sp (thread.GetProcess());
47 if (!process_sp)
48 return false;
49
50 abi = process_sp->GetABI().get();
51
52 if (!abi)
53 return false;
54
55 TargetSP target_sp (thread.CalculateTarget());
56
Jim Inghama8d26eb2012-04-13 23:11:52 +000057 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham1e58cef2012-04-13 20:38:13 +000058
59 SetBreakpoints();
60
61 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
62 // If we can't read memory at the point of the process where we are planning to put our function, we're
63 // not going to get any further...
64 Error error;
65 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
66 if (!error.Success())
67 {
68 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +000069 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 +000070 return false;
71 }
72
73 Module *exe_module = target_sp->GetExecutableModulePointer();
74
75 if (exe_module == NULL)
76 {
77 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +000078 log->Printf ("ThreadPlanCallFunction(%p): Can't execute code without an executable module.", this);
Jim Ingham1e58cef2012-04-13 20:38:13 +000079 return false;
80 }
81 else
82 {
83 ObjectFile *objectFile = exe_module->GetObjectFile();
84 if (!objectFile)
85 {
86 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +000087 log->Printf ("ThreadPlanCallFunction(%p): Could not find object file for module \"%s\".",
88 this, exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham1e58cef2012-04-13 20:38:13 +000089 return false;
90 }
91 m_start_addr = objectFile->GetEntryPointAddress();
92 if (!m_start_addr.IsValid())
93 {
94 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +000095 log->Printf ("ThreadPlanCallFunction(%p): Could not find entry point address for executable module \"%s\".",
96 this, exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham1e58cef2012-04-13 20:38:13 +000097 return false;
98 }
99 }
100
101 start_load_addr = m_start_addr.GetLoadAddress (target_sp.get());
102
103 // Checkpoint the thread state so we can restore it later.
104 if (log && log->GetVerbose())
105 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
106
107 if (!thread.CheckpointThreadState (m_stored_thread_state))
108 {
109 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000110 log->Printf ("ThreadPlanCallFunction(%p): Setting up ThreadPlanCallFunction, failed to checkpoint thread state.", this);
Jim Ingham1e58cef2012-04-13 20:38:13 +0000111 return false;
112 }
113 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
114 thread.SetStopInfoToNothing();
115
116 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),
Peter Collingbourneabb53e52011-06-03 20:41:09 +0000133 m_function_sp (NULL),
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),
Peter Collingbourneabb53e52011-06-03 20:41:09 +0000197 m_function_sp(NULL),
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),
200 m_stop_address (LLDB_INVALID_ADDRESS)
Greg Clayton989816b2011-05-14 01:50:35 +0000201{
Jim Ingham1e58cef2012-04-13 20:38:13 +0000202 lldb::addr_t start_load_addr;
203 ABI *abi;
204 lldb::addr_t function_load_addr;
Jim Ingham110b55f2012-05-11 18:43:38 +0000205 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Claytonf4124de2012-02-21 00:09:25 +0000206 return;
207
Greg Clayton989816b2011-05-14 01:50:35 +0000208 if (!abi->PrepareTrivialCall (thread,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000209 m_function_sp,
210 function_load_addr,
Greg Clayton989816b2011-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 Clayton61d4f7a2011-05-12 02:14:56 +0000219 return;
220 }
Chris Lattner24943d22010-06-08 16:52:24 +0000221
Jim Ingham2f6267f2011-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 Ingham038fa8e2012-05-10 01:35:39 +0000229 DoTakedown(true);
Jim Ingham2f6267f2011-01-22 01:27:23 +0000230}
231
232void
233ThreadPlanCallFunction::ReportRegisterState (const char *message)
234{
Greg Clayton628cead2011-05-19 03:54:16 +0000235 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callanan6dff8272010-11-08 03:49:50 +0000236 if (log)
237 {
Greg Clayton628cead2011-05-19 03:54:16 +0000238 StreamString strm;
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000239 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000240
241 log->PutCString(message);
242
Greg Clayton628cead2011-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 Callanan6dff8272010-11-08 03:49:50 +0000248 {
Greg Clayton628cead2011-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 Callanan6dff8272010-11-08 03:49:50 +0000255 }
Greg Clayton628cead2011-05-19 03:54:16 +0000256 log->PutCString(strm.GetData());
Sean Callanan6dff8272010-11-08 03:49:50 +0000257 }
Sean Callanan14a97ff2010-11-04 01:51:38 +0000258}
259
260void
Jim Ingham038fa8e2012-05-10 01:35:39 +0000261ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan14a97ff2010-11-04 01:51:38 +0000262{
Jim Inghama8d26eb2012-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 Ingham2f6267f2011-01-22 01:27:23 +0000273 if (!m_takedown_done)
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000274 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000275 if (success)
Greg Clayton2f085c62011-05-15 01:25:55 +0000276 {
Jim Ingham038fa8e2012-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 Clayton2f085c62011-05-15 01:25:55 +0000284 }
Jim Ingham2f6267f2011-01-22 01:27:23 +0000285 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000286 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 +0000287 m_takedown_done = true;
Jim Inghamba560cc2011-11-01 02:46:54 +0000288 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham2370a972011-05-17 01:10:11 +0000289 m_real_stop_info_sp = GetPrivateStopReason();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000290 m_thread.RestoreThreadStateFromCheckpoint(m_stored_thread_state);
Jim Ingham038fa8e2012-05-10 01:35:39 +0000291 SetPlanComplete(success);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000292 ClearBreakpoints();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000293 if (log && log->GetVerbose())
294 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham78108e62011-01-26 19:13:09 +0000295
Jim Ingham2f6267f2011-01-22 01:27:23 +0000296 }
297 else
298 {
299 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000300 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 +0000301 }
Chris Lattner24943d22010-06-08 16:52:24 +0000302}
303
304void
Jim Ingham6c9662e2011-01-18 01:58:06 +0000305ThreadPlanCallFunction::WillPop ()
306{
Jim Ingham038fa8e2012-05-10 01:35:39 +0000307 DoTakedown(true);
Jim Ingham6c9662e2011-01-18 01:58:06 +0000308}
309
310void
Greg Clayton989816b2011-05-14 01:50:35 +0000311ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +0000312{
Greg Clayton989816b2011-05-14 01:50:35 +0000313 if (level == eDescriptionLevelBrief)
Chris Lattner24943d22010-06-08 16:52:24 +0000314 {
315 s->Printf("Function call thread plan");
316 }
317 else
318 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000319 TargetSP target_sp (m_thread.CalculateTarget());
320 s->Printf("Thread plan to call 0x%llx", m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner24943d22010-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 Callanan07f3d8d2010-11-03 01:37:52 +0000335{
Jim Ingham2370a972011-05-17 01:10:11 +0000336 m_real_stop_info_sp = GetPrivateStopReason();
337
Jim Ingham988ddbc2010-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 Granata4c3fb4b2011-07-19 18:03:25 +0000340 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000341 return true;
Sean Callananba8547d2010-10-19 22:24:06 +0000342
Sean Callanan94fb5432010-11-03 19:36:28 +0000343 // Check if the breakpoint is one of ours.
344
Jim Ingham038fa8e2012-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 Callanan94fb5432010-11-03 19:36:28 +0000352 return true;
353
Jim Ingham988ddbc2010-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 Ingham110b55f2012-05-11 18:43:38 +0000355 if (!m_discard_on_error)
Jim Ingham988ddbc2010-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 Callanan07f3d8d2010-11-03 01:37:52 +0000360
Jim Ingham038fa8e2012-05-10 01:35:39 +0000361
362 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000363 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000364 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham2370a972011-05-17 01:10:11 +0000365 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Claytonf4124de2012-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 Ingham988ddbc2010-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 Callanan07f3d8d2010-11-03 01:37:52 +0000375 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000376
377 if (!bp.IsInternal())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000378 {
379 is_internal = false;
380 break;
381 }
382 }
383 if (is_internal)
384 return false;
385 }
386
Jim Ingham110b55f2012-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 Ingham988ddbc2010-10-26 00:27:45 +0000394 }
395 else
396 {
397 // If the subplan is running, any crashes are attributable to us.
Jim Ingham78108e62011-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.
Jim Ingham038fa8e2012-05-10 01:35:39 +0000401 if (m_subplan_sp != NULL)
402 {
Jim Ingham110b55f2012-05-11 18:43:38 +0000403 if (m_discard_on_error)
Jim Ingham038fa8e2012-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 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
Jim Ingham038fa8e2012-05-10 01:35:39 +0000423 DoTakedown(true);
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)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000483 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this);
Chris Lattner24943d22010-06-08 16:52:24 +0000484
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}