summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2019-03-19 15:38:26 +0000
committerAdrian Prantl <aprantl@apple.com>2019-03-19 15:38:26 +0000
commita2d84c62e70daaf19fa61ff9ff8fb0c2d05b429a (patch)
tree950e33e3a9ff5c51ecf7e2f1ddcf0a17661af3a4
parent9941de4247d4e82aa56cac64e4a4a4c0ed06c9af (diff)
Improve error handling for Clang module imports.
rdar://problem/48883558 Differential Revision: https://reviews.llvm.org/D59524 git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@356462 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h (renamed from packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h)0
-rw-r--r--packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h (renamed from packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h)0
-rw-r--r--packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap (renamed from packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap)0
-rw-r--r--packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile3
-rw-r--r--packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py27
-rw-r--r--source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp14
6 files changed, 33 insertions, 11 deletions
diff --git a/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
index 3d9a88c02..3d9a88c02 100644
--- a/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
+++ b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
diff --git a/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h
index 1fe02e897..1fe02e897 100644
--- a/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
+++ b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h
diff --git a/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
index 4221d0f91..4221d0f91 100644
--- a/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
+++ b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
diff --git a/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
index 796b4dc5e..2b8f23bce 100644
--- a/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
+++ b/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
@@ -1,6 +1,5 @@
LEVEL = ../../../make
CXX_SOURCES := main.cpp
-
-CFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS)
+CFLAGS_EXTRAS = $(MANDATORY_MODULE_BUILD_CFLAGS) -I$(BUILDDIR)/include
include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py b/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
index 74ac40056..cee551d2b 100644
--- a/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
+++ b/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
@@ -2,13 +2,9 @@
from __future__ import print_function
-
-from distutils.version import StrictVersion
import unittest2
-import os
-import time
import lldb
-import platform
+import shutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -19,13 +15,32 @@ class CXXModulesImportTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
+ def build(self):
+ include = self.getBuildArtifact('include')
+ lldbutil.mkdir_p(include)
+ for f in ['Foo.h', 'Bar.h', 'module.modulemap']:
+ shutil.copyfile(self.getSourcePath(os.path.join('Inputs', f)),
+ os.path.join(include, f))
+ super(CXXModulesImportTestCase, self).build()
+
@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 -l Objective-C++ -- @import Bar")
self.expect("expr -- Bar()", substrs = ["success"])
+ self.expect("expr -l Objective-C++ -- @import THIS_MODULE_DOES_NOT_EXIST",
+ error=True)
+
+ @skipUnlessDarwin
+ @skipIf(macos_version=["<", "10.12"])
+ def test_expr_failing_import(self):
+ self.build()
+ shutil.rmtree(self.getBuildArtifact('include'))
+ target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
+ self, 'break here', lldb.SBFileSpec('main.cpp'))
+
+ self.expect("expr -l Objective-C++ -- @import Bar", error=True)
diff --git a/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
index 78941355b..05294927a 100644
--- a/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ b/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -229,15 +229,23 @@ bool ClangModulesDeclVendorImpl::AddModule(const SourceModule &module,
std::equal(sysroot_begin, sysroot_end, path_begin);
// No need to inject search paths to modules in the sysroot.
if (!is_system_module) {
+ auto error = [&]() {
+ error_stream.Printf("error: No module map file in %s\n",
+ module.search_path.AsCString());
+ return false;
+ };
+
bool is_system = true;
bool is_framework = false;
auto *dir =
HS.getFileMgr().getDirectory(module.search_path.GetStringRef());
+ if (!dir)
+ return error();
auto *file = HS.lookupModuleMapFile(dir, is_framework);
+ if (!file)
+ return error();
if (!HS.loadModuleMapFile(file, is_system))
- error_stream.Printf("error: No module map file in %s\n",
- module.search_path.AsCString());
- return false;
+ return error();
}
}
if (!HS.lookupModule(module.path.front().GetStringRef())) {