[Lldb-commits] [lldb] r128128 - in /lldb/trunk/source/Plugins/Platform/Linux: PlatformLinux.cpp PlatformLinux.h

Stephen Wilson wilsons at start.ca
Tue Mar 22 17:57:47 PDT 2011


Author: wilsons
Date: Tue Mar 22 19:57:47 2011
New Revision: 128128

URL: http://llvm.org/viewvc/llvm-project?rev=128128&view=rev
Log:
linux: PlatformLinux improvements
    
Add a few missing virtual methods to PlatformLinux and have it register itself
with PluginManager.


Modified:
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h

Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp?rev=128128&r1=128127&r2=128128&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Tue Mar 22 19:57:47 2011
@@ -10,27 +10,57 @@
 #include "PlatformLinux.h"
 
 // C Includes
+#include <stdio.h>
+#include <sys/utsname.h>
+
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/Error.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/StreamString.h"
 #include "lldb/Host/FileSpec.h"
 #include "lldb/Host/Host.h"
+#include "lldb/Target/Target.h"
 #include "lldb/Target/Process.h"
 
 using namespace lldb;
 using namespace lldb_private;
-    
+
+Platform *
+PlatformLinux::CreateInstance ()
+{
+    return new PlatformLinux();
+}
+
+const char *
+PlatformLinux::GetPluginNameStatic()
+{
+    return "plugin.platform.linux";
+}
+
+const char *
+PlatformLinux::GetPluginDescriptionStatic()
+{
+    return "Default platform plugin for Linux";
+}
+
 void
 PlatformLinux::Initialize ()
 {
-#if defined (__linux__)
-    PlatformSP default_platform_sp (new PlatformLinux());
-    Platform::SetDefaultPlatform (default_platform_sp);
-#endif
+    static bool g_initialized = false;
+
+    if (!g_initialized)
+    {
+        PlatformSP default_platform_sp (CreateInstance());
+        Platform::SetDefaultPlatform (default_platform_sp);
+        PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                      GetPluginDescriptionStatic(),
+                                      CreateInstance);
+        g_initialized = true;
+    }
 }
 
 void
@@ -146,7 +176,7 @@
 /// Default Constructor
 //------------------------------------------------------------------
 PlatformLinux::PlatformLinux () :
-    Platform()
+    Platform(true)
 {
 }
 
@@ -184,3 +214,43 @@
     }
     return false;
 }
+
+void
+PlatformLinux::GetStatus (Stream &strm)
+{
+    struct utsname un;
+
+    if (uname(&un)) {
+        strm << "Linux";
+        return;
+    }
+
+    strm << un.sysname << ' ' << un.release << ' ' << un.version << '\n';
+}
+
+size_t
+PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target, 
+                                                BreakpointSite *bp_site)
+{
+    static const uint8_t g_i386_opcode[] = { 0xCC };
+
+    ArchSpec arch = target.GetArchitecture();
+    const uint8_t *opcode = NULL;
+    size_t opcode_size = 0;
+
+    switch (arch.GetCore())
+    {
+    default:
+        assert(false && "CPU type not supported!");
+        break;
+
+    case ArchSpec::eCore_x86_32_i386:
+    case ArchSpec::eCore_x86_64_x86_64:
+        opcode = g_i386_opcode;
+        opcode_size = sizeof(g_i386_opcode);
+        break;
+    }
+
+    bp_site->SetTrapOpcode(opcode, opcode_size);
+    return opcode_size;
+}

Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h?rev=128128&r1=128127&r2=128128&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h Tue Mar 22 19:57:47 2011
@@ -36,16 +36,25 @@
         //------------------------------------------------------------
         // lldb_private::PluginInterface functions
         //------------------------------------------------------------
+        static Platform *
+        CreateInstance ();
+
+        static const char *
+        GetPluginNameStatic();
+
+        static const char *
+        GetPluginDescriptionStatic();
+
         virtual const char *
         GetPluginName()
         {
-            return "PlatformLinux";
+            return GetPluginNameStatic();
         }
         
         virtual const char *
         GetShortPluginName()
         {
-            return "platform.linux";
+            return "PlatformLinux";
         }
         
         virtual uint32_t
@@ -53,7 +62,6 @@
         {
             return 1;
         }
-        
 
         //------------------------------------------------------------
         // lldb_private::Platform functions
@@ -63,6 +71,15 @@
                            const ArchSpec &arch,
                            lldb::ModuleSP &module_sp);
 
+        virtual const char *
+        GetDescription ()
+        {
+            return GetPluginDescriptionStatic();
+        }
+
+        virtual void
+        GetStatus (Stream &strm);
+
         virtual Error
         GetFile (const FileSpec &platform_file, FileSpec &local_file);
 
@@ -77,12 +94,15 @@
         virtual bool
         GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch);
 
+        virtual size_t
+        GetSoftwareBreakpointTrapOpcode (Target &target, 
+                                         BreakpointSite *bp_site);
+
     protected:
         
         
     private:
         DISALLOW_COPY_AND_ASSIGN (PlatformLinux);
-
     };
 } // namespace lldb_private
 





More information about the lldb-commits mailing list