[Lldb-commits] [lldb] r121236 - in /lldb/trunk: include/lldb/Core/ include/lldb/Target/ source/Commands/ source/Core/ source/Plugins/DynamicLoader/MacOSX-DYLD/ source/Plugins/ObjectFile/ELF/ source/Plugins/ObjectFile/Mach-O/ source/Plugins/Process/gdb-remote/ source/Target/

Greg Clayton gclayton at apple.com
Tue Dec 7 21:08:21 PST 2010


Author: gclayton
Date: Tue Dec  7 23:08:21 2010
New Revision: 121236

URL: http://llvm.org/viewvc/llvm-project?rev=121236&view=rev
Log:
Added the ability to dump sections to a certain depth (for when sections
have children sections).

Modified SectionLoadList to do it's own multi-threaded protected on its map.
The ThreadSafeSTLMap class was difficult to deal with and wasn't providing
much utility, it was only getting in the way.

Make sure when the communication read thread is about to exit, it clears the
thread in the main class.

Fixed the ModuleList to correctly ignore architectures and UUIDs if they aren't
valid when searching for a matching module. If we specified a file with no arch,
and then modified the file and loaded it again, it would not match on subsequent
searches if the arch was invalid since it would compare an invalid architecture
to the one that was found or selected within the shared library or executable.
This was causing stale modules to stay around in the global module list when they
should have been removed.

Removed deprecated functions from the DynamicLoaderMacOSXDYLD class.

Modified "ProcessGDBRemote::IsAlive" to check if we are connected to a gdb
server and also make sure our process hasn't exited.




Modified:
    lldb/trunk/include/lldb/Core/Section.h
    lldb/trunk/include/lldb/Target/SectionLoadList.h
    lldb/trunk/source/Commands/CommandObjectImage.cpp
    lldb/trunk/source/Core/Communication.cpp
    lldb/trunk/source/Core/ModuleList.cpp
    lldb/trunk/source/Core/Section.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/SectionLoadList.cpp

Modified: lldb/trunk/include/lldb/Core/Section.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Section.h (original)
+++ lldb/trunk/include/lldb/Core/Section.h Tue Dec  7 23:08:21 2010
@@ -46,7 +46,7 @@
     ContainsSection(lldb::user_id_t sect_id) const;
 
     void
-    Dump (Stream *s, Target *target, bool show_header) const;
+    Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const;
 
     lldb::SectionSP
     FindSectionByName (const ConstString &section_dstr) const;
@@ -137,7 +137,7 @@
     }
 
     void
-    Dump (Stream *s, Target *target) const;
+    Dump (Stream *s, Target *target, uint32_t depth) const;
 
     void
     DumpName (Stream *s) const;

Modified: lldb/trunk/include/lldb/Target/SectionLoadList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/SectionLoadList.h?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/SectionLoadList.h (original)
+++ lldb/trunk/include/lldb/Target/SectionLoadList.h Tue Dec  7 23:08:21 2010
@@ -12,10 +12,12 @@
 
 // C Includes
 // C++ Includes
+#include <map>
+
 // Other libraries and framework includes
 // Project includes
 #include "lldb/lldb-include.h"
-#include "lldb/Core/ThreadSafeSTLMap.h"
+#include "lldb/Host/Mutex.h"
 
 namespace lldb_private {
 
@@ -26,7 +28,9 @@
     // Constructors and Destructors
     //------------------------------------------------------------------
     SectionLoadList () :
-        m_section_load_info ()
+        m_collection (),
+        m_mutex (Mutex::eMutexTypeRecursive)
+
     {
     }
 
@@ -61,10 +65,13 @@
     size_t
     SetSectionUnloaded (const Section *section);
 
+    void
+    Dump (Stream &s, Target *target);
 
 protected:
-    typedef ThreadSafeSTLMap<lldb::addr_t, const Section *> collection;
-    collection m_section_load_info;    ///< A mapping of all currently loaded sections.
+    typedef std::map<lldb::addr_t, const Section *> collection;
+    collection m_collection;
+    mutable Mutex m_mutex;
 
 private:
     DISALLOW_COPY_AND_ASSIGN (SectionLoadList);

Modified: lldb/trunk/source/Commands/CommandObjectImage.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectImage.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectImage.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectImage.cpp Tue Dec  7 23:08:21 2010
@@ -185,7 +185,7 @@
                 strm << module->GetFileSpec();
                 strm.Printf ("' (%s):\n", module->GetArchitecture().AsCString());
                 strm.IndentMore();
-                section_list->Dump(&strm, interpreter.GetDebugger().GetExecutionContext().target, true);
+                section_list->Dump(&strm, interpreter.GetDebugger().GetExecutionContext().target, true, UINT32_MAX);
                 strm.IndentLess();
             }
         }

Modified: lldb/trunk/source/Core/Communication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Communication.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Core/Communication.cpp (original)
+++ lldb/trunk/source/Core/Communication.cpp Tue Dec  7 23:08:21 2010
@@ -346,6 +346,7 @@
 
     // Let clients know that this thread is exiting
     comm->BroadcastEvent (eBroadcastBitReadThreadDidExit);
+    comm->m_read_thread = LLDB_INVALID_HOST_THREAD;
     return NULL;
 }
 

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Tue Dec  7 23:08:21 2010
@@ -223,13 +223,13 @@
                 return false;
         }
 
-        if (m_arch_ptr)
+        if (m_arch_ptr && m_arch_ptr->IsValid())
         {
             if (module_sp->GetArchitecture() != *m_arch_ptr)
                 return false;
         }
 
-        if (m_uuid_ptr)
+        if (m_uuid_ptr && m_uuid_ptr->IsValid())
         {
             if (module_sp->GetUUID() != *m_uuid_ptr)
                 return false;

Modified: lldb/trunk/source/Core/Section.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Core/Section.cpp (original)
+++ lldb/trunk/source/Core/Section.cpp Tue Dec  7 23:08:21 2010
@@ -222,7 +222,7 @@
 
 
 void
-Section::Dump (Stream *s, Target *target) const
+Section::Dump (Stream *s, Target *target, uint32_t depth) const
 {
 //    s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
     s->Indent();
@@ -283,7 +283,8 @@
         s->Printf(" + 0x%llx\n", m_linked_offset);
     }
 
-    m_children.Dump(s, target, false);
+    if (depth > 0)
+        m_children.Dump(s, target, false, depth - 1);
 }
 
 void
@@ -666,7 +667,7 @@
 }
 
 void
-SectionList::Dump (Stream *s, Target *target, bool show_header) const
+SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
 {
     bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
     if (show_header && !m_sections.empty())
@@ -688,7 +689,7 @@
     const_iterator end = m_sections.end();
     for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
     {
-        (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL);
+        (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
     }
 
     if (show_header && !m_sections.empty())

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Tue Dec  7 23:08:21 2010
@@ -1019,33 +1019,13 @@
     }
 }
 
-//----------------------------------------------------------------------
-// Static callback function that gets called when the process state
-// changes.
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXDYLD::Initialize(void *baton, Process *process)
-{
-    ((DynamicLoaderMacOSXDYLD*)baton)->PrivateInitialize(process);
-}
-
 void
 DynamicLoaderMacOSXDYLD::PrivateInitialize(Process *process)
 {
     DEBUG_PRINTF("DynamicLoaderMacOSXDYLD::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
     Clear(true);
     m_process = process;
-}
-
-
-//----------------------------------------------------------------------
-// Static callback function that gets called when the process state
-// changes.
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXDYLD::ProcessStateChanged(void *baton, Process *process, StateType state)
-{
-    ((DynamicLoaderMacOSXDYLD*)baton)->PrivateProcessStateChanged(process, state);
+    m_process->GetTarget().GetSectionLoadList().Clear();
 }
 
 bool

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h Tue Dec  7 23:08:21 2010
@@ -62,18 +62,6 @@
     virtual void
     DidLaunch ();
 
-    //------------------------------------------------------------------
-    // Process::Notifications callback functions
-    //------------------------------------------------------------------
-    static void
-    Initialize (void *baton,
-                lldb_private::Process *process);
-
-    static void
-    ProcessStateChanged (void *baton,
-                         lldb_private::Process *process,
-                         lldb::StateType state);
-
     virtual lldb::ThreadPlanSP
     GetStepThroughTrampolinePlan (lldb_private::Thread &thread,
                                   bool stop_others);

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Tue Dec  7 23:08:21 2010
@@ -684,7 +684,7 @@
     s->EOL();
     SectionList *section_list = GetSectionList();
     if (section_list)
-        section_list->Dump(s, NULL, true);
+        section_list->Dump(s, NULL, true, UINT32_MAX);
     Symtab *symtab = GetSymtab();
     if (symtab)
         symtab->Dump(s, NULL, lldb::eSortOrderNone);

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Tue Dec  7 23:08:21 2010
@@ -1346,7 +1346,7 @@
     *s << ", file = '" << m_file << "', arch = " << header_arch.AsCString() << "\n";
 
     if (m_sections_ap.get())
-        m_sections_ap->Dump(s, NULL, true);
+        m_sections_ap->Dump(s, NULL, true, UINT32_MAX);
 
     if (m_symtab_ap.get())
         m_symtab_ap->Dump(s, NULL, eSortOrderNone);

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Tue Dec  7 23:08:21 2010
@@ -1242,7 +1242,7 @@
 bool
 ProcessGDBRemote::IsAlive ()
 {
-    return m_gdb_comm.IsConnected();
+    return m_gdb_comm.IsConnected() && m_private_state.GetValue() != eStateExited;
 }
 
 addr_t

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Dec  7 23:08:21 2010
@@ -414,13 +414,18 @@
 void
 Process::SetExitStatus (int status, const char *cstr)
 {
-    m_exit_status = status;
-    if (cstr)
-        m_exit_string = cstr;
-    else
-        m_exit_string.clear();
+    if (m_private_state.GetValue() != eStateExited)
+    {
+        m_exit_status = status;
+        if (cstr)
+            m_exit_string = cstr;
+        else
+            m_exit_string.clear();
 
-    SetPrivateState (eStateExited);
+        DidExit ();
+
+        SetPrivateState (eStateExited);
+    }
 }
 
 // This static callback can be used to watch for local child processes on

Modified: lldb/trunk/source/Target/SectionLoadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/SectionLoadList.cpp?rev=121236&r1=121235&r2=121236&view=diff
==============================================================================
--- lldb/trunk/source/Target/SectionLoadList.cpp (original)
+++ lldb/trunk/source/Target/SectionLoadList.cpp Tue Dec  7 23:08:21 2010
@@ -28,13 +28,15 @@
 bool
 SectionLoadList::IsEmpty() const
 {
-    return m_section_load_info.IsEmpty();
+    Mutex::Locker locker(m_mutex);
+    return m_collection.empty();
 }
 
 void
 SectionLoadList::Clear ()
 {
-    m_section_load_info.Clear();
+    Mutex::Locker locker(m_mutex);
+    return m_collection.clear();
 }
 
 addr_t
@@ -42,9 +44,22 @@
 {
     // 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;
+    if (section)
+    {
+        Mutex::Locker locker(m_mutex);
+        collection::const_iterator pos, end = m_collection.end();
+        for (pos = m_collection.begin(); pos != end; ++pos)
+        {
+            const addr_t pos_load_addr = pos->first;
+            const Section *pos_section = pos->second;
+            if (pos_section == section)
+            {
+                section_load_addr = pos_load_addr;
+                break;
+            }
+        }
+    }
+    return section_load_addr;
 }
 
 bool
@@ -60,16 +75,19 @@
                      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))
+    Mutex::Locker locker(m_mutex);
+    collection::iterator pos = m_collection.find(load_addr);
+    if (pos != m_collection.end())
     {
-        if (existing_section == section)
-            return false;   // No change
+        if (section == pos->second)
+            return false; // No change...
+        else
+            pos->second = section;
+    }
+    else
+    {
+        m_collection[load_addr] = section;
     }
-    m_section_load_info.SetValueForKeyNoLock (load_addr, section);
     return true;    // Changed
 }
 
@@ -85,14 +103,22 @@
                      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))
+    Mutex::Locker locker(m_mutex);
+    bool erased = false;
+    do 
     {
-        unload_count += m_section_load_info.EraseNoLock (section_load_addr);
-    }
+        erased = false;
+        for (collection::iterator pos = m_collection.begin(); pos != m_collection.end(); ++pos)
+        {
+            if (pos->second == section)
+            {
+                m_collection.erase(pos);
+                erased = true;
+            }
+        }
+    } while (erased);
+    
     return unload_count;
 }
 
@@ -108,28 +134,44 @@
                      section->GetModule()->GetFileSpec().GetFilename().AsCString(),
                      section->GetName().AsCString(),
                      load_addr);
-
-    return m_section_load_info.Erase (load_addr) == 1;
+    Mutex::Locker locker(m_mutex);
+    return m_collection.erase (load_addr) != 0;
 }
 
 
 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))
+    // First find the top level section that this load address exists in    
+    Mutex::Locker locker(m_mutex);
+    collection::const_iterator pos = m_collection.lower_bound (load_addr);
+    if (pos != m_collection.end())
     {
-        addr_t offset = load_addr - section_load_addr;
-        if (offset < section->GetByteSize())
+        if (load_addr != pos->first && pos != m_collection.begin())
+            --pos;
+        assert (load_addr >= pos->first);
+        addr_t offset = load_addr - pos->first;
+        if (offset < pos->second->GetByteSize())
         {
             // We have found the top level section, now we need to find the
             // deepest child section.
-            return section->ResolveContainedAddress (offset, so_addr);
+            return pos->second->ResolveContainedAddress (offset, so_addr);
         }
     }
     so_addr.Clear();
     return false;
 }
+
+void
+SectionLoadList::Dump (Stream &s, Target *target)
+{
+    Mutex::Locker locker(m_mutex);
+    collection::const_iterator pos, end;
+    for (pos = m_collection.begin(), end = m_collection.end(); pos != end; ++pos)
+    {
+        s.Printf("addr = 0x%16.16llx, section = %p: ", pos->first, pos->second);
+        pos->second->Dump (&s, target, 0);
+    }
+}
+
+





More information about the lldb-commits mailing list