[Lldb-commits] [lldb] r139166 - in /lldb/trunk: include/lldb/Breakpoint/WatchpointLocationList.h include/lldb/Target/Target.h include/lldb/lldb-forward-rtti.h include/lldb/lldb-types.h lldb.xcodeproj/project.pbxproj source/Breakpoint/WatchpointLocationList.cpp source/Target/Target.cpp

Johnny Chen johnny.chen at apple.com
Tue Sep 6 13:05:25 PDT 2011


Author: johnny
Date: Tue Sep  6 15:05:25 2011
New Revision: 139166

URL: http://llvm.org/viewvc/llvm-project?rev=139166&view=rev
Log:
Add a data type WatchpointLocationList to the repository.  A Target contains an instance of watchpoint location list.
Also add a typefed for WatchpointLocationSP to lldb-forward-rtti.h.

Added:
    lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h
    lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp
Modified:
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/include/lldb/lldb-forward-rtti.h
    lldb/trunk/include/lldb/lldb-types.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Target/Target.cpp

Added: lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h?rev=139166&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h (added)
+++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h Tue Sep  6 15:05:25 2011
@@ -0,0 +1,191 @@
+//===-- WatchpointLocationList.h --------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_WatchpointLocationList_h_
+#define liblldb_WatchpointLocationList_h_
+
+// C Includes
+// C++ Includes
+#include <vector>
+#include <map>
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-private.h"
+#include "lldb/Core/Address.h"
+#include "lldb/Host/Mutex.h"
+
+namespace lldb_private {
+
+//----------------------------------------------------------------------
+/// @class WatchpointLocationList WatchpointLocationList.h "lldb/Breakpoint/WatchpointLocationList.h"
+/// @brief This class is used by Watchpoint to manage a list of watchpoint locations,
+//  each watchpoint location in the list
+/// has a unique ID, and is unique by Address as well.
+//----------------------------------------------------------------------
+
+class WatchpointLocationList
+{
+// Only Target can make the location list, or add elements to it.
+// This is not just some random collection of locations.  Rather, the act of adding the location
+// to this list sets its ID.
+friend class WatchpointLocation;
+
+public:
+    //------------------------------------------------------------------
+    /// Default constructor makes an empty list.
+    //------------------------------------------------------------------
+    WatchpointLocationList();
+
+    //------------------------------------------------------------------
+    /// Destructor, currently does nothing.
+    //------------------------------------------------------------------
+    ~WatchpointLocationList();
+
+    //------------------------------------------------------------------
+    /// Add a WatchpointLocation to the list.
+    ///
+    /// @param[in] wp_loc_sp
+    ///    A shared pointer to a watchpoint location being added to the list.
+    ///
+    /// @return
+    ///    The ID of the WatchpointLocation in the list.
+    //------------------------------------------------------------------
+    lldb::watch_id_t
+    Add (const lldb::WatchpointLocationSP& wp_loc_sp);
+
+    //------------------------------------------------------------------
+    /// Standard "Dump" method.
+    //------------------------------------------------------------------
+    void
+    Dump (Stream *s) const;
+
+    //------------------------------------------------------------------
+    /// Returns a shared pointer to the watchpoint location at address
+    /// \a addr - const version.
+    ///
+    /// @param[in] addr
+    ///     The address to look for.
+    ///
+    /// @result
+    ///     A shared pointer to the watchpoint.  May contain a NULL
+    ///     pointer if the watchpoint doesn't exist.
+    //------------------------------------------------------------------
+    const lldb::WatchpointLocationSP
+    FindByAddress (lldb::addr_t addr) const;
+
+    //------------------------------------------------------------------
+    /// Returns a shared pointer to the watchpoint location with id
+    /// \a breakID, const version.
+    ///
+    /// @param[in] breakID
+    ///     The watchpoint location ID to seek for.
+    ///
+    /// @result
+    ///     A shared pointer to the watchpoint.  May contain a NULL
+    ///     pointer if the watchpoint doesn't exist.
+    //------------------------------------------------------------------
+    lldb::WatchpointLocationSP
+    FindByID (lldb::watch_id_t watchID) const;
+
+    //------------------------------------------------------------------
+    /// Returns the watchpoint location id to the watchpoint location
+    /// at address \a addr.
+    ///
+    /// @param[in] addr
+    ///     The address to match.
+    ///
+    /// @result
+    ///     The ID of the watchpoint location, or LLDB_INVALID_WATCH_ID.
+    //------------------------------------------------------------------
+    lldb::watch_id_t
+    FindIDByAddress (lldb::addr_t addr);
+
+    //------------------------------------------------------------------
+    /// Removes the watchpoint location given by \b watchID from this list.
+    ///
+    /// @param[in] watchID
+    ///   The watchpoint location ID to remove.
+    ///
+    /// @result
+    ///   \b true if the watchpoint location \a watchID was in the list.
+    //------------------------------------------------------------------
+    bool
+    Remove (lldb::watch_id_t watchID);
+
+    //------------------------------------------------------------------
+    /// Returns the number hit count of all locations in this list.
+    ///
+    /// @result
+    ///     Hit count of all locations in this list.
+    //------------------------------------------------------------------
+    uint32_t
+    GetHitCount () const;
+
+    //------------------------------------------------------------------
+    /// Enquires of the watchpoint location in this list with ID \a
+    /// watchID whether we should stop.
+    ///
+    /// @param[in] context
+    ///     This contains the information about this stop.
+    ///
+    /// @param[in] watchID
+    ///     This watch ID that we hit.
+    ///
+    /// @return
+    ///     \b true if we should stop, \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    ShouldStop (StoppointCallbackContext *context,
+                lldb::watch_id_t watchID);
+
+    //------------------------------------------------------------------
+    /// Returns the number of elements in this watchpoint location list.
+    ///
+    /// @result
+    ///     The number of elements.
+    //------------------------------------------------------------------
+    size_t
+    GetSize() const
+    {
+        return m_address_to_location.size();
+    }
+
+    //------------------------------------------------------------------
+    /// Print a description of the watchpoint locations in this list to
+    /// the stream \a s.
+    ///
+    /// @param[in] s
+    ///     The stream to which to print the description.
+    ///
+    /// @param[in] level
+    ///     The description level that indicates the detail level to
+    ///     provide.
+    ///
+    /// @see lldb::DescriptionLevel
+    //------------------------------------------------------------------
+    void
+    GetDescription (Stream *s,
+                    lldb::DescriptionLevel level);
+
+protected:
+    typedef std::map<lldb::addr_t, lldb::WatchpointLocationSP> addr_map;
+
+    addr_map::iterator
+    GetIDIterator(lldb::watch_id_t watchID);
+
+    addr_map::const_iterator
+    GetIDConstIterator(lldb::watch_id_t watchID) const;
+
+    addr_map m_address_to_location;
+    mutable Mutex m_mutex;
+};
+
+} // namespace lldb_private
+
+#endif  // liblldb_WatchpointLocationList_h_

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=139166&r1=139165&r2=139166&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Tue Sep  6 15:05:25 2011
@@ -18,6 +18,7 @@
 #include "lldb/lldb-public.h"
 #include "lldb/Breakpoint/BreakpointList.h"
 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
+#include "lldb/Breakpoint/WatchpointLocationList.h"
 #include "lldb/Core/Broadcaster.h"
 #include "lldb/Core/Event.h"
 #include "lldb/Core/ModuleList.h"
@@ -813,6 +814,7 @@
     BreakpointList  m_breakpoint_list;
     BreakpointList  m_internal_breakpoint_list;
     lldb::BreakpointSP m_last_created_breakpoint;
+    WatchpointLocationList  m_watchpoint_location_list;
     // We want to tightly control the process destruction process so
     // we can correctly tear down everything that we need to, so the only
     // class that knows about the process lifespan is this target class.

Modified: lldb/trunk/include/lldb/lldb-forward-rtti.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward-rtti.h?rev=139166&r1=139165&r2=139166&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward-rtti.h (original)
+++ lldb/trunk/include/lldb/lldb-forward-rtti.h Tue Sep  6 15:05:25 2011
@@ -86,6 +86,7 @@
     typedef SharedPtr<lldb_private::Variable>::Type VariableSP;
     typedef SharedPtr<lldb_private::VariableList>::Type VariableListSP;
     typedef SharedPtr<lldb_private::ValueObjectList>::Type ValueObjectListSP;
+    typedef SharedPtr<lldb_private::WatchpointLocation>::Type WatchpointLocationSP;
 
 } // namespace lldb
 

Modified: lldb/trunk/include/lldb/lldb-types.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-types.h?rev=139166&r1=139165&r2=139166&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-types.h (original)
+++ lldb/trunk/include/lldb/lldb-types.h Tue Sep  6 15:05:25 2011
@@ -94,6 +94,7 @@
     typedef int32_t     pid_t;
     typedef uint32_t    tid_t;
     typedef int32_t     break_id_t;
+    typedef int32_t     watch_id_t;
     typedef void *      clang_type_t;
 }
 

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=139166&r1=139165&r2=139166&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Sep  6 15:05:25 2011
@@ -437,6 +437,7 @@
 		9AC703AF117675410086C050 /* SBInstruction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC703AE117675410086C050 /* SBInstruction.cpp */; };
 		9AC703B1117675490086C050 /* SBInstructionList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC703B0117675490086C050 /* SBInstructionList.cpp */; };
 		B271B11413D6139300C3FEDB /* FormatClasses.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94A9112D13D5DF210046D8A6 /* FormatClasses.cpp */; };
+		B27318421416AC12006039C8 /* WatchpointLocationList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27318411416AC12006039C8 /* WatchpointLocationList.cpp */; };
 		B28058A1139988B0002D96D0 /* InferiorCallPOSIX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28058A0139988B0002D96D0 /* InferiorCallPOSIX.cpp */; };
 /* End PBXBuildFile section */
 
@@ -1291,6 +1292,8 @@
 		AF68D3301255A110002FF25B /* UnwindLLDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnwindLLDB.h; path = Utility/UnwindLLDB.h; sourceTree = "<group>"; };
 		AF94005711C03F6500085DB9 /* SymbolVendor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SymbolVendor.cpp; path = source/Symbol/SymbolVendor.cpp; sourceTree = "<group>"; };
 		B23DD24F12EDFAC1000C3894 /* ARMUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ARMUtils.h; path = Utility/ARMUtils.h; sourceTree = "<group>"; };
+		B27318411416AC12006039C8 /* WatchpointLocationList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WatchpointLocationList.cpp; path = source/Breakpoint/WatchpointLocationList.cpp; sourceTree = "<group>"; };
+		B27318431416AC43006039C8 /* WatchpointLocationList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WatchpointLocationList.h; path = include/lldb/Breakpoint/WatchpointLocationList.h; sourceTree = "<group>"; };
 		B28058A0139988B0002D96D0 /* InferiorCallPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = InferiorCallPOSIX.cpp; path = Utility/InferiorCallPOSIX.cpp; sourceTree = "<group>"; };
 		B28058A2139988C6002D96D0 /* InferiorCallPOSIX.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = InferiorCallPOSIX.h; path = Utility/InferiorCallPOSIX.h; sourceTree = "<group>"; };
 		B287E63E12EFAE2C00C9BEFE /* ARMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ARMDefines.h; path = Utility/ARMDefines.h; sourceTree = "<group>"; };
@@ -2176,7 +2179,9 @@
 				26BC7CFB10F1B71400F91463 /* StoppointLocation.h */,
 				26BC7E1710F1B83100F91463 /* StoppointLocation.cpp */,
 				26BC7CFC10F1B71400F91463 /* WatchpointLocation.h */,
+				B27318431416AC43006039C8 /* WatchpointLocationList.h */,
 				26BC7E1810F1B83100F91463 /* WatchpointLocation.cpp */,
+				B27318411416AC12006039C8 /* WatchpointLocationList.cpp */,
 			);
 			name = Breakpoint;
 			sourceTree = "<group>";
@@ -3338,6 +3343,7 @@
 				949ADF031406F648004833E1 /* ValueObjectConstResultImpl.cpp in Sources */,
 				268ED0A5140FF54200DE830F /* DataEncoder.cpp in Sources */,
 				26A0DA4E140F7226006DA411 /* HashedNameToDIE.cpp in Sources */,
+				B27318421416AC12006039C8 /* WatchpointLocationList.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp?rev=139166&view=auto
==============================================================================
--- lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp (added)
+++ lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp Tue Sep  6 15:05:25 2011
@@ -0,0 +1,190 @@
+//===-- WatchpointLocationList.cpp ------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Breakpoint/WatchpointLocationList.h"
+#include "lldb/Breakpoint/WatchpointLocation.h"
+#include "lldb/Core/ModuleList.h"
+#include "lldb/Target/Target.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+WatchpointLocationList::WatchpointLocationList() :
+    m_address_to_location (),
+    m_mutex (Mutex::eMutexTypeRecursive)
+{
+}
+
+WatchpointLocationList::~WatchpointLocationList()
+{
+}
+
+// Add watchpoint loc to the list.  However, if the element already exists in the
+// list, then replace it with the input one.
+
+lldb::watch_id_t
+WatchpointLocationList::Add (const WatchpointLocationSP &wp_loc_sp)
+{
+    Mutex::Locker locker (m_mutex);
+    lldb::addr_t wp_addr = wp_loc_sp->GetLoadAddress();
+    addr_map::iterator iter = m_address_to_location.find(wp_addr);
+
+    if (iter == m_address_to_location.end())
+    {
+        m_address_to_location.insert(iter, addr_map::value_type(wp_addr, wp_loc_sp));
+    }
+    else
+    {
+        m_address_to_location[wp_addr] = wp_loc_sp;
+    }
+    return wp_loc_sp->GetID();
+}
+
+void
+WatchpointLocationList::Dump (Stream *s) const
+{
+    Mutex::Locker locker (m_mutex);
+    s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
+    //s->Indent();
+    s->Printf("WatchpointLocationList with %zu WatchpointLocations:\n",
+              m_address_to_location.size());
+    s->IndentMore();
+    addr_map::const_iterator pos, end = m_address_to_location.end();
+    for (pos = m_address_to_location.begin(); pos != end; ++pos)
+        pos->second->Dump(s);
+    s->IndentLess();
+}
+
+const WatchpointLocationSP
+WatchpointLocationList::FindByAddress (lldb::addr_t addr) const
+{
+    WatchpointLocationSP wp_loc_sp;
+    Mutex::Locker locker (m_mutex);
+    if (!m_address_to_location.empty())
+    {
+        addr_map::const_iterator pos = m_address_to_location.find (addr);
+        if (pos != m_address_to_location.end())
+            wp_loc_sp = pos->second;
+    }
+
+    return wp_loc_sp;
+}
+
+class WatchpointLocationIDMatches
+{
+public:
+    WatchpointLocationIDMatches (lldb::watch_id_t watch_id) :
+        m_watch_id(watch_id)
+    {
+    }
+
+    bool operator() (std::pair <lldb::addr_t, WatchpointLocationSP> val_pair) const
+    {
+        return m_watch_id == val_pair.second.get()->GetID();
+    }
+
+private:
+   const lldb::watch_id_t m_watch_id;
+};
+
+WatchpointLocationList::addr_map::iterator
+WatchpointLocationList::GetIDIterator (lldb::watch_id_t watch_id)
+{
+    return std::find_if(m_address_to_location.begin(), m_address_to_location.end(), // Search full range
+                        WatchpointLocationIDMatches(watch_id));                     // Predicate
+}
+
+WatchpointLocationList::addr_map::const_iterator
+WatchpointLocationList::GetIDConstIterator (lldb::watch_id_t watch_id) const
+{
+    return std::find_if(m_address_to_location.begin(), m_address_to_location.end(), // Search full range
+                        WatchpointLocationIDMatches(watch_id));                     // Predicate
+}
+
+WatchpointLocationSP
+WatchpointLocationList::FindByID (lldb::watch_id_t watch_id) const
+{
+    WatchpointLocationSP wp_loc_sp;
+    Mutex::Locker locker (m_mutex);
+    addr_map::const_iterator pos = GetIDConstIterator(watch_id);
+    if (pos != m_address_to_location.end())
+        wp_loc_sp = pos->second;
+
+    return wp_loc_sp;
+}
+
+lldb::watch_id_t
+WatchpointLocationList::FindIDByAddress (lldb::addr_t addr)
+{
+    WatchpointLocationSP wp_loc_sp = FindByAddress (addr);
+    if (wp_loc_sp)
+    {
+        return wp_loc_sp->GetID();
+    }
+    return LLDB_INVALID_WATCH_ID;
+}
+
+bool
+WatchpointLocationList::Remove (lldb::watch_id_t watch_id)
+{
+    Mutex::Locker locker (m_mutex);
+    addr_map::iterator pos = GetIDIterator(watch_id);    // Predicate
+    if (pos != m_address_to_location.end())
+    {
+        m_address_to_location.erase(pos);
+        return true;
+    }
+    return false;
+}
+
+uint32_t
+WatchpointLocationList::GetHitCount () const
+{
+    uint32_t hit_count = 0;
+    Mutex::Locker locker (m_mutex);
+    addr_map::const_iterator pos, end = m_address_to_location.end();
+    for (pos = m_address_to_location.begin(); pos != end; ++pos)
+        hit_count += pos->second->GetHitCount();
+    return hit_count;
+}
+
+bool
+WatchpointLocationList::ShouldStop (StoppointCallbackContext *context, lldb::watch_id_t watch_id)
+{
+    WatchpointLocationSP wp_loc_sp = FindByID (watch_id);
+    if (wp_loc_sp)
+    {
+        // Let the WatchpointLocation decide if it should stop here (could not have
+        // reached it's target hit count yet, or it could have a callback
+        // that decided it shouldn't stop.
+        return wp_loc_sp->ShouldStop (context);
+    }
+    // We should stop here since this WatchpointLocation isn't valid anymore or it
+    // doesn't exist.
+    return true;
+}
+
+void
+WatchpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level)
+{
+    Mutex::Locker locker (m_mutex);
+    addr_map::iterator pos, end = m_address_to_location.end();
+
+    for (pos = m_address_to_location.begin(); pos != end; ++pos)
+    {
+        s->Printf(" ");
+        pos->second->Dump(s);
+    }
+}
+

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139166&r1=139165&r2=139166&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue Sep  6 15:05:25 2011
@@ -53,6 +53,7 @@
     m_section_load_list (),
     m_breakpoint_list (false),
     m_internal_breakpoint_list (true),
+    m_watchpoint_location_list (),
     m_process_sp (),
     m_search_filter_sp (),
     m_image_search_paths (ImageSearchPathsChanged, this),





More information about the lldb-commits mailing list