[Lldb-commits] [lldb] Remove watchpointresource setid method (PR #79388)

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 24 15:04:06 PST 2024


https://github.com/jasonmolenda created https://github.com/llvm/llvm-project/pull/79388

None

>From 229ea2a0311c7c0ecd8554016d3827f8c8ae6c5f Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Wed, 24 Jan 2024 14:45:41 -0800
Subject: [PATCH 1/2] [lldb] [NFC] Remove unused WatchpointResourceList class

In `[lldb] [mostly NFC] Large WP foundation: WatchpointResources
(#68845)` I added a new template StopPointSiteList to combine
WatchpointResourceList and BreakpointSiteList.  But I didn't
remove the now-unused WatchpointResourceList class.  This patch
fixes that.
---
 .../lldb/Breakpoint/WatchpointResourceList.h  | 145 ------------------
 .../Breakpoint/WatchpointResourceList.cpp     | 114 --------------
 2 files changed, 259 deletions(-)
 delete mode 100644 lldb/include/lldb/Breakpoint/WatchpointResourceList.h
 delete mode 100644 lldb/source/Breakpoint/WatchpointResourceList.cpp

diff --git a/lldb/include/lldb/Breakpoint/WatchpointResourceList.h b/lldb/include/lldb/Breakpoint/WatchpointResourceList.h
deleted file mode 100644
index 0e6c5fab877895..00000000000000
--- a/lldb/include/lldb/Breakpoint/WatchpointResourceList.h
+++ /dev/null
@@ -1,145 +0,0 @@
-//===-- WatchpointResourceList.h --------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLDB_BREAKPOINT_WATCHPOINTRESOURCELIST_H
-#define LLDB_BREAKPOINT_WATCHPOINTRESOURCELIST_H
-
-#include "lldb/Utility/Iterable.h"
-#include "lldb/lldb-private.h"
-#include "lldb/lldb-public.h"
-
-#include <mutex>
-#include <vector>
-
-namespace lldb_private {
-
-class WatchpointResourceList {
-
-public:
-  WatchpointResourceList();
-
-  ~WatchpointResourceList();
-
-  /// Add a WatchpointResource to the list.
-  ///
-  /// \param[in] wp_res_sp
-  ///    A shared pointer to a breakpoint site being added to the list.
-  ///
-  /// \return
-  ///    The ID of the BreakpointSite in the list.
-  lldb::wp_resource_id_t Add(const lldb::WatchpointResourceSP &wp_res_sp);
-
-  /// Removes the watchpoint resource given by \a id from this list.
-  ///
-  /// \param[in] id
-  ///   The watchpoint resource to remove.
-  ///
-  /// \result
-  ///   \b true if the watchpoint resource \a id was in the list.
-  bool Remove(lldb::wp_resource_id_t id);
-
-  /// Removes the watchpoint resource containing address \a addr from this list.
-  ///
-  /// \param[in] addr
-  ///   The address from which to remove a watchpoint resource.
-  ///
-  /// \result
-  ///   \b true if \a addr had a watchpoint resource to remove from the list.
-  bool RemoveByAddress(lldb::addr_t addr);
-
-  /// Returns a shared pointer to the watchpoint resource which contains
-  /// \a addr.
-  ///
-  /// \param[in] addr
-  ///     The address to look for.
-  ///
-  /// \result
-  ///     A shared pointer to the watchpoint resource. May contain a nullptr
-  ///     pointer if no watchpoint site exists with a matching address.
-  lldb::WatchpointResourceSP FindByAddress(lldb::addr_t addr);
-
-  /// Returns a shared pointer to the watchpoint resource which is owned
-  /// by \a wp_sp.
-  ///
-  /// \param[in] wp_sp
-  ///     The WatchpointSP to look for.
-  ///
-  /// \result
-  ///     A shared pointer to the watchpoint resource. May contain a nullptr
-  ///     pointer if no watchpoint site exists
-  lldb::WatchpointResourceSP FindByWatchpointSP(lldb::WatchpointSP &wp_sp);
-
-  /// Returns a shared pointer to the watchpoint resource which is owned
-  /// by \a wp.
-  ///
-  /// \param[in] wp
-  ///     The Watchpoint to look for.
-  ///
-  /// \result
-  ///     A shared pointer to the watchpoint resource. May contain a nullptr
-  ///     pointer if no watchpoint site exists
-  lldb::WatchpointResourceSP
-  FindByWatchpoint(const lldb_private::Watchpoint *wp);
-
-  /// Returns a shared pointer to the watchpoint resource which has hardware
-  /// index \a id.  Some Process plugins may not have access to the actual
-  /// hardware watchpoint register number used for a WatchpointResource, so
-  /// the wp_resource_id_t may not be correctly tracking the target's wp
-  /// register target.
-  ///
-  /// \param[in] id
-  ///     The hardware resource index to search for.
-  ///
-  /// \result
-  ///     A shared pointer to the watchpoint resource. May contain a nullptr
-  ///     pointer if no watchpoint site exists with a matching id.
-  lldb::WatchpointResourceSP FindByID(lldb::wp_resource_id_t id);
-
-  ///
-  /// Get the number of WatchpointResources that are available.
-  ///
-  /// \return
-  ///     The number of WatchpointResources that are stored in the
-  ///     WatchpointResourceList.
-  uint32_t GetSize();
-
-  /// Get the WatchpointResource at a given index.
-  ///
-  /// \param [in] idx
-  ///     The index of the resource.
-  /// \return
-  ///     The WatchpointResource at that index number.
-  lldb::WatchpointResourceSP GetResourceAtIndex(uint32_t idx);
-
-  typedef std::vector<lldb::WatchpointResourceSP> collection;
-  typedef LockingAdaptedIterable<collection, lldb::WatchpointResourceSP,
-                                 vector_adapter, std::mutex>
-      WatchpointResourceIterable;
-
-  /// Iterate over the list of WatchpointResources.
-  ///
-  /// \return
-  ///     An Iterable object which can be used to loop over the resources
-  ///     that exist.
-  WatchpointResourceIterable Resources() {
-    return WatchpointResourceIterable(m_resources, m_mutex);
-  }
-
-  /// Clear out the list of resources from the WatchpointResourceList
-  void Clear();
-
-  std::mutex &GetMutex();
-
-private:
-  collection m_resources;
-  std::mutex m_mutex;
-};
-
-} // namespace lldb_private
-
-#endif // LLDB_BREAKPOINT_WATCHPOINTRESOURCELIST_H
diff --git a/lldb/source/Breakpoint/WatchpointResourceList.cpp b/lldb/source/Breakpoint/WatchpointResourceList.cpp
deleted file mode 100644
index d1d364832098f4..00000000000000
--- a/lldb/source/Breakpoint/WatchpointResourceList.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-//===-- WatchpointResourceList.cpp ----------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Breakpoint/WatchpointResourceList.h"
-#include "lldb/Breakpoint/WatchpointResource.h"
-#include "lldb/Utility/LLDBLog.h"
-#include "lldb/Utility/Log.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-WatchpointResourceList::WatchpointResourceList() : m_resources(), m_mutex() {}
-
-WatchpointResourceList::~WatchpointResourceList() { Clear(); }
-
-wp_resource_id_t
-WatchpointResourceList::Add(const WatchpointResourceSP &wp_res_sp) {
-  Log *log = GetLog(LLDBLog::Watchpoints);
-  std::lock_guard<std::mutex> guard(m_mutex);
-  LLDB_LOGF(log, "WatchpointResourceList::Add(addr 0x%" PRIx64 " size %zu)",
-            wp_res_sp->GetLoadAddress(), wp_res_sp->GetByteSize());
-
-  m_resources.push_back(wp_res_sp);
-  return wp_res_sp->GetID();
-}
-
-bool WatchpointResourceList::Remove(wp_resource_id_t id) {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  Log *log = GetLog(LLDBLog::Watchpoints);
-  for (collection::iterator pos = m_resources.begin(); pos != m_resources.end();
-       ++pos) {
-    if ((*pos)->GetID() == id) {
-      LLDB_LOGF(log,
-                "WatchpointResourceList::Remove(addr 0x%" PRIx64 " size %zu)",
-                (*pos)->GetLoadAddress(), (*pos)->GetByteSize());
-      m_resources.erase(pos);
-      return true;
-    }
-  }
-  return false;
-}
-
-bool WatchpointResourceList::RemoveByAddress(addr_t addr) {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  Log *log = GetLog(LLDBLog::Watchpoints);
-  for (collection::iterator pos = m_resources.begin(); pos != m_resources.end();
-       ++pos) {
-    if ((*pos)->Contains(addr)) {
-      LLDB_LOGF(log,
-                "WatchpointResourceList::RemoveByAddress(addr 0x%" PRIx64
-                " size %zu)",
-                (*pos)->GetLoadAddress(), (*pos)->GetByteSize());
-      m_resources.erase(pos);
-      return true;
-    }
-  }
-  return false;
-}
-
-WatchpointResourceSP WatchpointResourceList::FindByAddress(addr_t addr) {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  for (WatchpointResourceSP wp_res_sp : m_resources)
-    if (wp_res_sp->Contains(addr))
-      return wp_res_sp;
-  return {};
-}
-
-WatchpointResourceSP
-WatchpointResourceList::FindByWatchpointSP(WatchpointSP &wp_sp) {
-  return FindByWatchpoint(wp_sp.get());
-}
-
-WatchpointResourceSP
-WatchpointResourceList::FindByWatchpoint(const Watchpoint *wp) {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  for (WatchpointResourceSP wp_res_sp : m_resources)
-    if (wp_res_sp->ConstituentsContains(wp))
-      return wp_res_sp;
-  return {};
-}
-
-WatchpointResourceSP WatchpointResourceList::FindByID(wp_resource_id_t id) {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  for (WatchpointResourceSP wp_res_sp : m_resources)
-    if (wp_res_sp->GetID() == id)
-      return wp_res_sp;
-  return {};
-}
-
-uint32_t WatchpointResourceList::GetSize() {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  return m_resources.size();
-}
-
-lldb::WatchpointResourceSP
-WatchpointResourceList::GetResourceAtIndex(uint32_t idx) {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  if (idx < m_resources.size())
-    return m_resources[idx];
-
-  return {};
-}
-
-void WatchpointResourceList::Clear() {
-  std::lock_guard<std::mutex> guard(m_mutex);
-  m_resources.clear();
-}
-
-std::mutex &WatchpointResourceList::GetMutex() { return m_mutex; }

>From f5062d13cc119cf9f351287249bbae26867ee71e Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Wed, 24 Jan 2024 15:00:53 -0800
Subject: [PATCH 2/2] [lldb] [NFC] Remove unused WatchpointResource::SetID
 method

I originally thought to try to guesstimate the hardware watchpoint
index number that a Resource was associated with, but gdb remote
serial protocol doesn't give us the hardware register index used
so it was only a guess.  I changed my mind and simply use
ever-incrementing ID numbers for the WatchpointResources, but forgot
to remove the SetID method.
---
 lldb/include/lldb/Breakpoint/WatchpointResource.h | 8 --------
 lldb/source/Breakpoint/WatchpointResource.cpp     | 2 --
 2 files changed, 10 deletions(-)

diff --git a/lldb/include/lldb/Breakpoint/WatchpointResource.h b/lldb/include/lldb/Breakpoint/WatchpointResource.h
index 4b1d733850f1bb..070d84cff8f26f 100644
--- a/lldb/include/lldb/Breakpoint/WatchpointResource.h
+++ b/lldb/include/lldb/Breakpoint/WatchpointResource.h
@@ -121,14 +121,6 @@ class WatchpointResource
   ///    A copy of the Watchpoints which own this resource.
   WatchpointCollection CopyConstituentsList();
 
-  // The ID of the WatchpointResource is set by the WatchpointResourceList
-  // when the Resource has been set in the inferior and is being added
-  // to the List, in an attempt to match the hardware watchpoint register
-  // ordering.  If a Process can correctly identify the hardware watchpoint
-  // register index when it has created the Resource, it may initialize it
-  // before it is inserted in the WatchpointResourceList.
-  void SetID(lldb::wp_resource_id_t);
-
   lldb::wp_resource_id_t GetID() const;
 
   bool Contains(lldb::addr_t addr);
diff --git a/lldb/source/Breakpoint/WatchpointResource.cpp b/lldb/source/Breakpoint/WatchpointResource.cpp
index d0f8dc346f3c02..c1eb50c0358b30 100644
--- a/lldb/source/Breakpoint/WatchpointResource.cpp
+++ b/lldb/source/Breakpoint/WatchpointResource.cpp
@@ -42,8 +42,6 @@ void WatchpointResource::SetType(bool read, bool write) {
 
 wp_resource_id_t WatchpointResource::GetID() const { return m_id; }
 
-void WatchpointResource::SetID(wp_resource_id_t id) { m_id = id; }
-
 bool WatchpointResource::Contains(addr_t addr) {
   if (addr >= m_addr && addr < m_addr + m_size)
     return true;



More information about the lldb-commits mailing list