[Lldb-commits] [lldb] r123398 - in /lldb/trunk/source/Expression: ClangExpressionDeclMap.cpp IRForTarget.cpp

Sean Callanan scallanan at apple.com
Thu Jan 13 13:23:32 PST 2011


Author: spyffe
Date: Thu Jan 13 15:23:32 2011
New Revision: 123398

URL: http://llvm.org/viewvc/llvm-project?rev=123398&view=rev
Log:
Fixed handling of explicitly-declared persistent
variables.

Modified:
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Expression/IRForTarget.cpp

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=123398&r1=123397&r2=123398&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Thu Jan 13 15:23:32 2011
@@ -213,7 +213,7 @@
     TypeFromUser user_type(ClangASTContext::CopyType(context, 
                                                      parser_type.GetASTContext(),
                                                      parser_type.GetOpaqueQualType()),
-                            context);
+                           context);
     
     if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (name, 
                                                                      user_type, 
@@ -939,7 +939,8 @@
                 return false;
             }
             
-            if (var_sp->m_flags & ClangExpressionVariable::EVNeedsFreezeDry)
+            if (var_sp->m_flags & ClangExpressionVariable::EVNeedsFreezeDry ||
+                var_sp->m_flags & ClangExpressionVariable::EVKeepInTarget)
             {
                 mem = var_sp->m_live_sp->GetValue().GetScalar().ULongLong();
                 

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=123398&r1=123397&r2=123398&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Thu Jan 13 15:23:32 2011
@@ -816,6 +816,8 @@
 IRForTarget::RewritePersistentAlloc (llvm::Instruction *persistent_alloc,
                                      llvm::Module &llvm_module)
 {
+    lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+
     AllocaInst *alloc = dyn_cast<AllocaInst>(persistent_alloc);
     
     MDNode *alloc_md = alloc->getMetadata("clang.decl.ptr");
@@ -842,8 +844,8 @@
     if (!m_decl_map->AddPersistentVariable(decl, persistent_variable_name, result_decl_type, false, false))
         return false;
     
-    GlobalVariable *persistent_global = new GlobalVariable(llvm_module, 
-                                                           alloc->getType()->getElementType(),
+    GlobalVariable *persistent_global = new GlobalVariable(llvm_module,
+                                                           alloc->getType(),
                                                            false, /* not constant */
                                                            GlobalValue::ExternalLinkage,
                                                            NULL, /* no initializer */
@@ -861,7 +863,17 @@
     MDNode *persistent_global_md = MDNode::get(llvm_module.getContext(), values, 2);
     named_metadata->addOperand(persistent_global_md);
     
-    alloc->replaceAllUsesWith(persistent_global);
+    // Now, since the variable is a pointer variable, we will drop in a load of that
+    // pointer variable.
+    
+    LoadInst *persistent_load = new LoadInst (persistent_global, "", alloc);
+    
+    if (log)
+        log->Printf("Replacing \"%s\" with \"%s\"",
+                    PrintValue(alloc).c_str(),
+                    PrintValue(persistent_load).c_str());
+    
+    alloc->replaceAllUsesWith(persistent_load);
     alloc->eraseFromParent();
     
     return true;
@@ -1006,7 +1018,7 @@
         clang::QualType qual_type;
         const Type *value_type;
         
-        if (!name.compare("$__lldb_expr_result"))
+        if (name[0] == '$')
         {
             // The $__lldb_expr_result name indicates the the return value has allocated as
             // a static variable.  Per the comment at ASTResultSynthesizer::SynthesizeBodyResult,
@@ -1015,6 +1027,8 @@
             //
             // Consequently, when reporting the size of the type, we report a pointer type pointing
             // to the type of $__lldb_expr_result, not the type itself.
+            //
+            // We also do this for any user-declared persistent variables.
             
             qual_type = ast_context->getPointerType(clang::QualType::getFromOpaquePtr(opaque_type));
             value_type = PointerType::get(global_variable->getType(), 0);
@@ -1029,7 +1043,7 @@
         off_t value_alignment = (ast_context->getTypeAlign(qual_type) + 7) / 8;
         
         if (log)
-            log->Printf("Type of \"%s\" is [clang \"%s\", lldb \"%s\"] [size %d, align %d]", 
+            log->Printf("Type of \"%s\" is [clang \"%s\", llvm \"%s\"] [size %d, align %d]", 
                         name.c_str(), 
                         qual_type.getAsString().c_str(), 
                         PrintType(value_type).c_str(), 





More information about the lldb-commits mailing list