From 178efe7379d37161b54dbe37628bd5ddd4f1758d Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 21 Nov 2017 01:20:28 +0000 Subject: Re-revert "Refactor debuginfo-tests." This is still breaking greendragon. At this point I give up until someone can fix the greendragon bots, and I will probably abandon this effort in favor of using a private github repository. --- clang/test/CMakeLists.txt | 8 -- clang/test/lit.cfg.py | 2 + debuginfo-tests/CMakeLists.txt | 46 ------- debuginfo-tests/aggregate-indirect-arg.cpp | 32 +++++ debuginfo-tests/asan-blocks.c | 41 ++++++ debuginfo-tests/asan.c | 31 +++++ debuginfo-tests/block_var.m | 32 +++++ debuginfo-tests/blocks.m | 43 +++++++ debuginfo-tests/ctor.cpp | 25 ++++ debuginfo-tests/dbg-arg.c | 46 +++++++ debuginfo-tests/foreach.m | 31 +++++ debuginfo-tests/forward-declare-class.cpp | 27 ++++ debuginfo-tests/lit.cfg.py | 59 --------- debuginfo-tests/lit.local.cfg | 3 + debuginfo-tests/lit.site.cfg.py.in | 25 ---- debuginfo-tests/llgdb.py | 157 +++++++++++++++++++++++ debuginfo-tests/nested-struct.cpp | 21 +++ debuginfo-tests/nrvo-string.cpp | 27 ++++ debuginfo-tests/safestack.c | 51 ++++++++ debuginfo-tests/sret.cpp | 71 ++++++++++ debuginfo-tests/stack-var.c | 18 +++ debuginfo-tests/static-member-2.cpp | 39 ++++++ debuginfo-tests/static-member.cpp | 36 ++++++ debuginfo-tests/tests/aggregate-indirect-arg.cpp | 32 ----- debuginfo-tests/tests/asan-blocks.c | 41 ------ debuginfo-tests/tests/asan.c | 31 ----- debuginfo-tests/tests/block_var.m | 32 ----- debuginfo-tests/tests/blocks.m | 43 ------- debuginfo-tests/tests/ctor.cpp | 25 ---- debuginfo-tests/tests/dbg-arg.c | 46 ------- debuginfo-tests/tests/foreach.m | 31 ----- debuginfo-tests/tests/forward-declare-class.cpp | 27 ---- debuginfo-tests/tests/lit.local.cfg | 3 - debuginfo-tests/tests/llgdb.py | 157 ----------------------- debuginfo-tests/tests/nested-struct.cpp | 21 --- debuginfo-tests/tests/nrvo-string.cpp | 27 ---- debuginfo-tests/tests/safestack.c | 51 -------- debuginfo-tests/tests/sret.cpp | 71 ---------- debuginfo-tests/tests/stack-var.c | 18 --- debuginfo-tests/tests/static-member-2.cpp | 39 ------ debuginfo-tests/tests/static-member.cpp | 36 ------ debuginfo-tests/tests/vla.c | 24 ---- debuginfo-tests/vla.c | 24 ++++ llvm/CMakeLists.txt | 19 +-- llvm/projects/CMakeLists.txt | 1 - llvm/utils/lit/lit/llvm/config.py | 9 +- llvm/utils/test_debuginfo.pl | 2 +- 47 files changed, 768 insertions(+), 913 deletions(-) delete mode 100644 debuginfo-tests/CMakeLists.txt create mode 100644 debuginfo-tests/aggregate-indirect-arg.cpp create mode 100644 debuginfo-tests/asan-blocks.c create mode 100644 debuginfo-tests/asan.c create mode 100644 debuginfo-tests/block_var.m create mode 100644 debuginfo-tests/blocks.m create mode 100644 debuginfo-tests/ctor.cpp create mode 100644 debuginfo-tests/dbg-arg.c create mode 100644 debuginfo-tests/foreach.m create mode 100644 debuginfo-tests/forward-declare-class.cpp delete mode 100644 debuginfo-tests/lit.cfg.py create mode 100644 debuginfo-tests/lit.local.cfg delete mode 100644 debuginfo-tests/lit.site.cfg.py.in create mode 100644 debuginfo-tests/llgdb.py create mode 100644 debuginfo-tests/nested-struct.cpp create mode 100644 debuginfo-tests/nrvo-string.cpp create mode 100644 debuginfo-tests/safestack.c create mode 100644 debuginfo-tests/sret.cpp create mode 100644 debuginfo-tests/stack-var.c create mode 100644 debuginfo-tests/static-member-2.cpp create mode 100644 debuginfo-tests/static-member.cpp delete mode 100644 debuginfo-tests/tests/aggregate-indirect-arg.cpp delete mode 100644 debuginfo-tests/tests/asan-blocks.c delete mode 100644 debuginfo-tests/tests/asan.c delete mode 100644 debuginfo-tests/tests/block_var.m delete mode 100644 debuginfo-tests/tests/blocks.m delete mode 100644 debuginfo-tests/tests/ctor.cpp delete mode 100644 debuginfo-tests/tests/dbg-arg.c delete mode 100644 debuginfo-tests/tests/foreach.m delete mode 100644 debuginfo-tests/tests/forward-declare-class.cpp delete mode 100644 debuginfo-tests/tests/lit.local.cfg delete mode 100644 debuginfo-tests/tests/llgdb.py delete mode 100644 debuginfo-tests/tests/nested-struct.cpp delete mode 100644 debuginfo-tests/tests/nrvo-string.cpp delete mode 100644 debuginfo-tests/tests/safestack.c delete mode 100644 debuginfo-tests/tests/sret.cpp delete mode 100644 debuginfo-tests/tests/stack-var.c delete mode 100644 debuginfo-tests/tests/static-member-2.cpp delete mode 100644 debuginfo-tests/tests/static-member.cpp delete mode 100644 debuginfo-tests/tests/vla.c create mode 100644 debuginfo-tests/vla.c diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 3bf69bf84b2..c1ac9e4f0f9 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -88,14 +88,6 @@ set(CLANG_TEST_PARAMS clang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg ) -if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/debuginfo-tests/CMakeLists.txt") - # This is a hack to keep existing build build infrastructure working while we - # can migrate to the new standard workflow of checking out debuginfo-tests into - # llvm/projects or using it in a mono-repo - set(DEBUGINFO_TESTS_EXCLUDE_FROM_ALL ON) - add_subdirectory(debuginfo-tests) -endif() - if( NOT CLANG_BUILT_STANDALONE ) list(APPEND CLANG_TEST_DEPS llvm-config diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py index d2f0491821d..39bdf36afd1 100644 --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -58,6 +58,8 @@ tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] tools = [ 'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'opt', + ToolSubst('%test_debuginfo', command=os.path.join( + config.llvm_src_root, 'utils', 'test_debuginfo.pl')), ToolSubst('%clang_func_map', command=FindTool( 'clang-func-mapping'), unresolved='ignore'), ] diff --git a/debuginfo-tests/CMakeLists.txt b/debuginfo-tests/CMakeLists.txt deleted file mode 100644 index 5c4b1701243..00000000000 --- a/debuginfo-tests/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -# 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. - -if (DEBUGINFO_TESTS_EXCLUDE_FROM_ALL) - # When run from inside of the clang tree, lit will pick up two different - # test suites. It will pick up debuginfo-tests as a standalone test - # suite since it has a lit.cfg, but it will also run because it will - # be identified as a subsuite of clang during discovery. We rely on - # clang to set this so that this configuration only gets picked up - # once. - set(EXCLUDE_FROM_ALL ON) -endif() - -set(DEBUGINFO_TESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(DEBUGINFO_TESTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) - -set(DEBUGINFO_TEST_DEPS - clang - llvm-config - FileCheck - count - not - ) - -get_target_property(CLANG_SOURCE_DIR clang SOURCE_DIR) - -if (TARGET lld) - set(DEBUGINFO_TESTS_HAS_LLD 1) - list(APPEND DEBUGINFO_TEST_DEPS lld) - get_target_property(LLD_SOURCE_DIR lld SOURCE_DIR) -endif() - -configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in - ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py - MAIN_CONFIG - ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py - ) - -add_lit_testsuite(check-debuginfo "Running debug info integration tests" - ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${DEBUGINFO_TEST_DEPS} - ) - -set_target_properties(check-debuginfo PROPERTIES FOLDER "Debug info tests") \ No newline at end of file diff --git a/debuginfo-tests/aggregate-indirect-arg.cpp b/debuginfo-tests/aggregate-indirect-arg.cpp new file mode 100644 index 00000000000..86c7caf9618 --- /dev/null +++ b/debuginfo-tests/aggregate-indirect-arg.cpp @@ -0,0 +1,32 @@ +// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out +// RUN: %test_debuginfo %s %t.out +// Radar 8945514 +// DEBUGGER: break 22 +// DEBUGGER: r +// DEBUGGER: p v +// CHECK: ${{[0-9]+}} = +// CHECK: Data ={{.*}} 0x0{{(0*)}} +// CHECK: Kind = 2142 + +class SVal { +public: + ~SVal() {} + const void* Data; + unsigned Kind; +}; + +void bar(SVal &v) {} +class A { +public: + void foo(SVal v) { bar(v); } +}; + +int main() { + SVal v; + v.Data = 0; + v.Kind = 2142; + A a; + a.foo(v); + return 0; +} diff --git a/debuginfo-tests/asan-blocks.c b/debuginfo-tests/asan-blocks.c new file mode 100644 index 00000000000..b919a291eba --- /dev/null +++ b/debuginfo-tests/asan-blocks.c @@ -0,0 +1,41 @@ +// RUN: %clang -fblocks %target_itanium_abi_host_triple -arch x86_64 %s -o %t.out -g -fsanitize=address +// RUN: %test_debuginfo %s %t.out +// FIXME: Remove system-darwin when we build BlocksRuntime everywhere. +// REQUIRES: not_asan, system-darwin +// Zorg configures the ASAN stage2 bots to not build the asan +// compiler-rt. Only run this test on non-asanified configurations. +void b(); +struct S { + int a[8]; +}; + +int f(struct S s, unsigned i) { + // DEBUGGER: break 17 + // DEBUGGER: r + // DEBUGGER: p s + // CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7) + return s.a[i]; +} + +int main(int argc, const char **argv) { + struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}}; + if (f(s, 4) == 4) { + // DEBUGGER: break 27 + // DEBUGGER: c + // DEBUGGER: p s + // CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7) + b(); + } + return 0; +} + +void c() {} + +void b() { + // DEBUGGER: break 40 + // DEBUGGER: c + // DEBUGGER: p x + // CHECK: 42 + __block int x = 42; + c(); +} diff --git a/debuginfo-tests/asan.c b/debuginfo-tests/asan.c new file mode 100644 index 00000000000..a2df7545722 --- /dev/null +++ b/debuginfo-tests/asan.c @@ -0,0 +1,31 @@ +// RUN: %clang -fblocks %target_itanium_abi_host_triple -arch x86_64 %s -o %t.out -g -fsanitize=address +// RUN: %test_debuginfo %s %t.out +// REQUIRES: not_asan +// Zorg configures the ASAN stage2 bots to not build the asan +// compiler-rt. Only run this test on non-asanified configurations. +// + +struct S { + int a[8]; +}; + +int f(struct S s, unsigned i) { + // DEBUGGER: break 14 + return s.a[i]; +} + +int main(int argc, const char **argv) { + struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}}; + if (f(s, 4) == 4) + return f(s, 0); + return 0; +} + +// DEBUGGER: r +// DEBUGGER: p s +// CHECK: a = +// DEBUGGER: p s.a[0] +// CHECK: = 0 +// DEBUGGER: p s.a[1] +// CHECK: = 1 +// DEBUGGER: p s.a[7] diff --git a/debuginfo-tests/block_var.m b/debuginfo-tests/block_var.m new file mode 100644 index 00000000000..7ec786f1798 --- /dev/null +++ b/debuginfo-tests/block_var.m @@ -0,0 +1,32 @@ +// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out -framework Foundation +// RUN: %test_debuginfo %s %t.out + +// REQUIRES: system-darwin + +// DEBUGGER: break 24 +// DEBUGGER: r +// DEBUGGER: p result +// CHECK: ${{[0-9]}} = 42 + +void doBlock(void (^block)(void)) +{ + block(); +} + +int I(int n) +{ + __block int result; + int i = 2; + doBlock(^{ + result = n; + }); + return result + i; /* Check value of 'result' */ +} + + +int main (int argc, const char * argv[]) { + return I(42); +} + + diff --git a/debuginfo-tests/blocks.m b/debuginfo-tests/blocks.m new file mode 100644 index 00000000000..8e5a2121320 --- /dev/null +++ b/debuginfo-tests/blocks.m @@ -0,0 +1,43 @@ +// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out -framework Foundation +// RUN: %test_debuginfo %s %t.out + +// REQUIRES: system-darwin +// Radar 9279956 + +// DEBUGGER: break 31 +// DEBUGGER: r +// DEBUGGER: p m2 +// CHECK: ${{[0-9]}} = 1 +// DEBUGGER: p dbTransaction +// CHECK: ${{[0-9]}} = 0 +// DEBUGGER: p master +// CHECK: ${{[0-9]}} = 0 + +#include + +extern void foo(void(^)(void)); + +@interface A:NSObject @end +@implementation A +- (void) helper { + int master = 0; + __block int m2 = 0; + __block int dbTransaction = 0; + int (^x)(void) = ^(void) { (void) self; + (void) master; + (void) dbTransaction; + m2++; + return m2; + }; + master = x(); +} +@end + +void foo(void(^x)(void)) {} + +int main() { + A *a = [A alloc]; + [a helper]; + return 0; +} diff --git a/debuginfo-tests/ctor.cpp b/debuginfo-tests/ctor.cpp new file mode 100644 index 00000000000..92cdbcd7e0b --- /dev/null +++ b/debuginfo-tests/ctor.cpp @@ -0,0 +1,25 @@ +// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out +// RUN: %test_debuginfo %s %t.out + + +// DEBUGGER: break 14 +// DEBUGGER: r +// DEBUGGER: p *this +// CHECK-NEXT-NOT: Cannot access memory at address + +class A { +public: + A() : zero(0), data(42) + { + } +private: + int zero; + int data; +}; + +int main() { + A a; + return 0; +} + diff --git a/debuginfo-tests/dbg-arg.c b/debuginfo-tests/dbg-arg.c new file mode 100644 index 00000000000..a65dc910b8b --- /dev/null +++ b/debuginfo-tests/dbg-arg.c @@ -0,0 +1,46 @@ +// This test case checks debug info during register moves for an argument. +// RUN: %clang %target_itanium_abi_host_triple -m64 -mllvm -fast-isel=false %s -c -o %t.o -g +// RUN: %clang %target_itanium_abi_host_triple -m64 %t.o -o %t.out +// RUN: %test_debuginfo %s %t.out +// +// DEBUGGER: break 26 +// DEBUGGER: r +// DEBUGGER: print mutex +// CHECK: ={{.* 0x[0-9A-Fa-f]+}} +// +// Radar 8412415 + +struct _mtx +{ + long unsigned int ptr; + int waiters; + struct { + int tag; + int pad; + } mtxi; +}; + + +int foobar(struct _mtx *mutex) { + int r = 1; + int l = 0; + int j = 0; + do { + if (mutex->waiters) { + r = 2; + } + j = bar(r, l); + ++l; + } while (l < j); + return r + j; +} + +int bar(int i, int j) { + return i + j; +} + +int main() { + struct _mtx m; + m.waiters = 0; + return foobar(&m); +} diff --git a/debuginfo-tests/foreach.m b/debuginfo-tests/foreach.m new file mode 100644 index 00000000000..2e3c312c877 --- /dev/null +++ b/debuginfo-tests/foreach.m @@ -0,0 +1,31 @@ +// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out -framework Foundation +// RUN: %test_debuginfo %s %t.out +// +// REQUIRES: system-darwin +// Radar 8757124 + +// DEBUGGER: break 25 +// DEBUGGER: r +// DEBUGGER: po thing +// CHECK: aaa + +#import + +int main (int argc, const char * argv[]) { + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSArray *things = [NSArray arrayWithObjects:@"one", @"two", @"three" , nil]; + for (NSString *thing in things) { + NSLog (@"%@", thing); + } + + things = [NSArray arrayWithObjects:@"aaa", @"bbb", @"ccc" , nil]; + for (NSString *thing in things) { + NSLog (@"%@", thing); + } + [pool release]; + return 0; +} + + diff --git a/debuginfo-tests/forward-declare-class.cpp b/debuginfo-tests/forward-declare-class.cpp new file mode 100644 index 00000000000..132420009bd --- /dev/null +++ b/debuginfo-tests/forward-declare-class.cpp @@ -0,0 +1,27 @@ +// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %test_debuginfo %s %t.o +// Radar 9168773 + +// DEBUGGER: ptype A +// Work around a gdb bug where it believes that a class is a +// struct if there aren't any methods - even though it's tagged +// as a class. +// CHECK: type = {{struct|class}} A { +// CHECK-NEXT: {{(public:){0,1}}} +// CHECK-NEXT: int MyData; +// CHECK-NEXT: } +class A; +class B { +public: + void foo(const A *p); +}; + +B iEntry; + +class A { +public: + int MyData; +}; + +A irp; + diff --git a/debuginfo-tests/lit.cfg.py b/debuginfo-tests/lit.cfg.py deleted file mode 100644 index f754cef8459..00000000000 --- a/debuginfo-tests/lit.cfg.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- Python -*- - -import os -import platform -import re -import subprocess -import tempfile - -import lit.formats -import lit.util - -from lit.llvm import llvm_config -from lit.llvm.subst import ToolSubst -from lit.llvm.subst import FindTool - -# Configuration file for the 'lit' test runner. - -# name: The name of this test suite. -config.name = 'debuginfo-tests' - -# testFormat: The test format to use to interpret tests. -# -# For now we require '&&' between commands, until they get globally killed and -# the test runner updated. -config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) - -# suffixes: A list of file extensions to treat as test files. -config.suffixes = ['.c', '.cpp', '.m'] - -# excludes: A list of directories to exclude from the testsuite. The 'Inputs' -# subdirectories contain auxiliary inputs for various tests in their parent -# directories. -config.excludes = ['Inputs'] - -# test_source_root: The root path where tests are located. -config.test_source_root = os.path.join(config.debuginfo_tests_src_root, 'tests') - -# test_exec_root: The root path where tests should be run. -config.test_exec_root = config.debuginfo_tests_obj_root - -llvm_config.use_default_substitutions() - -llvm_config.use_clang() - -if config.llvm_use_sanitizer: - # Propagate path to symbolizer for ASan/MSan. - llvm_config.with_system_environment( - ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) - -tool_dirs = [config.llvm_tools_dir] - -tools = [ - ToolSubst('%test_debuginfo', command=os.path.join( - config.llvm_src_root, 'utils', 'test_debuginfo.pl')), -] - -llvm_config.add_tool_substitutions(tools, tool_dirs) - -lit.util.usePlatformSdkOnDarwin(config, lit_config) diff --git a/debuginfo-tests/lit.local.cfg b/debuginfo-tests/lit.local.cfg new file mode 100644 index 00000000000..ce0175cf7f9 --- /dev/null +++ b/debuginfo-tests/lit.local.cfg @@ -0,0 +1,3 @@ +# debuginfo-tests are not expected to pass in a cross-compilation setup. +if 'native' not in config.available_features: + config.unsupported = True diff --git a/debuginfo-tests/lit.site.cfg.py.in b/debuginfo-tests/lit.site.cfg.py.in deleted file mode 100644 index 8c4481a9f94..00000000000 --- a/debuginfo-tests/lit.site.cfg.py.in +++ /dev/null @@ -1,25 +0,0 @@ -@LIT_SITE_CFG_IN_HEADER@ - -import lit.util - -config.test_exec_root = "@CMAKE_BINARY_DIR@" - -config.llvm_src_root = "@LLVM_SOURCE_DIR@" -config.llvm_obj_root = "@LLVM_BINARY_DIR@" -config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" -config.llvm_libs_dir = "@LLVM_LIBS_DIR@" -config.llvm_shlib_dir = "@SHLIBDIR@" -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.host_arch = "@HOST_ARCH@" - -config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" - -@LIT_SITE_CFG_IN_FOOTER@ - -# Let the main config do the real work. -lit_config.load_config(config, "@DEBUGINFO_TESTS_SOURCE_DIR@/lit.cfg.py") diff --git a/debuginfo-tests/llgdb.py b/debuginfo-tests/llgdb.py new file mode 100644 index 00000000000..7d4fdd64fd1 --- /dev/null +++ b/debuginfo-tests/llgdb.py @@ -0,0 +1,157 @@ +#!/bin/env python +""" +A gdb-compatible frontend for lldb that implements just enough +commands to run the tests in the debuginfo-tests repository with lldb. +""" + +# ---------------------------------------------------------------------- +# Auto-detect lldb python module. +import commands, platform, os, sys +try: + # Just try for LLDB in case PYTHONPATH is already correctly setup. + import lldb +except ImportError: + lldb_python_dirs = list() + # lldb is not in the PYTHONPATH, try some defaults for the current platform. + platform_system = platform.system() + if platform_system == 'Darwin': + # On Darwin, try the currently selected Xcode directory + xcode_dir = commands.getoutput("xcode-select --print-path") + if xcode_dir: + lldb_python_dirs.append(os.path.realpath(xcode_dir + +'/../SharedFrameworks/LLDB.framework/Resources/Python')) + lldb_python_dirs.append(xcode_dir + +'/Library/PrivateFrameworks/LLDB.framework/Resources/Python') + lldb_python_dirs.append( +'/System/Library/PrivateFrameworks/LLDB.framework/Resources/Python') + success = False + for lldb_python_dir in lldb_python_dirs: + if os.path.exists(lldb_python_dir): + if not (sys.path.__contains__(lldb_python_dir)): + sys.path.append(lldb_python_dir) + try: + import lldb + except ImportError: + pass + else: + print 'imported lldb from: "%s"' % (lldb_python_dir) + success = True + break + if not success: + print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly" + sys.exit(1) +# ---------------------------------------------------------------------- + +# Command line option handling. +import argparse +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument('--quiet', '-q', action="store_true", help='ignored') +parser.add_argument('-batch', action="store_true", + help='exit after processing comand line') +parser.add_argument('-n', action="store_true", help='ignore .lldb file') +parser.add_argument('-x', dest='script', type=file, help='execute commands from file') +parser.add_argument("target", help="the program to debug") +args = parser.parse_args() + + +# Create a new debugger instance. +debugger = lldb.SBDebugger.Create() +debugger.SkipLLDBInitFiles(args.n) + +# Don't return from lldb function calls until the process stops. +debugger.SetAsync(False) + +# Create a target from a file and arch. +arch = os.popen("file "+args.target).read().split()[-1] +target = debugger.CreateTargetWithFileAndArch(args.target, arch) + +if not target: + print "Could not create target", args.target + sys.exit(1) + +if not args.script: + print "Interactive mode is not implemented." + sys.exit(1) + +import re +for command in args.script: + # Strip newline and whitespaces and split into words. + cmd = command[:-1].strip().split() + if not cmd: + continue + + print '> %s'% command[:-1] + + try: + if re.match('^r|(run)$', cmd[0]): + error = lldb.SBError() + launchinfo = lldb.SBLaunchInfo([]) + launchinfo.SetWorkingDirectory(os.getcwd()) + process = target.Launch(launchinfo, error) + print error + if not process or error.fail: + state = process.GetState() + print "State = %d" % state + print """ +ERROR: Could not launch process. +NOTE: There are several reasons why this may happen: + * Root needs to run "DevToolsSecurity --enable". + * Older versions of lldb cannot launch more than one process simultaneously. +""" + sys.exit(1) + + elif re.match('^b|(break)$', cmd[0]) and len(cmd) == 2: + if re.match('[0-9]+', cmd[1]): + # b line + mainfile = target.FindFunctions('main')[0].compile_unit.file + print target.BreakpointCreateByLocation(mainfile, int(cmd[1])) + else: + # b file:line + file, line = cmd[1].split(':') + print target.BreakpointCreateByLocation(file, int(line)) + + elif re.match('^ptype$', cmd[0]) and len(cmd) == 2: + # GDB's ptype has multiple incarnations depending on its + # argument (global variable, function, type). The definition + # here is for looking up the signature of a function and only + # if that fails it looks for a type with that name. + # Type lookup in LLDB would be "image lookup --type". + for elem in target.FindFunctions(cmd[1]): + print elem.function.type + continue + print target.FindFirstType(cmd[1]) + + elif re.match('^po$', cmd[0]) and len(cmd) > 1: + try: + opts = lldb.SBExpressionOptions() + opts.SetFetchDynamicValue(True) + opts.SetCoerceResultToId(True) + print target.EvaluateExpression(' '.join(cmd[1:]), opts) + except: + # FIXME: This is a fallback path for the lab.llvm.org + # buildbot running OS X 10.7; it should be removed. + thread = process.GetThreadAtIndex(0) + frame = thread.GetFrameAtIndex(0) + print frame.EvaluateExpression(' '.join(cmd[1:])) + + elif re.match('^p|(print)$', cmd[0]) and len(cmd) > 1: + thread = process.GetThreadAtIndex(0) + frame = thread.GetFrameAtIndex(0) + print frame.EvaluateExpression(' '.join(cmd[1:])) + + elif re.match('^n|(next)$', cmd[0]): + thread = process.GetThreadAtIndex(0) + thread.StepOver() + + elif re.match('^q|(quit)$', cmd[0]): + sys.exit(0) + + else: + print debugger.HandleCommand(' '.join(cmd)) + + except SystemExit: + lldb.SBDebugger_Terminate() + raise + except: + print 'Could not handle the command "%s"' % ' '.join(cmd) + diff --git a/debuginfo-tests/nested-struct.cpp b/debuginfo-tests/nested-struct.cpp new file mode 100644 index 00000000000..7533e6a8151 --- /dev/null +++ b/debuginfo-tests/nested-struct.cpp @@ -0,0 +1,21 @@ +// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %test_debuginfo %s %t.o +// Radar 9440721 +// If debug info for my_number() is emitted outside function foo's scope +// then a debugger may not be able to handle it. At least one version of +// gdb crashes in such cases. + +// DEBUGGER: ptype foo +// CHECK: int (void) + +int foo() { + struct Local { + static int my_number() { + return 42; + } + }; + + int i = 0; + i = Local::my_number(); + return i + 1; +} diff --git a/debuginfo-tests/nrvo-string.cpp b/debuginfo-tests/nrvo-string.cpp new file mode 100644 index 00000000000..18acebb0e6d --- /dev/null +++ b/debuginfo-tests/nrvo-string.cpp @@ -0,0 +1,27 @@ +// This ensures that DW_OP_deref is inserted when necessary, such as when NRVO +// of a string object occurs in C++. +// +// RUN: %clangxx -O0 -fno-exceptions %target_itanium_abi_host_triple %s -o %t.out -g +// RUN: %test_debuginfo %s %t.out +// RUN: %clangxx -O1 -fno-exceptions %target_itanium_abi_host_triple %s -o %t.out -g +// RUN: %test_debuginfo %s %t.out +// +// PR34513 + +struct string { + string() {} + string(int i) : i(i) {} + ~string() {} + int i = 0; +}; +string get_string() { + string unused; + string result = 3; +// DEBUGGER: break 21 + return result; +} +int main() { get_string(); } + +// DEBUGGER: r +// DEBUGGER: print result.i +// CHECK: = 3 diff --git a/debuginfo-tests/safestack.c b/debuginfo-tests/safestack.c new file mode 100644 index 00000000000..01c5f7ede92 --- /dev/null +++ b/debuginfo-tests/safestack.c @@ -0,0 +1,51 @@ +// RUN: %clang %target_itanium_abi_host_triple -arch x86_64 %s -o %t.out -g -fsanitize=safe-stack +// RUN: %test_debuginfo %s %t.out +// REQUIRES: not_asan +// Zorg configures the ASAN stage2 bots to not build the +// safestack compiler-rt. Only run this test on +// non-asanified configurations. + +struct S { + int a[8]; +}; + +int f(struct S s, unsigned i); + +int main(int argc, const char **argv) { + struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}}; + // DEBUGGER: break 17 + f(s, 4); + // DEBUGGER: break 19 + return 0; +} + +int f(struct S s, unsigned i) { + // DEBUGGER: break 24 + return s.a[i]; +} + +// DEBUGGER: r +// DEBUGGER: p s +// CHECK: a = +// DEBUGGER: p s.a[0] +// CHECK: = 0 +// DEBUGGER: p s.a[1] +// CHECK: = 1 +// DEBUGGER: p s.a[7] +// CHECK: = 7 +// DEBUGGER: c +// DEBUGGER: p s +// CHECK: a = +// DEBUGGER: p s.a[0] +// CHECK: = 0 +// DEBUGGER: p s.a[1] +// CHECK: = 1 +// DEBUGGER: p s.a[7] +// DEBUGGER: c +// DEBUGGER: p s +// CHECK: a = +// DEBUGGER: p s.a[0] +// CHECK: = 0 +// DEBUGGER: p s.a[1] +// CHECK: = 1 +// DEBUGGER: p s.a[7] diff --git a/debuginfo-tests/sret.cpp b/debuginfo-tests/sret.cpp new file mode 100644 index 00000000000..3c304e2f04a --- /dev/null +++ b/debuginfo-tests/sret.cpp @@ -0,0 +1,71 @@ +// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out +// RUN: %test_debuginfo %s %t.out +// Radar 8775834 +// DEBUGGER: break 62 +// DEBUGGER: r +// DEBUGGER: p a +// CHECK: ${{[0-9]+}} = +// LLDB does not print artificial members. +// CHECK: {{(_vptr\$A =)?.*}}m_int = 12 + +class A +{ +public: + A (int i=0); + A (const A& rhs); + const A& + operator= (const A& rhs); + virtual ~A() {} + + int get_int(); + +protected: + int m_int; +}; + +A::A (int i) : + m_int(i) +{ +} + +A::A (const A& rhs) : + m_int (rhs.m_int) +{ +} + +const A & +A::operator =(const A& rhs) +{ + m_int = rhs.m_int; + return *this; +} + +int A::get_int() +{ + return m_int; +} + +class B +{ +public: + B () {} + + A AInstance(); +}; + +A +B::AInstance() +{ + A a(12); + return a; +} + +int main (int argc, char const *argv[]) +{ + B b; + int return_val = b.AInstance().get_int(); + + A a(b.AInstance()); + return return_val; +} diff --git a/debuginfo-tests/stack-var.c b/debuginfo-tests/stack-var.c new file mode 100644 index 00000000000..372139c59b0 --- /dev/null +++ b/debuginfo-tests/stack-var.c @@ -0,0 +1,18 @@ +// RUN: %clang %target_itanium_abi_host_triple %s -O -o %t.out -g +// RUN: %test_debuginfo %s %t.out + +void __attribute__((noinline, optnone)) bar(int *test) {} +int main() { + int test; + test = 23; + // DEBUGGER: break 12 + // DEBUGGER: r + // DEBUGGER: p test + // CHECK: = 23 + bar(&test); + // DEBUGGER: break 17 + // DEBUGGER: c + // DEBUGGER: p test + // CHECK: = 23 + return test; +} diff --git a/debuginfo-tests/static-member-2.cpp b/debuginfo-tests/static-member-2.cpp new file mode 100644 index 00000000000..4edb2b060f1 --- /dev/null +++ b/debuginfo-tests/static-member-2.cpp @@ -0,0 +1,39 @@ +// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -o %t -c +// RUN: %clangxx %target_itanium_abi_host_triple %t -o %t.out +// RUN: %test_debuginfo %s %t.out + +// FIXME: LLDB finds the wrong symbol for "C". rdar://problem/14933867 +// XFAIL: darwin + +// DEBUGGER: delete breakpoints +// DEBUGGER: break static-member.cpp:33 +// DEBUGGER: r +// DEBUGGER: ptype C +// CHECK: {{struct|class}} C { +// CHECK: static const int a; +// CHECK-NEXT: static int b; +// CHECK-NEXT: static int c; +// CHECK-NEXT: int d; +// CHECK-NEXT: } +// DEBUGGER: p C::a +// CHECK: ${{[0-9]}} = 4 +// DEBUGGER: p C::c +// CHECK: ${{[0-9]}} = 15 + +// PR14471, PR14734 + +class C { +public: + const static int a = 4; + static int b; + static int c; + int d; +}; + +int C::c = 15; +const int C::a; + +int main() { + C instance_C; + return C::a; +} diff --git a/debuginfo-tests/static-member.cpp b/debuginfo-tests/static-member.cpp new file mode 100644 index 00000000000..1d8ad62c5b8 --- /dev/null +++ b/debuginfo-tests/static-member.cpp @@ -0,0 +1,36 @@ +// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -o %t -c +// RUN: %clangxx %target_itanium_abi_host_triple %t -o %t.out +// RUN: %test_debuginfo %s %t.out + +// DEBUGGER: delete breakpoints +// DEBUGGER: break static-member.cpp:33 +// DEBUGGER: r +// DEBUGGER: ptype MyClass +// CHECK: {{struct|class}} MyClass { +// CHECK: static const int a; +// CHECK-NEXT: static int b; +// CHECK-NEXT: static int c; +// CHECK-NEXT: int d; +// CHECK-NEXT: } +// DEBUGGER: p MyClass::a +// CHECK: ${{[0-9]}} = 4 +// DEBUGGER: p MyClass::c +// CHECK: ${{[0-9]}} = 15 + +// PR14471, PR14734 + +class MyClass { +public: + const static int a = 4; + static int b; + static int c; + int d; +}; + +int MyClass::c = 15; +const int MyClass::a; + +int main() { + MyClass instance_MyClass; + return MyClass::a; +} diff --git a/debuginfo-tests/tests/aggregate-indirect-arg.cpp b/debuginfo-tests/tests/aggregate-indirect-arg.cpp deleted file mode 100644 index eb2fd665cf6..00000000000 --- a/debuginfo-tests/tests/aggregate-indirect-arg.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out -// RUN: %test_debuginfo %s %t.out -// Radar 8945514 -// DEBUGGER: break 22 -// DEBUGGER: r -// DEBUGGER: p v -// CHECK: ${{[0-9]+}} = -// CHECK: Data ={{.*}} 0x0{{(0*)}} -// CHECK: Kind = 2142 - -class SVal { -public: - ~SVal() {} - const void* Data; - unsigned Kind; -}; - -void bar(SVal &v) {} -class A { -public: - void foo(SVal v) { bar(v); } -}; - -int main() { - SVal v; - v.Data = 0; - v.Kind = 2142; - A a; - a.foo(v); - return 0; -} diff --git a/debuginfo-tests/tests/asan-blocks.c b/debuginfo-tests/tests/asan-blocks.c deleted file mode 100644 index b919a291eba..00000000000 --- a/debuginfo-tests/tests/asan-blocks.c +++ /dev/null @@ -1,41 +0,0 @@ -// RUN: %clang -fblocks %target_itanium_abi_host_triple -arch x86_64 %s -o %t.out -g -fsanitize=address -// RUN: %test_debuginfo %s %t.out -// FIXME: Remove system-darwin when we build BlocksRuntime everywhere. -// REQUIRES: not_asan, system-darwin -// Zorg configures the ASAN stage2 bots to not build the asan -// compiler-rt. Only run this test on non-asanified configurations. -void b(); -struct S { - int a[8]; -}; - -int f(struct S s, unsigned i) { - // DEBUGGER: break 17 - // DEBUGGER: r - // DEBUGGER: p s - // CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7) - return s.a[i]; -} - -int main(int argc, const char **argv) { - struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}}; - if (f(s, 4) == 4) { - // DEBUGGER: break 27 - // DEBUGGER: c - // DEBUGGER: p s - // CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7) - b(); - } - return 0; -} - -void c() {} - -void b() { - // DEBUGGER: break 40 - // DEBUGGER: c - // DEBUGGER: p x - // CHECK: 42 - __block int x = 42; - c(); -} diff --git a/debuginfo-tests/tests/asan.c b/debuginfo-tests/tests/asan.c deleted file mode 100644 index a2df7545722..00000000000 --- a/debuginfo-tests/tests/asan.c +++ /dev/null @@ -1,31 +0,0 @@ -// RUN: %clang -fblocks %target_itanium_abi_host_triple -arch x86_64 %s -o %t.out -g -fsanitize=address -// RUN: %test_debuginfo %s %t.out -// REQUIRES: not_asan -// Zorg configures the ASAN stage2 bots to not build the asan -// compiler-rt. Only run this test on non-asanified configurations. -// - -struct S { - int a[8]; -}; - -int f(struct S s, unsigned i) { - // DEBUGGER: break 14 - return s.a[i]; -} - -int main(int argc, const char **argv) { - struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}}; - if (f(s, 4) == 4) - return f(s, 0); - return 0; -} - -// DEBUGGER: r -// DEBUGGER: p s -// CHECK: a = -// DEBUGGER: p s.a[0] -// CHECK: = 0 -// DEBUGGER: p s.a[1] -// CHECK: = 1 -// DEBUGGER: p s.a[7] diff --git a/debuginfo-tests/tests/block_var.m b/debuginfo-tests/tests/block_var.m deleted file mode 100644 index 32862172c57..00000000000 --- a/debuginfo-tests/tests/block_var.m +++ /dev/null @@ -1,32 +0,0 @@ -// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out -framework Foundation -// RUN: %test_debuginfo %s %t.out - -// REQUIRES: system-darwin - -// DEBUGGER: break 24 -// DEBUGGER: r -// DEBUGGER: p result -// CHECK: ${{[0-9]}} = 42 - -void doBlock(void (^block)(void)) -{ - block(); -} - -int I(int n) -{ - __block int result; - int i = 2; - doBlock(^{ - result = n; - }); - return result + i; /* Check value of 'result' */ -} - - -int main (int argc, const char * argv[]) { - return I(42); -} - - diff --git a/debuginfo-tests/tests/blocks.m b/debuginfo-tests/tests/blocks.m deleted file mode 100644 index 12c99774a31..00000000000 --- a/debuginfo-tests/tests/blocks.m +++ /dev/null @@ -1,43 +0,0 @@ -// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out -framework Foundation -// RUN: %test_debuginfo %s %t.out - -// REQUIRES: system-darwin -// Radar 9279956 - -// DEBUGGER: break 31 -// DEBUGGER: r -// DEBUGGER: p m2 -// CHECK: ${{[0-9]}} = 1 -// DEBUGGER: p dbTransaction -// CHECK: ${{[0-9]}} = 0 -// DEBUGGER: p master -// CHECK: ${{[0-9]}} = 0 - -#include - -extern void foo(void(^)(void)); - -@interface A:NSObject @end -@implementation A -- (void) helper { - int master = 0; - __block int m2 = 0; - __block int dbTransaction = 0; - int (^x)(void) = ^(void) { (void) self; - (void) master; - (void) dbTransaction; - m2++; - return m2; - }; - master = x(); -} -@end - -void foo(void(^x)(void)) {} - -int main() { - A *a = [A alloc]; - [a helper]; - return 0; -} diff --git a/debuginfo-tests/tests/ctor.cpp b/debuginfo-tests/tests/ctor.cpp deleted file mode 100644 index 364401a2d5c..00000000000 --- a/debuginfo-tests/tests/ctor.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out -// RUN: %test_debuginfo %s %t.out - - -// DEBUGGER: break 14 -// DEBUGGER: r -// DEBUGGER: p *this -// CHECK-NEXT-NOT: Cannot access memory at address - -class A { -public: - A() : zero(0), data(42) - { - } -private: - int zero; - int data; -}; - -int main() { - A a; - return 0; -} - diff --git a/debuginfo-tests/tests/dbg-arg.c b/debuginfo-tests/tests/dbg-arg.c deleted file mode 100644 index a65dc910b8b..00000000000 --- a/debuginfo-tests/tests/dbg-arg.c +++ /dev/null @@ -1,46 +0,0 @@ -// This test case checks debug info during register moves for an argument. -// RUN: %clang %target_itanium_abi_host_triple -m64 -mllvm -fast-isel=false %s -c -o %t.o -g -// RUN: %clang %target_itanium_abi_host_triple -m64 %t.o -o %t.out -// RUN: %test_debuginfo %s %t.out -// -// DEBUGGER: break 26 -// DEBUGGER: r -// DEBUGGER: print mutex -// CHECK: ={{.* 0x[0-9A-Fa-f]+}} -// -// Radar 8412415 - -struct _mtx -{ - long unsigned int ptr; - int waiters; - struct { - int tag; - int pad; - } mtxi; -}; - - -int foobar(struct _mtx *mutex) { - int r = 1; - int l = 0; - int j = 0; - do { - if (mutex->waiters) { - r = 2; - } - j = bar(r, l); - ++l; - } while (l < j); - return r + j; -} - -int bar(int i, int j) { - return i + j; -} - -int main() { - struct _mtx m; - m.waiters = 0; - return foobar(&m); -} diff --git a/debuginfo-tests/tests/foreach.m b/debuginfo-tests/tests/foreach.m deleted file mode 100644 index ccdc2827fd1..00000000000 --- a/debuginfo-tests/tests/foreach.m +++ /dev/null @@ -1,31 +0,0 @@ -// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out -framework Foundation -// RUN: %test_debuginfo %s %t.out -// -// REQUIRES: system-darwin -// Radar 8757124 - -// DEBUGGER: break 25 -// DEBUGGER: r -// DEBUGGER: po thing -// CHECK: aaa - -#import - -int main (int argc, const char * argv[]) { - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSArray *things = [NSArray arrayWithObjects:@"one", @"two", @"three" , nil]; - for (NSString *thing in things) { - NSLog (@"%@", thing); - } - - things = [NSArray arrayWithObjects:@"aaa", @"bbb", @"ccc" , nil]; - for (NSString *thing in things) { - NSLog (@"%@", thing); - } - [pool release]; - return 0; -} - - diff --git a/debuginfo-tests/tests/forward-declare-class.cpp b/debuginfo-tests/tests/forward-declare-class.cpp deleted file mode 100644 index 132420009bd..00000000000 --- a/debuginfo-tests/tests/forward-declare-class.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %test_debuginfo %s %t.o -// Radar 9168773 - -// DEBUGGER: ptype A -// Work around a gdb bug where it believes that a class is a -// struct if there aren't any methods - even though it's tagged -// as a class. -// CHECK: type = {{struct|class}} A { -// CHECK-NEXT: {{(public:){0,1}}} -// CHECK-NEXT: int MyData; -// CHECK-NEXT: } -class A; -class B { -public: - void foo(const A *p); -}; - -B iEntry; - -class A { -public: - int MyData; -}; - -A irp; - diff --git a/debuginfo-tests/tests/lit.local.cfg b/debuginfo-tests/tests/lit.local.cfg deleted file mode 100644 index ce0175cf7f9..00000000000 --- a/debuginfo-tests/tests/lit.local.cfg +++ /dev/null @@ -1,3 +0,0 @@ -# debuginfo-tests are not expected to pass in a cross-compilation setup. -if 'native' not in config.available_features: - config.unsupported = True diff --git a/debuginfo-tests/tests/llgdb.py b/debuginfo-tests/tests/llgdb.py deleted file mode 100644 index 7d4fdd64fd1..00000000000 --- a/debuginfo-tests/tests/llgdb.py +++ /dev/null @@ -1,157 +0,0 @@ -#!/bin/env python -""" -A gdb-compatible frontend for lldb that implements just enough -commands to run the tests in the debuginfo-tests repository with lldb. -""" - -# ---------------------------------------------------------------------- -# Auto-detect lldb python module. -import commands, platform, os, sys -try: - # Just try for LLDB in case PYTHONPATH is already correctly setup. - import lldb -except ImportError: - lldb_python_dirs = list() - # lldb is not in the PYTHONPATH, try some defaults for the current platform. - platform_system = platform.system() - if platform_system == 'Darwin': - # On Darwin, try the currently selected Xcode directory - xcode_dir = commands.getoutput("xcode-select --print-path") - if xcode_dir: - lldb_python_dirs.append(os.path.realpath(xcode_dir + -'/../SharedFrameworks/LLDB.framework/Resources/Python')) - lldb_python_dirs.append(xcode_dir + -'/Library/PrivateFrameworks/LLDB.framework/Resources/Python') - lldb_python_dirs.append( -'/System/Library/PrivateFrameworks/LLDB.framework/Resources/Python') - success = False - for lldb_python_dir in lldb_python_dirs: - if os.path.exists(lldb_python_dir): - if not (sys.path.__contains__(lldb_python_dir)): - sys.path.append(lldb_python_dir) - try: - import lldb - except ImportError: - pass - else: - print 'imported lldb from: "%s"' % (lldb_python_dir) - success = True - break - if not success: - print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly" - sys.exit(1) -# ---------------------------------------------------------------------- - -# Command line option handling. -import argparse -parser = argparse.ArgumentParser(description=__doc__) -parser.add_argument('--quiet', '-q', action="store_true", help='ignored') -parser.add_argument('-batch', action="store_true", - help='exit after processing comand line') -parser.add_argument('-n', action="store_true", help='ignore .lldb file') -parser.add_argument('-x', dest='script', type=file, help='execute commands from file') -parser.add_argument("target", help="the program to debug") -args = parser.parse_args() - - -# Create a new debugger instance. -debugger = lldb.SBDebugger.Create() -debugger.SkipLLDBInitFiles(args.n) - -# Don't return from lldb function calls until the process stops. -debugger.SetAsync(False) - -# Create a target from a file and arch. -arch = os.popen("file "+args.target).read().split()[-1] -target = debugger.CreateTargetWithFileAndArch(args.target, arch) - -if not target: - print "Could not create target", args.target - sys.exit(1) - -if not args.script: - print "Interactive mode is not implemented." - sys.exit(1) - -import re -for command in args.script: - # Strip newline and whitespaces and split into words. - cmd = command[:-1].strip().split() - if not cmd: - continue - - print '> %s'% command[:-1] - - try: - if re.match('^r|(run)$', cmd[0]): - error = lldb.SBError() - launchinfo = lldb.SBLaunchInfo([]) - launchinfo.SetWorkingDirectory(os.getcwd()) - process = target.Launch(launchinfo, error) - print error - if not process or error.fail: - state = process.GetState() - print "State = %d" % state - print """ -ERROR: Could not launch process. -NOTE: There are several reasons why this may happen: - * Root needs to run "DevToolsSecurity --enable". - * Older versions of lldb cannot launch more than one process simultaneously. -""" - sys.exit(1) - - elif re.match('^b|(break)$', cmd[0]) and len(cmd) == 2: - if re.match('[0-9]+', cmd[1]): - # b line - mainfile = target.FindFunctions('main')[0].compile_unit.file - print target.BreakpointCreateByLocation(mainfile, int(cmd[1])) - else: - # b file:line - file, line = cmd[1].split(':') - print target.BreakpointCreateByLocation(file, int(line)) - - elif re.match('^ptype$', cmd[0]) and len(cmd) == 2: - # GDB's ptype has multiple incarnations depending on its - # argument (global variable, function, type). The definition - # here is for looking up the signature of a function and only - # if that fails it looks for a type with that name. - # Type lookup in LLDB would be "image lookup --type". - for elem in target.FindFunctions(cmd[1]): - print elem.function.type - continue - print target.FindFirstType(cmd[1]) - - elif re.match('^po$', cmd[0]) and len(cmd) > 1: - try: - opts = lldb.SBExpressionOptions() - opts.SetFetchDynamicValue(True) - opts.SetCoerceResultToId(True) - print target.EvaluateExpression(' '.join(cmd[1:]), opts) - except: - # FIXME: This is a fallback path for the lab.llvm.org - # buildbot running OS X 10.7; it should be removed. - thread = process.GetThreadAtIndex(0) - frame = thread.GetFrameAtIndex(0) - print frame.EvaluateExpression(' '.join(cmd[1:])) - - elif re.match('^p|(print)$', cmd[0]) and len(cmd) > 1: - thread = process.GetThreadAtIndex(0) - frame = thread.GetFrameAtIndex(0) - print frame.EvaluateExpression(' '.join(cmd[1:])) - - elif re.match('^n|(next)$', cmd[0]): - thread = process.GetThreadAtIndex(0) - thread.StepOver() - - elif re.match('^q|(quit)$', cmd[0]): - sys.exit(0) - - else: - print debugger.HandleCommand(' '.join(cmd)) - - except SystemExit: - lldb.SBDebugger_Terminate() - raise - except: - print 'Could not handle the command "%s"' % ' '.join(cmd) - diff --git a/debuginfo-tests/tests/nested-struct.cpp b/debuginfo-tests/tests/nested-struct.cpp deleted file mode 100644 index 7533e6a8151..00000000000 --- a/debuginfo-tests/tests/nested-struct.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %test_debuginfo %s %t.o -// Radar 9440721 -// If debug info for my_number() is emitted outside function foo's scope -// then a debugger may not be able to handle it. At least one version of -// gdb crashes in such cases. - -// DEBUGGER: ptype foo -// CHECK: int (void) - -int foo() { - struct Local { - static int my_number() { - return 42; - } - }; - - int i = 0; - i = Local::my_number(); - return i + 1; -} diff --git a/debuginfo-tests/tests/nrvo-string.cpp b/debuginfo-tests/tests/nrvo-string.cpp deleted file mode 100644 index 18acebb0e6d..00000000000 --- a/debuginfo-tests/tests/nrvo-string.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// This ensures that DW_OP_deref is inserted when necessary, such as when NRVO -// of a string object occurs in C++. -// -// RUN: %clangxx -O0 -fno-exceptions %target_itanium_abi_host_triple %s -o %t.out -g -// RUN: %test_debuginfo %s %t.out -// RUN: %clangxx -O1 -fno-exceptions %target_itanium_abi_host_triple %s -o %t.out -g -// RUN: %test_debuginfo %s %t.out -// -// PR34513 - -struct string { - string() {} - string(int i) : i(i) {} - ~string() {} - int i = 0; -}; -string get_string() { - string unused; - string result = 3; -// DEBUGGER: break 21 - return result; -} -int main() { get_string(); } - -// DEBUGGER: r -// DEBUGGER: print result.i -// CHECK: = 3 diff --git a/debuginfo-tests/tests/safestack.c b/debuginfo-tests/tests/safestack.c deleted file mode 100644 index 01c5f7ede92..00000000000 --- a/debuginfo-tests/tests/safestack.c +++ /dev/null @@ -1,51 +0,0 @@ -// RUN: %clang %target_itanium_abi_host_triple -arch x86_64 %s -o %t.out -g -fsanitize=safe-stack -// RUN: %test_debuginfo %s %t.out -// REQUIRES: not_asan -// Zorg configures the ASAN stage2 bots to not build the -// safestack compiler-rt. Only run this test on -// non-asanified configurations. - -struct S { - int a[8]; -}; - -int f(struct S s, unsigned i); - -int main(int argc, const char **argv) { - struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}}; - // DEBUGGER: break 17 - f(s, 4); - // DEBUGGER: break 19 - return 0; -} - -int f(struct S s, unsigned i) { - // DEBUGGER: break 24 - return s.a[i]; -} - -// DEBUGGER: r -// DEBUGGER: p s -// CHECK: a = -// DEBUGGER: p s.a[0] -// CHECK: = 0 -// DEBUGGER: p s.a[1] -// CHECK: = 1 -// DEBUGGER: p s.a[7] -// CHECK: = 7 -// DEBUGGER: c -// DEBUGGER: p s -// CHECK: a = -// DEBUGGER: p s.a[0] -// CHECK: = 0 -// DEBUGGER: p s.a[1] -// CHECK: = 1 -// DEBUGGER: p s.a[7] -// DEBUGGER: c -// DEBUGGER: p s -// CHECK: a = -// DEBUGGER: p s.a[0] -// CHECK: = 0 -// DEBUGGER: p s.a[1] -// CHECK: = 1 -// DEBUGGER: p s.a[7] diff --git a/debuginfo-tests/tests/sret.cpp b/debuginfo-tests/tests/sret.cpp deleted file mode 100644 index 640015fab40..00000000000 --- a/debuginfo-tests/tests/sret.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out -// RUN: %test_debuginfo %s %t.out -// Radar 8775834 -// DEBUGGER: break 62 -// DEBUGGER: r -// DEBUGGER: p a -// CHECK: ${{[0-9]+}} = -// LLDB does not print artificial members. -// CHECK: {{(_vptr\$A =)?.*}}m_int = 12 - -class A -{ -public: - A (int i=0); - A (const A& rhs); - const A& - operator= (const A& rhs); - virtual ~A() {} - - int get_int(); - -protected: - int m_int; -}; - -A::A (int i) : - m_int(i) -{ -} - -A::A (const A& rhs) : - m_int (rhs.m_int) -{ -} - -const A & -A::operator =(const A& rhs) -{ - m_int = rhs.m_int; - return *this; -} - -int A::get_int() -{ - return m_int; -} - -class B -{ -public: - B () {} - - A AInstance(); -}; - -A -B::AInstance() -{ - A a(12); - return a; -} - -int main (int argc, char const *argv[]) -{ - B b; - int return_val = b.AInstance().get_int(); - - A a(b.AInstance()); - return return_val; -} diff --git a/debuginfo-tests/tests/stack-var.c b/debuginfo-tests/tests/stack-var.c deleted file mode 100644 index 372139c59b0..00000000000 --- a/debuginfo-tests/tests/stack-var.c +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %clang %target_itanium_abi_host_triple %s -O -o %t.out -g -// RUN: %test_debuginfo %s %t.out - -void __attribute__((noinline, optnone)) bar(int *test) {} -int main() { - int test; - test = 23; - // DEBUGGER: break 12 - // DEBUGGER: r - // DEBUGGER: p test - // CHECK: = 23 - bar(&test); - // DEBUGGER: break 17 - // DEBUGGER: c - // DEBUGGER: p test - // CHECK: = 23 - return test; -} diff --git a/debuginfo-tests/tests/static-member-2.cpp b/debuginfo-tests/tests/static-member-2.cpp deleted file mode 100644 index 4edb2b060f1..00000000000 --- a/debuginfo-tests/tests/static-member-2.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -o %t -c -// RUN: %clangxx %target_itanium_abi_host_triple %t -o %t.out -// RUN: %test_debuginfo %s %t.out - -// FIXME: LLDB finds the wrong symbol for "C". rdar://problem/14933867 -// XFAIL: darwin - -// DEBUGGER: delete breakpoints -// DEBUGGER: break static-member.cpp:33 -// DEBUGGER: r -// DEBUGGER: ptype C -// CHECK: {{struct|class}} C { -// CHECK: static const int a; -// CHECK-NEXT: static int b; -// CHECK-NEXT: static int c; -// CHECK-NEXT: int d; -// CHECK-NEXT: } -// DEBUGGER: p C::a -// CHECK: ${{[0-9]}} = 4 -// DEBUGGER: p C::c -// CHECK: ${{[0-9]}} = 15 - -// PR14471, PR14734 - -class C { -public: - const static int a = 4; - static int b; - static int c; - int d; -}; - -int C::c = 15; -const int C::a; - -int main() { - C instance_C; - return C::a; -} diff --git a/debuginfo-tests/tests/static-member.cpp b/debuginfo-tests/tests/static-member.cpp deleted file mode 100644 index 1d8ad62c5b8..00000000000 --- a/debuginfo-tests/tests/static-member.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -o %t -c -// RUN: %clangxx %target_itanium_abi_host_triple %t -o %t.out -// RUN: %test_debuginfo %s %t.out - -// DEBUGGER: delete breakpoints -// DEBUGGER: break static-member.cpp:33 -// DEBUGGER: r -// DEBUGGER: ptype MyClass -// CHECK: {{struct|class}} MyClass { -// CHECK: static const int a; -// CHECK-NEXT: static int b; -// CHECK-NEXT: static int c; -// CHECK-NEXT: int d; -// CHECK-NEXT: } -// DEBUGGER: p MyClass::a -// CHECK: ${{[0-9]}} = 4 -// DEBUGGER: p MyClass::c -// CHECK: ${{[0-9]}} = 15 - -// PR14471, PR14734 - -class MyClass { -public: - const static int a = 4; - static int b; - static int c; - int d; -}; - -int MyClass::c = 15; -const int MyClass::a; - -int main() { - MyClass instance_MyClass; - return MyClass::a; -} diff --git a/debuginfo-tests/tests/vla.c b/debuginfo-tests/tests/vla.c deleted file mode 100644 index e6ea1ef4ac2..00000000000 --- a/debuginfo-tests/tests/vla.c +++ /dev/null @@ -1,24 +0,0 @@ -// This test case verifies the debug location for variable-length arrays. -// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o -// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out -// RUN: %test_debuginfo %s %t.out -// -// DEBUGGER: break 18 -// DEBUGGER: r -// DEBUGGER: p vla[0] -// CHECK: 23 -// DEBUGGER: p vla[1] -// CHECK: 22 - -void init_vla(int size) { - int i; - int vla[size]; - for (i = 0; i < size; i++) - vla[i] = size-i; - vla[0] = size; // line 18 -} - -int main(int argc, const char **argv) { - init_vla(23); - return 0; -} diff --git a/debuginfo-tests/vla.c b/debuginfo-tests/vla.c new file mode 100644 index 00000000000..9c8e2771533 --- /dev/null +++ b/debuginfo-tests/vla.c @@ -0,0 +1,24 @@ +// This test case verifies the debug location for variable-length arrays. +// RUN: %clang %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o +// RUN: %clang %target_itanium_abi_host_triple %t.o -o %t.out +// RUN: %test_debuginfo %s %t.out +// +// DEBUGGER: break 18 +// DEBUGGER: r +// DEBUGGER: p vla[0] +// CHECK: 23 +// DEBUGGER: p vla[1] +// CHECK: 22 + +void init_vla(int size) { + int i; + int vla[size]; + for (i = 0; i < size; i++) + vla[i] = size-i; + vla[0] = size; // line 18 +} + +int main(int argc, const char **argv) { + init_vla(23); + return 0; +} diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 5f5b138b53b..8cd9d053c63 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -110,7 +110,7 @@ endif() # LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS # This allows an easy way of setting up a build directory for llvm and another # one for llvm+clang+... using the same sources. -set(LLVM_ALL_PROJECTS "clang;libcxx;libcxxabi;lldb;compiler-rt;debuginfo-tests;lld;polly") +set(LLVM_ALL_PROJECTS "clang;libcxx;libcxxabi;lldb;compiler-rt;lld;polly") set(LLVM_ENABLE_PROJECTS "" CACHE STRING "Semicolon-separated list of projects to build (${LLVM_ALL_PROJECTS}), or \"all\".") if( LLVM_ENABLE_PROJECTS STREQUAL "all" ) @@ -885,18 +885,13 @@ if( LLVM_INCLUDE_EXAMPLES ) endif() if( LLVM_INCLUDE_TESTS ) - if(TARGET clang) + if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang) include(LLVMExternalProjectUtils) - if (EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite) - llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite - USE_TOOLCHAIN - TOOLCHAIN_TOOLS clang lld clang-cl - EXCLUDE_FROM_ALL - NO_INSTALL - ALWAYS_CLEAN) - endif() - - add_llvm_external_project(debuginfo-tests projects/debuginfo-tests) + llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite + USE_TOOLCHAIN + EXCLUDE_FROM_ALL + NO_INSTALL + ALWAYS_CLEAN) endif() add_subdirectory(utils/lit) add_subdirectory(test) diff --git a/llvm/projects/CMakeLists.txt b/llvm/projects/CMakeLists.txt index 11835fa89d2..9102efbdcb4 100644 --- a/llvm/projects/CMakeLists.txt +++ b/llvm/projects/CMakeLists.txt @@ -10,7 +10,6 @@ foreach(entry ${entries}) (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxxabi) AND (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libunwind) AND (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/test-suite) AND - (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/debuginfo-tests) AND (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/parallel-libs) AND (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/openmp)) add_subdirectory(${entry}) diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py index 261f1b3885d..c631f8b8865 100644 --- a/llvm/utils/lit/lit/llvm/config.py +++ b/llvm/utils/lit/lit/llvm/config.py @@ -27,9 +27,8 @@ class LLVMConfig(object): # For tests that require Windows to run. features.add('system-windows') - lit_tools_dir = getattr(config, 'lit_tools_dir', None) # Seek sane tools in directories and set to $PATH. - path = self.lit_config.getToolsPath(lit_tools_dir, + path = self.lit_config.getToolsPath(config.lit_tools_dir, config.environment['PATH'], ['cmp.exe', 'grep.exe', 'sed.exe']) if path is not None: @@ -414,10 +413,8 @@ class LLVMConfig(object): self.config.substitutions.append( ('%target_itanium_abi_host_triple', '')) - clang_src_dir = getattr(self.config, 'clang_src_dir', None) - if clang_src_dir: - self.config.substitutions.append( - ('%src_include_dir', os.path.join(clang_src_dir, 'include'))) + self.config.substitutions.append( + ('%src_include_dir', self.config.clang_src_dir + '/include')) # FIXME: Find nicer way to prohibit this. self.config.substitutions.append( diff --git a/llvm/utils/test_debuginfo.pl b/llvm/utils/test_debuginfo.pl index d9613d73025..aaf90d95468 100755 --- a/llvm/utils/test_debuginfo.pl +++ b/llvm/utils/test_debuginfo.pl @@ -56,7 +56,7 @@ my $my_debugger = $ENV{'DEBUGGER'}; if (!$my_debugger) { if ($use_lldb) { my $path = dirname(Cwd::abs_path($0)); - $my_debugger = "/usr/bin/env python $path/../tools/clang/test/debuginfo-tests/tests/llgdb.py"; + $my_debugger = "/usr/bin/env python $path/../tools/clang/test/debuginfo-tests/llgdb.py"; } else { $my_debugger = "gdb"; } -- cgit v1.2.3