diff --git a/debuginfo-tests/CMakeLists.txt b/debuginfo-tests/CMakeLists.txt --- a/debuginfo-tests/CMakeLists.txt +++ b/debuginfo-tests/CMakeLists.txt @@ -1,3 +1,4 @@ +## TODO: update this comment. # Debug Info tests. These tests invoke clang to generate programs with # various types of debug info, and then run those programs under a debugger # such as GDB or LLDB to verify the results. @@ -9,19 +10,24 @@ ) target_link_libraries(check-gdb-llvm-support PRIVATE LLVMSupport) +## TODO: Update variable names? set(DEBUGINFO_TESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(DEBUGINFO_TESTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(DEBUGINFO_TEST_DEPS - clang FileCheck count llvm-config llvm-objdump + llvm-symbolizer check-gdb-llvm-support not ) +if ("clang" IN_LIST LLVM_ENABLE_PROJECTS) + list(APPEND DEBUGINFO_TEST_DEPS clang) +endif() + if ("mlir" IN_LIST LLVM_ENABLE_PROJECTS) add_llvm_executable(check-gdb-mlir-support llvm-prettyprinters/gdb/mlir-support.cpp @@ -50,8 +56,8 @@ endif() # The Windows builder scripts pass -fuse-ld=lld. -if (WIN32) - set(DEBUGINFO_TEST_DEPS ${DEBUGINFO_TEST_DEPS} lld) +if (WIN32 OR "lld" IN_LIST LLVM_ENABLE_PROJECTS) + list(APPEND DEBUGINFO_TEST_DEPS lld) endif() if (NOT DEFINED Python3_EXECUTABLE) @@ -65,6 +71,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py ) +# TODO: Consider new targets? add_lit_testsuite(check-debuginfo "Running debug info integration tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${DEBUGINFO_TEST_DEPS} @@ -75,4 +82,4 @@ DEPENDS ${DEBUGINFO_TEST_DEPS} ) -set_target_properties(check-debuginfo PROPERTIES FOLDER "Debug info tests") +set_target_properties(check-debuginfo PROPERTIES FOLDER "Tests") diff --git a/debuginfo-tests/lit.cfg.py b/debuginfo-tests/lit.cfg.py --- a/debuginfo-tests/lit.cfg.py +++ b/debuginfo-tests/lit.cfg.py @@ -42,6 +42,7 @@ llvm_config.use_default_substitutions() tools = [ + 'llvm-symbolizer', ToolSubst('%test_debuginfo', command=os.path.join( config.debuginfo_tests_src_root, 'llgdb-tests', 'test_debuginfo.pl')), ToolSubst("%llvm_src_root", config.llvm_src_root), @@ -73,22 +74,31 @@ tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers', arch, 'cdb.exe'))) -# clang_src_dir is not used by these tests, but is required by -# use_clang(), so set it to "". +config.enabled_projects = config.enabled_projects.split(';') + +# clang_src_dir and lld_src_dir are not used by these tests, but are required by +# use_clang() and use_lld(), so set it to "". if not hasattr(config, 'clang_src_dir'): config.clang_src_dir = "" -llvm_config.use_clang() +llvm_config.use_clang(required=('clang' in config.enabled_projects)) +if not hasattr(config, 'lld_src_dir'): + config.lld_src_dir = "" +llvm_config.use_lld(required=('lld' in config.enabled_projects)) if config.llvm_use_sanitizer: # Propagate path to symbolizer for ASan/MSan. llvm_config.with_system_environment( ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) -llvm_config.with_environment('PATHTOCLANG', llvm_config.config.clang) -llvm_config.with_environment('PATHTOCLANGPP', llvm_config.use_llvm_tool('clang++')) -llvm_config.with_environment('PATHTOCLANGCL', llvm_config.use_llvm_tool('clang-cl')) + +if llvm_config.config.clang: + llvm_config.with_environment('PATHTOCLANG', llvm_config.config.clang) + llvm_config.with_environment('PATHTOCLANGPP', llvm_config.use_llvm_tool('clang++')) + llvm_config.with_environment('PATHTOCLANGCL', llvm_config.use_llvm_tool('clang-cl')) # Check which debuggers are available: -built_lldb = llvm_config.use_llvm_tool('lldb', search_env='CLANG') +built_lldb = llvm_config.use_llvm_tool('lldb', + search_env='CLANG', + required=('lldb' in config.enabled_projects)) lldb_path = None if built_lldb is not None: lldb_path = built_lldb @@ -157,6 +167,9 @@ if apple_lldb_vers < 1000: config.available_features.add('apple-lldb-pre-1000') +for arch in config.targets_to_build.split(): + config.available_features.add(arch.lower() + '-registered-target') + llvm_config.feature_config( [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})] ) diff --git a/debuginfo-tests/lit.site.cfg.py.in b/debuginfo-tests/lit.site.cfg.py.in --- a/debuginfo-tests/lit.site.cfg.py.in +++ b/debuginfo-tests/lit.site.cfg.py.in @@ -14,9 +14,10 @@ config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@" config.debuginfo_tests_obj_root = "@DEBUGINFO_TESTS_BINARY_DIR@" config.debuginfo_tests_src_root = "@DEBUGINFO_TESTS_SOURCE_DIR@" -config.has_lld = lit.util.pythonize_bool("@DEBUGINFO_TESTS_HAS_LLD@") config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@" +config.targets_to_build = "@TARGETS_TO_BUILD@" +config.enabled_projects = "@LLVM_ENABLE_PROJECTS@" config.host_arch = "@HOST_ARCH@" config.is_msvc = lit.util.pythonize_bool("@MSVC@") diff --git a/debuginfo-tests/symbolizer-tests/Inputs/test.h b/debuginfo-tests/symbolizer-tests/Inputs/test.h new file mode 100644 --- /dev/null +++ b/debuginfo-tests/symbolizer-tests/Inputs/test.h @@ -0,0 +1,3 @@ +extern "C" inline int foz() { + return 1234; +} diff --git a/debuginfo-tests/symbolizer-tests/Inputs/test.cpp b/debuginfo-tests/symbolizer-tests/Inputs/test.cpp new file mode 100644 --- /dev/null +++ b/debuginfo-tests/symbolizer-tests/Inputs/test.cpp @@ -0,0 +1,15 @@ +#include "test.h" +int bar=42; + +int foo() { + return bar; +} + +int baz() { + volatile int k = 42; + return foz() + k; +} + +int main() { + return foo() + baz(); +} diff --git a/debuginfo-tests/symbolizer-tests/example1.c b/debuginfo-tests/symbolizer-tests/example1.c new file mode 100644 --- /dev/null +++ b/debuginfo-tests/symbolizer-tests/example1.c @@ -0,0 +1,13 @@ +## Test case taken from the example in the llvm-symbolizer command guide. +# REQUIRES: clang, ld.lld, x86-registered-target + +# RUN: rm -rf %t.dir && mkdir %t.dir && cd %t.dir +# RUN: %clang -g %S/Inputs/test.cpp -c -o test.o -target x86_64-unknown-linux +# RUN: ld.lld test.o -o test.elf + +# RUN: llvm-symbolizer --obj=test.elf 0x201260 0x201210 | FileCheck %s '-DDIR=%S' +# CHECK: foz +# CHECK-NEXT: [[DIR]]{{[\\/]}}Inputs{{[\\/]}}test.h:1:0 +# CHECK-EMPTY: +# CHECK-NEXT: baz() +# CHECK-NEXT: [[DIR]]{{[\\/]}}Inputs{{[\\/]}}test.cpp:8:0 diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py --- a/llvm/utils/lit/lit/llvm/config.py +++ b/llvm/utils/lit/lit/llvm/config.py @@ -546,11 +546,15 @@ tool_substitutions = [] if ld_lld: tool_substitutions.append(ToolSubst(r'ld\.lld', command=ld_lld)) + self.config.available_features.add('ld.lld') if lld_link: tool_substitutions.append(ToolSubst('lld-link', command=lld_link)) + self.config.available_features.add('lld-link') if ld64_lld: tool_substitutions.append(ToolSubst(r'ld64\.lld', command=ld64_lld)) + self.config.available_features.add('ld64.lld') if wasm_ld: tool_substitutions.append(ToolSubst('wasm-ld', command=wasm_ld)) + self.config.available_features.add('wasm-lld') self.add_tool_substitutions(tool_substitutions) return was_found