blob: cf4d0c49d1fe88f169a42f5199e57f2e0c577c94 [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
10#include "lldb/Target/ThreadPlanCallFunction.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
Jim Ingham46d005d2014-04-02 22:53:2115
Chris Lattner30fdc8d2010-06-08 16:52:2416// Project includes
Jim Ingham40d871f2010-10-26 00:27:4517#include "lldb/Breakpoint/Breakpoint.h"
18#include "lldb/Breakpoint/BreakpointLocation.h"
Chris Lattner30fdc8d2010-06-08 16:52:2419#include "lldb/Core/Address.h"
20#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:0621#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:2422#include "lldb/Core/Stream.h"
Greg Clayton1f746072012-08-29 21:13:0623#include "lldb/Symbol/ObjectFile.h"
Zachary Turner32abc6e2015-03-03 19:23:0924#include "lldb/Target/ABI.h"
Sean Callananf2115102010-11-03 22:19:3825#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:2426#include "lldb/Target/Process.h"
27#include "lldb/Target/RegisterContext.h"
Jim Ingham40d871f2010-10-26 00:27:4528#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:2429#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 Ingham0092c8e2012-04-13 20:38:1339bool
40ThreadPlanCallFunction::ConstructorSetup (Thread &thread,
Jim Ingham0092c8e2012-04-13 20:38:1341 ABI *& abi,
42 lldb::addr_t &start_load_addr,
43 lldb::addr_t &function_load_addr)
44{
Jim Ingham0092c8e2012-04-13 20:38:1345 SetIsMasterPlan (true);
Jim Ingham923886c2012-05-11 18:43:3846 SetOkayToDiscard (false);
Andrew Kaylor327c2672012-12-07 17:56:3147 SetPrivate (true);
Jim Ingham0092c8e2012-04-13 20:38:1348
49 ProcessSP process_sp (thread.GetProcess());
50 if (!process_sp)
51 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1052
Jim Ingham0092c8e2012-04-13 20:38:1353 abi = process_sp->GetABI().get();
Saleem Abdulrasool324a1032014-04-04 04:06:1054
Jim Ingham0092c8e2012-04-13 20:38:1355 if (!abi)
56 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:1057
Greg Clayton5160ce52013-03-27 23:08:4058 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:1059
Jim Ingham0092c8e2012-04-13 20:38:1360 SetBreakpoints();
Saleem Abdulrasool324a1032014-04-04 04:06:1061
Jim Ingham0092c8e2012-04-13 20:38:1362 m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
63 // If we can't read memory at the point of the process where we are planning to put our function, we're
64 // not going to get any further...
65 Error error;
66 process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
67 if (!error.Success())
68 {
Jim Inghamea06f3b2013-03-28 00:04:0569 m_constructor_errors.Printf ("Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", m_function_sp);
Jim Ingham0092c8e2012-04-13 20:38:1370 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:1071 log->Printf ("ThreadPlanCallFunction(%p): %s.",
72 static_cast<void*>(this),
73 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1374 return false;
75 }
Saleem Abdulrasool324a1032014-04-04 04:06:1076
Jim Ingham6fbc48b2013-11-07 00:11:4777 Module *exe_module = GetTarget().GetExecutableModulePointer();
Jim Ingham0092c8e2012-04-13 20:38:1378
79 if (exe_module == NULL)
80 {
Jim Inghamea06f3b2013-03-28 00:04:0581 m_constructor_errors.Printf ("Can't execute code without an executable module.");
Jim Ingham0092c8e2012-04-13 20:38:1382 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:1083 log->Printf ("ThreadPlanCallFunction(%p): %s.",
84 static_cast<void*>(this),
85 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:1386 return false;
87 }
88 else
89 {
90 ObjectFile *objectFile = exe_module->GetObjectFile();
91 if (!objectFile)
92 {
Jim Inghamea06f3b2013-03-28 00:04:0593 m_constructor_errors.Printf ("Could not find object file for module \"%s\".",
94 exe_module->GetFileSpec().GetFilename().AsCString());
95
Jim Ingham0092c8e2012-04-13 20:38:1396 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:1097 log->Printf ("ThreadPlanCallFunction(%p): %s.",
98 static_cast<void*>(this),
99 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:13100 return false;
101 }
Saleem Abdulrasool324a1032014-04-04 04:06:10102
Jim Ingham0092c8e2012-04-13 20:38:13103 m_start_addr = objectFile->GetEntryPointAddress();
104 if (!m_start_addr.IsValid())
105 {
Jim Inghamea06f3b2013-03-28 00:04:05106 m_constructor_errors.Printf ("Could not find entry point address for executable module \"%s\".",
107 exe_module->GetFileSpec().GetFilename().AsCString());
Jim Ingham0092c8e2012-04-13 20:38:13108 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10109 log->Printf ("ThreadPlanCallFunction(%p): %s.",
110 static_cast<void*>(this),
111 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:13112 return false;
113 }
114 }
Saleem Abdulrasool324a1032014-04-04 04:06:10115
Jim Ingham6fbc48b2013-11-07 00:11:47116 start_load_addr = m_start_addr.GetLoadAddress (&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:10117
Jim Ingham0092c8e2012-04-13 20:38:13118 // Checkpoint the thread state so we can restore it later.
119 if (log && log->GetVerbose())
120 ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
121
122 if (!thread.CheckpointThreadState (m_stored_thread_state))
123 {
Jim Inghamea06f3b2013-03-28 00:04:05124 m_constructor_errors.Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
Jim Ingham0092c8e2012-04-13 20:38:13125 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10126 log->Printf ("ThreadPlanCallFunction(%p): %s.",
127 static_cast<void*>(this),
128 m_constructor_errors.GetData());
Jim Ingham0092c8e2012-04-13 20:38:13129 return false;
130 }
Jim Ingham6fbc48b2013-11-07 00:11:47131 function_load_addr = m_function_addr.GetLoadAddress (&GetTarget());
Saleem Abdulrasool324a1032014-04-04 04:06:10132
Jim Ingham0092c8e2012-04-13 20:38:13133 return true;
134}
Chris Lattner30fdc8d2010-06-08 16:52:24135
136ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
Matt Kopec00049b82013-02-27 20:13:38137 const Address &function,
Greg Claytona1e5dc82015-08-11 22:53:00138 const CompilerType &return_type,
Sean Callanana464f3d2013-11-08 01:14:26139 llvm::ArrayRef<addr_t> args,
140 const EvaluateExpressionOptions &options) :
Jim Inghamb01e742a2010-06-19 04:45:32141 ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
Benjamin Kramer1ee0d4f2010-07-16 12:32:33142 m_valid (false),
Jim Ingham6fbc48b2013-11-07 00:11:47143 m_stop_other_threads (options.GetStopOthers()),
144 m_unwind_on_error (options.DoesUnwindOnError()),
145 m_ignore_breakpoints (options.DoesIgnoreBreakpoints()),
146 m_debug_execution (options.GetDebug()),
147 m_trap_exceptions (options.GetTrapExceptions()),
Jim Ingham16e0c682011-08-12 23:34:31148 m_function_addr (function),
Filipe Cabecinhasb4cb0be2012-09-11 18:11:07149 m_function_sp (0),
Jim Inghamce553d82011-11-01 02:46:54150 m_takedown_done (false),
Jim Ingham6fbc48b2013-11-07 00:11:47151 m_should_clear_objc_exception_bp(false),
152 m_should_clear_cxx_exception_bp (false),
Ewan Crawford90ff7912015-07-14 10:56:58153 m_stop_address (LLDB_INVALID_ADDRESS),
154 m_return_type (return_type)
Chris Lattner30fdc8d2010-06-08 16:52:24155{
Ewan Crawford90ff7912015-07-14 10:56:58156 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
157 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
158 ABI *abi = nullptr;
159
Jim Ingham923886c2012-05-11 18:43:38160 if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr))
Greg Clayton1ac04c32012-02-21 00:09:25161 return;
Saleem Abdulrasool324a1032014-04-04 04:06:10162
Sean Callanana464f3d2013-11-08 01:14:26163 if (!abi->PrepareTrivialCall(thread,
164 m_function_sp,
165 function_load_addr,
166 start_load_addr,
167 args))
Greg Clayton1ac04c32012-02-21 00:09:25168 return;
Saleem Abdulrasool324a1032014-04-04 04:06:10169
Jim Ingham9da36832011-01-22 01:27:23170 ReportRegisterState ("Function call was set up. Register state was:");
Saleem Abdulrasool324a1032014-04-04 04:06:10171
Jim Ingham9da36832011-01-22 01:27:23172 m_valid = true;
173}
174
Ewan Crawford90ff7912015-07-14 10:56:58175ThreadPlanCallFunction::ThreadPlanCallFunction(Thread &thread,
176 const Address &function,
177 const EvaluateExpressionOptions &options) :
178 ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion),
179 m_valid(false),
180 m_stop_other_threads(options.GetStopOthers()),
181 m_unwind_on_error(options.DoesUnwindOnError()),
182 m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
183 m_debug_execution(options.GetDebug()),
184 m_trap_exceptions(options.GetTrapExceptions()),
185 m_function_addr(function),
186 m_function_sp(0),
187 m_takedown_done(false),
188 m_should_clear_objc_exception_bp(false),
189 m_should_clear_cxx_exception_bp(false),
190 m_stop_address(LLDB_INVALID_ADDRESS),
Greg Claytona1e5dc82015-08-11 22:53:00191 m_return_type(CompilerType())
Ewan Crawford90ff7912015-07-14 10:56:58192{
193
194}
195
Jim Ingham9da36832011-01-22 01:27:23196ThreadPlanCallFunction::~ThreadPlanCallFunction ()
197{
Jim Ingham0161b492013-02-09 01:29:05198 DoTakedown(PlanSucceeded());
Jim Ingham9da36832011-01-22 01:27:23199}
200
201void
202ThreadPlanCallFunction::ReportRegisterState (const char *message)
203{
Greg Clayton5160ce52013-03-27 23:08:40204 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE));
Sean Callananece96492010-11-08 03:49:50205 if (log)
206 {
Greg Claytonaf247d72011-05-19 03:54:16207 StreamString strm;
Greg Clayton5ccbd292011-01-06 22:15:06208 RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
Jim Ingham9da36832011-01-22 01:27:23209
210 log->PutCString(message);
211
Greg Claytonaf247d72011-05-19 03:54:16212 RegisterValue reg_value;
213
214 for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
215 reg_idx < num_registers;
216 ++reg_idx)
Sean Callananece96492010-11-08 03:49:50217 {
Greg Claytonaf247d72011-05-19 03:54:16218 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
219 if (reg_ctx->ReadRegister(reg_info, reg_value))
220 {
221 reg_value.Dump(&strm, reg_info, true, false, eFormatDefault);
222 strm.EOL();
223 }
Sean Callananece96492010-11-08 03:49:50224 }
Greg Claytonaf247d72011-05-19 03:54:16225 log->PutCString(strm.GetData());
Sean Callananece96492010-11-08 03:49:50226 }
Sean Callanan10af7c42010-11-04 01:51:38227}
228
229void
Jim Ingham18de2fd2012-05-10 01:35:39230ThreadPlanCallFunction::DoTakedown (bool success)
Sean Callanan10af7c42010-11-04 01:51:38231{
Greg Clayton5160ce52013-03-27 23:08:40232 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10233
Jim Ingham87d0e612012-04-13 23:11:52234 if (!m_valid)
235 {
236 //Don't call DoTakedown if we were never valid to begin with.
237 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10238 log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.",
239 static_cast<void*>(this));
Jim Ingham87d0e612012-04-13 23:11:52240 return;
241 }
Saleem Abdulrasool324a1032014-04-04 04:06:10242
Jim Ingham9da36832011-01-22 01:27:23243 if (!m_takedown_done)
Jim Ingham77787032011-01-20 02:03:18244 {
Jim Ingham18de2fd2012-05-10 01:35:39245 if (success)
Greg Clayton70b57652011-05-15 01:25:55246 {
Ewan Crawford90ff7912015-07-14 10:56:58247 SetReturnValue();
Greg Clayton70b57652011-05-15 01:25:55248 }
Jim Ingham9da36832011-01-22 01:27:23249 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10250 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
251 static_cast<void*>(this), m_thread.GetID(), m_valid,
252 IsPlanComplete());
Jim Ingham9da36832011-01-22 01:27:23253 m_takedown_done = true;
Jim Inghamce553d82011-11-01 02:46:54254 m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
Jim Ingham60c41182013-06-04 01:40:51255 m_real_stop_info_sp = GetPrivateStopInfo ();
Ed Maste7b24e952013-11-12 16:47:08256 if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state))
257 {
258 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10259 log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore register state",
260 static_cast<void*>(this));
Ed Maste7b24e952013-11-12 16:47:08261 }
Jim Ingham18de2fd2012-05-10 01:35:39262 SetPlanComplete(success);
Jim Ingham77787032011-01-20 02:03:18263 ClearBreakpoints();
Jim Ingham9da36832011-01-22 01:27:23264 if (log && log->GetVerbose())
265 ReportRegisterState ("Restoring thread state after function call. Restored register state:");
Jim Ingham2c364392011-01-26 19:13:09266
Jim Ingham9da36832011-01-22 01:27:23267 }
268 else
269 {
270 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10271 log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called as no-op for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
272 static_cast<void*>(this), m_thread.GetID(), m_valid,
273 IsPlanComplete());
Jim Ingham77787032011-01-20 02:03:18274 }
Chris Lattner30fdc8d2010-06-08 16:52:24275}
276
277void
Jim Inghambda4e5eb2011-01-18 01:58:06278ThreadPlanCallFunction::WillPop ()
279{
Jim Ingham0161b492013-02-09 01:29:05280 DoTakedown(PlanSucceeded());
Jim Inghambda4e5eb2011-01-18 01:58:06281}
282
283void
Greg Clayton2a48f522011-05-14 01:50:35284ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24285{
Greg Clayton2a48f522011-05-14 01:50:35286 if (level == eDescriptionLevelBrief)
Chris Lattner30fdc8d2010-06-08 16:52:24287 {
288 s->Printf("Function call thread plan");
289 }
290 else
291 {
Greg Clayton1ac04c32012-02-21 00:09:25292 TargetSP target_sp (m_thread.CalculateTarget());
Daniel Malead01b2952012-11-29 21:49:15293 s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24294 }
295}
296
297bool
298ThreadPlanCallFunction::ValidatePlan (Stream *error)
299{
300 if (!m_valid)
Jim Inghamea06f3b2013-03-28 00:04:05301 {
302 if (error)
303 {
304 if (m_constructor_errors.GetSize() > 0)
305 error->PutCString (m_constructor_errors.GetData());
306 else
307 error->PutCString ("Unknown error");
308 }
Chris Lattner30fdc8d2010-06-08 16:52:24309 return false;
Jim Inghamea06f3b2013-03-28 00:04:05310 }
Chris Lattner30fdc8d2010-06-08 16:52:24311
312 return true;
313}
314
Jim Ingham0161b492013-02-09 01:29:05315
316Vote
317ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr)
318{
319 if (m_takedown_done || IsPlanComplete())
320 return eVoteYes;
321 else
322 return ThreadPlan::ShouldReportStop(event_ptr);
323}
324
Chris Lattner30fdc8d2010-06-08 16:52:24325bool
Jim Ingham221d51c2013-05-08 00:35:16326ThreadPlanCallFunction::DoPlanExplainsStop (Event *event_ptr)
Sean Callanan6db73ca2010-11-03 01:37:52327{
Greg Clayton5160ce52013-03-27 23:08:40328 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP|LIBLLDB_LOG_PROCESS));
Jim Ingham60c41182013-06-04 01:40:51329 m_real_stop_info_sp = GetPrivateStopInfo ();
Jim Ingham160f78c2011-05-17 01:10:11330
Jim Ingham40d871f2010-10-26 00:27:45331 // If our subplan knows why we stopped, even if it's done (which would forward the question to us)
332 // we answer yes.
Jim Ingham0161b492013-02-09 01:29:05333 if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop(event_ptr))
Jim Ingham184e9812013-01-15 02:47:48334 {
335 SetPlanComplete();
Jim Ingham40d871f2010-10-26 00:27:45336 return true;
Jim Ingham184e9812013-01-15 02:47:48337 }
Sean Callanan3e6fedc2010-10-19 22:24:06338
Sean Callananc98aca62010-11-03 19:36:28339 // Check if the breakpoint is one of ours.
340
Jim Ingham18de2fd2012-05-10 01:35:39341 StopReason stop_reason;
342 if (!m_real_stop_info_sp)
343 stop_reason = eStopReasonNone;
344 else
345 stop_reason = m_real_stop_info_sp->GetStopReason();
Jim Ingham0161b492013-02-09 01:29:05346 if (log)
347 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.", Thread::StopReasonAsCString(stop_reason));
Jim Ingham18de2fd2012-05-10 01:35:39348
349 if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
Sean Callananc98aca62010-11-03 19:36:28350 return true;
351
Jim Ingham35878c42014-04-08 21:33:21352 // One more quirk here. If this event was from Halt interrupting the target, then we should not consider
353 // ourselves complete. Return true to acknowledge the stop.
354 if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr))
355 {
356 if (log)
357 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: The event is an Interrupt, returning true.");
358 return true;
359 }
Jim Ingham0161b492013-02-09 01:29:05360 // We control breakpoints separately from other "stop reasons." So first,
361 // check the case where we stopped for an internal breakpoint, in that case, continue on.
362 // If it is not an internal breakpoint, consult m_ignore_breakpoints.
Sean Callanan6db73ca2010-11-03 01:37:52363
Jim Ingham18de2fd2012-05-10 01:35:39364
365 if (stop_reason == eStopReasonBreakpoint)
Jim Ingham40d871f2010-10-26 00:27:45366 {
Greg Clayton1ac04c32012-02-21 00:09:25367 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham160f78c2011-05-17 01:10:11368 uint64_t break_site_id = m_real_stop_info_sp->GetValue();
Greg Clayton1ac04c32012-02-21 00:09:25369 BreakpointSiteSP bp_site_sp;
370 if (process_sp)
371 bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id);
Jim Ingham40d871f2010-10-26 00:27:45372 if (bp_site_sp)
373 {
374 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
375 bool is_internal = true;
376 for (uint32_t i = 0; i < num_owners; i++)
377 {
Sean Callanan6db73ca2010-11-03 01:37:52378 Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
Jim Ingham0161b492013-02-09 01:29:05379 if (log)
380 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: hit breakpoint %d while calling function", bp.GetID());
Sean Callanan6db73ca2010-11-03 01:37:52381
382 if (!bp.IsInternal())
Jim Ingham40d871f2010-10-26 00:27:45383 {
384 is_internal = false;
385 break;
386 }
387 }
388 if (is_internal)
Jim Ingham0161b492013-02-09 01:29:05389 {
390 if (log)
391 log->Printf ("ThreadPlanCallFunction::PlanExplainsStop hit an internal breakpoint, not stopping.");
Jim Ingham40d871f2010-10-26 00:27:45392 return false;
Jim Ingham0161b492013-02-09 01:29:05393 }
Jim Ingham40d871f2010-10-26 00:27:45394 }
Jim Ingham0161b492013-02-09 01:29:05395
Jim Ingham184e9812013-01-15 02:47:48396 if (m_ignore_breakpoints)
Jim Ingham923886c2012-05-11 18:43:38397 {
Jim Ingham0161b492013-02-09 01:29:05398 if (log)
399 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true");
400 m_real_stop_info_sp->OverrideShouldStop(false);
Jim Ingham923886c2012-05-11 18:43:38401 return true;
402 }
403 else
Jim Ingham0161b492013-02-09 01:29:05404 {
405 if (log)
406 log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true");
407 m_real_stop_info_sp->OverrideShouldStop(true);
Jim Ingham923886c2012-05-11 18:43:38408 return false;
Jim Ingham0161b492013-02-09 01:29:05409 }
410 }
411 else if (!m_unwind_on_error)
412 {
413 // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack.
414 return false;
Jim Ingham40d871f2010-10-26 00:27:45415 }
416 else
417 {
418 // If the subplan is running, any crashes are attributable to us.
Jim Ingham2c364392011-01-26 19:13:09419 // If we want to discard the plan, then we say we explain the stop
420 // but if we are going to be discarded, let whoever is above us
421 // explain the stop.
Jim Ingham0161b492013-02-09 01:29:05422 // But don't discard the plan if the stop would restart itself (for instance if it is a
423 // signal that is set not to stop. Check that here first. We just say we explain the stop
424 // but aren't done and everything will continue on from there.
425
Jim Ingham841ee9b2015-05-07 18:51:04426 if (m_real_stop_info_sp && m_real_stop_info_sp->ShouldStopSynchronous(event_ptr))
Jim Ingham18de2fd2012-05-10 01:35:39427 {
Jim Ingham0161b492013-02-09 01:29:05428 SetPlanComplete(false);
429 if (m_subplan_sp)
Jim Ingham18de2fd2012-05-10 01:35:39430 {
Jim Ingham0161b492013-02-09 01:29:05431 if (m_unwind_on_error)
432 return true;
433 else
434 return false;
Jim Ingham18de2fd2012-05-10 01:35:39435 }
436 else
437 return false;
438 }
439 else
Jim Ingham0161b492013-02-09 01:29:05440 return true;
Jim Ingham40d871f2010-10-26 00:27:45441 }
Chris Lattner30fdc8d2010-06-08 16:52:24442}
443
444bool
445ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
446{
Jim Ingham221d51c2013-05-08 00:35:16447 // We do some computation in DoPlanExplainsStop that may or may not set the plan as complete.
Jim Ingham184e9812013-01-15 02:47:48448 // We need to do that here to make sure our state is correct.
Jim Ingham221d51c2013-05-08 00:35:16449 DoPlanExplainsStop(event_ptr);
Jim Ingham184e9812013-01-15 02:47:48450
451 if (IsPlanComplete())
Chris Lattner30fdc8d2010-06-08 16:52:24452 {
Jim Ingham9da36832011-01-22 01:27:23453 ReportRegisterState ("Function completed. Register state was:");
Chris Lattner30fdc8d2010-06-08 16:52:24454 return true;
455 }
456 else
457 {
458 return false;
459 }
460}
461
462bool
463ThreadPlanCallFunction::StopOthers ()
464{
465 return m_stop_other_threads;
466}
467
Chris Lattner30fdc8d2010-06-08 16:52:24468StateType
Jim Ingham06e827c2010-11-11 19:26:09469ThreadPlanCallFunction::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24470{
471 return eStateRunning;
472}
473
474void
475ThreadPlanCallFunction::DidPush ()
476{
Sean Callananbe3a1b12010-10-26 00:31:56477//#define SINGLE_STEP_EXPRESSIONS
478
Jim Ingham8559a352012-11-26 23:52:18479 // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding...
480 // Wait till the plan is pushed so we aren't changing the stop info till we're about to run.
481
482 GetThread().SetStopInfoToNothing();
483
Sean Callananbe3a1b12010-10-26 00:31:56484#ifndef SINGLE_STEP_EXPRESSIONS
Chris Lattner30fdc8d2010-06-08 16:52:24485 m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads));
486
487 m_thread.QueueThreadPlan(m_subplan_sp, false);
Jim Ingham77787032011-01-20 02:03:18488 m_subplan_sp->SetPrivate (true);
Sean Callananbe3a1b12010-10-26 00:31:56489#endif
Chris Lattner30fdc8d2010-06-08 16:52:24490}
491
492bool
493ThreadPlanCallFunction::WillStop ()
494{
495 return true;
496}
497
498bool
499ThreadPlanCallFunction::MischiefManaged ()
500{
Greg Clayton5160ce52013-03-27 23:08:40501 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10502
Chris Lattner30fdc8d2010-06-08 16:52:24503 if (IsPlanComplete())
504 {
Chris Lattner30fdc8d2010-06-08 16:52:24505 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10506 log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.",
507 static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24508
509 ThreadPlan::MischiefManaged ();
510 return true;
511 }
512 else
513 {
514 return false;
515 }
516}
Sean Callanan6db73ca2010-11-03 01:37:52517
518void
519ThreadPlanCallFunction::SetBreakpoints ()
520{
Greg Clayton1ac04c32012-02-21 00:09:25521 ProcessSP process_sp (m_thread.CalculateProcess());
Jim Ingham6fbc48b2013-11-07 00:11:47522 if (m_trap_exceptions && process_sp)
Greg Clayton1ac04c32012-02-21 00:09:25523 {
524 m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus);
525 m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC);
Sean Callanan6db73ca2010-11-03 01:37:52526
Greg Clayton1ac04c32012-02-21 00:09:25527 if (m_cxx_language_runtime)
Jim Ingham6fbc48b2013-11-07 00:11:47528 {
529 m_should_clear_cxx_exception_bp = !m_cxx_language_runtime->ExceptionBreakpointsAreSet();
Greg Clayton1ac04c32012-02-21 00:09:25530 m_cxx_language_runtime->SetExceptionBreakpoints();
Jim Ingham6fbc48b2013-11-07 00:11:47531 }
Greg Clayton1ac04c32012-02-21 00:09:25532 if (m_objc_language_runtime)
Jim Ingham6fbc48b2013-11-07 00:11:47533 {
534 m_should_clear_objc_exception_bp = !m_objc_language_runtime->ExceptionBreakpointsAreSet();
Greg Clayton1ac04c32012-02-21 00:09:25535 m_objc_language_runtime->SetExceptionBreakpoints();
Jim Ingham6fbc48b2013-11-07 00:11:47536 }
Greg Clayton1ac04c32012-02-21 00:09:25537 }
Sean Callanan6db73ca2010-11-03 01:37:52538}
539
540void
541ThreadPlanCallFunction::ClearBreakpoints ()
542{
Jim Ingham6fbc48b2013-11-07 00:11:47543 if (m_trap_exceptions)
544 {
545 if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
546 m_cxx_language_runtime->ClearExceptionBreakpoints();
547 if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
548 m_objc_language_runtime->ClearExceptionBreakpoints();
549 }
Sean Callanan6db73ca2010-11-03 01:37:52550}
Sean Callananc98aca62010-11-03 19:36:28551
552bool
553ThreadPlanCallFunction::BreakpointsExplainStop()
554{
Jim Ingham60c41182013-06-04 01:40:51555 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Sean Callananc98aca62010-11-03 19:36:28556
Jim Ingham6fbc48b2013-11-07 00:11:47557 if (m_trap_exceptions)
Jim Ingham184e9812013-01-15 02:47:48558 {
Jim Ingham6fbc48b2013-11-07 00:11:47559 if ((m_cxx_language_runtime &&
560 m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))
561 ||(m_objc_language_runtime &&
562 m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)))
563 {
564 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
565 if (log)
566 log->Printf ("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an exception breakpoint, setting plan complete.");
567
568 SetPlanComplete(false);
569
570 // If the user has set the ObjC language breakpoint, it would normally get priority over our internal
571 // catcher breakpoint, but in this case we can't let that happen, so force the ShouldStop here.
572 stop_info_sp->OverrideShouldStop (true);
573 return true;
574 }
Jim Ingham184e9812013-01-15 02:47:48575 }
Sean Callananc98aca62010-11-03 19:36:28576
Sean Callananc98aca62010-11-03 19:36:28577 return false;
578}
Jim Ingham8559a352012-11-26 23:52:18579
Jim Ingham0ff099f2014-03-07 11:16:37580void
581ThreadPlanCallFunction::SetStopOthers (bool new_value)
582{
583 m_subplan_sp->SetStopOthers(new_value);
584}
585
586
Jim Ingham8559a352012-11-26 23:52:18587bool
588ThreadPlanCallFunction::RestoreThreadState()
589{
590 return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
591}
592
Ewan Crawford90ff7912015-07-14 10:56:58593
594void
595ThreadPlanCallFunction::SetReturnValue()
596{
597 ProcessSP process_sp(m_thread.GetProcess());
598 const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
599 if (abi && m_return_type.IsValid())
600 {
601 const bool persistent = false;
602 m_return_valobj_sp = abi->GetReturnValueObject(m_thread, m_return_type, persistent);
603 }
604}