shivammittal99 created this revision.
shivammittal99 added reviewers: jingham, teemperor.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Signed-off-by: Shivam Mittal <shivammitta...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82732

Files:
  lldb/include/lldb/API/SBBreakpoint.h
  lldb/include/lldb/API/SBBreakpointLocation.h
  lldb/source/Commands/CommandObjectBreakpointCommand.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Commands/CommandObjectWatchpoint.cpp
  lldb/source/Commands/CommandObjectWatchpoint.h
  lldb/source/Commands/CommandObjectWatchpointCommand.cpp

Index: lldb/source/Commands/CommandObjectWatchpointCommand.cpp
===================================================================
--- lldb/source/Commands/CommandObjectWatchpointCommand.cpp
+++ 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<uint32_t> valid_wp_ids;
-    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command,
-                                                               valid_wp_ids)) {
+    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
+            target_sp, 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<uint32_t> valid_wp_ids;
-    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command,
-                                                               valid_wp_ids)) {
+    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
+            target_sp, 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<uint32_t> valid_wp_ids;
-    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command,
-                                                               valid_wp_ids)) {
+    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
+            target_sp, 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();
Index: lldb/source/Commands/CommandObjectWatchpoint.h
===================================================================
--- lldb/source/Commands/CommandObjectWatchpoint.h
+++ lldb/source/Commands/CommandObjectWatchpoint.h
@@ -12,6 +12,8 @@
 #include "lldb/Interpreter/CommandObjectMultiword.h"
 #include "lldb/Interpreter/OptionGroupWatchpoint.h"
 
+using namespace lldb;
+
 namespace lldb_private {
 
 // CommandObjectMultiwordWatchpoint
@@ -22,7 +24,7 @@
 
   ~CommandObjectMultiwordWatchpoint() override;
 
-  static bool VerifyWatchpointIDs(Target *target, Args &args,
+  static bool VerifyWatchpointIDs(TargetSP target_sp, Args &args,
                                   std::vector<uint32_t> &wp_ids);
 };
 
Index: lldb/source/Commands/CommandObjectWatchpoint.cpp
===================================================================
--- lldb/source/Commands/CommandObjectWatchpoint.cpp
+++ lldb/source/Commands/CommandObjectWatchpoint.cpp
@@ -25,21 +25,24 @@
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/StreamString.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(TargetSP target_sp,
                                                CommandReturnObject &result) {
   bool process_is_valid =
-      target->GetProcessSP() && target->GetProcessSP()->IsAlive();
+      target_sp->GetProcessSP() && target_sp->GetProcessSP()->IsAlive();
   if (!process_is_valid) {
     result.AppendError("There's no process or it is not alive.");
     result.SetStatus(eReturnStatusFailed);
@@ -65,12 +68,12 @@
 // Return true if wp_ids is successfully populated with the watch ids. False
 // otherwise.
 bool CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
-    Target *target, Args &args, std::vector<uint32_t> &wp_ids) {
+    TargetSP target_sp, Args &args, std::vector<uint32_t> &wp_ids) {
   // Pre-condition: args.GetArgumentCount() > 0.
   if (args.GetArgumentCount() == 0) {
-    if (target == nullptr)
+    if (!target_sp)
       return false;
-    WatchpointSP watch_sp = target->GetLastCreatedWatchpoint();
+    WatchpointSP watch_sp = target_sp->GetLastCreatedWatchpoint();
     if (watch_sp) {
       wp_ids.push_back(watch_sp->GetID());
       return true;
@@ -211,11 +214,12 @@
 
 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()) {
+    if (target_sp->GetProcessSP() && target_sp->GetProcessSP()->IsAlive()) {
       uint32_t num_supported_hardware_watchpoints;
-      Status error = target->GetProcessSP()->GetWatchpointSupportInfo(
+      Status error = target_sp->GetProcessSP()->GetWatchpointSupportInfo(
           num_supported_hardware_watchpoints);
       if (error.Success())
         result.AppendMessageWithFormat(
@@ -223,12 +227,7 @@
             num_supported_hardware_watchpoints);
     }
 
-    const WatchpointList &watchpoints = target->GetWatchpointList();
-
-    std::unique_lock<std::recursive_mutex> 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<uint32_t> wp_ids;
       if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
-              target, command, wp_ids)) {
+              target_sp, 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(target_sp, result))
       return false;
 
-    std::unique_lock<std::recursive_mutex> 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<uint32_t> wp_ids;
       if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
-              target, command, wp_ids)) {
+              target_sp, command, wp_ids)) {
         result.AppendError("Invalid watchpoints specification.");
         result.SetStatus(eReturnStatusFailed);
         return false;
@@ -330,9 +325,13 @@
 
       int count = 0;
       const size_t size = wp_ids.size();
-      for (size_t i = 0; i < size; ++i)
-        if (target->EnableWatchpointByID(wp_ids[i]))
+      for (size_t i = 0; i < size; ++i) {
+        lldb::SBWatchpoint sb_wp(sb_target.FindWatchpointByID(wp_ids[i]));
+        sb_wp.SetEnabled(false);
+
+        if (sb_wp.IsEnabled())
           ++count;
+      }
       result.AppendMessageWithFormat("%d watchpoints enabled.\n", count);
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
     }
@@ -364,15 +363,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(target_sp, result))
       return false;
 
-    std::unique_lock<std::recursive_mutex> 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 +378,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 +391,7 @@
       // Particular watchpoints selected; disable them.
       std::vector<uint32_t> wp_ids;
       if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
-              target, command, wp_ids)) {
+              target_sp, command, wp_ids)) {
         result.AppendError("Invalid watchpoints specification.");
         result.SetStatus(eReturnStatusFailed);
         return false;
@@ -403,9 +399,13 @@
 
       int count = 0;
       const size_t size = wp_ids.size();
-      for (size_t i = 0; i < size; ++i)
-        if (target->DisableWatchpointByID(wp_ids[i]))
+      for (size_t i = 0; i < size; ++i) {
+        lldb::SBWatchpoint sb_wp(sb_target.FindWatchpointByID(wp_ids[i]));
+        sb_wp.SetEnabled(false);
+
+        if (!sb_wp.IsEnabled())
           ++count;
+      }
       result.AppendMessageWithFormat("%d watchpoints disabled.\n", count);
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
     }
@@ -476,16 +476,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(target_sp, result))
       return false;
 
-    std::unique_lock<std::recursive_mutex> 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 +496,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 +507,8 @@
 
     // Particular watchpoints selected; delete them.
     std::vector<uint32_t> wp_ids;
-    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command,
-                                                               wp_ids)) {
+    if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
+            target_sp, command, wp_ids)) {
       result.AppendError("Invalid watchpoints specification.");
       result.SetStatus(eReturnStatusFailed);
       return false;
@@ -521,7 +517,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 +594,13 @@
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = &GetSelectedTarget();
-    if (!CheckTargetForWatchpointOperations(target, result))
-      return false;
-
-    std::unique_lock<std::recursive_mutex> lock;
-    target->GetWatchpointList().GetListMutex(lock);
+    TargetSP target_sp = GetDebugger().GetSelectedTarget();
+    lldb::SBTarget sb_target(target_sp);
 
-    const WatchpointList &watchpoints = target->GetWatchpointList();
+    if (!CheckTargetForWatchpointOperations(target_sp, 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 +609,7 @@
     }
 
     if (command.GetArgumentCount() == 0) {
-      target->IgnoreAllWatchpoints(m_options.m_ignore_count);
+      target_sp->IgnoreAllWatchpoints(m_options.m_ignore_count);
       result.AppendMessageWithFormat("All watchpoints ignored. (%" PRIu64
                                      " watchpoints)\n",
                                      (uint64_t)num_watchpoints);
@@ -625,7 +618,7 @@
       // Particular watchpoints selected; ignore them.
       std::vector<uint32_t> wp_ids;
       if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
-              target, command, wp_ids)) {
+              target_sp, command, wp_ids)) {
         result.AppendError("Invalid watchpoints specification.");
         result.SetStatus(eReturnStatusFailed);
         return false;
@@ -634,7 +627,8 @@
       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 (target_sp->IgnoreWatchpointByID(wp_ids[i],
+                                            m_options.m_ignore_count))
           ++count;
       result.AppendMessageWithFormat("%d watchpoints ignored.\n", count);
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -719,16 +713,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(target_sp, result))
       return false;
 
-    std::unique_lock<std::recursive_mutex> 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 +727,14 @@
     }
 
     if (command.GetArgumentCount() == 0) {
-      WatchpointSP wp_sp = target->GetLastCreatedWatchpoint();
+      WatchpointSP wp_sp = target_sp->GetLastCreatedWatchpoint();
       wp_sp->SetCondition(m_options.m_condition.c_str());
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
     } else {
       // Particular watchpoints selected; set condition on them.
       std::vector<uint32_t> wp_ids;
       if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
-              target, command, wp_ids)) {
+              target_sp, command, wp_ids)) {
         result.AppendError("Invalid watchpoints specification.");
         result.SetStatus(eReturnStatusFailed);
         return false;
@@ -753,9 +743,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 +827,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 +879,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 +914,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 +1011,7 @@
     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();
     StackFrame *frame = m_exe_ctx.GetFramePtr();
 
     OptionsWithRaw args(raw_command);
@@ -1065,7 +1054,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 +1078,7 @@
     if (m_option_watchpoint.watch_size != 0)
       size = m_option_watchpoint.watch_size;
     else
-      size = target->GetArchitecture().GetAddressByteSize();
+      size = target_sp->GetArchitecture().GetAddressByteSize();
 
     // Now it's time to create the watchpoint.
     uint32_t watch_type = m_option_watchpoint.watch_type;
@@ -1100,13 +1089,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 {
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ 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 {
Index: lldb/source/Commands/CommandObjectBreakpointCommand.cpp
===================================================================
--- lldb/source/Commands/CommandObjectBreakpointCommand.cpp
+++ 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",
Index: lldb/include/lldb/API/SBBreakpointLocation.h
===================================================================
--- lldb/include/lldb/API/SBBreakpointLocation.h
+++ 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;
 };
Index: lldb/include/lldb/API/SBBreakpoint.h
===================================================================
--- lldb/include/lldb/API/SBBreakpoint.h
+++ 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;
 };
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to