[Lldb-commits] [PATCH] D59524: Improve error handling for Clang module imports
Adrian Prantl via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 18 17:13:11 PDT 2019
aprantl created this revision.
aprantl added a reviewer: JDevlieghere.
Herald added a reviewer: serge-sans-paille.
Herald added a project: LLDB.
aprantl edited the summary of this revision.
Most notably this avoids nullptr dereferences when the import fails.
rdar://problem/48883558
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D59524
Files:
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ lldb/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/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
+++ lldb/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/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
===================================================================
--- lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
+++ lldb/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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59524.191215.patch
Type: text/x-patch
Size: 3777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190319/c7abaa85/attachment-0001.bin>
More information about the lldb-commits
mailing list