This revision was automatically updated to reflect the committed changes.
Closed by commit rL356462: Improve error handling for Clang module imports. 
(authored by adrian, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59524?vs=191215&id=191313#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59524/new/

https://reviews.llvm.org/D59524

Files:
  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/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
  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/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
@@ -0,0 +1 @@
+struct Bar { int success; };
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.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/Foo.h
@@ -0,0 +1 @@
+struct Foo {};
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
@@ -0,0 +1,7 @@
+module Foo {
+  header "Foo.h"
+}
+
+module Bar {
+  header "Bar.h"
+}
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
+++ lldb/trunk/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 @@
 
     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)
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
+++ lldb/trunk/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
Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
===================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -229,15 +229,23 @@
                             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())) {
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
@@ -1 +0,0 @@
-struct Bar { int success; };
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
@@ -1 +0,0 @@
-struct Foo {};
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
@@ -1,7 +0,0 @@
-module Foo {
-  header "Foo.h"
-}
-
-module Bar {
-  header "Bar.h"
-}
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to