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

Sean Callanan scallanan at apple.com
Tue Jun 22 16:46:25 PDT 2010


Author: spyffe
Date: Tue Jun 22 18:46:24 2010
New Revision: 106606

URL: http://llvm.org/viewvc/llvm-project?rev=106606&view=rev
Log:
Added support to the expression parser for locating
externally-defined functions.

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

Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=106606&r1=106605&r2=106606&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Tue Jun 22 18:46:24 2010
@@ -60,6 +60,7 @@
     
     clang::ASTContext *GetASTContext();
     clang::NamedDecl *AddVarDecl(void *type);
+    clang::NamedDecl *AddFunDecl(void *type);
 };
 
 }

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=106606&r1=106605&r2=106606&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Tue Jun 22 18:46:24 2010
@@ -29,6 +29,7 @@
 
 namespace lldb_private {
 
+class Function;
 class NameSearchContext;
 class Variable;
     
@@ -63,7 +64,8 @@
     ExecutionContext   *m_exe_ctx;
     SymbolContext      *m_sym_ctx; /* owned by ClangExpressionDeclMap */
     
-    void AddOneVariable(NameSearchContext &context, Variable* var);
+    void AddOneVariable(NameSearchContext &context, Variable *var);
+    void AddOneFunction(NameSearchContext &context, Function *fun);
 };
     
 } // namespace lldb_private

Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=106606&r1=106605&r2=106606&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Tue Jun 22 18:46:24 2010
@@ -97,3 +97,50 @@
     
     return Decl;
 }
+
+clang::NamedDecl *NameSearchContext::AddFunDecl(void *type) {
+    clang::FunctionDecl *Decl = FunctionDecl::Create(ASTSource.Context,
+                                                     const_cast<DeclContext*>(DC),
+                                                     SourceLocation(),
+                                                     Name.getAsIdentifierInfo(),
+                                                     QualType::getFromOpaquePtr(type),
+                                                     NULL,
+                                                     FunctionDecl::Static,
+                                                     FunctionDecl::Static,
+                                                     false,
+                                                     true);
+    
+    QualType QT = QualType::getFromOpaquePtr(type);
+    clang::Type *T = QT.getTypePtr();
+    
+    if (T->isFunctionProtoType())
+    {
+        FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(T);
+        
+        unsigned NumArgs = FPT->getNumArgs();
+        unsigned ArgIndex;
+        
+        ParmVarDecl *ParmVarDecls[NumArgs];
+        
+        for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
+        {
+            QualType ArgQT = FPT->getArgType(ArgIndex);
+            
+            ParmVarDecls[ArgIndex] = ParmVarDecl::Create(ASTSource.Context,
+                                                         const_cast<DeclContext*>(DC),
+                                                         SourceLocation(),
+                                                         NULL,
+                                                         ArgQT,
+                                                         NULL,
+                                                         ParmVarDecl::Static,
+                                                         ParmVarDecl::Static,
+                                                         NULL);
+        }
+        
+        Decl->setParams(ParmVarDecls, NumArgs);
+    }
+    
+    Decls.push_back(Decl);
+    
+    return Decl;
+}

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=106606&r1=106605&r2=106606&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Tue Jun 22 18:46:24 2010
@@ -115,6 +115,13 @@
     
     ConstString name_cs(name);
     
+    Function *fn = m_sym_ctx->FindFunctionByName(name_cs.GetCString());
+    
+    if (fn)
+    {
+        AddOneFunction(context, fn);
+    }
+    
     for (current_block_id = block->GetID();
          current_block_id != Block::InvalidID;
          current_block_id = blocks.GetParent(current_block_id))
@@ -167,7 +174,7 @@
     
     if (!var_type) 
     {
-        DEBUG_PRINTF("Skipped a definition for %s because it has no type\n", name);
+        DEBUG_PRINTF("Skipped a definition because it has no type\n");
         return;
     }
     
@@ -175,7 +182,7 @@
     
     if (!var_opaque_type)
     {
-        DEBUG_PRINTF("Skipped a definition for %s because it has no Clang type\n", name);
+        DEBUG_PRINTF("Skipped a definition because it has no Clang type\n");
         return;
     }
     
@@ -185,7 +192,7 @@
     
     if (!type_list)
     {
-        DEBUG_PRINTF("Skipped a definition for %s because the type has no associated type list\n", name);
+        DEBUG_PRINTF("Skipped a definition because the type has no associated type list\n");
         return;
     }
     
@@ -203,7 +210,7 @@
     
     if (!var_location_expr.Evaluate(m_exe_ctx, exe_ast_ctx, NULL, *var_location.get(), &err))
     {
-        DEBUG_PRINTF("Error evaluating the location of %s: %s\n", name, err.AsCString());
+        DEBUG_PRINTF("Error evaluating location: %s\n", err.AsCString());
         return;
     }
     
@@ -242,5 +249,47 @@
     
     m_tuples.push_back(tuple);
     
-    DEBUG_PRINTF("Found for a definition for %s\n", name);    
+    DEBUG_PRINTF("Found variable\n");    
+}
+
+void
+ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
+                                       Function* fun)
+{
+    Type *fun_type = fun->GetType();
+    
+    if (!fun_type) 
+    {
+        DEBUG_PRINTF("Skipped a function because it has no type\n");
+        return;
+    }
+    
+    void *fun_opaque_type = fun_type->GetOpaqueClangQualType();
+    
+    if (!fun_opaque_type)
+    {
+        DEBUG_PRINTF("Skipped a function because it has no Clang type\n");
+        return;
+    }
+    
+    std::auto_ptr<Value> fun_location(new Value);
+    
+    const Address &fun_address = fun->GetAddressRange().GetBaseAddress();
+    lldb::addr_t load_addr = fun_address.GetLoadAddress(m_exe_ctx->process);
+    fun_location->SetValueType(Value::eValueTypeLoadAddress);
+    fun_location->GetScalar() = load_addr;
+    
+    TypeList *type_list = fun_type->GetTypeList();
+    void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), type_list->GetClangASTContext().getASTContext(), fun_opaque_type);
+    
+    NamedDecl *fun_decl = context.AddFunDecl(copied_type);
+    
+    Tuple tuple;
+    
+    tuple.m_decl  = fun_decl;
+    tuple.m_value = fun_location.release();
+    
+    m_tuples.push_back(tuple);
+    
+    DEBUG_PRINTF("Found function\n");    
 }





More information about the lldb-commits mailing list