[Lldb-commits] [lldb] r162472 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj source/Plugins/Makefile source/Plugins/OperatingSystem/Python/ source/Plugins/OperatingSystem/Python/Makefile source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp source/Plugins/OperatingSystem/Python/OperatingSystemPython.h source/lldb.cpp

Greg Clayton gclayton at apple.com
Thu Aug 23 14:17:11 PDT 2012


Author: gclayton
Date: Thu Aug 23 16:17:11 2012
New Revision: 162472

URL: http://llvm.org/viewvc/llvm-project?rev=162472&view=rev
Log:
Added a hollowed out version of an OperatingSystem plugin that will use a class in python to get thread information for threads stored in memory.


Added:
    lldb/trunk/source/Plugins/OperatingSystem/Python/
    lldb/trunk/source/Plugins/OperatingSystem/Python/Makefile
    lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
    lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
Modified:
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Plugins/Makefile
    lldb/trunk/source/lldb.cpp

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=162472&r1=162471&r2=162472&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Aug 23 16:17:11 2012
@@ -413,6 +413,10 @@
 		2697A39315E404B1003E682C /* OptionValueArch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2697A39215E404B1003E682C /* OptionValueArch.cpp */; };
 		2697A39515E404BA003E682C /* OptionValueArch.h in Headers */ = {isa = PBXBuildFile; fileRef = 2697A39415E404BA003E682C /* OptionValueArch.h */; };
 		2697A54D133A6305004E4240 /* PlatformDarwin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2697A54B133A6305004E4240 /* PlatformDarwin.cpp */; };
+		2698699A15E6CBD0002415FF /* OperatingSystemPython.cpp in CopyFiles */ = {isa = PBXBuildFile; fileRef = 2698699815E6CBD0002415FF /* OperatingSystemPython.cpp */; };
+		2698699B15E6CBD0002415FF /* OperatingSystemPython.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2698699815E6CBD0002415FF /* OperatingSystemPython.cpp */; };
+		2698699C15E6CBD0002415FF /* OperatingSystemPython.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 2698699915E6CBD0002415FF /* OperatingSystemPython.h */; };
+		2698699D15E6CBD0002415FF /* OperatingSystemPython.h in Headers */ = {isa = PBXBuildFile; fileRef = 2698699915E6CBD0002415FF /* OperatingSystemPython.h */; };
 		26A527C114E24F5F00F3A14A /* ProcessMachCore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A527BD14E24F5F00F3A14A /* ProcessMachCore.cpp */; };
 		26A527C214E24F5F00F3A14A /* ProcessMachCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 26A527BE14E24F5F00F3A14A /* ProcessMachCore.h */; };
 		26A527C314E24F5F00F3A14A /* ThreadMachCore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A527BF14E24F5F00F3A14A /* ThreadMachCore.cpp */; };
@@ -676,6 +680,8 @@
 			dstSubfolderSpec = 0;
 			files = (
 				AF90106515AB7D3600FF120D /* lldb.1 in CopyFiles */,
+				2698699A15E6CBD0002415FF /* OperatingSystemPython.cpp in CopyFiles */,
+				2698699C15E6CBD0002415FF /* OperatingSystemPython.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 1;
 		};
@@ -993,6 +999,8 @@
 		2697A39415E404BA003E682C /* OptionValueArch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OptionValueArch.h; path = include/lldb/Interpreter/OptionValueArch.h; sourceTree = "<group>"; };
 		2697A54B133A6305004E4240 /* PlatformDarwin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformDarwin.cpp; sourceTree = "<group>"; };
 		2697A54C133A6305004E4240 /* PlatformDarwin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformDarwin.h; sourceTree = "<group>"; };
+		2698699815E6CBD0002415FF /* OperatingSystemPython.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OperatingSystemPython.cpp; sourceTree = "<group>"; };
+		2698699915E6CBD0002415FF /* OperatingSystemPython.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OperatingSystemPython.h; sourceTree = "<group>"; };
 		269FF07D12494F7D00225026 /* FuncUnwinders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FuncUnwinders.h; path = include/lldb/Symbol/FuncUnwinders.h; sourceTree = "<group>"; };
 		269FF07F12494F8E00225026 /* UnwindPlan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnwindPlan.h; path = include/lldb/Symbol/UnwindPlan.h; sourceTree = "<group>"; };
 		269FF08112494FC200225026 /* UnwindTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnwindTable.h; path = include/lldb/Symbol/UnwindTable.h; sourceTree = "<group>"; };
@@ -2262,6 +2270,7 @@
 			isa = PBXGroup;
 			children = (
 				26274F9F14030EEF006BA130 /* Darwin-Kernel */,
+				2698699715E6CBD0002415FF /* Python */,
 			);
 			path = OperatingSystem;
 			sourceTree = "<group>";
@@ -2337,6 +2346,15 @@
 			path = Linux;
 			sourceTree = "<group>";
 		};
+		2698699715E6CBD0002415FF /* Python */ = {
+			isa = PBXGroup;
+			children = (
+				2698699815E6CBD0002415FF /* OperatingSystemPython.cpp */,
+				2698699915E6CBD0002415FF /* OperatingSystemPython.h */,
+			);
+			path = Python;
+			sourceTree = "<group>";
+		};
 		26A3B4AB1181454800381BC2 /* BSD-Archive */ = {
 			isa = PBXGroup;
 			children = (
@@ -3364,6 +3382,7 @@
 				26ACEC2815E077AE00E94760 /* Property.h in Headers */,
 				26491E3B15E1DB8600CBFFC2 /* OptionValueRegex.h in Headers */,
 				2697A39515E404BA003E682C /* OptionValueArch.h in Headers */,
+				2698699D15E6CBD0002415FF /* OperatingSystemPython.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -4081,6 +4100,7 @@
 				2640E19F15DC78FD00F23B50 /* Property.cpp in Sources */,
 				26491E3E15E1DB9F00CBFFC2 /* OptionValueRegex.cpp in Sources */,
 				2697A39315E404B1003E682C /* OptionValueArch.cpp in Sources */,
+				2698699B15E6CBD0002415FF /* OperatingSystemPython.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: lldb/trunk/source/Plugins/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Makefile?rev=162472&r1=162471&r2=162472&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Makefile (original)
+++ lldb/trunk/source/Plugins/Makefile Thu Aug 23 16:17:11 2012
@@ -19,7 +19,8 @@
 	UnwindAssembly/InstEmulation UnwindAssembly/x86 \
 	LanguageRuntime/CPlusPlus/ItaniumABI \
 	LanguageRuntime/ObjC/AppleObjCRuntime \
-	DynamicLoader/POSIX-DYLD
+	DynamicLoader/POSIX-DYLD \
+	OperatingSystem/Python
 
 ifeq ($(HOST_OS),Darwin)
 DIRS += Process/MacOSX-Kernel

Added: lldb/trunk/source/Plugins/OperatingSystem/Python/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/Python/Makefile?rev=162472&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Python/Makefile (added)
+++ lldb/trunk/source/Plugins/OperatingSystem/Python/Makefile Thu Aug 23 16:17:11 2012
@@ -0,0 +1,14 @@
+##==- source/Plugins/OperatingSystem/Darwin-Kernel/Makefile -*- Makefile -*-==##
+# 
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+# 
+##===----------------------------------------------------------------------===##
+
+LLDB_LEVEL := ../../../..
+LIBRARYNAME := lldbPluginOperatingSystemPython
+BUILD_ARCHIVE = 1
+
+include $(LLDB_LEVEL)/Makefile

Added: lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp?rev=162472&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp (added)
+++ lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp Thu Aug 23 16:17:11 2012
@@ -0,0 +1,234 @@
+//===-- OperatingSystemPython.cpp --------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLDB_DISABLE_PYTHON
+
+#include "OperatingSystemPython.h"
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+#include "llvm/ADT/Triple.h"
+
+#include "lldb/Core/ArchSpec.h"
+#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/RegisterValue.h"
+#include "lldb/Core/ValueObjectVariable.h"
+#include "lldb/Symbol/ClangNamespaceDecl.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/StopInfo.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/ThreadList.h"
+#include "lldb/Target/Thread.h"
+#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
+#include "Plugins/Process/Utility/RegisterContextMemory.h"
+#include "Plugins/Process/Utility/ThreadMemory.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+void
+OperatingSystemPython::Initialize()
+{
+    PluginManager::RegisterPlugin (GetPluginNameStatic(),
+                                   GetPluginDescriptionStatic(),
+                                   CreateInstance);
+}
+
+void
+OperatingSystemPython::Terminate()
+{
+    PluginManager::UnregisterPlugin (CreateInstance);
+}
+
+OperatingSystem *
+OperatingSystemPython::CreateInstance (Process *process, bool force)
+{
+    // Python OperatingSystem plug-ins must be requested by name, so force must be true
+    if (force)
+        return new OperatingSystemPython (process);
+    return NULL;
+}
+
+
+const char *
+OperatingSystemPython::GetPluginNameStatic()
+{
+    return "python";
+}
+
+const char *
+OperatingSystemPython::GetPluginDescriptionStatic()
+{
+    return "Operating system plug-in that gathers OS information from a python class that implements the necessary OperatingSystem functionality.";
+}
+
+
+OperatingSystemPython::OperatingSystemPython (lldb_private::Process *process) :
+    OperatingSystem (process),
+    m_thread_list_valobj_sp (),
+    m_register_info_ap ()
+{
+    // TODO: python: create a new python class the implements the necessary
+    // python class that will cache a SBProcess that contains the "process"
+    // argument above and implements:
+    // dict get_thread_info()
+    // dict get_register_info()
+    // Bytes get_register_context_data(SBThread thread)
+}
+
+OperatingSystemPython::~OperatingSystemPython ()
+{
+}
+
+DynamicRegisterInfo *
+OperatingSystemPython::GetDynamicRegisterInfo ()
+{
+    // TODO: python: call get_register_info() on the python object that
+    // represents our instance of the OperatingSystem plug-in
+    
+    // Example code below shows creating a new DynamicRegisterInfo()
+    if (m_register_info_ap.get() == NULL && m_thread_list_valobj_sp)
+    {
+//        static ConstString g_gpr_member_name("gpr");
+//        m_register_info_ap.reset (new DynamicRegisterInfo());
+//        ConstString empty_name;
+//        const bool can_create = true;
+//        AddressType addr_type;
+//        addr_t base_addr = LLDB_INVALID_ADDRESS;
+//        ValueObjectSP gpr_valobj_sp (m_thread_list_valobj_sp->GetChildMemberWithName(GetThreadGPRMemberName (), can_create));
+//        
+//        if (gpr_valobj_sp->IsPointerType ())
+//            base_addr = gpr_valobj_sp->GetPointerValue (&addr_type);
+//        else
+//            base_addr = gpr_valobj_sp->GetAddressOf (true, &addr_type);
+//
+//        ValueObjectSP child_valobj_sp;
+//        if (gpr_valobj_sp)
+//        {
+//            ABI *abi = m_process->GetABI().get();
+//            assert (abi);
+//            uint32_t num_children = gpr_valobj_sp->GetNumChildren();
+//            
+//            ConstString gpr_name (gpr_valobj_sp->GetName());
+//            uint32_t reg_num = 0;
+//            for (uint32_t i=0; i<num_children; ++i)
+//            {
+//                child_valobj_sp = gpr_valobj_sp->GetChildAtIndex(i, can_create);
+//
+//                ConstString reg_name(child_valobj_sp->GetName());
+//                if (reg_name)
+//                {
+//                    const char *reg_name_cstr = reg_name.GetCString();
+//                    while (reg_name_cstr[0] == '_')
+//                        ++reg_name_cstr;
+//                    if (reg_name_cstr != reg_name.GetCString())
+//                        reg_name.SetCString (reg_name_cstr);
+//                }
+//                
+//                RegisterInfo reg_info;
+//                if (abi->GetRegisterInfoByName(reg_name, reg_info))
+//                {
+//                    // Adjust the byte size and the offset to match the layout of registers in our struct
+//                    reg_info.byte_size = child_valobj_sp->GetByteSize();
+//                    reg_info.byte_offset = child_valobj_sp->GetAddressOf(true, &addr_type) - base_addr;
+//                    reg_info.kinds[eRegisterKindLLDB] = reg_num++;
+//                    m_register_info_ap->AddRegister (reg_info, reg_name, empty_name, gpr_name);
+//                }
+//                else
+//                {
+//                    printf ("not able to find register info for %s\n", reg_name.GetCString()); // REMOVE THIS printf before checkin!!!
+//                }
+//            }
+//            
+//            m_register_info_ap->Finalize();
+//        }
+    }
+    assert (m_register_info_ap.get());
+    return m_register_info_ap.get();
+}
+
+//------------------------------------------------------------------
+// PluginInterface protocol
+//------------------------------------------------------------------
+const char *
+OperatingSystemPython::GetPluginName()
+{
+    return "OperatingSystemPython";
+}
+
+const char *
+OperatingSystemPython::GetShortPluginName()
+{
+    return GetPluginNameStatic();
+}
+
+uint32_t
+OperatingSystemPython::GetPluginVersion()
+{
+    return 1;
+}
+
+bool
+OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
+{
+    // TODO: python: call "dict get_thread_info()" on the
+    // python object that represents our instance of the OperatingSystem plug-in
+    // and parse the returned dictionary. We need to pass in the a Dictionary
+    // with the same kind of info we want back so we can reuse old threads, but
+    // only create new ones.
+    
+    // Make any constant strings once and cache the uniqued C string values
+    // so we don't have to rehash them each time through this function call
+//    dict thread_info_dict = python.get_thread_info()
+//    for thread_info in thread_info_dict:
+//    {
+//        ThreadSP thread_sp (old_thread_list.FindThreadByID (tid, false));
+//        if (!thread_sp)
+//            thread_sp.reset (new ThreadMemory (m_process->shared_from_this(), tid, valobj_sp));
+//        new_thread_list.AddThread(thread_sp);
+//    }
+    new_thread_list = old_thread_list;
+    return new_thread_list.GetSize(false) > 0;
+}
+
+void
+OperatingSystemPython::ThreadWasSelected (Thread *thread)
+{
+}
+
+RegisterContextSP
+OperatingSystemPython::CreateRegisterContextForThread (Thread *thread)
+{
+    // TODO: python: call "bytes get_register_context_data(SBThread thread)"
+    // and populate resulting data into thread
+    RegisterContextSP reg_ctx_sp;
+//    bytes b = get_register_context_data(thread)
+//    if (b)
+//    {
+//        reg_ctx_sp.reset (new RegisterContextMemory (*thread, 0, *GetDynamicRegisterInfo (), base_addr));
+//        // set bytes
+//    }
+    return reg_ctx_sp;
+}
+
+StopInfoSP
+OperatingSystemPython::CreateThreadStopReason (lldb_private::Thread *thread)
+{
+    // We should have gotten the thread stop info from the dictionary of data for
+    // the thread in the initial call to get_thread_info(), this should have been
+    // cached so we can return it here
+    StopInfoSP stop_info_sp; //(StopInfo::CreateStopReasonWithSignal (*thread, SIGSTOP));
+    return stop_info_sp;
+}
+
+
+#endif // #ifndef LLDB_DISABLE_PYTHON

Added: lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h?rev=162472&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h (added)
+++ lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h Thu Aug 23 16:17:11 2012
@@ -0,0 +1,89 @@
+//===-- OperatingSystemPython.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_DISABLE_PYTHON
+
+#ifndef liblldb_OperatingSystemPython_h_
+#define liblldb_OperatingSystemPython_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+#include "lldb/Target/OperatingSystem.h"
+
+class DynamicRegisterInfo;
+
+class OperatingSystemPython : public lldb_private::OperatingSystem
+{
+public:
+    //------------------------------------------------------------------
+    // Static Functions
+    //------------------------------------------------------------------
+    static lldb_private::OperatingSystem *
+    CreateInstance (lldb_private::Process *process, bool force);
+    
+    static void
+    Initialize();
+    
+    static void
+    Terminate();
+    
+    static const char *
+    GetPluginNameStatic();
+    
+    static const char *
+    GetPluginDescriptionStatic();
+    
+    //------------------------------------------------------------------
+    // Class Methods
+    //------------------------------------------------------------------
+    OperatingSystemPython (lldb_private::Process *process);
+    
+    virtual
+    ~OperatingSystemPython ();
+    
+    //------------------------------------------------------------------
+    // lldb_private::PluginInterface Methods
+    //------------------------------------------------------------------
+    virtual const char *
+    GetPluginName();
+    
+    virtual const char *
+    GetShortPluginName();
+    
+    virtual uint32_t
+    GetPluginVersion();
+    
+    //------------------------------------------------------------------
+    // lldb_private::OperatingSystem Methods
+    //------------------------------------------------------------------
+    virtual bool
+    UpdateThreadList (lldb_private::ThreadList &old_thread_list, 
+                      lldb_private::ThreadList &new_thread_list);
+    
+    virtual void
+    ThreadWasSelected (lldb_private::Thread *thread);
+
+    virtual lldb::RegisterContextSP
+    CreateRegisterContextForThread (lldb_private::Thread *thread);
+
+    virtual lldb::StopInfoSP
+    CreateThreadStopReason (lldb_private::Thread *thread);
+
+protected:
+    
+    DynamicRegisterInfo *
+    GetDynamicRegisterInfo ();
+
+    lldb::ValueObjectSP m_thread_list_valobj_sp;
+    std::auto_ptr<DynamicRegisterInfo> m_register_info_ap;
+    
+};
+
+#endif // #ifndef liblldb_OperatingSystemPython_h_
+#endif // #ifndef LLDB_DISABLE_PYTHON

Modified: lldb/trunk/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=162472&r1=162471&r2=162472&view=diff
==============================================================================
--- lldb/trunk/source/lldb.cpp (original)
+++ lldb/trunk/source/lldb.cpp Thu Aug 23 16:17:11 2012
@@ -40,6 +40,9 @@
 #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
 #include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
+#ifndef LLDB_DISABLE_PYTHON
+#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
+#endif
 #if defined (__APPLE__)
 #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
 #include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
@@ -105,6 +108,10 @@
         DynamicLoaderPOSIXDYLD::Initialize ();
         PlatformFreeBSD::Initialize();
         PlatformLinux::Initialize();
+#ifndef LLDB_DISABLE_PYTHON
+        OperatingSystemPython::Initialize();
+#endif
+
 #if defined (__APPLE__)
         //----------------------------------------------------------------------
         // Apple/Darwin hosted plugins
@@ -182,6 +189,10 @@
     DynamicLoaderPOSIXDYLD::Terminate ();
     PlatformFreeBSD::Terminate();
     PlatformLinux::Terminate();
+#ifndef LLDB_DISABLE_PYTHON
+    OperatingSystemPython::Terminate();
+#endif
+
 #if defined (__APPLE__)
     DynamicLoaderMacOSXDYLD::Terminate();
     DynamicLoaderDarwinKernel::Terminate();





More information about the lldb-commits mailing list