[Lldb-commits] [lldb] r356462 - Improve error handling for Clang module imports.
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 19 08:38:26 PDT 2019
Author: adrian
Date: Tue Mar 19 08:38:26 2019
New Revision: 356462
URL: http://llvm.org/viewvc/llvm-project?rev=356462&view=rev
Log:
Improve error handling for Clang module imports.
rdar://problem/48883558
Differential Revision: https://reviews.llvm.org/D59524
Added:
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
Removed:
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
Modified:
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
Removed: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h?rev=356461&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h (removed)
@@ -1 +0,0 @@
-struct Bar { int success; };
Removed: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h?rev=356461&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h (removed)
@@ -1 +0,0 @@
-struct Foo {};
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h?rev=356462&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h Tue Mar 19 08:38:26 2019
@@ -0,0 +1 @@
+struct Bar { int success; };
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h?rev=356462&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h Tue Mar 19 08:38:26 2019
@@ -0,0 +1 @@
+struct Foo {};
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap?rev=356462&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap Tue Mar 19 08:38:26 2019
@@ -0,0 +1,7 @@
+module Foo {
+ header "Foo.h"
+}
+
+module Bar {
+ header "Bar.h"
+}
Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile?rev=356462&r1=356461&r2=356462&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile Tue Mar 19 08:38:26 2019
@@ -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
Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py?rev=356462&r1=356461&r2=356462&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py Tue Mar 19 08:38:26 2019
@@ -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)
Removed: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap?rev=356461&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap (removed)
@@ -1,7 +0,0 @@
-module Foo {
- header "Foo.h"
-}
-
-module Bar {
- header "Bar.h"
-}
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=356462&r1=356461&r2=356462&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Tue Mar 19 08:38:26 2019
@@ -229,15 +229,23 @@ bool ClangModulesDeclVendorImpl::AddModu
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())) {
More information about the lldb-commits
mailing list