mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-13 19:24:21 +00:00
Deserialize Clang module search path from DWARF
This patch properly extracts the full submodule path as well as its search paths from DWARF import decls and passes it on to the ClangModulesDeclVendor. rdar://problem/47970144 Differential Revision: https://reviews.llvm.org/D58090 llvm-svn: 353961
This commit is contained in:
parent
7a290dfe30
commit
0f30a3b68f
@ -266,7 +266,7 @@ public:
|
|||||||
/// @return
|
/// @return
|
||||||
/// A list of imported module names.
|
/// A list of imported module names.
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
const std::vector<ConstString> &GetImportedModules();
|
const std::vector<SourceModule> &GetImportedModules();
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
/// Get the SymbolFile plug-in user data.
|
/// Get the SymbolFile plug-in user data.
|
||||||
@ -414,28 +414,29 @@ public:
|
|||||||
size_t GetNumFunctions() const { return m_functions_by_uid.size(); }
|
size_t GetNumFunctions() const { return m_functions_by_uid.size(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void *m_user_data; ///< User data for the SymbolFile parser to store
|
/// User data for the SymbolFile parser to store information into.
|
||||||
///information into.
|
void *m_user_data;
|
||||||
lldb::LanguageType
|
/// The programming language enumeration value.
|
||||||
m_language; ///< The programming language enumeration value.
|
lldb::LanguageType m_language;
|
||||||
Flags m_flags; ///< Compile unit flags that help with partial parsing.
|
/// Compile unit flags that help with partial parsing.
|
||||||
|
Flags m_flags;
|
||||||
/// Maps UIDs to functions.
|
/// Maps UIDs to functions.
|
||||||
llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions_by_uid;
|
llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions_by_uid;
|
||||||
std::vector<ConstString> m_imported_modules; ///< All modules, including the
|
/// All modules, including the current module, imported by this
|
||||||
///current module, imported by
|
/// compile unit.
|
||||||
///this
|
std::vector<SourceModule> m_imported_modules;
|
||||||
///< compile unit.
|
/// Files associated with this compile unit's line table and
|
||||||
FileSpecList m_support_files; ///< Files associated with this compile unit's
|
/// declarations.
|
||||||
///line table and declarations.
|
FileSpecList m_support_files;
|
||||||
std::unique_ptr<LineTable>
|
/// Line table that will get parsed on demand.
|
||||||
m_line_table_up; ///< Line table that will get parsed on demand.
|
std::unique_ptr<LineTable> m_line_table_up;
|
||||||
DebugMacrosSP
|
/// Debug macros that will get parsed on demand.
|
||||||
m_debug_macros_sp; ///< Debug macros that will get parsed on demand.
|
DebugMacrosSP m_debug_macros_sp;
|
||||||
lldb::VariableListSP m_variables; ///< Global and static variable list that
|
/// Global and static variable list that will get parsed on demand.
|
||||||
///will get parsed on demand.
|
lldb::VariableListSP m_variables;
|
||||||
lldb_private::LazyBool m_is_optimized; /// eLazyBoolYes if this compile unit
|
/// eLazyBoolYes if this compile unit was compiled with
|
||||||
/// was compiled with optimization.
|
/// optimization.
|
||||||
|
lldb_private::LazyBool m_is_optimized;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum {
|
enum {
|
||||||
|
27
lldb/include/lldb/Symbol/SourceModule.h
Normal file
27
lldb/include/lldb/Symbol/SourceModule.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
//===-- SourceModule.h ------------------------------------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef liblldb_SourceModule_h_
|
||||||
|
#define liblldb_SourceModule_h_
|
||||||
|
|
||||||
|
#include "lldb/Utility/ConstString.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace lldb_private {
|
||||||
|
|
||||||
|
/// Information needed to import a source-language module.
|
||||||
|
struct SourceModule {
|
||||||
|
/// Something like "Module.Submodule".
|
||||||
|
std::vector<ConstString> path;
|
||||||
|
ConstString search_path;
|
||||||
|
ConstString sysroot;
|
||||||
|
};
|
||||||
|
|
||||||
|
}; // namespace lldb_private
|
||||||
|
|
||||||
|
#endif
|
@ -14,6 +14,7 @@
|
|||||||
#include "lldb/Symbol/CompilerDeclContext.h"
|
#include "lldb/Symbol/CompilerDeclContext.h"
|
||||||
#include "lldb/Symbol/CompilerType.h"
|
#include "lldb/Symbol/CompilerType.h"
|
||||||
#include "lldb/Symbol/Function.h"
|
#include "lldb/Symbol/Function.h"
|
||||||
|
#include "lldb/Symbol/SourceModule.h"
|
||||||
#include "lldb/Symbol/Type.h"
|
#include "lldb/Symbol/Type.h"
|
||||||
#include "lldb/lldb-private.h"
|
#include "lldb/lldb-private.h"
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ public:
|
|||||||
|
|
||||||
virtual bool
|
virtual bool
|
||||||
ParseImportedModules(const SymbolContext &sc,
|
ParseImportedModules(const SymbolContext &sc,
|
||||||
std::vector<ConstString> &imported_modules) = 0;
|
std::vector<SourceModule> &imported_modules) = 0;
|
||||||
virtual size_t ParseBlocksRecursive(Function &func) = 0;
|
virtual size_t ParseBlocksRecursive(Function &func) = 0;
|
||||||
virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0;
|
virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0;
|
||||||
virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0;
|
virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "lldb/Core/ModuleChild.h"
|
#include "lldb/Core/ModuleChild.h"
|
||||||
#include "lldb/Core/PluginInterface.h"
|
#include "lldb/Core/PluginInterface.h"
|
||||||
|
#include "lldb/Symbol/SourceModule.h"
|
||||||
#include "lldb/Symbol/TypeList.h"
|
#include "lldb/Symbol/TypeList.h"
|
||||||
#include "lldb/Symbol/TypeMap.h"
|
#include "lldb/Symbol/TypeMap.h"
|
||||||
#include "lldb/lldb-private.h"
|
#include "lldb/lldb-private.h"
|
||||||
@ -60,8 +61,9 @@ public:
|
|||||||
|
|
||||||
virtual size_t ParseTypes(CompileUnit &comp_unit);
|
virtual size_t ParseTypes(CompileUnit &comp_unit);
|
||||||
|
|
||||||
virtual bool ParseImportedModules(const SymbolContext &sc,
|
virtual bool
|
||||||
std::vector<ConstString> &imported_modules);
|
ParseImportedModules(const SymbolContext &sc,
|
||||||
|
std::vector<SourceModule> &imported_modules);
|
||||||
|
|
||||||
virtual size_t ParseBlocksRecursive(Function &func);
|
virtual size_t ParseBlocksRecursive(Function &func);
|
||||||
|
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
struct Bar { int success; };
|
@ -0,0 +1 @@
|
|||||||
|
struct Foo {};
|
@ -0,0 +1,6 @@
|
|||||||
|
LEVEL = ../../../make
|
||||||
|
CXX_SOURCES := main.cpp
|
||||||
|
|
||||||
|
CFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS)
|
||||||
|
|
||||||
|
include $(LEVEL)/Makefile.rules
|
@ -0,0 +1,31 @@
|
|||||||
|
"""Test that importing modules in C++ works as expected."""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
import unittest2
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
import lldb
|
||||||
|
import platform
|
||||||
|
|
||||||
|
from lldbsuite.test.decorators import *
|
||||||
|
from lldbsuite.test.lldbtest import *
|
||||||
|
from lldbsuite.test import lldbutil
|
||||||
|
|
||||||
|
|
||||||
|
class CXXModulesImportTestCase(TestBase):
|
||||||
|
|
||||||
|
mydir = TestBase.compute_mydir(__file__)
|
||||||
|
|
||||||
|
@skipUnlessDarwin
|
||||||
|
@skipIf(macos_version=["<", "10.12"])
|
||||||
|
def test_expr(self):
|
||||||
|
self.build()
|
||||||
|
exe = self.getBuildArtifact("a.out")
|
||||||
|
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
|
||||||
|
self, 'break here', lldb.SBFileSpec('main.cpp'))
|
||||||
|
|
||||||
|
self.expect("expr -- @import Bar")
|
||||||
|
self.expect("expr -- Bar()", substrs = ["success"])
|
@ -0,0 +1,7 @@
|
|||||||
|
#include "Foo.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
Foo foo;
|
||||||
|
// break here.
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
module Foo {
|
||||||
|
header "Foo.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
module Bar {
|
||||||
|
header "Bar.h"
|
||||||
|
}
|
@ -113,24 +113,19 @@ public:
|
|||||||
|
|
||||||
void moduleImport(SourceLocation import_location, clang::ModuleIdPath path,
|
void moduleImport(SourceLocation import_location, clang::ModuleIdPath path,
|
||||||
const clang::Module * /*null*/) override {
|
const clang::Module * /*null*/) override {
|
||||||
std::vector<ConstString> string_path;
|
SourceModule module;
|
||||||
|
|
||||||
for (const std::pair<IdentifierInfo *, SourceLocation> &component : path) {
|
for (const std::pair<IdentifierInfo *, SourceLocation> &component : path)
|
||||||
string_path.push_back(ConstString(component.first->getName()));
|
module.path.push_back(ConstString(component.first->getName()));
|
||||||
}
|
|
||||||
|
|
||||||
StreamString error_stream;
|
StreamString error_stream;
|
||||||
|
|
||||||
ClangModulesDeclVendor::ModuleVector exported_modules;
|
ClangModulesDeclVendor::ModuleVector exported_modules;
|
||||||
|
if (!m_decl_vendor.AddModule(module, &exported_modules, m_error_stream))
|
||||||
if (!m_decl_vendor.AddModule(string_path, &exported_modules,
|
|
||||||
m_error_stream)) {
|
|
||||||
m_has_errors = true;
|
m_has_errors = true;
|
||||||
}
|
|
||||||
|
|
||||||
for (ClangModulesDeclVendor::ModuleID module : exported_modules) {
|
for (ClangModulesDeclVendor::ModuleID module : exported_modules)
|
||||||
m_persistent_vars.AddHandLoadedClangModule(module);
|
m_persistent_vars.AddHandLoadedClangModule(module);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasErrors() { return m_has_errors; }
|
bool hasErrors() { return m_has_errors; }
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "lldb/Host/Host.h"
|
#include "lldb/Host/Host.h"
|
||||||
#include "lldb/Host/HostInfo.h"
|
#include "lldb/Host/HostInfo.h"
|
||||||
#include "lldb/Symbol/CompileUnit.h"
|
#include "lldb/Symbol/CompileUnit.h"
|
||||||
|
#include "lldb/Symbol/SourceModule.h"
|
||||||
#include "lldb/Target/Target.h"
|
#include "lldb/Target/Target.h"
|
||||||
#include "lldb/Utility/FileSpec.h"
|
#include "lldb/Utility/FileSpec.h"
|
||||||
#include "lldb/Utility/LLDBAssert.h"
|
#include "lldb/Utility/LLDBAssert.h"
|
||||||
@ -71,7 +72,7 @@ public:
|
|||||||
|
|
||||||
~ClangModulesDeclVendorImpl() override = default;
|
~ClangModulesDeclVendorImpl() override = default;
|
||||||
|
|
||||||
bool AddModule(ModulePath &path, ModuleVector *exported_modules,
|
bool AddModule(const SourceModule &module, ModuleVector *exported_modules,
|
||||||
Stream &error_stream) override;
|
Stream &error_stream) override;
|
||||||
|
|
||||||
bool AddModulesForCompileUnit(CompileUnit &cu, ModuleVector &exported_modules,
|
bool AddModulesForCompileUnit(CompileUnit &cu, ModuleVector &exported_modules,
|
||||||
@ -184,7 +185,7 @@ void ClangModulesDeclVendorImpl::ReportModuleExports(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClangModulesDeclVendorImpl::AddModule(ModulePath &path,
|
bool ClangModulesDeclVendorImpl::AddModule(const SourceModule &module,
|
||||||
ModuleVector *exported_modules,
|
ModuleVector *exported_modules,
|
||||||
Stream &error_stream) {
|
Stream &error_stream) {
|
||||||
// Fail early.
|
// Fail early.
|
||||||
@ -199,7 +200,7 @@ bool ClangModulesDeclVendorImpl::AddModule(ModulePath &path,
|
|||||||
|
|
||||||
std::vector<ConstString> imported_module;
|
std::vector<ConstString> imported_module;
|
||||||
|
|
||||||
for (ConstString path_component : path) {
|
for (ConstString path_component : module.path) {
|
||||||
imported_module.push_back(path_component);
|
imported_module.push_back(path_component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,11 +215,34 @@ bool ClangModulesDeclVendorImpl::AddModule(ModulePath &path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_compiler_instance->getPreprocessor()
|
clang::HeaderSearch &HS =
|
||||||
.getHeaderSearchInfo()
|
m_compiler_instance->getPreprocessor().getHeaderSearchInfo();
|
||||||
.lookupModule(path[0].GetStringRef())) {
|
|
||||||
|
if (module.search_path) {
|
||||||
|
auto path_begin = llvm::sys::path::begin(module.search_path.GetStringRef());
|
||||||
|
auto path_end = llvm::sys::path::end(module.search_path.GetStringRef());
|
||||||
|
auto sysroot_begin = llvm::sys::path::begin(module.sysroot.GetStringRef());
|
||||||
|
auto sysroot_end = llvm::sys::path::end(module.sysroot.GetStringRef());
|
||||||
|
// FIXME: Use C++14 std::equal(it, it, it, it) variant once it's available.
|
||||||
|
bool is_system_module = (std::distance(path_begin, path_end) >=
|
||||||
|
std::distance(sysroot_begin, sysroot_end)) &&
|
||||||
|
std::equal(sysroot_begin, sysroot_end, path_begin);
|
||||||
|
// No need to inject search paths to modules in the sysroot.
|
||||||
|
if (!is_system_module) {
|
||||||
|
bool is_system = true;
|
||||||
|
bool is_framework = false;
|
||||||
|
auto *dir =
|
||||||
|
HS.getFileMgr().getDirectory(module.search_path.GetStringRef());
|
||||||
|
auto *file = HS.lookupModuleMapFile(dir, is_framework);
|
||||||
|
if (!HS.loadModuleMapFile(file, is_system))
|
||||||
|
error_stream.Printf("error: No module map file in %s\n",
|
||||||
|
module.search_path.AsCString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!HS.lookupModule(module.path.front().GetStringRef())) {
|
||||||
error_stream.Printf("error: Header search couldn't locate module %s\n",
|
error_stream.Printf("error: Header search couldn't locate module %s\n",
|
||||||
path[0].AsCString());
|
module.path.front().AsCString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +254,7 @@ bool ClangModulesDeclVendorImpl::AddModule(ModulePath &path,
|
|||||||
clang::SourceManager &source_manager =
|
clang::SourceManager &source_manager =
|
||||||
m_compiler_instance->getASTContext().getSourceManager();
|
m_compiler_instance->getASTContext().getSourceManager();
|
||||||
|
|
||||||
for (ConstString path_component : path) {
|
for (ConstString path_component : module.path) {
|
||||||
clang_path.push_back(std::make_pair(
|
clang_path.push_back(std::make_pair(
|
||||||
&m_compiler_instance->getASTContext().Idents.get(
|
&m_compiler_instance->getASTContext().Idents.get(
|
||||||
path_component.GetStringRef()),
|
path_component.GetStringRef()),
|
||||||
@ -250,19 +274,18 @@ bool ClangModulesDeclVendorImpl::AddModule(ModulePath &path,
|
|||||||
if (!top_level_module) {
|
if (!top_level_module) {
|
||||||
diagnostic_consumer->DumpDiagnostics(error_stream);
|
diagnostic_consumer->DumpDiagnostics(error_stream);
|
||||||
error_stream.Printf("error: Couldn't load top-level module %s\n",
|
error_stream.Printf("error: Couldn't load top-level module %s\n",
|
||||||
path[0].AsCString());
|
module.path.front().AsCString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
clang::Module *submodule = top_level_module;
|
clang::Module *submodule = top_level_module;
|
||||||
|
|
||||||
for (size_t ci = 1; ci < path.size(); ++ci) {
|
for (auto &component : llvm::ArrayRef<ConstString>(module.path).drop_front()) {
|
||||||
llvm::StringRef component = path[ci].GetStringRef();
|
submodule = submodule->findSubmodule(component.GetStringRef());
|
||||||
submodule = submodule->findSubmodule(component.str());
|
|
||||||
if (!submodule) {
|
if (!submodule) {
|
||||||
diagnostic_consumer->DumpDiagnostics(error_stream);
|
diagnostic_consumer->DumpDiagnostics(error_stream);
|
||||||
error_stream.Printf("error: Couldn't load submodule %s\n",
|
error_stream.Printf("error: Couldn't load submodule %s\n",
|
||||||
component.str().c_str());
|
component.GetCString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,12 +312,16 @@ bool ClangModulesDeclVendor::LanguageSupportsClangModules(
|
|||||||
switch (language) {
|
switch (language) {
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
// C++ and friends to be added
|
|
||||||
case lldb::LanguageType::eLanguageTypeC:
|
case lldb::LanguageType::eLanguageTypeC:
|
||||||
case lldb::LanguageType::eLanguageTypeC11:
|
case lldb::LanguageType::eLanguageTypeC11:
|
||||||
case lldb::LanguageType::eLanguageTypeC89:
|
case lldb::LanguageType::eLanguageTypeC89:
|
||||||
case lldb::LanguageType::eLanguageTypeC99:
|
case lldb::LanguageType::eLanguageTypeC99:
|
||||||
|
case lldb::LanguageType::eLanguageTypeC_plus_plus:
|
||||||
|
case lldb::LanguageType::eLanguageTypeC_plus_plus_03:
|
||||||
|
case lldb::LanguageType::eLanguageTypeC_plus_plus_11:
|
||||||
|
case lldb::LanguageType::eLanguageTypeC_plus_plus_14:
|
||||||
case lldb::LanguageType::eLanguageTypeObjC:
|
case lldb::LanguageType::eLanguageTypeObjC:
|
||||||
|
case lldb::LanguageType::eLanguageTypeObjC_plus_plus:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,21 +330,10 @@ bool ClangModulesDeclVendorImpl::AddModulesForCompileUnit(
|
|||||||
CompileUnit &cu, ClangModulesDeclVendor::ModuleVector &exported_modules,
|
CompileUnit &cu, ClangModulesDeclVendor::ModuleVector &exported_modules,
|
||||||
Stream &error_stream) {
|
Stream &error_stream) {
|
||||||
if (LanguageSupportsClangModules(cu.GetLanguage())) {
|
if (LanguageSupportsClangModules(cu.GetLanguage())) {
|
||||||
std::vector<ConstString> imported_modules = cu.GetImportedModules();
|
for (auto &imported_module : cu.GetImportedModules())
|
||||||
|
if (!AddModule(imported_module, &exported_modules, error_stream))
|
||||||
for (ConstString imported_module : imported_modules) {
|
|
||||||
std::vector<ConstString> path;
|
|
||||||
|
|
||||||
path.push_back(imported_module);
|
|
||||||
|
|
||||||
if (!AddModule(path, &exported_modules, error_stream)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
/// Add a module to the list of modules to search.
|
/// Add a module to the list of modules to search.
|
||||||
///
|
///
|
||||||
/// @param[in] path
|
/// @param[in] module
|
||||||
/// The path to the exact module to be loaded. E.g., if the desired
|
/// The path to the exact module to be loaded. E.g., if the desired
|
||||||
/// module is std.io, then this should be { "std", "io" }.
|
/// module is std.io, then this should be { "std", "io" }.
|
||||||
///
|
///
|
||||||
@ -53,7 +53,8 @@ public:
|
|||||||
/// compiler encountered a fatal error during a previous module
|
/// compiler encountered a fatal error during a previous module
|
||||||
/// load, then this will always return false for this ModuleImporter.
|
/// load, then this will always return false for this ModuleImporter.
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
virtual bool AddModule(ModulePath &path, ModuleVector *exported_modules,
|
virtual bool AddModule(const SourceModule &module,
|
||||||
|
ModuleVector *exported_modules,
|
||||||
Stream &error_stream) = 0;
|
Stream &error_stream) = 0;
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
@ -69,9 +69,9 @@ public:
|
|||||||
FileSpecList &support_files) override;
|
FileSpecList &support_files) override;
|
||||||
size_t ParseTypes(CompileUnit &cu) override { return 0; }
|
size_t ParseTypes(CompileUnit &cu) override { return 0; }
|
||||||
|
|
||||||
bool
|
bool ParseImportedModules(
|
||||||
ParseImportedModules(const SymbolContext &sc,
|
const SymbolContext &sc,
|
||||||
std::vector<ConstString> &imported_modules) override {
|
std::vector<lldb_private::SourceModule> &imported_modules) override {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@
|
|||||||
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -911,43 +912,57 @@ bool SymbolFileDWARF::ParseIsOptimized(CompileUnit &comp_unit) {
|
|||||||
|
|
||||||
bool SymbolFileDWARF::ParseImportedModules(
|
bool SymbolFileDWARF::ParseImportedModules(
|
||||||
const lldb_private::SymbolContext &sc,
|
const lldb_private::SymbolContext &sc,
|
||||||
std::vector<lldb_private::ConstString> &imported_modules) {
|
std::vector<SourceModule> &imported_modules) {
|
||||||
ASSERT_MODULE_LOCK(this);
|
ASSERT_MODULE_LOCK(this);
|
||||||
assert(sc.comp_unit);
|
assert(sc.comp_unit);
|
||||||
DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
|
DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
|
||||||
if (dwarf_cu) {
|
if (!dwarf_cu)
|
||||||
if (ClangModulesDeclVendor::LanguageSupportsClangModules(
|
return false;
|
||||||
sc.comp_unit->GetLanguage())) {
|
if (!ClangModulesDeclVendor::LanguageSupportsClangModules(
|
||||||
UpdateExternalModuleListIfNeeded();
|
sc.comp_unit->GetLanguage()))
|
||||||
|
return false;
|
||||||
|
UpdateExternalModuleListIfNeeded();
|
||||||
|
|
||||||
if (sc.comp_unit) {
|
if (!sc.comp_unit)
|
||||||
const DWARFDIE die = dwarf_cu->DIE();
|
return false;
|
||||||
|
|
||||||
if (die) {
|
const DWARFDIE die = dwarf_cu->DIE();
|
||||||
for (DWARFDIE child_die = die.GetFirstChild(); child_die;
|
if (!die)
|
||||||
child_die = child_die.GetSibling()) {
|
return false;
|
||||||
if (child_die.Tag() == DW_TAG_imported_declaration) {
|
|
||||||
if (DWARFDIE module_die =
|
for (DWARFDIE child_die = die.GetFirstChild(); child_die;
|
||||||
child_die.GetReferencedDIE(DW_AT_import)) {
|
child_die = child_die.GetSibling()) {
|
||||||
if (module_die.Tag() == DW_TAG_module) {
|
if (child_die.Tag() != DW_TAG_imported_declaration)
|
||||||
if (const char *name = module_die.GetAttributeValueAsString(
|
continue;
|
||||||
DW_AT_name, nullptr)) {
|
|
||||||
ConstString const_name(name);
|
DWARFDIE module_die = child_die.GetReferencedDIE(DW_AT_import);
|
||||||
imported_modules.push_back(const_name);
|
if (module_die.Tag() != DW_TAG_module)
|
||||||
}
|
continue;
|
||||||
}
|
|
||||||
}
|
if (const char *name =
|
||||||
}
|
module_die.GetAttributeValueAsString(DW_AT_name, nullptr)) {
|
||||||
}
|
SourceModule module;
|
||||||
}
|
module.path.push_back(ConstString(name));
|
||||||
} else {
|
|
||||||
for (const auto &pair : m_external_type_modules) {
|
DWARFDIE parent_die = module_die;
|
||||||
imported_modules.push_back(pair.first);
|
while ((parent_die = parent_die.GetParent())) {
|
||||||
}
|
if (parent_die.Tag() != DW_TAG_module)
|
||||||
|
break;
|
||||||
|
if (const char *name =
|
||||||
|
parent_die.GetAttributeValueAsString(DW_AT_name, nullptr))
|
||||||
|
module.path.push_back(ConstString(name));
|
||||||
}
|
}
|
||||||
|
std::reverse(module.path.begin(), module.path.end());
|
||||||
|
if (const char *include_path = module_die.GetAttributeValueAsString(
|
||||||
|
DW_AT_LLVM_include_path, nullptr))
|
||||||
|
module.search_path = ConstString(include_path);
|
||||||
|
if (const char *sysroot = module_die.GetAttributeValueAsString(
|
||||||
|
DW_AT_LLVM_isysroot, nullptr))
|
||||||
|
module.sysroot = ConstString(sysroot);
|
||||||
|
imported_modules.push_back(module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ParseDWARFLineTableCallbackInfo {
|
struct ParseDWARFLineTableCallbackInfo {
|
||||||
|
@ -125,7 +125,7 @@ public:
|
|||||||
|
|
||||||
bool ParseImportedModules(
|
bool ParseImportedModules(
|
||||||
const lldb_private::SymbolContext &sc,
|
const lldb_private::SymbolContext &sc,
|
||||||
std::vector<lldb_private::ConstString> &imported_modules) override;
|
std::vector<lldb_private::SourceModule> &imported_modules) override;
|
||||||
|
|
||||||
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@ bool SymbolFileDWARFDebugMap::ParseIsOptimized(CompileUnit &comp_unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SymbolFileDWARFDebugMap::ParseImportedModules(
|
bool SymbolFileDWARFDebugMap::ParseImportedModules(
|
||||||
const SymbolContext &sc, std::vector<ConstString> &imported_modules) {
|
const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
|
||||||
SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
|
SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
|
||||||
if (oso_dwarf)
|
if (oso_dwarf)
|
||||||
return oso_dwarf->ParseImportedModules(sc, imported_modules);
|
return oso_dwarf->ParseImportedModules(sc, imported_modules);
|
||||||
|
@ -72,7 +72,7 @@ public:
|
|||||||
|
|
||||||
bool ParseImportedModules(
|
bool ParseImportedModules(
|
||||||
const lldb_private::SymbolContext &sc,
|
const lldb_private::SymbolContext &sc,
|
||||||
std::vector<lldb_private::ConstString> &imported_modules) override;
|
std::vector<lldb_private::SourceModule> &imported_modules) override;
|
||||||
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
||||||
size_t
|
size_t
|
||||||
ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
|
ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
|
||||||
|
@ -1136,7 +1136,7 @@ bool SymbolFileNativePDB::ParseSupportFiles(CompileUnit &comp_unit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SymbolFileNativePDB::ParseImportedModules(
|
bool SymbolFileNativePDB::ParseImportedModules(
|
||||||
const SymbolContext &sc, std::vector<ConstString> &imported_modules) {
|
const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
|
||||||
// PDB does not yet support module debug info
|
// PDB does not yet support module debug info
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -94,9 +94,9 @@ public:
|
|||||||
FileSpecList &support_files) override;
|
FileSpecList &support_files) override;
|
||||||
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
|
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
|
||||||
|
|
||||||
bool
|
bool ParseImportedModules(
|
||||||
ParseImportedModules(const SymbolContext &sc,
|
const SymbolContext &sc,
|
||||||
std::vector<ConstString> &imported_modules) override;
|
std::vector<lldb_private::SourceModule> &imported_modules) override;
|
||||||
|
|
||||||
size_t ParseBlocksRecursive(Function &func) override;
|
size_t ParseBlocksRecursive(Function &func) override;
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ bool SymbolFilePDB::ParseSupportFiles(
|
|||||||
|
|
||||||
bool SymbolFilePDB::ParseImportedModules(
|
bool SymbolFilePDB::ParseImportedModules(
|
||||||
const lldb_private::SymbolContext &sc,
|
const lldb_private::SymbolContext &sc,
|
||||||
std::vector<lldb_private::ConstString> &imported_modules) {
|
std::vector<SourceModule> &imported_modules) {
|
||||||
// PDB does not yet support module debug info
|
// PDB does not yet support module debug info
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public:
|
|||||||
|
|
||||||
bool ParseImportedModules(
|
bool ParseImportedModules(
|
||||||
const lldb_private::SymbolContext &sc,
|
const lldb_private::SymbolContext &sc,
|
||||||
std::vector<lldb_private::ConstString> &imported_modules) override;
|
std::vector<lldb_private::SourceModule> &imported_modules) override;
|
||||||
|
|
||||||
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ bool SymbolFileSymtab::ParseSupportFiles(CompileUnit &comp_unit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SymbolFileSymtab::ParseImportedModules(
|
bool SymbolFileSymtab::ParseImportedModules(
|
||||||
const SymbolContext &sc, std::vector<ConstString> &imported_modules) {
|
const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public:
|
|||||||
|
|
||||||
bool ParseImportedModules(
|
bool ParseImportedModules(
|
||||||
const lldb_private::SymbolContext &sc,
|
const lldb_private::SymbolContext &sc,
|
||||||
std::vector<lldb_private::ConstString> &imported_modules) override;
|
std::vector<lldb_private::SourceModule> &imported_modules) override;
|
||||||
|
|
||||||
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
size_t ParseBlocksRecursive(lldb_private::Function &func) override;
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ void CompileUnit::SetVariableList(VariableListSP &variables) {
|
|||||||
m_variables = variables;
|
m_variables = variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<ConstString> &CompileUnit::GetImportedModules() {
|
const std::vector<SourceModule> &CompileUnit::GetImportedModules() {
|
||||||
if (m_imported_modules.empty() &&
|
if (m_imported_modules.empty() &&
|
||||||
m_flags.IsClear(flagsParsedImportedModules)) {
|
m_flags.IsClear(flagsParsedImportedModules)) {
|
||||||
m_flags.Set(flagsParsedImportedModules);
|
m_flags.Set(flagsParsedImportedModules);
|
||||||
|
@ -185,7 +185,7 @@ bool SymbolVendor::ParseIsOptimized(CompileUnit &comp_unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SymbolVendor::ParseImportedModules(
|
bool SymbolVendor::ParseImportedModules(
|
||||||
const SymbolContext &sc, std::vector<ConstString> &imported_modules) {
|
const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
|
||||||
ModuleSP module_sp(GetModule());
|
ModuleSP module_sp(GetModule());
|
||||||
if (module_sp) {
|
if (module_sp) {
|
||||||
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
||||||
|
Loading…
Reference in New Issue
Block a user