1ac7ddfbfSEd Maste //===-- ThreadPlanCallFunction.cpp ------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlanCallFunction.h" 11ac7ddfbfSEd Maste 12ac7ddfbfSEd Maste // C Includes 13ac7ddfbfSEd Maste // C++ Includes 14ac7ddfbfSEd Maste // Other libraries and framework includes 15ac7ddfbfSEd Maste #include "llvm/Support/MachO.h" 16ac7ddfbfSEd Maste // Project includes 17ac7ddfbfSEd Maste #include "lldb/lldb-private-log.h" 18ac7ddfbfSEd Maste #include "lldb/Breakpoint/Breakpoint.h" 19ac7ddfbfSEd Maste #include "lldb/Breakpoint/BreakpointLocation.h" 20ac7ddfbfSEd Maste #include "lldb/Core/Address.h" 21ac7ddfbfSEd Maste #include "lldb/Core/Log.h" 22ac7ddfbfSEd Maste #include "lldb/Core/Module.h" 23ac7ddfbfSEd Maste #include "lldb/Core/Stream.h" 24ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h" 25ac7ddfbfSEd Maste #include "lldb/Target/LanguageRuntime.h" 26ac7ddfbfSEd Maste #include "lldb/Target/Process.h" 27ac7ddfbfSEd Maste #include "lldb/Target/RegisterContext.h" 28ac7ddfbfSEd Maste #include "lldb/Target/StopInfo.h" 29ac7ddfbfSEd Maste #include "lldb/Target/Target.h" 30ac7ddfbfSEd Maste #include "lldb/Target/Thread.h" 31ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlanRunToAddress.h" 32ac7ddfbfSEd Maste 33ac7ddfbfSEd Maste using namespace lldb; 34ac7ddfbfSEd Maste using namespace lldb_private; 35ac7ddfbfSEd Maste 36ac7ddfbfSEd Maste //---------------------------------------------------------------------- 37ac7ddfbfSEd Maste // ThreadPlanCallFunction: Plan to call a single function 38ac7ddfbfSEd Maste //---------------------------------------------------------------------- 39ac7ddfbfSEd Maste bool 40ac7ddfbfSEd Maste ThreadPlanCallFunction::ConstructorSetup (Thread &thread, 41ac7ddfbfSEd Maste ABI *& abi, 42ac7ddfbfSEd Maste lldb::addr_t &start_load_addr, 43ac7ddfbfSEd Maste lldb::addr_t &function_load_addr) 44ac7ddfbfSEd Maste { 45ac7ddfbfSEd Maste SetIsMasterPlan (true); 46ac7ddfbfSEd Maste SetOkayToDiscard (false); 47ac7ddfbfSEd Maste SetPrivate (true); 48ac7ddfbfSEd Maste 49ac7ddfbfSEd Maste ProcessSP process_sp (thread.GetProcess()); 50ac7ddfbfSEd Maste if (!process_sp) 51ac7ddfbfSEd Maste return false; 52ac7ddfbfSEd Maste 53ac7ddfbfSEd Maste abi = process_sp->GetABI().get(); 54ac7ddfbfSEd Maste 55ac7ddfbfSEd Maste if (!abi) 56ac7ddfbfSEd Maste return false; 57ac7ddfbfSEd Maste 58ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP)); 59ac7ddfbfSEd Maste 60ac7ddfbfSEd Maste SetBreakpoints(); 61ac7ddfbfSEd Maste 62ac7ddfbfSEd Maste m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize(); 63ac7ddfbfSEd Maste // If we can't read memory at the point of the process where we are planning to put our function, we're 64ac7ddfbfSEd Maste // not going to get any further... 65ac7ddfbfSEd Maste Error error; 66ac7ddfbfSEd Maste process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error); 67ac7ddfbfSEd Maste if (!error.Success()) 68ac7ddfbfSEd Maste { 69ac7ddfbfSEd Maste m_constructor_errors.Printf ("Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", m_function_sp); 70ac7ddfbfSEd Maste if (log) 71ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); 72ac7ddfbfSEd Maste return false; 73ac7ddfbfSEd Maste } 74ac7ddfbfSEd Maste 75b952cd58SEd Maste Module *exe_module = GetTarget().GetExecutableModulePointer(); 76ac7ddfbfSEd Maste 77ac7ddfbfSEd Maste if (exe_module == NULL) 78ac7ddfbfSEd Maste { 79ac7ddfbfSEd Maste m_constructor_errors.Printf ("Can't execute code without an executable module."); 80ac7ddfbfSEd Maste if (log) 81ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); 82ac7ddfbfSEd Maste return false; 83ac7ddfbfSEd Maste } 84ac7ddfbfSEd Maste else 85ac7ddfbfSEd Maste { 86ac7ddfbfSEd Maste ObjectFile *objectFile = exe_module->GetObjectFile(); 87ac7ddfbfSEd Maste if (!objectFile) 88ac7ddfbfSEd Maste { 89ac7ddfbfSEd Maste m_constructor_errors.Printf ("Could not find object file for module \"%s\".", 90ac7ddfbfSEd Maste exe_module->GetFileSpec().GetFilename().AsCString()); 91ac7ddfbfSEd Maste 92ac7ddfbfSEd Maste if (log) 93ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); 94ac7ddfbfSEd Maste return false; 95ac7ddfbfSEd Maste } 96ac7ddfbfSEd Maste 97ac7ddfbfSEd Maste m_start_addr = objectFile->GetEntryPointAddress(); 98ac7ddfbfSEd Maste if (!m_start_addr.IsValid()) 99ac7ddfbfSEd Maste { 100ac7ddfbfSEd Maste m_constructor_errors.Printf ("Could not find entry point address for executable module \"%s\".", 101ac7ddfbfSEd Maste exe_module->GetFileSpec().GetFilename().AsCString()); 102ac7ddfbfSEd Maste if (log) 103ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); 104ac7ddfbfSEd Maste return false; 105ac7ddfbfSEd Maste } 106ac7ddfbfSEd Maste } 107ac7ddfbfSEd Maste 108b952cd58SEd Maste start_load_addr = m_start_addr.GetLoadAddress (&GetTarget()); 109ac7ddfbfSEd Maste 110ac7ddfbfSEd Maste // Checkpoint the thread state so we can restore it later. 111ac7ddfbfSEd Maste if (log && log->GetVerbose()) 112ac7ddfbfSEd Maste ReportRegisterState ("About to checkpoint thread before function call. Original register state was:"); 113ac7ddfbfSEd Maste 114ac7ddfbfSEd Maste if (!thread.CheckpointThreadState (m_stored_thread_state)) 115ac7ddfbfSEd Maste { 116ac7ddfbfSEd Maste m_constructor_errors.Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state."); 117ac7ddfbfSEd Maste if (log) 118ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); 119ac7ddfbfSEd Maste return false; 120ac7ddfbfSEd Maste } 121b952cd58SEd Maste function_load_addr = m_function_addr.GetLoadAddress (&GetTarget()); 122ac7ddfbfSEd Maste 123ac7ddfbfSEd Maste return true; 124ac7ddfbfSEd Maste } 125ac7ddfbfSEd Maste 126ac7ddfbfSEd Maste ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread, 127ac7ddfbfSEd Maste const Address &function, 128ac7ddfbfSEd Maste const ClangASTType &return_type, 129b952cd58SEd Maste llvm::ArrayRef<addr_t> args, 130b952cd58SEd Maste const EvaluateExpressionOptions &options) : 131ac7ddfbfSEd Maste ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion), 132ac7ddfbfSEd Maste m_valid (false), 133b952cd58SEd Maste m_stop_other_threads (options.GetStopOthers()), 134b952cd58SEd Maste m_unwind_on_error (options.DoesUnwindOnError()), 135b952cd58SEd Maste m_ignore_breakpoints (options.DoesIgnoreBreakpoints()), 136b952cd58SEd Maste m_debug_execution (options.GetDebug()), 137b952cd58SEd Maste m_trap_exceptions (options.GetTrapExceptions()), 138ac7ddfbfSEd Maste m_function_addr (function), 139ac7ddfbfSEd Maste m_function_sp (0), 140ac7ddfbfSEd Maste m_return_type (return_type), 141ac7ddfbfSEd Maste m_takedown_done (false), 142b952cd58SEd Maste m_should_clear_objc_exception_bp(false), 143b952cd58SEd Maste m_should_clear_cxx_exception_bp (false), 144b952cd58SEd Maste m_stop_address (LLDB_INVALID_ADDRESS) 145ac7ddfbfSEd Maste { 146ac7ddfbfSEd Maste lldb::addr_t start_load_addr; 147ac7ddfbfSEd Maste ABI *abi; 148ac7ddfbfSEd Maste lldb::addr_t function_load_addr; 149ac7ddfbfSEd Maste if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr)) 150ac7ddfbfSEd Maste return; 151ac7ddfbfSEd Maste 152ac7ddfbfSEd Maste if (!abi->PrepareTrivialCall(thread, 153ac7ddfbfSEd Maste m_function_sp, 154ac7ddfbfSEd Maste function_load_addr, 155ac7ddfbfSEd Maste start_load_addr, 156b952cd58SEd Maste args)) 157ac7ddfbfSEd Maste return; 158ac7ddfbfSEd Maste 159ac7ddfbfSEd Maste ReportRegisterState ("Function call was set up. Register state was:"); 160ac7ddfbfSEd Maste 161ac7ddfbfSEd Maste m_valid = true; 162ac7ddfbfSEd Maste } 163ac7ddfbfSEd Maste 164ac7ddfbfSEd Maste ThreadPlanCallFunction::~ThreadPlanCallFunction () 165ac7ddfbfSEd Maste { 166ac7ddfbfSEd Maste DoTakedown(PlanSucceeded()); 167ac7ddfbfSEd Maste } 168ac7ddfbfSEd Maste 169ac7ddfbfSEd Maste void 170ac7ddfbfSEd Maste ThreadPlanCallFunction::ReportRegisterState (const char *message) 171ac7ddfbfSEd Maste { 172ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE)); 173ac7ddfbfSEd Maste if (log) 174ac7ddfbfSEd Maste { 175ac7ddfbfSEd Maste StreamString strm; 176ac7ddfbfSEd Maste RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); 177ac7ddfbfSEd Maste 178ac7ddfbfSEd Maste log->PutCString(message); 179ac7ddfbfSEd Maste 180ac7ddfbfSEd Maste RegisterValue reg_value; 181ac7ddfbfSEd Maste 182ac7ddfbfSEd Maste for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount(); 183ac7ddfbfSEd Maste reg_idx < num_registers; 184ac7ddfbfSEd Maste ++reg_idx) 185ac7ddfbfSEd Maste { 186ac7ddfbfSEd Maste const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 187ac7ddfbfSEd Maste if (reg_ctx->ReadRegister(reg_info, reg_value)) 188ac7ddfbfSEd Maste { 189ac7ddfbfSEd Maste reg_value.Dump(&strm, reg_info, true, false, eFormatDefault); 190ac7ddfbfSEd Maste strm.EOL(); 191ac7ddfbfSEd Maste } 192ac7ddfbfSEd Maste } 193ac7ddfbfSEd Maste log->PutCString(strm.GetData()); 194ac7ddfbfSEd Maste } 195ac7ddfbfSEd Maste } 196ac7ddfbfSEd Maste 197ac7ddfbfSEd Maste void 198ac7ddfbfSEd Maste ThreadPlanCallFunction::DoTakedown (bool success) 199ac7ddfbfSEd Maste { 200ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP)); 201ac7ddfbfSEd Maste 202ac7ddfbfSEd Maste if (!m_valid) 203ac7ddfbfSEd Maste { 204ac7ddfbfSEd Maste //Don't call DoTakedown if we were never valid to begin with. 205ac7ddfbfSEd Maste if (log) 206ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.", this); 207ac7ddfbfSEd Maste return; 208ac7ddfbfSEd Maste } 209ac7ddfbfSEd Maste 210ac7ddfbfSEd Maste if (!m_takedown_done) 211ac7ddfbfSEd Maste { 212ac7ddfbfSEd Maste if (success) 213ac7ddfbfSEd Maste { 214ac7ddfbfSEd Maste ProcessSP process_sp (m_thread.GetProcess()); 215ac7ddfbfSEd Maste const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL; 216ac7ddfbfSEd Maste if (abi && m_return_type.IsValid()) 217ac7ddfbfSEd Maste { 218ac7ddfbfSEd Maste const bool persistent = false; 219ac7ddfbfSEd Maste m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent); 220ac7ddfbfSEd Maste } 221ac7ddfbfSEd Maste } 222ac7ddfbfSEd Maste if (log) 223ac7ddfbfSEd Maste 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()); 224ac7ddfbfSEd Maste m_takedown_done = true; 225ac7ddfbfSEd Maste m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC(); 226ac7ddfbfSEd Maste m_real_stop_info_sp = GetPrivateStopInfo (); 227*afda932aSEd Maste if (!m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) 228*afda932aSEd Maste { 229*afda932aSEd Maste if (log) 230*afda932aSEd Maste log->Printf("ThreadPlanCallFunction(%p): DoTakedown failed to restore register state", this); 231*afda932aSEd Maste } 232ac7ddfbfSEd Maste SetPlanComplete(success); 233ac7ddfbfSEd Maste ClearBreakpoints(); 234ac7ddfbfSEd Maste if (log && log->GetVerbose()) 235ac7ddfbfSEd Maste ReportRegisterState ("Restoring thread state after function call. Restored register state:"); 236ac7ddfbfSEd Maste 237ac7ddfbfSEd Maste } 238ac7ddfbfSEd Maste else 239ac7ddfbfSEd Maste { 240ac7ddfbfSEd Maste if (log) 241ac7ddfbfSEd Maste 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()); 242ac7ddfbfSEd Maste } 243ac7ddfbfSEd Maste } 244ac7ddfbfSEd Maste 245ac7ddfbfSEd Maste void 246ac7ddfbfSEd Maste ThreadPlanCallFunction::WillPop () 247ac7ddfbfSEd Maste { 248ac7ddfbfSEd Maste DoTakedown(PlanSucceeded()); 249ac7ddfbfSEd Maste } 250ac7ddfbfSEd Maste 251ac7ddfbfSEd Maste void 252ac7ddfbfSEd Maste ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level) 253ac7ddfbfSEd Maste { 254ac7ddfbfSEd Maste if (level == eDescriptionLevelBrief) 255ac7ddfbfSEd Maste { 256ac7ddfbfSEd Maste s->Printf("Function call thread plan"); 257ac7ddfbfSEd Maste } 258ac7ddfbfSEd Maste else 259ac7ddfbfSEd Maste { 260ac7ddfbfSEd Maste TargetSP target_sp (m_thread.CalculateTarget()); 261ac7ddfbfSEd Maste s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get())); 262ac7ddfbfSEd Maste } 263ac7ddfbfSEd Maste } 264ac7ddfbfSEd Maste 265ac7ddfbfSEd Maste bool 266ac7ddfbfSEd Maste ThreadPlanCallFunction::ValidatePlan (Stream *error) 267ac7ddfbfSEd Maste { 268ac7ddfbfSEd Maste if (!m_valid) 269ac7ddfbfSEd Maste { 270ac7ddfbfSEd Maste if (error) 271ac7ddfbfSEd Maste { 272ac7ddfbfSEd Maste if (m_constructor_errors.GetSize() > 0) 273ac7ddfbfSEd Maste error->PutCString (m_constructor_errors.GetData()); 274ac7ddfbfSEd Maste else 275ac7ddfbfSEd Maste error->PutCString ("Unknown error"); 276ac7ddfbfSEd Maste } 277ac7ddfbfSEd Maste return false; 278ac7ddfbfSEd Maste } 279ac7ddfbfSEd Maste 280ac7ddfbfSEd Maste return true; 281ac7ddfbfSEd Maste } 282ac7ddfbfSEd Maste 283ac7ddfbfSEd Maste 284ac7ddfbfSEd Maste Vote 285ac7ddfbfSEd Maste ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) 286ac7ddfbfSEd Maste { 287ac7ddfbfSEd Maste if (m_takedown_done || IsPlanComplete()) 288ac7ddfbfSEd Maste return eVoteYes; 289ac7ddfbfSEd Maste else 290ac7ddfbfSEd Maste return ThreadPlan::ShouldReportStop(event_ptr); 291ac7ddfbfSEd Maste } 292ac7ddfbfSEd Maste 293ac7ddfbfSEd Maste bool 294ac7ddfbfSEd Maste ThreadPlanCallFunction::DoPlanExplainsStop (Event *event_ptr) 295ac7ddfbfSEd Maste { 296ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP|LIBLLDB_LOG_PROCESS)); 297ac7ddfbfSEd Maste m_real_stop_info_sp = GetPrivateStopInfo (); 298ac7ddfbfSEd Maste 299ac7ddfbfSEd Maste // If our subplan knows why we stopped, even if it's done (which would forward the question to us) 300ac7ddfbfSEd Maste // we answer yes. 301ac7ddfbfSEd Maste if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop(event_ptr)) 302ac7ddfbfSEd Maste { 303ac7ddfbfSEd Maste SetPlanComplete(); 304ac7ddfbfSEd Maste return true; 305ac7ddfbfSEd Maste } 306ac7ddfbfSEd Maste 307ac7ddfbfSEd Maste // Check if the breakpoint is one of ours. 308ac7ddfbfSEd Maste 309ac7ddfbfSEd Maste StopReason stop_reason; 310ac7ddfbfSEd Maste if (!m_real_stop_info_sp) 311ac7ddfbfSEd Maste stop_reason = eStopReasonNone; 312ac7ddfbfSEd Maste else 313ac7ddfbfSEd Maste stop_reason = m_real_stop_info_sp->GetStopReason(); 314ac7ddfbfSEd Maste if (log) 315ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.", Thread::StopReasonAsCString(stop_reason)); 316ac7ddfbfSEd Maste 317ac7ddfbfSEd Maste if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop()) 318ac7ddfbfSEd Maste return true; 319ac7ddfbfSEd Maste 320ac7ddfbfSEd Maste // We control breakpoints separately from other "stop reasons." So first, 321ac7ddfbfSEd Maste // check the case where we stopped for an internal breakpoint, in that case, continue on. 322ac7ddfbfSEd Maste // If it is not an internal breakpoint, consult m_ignore_breakpoints. 323ac7ddfbfSEd Maste 324ac7ddfbfSEd Maste 325ac7ddfbfSEd Maste if (stop_reason == eStopReasonBreakpoint) 326ac7ddfbfSEd Maste { 327ac7ddfbfSEd Maste ProcessSP process_sp (m_thread.CalculateProcess()); 328ac7ddfbfSEd Maste uint64_t break_site_id = m_real_stop_info_sp->GetValue(); 329ac7ddfbfSEd Maste BreakpointSiteSP bp_site_sp; 330ac7ddfbfSEd Maste if (process_sp) 331ac7ddfbfSEd Maste bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id); 332ac7ddfbfSEd Maste if (bp_site_sp) 333ac7ddfbfSEd Maste { 334ac7ddfbfSEd Maste uint32_t num_owners = bp_site_sp->GetNumberOfOwners(); 335ac7ddfbfSEd Maste bool is_internal = true; 336ac7ddfbfSEd Maste for (uint32_t i = 0; i < num_owners; i++) 337ac7ddfbfSEd Maste { 338ac7ddfbfSEd Maste Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint(); 339ac7ddfbfSEd Maste if (log) 340ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: hit breakpoint %d while calling function", bp.GetID()); 341ac7ddfbfSEd Maste 342ac7ddfbfSEd Maste if (!bp.IsInternal()) 343ac7ddfbfSEd Maste { 344ac7ddfbfSEd Maste is_internal = false; 345ac7ddfbfSEd Maste break; 346ac7ddfbfSEd Maste } 347ac7ddfbfSEd Maste } 348ac7ddfbfSEd Maste if (is_internal) 349ac7ddfbfSEd Maste { 350ac7ddfbfSEd Maste if (log) 351ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction::PlanExplainsStop hit an internal breakpoint, not stopping."); 352ac7ddfbfSEd Maste return false; 353ac7ddfbfSEd Maste } 354ac7ddfbfSEd Maste } 355ac7ddfbfSEd Maste 356ac7ddfbfSEd Maste if (m_ignore_breakpoints) 357ac7ddfbfSEd Maste { 358ac7ddfbfSEd Maste if (log) 359ac7ddfbfSEd Maste log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true"); 360ac7ddfbfSEd Maste m_real_stop_info_sp->OverrideShouldStop(false); 361ac7ddfbfSEd Maste return true; 362ac7ddfbfSEd Maste } 363ac7ddfbfSEd Maste else 364ac7ddfbfSEd Maste { 365ac7ddfbfSEd Maste if (log) 366ac7ddfbfSEd Maste log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true"); 367ac7ddfbfSEd Maste m_real_stop_info_sp->OverrideShouldStop(true); 368ac7ddfbfSEd Maste return false; 369ac7ddfbfSEd Maste } 370ac7ddfbfSEd Maste } 371ac7ddfbfSEd Maste else if (!m_unwind_on_error) 372ac7ddfbfSEd Maste { 373ac7ddfbfSEd Maste // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack. 374ac7ddfbfSEd Maste return false; 375ac7ddfbfSEd Maste } 376ac7ddfbfSEd Maste else 377ac7ddfbfSEd Maste { 378ac7ddfbfSEd Maste // If the subplan is running, any crashes are attributable to us. 379ac7ddfbfSEd Maste // If we want to discard the plan, then we say we explain the stop 380ac7ddfbfSEd Maste // but if we are going to be discarded, let whoever is above us 381ac7ddfbfSEd Maste // explain the stop. 382ac7ddfbfSEd Maste // But don't discard the plan if the stop would restart itself (for instance if it is a 383ac7ddfbfSEd Maste // signal that is set not to stop. Check that here first. We just say we explain the stop 384ac7ddfbfSEd Maste // but aren't done and everything will continue on from there. 385ac7ddfbfSEd Maste 386ac7ddfbfSEd Maste if (m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) 387ac7ddfbfSEd Maste { 388ac7ddfbfSEd Maste SetPlanComplete(false); 389ac7ddfbfSEd Maste if (m_subplan_sp) 390ac7ddfbfSEd Maste { 391ac7ddfbfSEd Maste if (m_unwind_on_error) 392ac7ddfbfSEd Maste return true; 393ac7ddfbfSEd Maste else 394ac7ddfbfSEd Maste return false; 395ac7ddfbfSEd Maste } 396ac7ddfbfSEd Maste else 397ac7ddfbfSEd Maste return false; 398ac7ddfbfSEd Maste } 399ac7ddfbfSEd Maste else 400ac7ddfbfSEd Maste return true; 401ac7ddfbfSEd Maste } 402ac7ddfbfSEd Maste } 403ac7ddfbfSEd Maste 404ac7ddfbfSEd Maste bool 405ac7ddfbfSEd Maste ThreadPlanCallFunction::ShouldStop (Event *event_ptr) 406ac7ddfbfSEd Maste { 407ac7ddfbfSEd Maste // We do some computation in DoPlanExplainsStop that may or may not set the plan as complete. 408ac7ddfbfSEd Maste // We need to do that here to make sure our state is correct. 409ac7ddfbfSEd Maste DoPlanExplainsStop(event_ptr); 410ac7ddfbfSEd Maste 411ac7ddfbfSEd Maste if (IsPlanComplete()) 412ac7ddfbfSEd Maste { 413ac7ddfbfSEd Maste ReportRegisterState ("Function completed. Register state was:"); 414ac7ddfbfSEd Maste return true; 415ac7ddfbfSEd Maste } 416ac7ddfbfSEd Maste else 417ac7ddfbfSEd Maste { 418ac7ddfbfSEd Maste return false; 419ac7ddfbfSEd Maste } 420ac7ddfbfSEd Maste } 421ac7ddfbfSEd Maste 422ac7ddfbfSEd Maste bool 423ac7ddfbfSEd Maste ThreadPlanCallFunction::StopOthers () 424ac7ddfbfSEd Maste { 425ac7ddfbfSEd Maste return m_stop_other_threads; 426ac7ddfbfSEd Maste } 427ac7ddfbfSEd Maste 428ac7ddfbfSEd Maste void 429ac7ddfbfSEd Maste ThreadPlanCallFunction::SetStopOthers (bool new_value) 430ac7ddfbfSEd Maste { 431ac7ddfbfSEd Maste if (m_subplan_sp) 432ac7ddfbfSEd Maste { 433ac7ddfbfSEd Maste ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get()); 434ac7ddfbfSEd Maste address_plan->SetStopOthers(new_value); 435ac7ddfbfSEd Maste } 436ac7ddfbfSEd Maste m_stop_other_threads = new_value; 437ac7ddfbfSEd Maste } 438ac7ddfbfSEd Maste 439ac7ddfbfSEd Maste StateType 440ac7ddfbfSEd Maste ThreadPlanCallFunction::GetPlanRunState () 441ac7ddfbfSEd Maste { 442ac7ddfbfSEd Maste return eStateRunning; 443ac7ddfbfSEd Maste } 444ac7ddfbfSEd Maste 445ac7ddfbfSEd Maste void 446ac7ddfbfSEd Maste ThreadPlanCallFunction::DidPush () 447ac7ddfbfSEd Maste { 448ac7ddfbfSEd Maste //#define SINGLE_STEP_EXPRESSIONS 449ac7ddfbfSEd Maste 450ac7ddfbfSEd Maste // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding... 451ac7ddfbfSEd Maste // Wait till the plan is pushed so we aren't changing the stop info till we're about to run. 452ac7ddfbfSEd Maste 453ac7ddfbfSEd Maste GetThread().SetStopInfoToNothing(); 454ac7ddfbfSEd Maste 455ac7ddfbfSEd Maste #ifndef SINGLE_STEP_EXPRESSIONS 456ac7ddfbfSEd Maste m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads)); 457ac7ddfbfSEd Maste 458ac7ddfbfSEd Maste m_thread.QueueThreadPlan(m_subplan_sp, false); 459ac7ddfbfSEd Maste m_subplan_sp->SetPrivate (true); 460ac7ddfbfSEd Maste #endif 461ac7ddfbfSEd Maste } 462ac7ddfbfSEd Maste 463ac7ddfbfSEd Maste bool 464ac7ddfbfSEd Maste ThreadPlanCallFunction::WillStop () 465ac7ddfbfSEd Maste { 466ac7ddfbfSEd Maste return true; 467ac7ddfbfSEd Maste } 468ac7ddfbfSEd Maste 469ac7ddfbfSEd Maste bool 470ac7ddfbfSEd Maste ThreadPlanCallFunction::MischiefManaged () 471ac7ddfbfSEd Maste { 472ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 473ac7ddfbfSEd Maste 474ac7ddfbfSEd Maste if (IsPlanComplete()) 475ac7ddfbfSEd Maste { 476ac7ddfbfSEd Maste if (log) 477ac7ddfbfSEd Maste log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this); 478ac7ddfbfSEd Maste 479ac7ddfbfSEd Maste ThreadPlan::MischiefManaged (); 480ac7ddfbfSEd Maste return true; 481ac7ddfbfSEd Maste } 482ac7ddfbfSEd Maste else 483ac7ddfbfSEd Maste { 484ac7ddfbfSEd Maste return false; 485ac7ddfbfSEd Maste } 486ac7ddfbfSEd Maste } 487ac7ddfbfSEd Maste 488ac7ddfbfSEd Maste void 489ac7ddfbfSEd Maste ThreadPlanCallFunction::SetBreakpoints () 490ac7ddfbfSEd Maste { 491ac7ddfbfSEd Maste ProcessSP process_sp (m_thread.CalculateProcess()); 492b952cd58SEd Maste if (m_trap_exceptions && process_sp) 493ac7ddfbfSEd Maste { 494ac7ddfbfSEd Maste m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus); 495ac7ddfbfSEd Maste m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC); 496ac7ddfbfSEd Maste 497ac7ddfbfSEd Maste if (m_cxx_language_runtime) 498b952cd58SEd Maste { 499b952cd58SEd Maste m_should_clear_cxx_exception_bp = !m_cxx_language_runtime->ExceptionBreakpointsAreSet(); 500ac7ddfbfSEd Maste m_cxx_language_runtime->SetExceptionBreakpoints(); 501b952cd58SEd Maste } 502ac7ddfbfSEd Maste if (m_objc_language_runtime) 503b952cd58SEd Maste { 504b952cd58SEd Maste m_should_clear_objc_exception_bp = !m_objc_language_runtime->ExceptionBreakpointsAreSet(); 505ac7ddfbfSEd Maste m_objc_language_runtime->SetExceptionBreakpoints(); 506ac7ddfbfSEd Maste } 507ac7ddfbfSEd Maste } 508b952cd58SEd Maste } 509ac7ddfbfSEd Maste 510ac7ddfbfSEd Maste void 511ac7ddfbfSEd Maste ThreadPlanCallFunction::ClearBreakpoints () 512ac7ddfbfSEd Maste { 513b952cd58SEd Maste if (m_trap_exceptions) 514b952cd58SEd Maste { 515b952cd58SEd Maste if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp) 516ac7ddfbfSEd Maste m_cxx_language_runtime->ClearExceptionBreakpoints(); 517b952cd58SEd Maste if (m_objc_language_runtime && m_should_clear_objc_exception_bp) 518ac7ddfbfSEd Maste m_objc_language_runtime->ClearExceptionBreakpoints(); 519ac7ddfbfSEd Maste } 520b952cd58SEd Maste } 521ac7ddfbfSEd Maste 522ac7ddfbfSEd Maste bool 523ac7ddfbfSEd Maste ThreadPlanCallFunction::BreakpointsExplainStop() 524ac7ddfbfSEd Maste { 525ac7ddfbfSEd Maste StopInfoSP stop_info_sp = GetPrivateStopInfo (); 526ac7ddfbfSEd Maste 527b952cd58SEd Maste if (m_trap_exceptions) 528b952cd58SEd Maste { 529ac7ddfbfSEd Maste if ((m_cxx_language_runtime && 530ac7ddfbfSEd Maste m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)) 531ac7ddfbfSEd Maste ||(m_objc_language_runtime && 532ac7ddfbfSEd Maste m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))) 533ac7ddfbfSEd Maste { 534ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP)); 535ac7ddfbfSEd Maste if (log) 536ac7ddfbfSEd Maste log->Printf ("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an exception breakpoint, setting plan complete."); 537ac7ddfbfSEd Maste 538ac7ddfbfSEd Maste SetPlanComplete(false); 539ac7ddfbfSEd Maste 540ac7ddfbfSEd Maste // If the user has set the ObjC language breakpoint, it would normally get priority over our internal 541ac7ddfbfSEd Maste // catcher breakpoint, but in this case we can't let that happen, so force the ShouldStop here. 542ac7ddfbfSEd Maste stop_info_sp->OverrideShouldStop (true); 543ac7ddfbfSEd Maste return true; 544ac7ddfbfSEd Maste } 545b952cd58SEd Maste } 546ac7ddfbfSEd Maste 547ac7ddfbfSEd Maste return false; 548ac7ddfbfSEd Maste } 549ac7ddfbfSEd Maste 550ac7ddfbfSEd Maste bool 551ac7ddfbfSEd Maste ThreadPlanCallFunction::RestoreThreadState() 552ac7ddfbfSEd Maste { 553ac7ddfbfSEd Maste return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state); 554ac7ddfbfSEd Maste } 555ac7ddfbfSEd Maste 556