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

Sean Callanan scallanan at apple.com
Thu Sep 30 14:18:25 PDT 2010


Author: spyffe
Date: Thu Sep 30 16:18:25 2010
New Revision: 115208

URL: http://llvm.org/viewvc/llvm-project?rev=115208&view=rev
Log:
Switched the expression parser from using TargetData
to using Clang to get type sizes.  This fixes a bug
where the type size for a double[2] was being wrongly
reported as 8 instead of 16 bytes, causing problems
for IRForTarget.

Also improved logging so that the next bug in this
area will be easier to find.

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

Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=115208&r1=115207&r2=115208&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (original)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Thu Sep 30 16:18:25 2010
@@ -19,7 +19,6 @@
     class Function;
     class Instruction;
     class Module;
-    class TargetData;
     class Value;
 }
 
@@ -52,11 +51,6 @@
     ///     for use in looking up globals and allocating the argument
     ///     struct.  See the documentation for ClangExpressionDeclMap.
     ///
-    /// @param[in] target_data
-    ///     The data layout information for the target.  This information is
-    ///     used to determine the sizes of types that have been lowered into
-    ///     IR types.
-    ///
     /// @param[in] func_name
     ///     The name of the function to prepare for execution in the target.
     ///
@@ -66,7 +60,6 @@
     ///     are resolved.
     //------------------------------------------------------------------
     IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map,
-                const llvm::TargetData *target_data,
                 bool resolve_vars,
                 const char* func_name = "___clang_expr");
     
@@ -305,7 +298,6 @@
     
     std::string                             m_func_name;            ///< The name of the function to translate
     lldb_private::ClangExpressionDeclMap   *m_decl_map;             ///< The DeclMap containing the Decls 
-    const llvm::TargetData                 *m_target_data;          ///< The TargetData for use in determining type sizes
     llvm::Constant                         *m_sel_registerName;     ///< The address of the function sel_registerName, cast to the appropriate function pointer type
 };
 

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=115208&r1=115207&r2=115208&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Thu Sep 30 16:18:25 2010
@@ -436,21 +436,7 @@
     
     if (decl_map)
     {
-        std::string target_error;
-        
-        const llvm::Target *target = llvm::TargetRegistry::lookupTarget(m_target_triple, target_error);
-        
-        if (!target)
-        {
-            err.SetErrorToGenericError();
-            err.SetErrorStringWithFormat("Couldn't find a target for %s", m_target_triple.c_str());
-            return err;
-        }
-        
-        std::auto_ptr<llvm::TargetMachine> target_machine(target->createTargetMachine(m_target_triple, ""));
-        
         IRForTarget ir_for_target(decl_map, 
-                                  target_machine->getTargetData(),
                                   m_expr.NeedsVariableResolution(),
                                   function_name.c_str());
         

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=115208&r1=115207&r2=115208&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Thu Sep 30 16:18:25 2010
@@ -32,22 +32,20 @@
 static char ID;
 
 IRForTarget::IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map,
-                         const TargetData *target_data,
                          bool resolve_vars,
                          const char *func_name) :
     ModulePass(ID),
     m_decl_map(decl_map),
-    m_target_data(target_data),
     m_sel_registerName(NULL),
     m_func_name(func_name),
     m_resolve_vars(resolve_vars)
 {
 }
 
-/* A handy utility function used at several places in the code */
+/* Handy utility functions used at several places in the code */
 
 static std::string 
-PrintValue(Value *V, bool truncate = false)
+PrintValue(const Value *V, bool truncate = false)
 {
     std::string s;
     raw_string_ostream rso(s);
@@ -58,6 +56,18 @@
     return s;
 }
 
+static std::string
+PrintType(const Type *T, bool truncate = false)
+{
+    std::string s;
+    raw_string_ostream rso(s);
+    T->print(rso);
+    rso.flush();
+    if (truncate)
+        s.resize(s.length() - 1);
+    return s;
+}
+
 IRForTarget::~IRForTarget()
 {
 }
@@ -578,23 +588,34 @@
         
         std::string name = named_decl->getName().str();
         
-        void *qual_type = NULL;
+        void *opaque_type = NULL;
         clang::ASTContext *ast_context = NULL;
         
         if (clang::ValueDecl *value_decl = dyn_cast<clang::ValueDecl>(named_decl))
         {
-            qual_type = value_decl->getType().getAsOpaquePtr();
+            opaque_type = value_decl->getType().getAsOpaquePtr();
             ast_context = &value_decl->getASTContext();
         }
         else
         {
             return false;
         }
+        
+        clang::QualType qual_type(clang::QualType::getFromOpaquePtr(opaque_type));
             
         const Type *value_type = global_variable->getType();
-        
-        size_t value_size = m_target_data->getTypeStoreSize(value_type);
-        off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type);
+                
+        size_t value_size = (ast_context->getTypeSize(qual_type) + 7) / 8;
+        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]", 
+                        name.c_str(), 
+                        qual_type.getAsString().c_str(), 
+                        PrintType(value_type).c_str(), 
+                        value_size, 
+                        value_alignment);
+
         
         if (named_decl && !m_decl_map->AddValueToStruct(named_decl,
                                                         name.c_str(),
@@ -1103,6 +1124,13 @@
             return false;
     }
     
+    ///////////////////////////////
+    // Run function-level passes
+    //
+    
+    if (!replaceVariables(M, *function))
+        return false;
+    
     if (log)
     {
         std::string s;
@@ -1115,13 +1143,6 @@
         log->Printf("Module after preparing for execution: \n%s", s.c_str());
     }
     
-    ///////////////////////////////
-    // Run function-level passes
-    //
-    
-    if (!replaceVariables(M, *function))
-        return false;
-    
     return true;    
 }
 





More information about the lldb-commits mailing list