From da0bba5c9abb161ff824cf450537cf2ccf50d457 Mon Sep 17 00:00:00 2001 From: Tatyana Krasnukha Date: Thu, 23 Jul 2020 18:41:14 +0300 Subject: [PATCH] [lldb/Breakpoint] Rename StoppointLocation to StoppointSite and drop its relationship with BreakpointLocation Both of BreakpointLocation and BreakpointSite were inherited from StoppointLocation. However, the only thing they shared was hit counting logic. The patch encapsulates those logic into StoppointHitCounter, renames StoppointLocation to StoppointSite, and stops BreakpointLocation's inheriting from it. Differential Revision: https://reviews.llvm.org/D84527 --- lldb/include/lldb/Breakpoint/Breakpoint.h | 18 ++--- lldb/include/lldb/Breakpoint/BreakpointLocation.h | 30 ++++---- lldb/include/lldb/Breakpoint/BreakpointSite.h | 6 +- lldb/include/lldb/Breakpoint/StoppointHitCounter.h | 43 +++++++++++ lldb/include/lldb/Breakpoint/StoppointLocation.h | 85 ---------------------- lldb/include/lldb/Breakpoint/StoppointSite.h | 81 +++++++++++++++++++++ lldb/include/lldb/Breakpoint/Watchpoint.h | 8 +- lldb/include/lldb/lldb-forward.h | 2 - lldb/source/Breakpoint/Breakpoint.cpp | 6 +- lldb/source/Breakpoint/BreakpointLocation.cpp | 44 ++++++----- lldb/source/Breakpoint/BreakpointSite.cpp | 11 +-- lldb/source/Breakpoint/CMakeLists.txt | 2 +- lldb/source/Breakpoint/StoppointLocation.cpp | 32 -------- lldb/source/Breakpoint/StoppointSite.cpp | 23 ++++++ lldb/source/Breakpoint/Watchpoint.cpp | 14 ++-- 15 files changed, 208 insertions(+), 197 deletions(-) create mode 100644 lldb/include/lldb/Breakpoint/StoppointHitCounter.h delete mode 100644 lldb/include/lldb/Breakpoint/StoppointLocation.h create mode 100644 lldb/include/lldb/Breakpoint/StoppointSite.h delete mode 100644 lldb/source/Breakpoint/StoppointLocation.cpp create mode 100644 lldb/source/Breakpoint/StoppointSite.cpp diff --git a/lldb/include/lldb/Breakpoint/Breakpoint.h b/lldb/include/lldb/Breakpoint/Breakpoint.h index d29d210..5d3e596 100644 --- a/lldb/include/lldb/Breakpoint/Breakpoint.h +++ b/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 @@ protected: 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 @@ private: 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); diff --git a/lldb/include/lldb/Breakpoint/BreakpointLocation.h b/lldb/include/lldb/Breakpoint/BreakpointLocation.h index 04b2b89..4e1c57a 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointLocation.h +++ b/lldb/include/lldb/Breakpoint/BreakpointLocation.h @@ -13,7 +13,7 @@ #include #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 @@ namespace lldb_private { /// be useful if you've set options on the locations. class BreakpointLocation - : public std::enable_shared_from_this, - public StoppointLocation { + : public std::enable_shared_from_this { 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 @@ public: /// \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 @@ public: /// \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 @@ public: /// \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 @@ public: 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 @@ public: /// \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 @@ private: /// 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; diff --git a/lldb/include/lldb/Breakpoint/BreakpointSite.h b/lldb/include/lldb/Breakpoint/BreakpointSite.h index 6ddab5d..fc32c04 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointSite.h +++ b/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 @@ namespace lldb_private { /// by the process. class BreakpointSite : public std::enable_shared_from_this, - public StoppointLocation { + public StoppointSite { public: enum Type { eSoftware, // Breakpoint opcode has been written to memory and @@ -61,8 +61,6 @@ public: /// 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(); diff --git a/lldb/include/lldb/Breakpoint/StoppointHitCounter.h b/lldb/include/lldb/Breakpoint/StoppointHitCounter.h new file mode 100644 index 0000000..26f816d --- /dev/null +++ b/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 +#include +#include + +#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::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 diff --git a/lldb/include/lldb/Breakpoint/StoppointLocation.h b/lldb/include/lldb/Breakpoint/StoppointLocation.h deleted file mode 100644 index 4392c7b..0000000 --- a/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 diff --git a/lldb/include/lldb/Breakpoint/StoppointSite.h b/lldb/include/lldb/Breakpoint/StoppointSite.h new file mode 100644 index 0000000..7e5e334 --- /dev/null +++ b/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 diff --git a/lldb/include/lldb/Breakpoint/Watchpoint.h b/lldb/include/lldb/Breakpoint/Watchpoint.h index bce15f0..41b723a 100644 --- a/lldb/include/lldb/Breakpoint/Watchpoint.h +++ b/lldb/include/lldb/Breakpoint/Watchpoint.h @@ -12,7 +12,7 @@ #include #include -#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, - public StoppointLocation { + public StoppointSite { public: class WatchpointEventData : public EventData { public: @@ -158,8 +158,6 @@ private: 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 @@ private: std::unique_ptr 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); diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index 0bf9e2c..6682413 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -192,7 +192,6 @@ class Status; class StopInfo; class Stoppoint; class StoppointCallbackContext; -class StoppointLocation; class Stream; class StreamFile; class StreamString; @@ -405,7 +404,6 @@ typedef std::shared_ptr typedef std::unique_ptr StackFrameRecognizerManagerUP; typedef std::shared_ptr StopInfoSP; -typedef std::shared_ptr StoppointLocationSP; typedef std::shared_ptr StreamSP; typedef std::weak_ptr StreamWP; typedef std::shared_ptr StreamFileSP; diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp index 88c7f33..9ed9549 100644 --- a/lldb/source/Breakpoint/Breakpoint.cpp +++ b/lldb/source/Breakpoint/Breakpoint.cpp @@ -51,7 +51,7 @@ Breakpoint::Breakpoint(Target &target, SearchFilterSP &filter_sp, : 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 @@ Breakpoint::Breakpoint(Target &new_target, const Breakpoint &source_bp) 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; @@ -341,7 +341,7 @@ bool Breakpoint::IgnoreCountShouldStop() { 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(); } diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp b/lldb/source/Breakpoint/BreakpointLocation.cpp index eae1c1e..d3d6ea0 100644 --- a/lldb/source/Breakpoint/BreakpointLocation.cpp +++ b/lldb/source/Breakpoint/BreakpointLocation.cpp @@ -31,11 +31,10 @@ using namespace lldb_private; 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 @@ Breakpoint &BreakpointLocation::GetBreakpoint() { return m_owner; } 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 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx, return ret; } -uint32_t BreakpointLocation::GetIgnoreCount() { +uint32_t BreakpointLocation::GetIgnoreCount() const { return GetOptionsSpecifyingKind(BreakpointOptions::eIgnoreCount) ->GetIgnoreCount(); } @@ -425,16 +416,16 @@ bool BreakpointLocation::ShouldStop(StoppointCallbackContext *context) { 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 @@ void BreakpointLocation::GetDescription(Stream *s, } } + 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 @@ void BreakpointLocation::GetDescription(Stream *s, } 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 @@ void BreakpointLocation::Dump(Stream *s) const { 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 @@ void BreakpointLocation::Dump(Stream *s) const { (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()); } diff --git a/lldb/source/Breakpoint/BreakpointSite.cpp b/lldb/source/Breakpoint/BreakpointSite.cpp index faa7e4c..fb3f0cd 100644 --- a/lldb/source/Breakpoint/BreakpointSite.cpp +++ b/lldb/source/Breakpoint/BreakpointSite.cpp @@ -21,7 +21,7 @@ using namespace lldb_private; 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 @@ break_id_t BreakpointSite::GetNextID() { // 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::BumpHitCounts() { } } -void BreakpointSite::SetHardwareIndex(uint32_t index) { - std::lock_guard 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, diff --git a/lldb/source/Breakpoint/CMakeLists.txt b/lldb/source/Breakpoint/CMakeLists.txt index a7c0baf..4862c2b 100644 --- a/lldb/source/Breakpoint/CMakeLists.txt +++ b/lldb/source/Breakpoint/CMakeLists.txt @@ -19,7 +19,7 @@ add_lldb_library(lldbBreakpoint BreakpointSiteList.cpp Stoppoint.cpp StoppointCallbackContext.cpp - StoppointLocation.cpp + StoppointSite.cpp Watchpoint.cpp WatchpointList.cpp WatchpointOptions.cpp diff --git a/lldb/source/Breakpoint/StoppointLocation.cpp b/lldb/source/Breakpoint/StoppointLocation.cpp deleted file mode 100644 index 5bb4c78..0000000 --- a/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; -} diff --git a/lldb/source/Breakpoint/StoppointSite.cpp b/lldb/source/Breakpoint/StoppointSite.cpp new file mode 100644 index 0000000..ba8c483 --- /dev/null +++ b/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() {} diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp index 481c7b7..29ae1ef 100644 --- a/lldb/source/Breakpoint/Watchpoint.cpp +++ b/lldb/source/Breakpoint/Watchpoint.cpp @@ -25,7 +25,7 @@ using namespace lldb_private; 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 @@ void Watchpoint::SetWatchSpec(const std::string &str) { 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 || !HardwareRequired()); return m_is_hardware; @@ -126,12 +124,12 @@ bool Watchpoint::CaptureWatchedValue(const ExecutionContext &exe_ctx) { 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(); } } } @@ -140,7 +138,7 @@ void Watchpoint::IncrementFalseAlarmsAndReviseHitCount() { // should continue. bool Watchpoint::ShouldStop(StoppointCallbackContext *context) { - IncrementHitCount(); + m_hit_counter.Increment(); return IsEnabled(); } -- 2.7.4