[Lldb-commits] [PATCH] D105914: [lldb] Make TargetList iterable

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 13 10:34:21 PDT 2021


JDevlieghere created this revision.
JDevlieghere added a reviewer: jingham.
JDevlieghere requested review of this revision.

Make it possible to iterate over the TargetList.


https://reviews.llvm.org/D105914

Files:
  lldb/include/lldb/Target/TargetList.h


Index: lldb/include/lldb/Target/TargetList.h
===================================================================
--- lldb/include/lldb/Target/TargetList.h
+++ lldb/include/lldb/Target/TargetList.h
@@ -14,6 +14,7 @@
 
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/Broadcaster.h"
+#include "lldb/Utility/Iterable.h"
 
 namespace lldb_private {
 
@@ -42,6 +43,11 @@
     return GetStaticBroadcasterClass();
   }
 
+  typedef std::vector<lldb::TargetSP> collection;
+  typedef LockingAdaptedIterable<collection, lldb::TargetSP, vector_adapter,
+                                 std::recursive_mutex>
+      TargetIterable;
+
   /// Create a new Target.
   ///
   /// Clients must use this function to create a Target. This allows
@@ -179,14 +185,15 @@
 
   lldb::TargetSP GetSelectedTarget();
 
-protected:
-  typedef std::vector<lldb::TargetSP> collection;
-  // Member variables.
+  TargetIterable Targets() {
+    return TargetIterable(m_target_list, m_target_list_mutex);
+  }
+
+private:
   collection m_target_list;
   mutable std::recursive_mutex m_target_list_mutex;
   uint32_t m_selected_target_idx;
 
-private:
   static Status CreateTargetInternal(
       Debugger &debugger, llvm::StringRef user_exe_path,
       llvm::StringRef triple_str, LoadDependentFiles load_dependent_files,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105914.358338.patch
Type: text/x-patch
Size: 1302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210713/1a3b0201/attachment.bin>


More information about the lldb-commits mailing list