blob: 01ca1267dd92bc1020afbc624ea275f567257c7d [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- 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
Chris Lattner30fdc8d2010-06-08 16:52:2410// C Includes
11// C++ Includes
12// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:2413// Project includes
Eugene Zelenkoe65b2cf2015-12-15 01:33:1914#include "lldb/Target/ThreadPlanCallFunction.h"
Jim Ingham40d871f2010-10-26 00:27:4515#include "lldb/Breakpoint/Breakpoint.h"
16#include "lldb/Breakpoint/BreakpointLocation.h"
Chris Lattner30fdc8d2010-06-08 16:52:2417#include "lldb/Core/Address.h"
18#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:0619#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:2420#include "lldb/Core/Stream.h"
Greg Clayton1f746072012-08-29 21:13:0621#include "lldb/Symbol/ObjectFile.h"
Zachary Turner32abc6e2015-03-03 19:23:0922#include "lldb/Target/ABI.h"
Sean Callananf2115102010-11-03 22:19:3823#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:2424#include "lldb/Target/Process.h"
25#include "lldb/Target/RegisterContext.h"
Jim Ingham40d871f2010-10-26 00:27:4526#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:2427#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 Ingham0092c8e2012-04-13 20:38:1337bool
38ThreadPlanCallFunction::ConstructorSetup (Thread &thread,
Jim Ingham0092c8e2012-04-13 20:38:1339 ABI *& abi,
40 lldb::addr_t &start_load_addr,
41 lldb::addr_t &function_load_addr)
42{
Jim Ingham0092c8e2012-04-13 20:38:1343 SetIsMasterPlan (true);
Jim Ingham923886c2012-05-11 18:43:3844 SetOkayToDiscard (false);
Andrew Kaylor327c2672012-12-07 17:56:3145 SetPrivate (true);
Jim Ingham0092c8e2012-04-13 20:38:1346
47 ProcessSP process_sp (thread.GetProcess());
48 if (!process_sp)
49 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1050
Jim Ingham0092c8e2012-04-13 20:38:1351 abi = process_sp->GetABI().get();
Saleem Abdulrasool324a1032014-04-04 04:06:1052
Jim Ingham0092c8e2012-04-13 20:38:1353 if (!abi)
54 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1055
Greg Clayton5160ce52013-03-27 23:08:4056 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:1057
Jim Ingham0092c8e2012-04-13 20:38:1358 SetBreakpoints();
Saleem Abdulrasool324a1032014-04-04 04:06:1059
Jim Ingham0092c8e2012-04-13 20:38:1360 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
61 // If we can't read memory at the point of the process where we are planning to put our function, we're
62 // not going to get any further...
63 Error error;
64 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
65 if (!error.Success())
66 {
Jim Inghamea06f3b2013-03-28 00:04:0567 m_constructor_errors.Printf ("Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", m_function_sp);
Jim Ingham0092c8e2012-04-13 20:38:1368 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:1069 log->Printf ("ThreadPlanCallFunction(%p): %s.",
70 static_cast<void*>(this),
71 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1372 return false;
73 }
Saleem Abdulrasool324a1032014-04-04 04:06:1074
Jim Ingham6fbc48b2013-11-07 00:11:4775 Module *exe_module = GetTarget().GetExecutableModulePointer();
Jim Ingham0092c8e2012-04-13 20:38:1376
Eugene Zelenkoe65b2cf2015-12-15 01:33:1977 if (exe_module == nullptr)
Jim Ingham0092c8e2012-04-13 20:38:1378 {
Jim Inghamea06f3b2013-03-28 00:04:0579 m_constructor_errors.Printf ("Can't execute code without an executable module.");
Jim Ingham0092c8e2012-04-13 20:38:1380 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:1081 log->Printf ("ThreadPlanCallFunction(%p): %s.",
82 static_cast<void*>(this),
83 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1384 return false;
85 }
86 else
87 {
88 ObjectFile *objectFile = exe_module->GetObjectFile();
89 if (!objectFile)
90 {
Jim Inghamea06f3b2013-03-28 00:04:0591 m_constructor_errors.Printf ("Could not find object file for module \"%s\".",
92 exe_module->GetFileSpec().GetFilename().AsCString());
93
Jim Ingham0092c8e2012-04-13 20:38:1394 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:1095 log->Printf ("ThreadPlanCallFunction(%p): %s.",
96 static_cast<void*>(this),
97 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1398 return false;
99 }
Saleem Abdulrasool324a1032014-04-04 04:06:10100
Jim Ingham0092c8e2012-04-13 20:38:13101 m_start_addr = objectFile->GetEntryPointAddress();
102 if (!m_start_addr.IsValid())
103 {
Jim Inghamea06f3b2013-03-28 00:04:05104 m_constructor_errors.Printf ("Could not find entry point address for executable module \"%s\".",
105 exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham0092c8e2012-04-13 20:38:13106 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10107 log->Printf ("ThreadPlanCallFunction(%p): %s.",
108 static_cast<void*>(this),
109 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:13110 return false;
111 }
112 }
Saleem Abdulrasool324a1032014-04-04 04:06:10113
Jim Ingham6fbc48b2013-11-07 00:11:47114 start_load_addr = m_start_addr.GetLoadAddress (&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:10115
Jim Ingham0092c8e2012-04-13 20:38:13116 // Checkpoint the thread state so we can restore it later.
117 if (log && log->GetVerbose())
118 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
119
120 if (!thread.CheckpointThreadState (m_stored_thread_state))
121 {
Jim Inghamea06f3b2013-03-28 00:04:05122 m_constructor_errors.Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
Jim Ingham0092c8e2012-04-13 20:38:13123 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10124 log->Printf ("ThreadPlanCallFunction(%p): %s.",
125 static_cast<void*>(this),
126 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:13127 return false;
128 }
Jim Ingham6fbc48b2013-11-07 00:11:47129 function_load_addr = m_function_addr.GetLoadAddress (&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:10130
Jim Ingham0092c8e2012-04-13 20:38:13131 return true;
132}
Chris Lattner30fdc8d2010-06-08 16:52:24133
134ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
Matt Kopec00049b82013-02-27 20:13:38135 const Address &function,
Greg Claytona1e5dc82015-08-11 22:53:00136 const CompilerType &return_type,
Sean Callanana464f3d2013-11-08 01:14:26137 llvm::ArrayRef<addr_t> args,
138 const EvaluateExpressionOptions &options) :
Jim Inghamb01e742a2010-06-19 04:45:32139 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer1ee0d4f2010-07-16 12:32:33140 m_valid (false),
Jim Ingham6fbc48b2013-11-07 00:11:47141 m_stop_other_threads (options.GetStopOthers()),
142 m_unwind_on_error (options.DoesUnwindOnError()),
143 m_ignore_breakpoints (options.DoesIgnoreBreakpoints()),
144 m_debug_execution (options.GetDebug()),
145 m_trap_exceptions (options.GetTrapExceptions()),
Jim Ingham16e0c682011-08-12 23:34:31146 m_function_addr (function),
Filipe Cabecinhasb4cb0be2012-09-11 18:11:07147 m_function_sp (0),
Jim Inghamce553d82011-11-01 02:46:54148 m_takedown_done (false),
Jim Ingham6fbc48b2013-11-07 00:11:47149 m_should_clear_objc_exception_bp(false),
150 m_should_clear_cxx_exception_bp (false),
Ewan Crawford90ff7912015-07-14 10:56:58151 m_stop_address (LLDB_INVALID_ADDRESS),
152 m_return_type (return_type)
Chris Lattner30fdc8d2010-06-08 16:52:24153{
Ewan Crawford90ff7912015-07-14 10:56:58154 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
155 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
156 ABI *abi = nullptr;
157
Jim Ingham923886c2012-05-11 18:43:38158 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Clayton1ac04c32012-02-21 00:09:25159 return;
Saleem Abdulrasool324a1032014-04-04 04:06:10160
Sean Callanana464f3d2013-11-08 01:14:26161 if (!abi->PrepareTrivialCall(thread,
162 m_function_sp,
163 function_load_addr,
164 start_load_addr,
165 args))
Greg Clayton1ac04c32012-02-21 00:09:25166 return;
Saleem Abdulrasool324a1032014-04-04 04:06:10167
Jim Ingham9da36832011-01-22 01:27:23168 ReportRegisterState ("Function call was set up. Register state was:");
Saleem Abdulrasool324a1032014-04-04 04:06:10169
Jim Ingham9da36832011-01-22 01:27:23170 m_valid = true;
171}
172
Ewan Crawford90ff7912015-07-14 10:56:58173ThreadPlanCallFunction::ThreadPlanCallFunction(Thread &thread,
174 const Address &function,
175 const EvaluateExpressionOptions &options) :
176 ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
177 m_valid(false),
178 m_stop_other_threads(options.GetStopOthers()),
179 m_unwind_on_error(options.DoesUnwindOnError()),
180 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
181 m_debug_execution(options.GetDebug()),
182 m_trap_exceptions(options.GetTrapExceptions()),
183 m_function_addr(function),
184 m_function_sp(0),
185 m_takedown_done(false),
186 m_should_clear_objc_exception_bp(false),
187 m_should_clear_cxx_exception_bp(false),
188 m_stop_address(LLDB_INVALID_ADDRESS),
Greg Claytona1e5dc82015-08-11 22:53:00189 m_return_type(CompilerType())
Ewan Crawford90ff7912015-07-14 10:56:58190{
Ewan Crawford90ff7912015-07-14 10:56:58191}
192
Jim Ingham9da36832011-01-22 01:27:23193ThreadPlanCallFunction::~ThreadPlanCallFunction ()
194{
Jim Ingham0161b492013-02-09 01:29:05195 DoTakedown(PlanSucceeded());
Jim Ingham9da36832011-01-22 01:27:23196}
197
198void
199ThreadPlanCallFunction::ReportRegisterState (const char *message)
200{
Greg Clayton5160ce52013-03-27 23:08:40201 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callananece96492010-11-08 03:49:50202 if (log)
203 {
Greg Claytonaf247d72011-05-19 03:54:16204 StreamString strm;
Greg Clayton5ccbd292011-01-06 22:15:06205 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham9da36832011-01-22 01:27:23206
207 log->PutCString(message);
208
Greg Claytonaf247d72011-05-19 03:54:16209 RegisterValue reg_value;
210
211 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
212 reg_idx < num_registers;
213 ++reg_idx)
Sean Callananece96492010-11-08 03:49:50214 {
Greg Claytonaf247d72011-05-19 03:54:16215 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
216 if (reg_ctx->ReadRegister(reg_info, reg_value))
217 {
218 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
219 strm.EOL();
220 }
Sean Callananece96492010-11-08 03:49:50221 }
Greg Claytonaf247d72011-05-19 03:54:16222 log->PutCString(strm.GetData());
Sean Callananece96492010-11-08 03:49:50223 }
Sean Callanan10af7c42010-11-04 01:51:38224}
225
226void
Jim Ingham18de2fd2012-05-10 01:35:39227ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan10af7c42010-11-04 01:51:38228{
Greg Clayton5160ce52013-03-27 23:08:40229 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10230
Jim Ingham87d0e612012-04-13 23:11:52231 if (!m_valid)
232 {
233 //Don't call DoTakedown if we were never valid to begin with.
234 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10235 log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.",
236 static_cast<void*>(this));
Jim Ingham87d0e612012-04-13 23:11:52237 return;
238 }
Saleem Abdulrasool324a1032014-04-04 04:06:10239
Jim Ingham9da36832011-01-22 01:27:23240 if (!m_takedown_done)
Jim Ingham77787032011-01-20 02:03:18241 {
Jim Ingham18de2fd2012-05-10 01:35:39242 if (success)
Greg Clayton70b57652011-05-15 01:25:55243 {
Ewan Crawford90ff7912015-07-14 10:56:58244 SetReturnValue();
Greg Clayton70b57652011-05-15 01:25:55245 }
Jim Ingham9da36832011-01-22 01:27:23246 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10247 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
248 static_cast<void*>(this), m_thread.GetID(), m_valid,
249 IsPlanComplete());
Jim Ingham9da36832011-01-22 01:27:23250 m_takedown_done = true;
Jim Inghamce553d82011-11-01 02:46:54251 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham60c41182013-06-04 01:40:51252 m_real_stop_info_sp = GetPrivateStopInfo ();
Ed Maste7b24e952013-11-12 16:47:08253 if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state))
254 {
255 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10256 log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore register state",
257 static_cast<void*>(this));
Ed Maste7b24e952013-11-12 16:47:08258 }
Jim Ingham18de2fd2012-05-10 01:35:39259 SetPlanComplete(success);
Jim Ingham77787032011-01-20 02:03:18260 ClearBreakpoints();
Jim Ingham9da36832011-01-22 01:27:23261 if (log && log->GetVerbose())
262 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham9da36832011-01-22 01:27:23263 }
264 else
265 {
266 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10267 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called as no-op for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
268 static_cast<void*>(this), m_thread.GetID(), m_valid,
269 IsPlanComplete());
Jim Ingham77787032011-01-20 02:03:18270 }
Chris Lattner30fdc8d2010-06-08 16:52:24271}
272
273void
Jim Inghambda4e5eb2011-01-18 01:58:06274ThreadPlanCallFunction::WillPop ()
275{
Jim Ingham0161b492013-02-09 01:29:05276 DoTakedown(PlanSucceeded());
Jim Inghambda4e5eb2011-01-18 01:58:06277}
278
279void
Greg Clayton2a48f522011-05-14 01:50:35280ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24281{
Greg Clayton2a48f522011-05-14 01:50:35282 if (level == eDescriptionLevelBrief)
Chris Lattner30fdc8d2010-06-08 16:52:24283 {
284 s->Printf("Function call thread plan");
285 }
286 else
287 {
Greg Clayton1ac04c32012-02-21 00:09:25288 TargetSP target_sp (m_thread.CalculateTarget());
Daniel Malead01b2952012-11-29 21:49:15289 s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24290 }
291}
292
293bool
294ThreadPlanCallFunction::ValidatePlan (Stream *error)
295{
296 if (!m_valid)
Jim Inghamea06f3b2013-03-28 00:04:05297 {
298 if (error)
299 {
300 if (m_constructor_errors.GetSize() > 0)
301 error->PutCString (m_constructor_errors.GetData());
302 else
303 error->PutCString ("Unknown error");
304 }
Chris Lattner30fdc8d2010-06-08 16:52:24305 return false;
Jim Inghamea06f3b2013-03-28 00:04:05306 }
Chris Lattner30fdc8d2010-06-08 16:52:24307
308 return true;
309}
310
Jim Ingham0161b492013-02-09 01:29:05311Vote
312ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr)
313{
314 if (m_takedown_done || IsPlanComplete())
315 return eVoteYes;
316 else
317 return ThreadPlan::ShouldReportStop(event_ptr);
318}
319
Chris Lattner30fdc8d2010-06-08 16:52:24320bool
Jim Ingham221d51c2013-05-08 00:35:16321ThreadPlanCallFunction::DoPlanExplainsStop (Event *event_ptr)
Sean Callanan6db73ca2010-11-03 01:37:52322{
Greg Clayton5160ce52013-03-27 23:08:40323 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP|LIBLLDB_LOG_PROCESS));
Jim Ingham60c41182013-06-04 01:40:51324 m_real_stop_info_sp = GetPrivateStopInfo ();
Jim Ingham160f78c2011-05-17 01:10:11325
Jim Ingham40d871f2010-10-26 00:27:45326 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
327 // we answer yes.
Eugene Zelenkoe65b2cf2015-12-15 01:33:19328 if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr))
Jim Ingham184e9812013-01-15 02:47:48329 {
330 SetPlanComplete();
Jim Ingham40d871f2010-10-26 00:27:45331 return true;
Jim Ingham184e9812013-01-15 02:47:48332 }
Sean Callanan3e6fedc2010-10-19 22:24:06333
Sean Callananc98aca62010-11-03 19:36:28334 // Check if the breakpoint is one of ours.
335
Jim Ingham18de2fd2012-05-10 01:35:39336 StopReason stop_reason;
337 if (!m_real_stop_info_sp)
338 stop_reason = eStopReasonNone;
339 else
340 stop_reason = m_real_stop_info_sp->GetStopReason();
Jim Ingham0161b492013-02-09 01:29:05341 if (log)
342 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.", Thread::StopReasonAsCString(stop_reason));
Jim Ingham18de2fd2012-05-10 01:35:39343
344 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
Sean Callananc98aca62010-11-03 19:36:28345 return true;
346
Jim Ingham35878c42014-04-08 21:33:21347 // One more quirk here. If this event was from Halt interrupting the target, then we should not consider
348 // ourselves complete. Return true to acknowledge the stop.
349 if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr))
350 {
351 if (log)
352 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: The event is an Interrupt, returning true.");
353 return true;
354 }
Jim Ingham0161b492013-02-09 01:29:05355 // We control breakpoints separately from other "stop reasons." So first,
356 // check the case where we stopped for an internal breakpoint, in that case, continue on.
357 // If it is not an internal breakpoint, consult m_ignore_breakpoints.
Eugene Zelenkoe65b2cf2015-12-15 01:33:19358
Jim Ingham18de2fd2012-05-10 01:35:39359 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham40d871f2010-10-26 00:27:45360 {
Greg Clayton1ac04c32012-02-21 00:09:25361 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham160f78c2011-05-17 01:10:11362 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Clayton1ac04c32012-02-21 00:09:25363 BreakpointSiteSP bp_site_sp;
364 if (process_sp)
365 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham40d871f2010-10-26 00:27:45366 if (bp_site_sp)
367 {
368 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
369 bool is_internal = true;
370 for (uint32_t i = 0; i < num_owners; i++)
371 {
Sean Callanan6db73ca2010-11-03 01:37:52372 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Jim Ingham0161b492013-02-09 01:29:05373 if (log)
374 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: hit breakpoint %d while calling function", bp.GetID());
Sean Callanan6db73ca2010-11-03 01:37:52375
376 if (!bp.IsInternal())
Jim Ingham40d871f2010-10-26 00:27:45377 {
378 is_internal = false;
379 break;
380 }
381 }
382 if (is_internal)
Jim Ingham0161b492013-02-09 01:29:05383 {
384 if (log)
385 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop hit an internal breakpoint, not stopping.");
Jim Ingham40d871f2010-10-26 00:27:45386 return false;
Jim Ingham0161b492013-02-09 01:29:05387 }
Jim Ingham40d871f2010-10-26 00:27:45388 }
Jim Ingham0161b492013-02-09 01:29:05389
Jim Ingham184e9812013-01-15 02:47:48390 if (m_ignore_breakpoints)
Jim Ingham923886c2012-05-11 18:43:38391 {
Jim Ingham0161b492013-02-09 01:29:05392 if (log)
393 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true");
394 m_real_stop_info_sp->OverrideShouldStop(false);
Jim Ingham923886c2012-05-11 18:43:38395 return true;
396 }
397 else
Jim Ingham0161b492013-02-09 01:29:05398 {
399 if (log)
400 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true");
401 m_real_stop_info_sp->OverrideShouldStop(true);
Jim Ingham923886c2012-05-11 18:43:38402 return false;
Jim Ingham0161b492013-02-09 01:29:05403 }
404 }
405 else if (!m_unwind_on_error)
406 {
407 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
408 return false;
Jim Ingham40d871f2010-10-26 00:27:45409 }
410 else
411 {
412 // If the subplan is running, any crashes are attributable to us.
Jim Ingham2c364392011-01-26 19:13:09413 // If we want to discard the plan, then we say we explain the stop
414 // but if we are going to be discarded, let whoever is above us
415 // explain the stop.
Jim Ingham0161b492013-02-09 01:29:05416 // But don't discard the plan if the stop would restart itself (for instance if it is a
417 // signal that is set not to stop. Check that here first. We just say we explain the stop
418 // but aren't done and everything will continue on from there.
419
Jim Ingham841ee9b2015-05-07 18:51:04420 if (m_real_stop_info_sp && m_real_stop_info_sp->ShouldStopSynchronous(event_ptr))
Jim Ingham18de2fd2012-05-10 01:35:39421 {
Jim Ingham0161b492013-02-09 01:29:05422 SetPlanComplete(false);
Eugene Zelenkoe65b2cf2015-12-15 01:33:19423 return m_subplan_sp ? m_unwind_on_error : false;
Jim Ingham18de2fd2012-05-10 01:35:39424 }
425 else
Jim Ingham0161b492013-02-09 01:29:05426 return true;
Jim Ingham40d871f2010-10-26 00:27:45427 }
Chris Lattner30fdc8d2010-06-08 16:52:24428}
429
430bool
431ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
432{
Jim Ingham221d51c2013-05-08 00:35:16433 // We do some computation in DoPlanExplainsStop that may or may not set the plan as complete.
Jim Ingham184e9812013-01-15 02:47:48434 // We need to do that here to make sure our state is correct.
Jim Ingham221d51c2013-05-08 00:35:16435 DoPlanExplainsStop(event_ptr);
Jim Ingham184e9812013-01-15 02:47:48436
437 if (IsPlanComplete())
Chris Lattner30fdc8d2010-06-08 16:52:24438 {
Jim Ingham9da36832011-01-22 01:27:23439 ReportRegisterState ("Function completed. Register state was:");
Chris Lattner30fdc8d2010-06-08 16:52:24440 return true;
441 }
442 else
443 {
444 return false;
445 }
446}
447
448bool
449ThreadPlanCallFunction::StopOthers ()
450{
451 return m_stop_other_threads;
452}
453
Chris Lattner30fdc8d2010-06-08 16:52:24454StateType
Jim Ingham06e827c2010-11-11 19:26:09455ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24456{
457 return eStateRunning;
458}
459
460void
461ThreadPlanCallFunction::DidPush ()
462{
Sean Callananbe3a1b12010-10-26 00:31:56463//#define SINGLE_STEP_EXPRESSIONS
464
Jim Ingham8559a352012-11-26 23:52:18465 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
466 // Wait till the plan is pushed so we aren't changing the stop info till we're about to run.
467
468 GetThread().SetStopInfoToNothing();
469
Sean Callananbe3a1b12010-10-26 00:31:56470#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner30fdc8d2010-06-08 16:52:24471 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
472
473 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham77787032011-01-20 02:03:18474 m_subplan_sp->SetPrivate (true);
Sean Callananbe3a1b12010-10-26 00:31:56475#endif
Chris Lattner30fdc8d2010-06-08 16:52:24476}
477
478bool
479ThreadPlanCallFunction::WillStop ()
480{
481 return true;
482}
483
484bool
485ThreadPlanCallFunction::MischiefManaged ()
486{
Greg Clayton5160ce52013-03-27 23:08:40487 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10488
Chris Lattner30fdc8d2010-06-08 16:52:24489 if (IsPlanComplete())
490 {
Chris Lattner30fdc8d2010-06-08 16:52:24491 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10492 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
493 static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24494
495 ThreadPlan::MischiefManaged ();
496 return true;
497 }
498 else
499 {
500 return false;
501 }
502}
Sean Callanan6db73ca2010-11-03 01:37:52503
504void
505ThreadPlanCallFunction::SetBreakpoints ()
506{
Greg Clayton1ac04c32012-02-21 00:09:25507 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham6fbc48b2013-11-07 00:11:47508 if (m_trap_exceptions && process_sp)
Greg Clayton1ac04c32012-02-21 00:09:25509 {
510 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
511 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan6db73ca2010-11-03 01:37:52512
Greg Clayton1ac04c32012-02-21 00:09:25513 if (m_cxx_language_runtime)
Jim Ingham6fbc48b2013-11-07 00:11:47514 {
515 m_should_clear_cxx_exception_bp = !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
Greg Clayton1ac04c32012-02-21 00:09:25516 m_cxx_language_runtime->SetExceptionBreakpoints();
Jim Ingham6fbc48b2013-11-07 00:11:47517 }
Greg Clayton1ac04c32012-02-21 00:09:25518 if (m_objc_language_runtime)
Jim Ingham6fbc48b2013-11-07 00:11:47519 {
520 m_should_clear_objc_exception_bp = !m_objc_language_runtime->ExceptionBreakpointsAreSet();
Greg Clayton1ac04c32012-02-21 00:09:25521 m_objc_language_runtime->SetExceptionBreakpoints();
Jim Ingham6fbc48b2013-11-07 00:11:47522 }
Greg Clayton1ac04c32012-02-21 00:09:25523 }
Sean Callanan6db73ca2010-11-03 01:37:52524}
525
526void
527ThreadPlanCallFunction::ClearBreakpoints ()
528{
Jim Ingham6fbc48b2013-11-07 00:11:47529 if (m_trap_exceptions)
530 {
531 if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
532 m_cxx_language_runtime->ClearExceptionBreakpoints();
533 if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
534 m_objc_language_runtime->ClearExceptionBreakpoints();
535 }
Sean Callanan6db73ca2010-11-03 01:37:52536}
Sean Callananc98aca62010-11-03 19:36:28537
538bool
539ThreadPlanCallFunction::BreakpointsExplainStop()
540{
Jim Ingham60c41182013-06-04 01:40:51541 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Sean Callananc98aca62010-11-03 19:36:28542
Jim Ingham6fbc48b2013-11-07 00:11:47543 if (m_trap_exceptions)
Jim Ingham184e9812013-01-15 02:47:48544 {
Jim Ingham6fbc48b2013-11-07 00:11:47545 if ((m_cxx_language_runtime &&
546 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
547 ||(m_objc_language_runtime &&
548 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)))
549 {
550 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
551 if (log)
552 log->Printf ("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an exception breakpoint, setting plan complete.");
553
554 SetPlanComplete(false);
555
556 // If the user has set the ObjC language breakpoint, it would normally get priority over our internal
557 // catcher breakpoint, but in this case we can't let that happen, so force the ShouldStop here.
558 stop_info_sp->OverrideShouldStop (true);
559 return true;
560 }
Jim Ingham184e9812013-01-15 02:47:48561 }
Sean Callananc98aca62010-11-03 19:36:28562
Sean Callananc98aca62010-11-03 19:36:28563 return false;
564}
Jim Ingham8559a352012-11-26 23:52:18565
Jim Ingham0ff099f2014-03-07 11:16:37566void
567ThreadPlanCallFunction::SetStopOthers (bool new_value)
568{
569 m_subplan_sp->SetStopOthers(new_value);
570}
571
Jim Ingham8559a352012-11-26 23:52:18572bool
573ThreadPlanCallFunction::RestoreThreadState()
574{
575 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
576}
577
Ewan Crawford90ff7912015-07-14 10:56:58578void
579ThreadPlanCallFunction::SetReturnValue()
580{
581 ProcessSP process_sp(m_thread.GetProcess());
Eugene Zelenkoe65b2cf2015-12-15 01:33:19582 const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr;
Ewan Crawford90ff7912015-07-14 10:56:58583 if (abi && m_return_type.IsValid())
584 {
585 const bool persistent = false;
586 m_return_valobj_sp = abi->GetReturnValueObject(m_thread, m_return_type, persistent);
587 }
588}