hanchenye-llvm-project/lldb/source/Symbol/ClangASTImporter.cpp

201 lines
5.8 KiB
C++
Raw Normal View History

//===-- ClangASTImporter.cpp ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangASTImporter.h"
#include "lldb/Symbol/ClangNamespaceDecl.h"
using namespace lldb_private;
using namespace clang;
clang::QualType
ClangASTImporter::CopyType (clang::ASTContext *src_ast,
clang::QualType type)
{
MinionSP minion_sp (GetMinion(src_ast, false));
if (minion_sp)
return minion_sp->Import(type);
return QualType();
}
clang::Decl *
ClangASTImporter::CopyDecl (clang::ASTContext *src_ast,
clang::Decl *decl)
{
MinionSP minion_sp;
if (isa<clang::NamespaceDecl>(decl))
minion_sp = GetMinion(src_ast, true);
else
minion_sp = GetMinion(src_ast, false);
if (minion_sp)
{
clang::Decl *result = minion_sp->Import(decl);
if (!result)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
if (log)
{
if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s '%s'", decl->getDeclKindName(), named_decl->getNameAsString().c_str());
else
log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s", decl->getDeclKindName());
}
}
return result;
}
return NULL;
}
void
ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
DeclOrigin decl_origin = GetDeclOrigin(decl);
if (!decl_origin.Valid())
return;
if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
return;
MinionSP minion_sp (GetMinion(decl_origin.ctx, false));
if (minion_sp)
minion_sp->ImportDefinition(decl_origin.decl);
return;
}
void
ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
if (!decl_origin.Valid())
return;
if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
return;
MinionSP minion_sp (GetMinion(decl_origin.ctx, false));
if (minion_sp)
minion_sp->ImportDefinition(decl_origin.decl);
return;
}
void
ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
NamespaceMapSP &namespace_map)
{
m_namespace_maps[decl] = namespace_map;
}
ClangASTImporter::NamespaceMapSP
ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
{
NamespaceMetaMap::iterator iter = m_namespace_maps.find(decl);
if (iter != m_namespace_maps.end())
return iter->second;
else
return NamespaceMapSP();
}
void
ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
{
const DeclContext *parent_context = decl->getDeclContext();
const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
NamespaceMapSP parent_map;
if (parent_namespace)
parent_map = GetNamespaceMap(parent_namespace);
NamespaceMapSP new_map;
new_map.reset(new NamespaceMap);
if (m_map_completer)
{
std::string namespace_string = decl->getDeclName().getAsString();
m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
}
RegisterNamespaceMap (decl, new_map);
}
ClangASTImporter::NamespaceMapCompleter::~NamespaceMapCompleter ()
{
return;
}
clang::Decl
*ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
m_master.m_origins[to] = DeclOrigin (m_source_ctx, from);
if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
{
TagDecl *to_tag_decl = dyn_cast<TagDecl>(to);
to_tag_decl->setHasExternalLexicalStorage();
if (log)
log->Printf(" [ClangASTImporter] Imported %p, a %s named %s%s%s [%s->%s]",
to,
((clang::Decl*)from_tag_decl)->getDeclKindName(),
from_tag_decl->getName().str().c_str(),
(to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
(to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""),
(from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"),
(to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
}
if (isa<NamespaceDecl>(from))
{
NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to);
m_master.BuildNamespaceMap(to_namespace_decl);
to_namespace_decl->setHasExternalVisibleStorage();
}
if (isa<ObjCInterfaceDecl>(from))
{
ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);
to_interface_decl->setHasExternalVisibleStorage();
This patch modifies the expression parser to allow it to execute expressions even in the absence of a process. This allows expressions to run in situations where the target cannot run -- e.g., to perform calculations based on type information, or to inspect a binary's static data. This modification touches the following files: lldb-private-enumerations.h Introduce a new enum specifying the policy for processing an expression. Some expressions should always be JITted, for example if they are functions that will be used over and over again. Some expressions should always be interpreted, for example if the target is unsafe to run. For most, it is acceptable to JIT them, but interpretation is preferable when possible. Target.[h,cpp] Have EvaluateExpression now accept the new enum. ClangExpressionDeclMap.[cpp,h] Add support for the IR interpreter and also make the ClangExpressionDeclMap more robust in the absence of a process. ClangFunction.[cpp,h] Add support for the new enum. IRInterpreter.[cpp,h] New implementation. ClangUserExpression.[cpp,h] Add support for the new enum, and for running expressions in the absence of a process. ClangExpression.h Remove references to the old DWARF-based method of evaluating expressions, because it has been superseded for now. ClangUtilityFunction.[cpp,h] Add support for the new enum. ClangExpressionParser.[cpp,h] Add support for the new enum, remove references to DWARF, and add support for checking whether the expression could be evaluated statically. IRForTarget.[h,cpp] Add support for the new enum, and add utility functions to support the interpreter. IRToDWARF.cpp Removed CommandObjectExpression.cpp Remove references to the obsolete -i option. Process.cpp Modify calls to ClangUserExpression::Evaluate to pass the correct enum (for dlopen/dlclose) SBValue.cpp Add support for the new enum. SBFrame.cpp Add support for he new enum. BreakpointOptions.cpp Add support for the new enum. llvm-svn: 139772
2011-09-15 10:13:07 +08:00
if (!to_interface_decl->isForwardDecl())
to_interface_decl->setExternallyCompleted();
}
return clang::ASTImporter::Imported(from, to);
While tracking down memory consumption issue a few things were needed: the ability to dump more information about modules in "target modules list". We can now dump the shared pointer reference count for modules, the pointer to the module itself (in case performance tools can help track down who has references to said pointer), and the modification time. Added "target delete [target-idx ...]" to be able to delete targets when they are no longer needed. This will help track down memory usage issues and help to resolve when module ref counts keep getting incremented. If the command gets no arguments, the currently selected target will be deleted. If any arguments are given, they must all be valid target indexes (use the "target list" command to get the current target indexes). Took care of a bunch of "no newline at end of file" warnings. TimeValue objects can now dump their time to a lldb_private::Stream object. Modified the "target modules list --global" command to not error out if there are no targets since it doesn't require a target. Fixed an issue in the MacOSX DYLD dynamic loader plug-in where if a shared library was updated on disk, we would keep using the older one, even if it was updated. Don't allow the ModuleList::GetSharedModule(...) to return an empty module. Previously we could specify a valid path on disc to a module, and specify an architecture that wasn't contained in that module and get a shared pointer to a module that wouldn't be able to return an object file or a symbol file. We now make sure an object file can be extracted prior to adding the shared pointer to the module to get added to the shared list. llvm-svn: 137196
2011-08-10 10:10:13 +08:00
}