Skip to content

Commit 9379d19

Browse files
committed
[lldb] Decouple importing the std C++ module from the way the program is compiled
Summary: At the moment, when trying to import the `std` module in LLDB, we look at the imported modules used in the compiled program and try to infer the Clang configuration we need from the DWARF module-import. That was the initial idea but turned out to cause a few problems or inconveniences: * It requires that users compile their programs with C++ modules. Given how experimental C++ modules are makes this feature inaccessible for many users. Also it means that people can't just get the benefits of this feature for free when we activate it by default (and we can't just close all the associated bug reports). * Relying on DWARF's imported module tags (that are only emitted by default on macOS) means this can only be used when using DWARF (and with -glldb on Linux). * We essentially hardcoded the C standard library paths on some platforms (Linux) or just couldn't support this feature on other platforms (macOS). This patch drops the whole idea of looking at the imported module DWARF tags and instead just uses the support files of the compilation unit. If we look at the support files and see file paths that indicate where the C standard library and libc++ are, we can just create the module configuration this information. This fixes all the problems above which means we can enable all the tests now on Linux, macOS and with other debug information than what we currently had. The only debug information specific code is now the iteration over external type module when -gmodules is used (as `std` and also the `Darwin` module are their own external type module with their own files). The meat of this patch is the CppModuleConfiguration which looks at the file paths from the compilation unit and then figures out the include paths based on those paths. It's quite conservative in that it only enables modules if we find a single C library and single libc++ library. It's still missing some test mode where we try to compile an expression before we actually activate the config for the user (which probably also needs some caching mechanism), but for now it works and makes the feature usable. Reviewers: aprantl, shafik, jdoerfert Reviewed By: aprantl Subscribers: mgorny, abidh, JDevlieghere, lldb-commits Tags: #c_modules_in_lldb, #lldb Differential Revision: https://reviews.llvm.org/D67760 llvm-svn: 372716
1 parent a0d79d8 commit 9379d19

File tree

62 files changed

+437
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+437
-203
lines changed

lldb/include/lldb/Symbol/CompileUnit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ class CompileUnit : public std::enable_shared_from_this<CompileUnit>,
225225

226226
DebugMacros *GetDebugMacros();
227227

228+
/// Apply a lambda to each external lldb::Module referenced by this
229+
/// compilation unit. Recursively also descends into the referenced external
230+
/// modules of any encountered compilation unit.
231+
///
232+
/// \param[in] lambda
233+
/// The lambda that should be applied to every module.
234+
void ForEachExternalModule(llvm::function_ref<void(lldb::ModuleSP)> f);
235+
228236
/// Get the compile unit's support file list.
229237
///
230238
/// The support file list is used by the line table, and any objects that

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class SymbolFile : public PluginInterface {
122122
virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0;
123123
virtual bool ParseLineTable(CompileUnit &comp_unit) = 0;
124124
virtual bool ParseDebugMacros(CompileUnit &comp_unit) = 0;
125+
virtual void
126+
ForEachExternalModule(CompileUnit &comp_unit,
127+
llvm::function_ref<void(lldb::ModuleSP)> f) {}
125128
virtual bool ParseSupportFiles(CompileUnit &comp_unit,
126129
FileSpecList &support_files) = 0;
127130
virtual size_t ParseTypes(CompileUnit &comp_unit) = 0;

lldb/include/lldb/Target/Platform.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,6 @@ class Platform : public PluginInterface {
257257

258258
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir);
259259

260-
/// Retrieve the system include directories on this platform for the
261-
/// given language.
262-
///
263-
/// \param[in] lang
264-
/// The language for which the include directories should be queried.
265-
///
266-
/// \param[out] directories
267-
/// The include directories for this system.
268-
virtual std::vector<std::string>
269-
GetSystemIncludeDirectories(lldb::LanguageType lang) {
270-
return {};
271-
}
272-
273260
virtual UserIDResolver &GetUserIDResolver() = 0;
274261

275262
/// Locate a file for a platform.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/TestImportStdModule.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ class ImportStdModule(TestBase):
1111

1212
mydir = TestBase.compute_mydir(__file__)
1313

14-
# FIXME: This should work on more setups, so remove these
15-
# skipIf's in the future.
1614
@add_test_categories(["libc++"])
1715
@skipIf(compiler=no_match("clang"))
18-
@skipIf(oslist=no_match(["linux"]))
19-
@skipIf(debug_info=no_match(["dwarf"]))
2016
def test(self):
2117
self.build()
2218

@@ -34,12 +30,8 @@ def test(self):
3430
self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",
3531
substrs=["(char) $3 = 'a'"])
3632

37-
# FIXME: This should work on more setups, so remove these
38-
# skipIf's in the future.
3933
@add_test_categories(["libc++"])
4034
@skipIf(compiler=no_match("clang"))
41-
@skipIf(oslist=no_match(["linux"]))
42-
@skipIf(debug_info=no_match(["dwarf"]))
4335
def test_non_cpp_language(self):
4436
self.build()
4537

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ class TestImportStdModuleConflicts(TestBase):
1616

1717
mydir = TestBase.compute_mydir(__file__)
1818

19-
# FIXME: This should work on more setups, so remove these
20-
# skipIf's in the future.
2119
@add_test_categories(["libc++"])
2220
@skipIf(compiler=no_match("clang"))
23-
@skipIf(oslist=no_match(["linux"]))
24-
@skipIf(debug_info=no_match(["dwarf"]))
2521
def test(self):
2622
self.build()
2723

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/TestBasicDeque.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestBasicDeque(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestDbgInfoContentDeque(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/TestBasicForwardList.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestBasicForwardList(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestDbgInfoContentForwardList(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/TestBasicList.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestBasicList(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ class TestDbgInfoContentList(TestBase):
1111

1212
mydir = TestBase.compute_mydir(__file__)
1313

14-
# FIXME: This should work on more setups, so remove these
15-
# skipIf's in the future.
1614
@add_test_categories(["libc++"])
1715
@skipIf(compiler=no_match("clang"))
18-
@skipIf(oslist=no_match(["linux"]))
19-
@skipIf(debug_info=no_match(["dwarf"]))
2016
def test(self):
2117
self.build()
2218

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/TestMissingStdModule.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ class STLTestCase(TestBase):
1717

1818
mydir = TestBase.compute_mydir(__file__)
1919

20-
# FIXME: This should work on more setups, so remove these
21-
# skipIf's in the future.
2220
@add_test_categories(["libc++"])
2321
@skipIf(compiler=no_match("clang"))
24-
@skipIf(oslist=no_match(["linux"]))
25-
@skipIf(debug_info=no_match(["dwarf"]))
2622
def test(self):
2723
self.build()
2824

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/TestQueue.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestQueue(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestSharedPtrDbgInfoContent(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr/TestSharedPtr.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestSharedPtr(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/stack/TestStack.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestStack(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# system headers.
44
NO_TEST_COMMON_H := 1
55

6-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
76
CXXFLAGS += -I $(SRCDIR)/root/usr/include/c++/include/ -I $(SRCDIR)/root/usr/include/ -nostdinc -nostdinc++ -nostdlib++
87
CXX_SOURCES := main.cpp
98
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/sysroot/TestStdModuleSysroot.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ class ImportStdModule(TestBase):
1111

1212
mydir = TestBase.compute_mydir(__file__)
1313

14-
# FIXME: This should work on more setups, so remove these
15-
# skipIf's in the future.
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestUniquePtrDbgInfoContent(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/unique_ptr/TestUniquePtr.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestUniquePtr(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-basic/TestBasicVector.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestBasicVector(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/vector-bool/TestBoolVector.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class TestBoolVector(TestBase):
1010

1111
mydir = TestBase.compute_mydir(__file__)
1212

13-
# FIXME: This should work on more setups, so remove these
14-
# skipIf's in the future.
1513
@add_test_categories(["libc++"])
1614
@skipIf(compiler=no_match("clang"))
17-
@skipIf(oslist=no_match(["linux"]))
18-
@skipIf(debug_info=no_match(["dwarf"]))
1915
def test(self):
2016
self.build()
2117

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
USE_LIBCPP := 1
2-
CXXFLAGS += $(MANDATORY_CXXMODULE_BUILD_CFLAGS)
32
CXX_SOURCES := main.cpp
43
include Makefile.rules

0 commit comments

Comments
 (0)