[Lldb-commits] [lldb] r124716 - in /lldb/trunk: include/lldb/ include/lldb/Core/ include/lldb/Host/ include/lldb/Symbol/ lldb.xcodeproj/ source/ source/Core/ source/Host/common/ source/Host/macosx/ source/Plugins/SymbolFile/DWARF/ source/Symbol/

Greg Clayton gclayton at apple.com
Tue Feb 1 18:24:04 PST 2011


Author: gclayton
Date: Tue Feb  1 20:24:04 2011
New Revision: 124716

URL: http://llvm.org/viewvc/llvm-project?rev=124716&view=rev
Log:
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are 
prepared for plug-ins. Plug-ins will attempt to be loaded from the 
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins" 
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:

extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);

If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:

    bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
    bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);

This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.

To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:

    static void *
    Host::DynamicLibraryOpen (const FileSpec &file_spec, 
                              Error &error);

    static Error
    Host::DynamicLibraryClose (void *dynamic_library_handle);

    static void *
    Host::DynamicLibraryGetSymbol (void *dynamic_library_handle, 
                                  const char *symbol_name, 
                                  Error &error);

lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:


    typedef enum EnumerateDirectoryResult
    {
        eEnumerateDirectoryResultNext,  // Enumerate next entry in the current directory
        eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
        eEnumerateDirectoryResultExit,  // Exit from the current directory at the current level.
        eEnumerateDirectoryResultQuit   // Stop directory enumerations at any level
    };

    typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
                                                                                  FileSpec::FileType file_type,
                                                                                  const FileSpec &spec);

    static FileSpec::EnumerateDirectoryResult
    FileSpec::EnumerateDirectory (const char *dir_path,
                                  bool find_directories,
                                  bool find_files,
                                  bool find_other,
                                  EnumerateDirectoryCallbackType callback,
                                  void *callback_baton);

This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to 
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at 
all levels.

Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based 
declaration information. Columns support can be re-enabled with the
additions of a #define.

Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.

Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.




Added:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
Modified:
    lldb/trunk/include/lldb/Core/EmulateInstruction.h
    lldb/trunk/include/lldb/Core/FileSpec.h
    lldb/trunk/include/lldb/Core/PluginManager.h
    lldb/trunk/include/lldb/Host/Host.h
    lldb/trunk/include/lldb/Symbol/Declaration.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Core/EmulateInstruction.cpp
    lldb/trunk/source/Core/FileSpec.cpp
    lldb/trunk/source/Core/PluginManager.cpp
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Host/macosx/Symbols.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/source/Symbol/Declaration.cpp
    lldb/trunk/source/lldb.cpp

Modified: lldb/trunk/include/lldb/Core/EmulateInstruction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/EmulateInstruction.h?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/EmulateInstruction.h (original)
+++ lldb/trunk/include/lldb/Core/EmulateInstruction.h Tue Feb  1 20:24:04 2011
@@ -80,8 +80,8 @@
 {
 public:
 
-    static Disassembler*
-    FindPlugin (const ArchSpec &arch);
+    static EmulateInstruction*
+    FindPlugin (const ConstString &triple, const char *plugin_name);
 
     enum ContextType
     {

Modified: lldb/trunk/include/lldb/Core/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Core/FileSpec.h Tue Feb  1 20:24:04 2011
@@ -42,12 +42,13 @@
     typedef enum FileType
     {
         eFileTypeInvalid = -1,
-        eFileTypeUknown = 0,
+        eFileTypeUnknown = 0,
         eFileTypeDirectory,
         eFileTypePipe,
         eFileTypeRegular,
         eFileTypeSocket,
-        eFileTypeSymbolicLink
+        eFileTypeSymbolicLink,
+        eFileTypeOther
     } FileType;
 
     FileSpec();
@@ -543,6 +544,26 @@
     static size_t
     ResolveUsername (const char *src_path, char *dst_path, size_t dst_len);
 
+    typedef enum EnumerateDirectoryResult
+    {
+        eEnumerateDirectoryResultNext,  // Enumerate next entry in the current directory
+        eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
+        eEnumerateDirectoryResultExit,  // Exit from the current directory at the current level.
+        eEnumerateDirectoryResultQuit   // Stop directory enumerations at any level
+    };
+
+    typedef EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
+                                                                        FileType file_type,
+                                                                        const FileSpec &spec
+);
+
+    static EnumerateDirectoryResult
+    EnumerateDirectory (const char *dir_path,
+                        bool find_directories,
+                        bool find_files,
+                        bool find_other,
+                        EnumerateDirectoryCallbackType callback,
+                        void *callback_baton);
 
 protected:
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Core/PluginManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/PluginManager.h?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/PluginManager.h (original)
+++ lldb/trunk/include/lldb/Core/PluginManager.h Tue Feb  1 20:24:04 2011
@@ -12,12 +12,19 @@
 #define liblldb_PluginManager_h_
 
 #include "lldb/lldb-private.h"
+#include "lldb/Core/FileSpec.h"
 
 namespace lldb_private {
 
 class PluginManager
 {
 public:
+    static void
+    Initialize ();
+    
+    static void
+    Terminate ();
+
     //------------------------------------------------------------------
     // ABI
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Tue Feb  1 20:24:04 2011
@@ -337,13 +337,26 @@
                          bool disable_aslr);
     
     static bool
-    OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no);
+    OpenFileInExternalEditor (const FileSpec &file_spec, 
+                              uint32_t line_no);
 
     static void
     Backtrace (Stream &strm, uint32_t max_frames);
     
     static size_t
     GetEnvironment (StringList &env);
+
+    static void *
+    DynamicLibraryOpen (const FileSpec &file_spec, 
+                        Error &error);
+
+    static Error
+    DynamicLibraryClose (void *dynamic_library_handle);
+
+    static void *
+    DynamicLibraryGetSymbol (void *dynamic_library_handle, 
+                             const char *symbol_name, 
+                             Error &error);
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Symbol/Declaration.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Declaration.h?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Declaration.h (original)
+++ lldb/trunk/include/lldb/Symbol/Declaration.h Tue Feb  1 20:24:04 2011
@@ -31,7 +31,15 @@
     //------------------------------------------------------------------
     /// Default constructor.
     //------------------------------------------------------------------
-    Declaration ();
+    Declaration () :
+        m_file (),
+        m_line (0)
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+        ,m_column (0)
+#endif
+    {
+    }
+    
 
     //------------------------------------------------------------------
     /// Construct with file specification, and optional line and column.
@@ -48,17 +56,41 @@
     ///     The column number that describes where this was declared.
     ///     Set to zero if there is no column number information.
     //------------------------------------------------------------------
-    Declaration (const FileSpec& file_spec, uint32_t line = 0, uint32_t column = 0);
+    Declaration (const FileSpec& file_spec, uint32_t line = 0, uint32_t column = 0) :
+        m_file (file_spec),
+        m_line (line)
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+        ,m_column (column)
+#endif
+    {
+    }
 
     //------------------------------------------------------------------
     /// Construct with a reference to another Declaration object.
     //------------------------------------------------------------------
-    Declaration (const Declaration& rhs);
+    Declaration (const Declaration& rhs) :
+        m_file (rhs.m_file),
+        m_line (rhs.m_line)
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+        ,m_column (rhs.m_column)
+#endif
+    {
+        
+    }
 
     //------------------------------------------------------------------
     /// Construct with a pointer to another Declaration object.
     //------------------------------------------------------------------
-    Declaration (const Declaration* rhs_ptr);
+    Declaration(const Declaration* decl_ptr) :
+        m_file(),
+        m_line(0)
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+        ,m_column(0)
+#endif
+    {
+        if (decl_ptr)
+            *this = *decl_ptr;
+    }
 
     //------------------------------------------------------------------
     /// Clear the object's state.
@@ -67,7 +99,14 @@
     /// to zero.
     //------------------------------------------------------------------
     void
-    Clear ();
+    Clear ()
+    {
+        m_file.Clear();
+        m_line= 0;
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+        m_column = 0;
+#endif
+    }
 
     //------------------------------------------------------------------
     /// Compare two declaration objects.
@@ -112,7 +151,14 @@
     ///     column information is available.
     //------------------------------------------------------------------
     uint32_t
-    GetColumn () const;
+    GetColumn () const
+    {
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+        return m_column;
+#else
+        return 0;
+#endif
+    }
 
     //------------------------------------------------------------------
     /// Get accessor for file specification.
@@ -121,7 +167,10 @@
     ///     A reference to the file specification object.
     //------------------------------------------------------------------
     FileSpec&
-    GetFile ();
+    GetFile ()
+    {
+        return m_file;
+    }
 
     //------------------------------------------------------------------
     /// Get const accessor for file specification.
@@ -130,7 +179,10 @@
     ///     A const reference to the file specification object.
     //------------------------------------------------------------------
     const FileSpec&
-    GetFile () const;
+    GetFile () const
+    {
+        return m_file;
+    }
 
     //------------------------------------------------------------------
     /// Get accessor for the declaration line number.
@@ -140,11 +192,17 @@
     ///     line information is available.
     //------------------------------------------------------------------
     uint32_t
-    GetLine () const;
+    GetLine () const
+    {
+        return m_line;
+    }
 
 
     bool
-    IsValid() const;
+    IsValid() const
+    {
+        return m_file && m_line != 0;
+    }
 
     //------------------------------------------------------------------
     /// Get the memory cost of this object.
@@ -167,7 +225,12 @@
     ///     column information is available.
     //------------------------------------------------------------------
     void
-    SetColumn (uint32_t column);
+    SetColumn (uint32_t column)
+    {
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+        m_column = col;
+#endif
+    }
 
     //------------------------------------------------------------------
     /// Set accessor for the declaration file specification.
@@ -176,7 +239,10 @@
     ///     The new declaration file specifciation.
     //------------------------------------------------------------------
     void
-    SetFile (const FileSpec& file_spec);
+    SetFile (const FileSpec& file_spec)
+    {
+        m_file = file_spec;
+    }
 
     //------------------------------------------------------------------
     /// Set accessor for the declaration line number.
@@ -186,7 +252,10 @@
     ///     line information is available.
     //------------------------------------------------------------------
     void
-    SetLine (uint32_t line);
+    SetLine (uint32_t line)
+    {
+        m_line = line;
+    }
 protected:
     //------------------------------------------------------------------
     /// Member variables.
@@ -195,10 +264,15 @@
                         ///< source file where the declaration occurred.
     uint32_t m_line;    ///< Non-zero values indicates a valid line number,
                         ///< zero indicates no line number information is available.
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
     uint32_t m_column;  ///< Non-zero values indicates a valid column number,
                         ///< zero indicates no column information is available.
+#endif
 };
 
+bool
+operator == (const Declaration &lhs, const Declaration &rhs);
+
 } // namespace lldb_private
 
 #endif  // liblldb_Declaration_h_

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Tue Feb  1 20:24:04 2011
@@ -577,7 +577,9 @@
     ePathTypeLLDBShlibDir,          // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
     ePathTypeSupportExecutableDir,  // Find LLDB support executable directory (debugserver, etc)
     ePathTypeHeaderDir,             // Find LLDB header file directory
-    ePathTypePythonDir              // Find Python modules (PYTHONPATH) directory
+    ePathTypePythonDir,             // Find Python modules (PYTHONPATH) directory
+    ePathTypeLLDBSystemPlugins,     // System plug-ins directory
+    ePathTypeLLDBUserPlugins        // User plug-ins directory
 } PathType;
 
 

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Feb  1 20:24:04 2011
@@ -69,6 +69,7 @@
 		268F9D55123AA16600B91E9B /* SBSymbolContextList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268F9D54123AA16600B91E9B /* SBSymbolContextList.cpp */; };
 		26B42B1F1187A92B0079C8C8 /* lldb-include.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B42B1E1187A92B0079C8C8 /* lldb-include.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		26B42C4D1187ABA50079C8C8 /* LLDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B42C4C1187ABA50079C8C8 /* LLDB.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		26B8B42512EEC52A00A831B2 /* UniqueDWARFASTType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26B8B42312EEC52A00A831B2 /* UniqueDWARFASTType.cpp */; };
 		26C72C94124322890068DC16 /* SBStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 26C72C93124322890068DC16 /* SBStream.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		26C72C961243229A0068DC16 /* SBStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C72C951243229A0068DC16 /* SBStream.cpp */; };
 		26D27C9F11ED3A4E0024D721 /* ELFHeader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26D27C9D11ED3A4E0024D721 /* ELFHeader.cpp */; };
@@ -605,6 +606,8 @@
 		26B42B1E1187A92B0079C8C8 /* lldb-include.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-include.h"; path = "include/lldb/lldb-include.h"; sourceTree = "<group>"; };
 		26B42C4C1187ABA50079C8C8 /* LLDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLDB.h; path = include/lldb/API/LLDB.h; sourceTree = "<group>"; };
 		26B4E26E112F35F700AB3F64 /* TimeValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimeValue.h; path = include/lldb/Host/TimeValue.h; sourceTree = "<group>"; };
+		26B8B42212EEC52A00A831B2 /* UniqueDWARFASTType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UniqueDWARFASTType.h; sourceTree = "<group>"; };
+		26B8B42312EEC52A00A831B2 /* UniqueDWARFASTType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueDWARFASTType.cpp; sourceTree = "<group>"; };
 		26BC7C2510F1B3BC00F91463 /* lldb-defines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-defines.h"; path = "include/lldb/lldb-defines.h"; sourceTree = "<group>"; };
 		26BC7C2610F1B3BC00F91463 /* lldb-enumerations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-enumerations.h"; path = "include/lldb/lldb-enumerations.h"; sourceTree = "<group>"; };
 		26BC7C2810F1B3BC00F91463 /* lldb-private-interfaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-private-interfaces.h"; path = "include/lldb/lldb-private-interfaces.h"; sourceTree = "<group>"; };
@@ -1420,6 +1423,8 @@
 				26109B3C1155D70100CC3529 /* LogChannelDWARF.h */,
 				260C89DB10F57C5600BB2B04 /* SymbolFileDWARFDebugMap.cpp */,
 				260C89DC10F57C5600BB2B04 /* SymbolFileDWARFDebugMap.h */,
+				26B8B42212EEC52A00A831B2 /* UniqueDWARFASTType.h */,
+				26B8B42312EEC52A00A831B2 /* UniqueDWARFASTType.cpp */,
 			);
 			path = DWARF;
 			sourceTree = "<group>";
@@ -1680,7 +1685,6 @@
 				26BC7D5E10F1B77400F91463 /* Disassembler.h */,
 				26BC7E7610F1B85900F91463 /* Disassembler.cpp */,
 				26BC7D5F10F1B77400F91463 /* dwarf.h */,
-				26BC7E7710F1B85900F91463 /* DynamicLoader.cpp */,
 				26D9FDC612F784E60003F2EE /* EmulateInstruction.h */,
 				26D9FDC812F784FD0003F2EE /* EmulateInstruction.cpp */,
 				26BC7D6010F1B77400F91463 /* Error.h */,
@@ -2016,6 +2020,7 @@
 				4CB443BB1249920C00C13DC2 /* CPPLanguageRuntime.h */,
 				4CB443BC1249920C00C13DC2 /* CPPLanguageRuntime.cpp */,
 				26BC7DF110F1B81A00F91463 /* DynamicLoader.h */,
+				26BC7E7710F1B85900F91463 /* DynamicLoader.cpp */,
 				26BC7DF210F1B81A00F91463 /* ExecutionContext.h */,
 				26BC7F3510F1B90C00F91463 /* ExecutionContext.cpp */,
 				26DAFD9711529BC7005A394E /* ExecutionContextScope.h */,
@@ -2839,6 +2844,7 @@
 				B296983712C2FB98002D92C3 /* CommandObjectVersion.cpp in Sources */,
 				26D9FDC912F784FD0003F2EE /* EmulateInstruction.cpp in Sources */,
 				26D9FDCE12F7853F0003F2EE /* EmulateInstructionARM.cpp in Sources */,
+				26B8B42512EEC52A00A831B2 /* UniqueDWARFASTType.cpp in Sources */,
 				4906FD4212F2255300A2A77C /* ASTDumper.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

Modified: lldb/trunk/source/Core/EmulateInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/EmulateInstruction.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Core/EmulateInstruction.cpp (original)
+++ lldb/trunk/source/Core/EmulateInstruction.cpp Tue Feb  1 20:24:04 2011
@@ -10,11 +10,37 @@
 #include "EmulateInstruction.h"
 
 #include "lldb/Core/DataExtractor.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/StreamString.h"
 #include "lldb/Host/Endian.h"
 using namespace lldb;
 using namespace lldb_private;
 
+EmulateInstruction*
+EmulateInstruction::FindPlugin (const ConstString &triple, const char *plugin_name)
+{
+    EmulateInstructionCreateInstance create_callback = NULL;
+    if (plugin_name)
+    {
+        create_callback  = PluginManager::GetEmulateInstructionCreateCallbackForPluginName (plugin_name);
+        if (create_callback)
+        {
+            std::auto_ptr<EmulateInstruction> instance_ap(create_callback(triple));
+            if (instance_ap.get())
+                return instance_ap.release();
+        }
+    }
+    else
+    {
+        for (uint32_t idx = 0; (create_callback = PluginManager::GetEmulateInstructionCreateCallbackAtIndex(idx)) != NULL; ++idx)
+        {
+            std::auto_ptr<EmulateInstruction> instance_ap(create_callback(triple));
+            if (instance_ap.get())
+                return instance_ap.release();
+        }
+    }
+    return NULL;
+}
 
 EmulateInstruction::EmulateInstruction 
 (

Modified: lldb/trunk/source/Core/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Core/FileSpec.cpp (original)
+++ lldb/trunk/source/Core/FileSpec.cpp Tue Feb  1 20:24:04 2011
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 
+#include <dirent.h>
 #include <fcntl.h>
 #include <libgen.h>
 #include <stdlib.h>
@@ -27,6 +28,7 @@
 #include "lldb/Core/DataBufferMemoryMap.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Host/Host.h"
+#include "lldb/Utility/CleanUp.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -572,7 +574,7 @@
         default:
             break;
         }
-        return eFileTypeUknown;
+        return eFileTypeUnknown;
     }
     return eFileTypeInvalid;
 }
@@ -805,3 +807,102 @@
     }
     return lines.size();
 }
+
+FileSpec::EnumerateDirectoryResult
+FileSpec::EnumerateDirectory
+(
+    const char *dir_path, 
+    bool find_directories,
+    bool find_files,
+    bool find_other,
+    EnumerateDirectoryCallbackType callback,
+    void *callback_baton
+)
+{
+    if (dir_path && dir_path[0])
+    {
+        lldb_utility::CleanUp <DIR *, int> dir_path_dir (opendir(dir_path), NULL, closedir);
+        if (dir_path_dir.is_valid())
+        {
+            struct dirent* dp;
+            while ((dp = readdir(dir_path_dir.get())) != NULL)
+            {
+                // Only search directories
+                if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
+                {
+                    if (dp->d_namlen == 1 && dp->d_name[0] == '.')
+                        continue;
+
+                    if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
+                        continue;
+                }
+            
+                bool call_callback = false;
+                FileSpec::FileType file_type = eFileTypeUnknown;
+
+                switch (dp->d_type)
+                {
+                default:
+                case DT_UNKNOWN:    file_type = eFileTypeUnknown;       call_callback = true;               break;
+                case DT_FIFO:       file_type = eFileTypePipe;          call_callback = find_other;         break;
+                case DT_CHR:        file_type = eFileTypeOther;         call_callback = find_other;         break;
+                case DT_DIR:        file_type = eFileTypeDirectory;     call_callback = find_directories;   break;
+                case DT_BLK:        file_type = eFileTypeOther;         call_callback = find_other;         break;
+                case DT_REG:        file_type = eFileTypeRegular;       call_callback = find_files;         break;
+                case DT_LNK:        file_type = eFileTypeSymbolicLink;  call_callback = find_other;         break;
+                case DT_SOCK:       file_type = eFileTypeSocket;        call_callback = find_other;         break;
+                case DT_WHT:        file_type = eFileTypeOther;         call_callback = find_other;         break;
+                }
+
+                if (call_callback)
+                {
+                    char child_path[PATH_MAX];
+                    const int child_path_len = ::snprintf (child_path, sizeof(child_path), "%s/%s", dir_path, dp->d_name);
+                    if (child_path_len < sizeof(child_path) - 1)
+                    {
+                        // Don't resolve the file type or path
+                        FileSpec child_path_spec (child_path, false);
+
+                        EnumerateDirectoryResult result = callback (callback_baton, file_type, child_path_spec);
+                        
+                        switch (result)
+                        {
+                        default:
+                        case eEnumerateDirectoryResultNext:  
+                            // Enumerate next entry in the current directory. We just
+                            // exit this switch and will continue enumerating the
+                            // current directory as we currently are...
+                            break;
+
+                        case eEnumerateDirectoryResultEnter: // Recurse into the current entry if it is a directory or symlink, or next if not
+                            if (FileSpec::EnumerateDirectory (child_path, 
+                                                              find_directories, 
+                                                              find_files, 
+                                                              find_other, 
+                                                              callback, 
+                                                              callback_baton) == eEnumerateDirectoryResultQuit)
+                            {
+                                // The subdirectory returned Quit, which means to 
+                                // stop all directory enumerations at all levels.
+                                return eEnumerateDirectoryResultQuit;
+                            }
+                            break;
+                        
+                        case eEnumerateDirectoryResultExit:  // Exit from the current directory at the current level.
+                            // Exit from this directory level and tell parent to 
+                            // keep enumerating.
+                            return eEnumerateDirectoryResultNext;
+
+                        case eEnumerateDirectoryResultQuit:  // Stop directory enumerations at any level
+                            return eEnumerateDirectoryResultQuit;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    // By default when exiting a directory, we tell the parent enumeration
+    // to continue enumerating.
+    return eEnumerateDirectoryResultNext;    
+}
+

Modified: lldb/trunk/source/Core/PluginManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Core/PluginManager.cpp (original)
+++ lldb/trunk/source/Core/PluginManager.cpp Tue Feb  1 20:24:04 2011
@@ -12,6 +12,12 @@
 #include <string>
 #include <vector>
 
+#include "lldb/Core/Error.h"
+#include "lldb/Core/FileSpec.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/Mutex.h"
+
+using namespace lldb;
 using namespace lldb_private;
 
 enum PluginAction
@@ -21,6 +27,181 @@
     ePluginGetInstanceAtIndex
 };
 
+struct PluginInfo
+{
+    void *plugin_handle;
+    void *plugin_init_callback;
+    void *plugin_term_callback;
+};
+
+typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
+
+static Mutex &
+GetPluginMapMutex ()
+{
+    static Mutex g_plugin_map_mutex (Mutex::eMutexTypeRecursive);
+    return g_plugin_map_mutex;
+}
+
+static PluginTerminateMap &
+GetPluginMap ()
+{
+    static PluginTerminateMap g_plugin_map;
+    return g_plugin_map;
+}
+
+static bool
+PluginIsLoaded (const FileSpec &plugin_file_spec)
+{
+    Mutex::Locker locker (GetPluginMapMutex ());
+    PluginTerminateMap &plugin_map = GetPluginMap ();
+    return plugin_map.find (plugin_file_spec) != plugin_map.end();
+}
+    
+static void
+SetPluginInfo (const FileSpec &plugin_file_spec, const PluginInfo &plugin_info)
+{
+    Mutex::Locker locker (GetPluginMapMutex ());
+    PluginTerminateMap &plugin_map = GetPluginMap ();
+    assert (plugin_map.find (plugin_file_spec) != plugin_map.end());
+    plugin_map[plugin_file_spec] = plugin_info;
+}
+
+
+static FileSpec::EnumerateDirectoryResult 
+LoadPluginCallback 
+(
+    void *baton,
+    FileSpec::FileType file_type,
+    const FileSpec &file_spec
+)
+{
+//    PluginManager *plugin_manager = (PluginManager *)baton;
+    Error error;
+    
+    // If we have a regular file, a symbolic link or unknown file type, try
+    // and process the file. We must handle unknown as sometimes the directory 
+    // enumeration might be enumerating a file system that doesn't have correct
+    // file type information.
+    if (file_type == FileSpec::eFileTypeRegular         ||
+        file_type == FileSpec::eFileTypeSymbolicLink    ||
+        file_type == FileSpec::eFileTypeUnknown          )
+    {
+        FileSpec plugin_file_spec (file_spec);
+        plugin_file_spec.ResolvePath();
+        
+        if (PluginIsLoaded (plugin_file_spec))
+            return FileSpec::eEnumerateDirectoryResultNext;
+        else
+        {
+            PluginInfo plugin_info = { NULL, NULL, NULL };
+            plugin_info.plugin_handle = Host::DynamicLibraryOpen (plugin_file_spec, error);
+            if (plugin_info.plugin_handle)
+            {
+                bool success = false;
+                plugin_info.plugin_init_callback = Host::DynamicLibraryGetSymbol (plugin_info.plugin_handle, "LLDBPluginInitialize", error);
+                if (plugin_info.plugin_init_callback)
+                {
+                    // Call the plug-in "bool LLDBPluginInitialize(void)" function
+                    success = ((bool (*)(void))plugin_info.plugin_init_callback)();
+                }
+
+                if (success)
+                {
+                    // It is ok for the "LLDBPluginTerminate" symbol to be NULL
+                    plugin_info.plugin_term_callback = Host::DynamicLibraryGetSymbol (plugin_info.plugin_handle, "LLDBPluginTerminate", error);
+                }
+                else 
+                {
+                    // The initialize function returned FALSE which means the
+                    // plug-in might not be compatible, or might be too new or
+                    // too old, or might not want to run on this machine.
+                    Host::DynamicLibraryClose (plugin_info.plugin_handle);
+                    plugin_info.plugin_handle = NULL;
+                    plugin_info.plugin_init_callback = NULL;
+                }
+
+                // Regardless of success or failure, cache the plug-in load
+                // in our plug-in info so we don't try to load it again and 
+                // again.
+                SetPluginInfo (plugin_file_spec, plugin_info);
+
+                return FileSpec::eEnumerateDirectoryResultNext;
+            }
+        }
+    }
+    
+    if (file_type == FileSpec::eFileTypeUnknown     ||
+        file_type == FileSpec::eFileTypeDirectory   ||
+        file_type == FileSpec::eFileTypeSymbolicLink )
+    {
+        // Try and recurse into anything that a directory or symbolic link. 
+        // We must also do this for unknown as sometimes the directory enumeration
+        // might be enurating a file system that doesn't have correct file type
+        // information.
+        return FileSpec::eEnumerateDirectoryResultEnter;
+    }
+
+    return FileSpec::eEnumerateDirectoryResultNext;
+}
+
+
+void
+PluginManager::Initialize ()
+{
+    FileSpec dir_spec;
+    const bool find_directories = true;
+    const bool find_files = true;
+    const bool find_other = true;
+    char dir_path[PATH_MAX];
+    if (Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec))
+    {
+        if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
+        {
+            FileSpec::EnumerateDirectory (dir_path, 
+                                          find_directories,
+                                          find_files,
+                                          find_other,
+                                          LoadPluginCallback,
+                                          NULL);
+        }
+    }
+
+    if (Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec))
+    {
+        if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
+        {
+            FileSpec::EnumerateDirectory (dir_path, 
+                                          find_directories,
+                                          find_files,
+                                          find_other,
+                                          LoadPluginCallback,
+                                          NULL);
+        }
+    }
+}
+
+void
+PluginManager::Terminate ()
+{
+    Mutex::Locker locker (GetPluginMapMutex ());
+    PluginTerminateMap &plugin_map = GetPluginMap ();
+    
+    PluginTerminateMap::const_iterator pos, end = plugin_map.end();
+    for (pos = plugin_map.begin(); pos != end; ++pos)
+    {
+        // Call the plug-in "void LLDBPluginTerminate (void)" function if there
+        // is one (if the symbol was not NULL).
+        if (pos->second.plugin_handle)
+        {
+            if (pos->second.plugin_term_callback)
+                ((void (*)(void))pos->second.plugin_term_callback)();
+            Host::DynamicLibraryClose (pos->second.plugin_handle);
+        }
+    }
+    plugin_map.clear();
+}
+
 
 #pragma mark ABI
 
@@ -88,11 +269,11 @@
 
 bool
 PluginManager::RegisterPlugin
-    (
-        const char *name,
-        const char *description,
-        ABICreateInstance create_callback
-     )
+(
+    const char *name,
+    const char *description,
+    ABICreateInstance create_callback
+)
 {
     if (create_callback)
     {
@@ -458,10 +639,10 @@
 bool
 PluginManager::RegisterPlugin
 (
- const char *name,
- const char *description,
- EmulateInstructionCreateInstance create_callback
- )
+    const char *name,
+    const char *description,
+    EmulateInstructionCreateInstance create_callback
+)
 {
     if (create_callback)
     {
@@ -580,11 +761,11 @@
 
 bool
 PluginManager::RegisterPlugin
-    (
-        const char *name,
-        const char *description,
-        LanguageRuntimeCreateInstance create_callback
-     )
+(
+    const char *name,
+    const char *description,
+    LanguageRuntimeCreateInstance create_callback
+)
 {
     if (create_callback)
     {

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Tue Feb  1 20:24:04 2011
@@ -387,14 +387,14 @@
 void
 Host::Backtrace (Stream &strm, uint32_t max_frames)
 {
-    // TODO: Is there a way to backtrace the current process on linux?
+    // TODO: Is there a way to backtrace the current process on linux? Other systems?
 }
 
 
 size_t
 Host::GetEnvironment (StringList &env)
 {
-    // TODO: Is there a way to the host environment for this process on linux?
+    // TODO: Is there a way to the host environment for this process on linux? Other systems?
     return 0;
 }
 
@@ -642,6 +642,62 @@
 }
 #endif
 
+void *
+Host::DynamicLibraryOpen (const FileSpec &file_spec, Error &error)
+{
+    void *dynamic_library_handle = NULL;
+    char path[PATH_MAX];
+    if (file_spec.GetPath(path, sizeof(path)))
+    {
+        dynamic_library_handle = ::dlopen (path, RTLD_LAZY | RTLD_GLOBAL | RTLD_FIRST);
+        if (dynamic_library_handle)
+        {
+            error.Clear();
+        }
+        else
+        {
+            error.SetErrorString(::dlerror());
+        }
+    }
+    else 
+    {
+        error.SetErrorString("failed to extract path");
+    }
+
+    return dynamic_library_handle;
+}
+
+Error
+Host::DynamicLibraryClose (void *dynamic_library_handle)
+{
+    Error error;
+    if (dynamic_library_handle == NULL)
+    {
+        error.SetErrorString ("invalid dynamic library handle");
+    }
+    else if (::dlclose(dynamic_library_handle) != 0)
+    {
+        error.SetErrorString(::dlerror());
+    }
+    return error;
+}
+
+void *
+Host::DynamicLibraryGetSymbol (void *dynamic_library_handle, const char *symbol_name, Error &error)
+{
+    if (dynamic_library_handle == NULL)
+    {
+        error.SetErrorString ("invalid dynamic library handle");
+        return NULL;
+    }
+    
+    void *symbol_addr = ::dlsym (dynamic_library_handle, symbol_name);
+    if (symbol_addr == NULL)
+        error.SetErrorString(::dlerror());
+    else
+        error.Clear();
+    return symbol_addr;
+}
 
 bool
 Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
@@ -719,7 +775,7 @@
                     g_lldb_headers_dir.SetCString(resolved_path);
                 }
 #else
-                // TODO: Anyone know how we can determine this for linux??
+                // TODO: Anyone know how we can determine this for linux? Other systems??
                 g_lldb_headers_dir.SetCString ("/opt/local/include/lldb");
 #endif
             }
@@ -730,7 +786,7 @@
 
     case ePathTypePythonDir:                
         {
-            // TODO: Anyone know how we can determine this for linux??
+            // TODO: Anyone know how we can determine this for linux? Other systems?
             // For linux we are currently assuming the location of the lldb
             // binary that contains this function is the directory that will 
             // contain lldb.so, lldb.py and embedded_interpreter.py...
@@ -762,6 +818,57 @@
         }
         break;
     
+    case ePathTypeLLDBSystemPlugins:    // System plug-ins directory
+        {
+#if defined (__APPLE__)
+            static ConstString g_lldb_system_plugin_dir;
+            if (!g_lldb_system_plugin_dir)
+            {
+                FileSpec lldb_file_spec;
+                if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
+                {
+                    char raw_path[PATH_MAX];
+                    char resolved_path[PATH_MAX];
+                    lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
+
+                    char *framework_pos = ::strstr (raw_path, "LLDB.framework");
+                    if (framework_pos)
+                    {
+                        framework_pos += strlen("LLDB.framework");
+                        ::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path));
+                    }
+                    FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
+                    g_lldb_system_plugin_dir.SetCString(resolved_path);
+                }
+            }
+            file_spec.GetDirectory() = g_lldb_system_plugin_dir;
+            return file_spec.GetDirectory();
+#endif
+            // TODO: where would system LLDB plug-ins be located on linux? Other systems?
+            return false;
+        }
+        break;
+
+    case ePathTypeLLDBUserPlugins:      // User plug-ins directory
+        {
+#if defined (__APPLE__)
+            static ConstString g_lldb_user_plugin_dir;
+            if (!g_lldb_user_plugin_dir)
+            {
+                char user_plugin_path[PATH_MAX];
+                if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns", 
+                                       user_plugin_path, 
+                                       sizeof(user_plugin_path)))
+                {
+                    g_lldb_user_plugin_dir.SetCString(user_plugin_path);
+                }
+            }
+            file_spec.GetDirectory() = g_lldb_user_plugin_dir;
+            return file_spec.GetDirectory();
+#endif
+            // TODO: where would user LLDB plug-ins be located on linux? Other systems?
+            return false;
+        }
     default:
         assert (!"Unhandled PathType");
         break;

Modified: lldb/trunk/source/Host/macosx/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Symbols.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Symbols.cpp (original)
+++ lldb/trunk/source/Host/macosx/Symbols.cpp Tue Feb  1 20:24:04 2011
@@ -238,7 +238,7 @@
     {
         ::strncat (path, "/Contents/Resources/DWARF", sizeof(path) - strlen(path) - 1);
 
-        lldb_utility::CleanUp <DIR *, int> dirp (opendir("containing_part"), NULL, closedir);
+        lldb_utility::CleanUp <DIR *, int> dirp (opendir(path), NULL, closedir);
         if (dirp.is_valid())
         {
             dsym_fspec.GetDirectory().SetCString(path);

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Feb  1 20:24:04 2011
@@ -179,7 +179,8 @@
     m_namespace_index(),
     m_indexed (false),
     m_is_external_ast_source (false),
-    m_ranges()
+    m_ranges()//,
+    //m_unique_ast_type_map ()
 {
 }
 
@@ -3168,101 +3169,134 @@
                         }
                     }
 
-                    DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
-
-                    int tag_decl_kind = -1;
-                    AccessType default_accessibility = eAccessNone;
-                    if (tag == DW_TAG_structure_type)
+//                    UniqueDWARFASTType unique_ast_entry;
+//                    if (decl.IsValid())
+//                    {
+//                        if (m_unique_ast_type_map.Find (type_name_const_str,
+//                                                        die,
+//                                                        decl,
+//                                                        unique_ast_entry))
+//                        {
+//                            // We have already parsed this type or from another 
+//                            // compile unit. GCC loves to use the "one definition
+//                            // rule" which can result in multiple definitions
+//                            // of the same class over and over in each compile
+//                            // unit.
+//                            type_sp = unique_ast_entry.m_type_sp;
+//                        }
+//                    }
+//                    
+//                    if (type_sp)
+//                    {
+//                        m_die_to_type[die] = type_sp.get();
+//
+//                    }
+//                    else
                     {
-                        tag_decl_kind = clang::TTK_Struct;
-                        default_accessibility = eAccessPublic;
-                    }
-                    else if (tag == DW_TAG_union_type)
-                    {
-                        tag_decl_kind = clang::TTK_Union;
-                        default_accessibility = eAccessPublic;
-                    }
-                    else if (tag == DW_TAG_class_type)
-                    {
-                        tag_decl_kind = clang::TTK_Class;
-                        default_accessibility = eAccessPrivate;
-                    }
+                        DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
 
+                        int tag_decl_kind = -1;
+                        AccessType default_accessibility = eAccessNone;
+                        if (tag == DW_TAG_structure_type)
+                        {
+                            tag_decl_kind = clang::TTK_Struct;
+                            default_accessibility = eAccessPublic;
+                        }
+                        else if (tag == DW_TAG_union_type)
+                        {
+                            tag_decl_kind = clang::TTK_Union;
+                            default_accessibility = eAccessPublic;
+                        }
+                        else if (tag == DW_TAG_class_type)
+                        {
+                            tag_decl_kind = clang::TTK_Class;
+                            default_accessibility = eAccessPrivate;
+                        }
 
-                    if (is_forward_declaration)
-                    {
-                        // We have a forward declaration to a type and we need
-                        // to try and find a full declaration. We look in the
-                        // current type index just in case we have a forward
-                        // declaration followed by an actual declarations in the
-                        // DWARF. If this fails, we need to look elsewhere...
-                    
-                        type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
 
-                        if (!type_sp && m_debug_map_symfile)
+                        if (is_forward_declaration)
                         {
-                            // We weren't able to find a full declaration in
-                            // this DWARF, see if we have a declaration anywhere    
-                            // else...
-                            type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
-                        }
+                            // We have a forward declaration to a type and we need
+                            // to try and find a full declaration. We look in the
+                            // current type index just in case we have a forward
+                            // declaration followed by an actual declarations in the
+                            // DWARF. If this fails, we need to look elsewhere...
+                        
+                            type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
 
-                        if (type_sp)
+                            if (!type_sp && m_debug_map_symfile)
+                            {
+                                // We weren't able to find a full declaration in
+                                // this DWARF, see if we have a declaration anywhere    
+                                // else...
+                                type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
+                            }
+
+                            if (type_sp)
+                            {
+                                // We found a real definition for this type elsewhere
+                                // so lets use it and cache the fact that we found
+                                // a complete type for this die
+                                m_die_to_type[die] = type_sp.get();
+                                return type_sp;
+                            }
+                        }
+                        assert (tag_decl_kind != -1);
+                        bool clang_type_was_created = false;
+                        clang_type = m_forward_decl_die_to_clang_type.lookup (die);
+                        if (clang_type == NULL)
                         {
-                            // We found a real definition for this type elsewhere
-                            // so lets use it and cache the fact that we found
-                            // a complete type for this die
-                            m_die_to_type[die] = type_sp.get();
-                            return type_sp;
+                            clang_type_was_created = true;
+                            clang_type = ast.CreateRecordType (type_name_cstr, 
+                                                               tag_decl_kind, 
+                                                               GetClangDeclContextForDIE (dwarf_cu, die), 
+                                                               class_language);
                         }
-                    }
-                    assert (tag_decl_kind != -1);
-                    bool clang_type_was_created = false;
-                    clang_type = m_forward_decl_die_to_clang_type.lookup (die);
-                    if (clang_type == NULL)
-                    {
-                        clang_type_was_created = true;
-                        clang_type = ast.CreateRecordType (type_name_cstr, 
-                                                           tag_decl_kind, 
-                                                           GetClangDeclContextForDIE (dwarf_cu, die), 
-                                                           class_language);
-                    }
 
-                    // Store a forward declaration to this class type in case any 
-                    // parameters in any class methods need it for the clang 
-                    // types for function prototypes. 
-                    m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
-                    type_sp.reset (new Type (die->GetOffset(), 
-                                             this, 
-                                             type_name_const_str, 
-                                             byte_size, 
-                                             NULL, 
-                                             LLDB_INVALID_UID, 
-                                             Type::eEncodingIsUID, 
-                                             &decl, 
-                                             clang_type, 
-                                             Type::eResolveStateForward));
-                    
-                    m_die_to_type[die] = type_sp.get();
+                        // Store a forward declaration to this class type in case any 
+                        // parameters in any class methods need it for the clang 
+                        // types for function prototypes. 
+                        m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
+                        type_sp.reset (new Type (die->GetOffset(), 
+                                                 this, 
+                                                 type_name_const_str, 
+                                                 byte_size, 
+                                                 NULL, 
+                                                 LLDB_INVALID_UID, 
+                                                 Type::eEncodingIsUID, 
+                                                 &decl, 
+                                                 clang_type, 
+                                                 Type::eResolveStateForward));
 
-                    if (die->HasChildren() == false && is_forward_declaration == false)
-                    {
-                        // No children for this struct/union/class, lets finish it
-                        ast.StartTagDeclarationDefinition (clang_type);
-                        ast.CompleteTagDeclarationDefinition (clang_type);
-                    }
-                    else if (clang_type_was_created)
-                    {
-                        // Leave this as a forward declaration until we need
-                        // to know the details of the type. lldb_private::Type
-                        // will automatically call the SymbolFile virtual function
-                        // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
-                        // When the definition needs to be defined.
-                        m_forward_decl_die_to_clang_type[die] = clang_type;
-                        m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
-                        ClangASTContext::SetHasExternalStorage (clang_type, true);
+                        m_die_to_type[die] = type_sp.get();
+
+                        // Add our type to the unique type map so we don't
+                        // end up creating many copies of the same type over
+                        // and over in the ASTContext for our module
+//                        unique_ast_entry.m_type_sp = type_sp;
+//                        unique_ast_entry.m_die = die;
+//                        unique_ast_entry.m_declaration = decl;
+//                        m_unique_ast_type_map.Insert (type_name_const_str, 
+//                                                      unique_ast_entry);
+                        
+                        if (die->HasChildren() == false && is_forward_declaration == false)
+                        {
+                            // No children for this struct/union/class, lets finish it
+                            ast.StartTagDeclarationDefinition (clang_type);
+                            ast.CompleteTagDeclarationDefinition (clang_type);
+                        }
+                        else if (clang_type_was_created)
+                        {
+                            // Leave this as a forward declaration until we need
+                            // to know the details of the type. lldb_private::Type
+                            // will automatically call the SymbolFile virtual function
+                            // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
+                            // When the definition needs to be defined.
+                            m_forward_decl_die_to_clang_type[die] = clang_type;
+                            m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
+                            ClangASTContext::SetHasExternalStorage (clang_type, true);
+                        }
                     }
-                    
                 }
                 break;
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Tue Feb  1 20:24:04 2011
@@ -32,6 +32,7 @@
 // Project includes
 #include "DWARFDefines.h"
 #include "NameToDIE.h"
+//#include "UniqueDWARFASTType.h"
 
 
 //----------------------------------------------------------------------
@@ -350,7 +351,7 @@
          m_is_external_ast_source:1;
 
     std::auto_ptr<DWARFDebugRanges>     m_ranges;
-
+//    UniqueDWARFASTTypeMap m_unique_ast_type_map;
     typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::DeclContext *> DIEToDeclContextMap;
     typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *> DIEToTypePtr;
     typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> DIEToVariableSP;

Added: lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp?rev=124716&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp (added)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp Tue Feb  1 20:24:04 2011
@@ -0,0 +1,41 @@
+//===-- UniqueDWARFASTType.cpp ----------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "UniqueDWARFASTType.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Symbol/Declaration.h"
+
+#include "DWARFDebugInfoEntry.h"
+
+bool
+UniqueDWARFASTTypeList::Find 
+(
+    const DWARFDebugInfoEntry *die, 
+    const lldb_private::Declaration &decl,
+    UniqueDWARFASTType &entry
+) const
+{
+    collection::const_iterator pos, end = m_collection.end();
+    for (pos = m_collection.begin(); pos != end; ++pos)
+    {
+        if (pos->m_die->Tag() == die->Tag())
+        {
+            if (pos->m_declaration == decl)
+            {
+                entry = *pos;
+                return true;
+            }
+        }
+    }
+    return false;
+}

Added: lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h?rev=124716&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h (added)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h Tue Feb  1 20:24:04 2011
@@ -0,0 +1,151 @@
+//===-- UniqueDWARFASTType.h ------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_UniqueDWARFASTType_h_
+#define lldb_UniqueDWARFASTType_h_
+
+// C Includes
+// C++ Includes
+#include <vector>
+
+// Other libraries and framework includes
+#include "llvm/ADT/DenseMap.h"
+
+// Project includes
+#include "lldb/Symbol/Declaration.h"
+
+class DWARFCompileUnit;
+class DWARFDebugInfoEntry;
+class SymbolFileDWARF;
+
+class UniqueDWARFASTType
+{
+public:
+	//------------------------------------------------------------------
+	// Constructors and Destructors
+	//------------------------------------------------------------------
+	UniqueDWARFASTType () :
+        m_type_sp (),
+        m_die (NULL),
+        m_declaration ()
+    {
+    }
+
+	UniqueDWARFASTType (lldb::TypeSP &type_sp,
+                        DWARFDebugInfoEntry *die,
+                        const lldb_private::Declaration &decl) :
+        m_type_sp (type_sp),
+        m_die (die),
+        m_declaration (decl)
+    {
+    }
+    
+    UniqueDWARFASTType (const UniqueDWARFASTType &rhs) :
+        m_type_sp (rhs.m_type_sp),
+        m_die (rhs.m_die),
+        m_declaration (rhs.m_declaration)
+    {
+    }
+
+	~UniqueDWARFASTType()
+    {
+    }
+
+    UniqueDWARFASTType &
+    operator= (const UniqueDWARFASTType &rhs)
+    {
+        if (this != &rhs)
+        {
+            m_type_sp = rhs.m_type_sp;
+            m_die = rhs.m_die;
+            m_declaration = rhs.m_declaration;
+        }
+        return *this;
+    }
+
+    lldb::TypeSP m_type_sp;
+    const DWARFDebugInfoEntry *m_die;
+    lldb_private::Declaration m_declaration;    
+};
+
+class UniqueDWARFASTTypeList
+{
+public:
+    UniqueDWARFASTTypeList () :
+        m_collection()
+    {
+    }
+    
+    ~UniqueDWARFASTTypeList ()
+    {
+    }
+    
+    uint32_t
+    GetSize()
+    {
+        return (uint32_t)m_collection.size();
+    }
+    
+    void
+    Append (const UniqueDWARFASTType &entry)
+    {
+        m_collection.push_back (entry);
+    }
+    
+    bool
+    Find (const DWARFDebugInfoEntry *die, 
+          const lldb_private::Declaration &decl,
+          UniqueDWARFASTType &entry) const;
+    
+protected:
+    typedef std::vector<UniqueDWARFASTType> collection;
+    collection m_collection;
+};
+
+class UniqueDWARFASTTypeMap
+{
+public:
+    UniqueDWARFASTTypeMap () :
+        m_collection ()
+    {
+    }
+    
+    ~UniqueDWARFASTTypeMap ()
+    {
+    }
+
+    void
+    Insert (const lldb_private::ConstString &name, 
+            const UniqueDWARFASTType &entry)
+    {
+        m_collection[name.GetCString()].Append (entry);
+    }
+
+    bool
+    Find (const lldb_private::ConstString &name, 
+          const DWARFDebugInfoEntry *die, 
+          const lldb_private::Declaration &decl,
+          UniqueDWARFASTType &entry) const
+    {
+        const char *unique_name_cstr = name.GetCString();
+        collection::const_iterator pos = m_collection.find (unique_name_cstr);
+        if (pos != m_collection.end())
+        {
+            return pos->second.Find (die, decl, entry);
+        }
+        return false;
+    }
+
+protected:
+    // A unique name string should be used
+    typedef llvm::DenseMap<const char *, UniqueDWARFASTTypeList> collection;
+    collection m_collection;
+};
+
+#endif	// lldb_UniqueDWARFASTType_h_

Modified: lldb/trunk/source/Symbol/Declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Declaration.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Declaration.cpp (original)
+++ lldb/trunk/source/Symbol/Declaration.cpp Tue Feb  1 20:24:04 2011
@@ -12,50 +12,6 @@
 
 using namespace lldb_private;
 
-Declaration::Declaration() :
-    m_file(),
-    m_line(0),
-    m_column(0)
-{
-}
-
-Declaration::Declaration(const FileSpec& f, uint32_t l, uint32_t c) :
-    m_file(f),
-    m_line(l),
-    m_column(c)
-{
-}
-
-Declaration::Declaration(const Declaration& rhs) :
-    m_file(rhs.m_file),
-    m_line(rhs.m_line),
-    m_column(rhs.m_column)
-{
-}
-
-Declaration::Declaration(const Declaration* decl_ptr) :
-    m_file(),
-    m_line(0),
-    m_column(0)
-{
-    if (decl_ptr != NULL)
-        *this = *decl_ptr;
-}
-
-bool
-Declaration::IsValid() const
-{
-    return m_file && m_line != 0;
-}
-
-void
-Declaration::Clear()
-{
-    m_file.Clear();
-    m_line= 0;
-    m_column = 0;
-}
-
 void
 Declaration::Dump(Stream *s, bool show_fullpaths) const
 {
@@ -68,19 +24,25 @@
             *s << m_file.GetFilename();
         if (m_line > 0)
             s->Printf(":%u", m_line);
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
         if (m_column > 0)
             s->Printf(":%u", m_column);
+#endif
     }
     else
     {
         if (m_line > 0)
         {
             s->Printf(", line = %u", m_line);
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
             if (m_column > 0)
                 s->Printf(":%u", m_column);
+#endif
         }
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
         else if (m_column > 0)
             s->Printf(", column = %u", m_column);
+#endif
     }
 }
 
@@ -96,67 +58,27 @@
 
         if (m_line > 0)
             s->Printf(":%u", m_line);
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
         if (m_column > 0)
             s->Printf(":%u", m_column);
+#endif
     }
     else
     {
         s->Printf(" line %u", m_line);
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
         if (m_column > 0)
             s->Printf(":%u", m_column);
+#endif
     }
 }
 
-uint32_t
-Declaration::GetColumn() const
-{
-    return m_column;
-}
-
-FileSpec&
-Declaration::GetFile()
-{
-    return m_file;
-}
-
-const FileSpec&
-Declaration::GetFile() const
-{
-    return m_file;
-}
-
-uint32_t
-Declaration::GetLine() const
-{
-    return m_line;
-}
-
 size_t
 Declaration::MemorySize() const
 {
     return sizeof(Declaration);
 }
 
-void
-Declaration::SetColumn(uint32_t col)
-{
-    m_column = col;
-}
-
-void
-Declaration::SetFile(const FileSpec& file)
-{
-    m_file = file;
-}
-
-void
-Declaration::SetLine(uint32_t line)
-{
-    m_line = line;
-}
-
-
-
 int
 Declaration::Compare(const Declaration& a, const Declaration& b)
 {
@@ -167,9 +89,26 @@
         return -1;
     else if (a.m_line > b.m_line)
         return 1;
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
     if (a.m_column < b.m_column)
         return -1;
     else if (a.m_column > b.m_column)
         return 1;
+#endif
     return 0;
 }
+
+bool
+lldb_private::operator == (const Declaration &lhs, const Declaration &rhs)
+{
+#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
+    if (lhs.GetColumn () == rhs.GetColumn ())
+        if (lhs.GetLine () == rhs.GetLine ())
+            return lhs.GetFile() == rhs.GetFile();
+#else
+    if (lhs.GetLine () == rhs.GetLine ())
+        return lhs.GetFile() == rhs.GetFile();
+#endif
+    return false;
+}
+

Modified: lldb/trunk/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=124716&r1=124715&r2=124716&view=diff
==============================================================================
--- lldb/trunk/source/lldb.cpp (original)
+++ lldb/trunk/source/lldb.cpp Tue Feb  1 20:24:04 2011
@@ -11,6 +11,7 @@
 #include "lldb/lldb-private-log.h"
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/Log.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/Mutex.h"
@@ -97,6 +98,8 @@
         ProcessLinux::Initialize();
         DynamicLoaderLinuxDYLD::Initialize();
 #endif
+        // Scan for any system or user LLDB plug-ins
+        PluginManager::Initialize();
     }
 }
 
@@ -110,6 +113,10 @@
 lldb_private::Terminate ()
 {
     Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
+    
+    // Terminate and unload and loaded system or user LLDB plug-ins
+    PluginManager::Terminate();
+
     DisassemblerLLVM::Terminate();
     ObjectContainerBSDArchive::Terminate();
     ObjectFileELF::Terminate();





More information about the lldb-commits mailing list