Index: lldb/include/lldb/Breakpoint/Breakpoint.h =================================================================== --- lldb/include/lldb/Breakpoint/Breakpoint.h +++ lldb/include/lldb/Breakpoint/Breakpoint.h @@ -142,7 +142,8 @@ // Saving & restoring breakpoints: static lldb::BreakpointSP CreateFromStructuredData( - Target &target, StructuredData::ObjectSP &data_object_sp, Status &error); + lldb::TargetSP target_sp, StructuredData::ObjectSP &data_object_sp, + Status &error); static bool SerializedBreakpointMatchesNames(StructuredData::ObjectSP &bkpt_object_sp, @@ -570,7 +571,7 @@ // This one should only be used by Target to copy breakpoints from target to // target - primarily from the dummy target to prime new targets. - static lldb::BreakpointSP CopyFromBreakpoint(Target& new_target, + static lldb::BreakpointSP CopyFromBreakpoint(lldb::TargetSP new_target, const Breakpoint &bp_to_copy_from); protected: Index: lldb/include/lldb/Core/SearchFilter.h =================================================================== --- lldb/include/lldb/Core/SearchFilter.h +++ lldb/include/lldb/Core/SearchFilter.h @@ -190,7 +190,7 @@ lldb::SearchFilterSP CopyForBreakpoint(Breakpoint &breakpoint); static lldb::SearchFilterSP - CreateFromStructuredData(Target &target, + CreateFromStructuredData(const lldb::TargetSP& target_sp, const StructuredData::Dictionary &data_dict, Status &error); @@ -288,7 +288,7 @@ bool ModulePasses(const lldb::ModuleSP &module_sp) override; static lldb::SearchFilterSP - CreateFromStructuredData(Target &target, + CreateFromStructuredData(const lldb::TargetSP& target_sp, const StructuredData::Dictionary &data_dict, Status &error); @@ -334,7 +334,7 @@ void Search(Searcher &searcher) override; static lldb::SearchFilterSP - CreateFromStructuredData(Target &target, + CreateFromStructuredData(const lldb::TargetSP& target_sp, const StructuredData::Dictionary &data_dict, Status &error); @@ -385,7 +385,7 @@ void Search(Searcher &searcher) override; static lldb::SearchFilterSP - CreateFromStructuredData(Target &target, + CreateFromStructuredData(const lldb::TargetSP& target_sp, const StructuredData::Dictionary &data_dict, Status &error); @@ -425,7 +425,7 @@ void Search(Searcher &searcher) override; static lldb::SearchFilterSP - CreateFromStructuredData(Target &target, + CreateFromStructuredData(const lldb::TargetSP& target_sp, const StructuredData::Dictionary &data_dict, Status &error); Index: lldb/source/Breakpoint/Breakpoint.cpp =================================================================== --- lldb/source/Breakpoint/Breakpoint.cpp +++ lldb/source/Breakpoint/Breakpoint.cpp @@ -66,9 +66,12 @@ // Destructor Breakpoint::~Breakpoint() = default; -BreakpointSP Breakpoint::CopyFromBreakpoint(Target& new_target, +BreakpointSP Breakpoint::CopyFromBreakpoint(TargetSP new_target, const Breakpoint& bp_to_copy_from) { - BreakpointSP bp(new Breakpoint(new_target, bp_to_copy_from)); + if (!new_target) + return BreakpointSP(); + + BreakpointSP bp(new Breakpoint(*new_target, bp_to_copy_from)); // Now go through and copy the filter & resolver: bp->m_resolver_sp = bp_to_copy_from.m_resolver_sp->CopyForBreakpoint(bp); bp->m_filter_sp = bp_to_copy_from.m_filter_sp->CopyForBreakpoint(*bp); @@ -125,8 +128,10 @@ } lldb::BreakpointSP Breakpoint::CreateFromStructuredData( - Target &target, StructuredData::ObjectSP &object_data, Status &error) { + TargetSP target_sp, StructuredData::ObjectSP &object_data, Status &error) { BreakpointSP result_sp; + if (!target_sp) + return result_sp; StructuredData::Dictionary *breakpoint_dict = object_data->GetAsDictionary(); @@ -160,11 +165,11 @@ SearchFilter::GetSerializationKey(), filter_dict); SearchFilterSP filter_sp; if (!success) - filter_sp = std::make_shared( - target.shared_from_this()); + filter_sp = + std::make_shared(target_sp); else { - filter_sp = SearchFilter::CreateFromStructuredData(target, *filter_dict, - create_error); + filter_sp = SearchFilter::CreateFromStructuredData(target_sp, *filter_dict, + create_error); if (create_error.Fail()) { error.SetErrorStringWithFormat( "Error creating breakpoint filter from data: %s.", @@ -175,6 +180,7 @@ std::unique_ptr options_up; StructuredData::Dictionary *options_dict; + Target& target = *target_sp; success = breakpoint_dict->GetValueForKeyAsDictionary( BreakpointOptions::GetSerializationKey(), options_dict); if (success) { @@ -192,8 +198,8 @@ success = breakpoint_dict->GetValueForKeyAsBoolean( Breakpoint::GetKey(OptionNames::Hardware), hardware); - result_sp = - target.CreateBreakpoint(filter_sp, resolver_sp, false, hardware, true); + result_sp = target.CreateBreakpoint(filter_sp, resolver_sp, false, + hardware, true); if (result_sp && options_up) { result_sp->m_options_up = std::move(options_up); Index: lldb/source/Core/SearchFilter.cpp =================================================================== --- lldb/source/Core/SearchFilter.cpp +++ lldb/source/Core/SearchFilter.cpp @@ -75,7 +75,8 @@ SearchFilter::~SearchFilter() = default; SearchFilterSP SearchFilter::CreateFromStructuredData( - Target &target, const StructuredData::Dictionary &filter_dict, + const lldb::TargetSP& target_sp, + const StructuredData::Dictionary &filter_dict, Status &error) { SearchFilterSP result_sp; if (!filter_dict.IsValid()) { @@ -109,19 +110,19 @@ switch (filter_type) { case Unconstrained: result_sp = SearchFilterForUnconstrainedSearches::CreateFromStructuredData( - target, *subclass_options, error); + target_sp, *subclass_options, error); break; case ByModule: result_sp = SearchFilterByModule::CreateFromStructuredData( - target, *subclass_options, error); + target_sp, *subclass_options, error); break; case ByModules: result_sp = SearchFilterByModuleList::CreateFromStructuredData( - target, *subclass_options, error); + target_sp, *subclass_options, error); break; case ByModulesAndCU: result_sp = SearchFilterByModuleListAndCU::CreateFromStructuredData( - target, *subclass_options, error); + target_sp, *subclass_options, error); break; case Exception: error.SetErrorString("Can't serialize exception breakpoints yet."); @@ -212,7 +213,7 @@ searcher.SearchCallback(*this, empty_sc, nullptr); return; } - + DoModuleIteration(empty_sc, searcher); } @@ -362,11 +363,11 @@ // Selects a shared library matching a given file spec, consulting the targets // "black list". SearchFilterSP SearchFilterForUnconstrainedSearches::CreateFromStructuredData( - Target &target, const StructuredData::Dictionary &data_dict, + const lldb::TargetSP& target_sp, + const StructuredData::Dictionary &data_dict, Status &error) { // No options for an unconstrained search. - return std::make_shared( - target.shared_from_this()); + return std::make_shared(target_sp); } StructuredData::ObjectSP @@ -472,7 +473,8 @@ } SearchFilterSP SearchFilterByModule::CreateFromStructuredData( - Target &target, const StructuredData::Dictionary &data_dict, + const lldb::TargetSP& target_sp, + const StructuredData::Dictionary &data_dict, Status &error) { StructuredData::Array *modules_array; bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList), @@ -497,8 +499,7 @@ } FileSpec module_spec(module); - return std::make_shared(target.shared_from_this(), - module_spec); + return std::make_shared(target_sp, module_spec); } StructuredData::ObjectSP SearchFilterByModule::SerializeToStructuredData() { @@ -617,14 +618,15 @@ } SearchFilterSP SearchFilterByModuleList::CreateFromStructuredData( - Target &target, const StructuredData::Dictionary &data_dict, + const lldb::TargetSP& target_sp, + const StructuredData::Dictionary &data_dict, Status &error) { StructuredData::Array *modules_array; bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList), modules_array); if (!success) - return std::make_shared(target.shared_from_this(), + return std::make_shared(target_sp, FileSpecList{}); FileSpecList modules; size_t num_modules = modules_array->GetSize(); @@ -638,8 +640,7 @@ } modules.EmplaceBack(module); } - return std::make_shared(target.shared_from_this(), - modules); + return std::make_shared(target_sp, modules); } void SearchFilterByModuleList::SerializeUnwrapped( @@ -667,7 +668,8 @@ SearchFilterByModuleListAndCU::~SearchFilterByModuleListAndCU() = default; lldb::SearchFilterSP SearchFilterByModuleListAndCU::CreateFromStructuredData( - Target &target, const StructuredData::Dictionary &data_dict, + const lldb::TargetSP& target_sp, + const StructuredData::Dictionary &data_dict, Status &error) { StructuredData::Array *modules_array = nullptr; SearchFilterSP result_sp; @@ -710,7 +712,7 @@ } return std::make_shared( - target.shared_from_this(), modules, cus); + target_sp, modules, cus); } StructuredData::ObjectSP Index: lldb/source/Target/Target.cpp =================================================================== --- lldb/source/Target/Target.cpp +++ lldb/source/Target/Target.cpp @@ -131,7 +131,8 @@ if (breakpoint_sp->IsInternal()) continue; - BreakpointSP new_bp(Breakpoint::CopyFromBreakpoint(*this, *breakpoint_sp)); + BreakpointSP new_bp( + Breakpoint::CopyFromBreakpoint(shared_from_this(), *breakpoint_sp)); AddBreakpoint(std::move(new_bp), false); } @@ -1108,8 +1109,8 @@ !Breakpoint::SerializedBreakpointMatchesNames(bkpt_data_sp, names)) continue; - BreakpointSP bkpt_sp = - Breakpoint::CreateFromStructuredData(*this, bkpt_data_sp, error); + BreakpointSP bkpt_sp = Breakpoint::CreateFromStructuredData( + shared_from_this(), bkpt_data_sp, error); if (!error.Success()) { error.SetErrorStringWithFormat( "Error restoring breakpoint %zu from %s: %s.", i,