blob: 1f4edb406e928b5bb613e94ed4ce0bd7d897dbda [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,
Jim Inghamb7940202013-01-15 02:47:48 +0000126 bool unwind_on_error,
127 bool ignore_breakpoints,
Greg Clayton989816b2011-05-14 01:50:35 +0000128 addr_t *this_arg,
129 addr_t *cmd_arg) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000130 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer36a08102010-07-16 12:32:33 +0000131 m_valid (false),
132 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000133 m_function_addr (function),
Filipe Cabecinhas5ebd51f2012-09-11 18:11:07 +0000134 m_function_sp (0),
Jim Ingham016ef882011-12-22 19:12:40 +0000135 m_return_type (return_type),
Jim Inghamba560cc2011-11-01 02:46:54 +0000136 m_takedown_done (false),
Jim Ingham110b55f2012-05-11 18:43:38 +0000137 m_stop_address (LLDB_INVALID_ADDRESS),
Jim Inghamb7940202013-01-15 02:47:48 +0000138 m_unwind_on_error (unwind_on_error),
139 m_ignore_breakpoints (ignore_breakpoints)
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,
Jim Inghamb7940202013-01-15 02:47:48 +0000188 bool unwind_on_error,
189 bool ignore_breakpoints,
Greg Clayton989816b2011-05-14 01:50:35 +0000190 addr_t *arg1_ptr,
191 addr_t *arg2_ptr,
192 addr_t *arg3_ptr,
193 addr_t *arg4_ptr,
194 addr_t *arg5_ptr,
195 addr_t *arg6_ptr) :
196 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
197 m_valid (false),
198 m_stop_other_threads (stop_other_threads),
Jim Ingham574c3d62011-08-12 23:34:31 +0000199 m_function_addr (function),
Jim Ingham76b258d2012-11-26 23:52:18 +0000200 m_function_sp (0),
Jim Ingham016ef882011-12-22 19:12:40 +0000201 m_return_type (return_type),
Jim Ingham1e58cef2012-04-13 20:38:13 +0000202 m_takedown_done (false),
Jim Ingham76b258d2012-11-26 23:52:18 +0000203 m_stop_address (LLDB_INVALID_ADDRESS),
Jim Inghamb7940202013-01-15 02:47:48 +0000204 m_unwind_on_error (unwind_on_error),
205 m_ignore_breakpoints (ignore_breakpoints)
Greg Clayton989816b2011-05-14 01:50:35 +0000206{
Jim Ingham1e58cef2012-04-13 20:38:13 +0000207 lldb::addr_t start_load_addr;
208 ABI *abi;
209 lldb::addr_t function_load_addr;
Jim Ingham110b55f2012-05-11 18:43:38 +0000210 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Claytonf4124de2012-02-21 00:09:25 +0000211 return;
212
Greg Clayton989816b2011-05-14 01:50:35 +0000213 if (!abi->PrepareTrivialCall (thread,
Jim Ingham1e58cef2012-04-13 20:38:13 +0000214 m_function_sp,
215 function_load_addr,
Greg Clayton989816b2011-05-14 01:50:35 +0000216 start_load_addr,
217 arg1_ptr,
218 arg2_ptr,
219 arg3_ptr,
220 arg4_ptr,
221 arg5_ptr,
222 arg6_ptr))
223 {
Greg Clayton61d4f7a2011-05-12 02:14:56 +0000224 return;
225 }
Chris Lattner24943d22010-06-08 16:52:24 +0000226
Jim Ingham2f6267f2011-01-22 01:27:23 +0000227 ReportRegisterState ("Function call was set up. Register state was:");
228
229 m_valid = true;
230}
231
232ThreadPlanCallFunction::~ThreadPlanCallFunction ()
233{
Jim Ingham038fa8e2012-05-10 01:35:39 +0000234 DoTakedown(true);
Jim Ingham2f6267f2011-01-22 01:27:23 +0000235}
236
237void
238ThreadPlanCallFunction::ReportRegisterState (const char *message)
239{
Greg Clayton628cead2011-05-19 03:54:16 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callanan6dff8272010-11-08 03:49:50 +0000241 if (log)
242 {
Greg Clayton628cead2011-05-19 03:54:16 +0000243 StreamString strm;
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000244 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000245
246 log->PutCString(message);
247
Greg Clayton628cead2011-05-19 03:54:16 +0000248 RegisterValue reg_value;
249
250 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
251 reg_idx < num_registers;
252 ++reg_idx)
Sean Callanan6dff8272010-11-08 03:49:50 +0000253 {
Greg Clayton628cead2011-05-19 03:54:16 +0000254 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
255 if (reg_ctx->ReadRegister(reg_info, reg_value))
256 {
257 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
258 strm.EOL();
259 }
Sean Callanan6dff8272010-11-08 03:49:50 +0000260 }
Greg Clayton628cead2011-05-19 03:54:16 +0000261 log->PutCString(strm.GetData());
Sean Callanan6dff8272010-11-08 03:49:50 +0000262 }
Sean Callanan14a97ff2010-11-04 01:51:38 +0000263}
264
265void
Jim Ingham038fa8e2012-05-10 01:35:39 +0000266ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan14a97ff2010-11-04 01:51:38 +0000267{
Jim Inghama8d26eb2012-04-13 23:11:52 +0000268 LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
269
270 if (!m_valid)
271 {
272 //Don't call DoTakedown if we were never valid to begin with.
273 if (log)
274 log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.", this);
275 return;
276 }
277
Jim Ingham2f6267f2011-01-22 01:27:23 +0000278 if (!m_takedown_done)
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000279 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000280 if (success)
Greg Clayton2f085c62011-05-15 01:25:55 +0000281 {
Jim Ingham038fa8e2012-05-10 01:35:39 +0000282 ProcessSP process_sp (m_thread.GetProcess());
283 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
284 if (abi && m_return_type.IsValid())
285 {
286 const bool persistent = false;
287 m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent);
288 }
Greg Clayton2f085c62011-05-15 01:25:55 +0000289 }
Jim Ingham2f6267f2011-01-22 01:27:23 +0000290 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000291 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 +0000292 m_takedown_done = true;
Jim Inghamba560cc2011-11-01 02:46:54 +0000293 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham2370a972011-05-17 01:10:11 +0000294 m_real_stop_info_sp = GetPrivateStopReason();
Jim Ingham76b258d2012-11-26 23:52:18 +0000295 m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state);
Jim Ingham038fa8e2012-05-10 01:35:39 +0000296 SetPlanComplete(success);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000297 ClearBreakpoints();
Jim Ingham2f6267f2011-01-22 01:27:23 +0000298 if (log && log->GetVerbose())
299 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham78108e62011-01-26 19:13:09 +0000300
Jim Ingham2f6267f2011-01-22 01:27:23 +0000301 }
302 else
303 {
304 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000305 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 +0000306 }
Chris Lattner24943d22010-06-08 16:52:24 +0000307}
308
309void
Jim Ingham6c9662e2011-01-18 01:58:06 +0000310ThreadPlanCallFunction::WillPop ()
311{
Jim Ingham038fa8e2012-05-10 01:35:39 +0000312 DoTakedown(true);
Jim Ingham6c9662e2011-01-18 01:58:06 +0000313}
314
315void
Greg Clayton989816b2011-05-14 01:50:35 +0000316ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +0000317{
Greg Clayton989816b2011-05-14 01:50:35 +0000318 if (level == eDescriptionLevelBrief)
Chris Lattner24943d22010-06-08 16:52:24 +0000319 {
320 s->Printf("Function call thread plan");
321 }
322 else
323 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000324 TargetSP target_sp (m_thread.CalculateTarget());
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000325 s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner24943d22010-06-08 16:52:24 +0000326 }
327}
328
329bool
330ThreadPlanCallFunction::ValidatePlan (Stream *error)
331{
332 if (!m_valid)
333 return false;
334
335 return true;
336}
337
338bool
339ThreadPlanCallFunction::PlanExplainsStop ()
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000340{
Jim Ingham2370a972011-05-17 01:10:11 +0000341 m_real_stop_info_sp = GetPrivateStopReason();
342
Jim Ingham988ddbc2010-10-26 00:27:45 +0000343 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
344 // we answer yes.
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000345 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop())
Jim Inghamb7940202013-01-15 02:47:48 +0000346 {
347 SetPlanComplete();
Jim Ingham988ddbc2010-10-26 00:27:45 +0000348 return true;
Jim Inghamb7940202013-01-15 02:47:48 +0000349 }
Sean Callananba8547d2010-10-19 22:24:06 +0000350
Sean Callanan94fb5432010-11-03 19:36:28 +0000351 // Check if the breakpoint is one of ours.
352
Jim Ingham038fa8e2012-05-10 01:35:39 +0000353 StopReason stop_reason;
354 if (!m_real_stop_info_sp)
355 stop_reason = eStopReasonNone;
356 else
357 stop_reason = m_real_stop_info_sp->GetStopReason();
358
359 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
Sean Callanan94fb5432010-11-03 19:36:28 +0000360 return true;
361
Jim Ingham988ddbc2010-10-26 00:27:45 +0000362 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
Jim Inghamb7940202013-01-15 02:47:48 +0000363 if (!m_unwind_on_error)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000364 return false;
365
366 // Otherwise, check the case where we stopped for an internal breakpoint, in that case, continue on.
367 // If it is not an internal breakpoint, consult OkayToDiscard.
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000368
Jim Ingham038fa8e2012-05-10 01:35:39 +0000369
370 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham988ddbc2010-10-26 00:27:45 +0000371 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000372 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham2370a972011-05-17 01:10:11 +0000373 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Claytonf4124de2012-02-21 00:09:25 +0000374 BreakpointSiteSP bp_site_sp;
375 if (process_sp)
376 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham988ddbc2010-10-26 00:27:45 +0000377 if (bp_site_sp)
378 {
379 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
380 bool is_internal = true;
381 for (uint32_t i = 0; i < num_owners; i++)
382 {
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000383 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000384
385 if (!bp.IsInternal())
Jim Ingham988ddbc2010-10-26 00:27:45 +0000386 {
387 is_internal = false;
388 break;
389 }
390 }
391 if (is_internal)
392 return false;
393 }
394
Jim Inghamb7940202013-01-15 02:47:48 +0000395 if (m_ignore_breakpoints)
Jim Ingham110b55f2012-05-11 18:43:38 +0000396 {
397 DoTakedown(false);
398 return true;
399 }
400 else
401 return false;
Jim Ingham988ddbc2010-10-26 00:27:45 +0000402 }
403 else
404 {
405 // If the subplan is running, any crashes are attributable to us.
Jim Ingham78108e62011-01-26 19:13:09 +0000406 // If we want to discard the plan, then we say we explain the stop
407 // but if we are going to be discarded, let whoever is above us
408 // explain the stop.
Jim Inghamb7940202013-01-15 02:47:48 +0000409 SetPlanComplete(false);
Sean Callananb386d822012-08-09 00:50:26 +0000410 if (m_subplan_sp)
Jim Ingham038fa8e2012-05-10 01:35:39 +0000411 {
Jim Inghamb7940202013-01-15 02:47:48 +0000412 if (m_unwind_on_error)
Jim Ingham038fa8e2012-05-10 01:35:39 +0000413 {
414 DoTakedown(false);
415 return true;
416 }
417 else
418 return false;
419 }
420 else
421 return false;
Jim Ingham988ddbc2010-10-26 00:27:45 +0000422 }
Chris Lattner24943d22010-06-08 16:52:24 +0000423}
424
425bool
426ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
427{
Jim Inghamb7940202013-01-15 02:47:48 +0000428 // We do some computation in PlanExplainsStop that may or may not set the plan as complete.
429 // We need to do that here to make sure our state is correct.
430 PlanExplainsStop();
431
432 if (IsPlanComplete())
Chris Lattner24943d22010-06-08 16:52:24 +0000433 {
Jim Ingham2f6267f2011-01-22 01:27:23 +0000434 ReportRegisterState ("Function completed. Register state was:");
Sean Callananf5857a02010-07-31 01:32:05 +0000435
Jim Ingham038fa8e2012-05-10 01:35:39 +0000436 DoTakedown(true);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000437
Chris Lattner24943d22010-06-08 16:52:24 +0000438 return true;
439 }
440 else
441 {
442 return false;
443 }
444}
445
446bool
447ThreadPlanCallFunction::StopOthers ()
448{
449 return m_stop_other_threads;
450}
451
452void
453ThreadPlanCallFunction::SetStopOthers (bool new_value)
454{
455 if (m_subplan_sp)
456 {
457 ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get());
458 address_plan->SetStopOthers(new_value);
459 }
460 m_stop_other_threads = new_value;
461}
462
463StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000464ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000465{
466 return eStateRunning;
467}
468
469void
470ThreadPlanCallFunction::DidPush ()
471{
Sean Callananc2c6f772010-10-26 00:31:56 +0000472//#define SINGLE_STEP_EXPRESSIONS
473
Jim Ingham76b258d2012-11-26 23:52:18 +0000474 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
475 // Wait till the plan is pushed so we aren't changing the stop info till we're about to run.
476
477 GetThread().SetStopInfoToNothing();
478
Sean Callananc2c6f772010-10-26 00:31:56 +0000479#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner24943d22010-06-08 16:52:24 +0000480 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
481
482 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000483 m_subplan_sp->SetPrivate (true);
Sean Callananc2c6f772010-10-26 00:31:56 +0000484#endif
Chris Lattner24943d22010-06-08 16:52:24 +0000485}
486
487bool
488ThreadPlanCallFunction::WillStop ()
489{
490 return true;
491}
492
493bool
494ThreadPlanCallFunction::MischiefManaged ()
495{
Jim Inghamb7940202013-01-15 02:47:48 +0000496 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
497
498 if (PlanExplainsStop() && !IsPlanComplete())
499 {
500 if (log)
501 log->Printf ("ThreadPlanCallFunction: Got into MischiefManaged, explained stop but was not complete.");
502 }
503
Chris Lattner24943d22010-06-08 16:52:24 +0000504 if (IsPlanComplete())
505 {
Chris Lattner24943d22010-06-08 16:52:24 +0000506 if (log)
Jim Inghama8d26eb2012-04-13 23:11:52 +0000507 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this);
Chris Lattner24943d22010-06-08 16:52:24 +0000508
509 ThreadPlan::MischiefManaged ();
510 return true;
511 }
512 else
513 {
514 return false;
515 }
516}
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000517
518void
519ThreadPlanCallFunction::SetBreakpoints ()
520{
Greg Claytonf4124de2012-02-21 00:09:25 +0000521 ProcessSP process_sp (m_thread.CalculateProcess());
522 if (process_sp)
523 {
524 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
525 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000526
Greg Claytonf4124de2012-02-21 00:09:25 +0000527 if (m_cxx_language_runtime)
528 m_cxx_language_runtime->SetExceptionBreakpoints();
529 if (m_objc_language_runtime)
530 m_objc_language_runtime->SetExceptionBreakpoints();
531 }
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000532}
533
534void
535ThreadPlanCallFunction::ClearBreakpoints ()
536{
Sean Callanan29756d42010-11-03 22:19:38 +0000537 if (m_cxx_language_runtime)
538 m_cxx_language_runtime->ClearExceptionBreakpoints();
539 if (m_objc_language_runtime)
540 m_objc_language_runtime->ClearExceptionBreakpoints();
Sean Callanan07f3d8d2010-11-03 01:37:52 +0000541}
Sean Callanan94fb5432010-11-03 19:36:28 +0000542
543bool
544ThreadPlanCallFunction::BreakpointsExplainStop()
545{
Greg Clayton989816b2011-05-14 01:50:35 +0000546 StopInfoSP stop_info_sp = GetPrivateStopReason();
Sean Callanan94fb5432010-11-03 19:36:28 +0000547
Jim Inghamb7940202013-01-15 02:47:48 +0000548 if ((m_cxx_language_runtime &&
549 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
550 ||(m_objc_language_runtime &&
551 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)))
552 {
553 SetPlanComplete(false);
Sean Callanan29756d42010-11-03 22:19:38 +0000554 return true;
Jim Inghamb7940202013-01-15 02:47:48 +0000555 }
Sean Callanan94fb5432010-11-03 19:36:28 +0000556
Jim Inghamb7940202013-01-15 02:47:48 +0000557 // Finally, if the process is set to ignore breakpoints in function calls,
558 // then we explain all breakpoint stops.
559
560 if (m_ignore_breakpoints)
Sean Callanan29756d42010-11-03 22:19:38 +0000561 return true;
Sean Callanan94fb5432010-11-03 19:36:28 +0000562
563 return false;
564}
Jim Ingham76b258d2012-11-26 23:52:18 +0000565
566bool
567ThreadPlanCallFunction::RestoreThreadState()
568{
569 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
570}
571