diff --git a/lldb/bindings/interface/SBTarget.i b/lldb/bindings/interface/SBTarget.i --- a/lldb/bindings/interface/SBTarget.i +++ b/lldb/bindings/interface/SBTarget.i @@ -850,21 +850,33 @@ lldb::SBWatchpoint GetWatchpointAtIndex (uint32_t idx) const; - bool - DeleteWatchpoint (lldb::watch_id_t watch_id); - lldb::SBWatchpoint FindWatchpointByID (lldb::watch_id_t watch_id); bool EnableAllWatchpoints (); + bool + EnableWatchpoint (lldb::watch_id_t watch_id); + bool DisableAllWatchpoints (); + bool + DisableWatchpoint (lldb::watch_id_t watch_id); + bool DeleteAllWatchpoints (); + bool + DeleteWatchpoint (lldb::watch_id_t watch_id); + + bool + IgnoreAllWatchpoints (uint32_t ignore_count); + + bool + IgnoreWatchpoint (lldb::watch_id_t watch_id, uint32_t ignore_count); + lldb::SBWatchpoint WatchAddress (lldb::addr_t addr, size_t size, diff --git a/lldb/include/lldb/API/SBBreakpoint.h b/lldb/include/lldb/API/SBBreakpoint.h --- a/lldb/include/lldb/API/SBBreakpoint.h +++ b/lldb/include/lldb/API/SBBreakpoint.h @@ -138,15 +138,15 @@ // Can only be called from a ScriptedBreakpointResolver... SBError AddLocation(SBAddress &address); - + + lldb::BreakpointSP GetSP() const; + private: friend class SBBreakpointList; friend class SBBreakpointLocation; friend class SBBreakpointName; friend class SBTarget; - lldb::BreakpointSP GetSP() const; - lldb::BreakpointWP m_opaque_wp; }; diff --git a/lldb/include/lldb/API/SBBreakpointLocation.h b/lldb/include/lldb/API/SBBreakpointLocation.h --- a/lldb/include/lldb/API/SBBreakpointLocation.h +++ b/lldb/include/lldb/API/SBBreakpointLocation.h @@ -88,12 +88,13 @@ SBBreakpointLocation(const lldb::BreakpointLocationSP &break_loc_sp); + BreakpointLocationSP GetSP() const; + private: friend class SBBreakpoint; friend class SBBreakpointCallbackBaton; void SetLocation(const lldb::BreakpointLocationSP &break_loc_sp); - BreakpointLocationSP GetSP() const; lldb::BreakpointLocationWP m_opaque_wp; }; diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -66,6 +66,8 @@ lldb::SBProcess GetProcess(); + bool IsProcessValid() const; + /// Sets whether we should collect statistics on lldb or not. /// /// \param[in] v @@ -754,7 +756,7 @@ lldb::SBWatchpoint GetWatchpointAtIndex(uint32_t idx) const; - bool DeleteWatchpoint(lldb::watch_id_t watch_id); + lldb::SBWatchpoint GetLastCreatedWatchpoint() const; lldb::SBWatchpoint FindWatchpointByID(lldb::watch_id_t watch_id); @@ -762,10 +764,16 @@ bool write, SBError &error); bool EnableAllWatchpoints(); + bool EnableWatchpoint(lldb::watch_id_t watch_id); bool DisableAllWatchpoints(); + bool DisableWatchpoint(lldb::watch_id_t watch_id); bool DeleteAllWatchpoints(); + bool DeleteWatchpoint(lldb::watch_id_t watch_id); + + bool IgnoreAllWatchpoints(uint32_t ignore_count); + bool IgnoreWatchpoint(lldb::watch_id_t watch_id, uint32_t ignore_count); lldb::SBBroadcaster GetBroadcaster() const; diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -187,6 +187,12 @@ return LLDB_RECORD_RESULT(sb_process); } +bool SBTarget::IsProcessValid() const { + LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, IsProcessValid); + + return m_opaque_sp->GetProcessSP() && m_opaque_sp->GetProcessSP()->IsAlive(); +} + SBPlatform SBTarget::GetPlatform() { LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBTarget, GetPlatform); @@ -1373,21 +1379,16 @@ return LLDB_RECORD_RESULT(sb_watchpoint); } -bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) { - LLDB_RECORD_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t), - wp_id); +SBWatchpoint SBTarget::GetLastCreatedWatchpoint() const { + LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBWatchpoint, SBTarget, + GetLastCreatedWatchpoint); - - bool result = false; + SBWatchpoint sb_watchpoint; TargetSP target_sp(GetSP()); if (target_sp) { - std::lock_guard guard(target_sp->GetAPIMutex()); - std::unique_lock lock; - target_sp->GetWatchpointList().GetListMutex(lock); - result = target_sp->RemoveWatchpointByID(wp_id); + sb_watchpoint.SetSP(target_sp->GetLastCreatedWatchpoint()); } - - return result; + return LLDB_RECORD_RESULT(sb_watchpoint); } SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) { @@ -1460,6 +1461,22 @@ return false; } +bool SBTarget::EnableWatchpoint(lldb::watch_id_t watch_id) { + LLDB_RECORD_METHOD(bool, SBTarget, EnableWatchpoint, (lldb::watch_id_t), + watch_id); + + bool result = false; + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard guard(target_sp->GetAPIMutex()); + std::unique_lock lock; + target_sp->GetWatchpointList().GetListMutex(lock); + result = target_sp->EnableWatchpointByID(watch_id); + } + + return result; +} + bool SBTarget::DisableAllWatchpoints() { LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllWatchpoints); @@ -1474,6 +1491,84 @@ return false; } +bool SBTarget::DisableWatchpoint(lldb::watch_id_t watch_id) { + LLDB_RECORD_METHOD(bool, SBTarget, DisableWatchpoint, (lldb::watch_id_t), + watch_id); + + bool result = false; + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard guard(target_sp->GetAPIMutex()); + std::unique_lock lock; + target_sp->GetWatchpointList().GetListMutex(lock); + result = target_sp->DisableWatchpointByID(watch_id); + } + + return result; +} + +bool SBTarget::DeleteAllWatchpoints() { + LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllWatchpoints); + + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard guard(target_sp->GetAPIMutex()); + std::unique_lock lock; + target_sp->GetWatchpointList().GetListMutex(lock); + target_sp->RemoveAllWatchpoints(); + return true; + } + return false; +} + +bool SBTarget::DeleteWatchpoint(lldb::watch_id_t watch_id) { + LLDB_RECORD_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t), + watch_id); + + bool result = false; + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard guard(target_sp->GetAPIMutex()); + std::unique_lock lock; + target_sp->GetWatchpointList().GetListMutex(lock); + result = target_sp->RemoveWatchpointByID(watch_id); + } + + return result; +} + +bool SBTarget::IgnoreAllWatchpoints(uint32_t ignore_count) { + LLDB_RECORD_METHOD(bool, SBTarget, IgnoreAllWatchpoints, (uint32_t), + ignore_count); + + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard guard(target_sp->GetAPIMutex()); + std::unique_lock lock; + target_sp->GetWatchpointList().GetListMutex(lock); + return target_sp->IgnoreAllWatchpoints(ignore_count); + } + + return false; +} + +bool SBTarget::IgnoreWatchpoint(lldb::watch_id_t watch_id, + uint32_t ignore_count) { + LLDB_RECORD_METHOD(bool, SBTarget, IgnoreWatchpoint, + (lldb::watch_id_t, uint32_t), watch_id, ignore_count); + + bool result = false; + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard guard(target_sp->GetAPIMutex()); + std::unique_lock lock; + target_sp->GetWatchpointList().GetListMutex(lock); + result = target_sp->IgnoreWatchpointByID(watch_id, ignore_count); + } + + return result; +} + SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr, SBType type) { LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress, @@ -1531,20 +1626,6 @@ return LLDB_RECORD_RESULT(sb_value); } -bool SBTarget::DeleteAllWatchpoints() { - LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllWatchpoints); - - TargetSP target_sp(GetSP()); - if (target_sp) { - std::lock_guard guard(target_sp->GetAPIMutex()); - std::unique_lock lock; - target_sp->GetWatchpointList().GetListMutex(lock); - target_sp->RemoveAllWatchpoints(); - return true; - } - return false; -} - void SBTarget::AppendImageSearchPath(const char *from, const char *to, lldb::SBError &error) { LLDB_RECORD_METHOD(void, SBTarget, AppendImageSearchPath, @@ -2423,6 +2504,7 @@ LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsValid, ()); LLDB_REGISTER_METHOD_CONST(bool, SBTarget, operator bool, ()); LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, GetProcess, ()); + LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsProcessValid, ()); LLDB_REGISTER_METHOD(lldb::SBPlatform, SBTarget, GetPlatform, ()); LLDB_REGISTER_METHOD_CONST(lldb::SBDebugger, SBTarget, GetDebugger, ()); LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBTarget, GetStatistics, ()); @@ -2561,20 +2643,27 @@ LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumWatchpoints, ()); LLDB_REGISTER_METHOD_CONST(lldb::SBWatchpoint, SBTarget, GetWatchpointAtIndex, (uint32_t)); - LLDB_REGISTER_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t)); + LLDB_REGISTER_METHOD_CONST(lldb::SBWatchpoint, SBTarget, + GetLastCreatedWatchpoint, ()); LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID, (lldb::watch_id_t)); LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress, (lldb::addr_t, size_t, bool, bool, lldb::SBError &)); LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllWatchpoints, ()); + LLDB_REGISTER_METHOD(bool, SBTarget, EnableWatchpoint, (lldb::watch_id_t)); LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllWatchpoints, ()); + LLDB_REGISTER_METHOD(bool, SBTarget, DisableWatchpoint, (lldb::watch_id_t)); + LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllWatchpoints, ()); + LLDB_REGISTER_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t)); + LLDB_REGISTER_METHOD(bool, SBTarget, IgnoreAllWatchpoints, (uint32_t)); + LLDB_REGISTER_METHOD(bool, SBTarget, IgnoreWatchpoint, + (lldb::watch_id_t, uint32_t)); LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress, (const char *, lldb::SBAddress, lldb::SBType)); LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromData, (const char *, lldb::SBData, lldb::SBType)); LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression, (const char *, const char *)); - LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllWatchpoints, ()); LLDB_REGISTER_METHOD(void, SBTarget, AppendImageSearchPath, (const char *, const char *, lldb::SBError &)); LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule, diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -19,6 +19,10 @@ #include "lldb/Interpreter/OptionGroupPythonClassWithDict.h" #include "lldb/Target/Target.h" +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBBreakpointLocation.h" +#include "lldb/API/SBTarget.h" + using namespace lldb; using namespace lldb_private; @@ -620,10 +624,10 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + SBTarget sb_target(target_sp); - const BreakpointList &breakpoints = target->GetBreakpointList(); - size_t num_breakpoints = breakpoints.GetSize(); + size_t num_breakpoints = sb_target.GetNumBreakpoints(); if (num_breakpoints == 0) { result.AppendError("No breakpoints exist for which to list commands"); @@ -640,7 +644,7 @@ BreakpointIDList valid_bp_ids; CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( - command, target, result, &valid_bp_ids, + command, target_sp.get(), result, &valid_bp_ids, BreakpointName::Permissions::PermissionKinds::listPerm); if (result.Succeeded()) { @@ -648,14 +652,14 @@ for (size_t i = 0; i < count; ++i) { BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { - Breakpoint *bp = - target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); + SBBreakpoint sb_bp = + sb_target.FindBreakpointByID(cur_bp_id.GetBreakpointID()); - if (bp) { - BreakpointLocationSP bp_loc_sp; + if (sb_bp) { + lldb::SBBreakpointLocation sb_bp_loc; if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { - bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID()); - if (!bp_loc_sp) { + sb_bp_loc = sb_bp.FindLocationByID(cur_bp_id.GetLocationID()); + if (!sb_bp_loc) { result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); @@ -669,13 +673,13 @@ cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); const Baton *baton = nullptr; - if (bp_loc_sp) + if (sb_bp_loc) baton = - bp_loc_sp + sb_bp_loc.GetSP() ->GetOptionsSpecifyingKind(BreakpointOptions::eCallback) ->GetBaton(); else - baton = bp->GetOptions()->GetBaton(); + baton = sb_bp.GetSP()->GetOptions()->GetBaton(); if (baton) { result.GetOutputStream().Printf("Breakpoint %s:\n", diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -52,6 +52,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatAdapters.h" +#include "lldb/API/SBTarget.h" using namespace lldb; using namespace lldb_private; @@ -2966,21 +2967,21 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = GetDebugger().GetSelectedTarget().get(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); const bool use_global_module_list = m_options.m_use_global_module_list; // Define a local module list here to ensure it lives longer than any // "locker" object which might lock its contents below (through the // "module_list_ptr" variable). ModuleList module_list; - if (target == nullptr && !use_global_module_list) { + if (!target_sp && !use_global_module_list) { result.AppendError("invalid target, create a debug target using the " "'target create' command"); result.SetStatus(eReturnStatusFailed); return false; } else { - if (target) { + if (target_sp) { uint32_t addr_byte_size = - target->GetArchitecture().GetAddressByteSize(); + target_sp->GetArchitecture().GetAddressByteSize(); result.GetOutputStream().SetAddressByteSize(addr_byte_size); result.GetErrorStream().SetAddressByteSize(addr_byte_size); } @@ -2988,12 +2989,13 @@ Stream &strm = result.GetOutputStream(); if (m_options.m_module_addr != LLDB_INVALID_ADDRESS) { - if (target) { + if (target_sp) { Address module_address; - if (module_address.SetLoadAddress(m_options.m_module_addr, target)) { + if (module_address.SetLoadAddress(m_options.m_module_addr, + target_sp.get())) { ModuleSP module_sp(module_address.GetModule()); if (module_sp) { - PrintModule(target, module_sp.get(), 0, strm); + PrintModule(target_sp.get(), module_sp.get(), 0, strm); result.SetStatus(eReturnStatusSuccessFinishResult); } else { result.AppendErrorWithFormat( @@ -3031,13 +3033,14 @@ guard.lock(); num_modules = Module::GetNumberAllocatedModules(); } else { - module_list_ptr = &target->GetImages(); + module_list_ptr = &target_sp->GetImages(); } } else { for (const Args::ArgEntry &arg : command) { // Dump specified images (by basename or fullpath) - const size_t num_matches = FindModulesByName( - target, arg.c_str(), module_list, use_global_module_list); + const size_t num_matches = + FindModulesByName(target_sp.get(), arg.c_str(), module_list, + use_global_module_list); if (num_matches == 0) { if (argc == 1) { result.AppendErrorWithFormat("no modules found that match '%s'", @@ -3072,7 +3075,7 @@ } const size_t indent = strm.Printf("[%3u] ", image_idx); - PrintModule(target, module, indent, strm); + PrintModule(target_sp.get(), module, indent, strm); } result.SetStatus(eReturnStatusSuccessFinishResult); } else { diff --git a/lldb/source/Commands/CommandObjectWatchpoint.h b/lldb/source/Commands/CommandObjectWatchpoint.h --- a/lldb/source/Commands/CommandObjectWatchpoint.h +++ b/lldb/source/Commands/CommandObjectWatchpoint.h @@ -12,6 +12,10 @@ #include "lldb/Interpreter/CommandObjectMultiword.h" #include "lldb/Interpreter/OptionGroupWatchpoint.h" +namespace lldb { +class SBTarget; +} + namespace lldb_private { // CommandObjectMultiwordWatchpoint @@ -22,7 +26,7 @@ ~CommandObjectMultiwordWatchpoint() override; - static bool VerifyWatchpointIDs(Target *target, Args &args, + static bool VerifyWatchpointIDs(lldb::SBTarget sb_target, Args &args, std::vector &wp_ids); }; diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp --- a/lldb/source/Commands/CommandObjectWatchpoint.cpp +++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -14,7 +14,6 @@ #include "llvm/ADT/StringRef.h" #include "lldb/Breakpoint/Watchpoint.h" -#include "lldb/Breakpoint/WatchpointList.h" #include "lldb/Core/ValueObject.h" #include "lldb/Host/OptionParser.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -25,21 +24,25 @@ #include "lldb/Target/Target.h" #include "lldb/Utility/StreamString.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBWatchpoint.h" + using namespace lldb; using namespace lldb_private; -static void AddWatchpointDescription(Stream *s, Watchpoint *wp, +static void AddWatchpointDescription(Stream *s, WatchpointSP wp_sp, lldb::DescriptionLevel level) { s->IndentMore(); - wp->GetDescription(s, level); + wp_sp->GetDescription(s, level); s->IndentLess(); s->EOL(); } -static bool CheckTargetForWatchpointOperations(Target *target, +static bool CheckTargetForWatchpointOperations(lldb::SBTarget sb_target, CommandReturnObject &result) { - bool process_is_valid = - target->GetProcessSP() && target->GetProcessSP()->IsAlive(); + bool process_is_valid = sb_target.IsProcessValid(); if (!process_is_valid) { result.AppendError("There's no process or it is not alive."); result.SetStatus(eReturnStatusFailed); @@ -65,14 +68,14 @@ // Return true if wp_ids is successfully populated with the watch ids. False // otherwise. bool CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - Target *target, Args &args, std::vector &wp_ids) { + lldb::SBTarget sb_target, Args &args, std::vector &wp_ids) { // Pre-condition: args.GetArgumentCount() > 0. if (args.GetArgumentCount() == 0) { - if (target == nullptr) + if (!sb_target) return false; - WatchpointSP watch_sp = target->GetLastCreatedWatchpoint(); - if (watch_sp) { - wp_ids.push_back(watch_sp->GetID()); + lldb::SBWatchpoint sb_wp = sb_target.GetLastCreatedWatchpoint(); + if (sb_wp) { + wp_ids.push_back(sb_wp.GetID()); return true; } else return false; @@ -211,24 +214,20 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); - if (target->GetProcessSP() && target->GetProcessSP()->IsAlive()) { - uint32_t num_supported_hardware_watchpoints; - Status error = target->GetProcessSP()->GetWatchpointSupportInfo( - num_supported_hardware_watchpoints); + if (sb_target.IsProcessValid()) { + lldb::SBError error; + uint32_t num_supported_hardware_watchpoints = + sb_target.GetProcess().GetNumSupportedHardwareWatchpoints(error); if (error.Success()) result.AppendMessageWithFormat( "Number of supported hardware watchpoints: %u\n", num_supported_hardware_watchpoints); } - const WatchpointList &watchpoints = target->GetWatchpointList(); - - std::unique_lock lock; - target->GetWatchpointList().GetListMutex(lock); - - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendMessage("No watchpoints currently set."); @@ -242,15 +241,15 @@ // No watchpoint selected; show info about all currently set watchpoints. result.AppendMessage("Current watchpoints:"); for (size_t i = 0; i < num_watchpoints; ++i) { - Watchpoint *wp = watchpoints.GetByIndex(i).get(); - AddWatchpointDescription(&output_stream, wp, m_options.m_level); + WatchpointSP wp_sp = sb_target.GetWatchpointAtIndex(i).GetSP(); + AddWatchpointDescription(&output_stream, wp_sp, m_options.m_level); } result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { // Particular watchpoints selected; enable them. std::vector wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - target, command, wp_ids)) { + sb_target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -258,9 +257,9 @@ const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) { - Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get(); - if (wp) - AddWatchpointDescription(&output_stream, wp, m_options.m_level); + WatchpointSP wp_sp = sb_target.GetWatchpointAtIndex(wp_ids[i]).GetSP(); + if (wp_sp) + AddWatchpointDescription(&output_stream, wp_sp, m_options.m_level); result.SetStatus(eReturnStatusSuccessFinishNoResult); } } @@ -294,16 +293,12 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); - if (!CheckTargetForWatchpointOperations(target, result)) + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); + if (!CheckTargetForWatchpointOperations(sb_target, result)) return false; - std::unique_lock lock; - target->GetWatchpointList().GetListMutex(lock); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be enabled."); @@ -313,7 +308,7 @@ if (command.GetArgumentCount() == 0) { // No watchpoint selected; enable all currently set watchpoints. - target->EnableAllWatchpoints(); + sb_target.EnableAllWatchpoints(); result.AppendMessageWithFormat("All watchpoints enabled. (%" PRIu64 " watchpoints)\n", (uint64_t)num_watchpoints); @@ -322,7 +317,7 @@ // Particular watchpoints selected; enable them. std::vector wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - target, command, wp_ids)) { + sb_target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -331,8 +326,9 @@ int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) - if (target->EnableWatchpointByID(wp_ids[i])) + if (sb_target.EnableWatchpoint(wp_ids[i])) ++count; + result.AppendMessageWithFormat("%d watchpoints enabled.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); } @@ -364,15 +360,12 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); - if (!CheckTargetForWatchpointOperations(target, result)) + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); + if (!CheckTargetForWatchpointOperations(sb_target, result)) return false; - std::unique_lock lock; - target->GetWatchpointList().GetListMutex(lock); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be disabled."); @@ -382,7 +375,7 @@ if (command.GetArgumentCount() == 0) { // No watchpoint selected; disable all currently set watchpoints. - if (target->DisableAllWatchpoints()) { + if (sb_target.DisableAllWatchpoints()) { result.AppendMessageWithFormat("All watchpoints disabled. (%" PRIu64 " watchpoints)\n", (uint64_t)num_watchpoints); @@ -395,7 +388,7 @@ // Particular watchpoints selected; disable them. std::vector wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - target, command, wp_ids)) { + sb_target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -404,7 +397,7 @@ int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) - if (target->DisableWatchpointByID(wp_ids[i])) + if (sb_target.DisableWatchpoint(wp_ids[i])) ++count; result.AppendMessageWithFormat("%d watchpoints disabled.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -476,16 +469,12 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); - if (!CheckTargetForWatchpointOperations(target, result)) + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); + if (!CheckTargetForWatchpointOperations(sb_target, result)) return false; - std::unique_lock lock; - target->GetWatchpointList().GetListMutex(lock); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be deleted."); @@ -500,7 +489,7 @@ true)) { result.AppendMessage("Operation cancelled..."); } else { - target->RemoveAllWatchpoints(); + sb_target.DeleteAllWatchpoints(); result.AppendMessageWithFormat("All watchpoints removed. (%" PRIu64 " watchpoints)\n", (uint64_t)num_watchpoints); @@ -511,8 +500,8 @@ // Particular watchpoints selected; delete them. std::vector wp_ids; - if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, - wp_ids)) { + if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( + sb_target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -521,7 +510,7 @@ int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) - if (target->RemoveWatchpointByID(wp_ids[i])) + if (sb_target.DeleteWatchpoint(wp_ids[i])) ++count; result.AppendMessageWithFormat("%d watchpoints deleted.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -598,16 +587,13 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); - if (!CheckTargetForWatchpointOperations(target, result)) - return false; + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); - std::unique_lock lock; - target->GetWatchpointList().GetListMutex(lock); - - const WatchpointList &watchpoints = target->GetWatchpointList(); + if (!CheckTargetForWatchpointOperations(sb_target, result)) + return false; - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be ignored."); @@ -616,7 +602,7 @@ } if (command.GetArgumentCount() == 0) { - target->IgnoreAllWatchpoints(m_options.m_ignore_count); + sb_target.IgnoreAllWatchpoints(m_options.m_ignore_count); result.AppendMessageWithFormat("All watchpoints ignored. (%" PRIu64 " watchpoints)\n", (uint64_t)num_watchpoints); @@ -625,7 +611,7 @@ // Particular watchpoints selected; ignore them. std::vector wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - target, command, wp_ids)) { + sb_target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -634,7 +620,7 @@ int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) - if (target->IgnoreWatchpointByID(wp_ids[i], m_options.m_ignore_count)) + if (sb_target.IgnoreWatchpoint(wp_ids[i], m_options.m_ignore_count)) ++count; result.AppendMessageWithFormat("%d watchpoints ignored.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -719,16 +705,12 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); - if (!CheckTargetForWatchpointOperations(target, result)) + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); + if (!CheckTargetForWatchpointOperations(sb_target, result)) return false; - std::unique_lock lock; - target->GetWatchpointList().GetListMutex(lock); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be modified."); @@ -737,14 +719,14 @@ } if (command.GetArgumentCount() == 0) { - WatchpointSP wp_sp = target->GetLastCreatedWatchpoint(); + WatchpointSP wp_sp = sb_target.GetLastCreatedWatchpoint().GetSP(); wp_sp->SetCondition(m_options.m_condition.c_str()); result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { // Particular watchpoints selected; set condition on them. std::vector wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - target, command, wp_ids)) { + sb_target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -753,9 +735,9 @@ int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) { - WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]); - if (wp_sp) { - wp_sp->SetCondition(m_options.m_condition.c_str()); + lldb::SBWatchpoint sb_wp = sb_target.FindWatchpointByID(wp_ids[i]); + if (sb_wp.GetSP()) { + sb_wp.SetCondition(m_options.m_condition.c_str()); ++count; } } @@ -837,7 +819,7 @@ } bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = GetDebugger().GetSelectedTarget().get(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); StackFrame *frame = m_exe_ctx.GetFramePtr(); // If no argument is present, issue an error message. There's no way to @@ -889,8 +871,8 @@ Status error(Variable::GetValuesForVariableExpressionPath( command.GetArgumentAtIndex(0), - m_exe_ctx.GetBestExecutionContextScope(), GetVariableCallback, target, - variable_list, valobj_list)); + m_exe_ctx.GetBestExecutionContextScope(), GetVariableCallback, + target_sp.get(), variable_list, valobj_list)); if (valobj_list.GetSize()) valobj_sp = valobj_list.GetValueObjectAtIndex(0); @@ -924,20 +906,19 @@ uint32_t watch_type = m_option_watchpoint.watch_type; error.Clear(); - Watchpoint *wp = - target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error) - .get(); - if (wp) { - wp->SetWatchSpec(command.GetArgumentAtIndex(0)); - wp->SetWatchVariable(true); + WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, &compiler_type, + watch_type, error); + if (wp_sp) { + wp_sp->SetWatchSpec(command.GetArgumentAtIndex(0)); + wp_sp->SetWatchVariable(true); if (var_sp && var_sp->GetDeclaration().GetFile()) { StreamString ss; // True to show fullpath for declaration file. var_sp->GetDeclaration().DumpStopContext(&ss, true); - wp->SetDeclInfo(std::string(ss.GetString())); + wp_sp->SetDeclInfo(std::string(ss.GetString())); } output_stream.Printf("Watchpoint created: "); - wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); + wp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); output_stream.EOL(); result.SetStatus(eReturnStatusSuccessFinishResult); } else { @@ -1022,7 +1003,9 @@ m_option_group.NotifyOptionParsingStarting( &exe_ctx); // This is a raw command, so notify the option group - Target *target = GetDebugger().GetSelectedTarget().get(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); + StackFrame *frame = m_exe_ctx.GetFramePtr(); OptionsWithRaw args(raw_command); @@ -1065,7 +1048,7 @@ options.SetTimeout(llvm::None); ExpressionResults expr_result = - target->EvaluateExpression(expr, frame, valobj_sp, options); + target_sp->EvaluateExpression(expr, frame, valobj_sp, options); if (expr_result != eExpressionCompleted) { result.GetErrorStream().Printf( "error: expression evaluation of address to watch failed\n"); @@ -1089,7 +1072,7 @@ if (m_option_watchpoint.watch_size != 0) size = m_option_watchpoint.watch_size; else - size = target->GetArchitecture().GetAddressByteSize(); + size = sb_target.GetAddressByteSize(); // Now it's time to create the watchpoint. uint32_t watch_type = m_option_watchpoint.watch_type; @@ -1100,13 +1083,12 @@ CompilerType compiler_type(valobj_sp->GetCompilerType()); Status error; - Watchpoint *wp = - target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error) - .get(); - if (wp) { + WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, &compiler_type, + watch_type, error); + if (wp_sp) { Stream &output_stream = result.GetOutputStream(); output_stream.Printf("Watchpoint created: "); - wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); + wp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); output_stream.EOL(); result.SetStatus(eReturnStatusSuccessFinishResult); } else { diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp --- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp @@ -19,6 +19,9 @@ #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Target/Target.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBWatchpoint.h" + using namespace lldb; using namespace lldb_private; @@ -398,10 +401,10 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); - const WatchpointList &watchpoints = target->GetWatchpointList(); - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to have commands added"); @@ -417,8 +420,8 @@ } std::vector valid_wp_ids; - if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, - valid_wp_ids)) { + if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( + sb_target, command, valid_wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -429,12 +432,12 @@ for (size_t i = 0; i < count; ++i) { uint32_t cur_wp_id = valid_wp_ids.at(i); if (cur_wp_id != LLDB_INVALID_WATCH_ID) { - Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get(); + lldb::SBWatchpoint sb_wp = sb_target.FindWatchpointByID(cur_wp_id); // Sanity check wp first. - if (wp == nullptr) + if (!sb_wp) continue; - WatchpointOptions *wp_options = wp->GetOptions(); + WatchpointOptions *wp_options = sb_wp.GetSP()->GetOptions(); // Skip this watchpoint if wp_options is not good. if (wp_options == nullptr) continue; @@ -508,10 +511,10 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); - const WatchpointList &watchpoints = target->GetWatchpointList(); - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to have commands deleted"); @@ -527,8 +530,8 @@ } std::vector valid_wp_ids; - if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, - valid_wp_ids)) { + if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( + sb_target, command, valid_wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -539,9 +542,9 @@ for (size_t i = 0; i < count; ++i) { uint32_t cur_wp_id = valid_wp_ids.at(i); if (cur_wp_id != LLDB_INVALID_WATCH_ID) { - Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get(); - if (wp) - wp->ClearCallback(); + SBWatchpoint sb_wp = sb_target.FindWatchpointByID(cur_wp_id); + if (sb_wp) + sb_wp.GetSP()->ClearCallback(); } else { result.AppendErrorWithFormat("Invalid watchpoint ID: %u.\n", cur_wp_id); result.SetStatus(eReturnStatusFailed); @@ -580,10 +583,10 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + lldb::SBTarget sb_target(target_sp); - const WatchpointList &watchpoints = target->GetWatchpointList(); - size_t num_watchpoints = watchpoints.GetSize(); + size_t num_watchpoints = sb_target.GetNumWatchpoints(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist for which to list commands"); @@ -599,8 +602,8 @@ } std::vector valid_wp_ids; - if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, - valid_wp_ids)) { + if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( + sb_target, command, valid_wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; @@ -611,10 +614,10 @@ for (size_t i = 0; i < count; ++i) { uint32_t cur_wp_id = valid_wp_ids.at(i); if (cur_wp_id != LLDB_INVALID_WATCH_ID) { - Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get(); + SBWatchpoint sb_wp = sb_target.FindWatchpointByID(cur_wp_id); - if (wp) { - const WatchpointOptions *wp_options = wp->GetOptions(); + if (sb_wp) { + const WatchpointOptions *wp_options = sb_wp.GetSP()->GetOptions(); if (wp_options) { // Get the callback baton associated with the current watchpoint. const Baton *baton = wp_options->GetBaton();