diff options
Diffstat (limited to 'source/Target/Thread.cpp')
-rw-r--r-- | source/Target/Thread.cpp | 193 |
1 files changed, 121 insertions, 72 deletions
diff --git a/source/Target/Thread.cpp b/source/Target/Thread.cpp index 5ac1de7ae01b..569d7a0a0f9e 100644 --- a/source/Target/Thread.cpp +++ b/source/Target/Thread.cpp @@ -7,10 +7,6 @@ // //===----------------------------------------------------------------------===// -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "lldb/Target/Thread.h" #include "Plugins/Process/Utility/UnwindLLDB.h" #include "Plugins/Process/Utility/UnwindMacOSXFrameBackchain.h" @@ -18,7 +14,6 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/FormatEntity.h" #include "lldb/Core/Module.h" -#include "lldb/Core/State.h" #include "lldb/Core/ValueObject.h" #include "lldb/Host/Host.h" #include "lldb/Interpreter/OptionValueFileSpecList.h" @@ -28,8 +23,10 @@ #include "lldb/Target/ABI.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" +#include "lldb/Target/StackFrameRecognizer.h" #include "lldb/Target/StopInfo.h" #include "lldb/Target/SystemRuntime.h" #include "lldb/Target/Target.h" @@ -49,6 +46,7 @@ #include "lldb/Target/Unwind.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" +#include "lldb/Utility/State.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/StreamString.h" #include "lldb/lldb-enumerations.h" @@ -64,30 +62,31 @@ const ThreadPropertiesSP &Thread::GetGlobalProperties() { return *g_settings_sp_ptr; } -static PropertyDefinition g_properties[] = { +static constexpr PropertyDefinition g_properties[] = { {"step-in-avoid-nodebug", OptionValue::eTypeBoolean, true, true, nullptr, - nullptr, + {}, "If true, step-in will not stop in functions with no debug information."}, {"step-out-avoid-nodebug", OptionValue::eTypeBoolean, true, false, nullptr, - nullptr, "If true, when step-in/step-out/step-over leave the current " - "frame, they will continue to step out till they come to a " - "function with " - "debug information. Passing a frame argument to step-out will " - "override this option."}, - {"step-avoid-regexp", OptionValue::eTypeRegex, true, 0, "^std::", nullptr, + {}, "If true, when step-in/step-out/step-over leave the current frame, " + "they will continue to step out till they come to a function with " + "debug information. Passing a frame argument to step-out will " + "override this option."}, + {"step-avoid-regexp", OptionValue::eTypeRegex, true, 0, "^std::", {}, "A regular expression defining functions step-in won't stop in."}, {"step-avoid-libraries", OptionValue::eTypeFileSpecList, true, 0, nullptr, - nullptr, "A list of libraries that source stepping won't stop in."}, - {"trace-thread", OptionValue::eTypeBoolean, false, false, nullptr, nullptr, + {}, "A list of libraries that source stepping won't stop in."}, + {"trace-thread", OptionValue::eTypeBoolean, false, false, nullptr, {}, "If true, this thread will single-step and log execution."}, - {nullptr, OptionValue::eTypeInvalid, false, 0, nullptr, nullptr, nullptr}}; + {"max-backtrace-depth", OptionValue::eTypeUInt64, false, 300000, nullptr, + {}, "Maximum number of frames to backtrace."}}; enum { ePropertyStepInAvoidsNoDebug, ePropertyStepOutAvoidsNoDebug, ePropertyStepAvoidRegex, ePropertyStepAvoidLibraries, - ePropertyEnableThreadTrace + ePropertyEnableThreadTrace, + ePropertyMaxBacktraceDepth }; class ThreadOptionValueProperties : public OptionValueProperties { @@ -165,6 +164,12 @@ bool ThreadProperties::GetStepOutAvoidsNoDebug() const { nullptr, idx, g_properties[idx].default_uint_value != 0); } +uint64_t ThreadProperties::GetMaxBacktraceDepth() const { + const uint32_t idx = ePropertyMaxBacktraceDepth; + return m_collection_sp->GetPropertyAtIndexAsUInt64( + nullptr, idx, g_properties[idx].default_uint_value != 0); +} + //------------------------------------------------------------------ // Thread Event Data //------------------------------------------------------------------ @@ -259,6 +264,7 @@ Thread::Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id) static_cast<void *>(this), GetID()); CheckInWithManager(); + QueueFundamentalPlan(true); } @@ -392,13 +398,14 @@ lldb::StopInfoSP Thread::GetStopInfo() { m_stop_info_sp ->IsValid() && m_stop_info_stop_id == stop_id; bool have_valid_completed_plan = completed_plan_sp && completed_plan_sp->PlanSucceeded(); + bool plan_failed = completed_plan_sp && !completed_plan_sp->PlanSucceeded(); bool plan_overrides_trace = have_valid_stop_info && have_valid_completed_plan && (m_stop_info_sp->GetStopReason() == eStopReasonTrace); - if (have_valid_stop_info && !plan_overrides_trace) { + if (have_valid_stop_info && !plan_overrides_trace && !plan_failed) { return m_stop_info_sp; - } else if (have_valid_completed_plan) { + } else if (completed_plan_sp) { return StopInfo::CreateStopReasonWithPlan( completed_plan_sp, GetReturnValueObject(), GetExpressionVariable()); } else { @@ -1031,9 +1038,11 @@ void Thread::PushPlan(ThreadPlanSP &thread_plan_sp) { if (thread_plan_sp) { // If the thread plan doesn't already have a tracer, give it its parent's // tracer: - if (!thread_plan_sp->GetThreadPlanTracer()) + if (!thread_plan_sp->GetThreadPlanTracer()) { + assert(!m_plan_stack.empty()); thread_plan_sp->SetThreadPlanTracer( m_plan_stack.back()->GetThreadPlanTracer()); + } m_plan_stack.push_back(thread_plan_sp); thread_plan_sp->DidPush(); @@ -1170,12 +1179,34 @@ ThreadPlan *Thread::GetPreviousPlan(ThreadPlan *current_plan) { return nullptr; } -void Thread::QueueThreadPlan(ThreadPlanSP &thread_plan_sp, - bool abort_other_plans) { +Status Thread::QueueThreadPlan(ThreadPlanSP &thread_plan_sp, + bool abort_other_plans) { + Status status; + StreamString s; + if (!thread_plan_sp->ValidatePlan(&s)) { + DiscardThreadPlansUpToPlan(thread_plan_sp); + thread_plan_sp.reset(); + status.SetErrorString(s.GetString()); + return status; + } + if (abort_other_plans) DiscardThreadPlans(true); PushPlan(thread_plan_sp); + + // This seems a little funny, but I don't want to have to split up the + // constructor and the DidPush in the scripted plan, that seems annoying. + // That means the constructor has to be in DidPush. So I have to validate the + // plan AFTER pushing it, and then take it off again... + if (!thread_plan_sp->ValidatePlan(&s)) { + DiscardThreadPlansUpToPlan(thread_plan_sp); + thread_plan_sp.reset(); + status.SetErrorString(s.GetString()); + return status; + } + + return status; } void Thread::EnableTracer(bool value, bool single_stepping) { @@ -1340,23 +1371,24 @@ ThreadPlanSP Thread::QueueFundamentalPlan(bool abort_other_plans) { } ThreadPlanSP Thread::QueueThreadPlanForStepSingleInstruction( - bool step_over, bool abort_other_plans, bool stop_other_threads) { + bool step_over, bool abort_other_plans, bool stop_other_threads, + Status &status) { ThreadPlanSP thread_plan_sp(new ThreadPlanStepInstruction( *this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); - QueueThreadPlan(thread_plan_sp, abort_other_plans); + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); return thread_plan_sp; } ThreadPlanSP Thread::QueueThreadPlanForStepOverRange( bool abort_other_plans, const AddressRange &range, const SymbolContext &addr_context, lldb::RunMode stop_other_threads, - LazyBool step_out_avoids_code_withoug_debug_info) { + Status &status, LazyBool step_out_avoids_code_withoug_debug_info) { ThreadPlanSP thread_plan_sp; thread_plan_sp.reset(new ThreadPlanStepOverRange( *this, range, addr_context, stop_other_threads, step_out_avoids_code_withoug_debug_info)); - QueueThreadPlan(thread_plan_sp, abort_other_plans); + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); return thread_plan_sp; } @@ -1365,17 +1397,17 @@ ThreadPlanSP Thread::QueueThreadPlanForStepOverRange( ThreadPlanSP Thread::QueueThreadPlanForStepOverRange( bool abort_other_plans, const LineEntry &line_entry, const SymbolContext &addr_context, lldb::RunMode stop_other_threads, - LazyBool step_out_avoids_code_withoug_debug_info) { + Status &status, LazyBool step_out_avoids_code_withoug_debug_info) { return QueueThreadPlanForStepOverRange( abort_other_plans, line_entry.GetSameLineContiguousAddressRange(), - addr_context, stop_other_threads, + addr_context, stop_other_threads, status, step_out_avoids_code_withoug_debug_info); } ThreadPlanSP Thread::QueueThreadPlanForStepInRange( bool abort_other_plans, const AddressRange &range, const SymbolContext &addr_context, const char *step_in_target, - lldb::RunMode stop_other_threads, + lldb::RunMode stop_other_threads, Status &status, LazyBool step_in_avoids_code_without_debug_info, LazyBool step_out_avoids_code_without_debug_info) { ThreadPlanSP thread_plan_sp( @@ -1388,7 +1420,7 @@ ThreadPlanSP Thread::QueueThreadPlanForStepInRange( if (step_in_target) plan->SetStepInTarget(step_in_target); - QueueThreadPlan(thread_plan_sp, abort_other_plans); + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); return thread_plan_sp; } @@ -1396,12 +1428,12 @@ ThreadPlanSP Thread::QueueThreadPlanForStepInRange( ThreadPlanSP Thread::QueueThreadPlanForStepInRange( bool abort_other_plans, const LineEntry &line_entry, const SymbolContext &addr_context, const char *step_in_target, - lldb::RunMode stop_other_threads, + lldb::RunMode stop_other_threads, Status &status, LazyBool step_in_avoids_code_without_debug_info, LazyBool step_out_avoids_code_without_debug_info) { return QueueThreadPlanForStepInRange( abort_other_plans, line_entry.GetSameLineContiguousAddressRange(), - addr_context, step_in_target, stop_other_threads, + addr_context, step_in_target, stop_other_threads, status, step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info); } @@ -1409,23 +1441,19 @@ ThreadPlanSP Thread::QueueThreadPlanForStepInRange( ThreadPlanSP Thread::QueueThreadPlanForStepOut( bool abort_other_plans, SymbolContext *addr_context, bool first_insn, bool stop_other_threads, Vote stop_vote, Vote run_vote, uint32_t frame_idx, - LazyBool step_out_avoids_code_without_debug_info) { + Status &status, LazyBool step_out_avoids_code_without_debug_info) { ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut( *this, addr_context, first_insn, stop_other_threads, stop_vote, run_vote, frame_idx, step_out_avoids_code_without_debug_info)); - if (thread_plan_sp->ValidatePlan(nullptr)) { - QueueThreadPlan(thread_plan_sp, abort_other_plans); - return thread_plan_sp; - } else { - return ThreadPlanSP(); - } + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); + return thread_plan_sp; } ThreadPlanSP Thread::QueueThreadPlanForStepOutNoShouldStop( bool abort_other_plans, SymbolContext *addr_context, bool first_insn, bool stop_other_threads, Vote stop_vote, Vote run_vote, uint32_t frame_idx, - bool continue_to_next_branch) { + Status &status, bool continue_to_next_branch) { const bool calculate_return_value = false; // No need to calculate the return value here. ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut( @@ -1436,59 +1464,51 @@ ThreadPlanSP Thread::QueueThreadPlanForStepOutNoShouldStop( static_cast<ThreadPlanStepOut *>(thread_plan_sp.get()); new_plan->ClearShouldStopHereCallbacks(); - if (thread_plan_sp->ValidatePlan(nullptr)) { - QueueThreadPlan(thread_plan_sp, abort_other_plans); - return thread_plan_sp; - } else { - return ThreadPlanSP(); - } + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); + return thread_plan_sp; } ThreadPlanSP Thread::QueueThreadPlanForStepThrough(StackID &return_stack_id, bool abort_other_plans, - bool stop_other_threads) { + bool stop_other_threads, + Status &status) { ThreadPlanSP thread_plan_sp( new ThreadPlanStepThrough(*this, return_stack_id, stop_other_threads)); if (!thread_plan_sp || !thread_plan_sp->ValidatePlan(nullptr)) return ThreadPlanSP(); - QueueThreadPlan(thread_plan_sp, abort_other_plans); + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); return thread_plan_sp; } ThreadPlanSP Thread::QueueThreadPlanForRunToAddress(bool abort_other_plans, Address &target_addr, - bool stop_other_threads) { + bool stop_other_threads, + Status &status) { ThreadPlanSP thread_plan_sp( new ThreadPlanRunToAddress(*this, target_addr, stop_other_threads)); - QueueThreadPlan(thread_plan_sp, abort_other_plans); + + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); return thread_plan_sp; } -ThreadPlanSP Thread::QueueThreadPlanForStepUntil(bool abort_other_plans, - lldb::addr_t *address_list, - size_t num_addresses, - bool stop_other_threads, - uint32_t frame_idx) { +ThreadPlanSP Thread::QueueThreadPlanForStepUntil( + bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses, + bool stop_other_threads, uint32_t frame_idx, Status &status) { ThreadPlanSP thread_plan_sp(new ThreadPlanStepUntil( *this, address_list, num_addresses, stop_other_threads, frame_idx)); - QueueThreadPlan(thread_plan_sp, abort_other_plans); + + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); return thread_plan_sp; } lldb::ThreadPlanSP Thread::QueueThreadPlanForStepScripted( - bool abort_other_plans, const char *class_name, bool stop_other_threads) { + bool abort_other_plans, const char *class_name, bool stop_other_threads, + Status &status) { ThreadPlanSP thread_plan_sp(new ThreadPlanPython(*this, class_name)); - QueueThreadPlan(thread_plan_sp, abort_other_plans); - // This seems a little funny, but I don't want to have to split up the - // constructor and the DidPush in the scripted plan, that seems annoying. - // That means the constructor has to be in DidPush. So I have to validate the - // plan AFTER pushing it, and then take it off again... - if (!thread_plan_sp->ValidatePlan(nullptr)) { - DiscardThreadPlansUpToPlan(thread_plan_sp); - return ThreadPlanSP(); - } else - return thread_plan_sp; + + status = QueueThreadPlan(thread_plan_sp, abort_other_plans); + return thread_plan_sp; } uint32_t Thread::GetIndexID() const { return m_index_id; } @@ -2107,12 +2127,12 @@ Status Thread::StepIn(bool source_step, if (source_step && frame_sp && frame_sp->HasDebugInformation()) { SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); new_plan_sp = QueueThreadPlanForStepInRange( - abort_other_plans, sc.line_entry, sc, nullptr, run_mode, + abort_other_plans, sc.line_entry, sc, nullptr, run_mode, error, step_in_avoids_code_without_debug_info, step_out_avoids_code_without_debug_info); } else { new_plan_sp = QueueThreadPlanForStepSingleInstruction( - false, abort_other_plans, run_mode); + false, abort_other_plans, run_mode, error); } new_plan_sp->SetIsMasterPlan(true); @@ -2141,11 +2161,11 @@ Status Thread::StepOver(bool source_step, if (source_step && frame_sp && frame_sp->HasDebugInformation()) { SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); new_plan_sp = QueueThreadPlanForStepOverRange( - abort_other_plans, sc.line_entry, sc, run_mode, + abort_other_plans, sc.line_entry, sc, run_mode, error, step_out_avoids_code_without_debug_info); } else { new_plan_sp = QueueThreadPlanForStepSingleInstruction( - true, abort_other_plans, run_mode); + true, abort_other_plans, run_mode, error); } new_plan_sp->SetIsMasterPlan(true); @@ -2170,7 +2190,7 @@ Status Thread::StepOut() { ThreadPlanSP new_plan_sp(QueueThreadPlanForStepOut( abort_other_plans, nullptr, first_instruction, stop_other_threads, - eVoteYes, eVoteNoOpinion, 0)); + eVoteYes, eVoteNoOpinion, 0, error)); new_plan_sp->SetIsMasterPlan(true); new_plan_sp->SetOkayToDiscard(false); @@ -2183,3 +2203,32 @@ Status Thread::StepOut() { } return error; } + +ValueObjectSP Thread::GetCurrentException() { + if (auto frame_sp = GetStackFrameAtIndex(0)) + if (auto recognized_frame = frame_sp->GetRecognizedFrame()) + if (auto e = recognized_frame->GetExceptionObject()) + return e; + + // FIXME: For now, only ObjC exceptions are supported. This should really + // iterate over all language runtimes and ask them all to give us the current + // exception. + if (auto runtime = GetProcess()->GetObjCLanguageRuntime()) + if (auto e = runtime->GetExceptionObjectForThread(shared_from_this())) + return e; + + return ValueObjectSP(); +} + +ThreadSP Thread::GetCurrentExceptionBacktrace() { + ValueObjectSP exception = GetCurrentException(); + if (!exception) return ThreadSP(); + + // FIXME: For now, only ObjC exceptions are supported. This should really + // iterate over all language runtimes and ask them all to give us the current + // exception. + auto runtime = GetProcess()->GetObjCLanguageRuntime(); + if (!runtime) return ThreadSP(); + + return runtime->GetBacktraceThreadFromException(exception); +} |