130fdc8d8SChris Lattner //===-- ThreadPlanCallFunction.cpp ------------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1030fdc8d8SChris Lattner // C Includes 1130fdc8d8SChris Lattner // C++ Includes 1230fdc8d8SChris Lattner // Other libraries and framework includes 1330fdc8d8SChris Lattner // Project includes 14e65b2cf2SEugene Zelenko #include "lldb/Target/ThreadPlanCallFunction.h" 1540d871faSJim Ingham #include "lldb/Breakpoint/Breakpoint.h" 1640d871faSJim Ingham #include "lldb/Breakpoint/BreakpointLocation.h" 1730fdc8d8SChris Lattner #include "lldb/Core/Address.h" 1830fdc8d8SChris Lattner #include "lldb/Core/Log.h" 191f746071SGreg Clayton #include "lldb/Core/Module.h" 201f746071SGreg Clayton #include "lldb/Symbol/ObjectFile.h" 2132abc6edSZachary Turner #include "lldb/Target/ABI.h" 22f211510fSSean Callanan #include "lldb/Target/LanguageRuntime.h" 2330fdc8d8SChris Lattner #include "lldb/Target/Process.h" 2430fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h" 2540d871faSJim Ingham #include "lldb/Target/StopInfo.h" 2630fdc8d8SChris Lattner #include "lldb/Target/Target.h" 2730fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 2830fdc8d8SChris Lattner #include "lldb/Target/ThreadPlanRunToAddress.h" 29*bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 3030fdc8d8SChris Lattner 3130fdc8d8SChris Lattner using namespace lldb; 3230fdc8d8SChris Lattner using namespace lldb_private; 3330fdc8d8SChris Lattner 3430fdc8d8SChris Lattner //---------------------------------------------------------------------- 3530fdc8d8SChris Lattner // ThreadPlanCallFunction: Plan to call a single function 3630fdc8d8SChris Lattner //---------------------------------------------------------------------- 37b9c1b51eSKate Stone bool ThreadPlanCallFunction::ConstructorSetup( 38b9c1b51eSKate Stone Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr, 39b9c1b51eSKate Stone lldb::addr_t &function_load_addr) { 400092c8ebSJim Ingham SetIsMasterPlan(true); 41923886ceSJim Ingham SetOkayToDiscard(false); 42327c267aSAndrew Kaylor SetPrivate(true); 430092c8ebSJim Ingham 440092c8ebSJim Ingham ProcessSP process_sp(thread.GetProcess()); 450092c8ebSJim Ingham if (!process_sp) 460092c8ebSJim Ingham return false; 470092c8ebSJim Ingham 480092c8ebSJim Ingham abi = process_sp->GetABI().get(); 490092c8ebSJim Ingham 500092c8ebSJim Ingham if (!abi) 510092c8ebSJim Ingham return false; 520092c8ebSJim Ingham 535160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP)); 540092c8ebSJim Ingham 550092c8ebSJim Ingham SetBreakpoints(); 560092c8ebSJim Ingham 570092c8ebSJim Ingham m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize(); 58b9c1b51eSKate Stone // If we can't read memory at the point of the process where we are planning 59b9c1b51eSKate Stone // to put our function, we're 600092c8ebSJim Ingham // not going to get any further... 610092c8ebSJim Ingham Error error; 620092c8ebSJim Ingham process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error); 63b9c1b51eSKate Stone if (!error.Success()) { 64b9c1b51eSKate Stone m_constructor_errors.Printf( 65b9c1b51eSKate Stone "Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", 66b9c1b51eSKate Stone m_function_sp); 670092c8ebSJim Ingham if (log) 68b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this), 69324a1036SSaleem Abdulrasool m_constructor_errors.GetData()); 700092c8ebSJim Ingham return false; 710092c8ebSJim Ingham } 720092c8ebSJim Ingham 736fbc48bcSJim Ingham Module *exe_module = GetTarget().GetExecutableModulePointer(); 740092c8ebSJim Ingham 75b9c1b51eSKate Stone if (exe_module == nullptr) { 76b9c1b51eSKate Stone m_constructor_errors.Printf( 77b9c1b51eSKate Stone "Can't execute code without an executable module."); 780092c8ebSJim Ingham if (log) 79b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this), 80324a1036SSaleem Abdulrasool m_constructor_errors.GetData()); 810092c8ebSJim Ingham return false; 82b9c1b51eSKate Stone } else { 830092c8ebSJim Ingham ObjectFile *objectFile = exe_module->GetObjectFile(); 84b9c1b51eSKate Stone if (!objectFile) { 85b9c1b51eSKate Stone m_constructor_errors.Printf( 86b9c1b51eSKate Stone "Could not find object file for module \"%s\".", 87ea06f3bfSJim Ingham exe_module->GetFileSpec().GetFilename().AsCString()); 88ea06f3bfSJim Ingham 890092c8ebSJim Ingham if (log) 90324a1036SSaleem Abdulrasool log->Printf("ThreadPlanCallFunction(%p): %s.", 91b9c1b51eSKate Stone static_cast<void *>(this), m_constructor_errors.GetData()); 920092c8ebSJim Ingham return false; 930092c8ebSJim Ingham } 94ea06f3bfSJim Ingham 950092c8ebSJim Ingham m_start_addr = objectFile->GetEntryPointAddress(); 96b9c1b51eSKate Stone if (!m_start_addr.IsValid()) { 97b9c1b51eSKate Stone m_constructor_errors.Printf( 98b9c1b51eSKate Stone "Could not find entry point address for executable module \"%s\".", 99ea06f3bfSJim Ingham exe_module->GetFileSpec().GetFilename().AsCString()); 1000092c8ebSJim Ingham if (log) 101324a1036SSaleem Abdulrasool log->Printf("ThreadPlanCallFunction(%p): %s.", 102b9c1b51eSKate Stone static_cast<void *>(this), m_constructor_errors.GetData()); 1030092c8ebSJim Ingham return false; 1040092c8ebSJim Ingham } 1050092c8ebSJim Ingham } 1060092c8ebSJim Ingham 1076fbc48bcSJim Ingham start_load_addr = m_start_addr.GetLoadAddress(&GetTarget()); 1080092c8ebSJim Ingham 1090092c8ebSJim Ingham // Checkpoint the thread state so we can restore it later. 1100092c8ebSJim Ingham if (log && log->GetVerbose()) 111b9c1b51eSKate Stone ReportRegisterState("About to checkpoint thread before function call. " 112b9c1b51eSKate Stone "Original register state was:"); 1130092c8ebSJim Ingham 114b9c1b51eSKate Stone if (!thread.CheckpointThreadState(m_stored_thread_state)) { 115b9c1b51eSKate Stone m_constructor_errors.Printf("Setting up ThreadPlanCallFunction, failed to " 116b9c1b51eSKate Stone "checkpoint thread state."); 1170092c8ebSJim Ingham if (log) 118b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this), 119324a1036SSaleem Abdulrasool m_constructor_errors.GetData()); 1200092c8ebSJim Ingham return false; 1210092c8ebSJim Ingham } 1226fbc48bcSJim Ingham function_load_addr = m_function_addr.GetLoadAddress(&GetTarget()); 1230092c8ebSJim Ingham 1240092c8ebSJim Ingham return true; 1250092c8ebSJim Ingham } 12630fdc8d8SChris Lattner 127b9c1b51eSKate Stone ThreadPlanCallFunction::ThreadPlanCallFunction( 128b9c1b51eSKate Stone Thread &thread, const Address &function, const CompilerType &return_type, 129b9c1b51eSKate Stone llvm::ArrayRef<addr_t> args, const EvaluateExpressionOptions &options) 130b9c1b51eSKate Stone : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread, 131b9c1b51eSKate Stone eVoteNoOpinion, eVoteNoOpinion), 132b9c1b51eSKate Stone m_valid(false), m_stop_other_threads(options.GetStopOthers()), 1336fbc48bcSJim Ingham m_unwind_on_error(options.DoesUnwindOnError()), 1346fbc48bcSJim Ingham m_ignore_breakpoints(options.DoesIgnoreBreakpoints()), 1356fbc48bcSJim Ingham m_debug_execution(options.GetDebug()), 136b9c1b51eSKate Stone m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function), 137b9c1b51eSKate Stone m_function_sp(0), m_takedown_done(false), 1386fbc48bcSJim Ingham m_should_clear_objc_exception_bp(false), 1396fbc48bcSJim Ingham m_should_clear_cxx_exception_bp(false), 140b9c1b51eSKate Stone m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(return_type) { 14190ff7911SEwan Crawford lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS; 14290ff7911SEwan Crawford lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS; 14390ff7911SEwan Crawford ABI *abi = nullptr; 14490ff7911SEwan Crawford 145923886ceSJim Ingham if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr)) 1461ac04c30SGreg Clayton return; 1471ac04c30SGreg Clayton 148b9c1b51eSKate Stone if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr, 149b9c1b51eSKate Stone start_load_addr, args)) 15030fdc8d8SChris Lattner return; 15130fdc8d8SChris Lattner 1529da3683cSJim Ingham ReportRegisterState("Function call was set up. Register state was:"); 1539da3683cSJim Ingham 1549da3683cSJim Ingham m_valid = true; 1559da3683cSJim Ingham } 1569da3683cSJim Ingham 157b9c1b51eSKate Stone ThreadPlanCallFunction::ThreadPlanCallFunction( 158b9c1b51eSKate Stone Thread &thread, const Address &function, 159b9c1b51eSKate Stone const EvaluateExpressionOptions &options) 160b9c1b51eSKate Stone : ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread, 161b9c1b51eSKate Stone eVoteNoOpinion, eVoteNoOpinion), 162b9c1b51eSKate Stone m_valid(false), m_stop_other_threads(options.GetStopOthers()), 16390ff7911SEwan Crawford m_unwind_on_error(options.DoesUnwindOnError()), 16490ff7911SEwan Crawford m_ignore_breakpoints(options.DoesIgnoreBreakpoints()), 16590ff7911SEwan Crawford m_debug_execution(options.GetDebug()), 166b9c1b51eSKate Stone m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function), 167b9c1b51eSKate Stone m_function_sp(0), m_takedown_done(false), 16890ff7911SEwan Crawford m_should_clear_objc_exception_bp(false), 16990ff7911SEwan Crawford m_should_clear_cxx_exception_bp(false), 170b9c1b51eSKate Stone m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {} 17190ff7911SEwan Crawford 172b9c1b51eSKate Stone ThreadPlanCallFunction::~ThreadPlanCallFunction() { 1730161b49cSJim Ingham DoTakedown(PlanSucceeded()); 1749da3683cSJim Ingham } 1759da3683cSJim Ingham 176b9c1b51eSKate Stone void ThreadPlanCallFunction::ReportRegisterState(const char *message) { 177b9c1b51eSKate Stone Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP | 178b9c1b51eSKate Stone LIBLLDB_LOG_VERBOSE)); 179b9c1b51eSKate Stone if (log) { 180af247d7bSGreg Clayton StreamString strm; 1815ccbd294SGreg Clayton RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); 182ece96492SSean Callanan 1839da3683cSJim Ingham log->PutCString(message); 184ece96492SSean Callanan 185af247d7bSGreg Clayton RegisterValue reg_value; 186ece96492SSean Callanan 187af247d7bSGreg Clayton for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount(); 188b9c1b51eSKate Stone reg_idx < num_registers; ++reg_idx) { 189af247d7bSGreg Clayton const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx); 190b9c1b51eSKate Stone if (reg_ctx->ReadRegister(reg_info, reg_value)) { 191af247d7bSGreg Clayton reg_value.Dump(&strm, reg_info, true, false, eFormatDefault); 192af247d7bSGreg Clayton strm.EOL(); 193ece96492SSean Callanan } 194ece96492SSean Callanan } 195c156427dSZachary Turner log->PutString(strm.GetString()); 196af247d7bSGreg Clayton } 19710af7c43SSean Callanan } 19810af7c43SSean Callanan 199b9c1b51eSKate Stone void ThreadPlanCallFunction::DoTakedown(bool success) { 2005160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP)); 20187d0e618SJim Ingham 202b9c1b51eSKate Stone if (!m_valid) { 20387d0e618SJim Ingham // Don't call DoTakedown if we were never valid to begin with. 20487d0e618SJim Ingham if (log) 205b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction(%p): Log called on " 206b9c1b51eSKate Stone "ThreadPlanCallFunction that was never valid.", 207324a1036SSaleem Abdulrasool static_cast<void *>(this)); 20887d0e618SJim Ingham return; 20987d0e618SJim Ingham } 21087d0e618SJim Ingham 211b9c1b51eSKate Stone if (!m_takedown_done) { 212b9c1b51eSKate Stone if (success) { 21390ff7911SEwan Crawford SetReturnValue(); 21418de2fdcSJim Ingham } 2159da3683cSJim Ingham if (log) 216b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction(%p): DoTakedown called for thread " 217b9c1b51eSKate Stone "0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n", 218324a1036SSaleem Abdulrasool static_cast<void *>(this), m_thread.GetID(), m_valid, 219324a1036SSaleem Abdulrasool IsPlanComplete()); 2209da3683cSJim Ingham m_takedown_done = true; 221b9c1b51eSKate Stone m_stop_address = 222b9c1b51eSKate Stone m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC(); 22360c4118cSJim Ingham m_real_stop_info_sp = GetPrivateStopInfo(); 224b9c1b51eSKate Stone if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) { 2257b24e95eSEd Maste if (log) 226b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore " 227b9c1b51eSKate Stone "register state", 228324a1036SSaleem Abdulrasool static_cast<void *>(this)); 2297b24e95eSEd Maste } 23018de2fdcSJim Ingham SetPlanComplete(success); 23110af7c43SSean Callanan ClearBreakpoints(); 2329da3683cSJim Ingham if (log && log->GetVerbose()) 233b9c1b51eSKate Stone ReportRegisterState("Restoring thread state after function call. " 234b9c1b51eSKate Stone "Restored register state:"); 235b9c1b51eSKate Stone } else { 2369da3683cSJim Ingham if (log) 237b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction(%p): DoTakedown called as no-op for " 238b9c1b51eSKate Stone "thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n", 239324a1036SSaleem Abdulrasool static_cast<void *>(this), m_thread.GetID(), m_valid, 240324a1036SSaleem Abdulrasool IsPlanComplete()); 24130fdc8d8SChris Lattner } 24277787033SJim Ingham } 24330fdc8d8SChris Lattner 244b9c1b51eSKate Stone void ThreadPlanCallFunction::WillPop() { DoTakedown(PlanSucceeded()); } 245bda4e5ebSJim Ingham 246b9c1b51eSKate Stone void ThreadPlanCallFunction::GetDescription(Stream *s, DescriptionLevel level) { 247b9c1b51eSKate Stone if (level == eDescriptionLevelBrief) { 24830fdc8d8SChris Lattner s->Printf("Function call thread plan"); 249b9c1b51eSKate Stone } else { 2501ac04c30SGreg Clayton TargetSP target_sp(m_thread.CalculateTarget()); 251b9c1b51eSKate Stone s->Printf("Thread plan to call 0x%" PRIx64, 252b9c1b51eSKate Stone m_function_addr.GetLoadAddress(target_sp.get())); 25330fdc8d8SChris Lattner } 25430fdc8d8SChris Lattner } 25530fdc8d8SChris Lattner 256b9c1b51eSKate Stone bool ThreadPlanCallFunction::ValidatePlan(Stream *error) { 257b9c1b51eSKate Stone if (!m_valid) { 258b9c1b51eSKate Stone if (error) { 259ea06f3bfSJim Ingham if (m_constructor_errors.GetSize() > 0) 260c156427dSZachary Turner error->PutCString(m_constructor_errors.GetString()); 261ea06f3bfSJim Ingham else 262ea06f3bfSJim Ingham error->PutCString("Unknown error"); 263ea06f3bfSJim Ingham } 26430fdc8d8SChris Lattner return false; 265ea06f3bfSJim Ingham } 26630fdc8d8SChris Lattner 26730fdc8d8SChris Lattner return true; 26830fdc8d8SChris Lattner } 26930fdc8d8SChris Lattner 270b9c1b51eSKate Stone Vote ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) { 2710161b49cSJim Ingham if (m_takedown_done || IsPlanComplete()) 2720161b49cSJim Ingham return eVoteYes; 2730161b49cSJim Ingham else 2740161b49cSJim Ingham return ThreadPlan::ShouldReportStop(event_ptr); 2750161b49cSJim Ingham } 2760161b49cSJim Ingham 277b9c1b51eSKate Stone bool ThreadPlanCallFunction::DoPlanExplainsStop(Event *event_ptr) { 278b9c1b51eSKate Stone Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP | 279b9c1b51eSKate Stone LIBLLDB_LOG_PROCESS)); 28060c4118cSJim Ingham m_real_stop_info_sp = GetPrivateStopInfo(); 281160f78c5SJim Ingham 282b9c1b51eSKate Stone // If our subplan knows why we stopped, even if it's done (which would forward 283b9c1b51eSKate Stone // the question to us) 28440d871faSJim Ingham // we answer yes. 285b9c1b51eSKate Stone if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr)) { 286184e9811SJim Ingham SetPlanComplete(); 28740d871faSJim Ingham return true; 288184e9811SJim Ingham } 2893e6fedcaSSean Callanan 290c98aca60SSean Callanan // Check if the breakpoint is one of ours. 291c98aca60SSean Callanan 29218de2fdcSJim Ingham StopReason stop_reason; 29318de2fdcSJim Ingham if (!m_real_stop_info_sp) 29418de2fdcSJim Ingham stop_reason = eStopReasonNone; 29518de2fdcSJim Ingham else 29618de2fdcSJim Ingham stop_reason = m_real_stop_info_sp->GetStopReason(); 2970161b49cSJim Ingham if (log) 298b9c1b51eSKate Stone log->Printf( 299b9c1b51eSKate Stone "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.", 300b9c1b51eSKate Stone Thread::StopReasonAsCString(stop_reason)); 30118de2fdcSJim Ingham 30218de2fdcSJim Ingham if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop()) 303c98aca60SSean Callanan return true; 304c98aca60SSean Callanan 305b9c1b51eSKate Stone // One more quirk here. If this event was from Halt interrupting the target, 306b9c1b51eSKate Stone // then we should not consider 30735878c47SJim Ingham // ourselves complete. Return true to acknowledge the stop. 308b9c1b51eSKate Stone if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr)) { 30935878c47SJim Ingham if (log) 310b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction::PlanExplainsStop: The event is an " 311b9c1b51eSKate Stone "Interrupt, returning true."); 31235878c47SJim Ingham return true; 31335878c47SJim Ingham } 3140161b49cSJim Ingham // We control breakpoints separately from other "stop reasons." So first, 315b9c1b51eSKate Stone // check the case where we stopped for an internal breakpoint, in that case, 316b9c1b51eSKate Stone // continue on. 3170161b49cSJim Ingham // If it is not an internal breakpoint, consult m_ignore_breakpoints. 3186db73ca5SSean Callanan 319b9c1b51eSKate Stone if (stop_reason == eStopReasonBreakpoint) { 3201ac04c30SGreg Clayton ProcessSP process_sp(m_thread.CalculateProcess()); 321160f78c5SJim Ingham uint64_t break_site_id = m_real_stop_info_sp->GetValue(); 3221ac04c30SGreg Clayton BreakpointSiteSP bp_site_sp; 3231ac04c30SGreg Clayton if (process_sp) 3241ac04c30SGreg Clayton bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id); 325b9c1b51eSKate Stone if (bp_site_sp) { 32640d871faSJim Ingham uint32_t num_owners = bp_site_sp->GetNumberOfOwners(); 32740d871faSJim Ingham bool is_internal = true; 328b9c1b51eSKate Stone for (uint32_t i = 0; i < num_owners; i++) { 3296db73ca5SSean Callanan Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint(); 3300161b49cSJim Ingham if (log) 331b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction::PlanExplainsStop: hit " 332b9c1b51eSKate Stone "breakpoint %d while calling function", 333b9c1b51eSKate Stone bp.GetID()); 3346db73ca5SSean Callanan 335b9c1b51eSKate Stone if (!bp.IsInternal()) { 33640d871faSJim Ingham is_internal = false; 33740d871faSJim Ingham break; 33840d871faSJim Ingham } 33940d871faSJim Ingham } 340b9c1b51eSKate Stone if (is_internal) { 3410161b49cSJim Ingham if (log) 342b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction::PlanExplainsStop hit an " 343b9c1b51eSKate Stone "internal breakpoint, not stopping."); 34440d871faSJim Ingham return false; 34540d871faSJim Ingham } 3460161b49cSJim Ingham } 34740d871faSJim Ingham 348b9c1b51eSKate Stone if (m_ignore_breakpoints) { 3490161b49cSJim Ingham if (log) 350b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring " 351b9c1b51eSKate Stone "breakpoints, overriding breakpoint stop info ShouldStop, " 352b9c1b51eSKate Stone "returning true"); 3530161b49cSJim Ingham m_real_stop_info_sp->OverrideShouldStop(false); 354923886ceSJim Ingham return true; 355b9c1b51eSKate Stone } else { 3560161b49cSJim Ingham if (log) 357b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not " 358b9c1b51eSKate Stone "ignoring breakpoints, overriding breakpoint stop info " 359b9c1b51eSKate Stone "ShouldStop, returning true"); 3600161b49cSJim Ingham m_real_stop_info_sp->OverrideShouldStop(true); 3610161b49cSJim Ingham return false; 3620161b49cSJim Ingham } 363b9c1b51eSKate Stone } else if (!m_unwind_on_error) { 364b9c1b51eSKate Stone // If we don't want to discard this plan, than any stop we don't understand 365b9c1b51eSKate Stone // should be propagated up the stack. 366923886ceSJim Ingham return false; 367b9c1b51eSKate Stone } else { 36840d871faSJim Ingham // If the subplan is running, any crashes are attributable to us. 3692c36439cSJim Ingham // If we want to discard the plan, then we say we explain the stop 3702c36439cSJim Ingham // but if we are going to be discarded, let whoever is above us 3712c36439cSJim Ingham // explain the stop. 372b9c1b51eSKate Stone // But don't discard the plan if the stop would restart itself (for instance 373b9c1b51eSKate Stone // if it is a 374b9c1b51eSKate Stone // signal that is set not to stop. Check that here first. We just say we 375b9c1b51eSKate Stone // explain the stop 3760161b49cSJim Ingham // but aren't done and everything will continue on from there. 3770161b49cSJim Ingham 378b9c1b51eSKate Stone if (m_real_stop_info_sp && 379b9c1b51eSKate Stone m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) { 380184e9811SJim Ingham SetPlanComplete(false); 381e65b2cf2SEugene Zelenko return m_subplan_sp ? m_unwind_on_error : false; 382b9c1b51eSKate Stone } else 3830161b49cSJim Ingham return true; 3840161b49cSJim Ingham } 38540d871faSJim Ingham } 38630fdc8d8SChris Lattner 387b9c1b51eSKate Stone bool ThreadPlanCallFunction::ShouldStop(Event *event_ptr) { 388b9c1b51eSKate Stone // We do some computation in DoPlanExplainsStop that may or may not set the 389b9c1b51eSKate Stone // plan as complete. 390184e9811SJim Ingham // We need to do that here to make sure our state is correct. 391221d51cfSJim Ingham DoPlanExplainsStop(event_ptr); 392184e9811SJim Ingham 393b9c1b51eSKate Stone if (IsPlanComplete()) { 3949da3683cSJim Ingham ReportRegisterState("Function completed. Register state was:"); 39530fdc8d8SChris Lattner return true; 396b9c1b51eSKate Stone } else { 39730fdc8d8SChris Lattner return false; 39830fdc8d8SChris Lattner } 39930fdc8d8SChris Lattner } 40030fdc8d8SChris Lattner 401b9c1b51eSKate Stone bool ThreadPlanCallFunction::StopOthers() { return m_stop_other_threads; } 40230fdc8d8SChris Lattner 403b9c1b51eSKate Stone StateType ThreadPlanCallFunction::GetPlanRunState() { return eStateRunning; } 40430fdc8d8SChris Lattner 405b9c1b51eSKate Stone void ThreadPlanCallFunction::DidPush() { 406be3a1b14SSean Callanan //#define SINGLE_STEP_EXPRESSIONS 407be3a1b14SSean Callanan 408b9c1b51eSKate Stone // Now set the thread state to "no reason" so we don't run with whatever 409b9c1b51eSKate Stone // signal was outstanding... 410b9c1b51eSKate Stone // Wait till the plan is pushed so we aren't changing the stop info till we're 411b9c1b51eSKate Stone // about to run. 4128559a355SJim Ingham 4138559a355SJim Ingham GetThread().SetStopInfoToNothing(); 4148559a355SJim Ingham 415be3a1b14SSean Callanan #ifndef SINGLE_STEP_EXPRESSIONS 416b9c1b51eSKate Stone m_subplan_sp.reset( 417b9c1b51eSKate Stone new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads)); 41830fdc8d8SChris Lattner 41930fdc8d8SChris Lattner m_thread.QueueThreadPlan(m_subplan_sp, false); 42077787033SJim Ingham m_subplan_sp->SetPrivate(true); 421be3a1b14SSean Callanan #endif 42230fdc8d8SChris Lattner } 42330fdc8d8SChris Lattner 424b9c1b51eSKate Stone bool ThreadPlanCallFunction::WillStop() { return true; } 42530fdc8d8SChris Lattner 426b9c1b51eSKate Stone bool ThreadPlanCallFunction::MischiefManaged() { 4275160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 42830fdc8d8SChris Lattner 429b9c1b51eSKate Stone if (IsPlanComplete()) { 43030fdc8d8SChris Lattner if (log) 431324a1036SSaleem Abdulrasool log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", 432324a1036SSaleem Abdulrasool static_cast<void *>(this)); 43330fdc8d8SChris Lattner 43430fdc8d8SChris Lattner ThreadPlan::MischiefManaged(); 43530fdc8d8SChris Lattner return true; 436b9c1b51eSKate Stone } else { 43730fdc8d8SChris Lattner return false; 43830fdc8d8SChris Lattner } 43930fdc8d8SChris Lattner } 4406db73ca5SSean Callanan 441b9c1b51eSKate Stone void ThreadPlanCallFunction::SetBreakpoints() { 4421ac04c30SGreg Clayton ProcessSP process_sp(m_thread.CalculateProcess()); 443b9c1b51eSKate Stone if (m_trap_exceptions && process_sp) { 444b9c1b51eSKate Stone m_cxx_language_runtime = 445b9c1b51eSKate Stone process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus); 4461ac04c30SGreg Clayton m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC); 4476db73ca5SSean Callanan 448b9c1b51eSKate Stone if (m_cxx_language_runtime) { 449b9c1b51eSKate Stone m_should_clear_cxx_exception_bp = 450b9c1b51eSKate Stone !m_cxx_language_runtime->ExceptionBreakpointsAreSet(); 451f211510fSSean Callanan m_cxx_language_runtime->SetExceptionBreakpoints(); 4526fbc48bcSJim Ingham } 453b9c1b51eSKate Stone if (m_objc_language_runtime) { 454b9c1b51eSKate Stone m_should_clear_objc_exception_bp = 455b9c1b51eSKate Stone !m_objc_language_runtime->ExceptionBreakpointsAreSet(); 456f211510fSSean Callanan m_objc_language_runtime->SetExceptionBreakpoints(); 4576db73ca5SSean Callanan } 4581ac04c30SGreg Clayton } 4596fbc48bcSJim Ingham } 4606db73ca5SSean Callanan 461b9c1b51eSKate Stone void ThreadPlanCallFunction::ClearBreakpoints() { 462b9c1b51eSKate Stone if (m_trap_exceptions) { 4636fbc48bcSJim Ingham if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp) 464f211510fSSean Callanan m_cxx_language_runtime->ClearExceptionBreakpoints(); 4656fbc48bcSJim Ingham if (m_objc_language_runtime && m_should_clear_objc_exception_bp) 466f211510fSSean Callanan m_objc_language_runtime->ClearExceptionBreakpoints(); 4676db73ca5SSean Callanan } 4686fbc48bcSJim Ingham } 469c98aca60SSean Callanan 470b9c1b51eSKate Stone bool ThreadPlanCallFunction::BreakpointsExplainStop() { 47160c4118cSJim Ingham StopInfoSP stop_info_sp = GetPrivateStopInfo(); 472c98aca60SSean Callanan 473b9c1b51eSKate Stone if (m_trap_exceptions) { 474184e9811SJim Ingham if ((m_cxx_language_runtime && 475b9c1b51eSKate Stone m_cxx_language_runtime->ExceptionBreakpointsExplainStop( 476b9c1b51eSKate Stone stop_info_sp)) || 477b9c1b51eSKate Stone (m_objc_language_runtime && 478b9c1b51eSKate Stone m_objc_language_runtime->ExceptionBreakpointsExplainStop( 479b9c1b51eSKate Stone stop_info_sp))) { 480641a67ceSJim Ingham Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP)); 481641a67ceSJim Ingham if (log) 482b9c1b51eSKate Stone log->Printf("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an " 483b9c1b51eSKate Stone "exception breakpoint, setting plan complete."); 484641a67ceSJim Ingham 485184e9811SJim Ingham SetPlanComplete(false); 486641a67ceSJim Ingham 487b9c1b51eSKate Stone // If the user has set the ObjC language breakpoint, it would normally get 488b9c1b51eSKate Stone // priority over our internal 489b9c1b51eSKate Stone // catcher breakpoint, but in this case we can't let that happen, so force 490b9c1b51eSKate Stone // the ShouldStop here. 491641a67ceSJim Ingham stop_info_sp->OverrideShouldStop(true); 492c98aca60SSean Callanan return true; 493184e9811SJim Ingham } 4946fbc48bcSJim Ingham } 495f211510fSSean Callanan 496c98aca60SSean Callanan return false; 497c98aca60SSean Callanan } 4988559a355SJim Ingham 499b9c1b51eSKate Stone void ThreadPlanCallFunction::SetStopOthers(bool new_value) { 5000ff099f1SJim Ingham m_subplan_sp->SetStopOthers(new_value); 5010ff099f1SJim Ingham } 5020ff099f1SJim Ingham 503b9c1b51eSKate Stone bool ThreadPlanCallFunction::RestoreThreadState() { 5048559a355SJim Ingham return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state); 5058559a355SJim Ingham } 5068559a355SJim Ingham 507b9c1b51eSKate Stone void ThreadPlanCallFunction::SetReturnValue() { 50890ff7911SEwan Crawford ProcessSP process_sp(m_thread.GetProcess()); 509e65b2cf2SEugene Zelenko const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr; 510b9c1b51eSKate Stone if (abi && m_return_type.IsValid()) { 51190ff7911SEwan Crawford const bool persistent = false; 512b9c1b51eSKate Stone m_return_valobj_sp = 513b9c1b51eSKate Stone abi->GetReturnValueObject(m_thread, m_return_type, persistent); 51490ff7911SEwan Crawford } 51590ff7911SEwan Crawford } 516