[Lldb-commits] [lldb] r179539 - Audited the existing Materializer code to ensure

Sean Callanan scallanan at apple.com
Mon Apr 15 10:12:48 PDT 2013


Author: spyffe
Date: Mon Apr 15 12:12:47 2013
New Revision: 179539

URL: http://llvm.org/viewvc/llvm-project?rev=179539&view=rev
Log:
Audited the existing Materializer code to ensure
that it works in the absence of a process.  Codepaths
in the Materializer now use the best execution context
scope available to them.

Modified:
    lldb/trunk/include/lldb/Expression/IRExecutionUnit.h
    lldb/trunk/include/lldb/Expression/IRMemoryMap.h
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Expression/IRExecutionUnit.cpp
    lldb/trunk/source/Expression/IRMemoryMap.cpp
    lldb/trunk/source/Expression/Materializer.cpp

Modified: lldb/trunk/include/lldb/Expression/IRExecutionUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRExecutionUnit.h?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRExecutionUnit.h (original)
+++ lldb/trunk/include/lldb/Expression/IRExecutionUnit.h Mon Apr 15 12:12:47 2013
@@ -66,7 +66,7 @@ public:
     //------------------------------------------------------------------
     IRExecutionUnit (std::auto_ptr<llvm::Module> &module_ap,
                      ConstString &name,
-                     lldb::ProcessSP process_sp,
+                     const lldb::TargetSP &target_sp,
                      std::vector<std::string> &cpu_features);
     
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Expression/IRMemoryMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRMemoryMap.h?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRMemoryMap.h (original)
+++ lldb/trunk/include/lldb/Expression/IRMemoryMap.h Mon Apr 15 12:12:47 2013
@@ -37,7 +37,6 @@ namespace lldb_private
 class IRMemoryMap
 {
 public:
-    IRMemoryMap (lldb::ProcessSP process_sp);
     IRMemoryMap (lldb::TargetSP target_sp);
     ~IRMemoryMap ();
     
@@ -64,9 +63,12 @@ public:
     lldb::ByteOrder GetByteOrder();
     uint32_t GetAddressByteSize();
     
+    // This function can return NULL.
     ExecutionContextScope *GetBestExecutionContextScope();
 
 protected:
+    // This function should only be used if you know you are using the JIT.
+    // Any other cases should use GetBestExecutionContextScope().
     lldb::ProcessWP GetProcessWP ()
     {
         return m_process_wp;

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Mon Apr 15 12:12:47 2013
@@ -503,7 +503,7 @@ ClangExpressionParser::PrepareForExecuti
     
     m_execution_unit.reset(new IRExecutionUnit(module_ap, // handed off here
                                                function_name,
-                                               exe_ctx.GetProcessSP(),
+                                               exe_ctx.GetTargetSP(),
                                                m_compiler->getTargetOpts().Features));
         
     ClangExpressionDeclMap *decl_map = m_expr.DeclMap(); // result can be NULL

Modified: lldb/trunk/source/Expression/IRExecutionUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRExecutionUnit.cpp?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRExecutionUnit.cpp (original)
+++ lldb/trunk/source/Expression/IRExecutionUnit.cpp Mon Apr 15 12:12:47 2013
@@ -27,9 +27,9 @@ using namespace lldb_private;
 
 IRExecutionUnit::IRExecutionUnit (std::auto_ptr<llvm::Module> &module_ap,
                                   ConstString &name,
-                                  lldb::ProcessSP process_sp,
+                                  const lldb::TargetSP &target_sp,
                                   std::vector<std::string> &cpu_features) :
-    IRMemoryMap(process_sp),
+    IRMemoryMap(target_sp),
     m_module_ap(module_ap),
     m_module(m_module_ap.get()),
     m_cpu_features(cpu_features),

Modified: lldb/trunk/source/Expression/IRMemoryMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRMemoryMap.cpp?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRMemoryMap.cpp (original)
+++ lldb/trunk/source/Expression/IRMemoryMap.cpp Mon Apr 15 12:12:47 2013
@@ -18,16 +18,11 @@
 
 using namespace lldb_private;
 
-IRMemoryMap::IRMemoryMap (lldb::ProcessSP process_sp) :
-    m_process_wp(process_sp),
-    m_target_wp(process_sp->GetTarget().shared_from_this())
-{
-}
-
 IRMemoryMap::IRMemoryMap (lldb::TargetSP target_sp) :
-    m_process_wp(),
     m_target_wp(target_sp)
 {
+    if (target_sp)
+        m_process_wp = target_sp->GetProcessSP();
 }
 
 IRMemoryMap::~IRMemoryMap ()

Modified: lldb/trunk/source/Expression/Materializer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/Materializer.cpp?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- lldb/trunk/source/Expression/Materializer.cpp (original)
+++ lldb/trunk/source/Expression/Materializer.cpp Mon Apr 15 12:12:47 2013
@@ -340,7 +340,12 @@ public:
                         m_variable_sp->GetName().AsCString());
         }
         
-        lldb::ValueObjectSP valobj_sp = ValueObjectVariable::Create(frame_sp.get(), m_variable_sp);
+        ExecutionContextScope *scope = frame_sp.get();
+        
+        if (!scope)
+            scope = map.GetBestExecutionContextScope();
+        
+        lldb::ValueObjectSP valobj_sp = ValueObjectVariable::Create(scope, m_variable_sp);
         
         if (!valobj_sp)
         {
@@ -458,7 +463,12 @@ public:
         
         if (m_temporary_allocation != LLDB_INVALID_ADDRESS)
         {
-            lldb::ValueObjectSP valobj_sp = ValueObjectVariable::Create(frame_sp.get(), m_variable_sp);
+            ExecutionContextScope *scope = frame_sp.get();
+            
+            if (!scope)
+                scope = map.GetBestExecutionContextScope();
+            
+            lldb::ValueObjectSP valobj_sp = ValueObjectVariable::Create(scope, m_variable_sp);
             
             if (!valobj_sp)
             {
@@ -665,6 +675,17 @@ Materializer::Materializer () :
 Materializer::Dematerializer
 Materializer::Materialize (lldb::StackFrameSP &frame_sp, lldb::ClangExpressionVariableSP &result_sp, IRMemoryMap &map, lldb::addr_t process_address, Error &error)
 {
+    ExecutionContextScope *exe_scope = frame_sp.get();
+    
+    if (!exe_scope)
+        exe_scope = map.GetBestExecutionContextScope();
+    
+    if (!exe_scope)
+    {
+        error.SetErrorToGenericError();
+        error.SetErrorString("Couldn't dematerialize: target doesn't exist");
+    }
+    
     for (EntityUP &entity_up : m_entities)
     {
         entity_up->Materialize(frame_sp, map, process_address, error);
@@ -683,10 +704,12 @@ Materializer::Dematerializer::Dematerial
 {
     lldb::StackFrameSP frame_sp = m_frame_wp.lock();
     
-    if (!frame_sp)
+    ExecutionContextScope *exe_scope = m_map.GetBestExecutionContextScope();
+    
+    if (!exe_scope)
     {
         error.SetErrorToGenericError();
-        error.SetErrorString("Couldn't dematerialize: frame is gone");
+        error.SetErrorString("Couldn't dematerialize: target is gone");
     }
     else
     {





More information about the lldb-commits mailing list