[Lldb-commits] [lldb] r113902 - in /lldb/trunk: include/lldb/Core/ThreadSafeSTLMap.h include/lldb/Target/SectionLoadList.h source/Target/SectionLoadList.cpp source/Target/Target.cpp

Greg Clayton gclayton at apple.com
Tue Sep 14 16:52:43 PDT 2010


Author: gclayton
Date: Tue Sep 14 18:52:43 2010
New Revision: 113902

URL: http://llvm.org/viewvc/llvm-project?rev=113902&view=rev
Log:
Clear the section list when a our current process is destroyed.

Add missing files that I forgot to checkin.


Added:
    lldb/trunk/include/lldb/Target/SectionLoadList.h
    lldb/trunk/source/Target/SectionLoadList.cpp
Modified:
    lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h?rev=113902&r1=113901&r2=113902&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h (original)
+++ lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h Tue Sep 14 18:52:43 2010
@@ -46,6 +46,13 @@
         Mutex::Locker locker(m_mutex);
         return m_collection.empty();
     }
+    
+    void
+    Clear()
+    {
+        Mutex::Locker locker(m_mutex);
+        return m_collection.clear();
+    }
 
     size_t
     Erase (const _Key& key)

Added: lldb/trunk/include/lldb/Target/SectionLoadList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/SectionLoadList.h?rev=113902&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Target/SectionLoadList.h (added)
+++ lldb/trunk/include/lldb/Target/SectionLoadList.h Tue Sep 14 18:52:43 2010
@@ -0,0 +1,75 @@
+//===-- SectionLoadList.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_SectionLoadList_h_
+#define liblldb_SectionLoadList_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-include.h"
+#include "lldb/Core/ThreadSafeSTLMap.h"
+
+namespace lldb_private {
+
+class SectionLoadList
+{
+public:
+    //------------------------------------------------------------------
+    // Constructors and Destructors
+    //------------------------------------------------------------------
+    SectionLoadList () :
+        m_section_load_info ()
+    {
+    }
+
+    ~SectionLoadList()
+    {
+    }
+
+    bool
+    IsEmpty() const;
+
+    void
+    Clear ();
+
+    lldb::addr_t
+    GetSectionLoadAddress (const Section *section) const;
+
+    bool
+    ResolveLoadAddress (lldb::addr_t load_addr, Address &so_addr) const;
+
+    bool
+    SetSectionLoadAddress (const Section *section, lldb::addr_t load_addr);
+
+    // The old load address should be specified when unloading to ensure we get
+    // the correct instance of the section as a shared library could be loaded
+    // at more than one location.
+    bool
+    SetSectionUnloaded (const Section *section, lldb::addr_t load_addr);
+
+    // Unload all instances of a section. This function can be used on systems
+    // that don't support multiple copies of the same shared library to be
+    // loaded at the same time.
+    size_t
+    SetSectionUnloaded (const Section *section);
+
+
+protected:
+    typedef ThreadSafeSTLMap<lldb::addr_t, const Section *> collection;
+    collection m_section_load_info;    ///< A mapping of all currently loaded sections.
+
+private:
+    DISALLOW_COPY_AND_ASSIGN (SectionLoadList);
+};
+
+} // namespace lldb_private
+
+#endif  // liblldb_SectionLoadList_h_

Added: lldb/trunk/source/Target/SectionLoadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/SectionLoadList.cpp?rev=113902&view=auto
==============================================================================
--- lldb/trunk/source/Target/SectionLoadList.cpp (added)
+++ lldb/trunk/source/Target/SectionLoadList.cpp Tue Sep 14 18:52:43 2010
@@ -0,0 +1,135 @@
+//===-- SectionLoadList.cpp -------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/SectionLoadList.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Log.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/Stream.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Symbol/SymbolContext.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+
+bool
+SectionLoadList::IsEmpty() const
+{
+    return m_section_load_info.IsEmpty();
+}
+
+void
+SectionLoadList::Clear ()
+{
+    m_section_load_info.Clear();
+}
+
+addr_t
+SectionLoadList::GetSectionLoadAddress (const Section *section) const
+{
+    // TODO: add support for the same section having multiple load addresses
+    addr_t section_load_addr = LLDB_INVALID_ADDRESS;
+    if (m_section_load_info.GetFirstKeyForValue (section, section_load_addr))
+        return section_load_addr;
+    return LLDB_INVALID_ADDRESS;
+}
+
+bool
+SectionLoadList::SetSectionLoadAddress (const Section *section, addr_t load_addr)
+{
+    Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_SHLIB | LIBLLDB_LOG_VERBOSE);
+
+    if (log)
+        log->Printf ("SectionLoadList::%s (section = %p (%s.%s), load_addr = 0x%16.16llx)",
+                     __FUNCTION__,
+                     section,
+                     section->GetModule()->GetFileSpec().GetFilename().AsCString(),
+                     section->GetName().AsCString(),
+                     load_addr);
+
+
+    const Section *existing_section = NULL;
+    Mutex::Locker locker(m_section_load_info.GetMutex());
+
+    if (m_section_load_info.GetValueForKeyNoLock (load_addr, existing_section))
+    {
+        if (existing_section == section)
+            return false;   // No change
+    }
+    m_section_load_info.SetValueForKeyNoLock (load_addr, section);
+    return true;    // Changed
+}
+
+size_t
+SectionLoadList::SetSectionUnloaded (const Section *section)
+{
+    Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_SHLIB | LIBLLDB_LOG_VERBOSE);
+
+    if (log)
+        log->Printf ("SectionLoadList::%s (section = %p (%s.%s))",
+                     __FUNCTION__,
+                     section,
+                     section->GetModule()->GetFileSpec().GetFilename().AsCString(),
+                     section->GetName().AsCString());
+
+    Mutex::Locker locker(m_section_load_info.GetMutex());
+
+    size_t unload_count = 0;
+    addr_t section_load_addr;
+    while (m_section_load_info.GetFirstKeyForValueNoLock (section, section_load_addr))
+    {
+        unload_count += m_section_load_info.EraseNoLock (section_load_addr);
+    }
+    return unload_count;
+}
+
+bool
+SectionLoadList::SetSectionUnloaded (const Section *section, addr_t load_addr)
+{
+    Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_SHLIB | LIBLLDB_LOG_VERBOSE);
+
+    if (log)
+        log->Printf ("SectionLoadList::%s (section = %p (%s.%s), load_addr = 0x%16.16llx)",
+                     __FUNCTION__,
+                     section,
+                     section->GetModule()->GetFileSpec().GetFilename().AsCString(),
+                     section->GetName().AsCString(),
+                     load_addr);
+
+    return m_section_load_info.Erase (load_addr) == 1;
+}
+
+
+bool
+SectionLoadList::ResolveLoadAddress (addr_t load_addr, Address &so_addr) const
+{
+    addr_t section_load_addr = LLDB_INVALID_ADDRESS;
+    const Section *section = NULL;
+
+    // First find the top level section that this load address exists in
+    if (m_section_load_info.LowerBound (load_addr, section_load_addr, section, true))
+    {
+        addr_t offset = load_addr - section_load_addr;
+        if (offset < section->GetByteSize())
+        {
+            // We have found the top level section, now we need to find the
+            // deepest child section.
+            return section->ResolveContainedAddress (offset, so_addr);
+        }
+    }
+    so_addr.Clear();
+    return false;
+}

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=113902&r1=113901&r2=113902&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue Sep 14 18:52:43 2010
@@ -82,6 +82,7 @@
 {
     if (m_process_sp.get())
     {
+        m_section_load_list.Clear();
         if (m_process_sp->IsAlive())
             m_process_sp->Destroy();
         else





More information about the lldb-commits mailing list