Index: include/lldb/API/SystemInitializerFull.h =================================================================== --- include/lldb/API/SystemInitializerFull.h +++ include/lldb/API/SystemInitializerFull.h @@ -29,6 +29,8 @@ void Initialize() override; void Terminate() override; + /// Retrieve the default clang module cache path. + static void InitializeClang(); private: void InitializeSWIG(); }; Index: include/lldb/Core/ModuleList.h =================================================================== --- include/lldb/Core/ModuleList.h +++ include/lldb/Core/ModuleList.h @@ -79,6 +79,10 @@ public: ModuleListProperties(); + /// Set the default clang modules cache path. + /// This avoids Core depending on Clang. + static void Initialize(llvm::StringRef clang_modules_cache_path); + FileSpec GetClangModulesCachePath() const; bool SetClangModulesCachePath(llvm::StringRef path); bool GetEnableExternalLookup() const; Index: source/API/SystemInitializerFull.cpp =================================================================== --- source/API/SystemInitializerFull.cpp +++ source/API/SystemInitializerFull.cpp @@ -119,6 +119,7 @@ #endif #include "llvm/Support/TargetSelect.h" +#include "clang/Driver/Driver.h" #include @@ -385,6 +386,13 @@ // AFTER PluginManager::Initialize is called. Debugger::SettingsInitialize(); + InitializeClang(); +} + +void SystemInitializerFull::InitializeClang() { + llvm::SmallString<128> path; + clang::driver::Driver::getDefaultModuleCachePath(path); + ModuleListProperties::Initialize(path); } void SystemInitializerFull::InitializeSWIG() { Index: source/Core/ModuleList.cpp =================================================================== --- source/Core/ModuleList.cpp +++ source/Core/ModuleList.cpp @@ -34,7 +34,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" // for fs -#include "clang/Driver/Driver.h" #include // for operator!=, time_point #include // for shared_ptr @@ -79,15 +78,20 @@ enum { ePropertyEnableExternalLookup, ePropertyClangModulesCachePath }; +std::string g_default_clang_modules_cache_path; } // namespace +void ModuleListProperties::Initialize( + llvm::StringRef clang_modules_cache_path) { + g_default_clang_modules_cache_path = clang_modules_cache_path.str(); +} + ModuleListProperties::ModuleListProperties() { m_collection_sp.reset(new OptionValueProperties(ConstString("symbols"))); m_collection_sp->Initialize(g_properties); - llvm::SmallString<128> path; - clang::driver::Driver::getDefaultModuleCachePath(path); - SetClangModulesCachePath(path); + assert(!g_default_clang_modules_cache_path.empty()); + SetClangModulesCachePath(g_default_clang_modules_cache_path); } bool ModuleListProperties::GetEnableExternalLookup() const { Index: tools/lldb-test/CMakeLists.txt =================================================================== --- tools/lldb-test/CMakeLists.txt +++ tools/lldb-test/CMakeLists.txt @@ -19,6 +19,7 @@ lldbUtility ${LLDB_ALL_PLUGINS} ${host_lib} + clangDriver LINK_COMPONENTS Support Index: tools/lldb-test/lldb-test.cpp =================================================================== --- tools/lldb-test/lldb-test.cpp +++ tools/lldb-test/lldb-test.cpp @@ -34,6 +34,9 @@ #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" #include "llvm/Support/WithColor.h" + +#include "clang/Driver/Driver.h" + #include using namespace lldb; @@ -467,6 +470,11 @@ cl::ParseCommandLineOptions(argc, argv, "LLDB Testing Utility\n"); + // Retrieve the default modulecache path from clang. + llvm::SmallString<128> path; + clang::driver::Driver::getDefaultModuleCachePath(path); + ModuleListProperties::Initialize(path); + SystemLifetimeManager DebuggerLifetime; DebuggerLifetime.Initialize(llvm::make_unique(), nullptr); Index: unittests/Host/SymbolsTest.cpp =================================================================== --- unittests/Host/SymbolsTest.cpp +++ unittests/Host/SymbolsTest.cpp @@ -9,13 +9,16 @@ #include "gtest/gtest.h" +#include "lldb/API/SystemInitializerFull.h" #include "lldb/Host/Symbols.h" +#include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" using namespace lldb_private; TEST(SymbolsTest, LocateExecutableSymbolFileForUnknownExecutableAndUnknownSymbolFile) { + ModuleListProperties::Initialize("dummy"); ModuleSpec module_spec; FileSpec symbol_file_spec = Symbols::LocateExecutableSymbolFile(module_spec); EXPECT_TRUE(symbol_file_spec.GetFilename().IsEmpty()); @@ -23,6 +26,7 @@ TEST(SymbolsTest, LocateExecutableSymbolFileForUnknownExecutableAndMissingSymbolFile) { + ModuleListProperties::Initialize("dummy"); ModuleSpec module_spec; // using a GUID here because the symbol file shouldn't actually exist on disk module_spec.GetSymbolFileSpec().SetFile( Index: unittests/Target/ModuleCacheTest.cpp =================================================================== --- unittests/Target/ModuleCacheTest.cpp +++ unittests/Target/ModuleCacheTest.cpp @@ -5,7 +5,9 @@ #include "llvm/Support/Path.h" #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" +#include "lldb/API/SystemInitializerFull.h" #include "lldb/Core/Module.h" +#include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Host/HostInfo.h" #include "lldb/Symbol/SymbolContext.h" @@ -67,6 +69,7 @@ void ModuleCacheTest::SetUpTestCase() { HostInfo::Initialize(); ObjectFileELF::Initialize(); + ModuleListProperties::Initialize("dummy"); FileSpec tmpdir_spec; HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, s_cache_dir);