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

Sean Callanan scallanan at apple.com
Mon Aug 30 15:17:17 PDT 2010


Author: spyffe
Date: Mon Aug 30 17:17:16 2010
New Revision: 112540

URL: http://llvm.org/viewvc/llvm-project?rev=112540&view=rev
Log:
Fixed a bug where the parser-specific members of
persistent variables were staying around too long.
This caused the following problem:

- A persistent result variable is created for the
  result of an expression.  The pointer to the
  corresponding Decl is stored in the variable.

- The persistent variable is looked up during
  struct generation (correctly) using its Decl.

- Another expression defines a new result variable
  which happens to have a Decl in the same place
  as the original result variable.

- The persistent variable is looked up during
  struct generation using its Decl, but the old
  result variable appears first in the list and
  has the same Decl pointer.

The fix is to destroy parser-specific data when
it is no longer valid.

Also improved some logging as I diagnosed the
bug.

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

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=112540&r1=112539&r2=112540&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Mon Aug 30 17:17:16 2010
@@ -117,6 +117,9 @@
     /// @param[in] decl
     ///     The Clang declaration for the variable.
     ///
+    /// @param[in] name
+    ///     The name of the variable.
+    ///
     /// @param[in] value
     ///     The LLVM IR value for this variable.
     ///
@@ -130,6 +133,7 @@
     ///     True on success; false otherwise.
     //------------------------------------------------------------------
     bool AddValueToStruct (const clang::NamedDecl *decl,
+                           const char *name,
                            llvm::Value *value,
                            size_t size,
                            off_t alignment);
@@ -185,6 +189,9 @@
     ///     As long as the struct is aligned according to its required
     ///     alignment, this offset will align the field correctly.
     ///
+    /// @param[out] name
+    ///     The name of the field as used in materialization.
+    ///
     /// @param[in] index
     ///     The index of the field about which information is requested.
     ///
@@ -194,6 +201,7 @@
     bool GetStructElement (const clang::NamedDecl *&decl,
                            llvm::Value *&value,
                            off_t &offset,
+                           const char *&name,
                            uint32_t index);
     
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=112540&r1=112539&r2=112540&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Mon Aug 30 17:17:16 2010
@@ -60,6 +60,16 @@
         if (entity.m_parser_vars.get() &&
             entity.m_parser_vars->m_lldb_value)
             delete entity.m_parser_vars->m_lldb_value;
+        
+        entity.DisableParserVars();
+    }
+    
+    for (uint64_t pvar_index = 0, num_pvars = m_persistent_vars->Size();
+         pvar_index < num_pvars;
+         ++pvar_index)
+    {
+        ClangExpressionVariable &pvar(m_persistent_vars->VariableAtIndex(pvar_index));
+        pvar.DisableParserVars();
     }
     
     if (m_sym_ctx)
@@ -106,10 +116,13 @@
 
 bool 
 ClangExpressionDeclMap::AddValueToStruct (const clang::NamedDecl *decl,
+                                          const char *name,
                                           llvm::Value *value,
                                           size_t size,
                                           off_t alignment)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+    
     m_struct_laid_out = false;
     
     if (m_struct_members.GetVariable(decl))
@@ -123,6 +136,12 @@
     if (!var)
         return false;
     
+    if (log)
+        log->Printf("Adding value for decl %p [%s - %s] to the structure",
+                    decl,
+                    name,
+                    var->m_name.c_str());
+    
     // We know entity->m_parser_vars is valid because we used a parser variable
     // to find it
     var->m_parser_vars->m_llvm_value = value;
@@ -190,6 +209,7 @@
 ClangExpressionDeclMap::GetStructElement (const clang::NamedDecl *&decl,
                                           llvm::Value *&value,
                                           off_t &offset,
+                                          const char *&name,
                                           uint32_t index)
 {
     if (!m_struct_laid_out)
@@ -207,6 +227,7 @@
     decl = member.m_parser_vars->m_named_decl;
     value = member.m_parser_vars->m_llvm_value;
     offset = member.m_jit_vars->m_offset;
+    name = member.m_name.c_str();
         
     return true;
 }
@@ -427,17 +448,20 @@
         }
         else if (persistent_variable)
         {
-            if (!member.m_name.compare(m_result_name) && !dematerialize)
-                continue;
+            if (!member.m_name.compare(m_result_name))
+            {
+                if (!dematerialize)
+                    continue;
                 
-            if (dematerialize)
-            {                
                 if (log)
                     log->PutCString("Found result member in the struct");
-                    
+                
                 *result = &member;
             }
             
+            if (log)
+                log->Printf("Searched for persistent variable %s and found %s", member.m_name.c_str(), persistent_variable->m_name.c_str());
+            
             if (!DoMaterializeOnePersistentVariable(dematerialize, *exe_ctx, persistent_variable->m_name.c_str(), m_materialized_location + member.m_jit_vars->m_offset, err))
                 return false;
         }
@@ -457,12 +481,7 @@
                                                            const char *name,
                                                            lldb::addr_t addr,
                                                            Error &err)
-{
-    Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
-
-    if (log)
-        log->Printf("Found persistent variable %s", name);
-    
+{    
     ClangExpressionVariable *pvar(m_persistent_vars->GetVariable(name));
     
     if (!pvar)
@@ -883,6 +902,8 @@
 ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
                                        ClangExpressionVariable *pvar)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+    
     TypeFromUser user_type = pvar->m_user_type;
     
     TypeFromParser parser_type(ClangASTContext::CopyType(context.GetASTContext(), 
@@ -897,6 +918,9 @@
     pvar->m_parser_vars->m_named_decl  = var_decl;
     pvar->m_parser_vars->m_llvm_value  = NULL;
     pvar->m_parser_vars->m_lldb_value  = NULL;
+    
+    if (log)
+        log->Printf("Added pvar %s, returned (NamedDecl)%p", pvar->m_name.c_str(), var_decl);  
 }
 
 void

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=112540&r1=112539&r2=112540&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Mon Aug 30 17:17:16 2010
@@ -529,6 +529,7 @@
         off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type);
         
         if (named_decl && !m_decl_map->AddValueToStruct(named_decl,
+                                                        name.c_str(),
                                                         V,
                                                         value_size, 
                                                         value_alignment))
@@ -881,13 +882,15 @@
         const clang::NamedDecl *decl;
         Value *value;
         off_t offset;
+        const char *name;
         
-        if (!m_decl_map->GetStructElement (decl, value, offset, element_index))
+        if (!m_decl_map->GetStructElement (decl, value, offset, name, element_index))
             return false;
         
         if (log)
-            log->Printf("  %s (%s) placed at %d",
+            log->Printf("  %s [%s] (%s) placed at %d",
                         value->getName().str().c_str(),
+                        name,
                         PrintValue(value, true).c_str(),
                         offset);
         





More information about the lldb-commits mailing list