tatyana-krasnukha updated this revision to Diff 281600.
tatyana-krasnukha added reviewers: JDevlieghere, jingham.
tatyana-krasnukha added a comment.

Addressed comments.

> It's also a little weird that we're clearing watchpoint hit counts when a 
> process dies, but not breakpoint hit counts. If we do one we should do the 
> other...

BreakpointSites die with the Process, so there is no need to reset their hit 
count. I'm not sure what logic Breakpoint should follow (as it lives without a 
process). If we are going to change it, I would do it in a different revision.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84527/new/

https://reviews.llvm.org/D84527

Files:
  lldb/include/lldb/Breakpoint/Breakpoint.h
  lldb/include/lldb/Breakpoint/BreakpointLocation.h
  lldb/include/lldb/Breakpoint/BreakpointSite.h
  lldb/include/lldb/Breakpoint/StoppointHitCounter.h
  lldb/include/lldb/Breakpoint/StoppointLocation.h
  lldb/include/lldb/Breakpoint/StoppointSite.h
  lldb/include/lldb/Breakpoint/Watchpoint.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Breakpoint/Breakpoint.cpp
  lldb/source/Breakpoint/BreakpointLocation.cpp
  lldb/source/Breakpoint/BreakpointSite.cpp
  lldb/source/Breakpoint/CMakeLists.txt
  lldb/source/Breakpoint/StoppointLocation.cpp
  lldb/source/Breakpoint/StoppointSite.cpp
  lldb/source/Breakpoint/Watchpoint.cpp

Index: lldb/source/Breakpoint/Watchpoint.cpp
===================================================================
--- lldb/source/Breakpoint/Watchpoint.cpp
+++ lldb/source/Breakpoint/Watchpoint.cpp
@@ -25,7 +25,7 @@
 
 Watchpoint::Watchpoint(Target &target, lldb::addr_t addr, uint32_t size,
                        const CompilerType *type, bool hardware)
-    : StoppointLocation(0, addr, size, hardware), m_target(target),
+    : StoppointSite(0, addr, size, hardware), m_target(target),
       m_enabled(false), m_is_hardware(hardware), m_is_watch_variable(false),
       m_is_ephemeral(false), m_disabled_count(0), m_watch_read(0),
       m_watch_write(0), m_watch_was_read(0), m_watch_was_written(0),
@@ -93,8 +93,6 @@
   m_watch_spec_str = str;
 }
 
-// Override default impl of StoppointLocation::IsHardware() since m_is_hardware
-// member field is more accurate.
 bool Watchpoint::IsHardware() const {
   lldbassert(m_is_hardware || GetHardwareIndex() == LLDB_INVALID_INDEX32);
   lldbassert(m_is_hardware || !HardwareRequired());
@@ -127,12 +125,12 @@
 void Watchpoint::IncrementFalseAlarmsAndReviseHitCount() {
   ++m_false_alarms;
   if (m_false_alarms) {
-    if (m_hit_count >= m_false_alarms) {
-      m_hit_count -= m_false_alarms;
+    if (m_hit_counter.GetValue() >= m_false_alarms) {
+      m_hit_counter.Decrement(m_false_alarms);
       m_false_alarms = 0;
     } else {
-      m_false_alarms -= m_hit_count;
-      m_hit_count = 0;
+      m_false_alarms -= m_hit_counter.GetValue();
+      m_hit_counter.Reset();
     }
   }
 }
@@ -141,7 +139,7 @@
 // should continue.
 
 bool Watchpoint::ShouldStop(StoppointCallbackContext *context) {
-  IncrementHitCount();
+  m_hit_counter.Increment();
 
   return IsEnabled();
 }
Index: lldb/source/Breakpoint/StoppointSite.cpp
===================================================================
--- /dev/null
+++ lldb/source/Breakpoint/StoppointSite.cpp
@@ -0,0 +1,23 @@
+//===-- StoppointSite.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/StoppointSite.h"
+
+
+using namespace lldb;
+using namespace lldb_private;
+
+StoppointSite::StoppointSite(break_id_t id, addr_t addr, bool hardware)
+    : m_id(id), m_addr(addr), m_is_hardware_required(hardware),
+      m_hardware_index(LLDB_INVALID_INDEX32), m_byte_size(0), m_hit_counter() {}
+
+StoppointSite::StoppointSite(break_id_t id, addr_t addr,
+                             uint32_t byte_size, bool hardware)
+    : m_id(id), m_addr(addr), m_is_hardware_required(hardware),
+      m_hardware_index(LLDB_INVALID_INDEX32), m_byte_size(byte_size),
+      m_hit_counter() {}
Index: lldb/source/Breakpoint/StoppointLocation.cpp
===================================================================
--- lldb/source/Breakpoint/StoppointLocation.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//===-- StoppointLocation.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/StoppointLocation.h"
-
-
-using namespace lldb;
-using namespace lldb_private;
-
-// StoppointLocation constructor
-StoppointLocation::StoppointLocation(break_id_t bid, addr_t addr, bool hardware)
-    : m_loc_id(bid), m_addr(addr), m_hardware(hardware),
-      m_hardware_index(LLDB_INVALID_INDEX32), m_byte_size(0), m_hit_count(0) {}
-
-StoppointLocation::StoppointLocation(break_id_t bid, addr_t addr,
-                                     uint32_t byte_size, bool hardware)
-    : m_loc_id(bid), m_addr(addr), m_hardware(hardware),
-      m_hardware_index(LLDB_INVALID_INDEX32), m_byte_size(byte_size),
-      m_hit_count(0) {}
-
-// Destructor
-StoppointLocation::~StoppointLocation() {}
-
-void StoppointLocation::DecrementHitCount() {
-  assert(m_hit_count > 0);
-  --m_hit_count;
-}
Index: lldb/source/Breakpoint/CMakeLists.txt
===================================================================
--- lldb/source/Breakpoint/CMakeLists.txt
+++ lldb/source/Breakpoint/CMakeLists.txt
@@ -19,7 +19,7 @@
   BreakpointSiteList.cpp
   Stoppoint.cpp
   StoppointCallbackContext.cpp
-  StoppointLocation.cpp
+  StoppointSite.cpp
   Watchpoint.cpp
   WatchpointList.cpp
   WatchpointOptions.cpp
Index: lldb/source/Breakpoint/BreakpointSite.cpp
===================================================================
--- lldb/source/Breakpoint/BreakpointSite.cpp
+++ lldb/source/Breakpoint/BreakpointSite.cpp
@@ -21,7 +21,7 @@
 BreakpointSite::BreakpointSite(BreakpointSiteList *list,
                                const BreakpointLocationSP &owner,
                                lldb::addr_t addr, bool use_hardware)
-    : StoppointLocation(GetNextID(), addr, 0, use_hardware),
+    : StoppointSite(GetNextID(), addr, 0, use_hardware),
       m_type(eSoftware), // Process subclasses need to set this correctly using
                          // SetType()
       m_saved_opcode(), m_trap_opcode(),
@@ -48,7 +48,7 @@
 // should continue.
 
 bool BreakpointSite::ShouldStop(StoppointCallbackContext *context) {
-  IncrementHitCount();
+  m_hit_counter.Increment();
   // ShouldStop can do a lot of work, and might even come come back and hit
   // this breakpoint site again.  So don't hold the m_owners_mutex the whole
   // while.  Instead make a local copy of the collection and call ShouldStop on
@@ -156,13 +156,6 @@
   }
 }
 
-void BreakpointSite::SetHardwareIndex(uint32_t index) {
-  std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
-  for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) {
-    loc_sp->SetHardwareIndex(index);
-  }
-}
-
 bool BreakpointSite::IntersectsRange(lldb::addr_t addr, size_t size,
                                      lldb::addr_t *intersect_addr,
                                      size_t *intersect_size,
Index: lldb/source/Breakpoint/BreakpointLocation.cpp
===================================================================
--- lldb/source/Breakpoint/BreakpointLocation.cpp
+++ lldb/source/Breakpoint/BreakpointLocation.cpp
@@ -31,11 +31,10 @@
 BreakpointLocation::BreakpointLocation(break_id_t loc_id, Breakpoint &owner,
                                        const Address &addr, lldb::tid_t tid,
                                        bool hardware, bool check_for_resolver)
-    : StoppointLocation(loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()),
-                        hardware),
-      m_being_created(true), m_should_resolve_indirect_functions(false),
+    : m_being_created(true), m_should_resolve_indirect_functions(false),
       m_is_reexported(false), m_is_indirect(false), m_address(addr),
-      m_owner(owner), m_options_up(), m_bp_site_sp(), m_condition_mutex() {
+      m_owner(owner), m_options_up(), m_bp_site_sp(), m_condition_mutex(),
+      m_condition_hash(0), m_loc_id(loc_id), m_hit_counter() {
   if (check_for_resolver) {
     Symbol *symbol = m_address.CalculateSymbolContextSymbol();
     if (symbol && symbol->IsIndirect()) {
@@ -68,14 +67,6 @@
 
 Target &BreakpointLocation::GetTarget() { return m_owner.GetTarget(); }
 
-bool BreakpointLocation::IsHardware() const {
-  if (m_bp_site_sp)
-    return m_bp_site_sp->IsHardware();
-
-  // If breakpoint location is not resolved yet, it cannot be hardware.
-  return false;
-}
-
 bool BreakpointLocation::IsEnabled() const {
   if (!m_owner.IsEnabled())
     return false;
@@ -340,7 +331,7 @@
   return ret;
 }
 
-uint32_t BreakpointLocation::GetIgnoreCount() {
+uint32_t BreakpointLocation::GetIgnoreCount() const {
   return GetOptionsSpecifyingKind(BreakpointOptions::eIgnoreCount)
       ->GetIgnoreCount();
 }
@@ -425,16 +416,16 @@
 void BreakpointLocation::BumpHitCount() {
   if (IsEnabled()) {
     // Step our hit count, and also step the hit count of the owner.
-    IncrementHitCount();
-    m_owner.IncrementHitCount();
+    m_hit_counter.Increment();
+    m_owner.m_hit_counter.Increment();
   }
 }
 
 void BreakpointLocation::UndoBumpHitCount() {
   if (IsEnabled()) {
     // Step our hit count, and also step the hit count of the owner.
-    DecrementHitCount();
-    m_owner.DecrementHitCount();
+    m_hit_counter.Decrement();
+    m_owner.m_hit_counter.Decrement();
   }
 }
 
@@ -601,12 +592,15 @@
     }
   }
 
+  bool is_resolved = IsResolved();
+  bool is_hardware = is_resolved && m_bp_site_sp->IsHardware();
+
   if (level == lldb::eDescriptionLevelVerbose) {
     s->EOL();
     s->Indent();
-    s->Printf("resolved = %s\n", IsResolved() ? "true" : "false");
+    s->Printf("resolved = %s\n", is_resolved ? "true" : "false");
     s->Indent();
-    s->Printf("hardware = %s\n", IsHardware() ? "true" : "false");
+    s->Printf("hardware = %s\n", is_hardware ? "true" : "false");
     s->Indent();
     s->Printf("hit count = %-4u\n", GetHitCount());
 
@@ -617,8 +611,8 @@
     }
     s->IndentLess();
   } else if (level != eDescriptionLevelInitial) {
-    s->Printf(", %sresolved, %shit count = %u ", (IsResolved() ? "" : "un"),
-              (IsHardware() ? "hardware, " : ""), GetHitCount());
+    s->Printf(", %sresolved, %shit count = %u ", (is_resolved ? "" : "un"),
+              (is_hardware ? "hardware, " : ""), GetHitCount());
     if (m_options_up) {
       m_options_up->GetDescription(s, level);
     }
@@ -629,6 +623,11 @@
   if (s == nullptr)
     return;
 
+  bool is_resolved = IsResolved();
+  bool is_hardware = is_resolved && m_bp_site_sp->IsHardware();
+  auto hardware_index = is_resolved ?
+      m_bp_site_sp->GetHardwareIndex() : LLDB_INVALID_INDEX32;
+
   lldb::tid_t tid = GetOptionsSpecifyingKind(BreakpointOptions::eThreadSpec)
       ->GetThreadSpecNoCreate()->GetTID();
   s->Printf("BreakpointLocation %u: tid = %4.4" PRIx64
@@ -639,8 +638,7 @@
             (m_options_up ? m_options_up->IsEnabled() : m_owner.IsEnabled())
                 ? "enabled "
                 : "disabled",
-            IsHardware() ? "hardware" : "software", GetHardwareIndex(),
-            GetHitCount(),
+            is_hardware ? "hardware" : "software", hardware_index, GetHitCount(),
             GetOptionsSpecifyingKind(BreakpointOptions::eIgnoreCount)
                 ->GetIgnoreCount());
 }
Index: lldb/source/Breakpoint/Breakpoint.cpp
===================================================================
--- lldb/source/Breakpoint/Breakpoint.cpp
+++ lldb/source/Breakpoint/Breakpoint.cpp
@@ -51,7 +51,7 @@
     : m_being_created(true), m_hardware(hardware), m_target(target),
       m_filter_sp(filter_sp), m_resolver_sp(resolver_sp),
       m_options_up(new BreakpointOptions(true)), m_locations(*this),
-      m_resolve_indirect_symbols(resolve_indirect_symbols), m_hit_count(0) {
+      m_resolve_indirect_symbols(resolve_indirect_symbols), m_hit_counter() {
   m_being_created = false;
 }
 
@@ -61,7 +61,7 @@
       m_options_up(new BreakpointOptions(*source_bp.m_options_up)),
       m_locations(*this),
       m_resolve_indirect_symbols(source_bp.m_resolve_indirect_symbols),
-      m_hit_count(0) {}
+      m_hit_counter() {}
 
 // Destructor
 Breakpoint::~Breakpoint() = default;
@@ -342,7 +342,7 @@
     return true;
 }
 
-uint32_t Breakpoint::GetHitCount() const { return m_hit_count; }
+uint32_t Breakpoint::GetHitCount() const { return m_hit_counter.GetValue(); }
 
 bool Breakpoint::IsOneShot() const { return m_options_up->IsOneShot(); }
 
Index: lldb/include/lldb/lldb-forward.h
===================================================================
--- lldb/include/lldb/lldb-forward.h
+++ lldb/include/lldb/lldb-forward.h
@@ -192,7 +192,6 @@
 class StopInfo;
 class Stoppoint;
 class StoppointCallbackContext;
-class StoppointLocation;
 class Stream;
 class StreamFile;
 class StreamString;
@@ -405,7 +404,6 @@
 typedef std::unique_ptr<lldb_private::StackFrameRecognizerManager>
     StackFrameRecognizerManagerUP;
 typedef std::shared_ptr<lldb_private::StopInfo> StopInfoSP;
-typedef std::shared_ptr<lldb_private::StoppointLocation> StoppointLocationSP;
 typedef std::shared_ptr<lldb_private::Stream> StreamSP;
 typedef std::weak_ptr<lldb_private::Stream> StreamWP;
 typedef std::shared_ptr<lldb_private::StreamFile> StreamFileSP;
Index: lldb/include/lldb/Breakpoint/Watchpoint.h
===================================================================
--- lldb/include/lldb/Breakpoint/Watchpoint.h
+++ lldb/include/lldb/Breakpoint/Watchpoint.h
@@ -12,7 +12,7 @@
 #include <memory>
 #include <string>
 
-#include "lldb/Breakpoint/StoppointLocation.h"
+#include "lldb/Breakpoint/StoppointSite.h"
 #include "lldb/Breakpoint/WatchpointOptions.h"
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Target/Target.h"
@@ -22,7 +22,7 @@
 namespace lldb_private {
 
 class Watchpoint : public std::enable_shared_from_this<Watchpoint>,
-                   public StoppointLocation {
+                   public StoppointSite {
 public:
   class WatchpointEventData : public EventData {
   public:
@@ -158,8 +158,6 @@
   friend class Target;
   friend class WatchpointList;
 
-  void ResetHitCount() { m_hit_count = 0; }
-
   void ResetHistoricValues() {
     m_old_value_sp.reset();
     m_new_value_sp.reset();
@@ -199,7 +197,7 @@
 
   std::unique_ptr<UserExpression> m_condition_up; // The condition to test.
 
-  void SetID(lldb::watch_id_t id) { m_loc_id = id; }
+  void SetID(lldb::watch_id_t id) { m_id = id; }
 
   void SendWatchpointChangedEvent(lldb::WatchpointEventType eventKind);
 
Index: lldb/include/lldb/Breakpoint/StoppointSite.h
===================================================================
--- /dev/null
+++ lldb/include/lldb/Breakpoint/StoppointSite.h
@@ -0,0 +1,81 @@
+//===-- StoppointSite.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_STOPPOINTSITE_H
+#define LLDB_BREAKPOINT_STOPPOINTSITE_H
+
+#include "lldb/Breakpoint/StoppointHitCounter.h"
+#include "lldb/Utility/UserID.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class StoppointSite {
+public:
+  StoppointSite(lldb::break_id_t bid, lldb::addr_t m_addr, bool hardware);
+
+  StoppointSite(lldb::break_id_t bid, lldb::addr_t m_addr,
+                uint32_t byte_size, bool hardware);
+
+  virtual ~StoppointSite() = default;
+
+  virtual lldb::addr_t GetLoadAddress() const { return m_addr; }
+
+  virtual void SetLoadAddress(lldb::addr_t addr) { m_addr = addr; }
+
+  uint32_t GetByteSize() const { return m_byte_size; }
+
+  uint32_t GetHitCount() const { return m_hit_counter.GetValue(); }
+
+  void ResetHitCount() { m_hit_counter.Reset(); }
+
+  bool HardwareRequired() const { return m_is_hardware_required; }
+
+  virtual bool IsHardware() const = 0;
+
+  uint32_t GetHardwareIndex() const { return m_hardware_index; }
+
+  void SetHardwareIndex(uint32_t index) { m_hardware_index = index; }
+
+  virtual bool ShouldStop(StoppointCallbackContext* context) = 0;
+
+  virtual void Dump(Stream* stream) const = 0;
+
+  lldb::break_id_t GetID() const { return m_id; }
+
+protected:
+  /// Stoppoint site ID.
+  lldb::break_id_t m_id;
+
+  /// The load address of this stop point.
+  lldb::addr_t m_addr;
+
+  /// True if this point is required to use hardware (which may fail due to
+  /// the lack of resources).
+  bool m_is_hardware_required;
+
+  /// The hardware resource index for this breakpoint/watchpoint.
+  uint32_t m_hardware_index;
+
+  /// The size in bytes of stoppoint, e.g. the length of the trap opcode for
+  /// software breakpoints, or the optional length in bytes for hardware
+  /// breakpoints, or the length of the watchpoint.
+  uint32_t m_byte_size;
+
+  /// Number of times this breakpoint/watchpoint has been hit.
+  StoppointHitCounter m_hit_counter;
+
+private:
+  StoppointSite(const StoppointSite &) = delete;
+  const StoppointSite &operator=(const StoppointSite &) = delete;
+  StoppointSite() = delete;
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_BREAKPOINT_STOPPOINTSITE_H
Index: lldb/include/lldb/Breakpoint/StoppointLocation.h
===================================================================
--- lldb/include/lldb/Breakpoint/StoppointLocation.h
+++ /dev/null
@@ -1,85 +0,0 @@
-//===-- StoppointLocation.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_STOPPOINTLOCATION_H
-#define LLDB_BREAKPOINT_STOPPOINTLOCATION_H
-
-#include "lldb/Utility/UserID.h"
-#include "lldb/lldb-private.h"
-// #include "lldb/Breakpoint/BreakpointOptions.h"
-
-namespace lldb_private {
-
-class StoppointLocation {
-public:
-  // Constructors and Destructors
-  StoppointLocation(lldb::break_id_t bid, lldb::addr_t m_addr, bool hardware);
-
-  StoppointLocation(lldb::break_id_t bid, lldb::addr_t m_addr,
-                    uint32_t byte_size, bool hardware);
-
-  virtual ~StoppointLocation();
-
-  // Operators
-
-  // Methods
-  virtual lldb::addr_t GetLoadAddress() const { return m_addr; }
-
-  virtual void SetLoadAddress(lldb::addr_t addr) { m_addr = addr; }
-
-  uint32_t GetByteSize() const { return m_byte_size; }
-
-  uint32_t GetHitCount() const { return m_hit_count; }
-
-  uint32_t GetHardwareIndex() const { return m_hardware_index; }
-
-  bool HardwareRequired() const { return m_hardware; }
-
-  virtual bool IsHardware() const = 0;
-
-  virtual bool ShouldStop(StoppointCallbackContext *context) { return true; }
-
-  virtual void Dump(Stream *stream) const {}
-
-  virtual void SetHardwareIndex(uint32_t index) { m_hardware_index = index; }
-
-  lldb::break_id_t GetID() const { return m_loc_id; }
-
-protected:
-  // Classes that inherit from StoppointLocation can see and modify these
-  lldb::break_id_t m_loc_id; // Stoppoint location ID
-  lldb::addr_t
-      m_addr; // The load address of this stop point. The base Stoppoint doesn't
-  // store a full Address since that's not needed for the breakpoint sites.
-  bool m_hardware; // True if this point has been is required to use hardware
-                   // (which may fail due to lack of resources)
-  uint32_t m_hardware_index; // The hardware resource index for this
-                             // breakpoint/watchpoint
-  uint32_t m_byte_size; // The size in bytes of stop location.  e.g. the length
-                        // of the trap opcode for
-  // software breakpoints, or the optional length in bytes for hardware
-  // breakpoints, or the length of the watchpoint.
-  uint32_t
-      m_hit_count; // Number of times this breakpoint/watchpoint has been hit
-
-  // If you override this, be sure to call the base class to increment the
-  // internal counter.
-  void IncrementHitCount() { ++m_hit_count; }
-
-  void DecrementHitCount();
-
-private:
-  // For StoppointLocation only
-  StoppointLocation(const StoppointLocation &) = delete;
-  const StoppointLocation &operator=(const StoppointLocation &) = delete;
-  StoppointLocation() = delete;
-};
-
-} // namespace lldb_private
-
-#endif // LLDB_BREAKPOINT_STOPPOINTLOCATION_H
Index: lldb/include/lldb/Breakpoint/StoppointHitCounter.h
===================================================================
--- /dev/null
+++ lldb/include/lldb/Breakpoint/StoppointHitCounter.h
@@ -0,0 +1,43 @@
+//===-- StoppointHitCounter.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_STOPPOINT_HIT_COUNTER_H
+#define LLDB_BREAKPOINT_STOPPOINT_HIT_COUNTER_H
+
+#include <assert.h>
+#include <cstdint>
+#include <limits>
+
+#include "lldb/Utility/LLDBAssert.h"
+
+namespace lldb_private {
+
+class StoppointHitCounter {
+public:
+  uint32_t GetValue() const { return m_hit_count; }
+
+  void Increment(uint32_t difference = 1) {
+    lldbassert(std::numeric_limits<uint32_t>::max() - m_hit_count >= difference);
+    m_hit_count += difference;
+  }
+
+  void Decrement(uint32_t difference = 1) {
+    lldbassert(m_hit_count >= difference);
+    m_hit_count -= difference;
+  }
+
+  void Reset() { m_hit_count = 0; }
+
+private:
+  /// Number of times this breakpoint/watchpoint has been hit.
+  uint32_t m_hit_count = 0;
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_BREAKPOINT_STOPPOINT_HIT_COUNTER_H
Index: lldb/include/lldb/Breakpoint/BreakpointSite.h
===================================================================
--- lldb/include/lldb/Breakpoint/BreakpointSite.h
+++ lldb/include/lldb/Breakpoint/BreakpointSite.h
@@ -14,7 +14,7 @@
 
 
 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
-#include "lldb/Breakpoint/StoppointLocation.h"
+#include "lldb/Breakpoint/StoppointSite.h"
 #include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/lldb-forward.h"
@@ -33,7 +33,7 @@
 /// by the process.
 
 class BreakpointSite : public std::enable_shared_from_this<BreakpointSite>,
-                       public StoppointLocation {
+                       public StoppointSite {
 public:
   enum Type {
     eSoftware, // Breakpoint opcode has been written to memory and
@@ -61,8 +61,6 @@
   /// Sets the trap opcode
   bool SetTrapOpcode(const uint8_t *trap_opcode, uint32_t trap_opcode_size);
 
-  void SetHardwareIndex(uint32_t index) override;
-
   /// Gets the original instruction bytes that were overwritten by the trap
   uint8_t *GetSavedOpcodeBytes();
 
Index: lldb/include/lldb/Breakpoint/BreakpointLocation.h
===================================================================
--- lldb/include/lldb/Breakpoint/BreakpointLocation.h
+++ lldb/include/lldb/Breakpoint/BreakpointLocation.h
@@ -13,7 +13,7 @@
 #include <mutex>
 
 #include "lldb/Breakpoint/BreakpointOptions.h"
-#include "lldb/Breakpoint/StoppointLocation.h"
+#include "lldb/Breakpoint/StoppointHitCounter.h"
 #include "lldb/Core/Address.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/lldb-private.h"
@@ -35,15 +35,14 @@
 /// be useful if you've set options on the locations.
 
 class BreakpointLocation
-    : public std::enable_shared_from_this<BreakpointLocation>,
-      public StoppointLocation {
+    : public std::enable_shared_from_this<BreakpointLocation> {
 public:
-  ~BreakpointLocation() override;
+  ~BreakpointLocation();
 
   /// Gets the load address for this breakpoint location \return
   ///     Returns breakpoint location load address, \b
   ///     LLDB_INVALID_ADDRESS if not yet set.
-  lldb::addr_t GetLoadAddress() const override;
+  lldb::addr_t GetLoadAddress() const;
 
   /// Gets the Address for this breakpoint location \return
   ///     Returns breakpoint location Address.
@@ -63,7 +62,7 @@
   /// \return
   ///     \b true if this breakpoint location thinks we should stop,
   ///     \b false otherwise.
-  bool ShouldStop(StoppointCallbackContext *context) override;
+  bool ShouldStop(StoppointCallbackContext *context);
 
   // The next section deals with various breakpoint options.
 
@@ -76,12 +75,6 @@
   ///     \b true if the breakpoint is enabled, \b false if disabled.
   bool IsEnabled() const;
 
-  /// Check if it is a hardware breakpoint.
-  ///
-  /// \return
-  ///     \b true if the breakpoint is a harware breakpoint.
-  bool IsHardware() const override;
-
   /// If \a auto_continue is \b true, set the breakpoint to continue when hit.
   void SetAutoContinue(bool auto_continue);
 
@@ -91,11 +84,14 @@
   ///     \b true if the breakpoint is set to auto-continue, \b false if not.
   bool IsAutoContinue() const;
 
+  /// Return the current Hit Count.
+  uint32_t GetHitCount() const { return m_hit_counter.GetValue(); }
+
   /// Return the current Ignore Count.
   ///
   /// \return
   ///     The number of breakpoint hits to be ignored.
-  uint32_t GetIgnoreCount();
+  uint32_t GetIgnoreCount() const;
 
   /// Set the breakpoint to ignore the next \a count breakpoint hits.
   ///
@@ -198,7 +194,7 @@
   void GetDescription(Stream *s, lldb::DescriptionLevel level);
 
   /// Standard "Dump" method.  At present it does nothing.
-  void Dump(Stream *s) const override;
+  void Dump(Stream *s) const;
 
   /// Use this to set location specific breakpoint options.
   ///
@@ -274,6 +270,9 @@
   ///     \b true or \b false as given in the description above.
   bool EquivalentToLocation(BreakpointLocation &location);
 
+  /// Returns the breakpoint location ID.
+  lldb::break_id_t GetID() const { return m_loc_id; }
+
 protected:
   friend class BreakpointSite;
   friend class BreakpointLocationList;
@@ -344,6 +343,9 @@
                                 /// multiple processes.
   size_t m_condition_hash; ///< For testing whether the condition source code
                            ///changed.
+  lldb::break_id_t m_loc_id; ///< Breakpoint location ID.
+  StoppointHitCounter m_hit_counter; ///< Number of times this breakpoint
+                                     /// location has been hit.
 
   void SetShouldResolveIndirectFunctions(bool do_resolve) {
     m_should_resolve_indirect_functions = do_resolve;
Index: lldb/include/lldb/Breakpoint/Breakpoint.h
===================================================================
--- lldb/include/lldb/Breakpoint/Breakpoint.h
+++ lldb/include/lldb/Breakpoint/Breakpoint.h
@@ -20,6 +20,7 @@
 #include "lldb/Breakpoint/BreakpointName.h"
 #include "lldb/Breakpoint/BreakpointOptions.h"
 #include "lldb/Breakpoint/Stoppoint.h"
+#include "lldb/Breakpoint/StoppointHitCounter.h"
 #include "lldb/Core/SearchFilter.h"
 #include "lldb/Utility/Event.h"
 #include "lldb/Utility/StringList.h"
@@ -624,13 +625,6 @@
 
   bool IgnoreCountShouldStop();
 
-  void IncrementHitCount() { m_hit_count++; }
-
-  void DecrementHitCount() {
-    assert(m_hit_count > 0);
-    m_hit_count--;
-  }
-
 private:
   // To call from CopyFromBreakpoint.
   Breakpoint(Target &new_target, const Breakpoint &bp_to_copy_from);
@@ -660,10 +654,12 @@
       m_locations; // The list of locations currently found for this breakpoint.
   std::string m_kind_description;
   bool m_resolve_indirect_symbols;
-  uint32_t m_hit_count; // Number of times this breakpoint/watchpoint has been
-                        // hit.  This is kept
-  // separately from the locations hit counts, since locations can go away when
-  // their backing library gets unloaded, and we would lose hit counts.
+
+  /// Number of times this breakpoint has been hit. This is kept separately
+  /// from the locations hit counts, since locations can go away when their
+  /// backing library gets unloaded, and we would lose hit counts.
+  StoppointHitCounter m_hit_counter;
+
   BreakpointName::Permissions m_permissions;
 
   void SendBreakpointChangedEvent(lldb::BreakpointEventType eventKind);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to