diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/lang/cpp')
66 files changed, 1107 insertions, 119 deletions
diff --git a/packages/Python/lldbsuite/test/lang/cpp/auto/TestCPPAuto.py b/packages/Python/lldbsuite/test/lang/cpp/auto/TestCPPAuto.py index 9746dec2fa3de..ea210a1e9ea29 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/auto/TestCPPAuto.py +++ b/packages/Python/lldbsuite/test/lang/cpp/auto/TestCPPAuto.py @@ -2,14 +2,16 @@ Tests that auto types work """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class CPPAutoTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureGcc("GCC does not generate complete debug info") + @expectedFailureAll(compiler="gcc", bugnumber="GCC generates incomplete debug info") + @expectedFailureAll(oslist=['windows'], bugnumber="llvm.org/pr26339") def test_with_run_command(self): """Test that auto types work in the expression parser""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/breakpoint-commands/TestCPPBreakpointCommands.py b/packages/Python/lldbsuite/test/lang/cpp/breakpoint-commands/TestCPPBreakpointCommands.py index 6c06f3750d139..0a1ac11adcea5 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/breakpoint-commands/TestCPPBreakpointCommands.py +++ b/packages/Python/lldbsuite/test/lang/cpp/breakpoint-commands/TestCPPBreakpointCommands.py @@ -8,13 +8,15 @@ from __future__ import print_function import os, time import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class CPPBreakpointCommandsTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureWindows + @expectedFailureAll(oslist=["windows"]) def test(self): """Test a sequence of breakpoint command add, list, and delete.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/call-function/TestCallCPPFunction.py b/packages/Python/lldbsuite/test/lang/cpp/call-function/TestCallCPPFunction.py index 3aa97af688198..260dd763c0079 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/call-function/TestCallCPPFunction.py +++ b/packages/Python/lldbsuite/test/lang/cpp/call-function/TestCallCPPFunction.py @@ -3,8 +3,9 @@ Tests calling a function by basename """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class CallCPPFunctionTestCase(TestBase): @@ -14,7 +15,7 @@ class CallCPPFunctionTestCase(TestBase): TestBase.setUp(self) self.line = line_number('main.cpp', '// breakpoint') - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") def test_with_run_command(self): """Test calling a function by basename""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/chained-calls/TestCppChainedCalls.py b/packages/Python/lldbsuite/test/lang/cpp/chained-calls/TestCppChainedCalls.py index 272665a78577d..140c4a832fd92 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/chained-calls/TestCppChainedCalls.py +++ b/packages/Python/lldbsuite/test/lang/cpp/chained-calls/TestCppChainedCalls.py @@ -1,12 +1,13 @@ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class TestCppChainedCalls(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_with_run_command(self): self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/char1632_t/TestChar1632T.py b/packages/Python/lldbsuite/test/lang/cpp/char1632_t/TestChar1632T.py index 9bb1faf4ba6d9..d4400d3a488d4 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/char1632_t/TestChar1632T.py +++ b/packages/Python/lldbsuite/test/lang/cpp/char1632_t/TestChar1632T.py @@ -9,8 +9,9 @@ from __future__ import print_function import os, time import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class Char1632TestCase(TestBase): @@ -24,8 +25,7 @@ class Char1632TestCase(TestBase): self.lines = [ line_number(self.source, '// breakpoint1'), line_number(self.source, '// breakpoint2') ] - @expectedFailureIcc # ICC (13.1) does not emit the DW_TAG_base_type for char16_t and char32_t. - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") + @expectedFailureAll(compiler="icc", bugnumber="ICC (13.1) does not emit the DW_TAG_base_type for char16_t and char32_t.") def test(self): """Test that the C++11 support for char16_t and char32_t works correctly.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py b/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py index d47d1b7dde416..acce769bf9497 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py +++ b/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py @@ -8,8 +8,9 @@ from __future__ import print_function import os, time import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class StaticVariableTestCase(TestBase): @@ -21,7 +22,7 @@ class StaticVariableTestCase(TestBase): # Find the line number to break at. self.line = line_number('main.cpp', '// Set break point at this line.') - @expectedFailureWindows("llvm.org/pr24764") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") def test_with_run_command(self): """Test that file and class static variables display correctly.""" self.build() @@ -49,9 +50,8 @@ class StaticVariableTestCase(TestBase): startstr = "(int) A::g_points[1].x = 11") @expectedFailureDarwin(9980907) - @expectedFailureClang('Clang emits incomplete debug info.') - @expectedFailureFreeBSD('llvm.org/pr20550 failing on FreeBSD-11') - @expectedFailureGcc('GCC emits incomplete debug info.') + @expectedFailureAll(compiler=["clang", "gcc"], bugnumber="Compiler emits incomplete debug info") + @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr20550 failing on FreeBSD-11') @add_test_categories(['pyapi']) def test_with_python_api(self): """Test Python APIs on file and class static variables.""" @@ -69,11 +69,8 @@ class StaticVariableTestCase(TestBase): self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Get the SBValue of 'A::g_points' and 'g_points'. frame = thread.GetFrameAtIndex(0) diff --git a/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py b/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py index b67e53c307458..fe10120d497e8 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py +++ b/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py @@ -6,9 +6,9 @@ from __future__ import print_function import os, time import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class ClassTypesTestCase(TestBase): @@ -92,11 +92,8 @@ class ClassTypesTestCase(TestBase): lldbutil.state_type_to_str(process.GetState())) # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # The filename of frame #0 should be 'main.cpp' and the line number # should be 93. @@ -203,11 +200,8 @@ class ClassTypesTestCase(TestBase): lldbutil.state_type_to_str(process.GetState())) # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) frame = thread.frames[0] self.assertTrue (frame.IsValid(), "Got a valid frame.") diff --git a/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py b/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py index 595d075d51805..6413b3e056ff6 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py +++ b/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py @@ -8,8 +8,9 @@ from __future__ import print_function import os, time import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class IterateFrameAndDisassembleTestCase(TestBase): @@ -46,7 +47,8 @@ class IterateFrameAndDisassembleTestCase(TestBase): # disassemble it. target = self.dbg.GetSelectedTarget() process = target.GetProcess() - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) depth = thread.GetNumFrames() for i in range(depth - 1): frame = thread.GetFrameAtIndex(i) diff --git a/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile b/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile new file mode 100644 index 0000000000000..52a92c0b61ae4 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/const_this/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../../make +CXX_SOURCES := main.cpp +CXXFLAGS += -std=c++11 +include $(LEVEL)/Makefile.rules + +cleanup: + rm -f Makefile *.d + diff --git a/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py b/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py new file mode 100644 index 0000000000000..a08af5d091e1c --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/const_this/TestConstThis.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), [] ) diff --git a/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp new file mode 100644 index 0000000000000..7614977b245f5 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/const_this/main.cpp @@ -0,0 +1,23 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +class foo { +public: + template <class T> T func(T x) const { + return x+2; //% self.expect("expr 2+3", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["5"]) + } +}; + +int i; + +int main() { + return foo().func(i); +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py b/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py index 67de03b54b20a..d525e12b31ee6 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py +++ b/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py @@ -20,7 +20,8 @@ class CPPTestDiamondInheritance(TestBase): self.set_breakpoint(line_number('main.cpp', '// breakpoint 2')) process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) frame = thread.GetFrameAtIndex(0) j1 = frame.FindVariable("j1") j1_Derived1 = j1.GetChildAtIndex(0) diff --git a/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestCppValueCast.py b/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestCppValueCast.py index 4e23cd8992854..b456de450a822 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestCppValueCast.py +++ b/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestCppValueCast.py @@ -10,8 +10,9 @@ import unittest2 import os, time import re import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class CppValueCastTestCase(TestBase): diff --git a/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestDynamicValue.py b/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestDynamicValue.py index 56e81c56cfa63..98e6ef92665dd 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestDynamicValue.py +++ b/packages/Python/lldbsuite/test/lang/cpp/dynamic-value/TestDynamicValue.py @@ -9,8 +9,9 @@ from __future__ import print_function import os, time import re import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class DynamicValueTestCase(TestBase): @@ -28,9 +29,8 @@ class DynamicValueTestCase(TestBase): self.main_second_call_line = line_number('pass-to-base.cpp', '// Break here and get real address of reallyA.') - @expectedFailureFreeBSD # FIXME: This needs to be root-caused. - @expectedFailureWindows("llvm.org/pr24663") @add_test_categories(['pyapi']) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663") def test_get_dynamic_vals(self): """Test fetching C++ dynamic values from pointers & references.""" self.build(dictionary=self.getBuildFlags()) diff --git a/packages/Python/lldbsuite/test/lang/cpp/exceptions/TestCPPExceptionBreakpoints.py b/packages/Python/lldbsuite/test/lang/cpp/exceptions/TestCPPExceptionBreakpoints.py index 65cf0b361d845..4ca4cb8b79ef3 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/exceptions/TestCPPExceptionBreakpoints.py +++ b/packages/Python/lldbsuite/test/lang/cpp/exceptions/TestCPPExceptionBreakpoints.py @@ -8,8 +8,9 @@ from __future__ import print_function import os, time import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class CPPBreakpointTestCase(TestBase): @@ -21,7 +22,7 @@ class CPPBreakpointTestCase(TestBase): self.source = 'exceptions.cpp' self.catch_line = line_number(self.source, '// This is the line you should stop at for catch') - @expectedFailureWindows("llvm.org/pr24538") # clang-cl does not support throw or catch + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24538, clang-cl does not support throw or catch") def test(self): """Test lldb exception breakpoint command for CPP.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/extern_c/Makefile b/packages/Python/lldbsuite/test/lang/cpp/extern_c/Makefile new file mode 100644 index 0000000000000..99bfa7e03b479 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/extern_c/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../../make +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/extern_c/TestExternCSymbols.py b/packages/Python/lldbsuite/test/lang/cpp/extern_c/TestExternCSymbols.py new file mode 100644 index 0000000000000..f08c0dcbda983 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/extern_c/TestExternCSymbols.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), []) diff --git a/packages/Python/lldbsuite/test/lang/cpp/extern_c/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/extern_c/main.cpp new file mode 100644 index 0000000000000..a4006c2f7ed1f --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/extern_c/main.cpp @@ -0,0 +1,29 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdint.h> + +extern "C" +{ + int foo(); +}; + +int foo() +{ + puts("foo"); + return 2; +} + +int main (int argc, char const *argv[], char const *envp[]) +{ + foo(); + return 0; //% self.expect("expression -- foo()", substrs = ['2']) +} + diff --git a/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py b/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py index 396a637041cb8..d5d5363882229 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py +++ b/packages/Python/lldbsuite/test/lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py @@ -19,7 +19,13 @@ class FrameVariableAnonymousUnionsTestCase(TestBase): self.runCmd("process launch", RUN_SUCCEEDED) - self.expect('frame variable -f x i', substrs=['ffffff41']) + process = self.dbg.GetSelectedTarget().GetProcess() + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect('frame variable -f x i', substrs=['ffffff41']) + else: + self.expect('frame variable -f x i', substrs=['41ffff00']) + self.expect('frame variable c', substrs=["'A"]) self.expect('frame variable x', matching=False, substrs=['3']) diff --git a/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py b/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py index de56cd6a6c491..eac78cd29951e 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py +++ b/packages/Python/lldbsuite/test/lang/cpp/global_operators/TestCppGlobalOperators.py @@ -2,14 +2,15 @@ Test that global operators are found and evaluated. """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class TestCppGlobalOperators(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_with_run_command(self): self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/gmodules/Makefile b/packages/Python/lldbsuite/test/lang/cpp/gmodules/Makefile new file mode 100644 index 0000000000000..da6f39a7488cf --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/gmodules/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../make + +PCH_CXX_SOURCE = pch.h +CXX_SOURCES = main.cpp +CFLAGS_EXTRAS += $(MODULE_DEBUG_INFO_FLAGS) + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py b/packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py new file mode 100644 index 0000000000000..942149f6173bb --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py @@ -0,0 +1,50 @@ +import lldb, os +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestWithGmodulesDebugInfo(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(["gmodules"]) + @expectedFailureAll(oslist=["macosx"], bugnumber="llvm.org/pr28156") + def test_specialized_typedef_from_pch(self): + self.build() + cwd = os.getcwd() + + src_file = os.path.join(cwd, "main.cpp") + src_file_spec = lldb.SBFileSpec(src_file) + self.assertTrue(src_file_spec.IsValid(), "breakpoint file") + + # Get the path of the executable + exe_path = os.path.join(cwd, 'a.out') + + # Load the executable + target = self.dbg.CreateTarget(exe_path) + self.assertTrue(target.IsValid(), VALID_TARGET) + + # Break on interesting line + breakpoint = target.BreakpointCreateBySourceRegex("break here", src_file_spec) + self.assertTrue(breakpoint.IsValid() and breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT) + + # Launch the process + process = target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertTrue(process.IsValid(), PROCESS_IS_VALID) + + # Get the thread of the process + self.assertTrue(process.GetState() == lldb.eStateStopped) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") + + # Get frame for current thread + frame = thread.frames[0] + + testValue = frame.EvaluateExpression("test") + self.assertTrue(testValue.GetError().Success(), "Test expression value invalid: %s" % (testValue.GetError().GetCString())) + self.assertTrue(testValue.GetTypeName() == "IntContainer", "Test expression type incorrect") + + memberValue = testValue.GetChildMemberWithName("storage") + self.assertTrue(memberValue.GetError().Success(), "Member value missing or invalid: %s" % (testValue.GetError().GetCString())) + self.assertTrue(memberValue.GetTypeName() == "int", "Member type incorrect") + self.assertEqual(42, memberValue.GetValueAsSigned(), "Member value incorrect") diff --git a/packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp new file mode 100644 index 0000000000000..aa4013685171c --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp @@ -0,0 +1,5 @@ +int main(int argc, const char * argv[]) +{ + IntContainer test(42); + return 0; // break here +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h b/packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h new file mode 100644 index 0000000000000..a6c59b94c896f --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h @@ -0,0 +1,12 @@ +template<typename T> +class GenericContainer { + private: + T storage; + + public: + GenericContainer(T value) { + storage = value; + }; +}; + +typedef GenericContainer<int> IntContainer; diff --git a/packages/Python/lldbsuite/test/lang/cpp/incomplete-types/TestCppIncompleteTypes.py b/packages/Python/lldbsuite/test/lang/cpp/incomplete-types/TestCppIncompleteTypes.py index 324f476efb9b8..1e3359ecde49b 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/incomplete-types/TestCppIncompleteTypes.py +++ b/packages/Python/lldbsuite/test/lang/cpp/incomplete-types/TestCppIncompleteTypes.py @@ -1,13 +1,13 @@ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class TestCppIncompleteTypes(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureFreeBSD("llvm.org/pr25626 test executable not built correctly on FreeBSD") - @skipIfGcc + @skipIf(compiler="gcc") def test_limit_debug_info(self): self.build() frame = self.get_test_frame('limit') @@ -20,7 +20,7 @@ class TestCppIncompleteTypes(TestBase): self.assertTrue(value_a.IsValid(), "'expr a' results in a valid SBValue object") self.assertTrue(value_a.GetError().Success(), "'expr a' is successful") - @skipIfGcc + @skipIf(compiler="gcc") @skipIfWindows # Clang on Windows asserts in external record layout in this case. def test_partial_limit_debug_info(self): self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/inlines/Makefile b/packages/Python/lldbsuite/test/lang/cpp/inlines/Makefile new file mode 100644 index 0000000000000..8f67abdf2b34c --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/inlines/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := inlines.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/inlines/TestInlines.py b/packages/Python/lldbsuite/test/lang/cpp/inlines/TestInlines.py new file mode 100644 index 0000000000000..284057de9dcd8 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/inlines/TestInlines.py @@ -0,0 +1,52 @@ +"""Test variable lookup when stopped in inline functions.""" + +from __future__ import print_function + +import os, time +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class InlinesTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line = line_number('inlines.cpp', '// Set break point at this line.') + + @expectedFailureAll("llvm.org/pr26710", oslist=["linux"], compiler="gcc") + def test(self): + """Test that local variables are visible in expressions.""" + self.build() + self.runToBreakpoint() + + # Check that 'frame variable' finds a variable + self.expect("frame variable inner_input", VARIABLES_DISPLAYED_CORRECTLY, + startstr = '(int) inner_input =') + + # Check that 'expr' finds a variable + self.expect("expr inner_input", VARIABLES_DISPLAYED_CORRECTLY, + startstr = '(int) $0 =') + + def runToBreakpoint(self): + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Break inside the main. + lldbutil.run_break_set_by_file_and_line(self, "inlines.cpp", self.line, num_expected_locations=2, + loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # The breakpoint should have a hit count of 1. + self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, + substrs = [' resolved, hit count = 1']) diff --git a/packages/Python/lldbsuite/test/lang/cpp/inlines/inlines.cpp b/packages/Python/lldbsuite/test/lang/cpp/inlines/inlines.cpp new file mode 100644 index 0000000000000..822d88e22f9bc --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/inlines/inlines.cpp @@ -0,0 +1,53 @@ +#include <stdio.h> +#include "inlines.h" + +#define INLINE_ME __inline__ __attribute__((always_inline)) + +int +not_inlined_2 (int input) +{ + printf ("Called in not_inlined_2 with : %d.\n", input); + return input; +} + +int +not_inlined_1 (int input) +{ + printf ("Called in not_inlined_1 with %d.\n", input); + return not_inlined_2(input); +} + +INLINE_ME int +inner_inline (int inner_input, int mod_value) +{ + int inner_result; + inner_result = inner_input % mod_value; + printf ("Returning: %d.\n", inner_result); + return not_inlined_1 (inner_result); // Set break point at this line. +} + +INLINE_ME int +outer_inline (int outer_input) +{ + int outer_result; + + outer_result = inner_inline (outer_input, outer_input % 3); + return outer_result; +} + +int +main (int argc, char **argv) +{ + printf ("Starting...\n"); + + int (*func_ptr) (int); + func_ptr = outer_inline; + + outer_inline (argc); + + func_ptr (argc); + + return 0; +} + + diff --git a/packages/Python/lldbsuite/test/lang/cpp/inlines/inlines.h b/packages/Python/lldbsuite/test/lang/cpp/inlines/inlines.h new file mode 100644 index 0000000000000..265d7b4966ed3 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/inlines/inlines.h @@ -0,0 +1,4 @@ +int inner_inline (int inner_input, int mod_value); +int outer_inline (int outer_input); +int not_inlined_2 (int input); +int not_inlined_1 (int input); diff --git a/packages/Python/lldbsuite/test/lang/cpp/lambdas/TestLambdas.py b/packages/Python/lldbsuite/test/lang/cpp/lambdas/TestLambdas.py new file mode 100644 index 0000000000000..97cc177aab70d --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/lambdas/TestLambdas.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), [lldbinline.expectedFailureAll(oslist=["windows"])]) diff --git a/packages/Python/lldbsuite/test/lang/cpp/lambdas/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/lambdas/main.cpp new file mode 100644 index 0000000000000..3cce3baf2924c --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/lambdas/main.cpp @@ -0,0 +1,17 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +int main (int argc, char const *argv[]) +{ + printf("Stop here\n"); //% self.runCmd("expression auto $add = [](int a, int b) { return a + b; }") + //% self.expect("expression $add(2,3)", substrs = ['= 5']) + return 0; +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/limit-debug-info/TestWithLimitDebugInfo.py b/packages/Python/lldbsuite/test/lang/cpp/limit-debug-info/TestWithLimitDebugInfo.py index ec26f9efe9074..9d4d1b54a9d31 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/limit-debug-info/TestWithLimitDebugInfo.py +++ b/packages/Python/lldbsuite/test/lang/cpp/limit-debug-info/TestWithLimitDebugInfo.py @@ -1,12 +1,13 @@ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class TestWithLimitDebugInfo(TestBase): mydir = TestBase.compute_mydir(__file__) - @skipIf(debug_info=not_in(["dwarf"])) + @skipIf(debug_info=no_match(["dwarf"])) def test_limit_debug_info(self): self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/Makefile b/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/Makefile new file mode 100644 index 0000000000000..35eb63f922f7b --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES = main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py b/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py new file mode 100644 index 0000000000000..12fc4c2363767 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py @@ -0,0 +1,197 @@ +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + +class TestMembersAndLocalsWithSameName(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_when_stopped_in_method(self): + self._load_exe() + + # Set breakpoints + bp1 = self.target.BreakpointCreateBySourceRegex("Break 1", self.src_file_spec) + self.assertTrue(bp1.IsValid() and bp1.GetNumLocations() >= 1, VALID_BREAKPOINT) + bp2 = self.target.BreakpointCreateBySourceRegex("Break 2", self.src_file_spec) + self.assertTrue(bp2.IsValid() and bp2.GetNumLocations() >= 1, VALID_BREAKPOINT) + bp3 = self.target.BreakpointCreateBySourceRegex("Break 3", self.src_file_spec) + self.assertTrue(bp3.IsValid() and bp3.GetNumLocations() >= 1, VALID_BREAKPOINT) + bp4 = self.target.BreakpointCreateBySourceRegex("Break 4", self.src_file_spec) + self.assertTrue(bp4.IsValid() and bp4.GetNumLocations() >= 1, VALID_BREAKPOINT) + + # Launch the process + self.process = self.target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) + + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + + self._test_globals() + + self.process.Continue() + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid()) + frame = thread.GetSelectedFrame() + self.assertTrue(frame.IsValid()) + + val = frame.EvaluateExpression("a"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 12345) + + val = frame.EvaluateExpression("b"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 54321) + + val = frame.EvaluateExpression("c"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 34567) + + self.process.Continue() + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid()) + frame = thread.GetSelectedFrame() + self.assertTrue(frame.IsValid()) + + val = frame.EvaluateExpression("a"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 10001) + + val = frame.EvaluateExpression("b"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 10002) + + val = frame.EvaluateExpression("c"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 10003) + + self.process.Continue() + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid()) + frame = thread.GetSelectedFrame() + self.assertTrue(frame.IsValid()) + + val = frame.EvaluateExpression("a"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 1) + + val = frame.EvaluateExpression("b"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 2) + + val = frame.EvaluateExpression("c"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 778899) + + def test_when_stopped_in_function(self): + self._load_exe() + + # Set breakpoints + bp1 = self.target.BreakpointCreateBySourceRegex("Break 1", self.src_file_spec) + self.assertTrue(bp1.IsValid() and bp1.GetNumLocations() >= 1, VALID_BREAKPOINT) + bp5 = self.target.BreakpointCreateBySourceRegex("Break 5", self.src_file_spec) + self.assertTrue(bp5.IsValid() and bp5.GetNumLocations() >= 1, VALID_BREAKPOINT) + bp6 = self.target.BreakpointCreateBySourceRegex("Break 6", self.src_file_spec) + self.assertTrue(bp6.IsValid() and bp6.GetNumLocations() >= 1, VALID_BREAKPOINT) + bp7 = self.target.BreakpointCreateBySourceRegex("Break 7", self.src_file_spec) + self.assertTrue(bp7.IsValid() and bp7.GetNumLocations() >= 1, VALID_BREAKPOINT) + + # Launch the process + self.process = self.target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) + + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + + self._test_globals() + + self.process.Continue() + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid()) + frame = thread.GetSelectedFrame() + self.assertTrue(frame.IsValid()) + + val = frame.EvaluateExpression("a"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 12345) + + val = frame.EvaluateExpression("b"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 54321) + + val = frame.EvaluateExpression("c"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 34567) + + self.process.Continue() + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid()) + frame = thread.GetSelectedFrame() + self.assertTrue(frame.IsValid()) + + val = frame.EvaluateExpression("a"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 10001) + + val = frame.EvaluateExpression("b"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 10002) + + val = frame.EvaluateExpression("c"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 10003) + + self.process.Continue() + self.assertTrue(self.process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid()) + frame = thread.GetSelectedFrame() + self.assertTrue(frame.IsValid()) + + val = frame.EvaluateExpression("a"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 1) + + val = frame.EvaluateExpression("b"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 2) + + val = frame.EvaluateExpression("c"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 778899) + + def _load_exe(self): + self.build() + + cwd = os.getcwd() + + src_file = os.path.join(cwd, "main.cpp") + self.src_file_spec = lldb.SBFileSpec(src_file) + self.assertTrue(self.src_file_spec.IsValid(), "breakpoint file") + + # Get the path of the executable + exe_path = os.path.join(cwd, 'a.out') + + # Load the executable + self.target = self.dbg.CreateTarget(exe_path) + self.assertTrue(self.target.IsValid(), VALID_TARGET) + + def _test_globals(self): + thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid()) + frame = thread.GetSelectedFrame() + self.assertTrue(frame.IsValid()) + + val = frame.EvaluateExpression("a"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 112233) + + val = frame.EvaluateExpression("b"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 445566) + + val = frame.EvaluateExpression("c"); + self.assertTrue(val.IsValid()) + self.assertEqual(val.GetValueAsUnsigned(), 778899) diff --git a/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/main.cpp new file mode 100644 index 0000000000000..baf08f6a98320 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/main.cpp @@ -0,0 +1,73 @@ +namespace NN +{ + int a = 778899; + int b = 665544; + int c = 445566; +} + +class A +{ +public: + A(); + int Method(int a, int b); + +private: + int a, b; +}; + +A::A() : a(10), b(100) { } + +int a = 112233; +int b = 445566; +int c = 778899; + +int +A::Method(int a, int b) +{ + { + int a = 12345; + int b = 54321; + int c = 34567; + this->a = a + b + this->b; // Break 2 + } + + { + using namespace NN; + int a = 10001; + int b = 10002; + int c = 10003; + this->a = a + b + this->b; // Break 3 + } + + return this->a + this->b + a + b; // Break 4 +} + +int +Function(int a, int b) +{ + int A; + + { + int a = 12345; + int b = 54321; + int c = 34567; + A = a + b + c; // Break 5 + } + + { + using namespace NN; + int a = 10001; + int b = 10002; + int c = 10003; + A = a + b + c; // Break 6 + } + + return A + a + b; // Break 7 +} + +int +main() +{ + A obj; + return obj.Method(1, 2) + Function(1, 2); // Break 1 +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py index a60d8252e9f0d..93d53c7de7122 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py @@ -8,8 +8,78 @@ from __future__ import print_function import os, time import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil + +class NamespaceBreakpointTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll(bugnumber="llvm.org/pr28548", compiler="gcc") + def test_breakpoints_func_auto(self): + """Test that we can set breakpoints correctly by basename to find all functions whose basename is "func".""" + self.build() + + names = [ "func()", "func(int)", "A::B::func()", "A::func()", "A::func(int)"] + + # Create a target by the debugger. + exe = os.path.join(os.getcwd(), "a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + module_list = lldb.SBFileSpecList() + module_list.Append(lldb.SBFileSpec(exe, False)) + cu_list = lldb.SBFileSpecList() + # Set a breakpoint by name "func" which should pick up all functions whose basename is "func" + bp = target.BreakpointCreateByName ("func", lldb.eFunctionNameTypeAuto, module_list, cu_list); + for bp_loc in bp: + name = bp_loc.GetAddress().GetFunction().GetName() + self.assertTrue(name in names, "make sure breakpoint locations are correct for 'func' with eFunctionNameTypeAuto") + + @expectedFailureAll(bugnumber="llvm.org/pr28548", compiler="gcc") + def test_breakpoints_func_full(self): + """Test that we can set breakpoints correctly by fullname to find all functions whose fully qualified name is "func" + (no namespaces).""" + self.build() + + names = [ "func()", "func(int)"] + + # Create a target by the debugger. + exe = os.path.join(os.getcwd(), "a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + module_list = lldb.SBFileSpecList() + module_list.Append(lldb.SBFileSpec(exe, False)) + cu_list = lldb.SBFileSpecList() + + # Set a breakpoint by name "func" whose fullly qualified named matches "func" which + # should pick up only functions whose basename is "func" and has no containing context + bp = target.BreakpointCreateByName ("func", lldb.eFunctionNameTypeFull, module_list, cu_list); + for bp_loc in bp: + name = bp_loc.GetAddress().GetFunction().GetName() + self.assertTrue(name in names, "make sure breakpoint locations are correct for 'func' with eFunctionNameTypeFull") + + def test_breakpoints_a_func_full(self): + """Test that we can set breakpoints correctly by fullname to find all functions whose fully qualified name is "A::func".""" + self.build() + + names = [ "A::func()", "A::func(int)"] + + # Create a target by the debugger. + exe = os.path.join(os.getcwd(), "a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + module_list = lldb.SBFileSpecList() + module_list.Append(lldb.SBFileSpec(exe, False)) + cu_list = lldb.SBFileSpecList() + + # Set a breakpoint by name "A::func" whose fullly qualified named matches "A::func" which + # should pick up only functions whose basename is "func" and is contained in the "A" namespace + bp = target.BreakpointCreateByName ("A::func", lldb.eFunctionNameTypeFull, module_list, cu_list); + for bp_loc in bp: + name = bp_loc.GetAddress().GetFunction().GetName() + self.assertTrue(name in names, "make sure breakpoint locations are correct for 'A::func' with eFunctionNameTypeFull") + class NamespaceTestCase(TestBase): @@ -38,7 +108,7 @@ class NamespaceTestCase(TestBase): 'stop reason = breakpoint']) # rdar://problem/8668674 - @expectedFailureWindows("llvm.org/pr24764") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") def test_with_run_command(self): """Test that anonymous and named namespace variables display correctly.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py index 4cad45564c870..12e8eef40cf35 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py @@ -7,8 +7,9 @@ from __future__ import print_function import os, time import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class NamespaceLookupTestCase(TestBase): @@ -33,8 +34,7 @@ class NamespaceLookupTestCase(TestBase): substrs = ['stopped', 'stop reason = breakpoint']) - @expectedFailureFreeBSD("llvm.org/pr25819") - @expectedFailureLinux("llvm.org/pr25819") + @expectedFailureAll(oslist=["windows", "linux", "freebsd"], bugnumber="llvm.org/pr25819") def test_scope_lookup_with_run_command(self): """Test scope lookup of functions in lldb.""" self.build() @@ -144,7 +144,7 @@ class NamespaceLookupTestCase(TestBase): # finds the global ::func(). self.expect("expr -- func()", startstr = "(int) $0 = 2") - @expectedFailureLinux("llvm.org/pr25819") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr25819") def test_scope_lookup_before_using_with_run_command(self): """Test scope lookup before using in lldb.""" self.build() @@ -158,9 +158,9 @@ class NamespaceLookupTestCase(TestBase): self.expect("expr -- func()", startstr = "(int) $0 = 1") # NOTE: this test may fail on older systems that don't emit import - # emtries in DWARF - may need to add checks for compiler versions here. - @expectedFailureFreeBSD("llvm.org/pr25819") - @expectedFailureLinux("llvm.org/pr25819") + # entries in DWARF - may need to add checks for compiler versions here. + @skipIf(compiler="gcc", oslist=["linux"], debug_info=["dwo"]) # Skip to avoid crash + @expectedFailureAll(oslist=["windows", "linux", "freebsd"], bugnumber="llvm.org/pr25819") def test_scope_after_using_directive_lookup_with_run_command(self): """Test scope lookup after using directive in lldb.""" self.build() @@ -203,8 +203,7 @@ class NamespaceLookupTestCase(TestBase): # the same type. self.expect("expr -- func()", startstr = "error") - @expectedFailureFreeBSD("llvm.org/pr25819") - @expectedFailureLinux("llvm.org/pr25819") + @expectedFailureAll(oslist=["windows", "linux", "freebsd"], bugnumber="llvm.org/pr25819") def test_scope_lookup_shadowed_by_using_with_run_command(self): """Test scope lookup shadowed by using in lldb.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/Makefile b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/Makefile new file mode 100644 index 0000000000000..0041add935a61 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/Makefile @@ -0,0 +1,19 @@ +LEVEL := ../../../make + +LD_EXTRAS := -L. -l$(LIB_PREFIX)a -l$(LIB_PREFIX)b +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + +.PHONY: +a.out: lib_a lib_b + +lib_%: + $(MAKE) -f $*.mk + +hidden_lib_d: + $(MAKE) -C hidden + +clean:: + $(MAKE) -f a.mk clean + $(MAKE) -f b.mk clean diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/TestNamespaceDefinitions.py b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/TestNamespaceDefinitions.py new file mode 100644 index 0000000000000..f45969429004a --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/TestNamespaceDefinitions.py @@ -0,0 +1,57 @@ +"""Test that forward declarations don't cause bogus conflicts in namespaced types""" + +from __future__ import print_function + + + +import unittest2 +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + +class NamespaceDefinitionsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_expr(self): + self.build() + self.common_setup() + + self.expect("expression -- Foo::MyClass()", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['thing = ']) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.source = 'main.cpp' + self.line = line_number(self.source, '// Set breakpoint here') + self.shlib_names = ["a", "b"] + + def common_setup(self): + # Run in synchronous mode + self.dbg.SetAsync(False) + + # Create a target by the debugger. + target = self.dbg.CreateTarget("a.out") + self.assertTrue(target, VALID_TARGET) + + # Break inside the foo function which takes a bar_ptr argument. + lldbutil.run_break_set_by_file_and_line (self, self.source, self.line, num_expected_locations=1, loc_exact=True) + + # Register our shared libraries for remote targets so they get automatically uploaded + environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple (None, environment, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # The breakpoint should have a hit count of 1. + self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, + substrs = [' resolved, hit count = 1']) + diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/a.cpp b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/a.cpp new file mode 100644 index 0000000000000..2ea0d2df2eca1 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/a.cpp @@ -0,0 +1,16 @@ +//===-- a.cpp ---------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "foo.h" + +class ThingInside { + int a; +}; + +Foo::MyClass a_class; diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/a.mk b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/a.mk new file mode 100644 index 0000000000000..5943e5077c54d --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/a.mk @@ -0,0 +1,9 @@ +LEVEL := ../../../make + +DYLIB_NAME := a +DYLIB_CXX_SOURCES := a.cpp +DYLIB_ONLY := YES + +CXXFLAGS += -fPIC + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/b.cpp b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/b.cpp new file mode 100644 index 0000000000000..6e7b41e00164a --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/b.cpp @@ -0,0 +1,12 @@ +//===-- b.cpp ---------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "foo.h" + +Foo::MyClass b_class; diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/b.mk b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/b.mk new file mode 100644 index 0000000000000..8ee2a13b1291b --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/b.mk @@ -0,0 +1,9 @@ +LEVEL := ../../../make + +DYLIB_NAME := b +DYLIB_CXX_SOURCES := b.cpp +DYLIB_ONLY := YES + +CXXFLAGS += -fPIC + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/foo.h b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/foo.h new file mode 100644 index 0000000000000..76b8e70880ecf --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/foo.h @@ -0,0 +1,18 @@ +//===-- foo.h ---------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +class ThingInside; + +namespace Foo { + class MyClass { + ThingInside *thing; + public: + MyClass() { } + }; +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/main.cpp new file mode 100644 index 0000000000000..076814eae1de1 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace_definitions/main.cpp @@ -0,0 +1,16 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +int +main (int argc, char const *argv[]) +{ + return 0; // Set breakpoint here +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py b/packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py index 97e9e27a6e986..d66d2ac530e5f 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py +++ b/packages/Python/lldbsuite/test/lang/cpp/nsimport/TestCppNsImport.py @@ -2,15 +2,15 @@ Tests imported namespaces in C++. """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class TestCppNsImport(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureFreeBSD("llvm.org/pr25925") - @expectedFailureGcc(None, ['>=', '4.9']) + @expectedFailureAll(oslist=['freebsd'], bugnumber="llvm.org/pr25925") def test_with_run_command(self): """Tests imported namespaces in C++.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/overloaded-functions/TestOverloadedFunctions.py b/packages/Python/lldbsuite/test/lang/cpp/overloaded-functions/TestOverloadedFunctions.py index d485dcd0f6528..ff00d99d7763c 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/overloaded-functions/TestOverloadedFunctions.py +++ b/packages/Python/lldbsuite/test/lang/cpp/overloaded-functions/TestOverloadedFunctions.py @@ -3,8 +3,9 @@ Tests that functions with the same name are resolved correctly. """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class CPPStaticMethodsTestCase(TestBase): @@ -14,7 +15,7 @@ class CPPStaticMethodsTestCase(TestBase): TestBase.setUp(self) self.line = line_number('main.cpp', '// breakpoint') - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") def test_with_run_command(self): """Test that functions with the same name are resolved correctly""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/printf/TestPrintf.py b/packages/Python/lldbsuite/test/lang/cpp/printf/TestPrintf.py new file mode 100644 index 0000000000000..2a2c673f86752 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/printf/TestPrintf.py @@ -0,0 +1,4 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest(__file__, globals(), [decorators.expectedFailureAll(bugnumber="rdar://problem/24599697")] ) diff --git a/packages/Python/lldbsuite/test/lang/cpp/printf/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/printf/main.cpp new file mode 100644 index 0000000000000..badf1be0b41f1 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/printf/main.cpp @@ -0,0 +1,21 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +class PrintfContainer { +public: + int printf() { + return 0; + } +}; + +int main() { + PrintfContainer().printf(); //% self.expect("expression -- printf(\"Hello\\n\")", substrs = ['6']) + return 0; +} + diff --git a/packages/Python/lldbsuite/test/lang/cpp/rvalue-references/TestRvalueReferences.py b/packages/Python/lldbsuite/test/lang/cpp/rvalue-references/TestRvalueReferences.py index d02c34ecb0fe1..78a2727094a77 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/rvalue-references/TestRvalueReferences.py +++ b/packages/Python/lldbsuite/test/lang/cpp/rvalue-references/TestRvalueReferences.py @@ -3,16 +3,17 @@ Tests that rvalue references are supported in C++ """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class RvalueReferencesTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) #rdar://problem/11479676 - @expectedFailureIcc("ICC (13.1, 14-beta) do not emit DW_TAG_rvalue_reference_type.") - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") + @expectedFailureAll(compiler="icc", bugnumber="ICC (13.1, 14-beta) do not emit DW_TAG_rvalue_reference_type.") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") def test_with_run_command(self): """Test that rvalues are supported in the C++ expression parser""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/scope/TestCppScope.py b/packages/Python/lldbsuite/test/lang/cpp/scope/TestCppScope.py index 66d4a15915756..d075eb65b8484 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/scope/TestCppScope.py +++ b/packages/Python/lldbsuite/test/lang/cpp/scope/TestCppScope.py @@ -2,15 +2,16 @@ Test scopes in C++. """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class TestCppScopes(TestBase): mydir = TestBase.compute_mydir(__file__) @expectedFailureDarwin - @expectedFailureWindows("llvm.org/pr24764") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") def test_with_run_command(self): self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/signed_types/TestSignedTypes.py b/packages/Python/lldbsuite/test/lang/cpp/signed_types/TestSignedTypes.py index 51e6d4579e284..3158c4c5bcf0e 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/signed_types/TestSignedTypes.py +++ b/packages/Python/lldbsuite/test/lang/cpp/signed_types/TestSignedTypes.py @@ -12,7 +12,7 @@ import lldb from lldbsuite.test.lldbtest import * import lldbsuite.test.lldbutil as lldbutil -class UnsignedTypesTestCase(TestBase): +class SignedTypesTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -48,7 +48,7 @@ class UnsignedTypesTestCase(TestBase): self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1']) - # Execute the assignment statement. + # Execute the puts(). self.runCmd("thread step-over") # Test that signed types display correctly. diff --git a/packages/Python/lldbsuite/test/lang/cpp/static_members/TestCPPStaticMembers.py b/packages/Python/lldbsuite/test/lang/cpp/static_members/TestCPPStaticMembers.py index 1c41b1b6f571e..dd220d9052785 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/static_members/TestCPPStaticMembers.py +++ b/packages/Python/lldbsuite/test/lang/cpp/static_members/TestCPPStaticMembers.py @@ -8,15 +8,16 @@ from __future__ import print_function import unittest2 import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class CPPStaticMembersTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @unittest2.expectedFailure # llvm.org/pr15401 - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_with_run_command(self): """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/static_methods/TestCPPStaticMethods.py b/packages/Python/lldbsuite/test/lang/cpp/static_methods/TestCPPStaticMethods.py index dba556431e399..9784be189cb44 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/static_methods/TestCPPStaticMethods.py +++ b/packages/Python/lldbsuite/test/lang/cpp/static_methods/TestCPPStaticMethods.py @@ -3,8 +3,9 @@ Tests expressions that distinguish between static and non-static methods. """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class CPPStaticMethodsTestCase(TestBase): @@ -14,7 +15,7 @@ class CPPStaticMethodsTestCase(TestBase): TestBase.setUp(self) self.line = line_number('main.cpp', '// Break at this line') - @expectedFailureWindows + @expectedFailureAll(oslist=["windows"]) def test_with_run_command(self): """Test that static methods are properly distinguished from regular methods""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/stl/TestSTL.py b/packages/Python/lldbsuite/test/lang/cpp/stl/TestSTL.py index 6dba1398947e8..e258208570254 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/stl/TestSTL.py +++ b/packages/Python/lldbsuite/test/lang/cpp/stl/TestSTL.py @@ -9,8 +9,9 @@ from __future__ import print_function import unittest2 import os, time import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class STLTestCase(TestBase): @@ -23,8 +24,7 @@ class STLTestCase(TestBase): self.source = 'main.cpp' self.line = line_number(self.source, '// Set break point at this line.') - # rdar://problem/10400981 - @unittest2.expectedFailure + @expectedFailureAll(bugnumber="rdar://problem/10400981") def test(self): """Test some expressions involving STL data types.""" self.build() @@ -67,7 +67,7 @@ class STLTestCase(TestBase): self.expect('expr associative_array["hello"]', substrs = [' = 2']) - @expectedFailureIcc # icc 13.1 and 14-beta do not emit DW_TAG_template_type_parameter + @expectedFailureAll(compiler="icc", bugnumber="ICC (13.1, 14-beta) do not emit DW_TAG_template_type_parameter.") @add_test_categories(['pyapi']) def test_SBType_template_aspects(self): """Test APIs for getting template arguments from an SBType.""" diff --git a/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py b/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py index d7435c4672747..865516de4edc2 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py +++ b/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py @@ -51,7 +51,8 @@ class StdCXXDisassembleTestCase(TestBase): # Disassemble the functions on the call stack. self.runCmd("thread backtrace") - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) depth = thread.GetNumFrames() for i in range(depth - 1): frame = thread.GetFrameAtIndex(i) diff --git a/packages/Python/lldbsuite/test/lang/cpp/template/Makefile b/packages/Python/lldbsuite/test/lang/cpp/template/Makefile new file mode 100644 index 0000000000000..194af7b323985 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/template/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS += $(NO_LIMIT_DEBUG_INFO_FLAGS) + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateArgs.py b/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateArgs.py new file mode 100644 index 0000000000000..e08d3a10786cc --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateArgs.py @@ -0,0 +1,87 @@ +""" +Test that C++ template classes that have integer parameters work correctly. + +We must reconstruct the types correctly so the template types are correct +and display correctly, and also make sure the expression parser works and +is able the find all needed functions when evaluating expressions +""" +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TemplateArgsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def prepareProcess(self): + self.build() + + # Create a target by the debugger. + exe = os.path.join(os.getcwd(), "a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Set breakpoints inside and outside methods that take pointers to the containing struct. + line = line_number('main.cpp', '// Breakpoint 1') + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, num_expected_locations=1, loc_exact=True) + + arguments = None + environment = None + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple (arguments, environment, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + # Get the thread of the process + self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + + # Get frame for current thread + return thread.GetSelectedFrame() + + def test_integer_args(self): + frame = self.prepareProcess() + + testpos = frame.FindVariable('testpos') + self.assertTrue(testpos.IsValid(), 'make sure we find a local variabble named "testpos"') + self.assertTrue(testpos.GetType().GetName() == 'TestObj<1>') + + expr_result = frame.EvaluateExpression("testpos.getArg()") + self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "testpos.getArg()"'); + self.assertTrue(expr_result.GetValue() == "1", "testpos.getArg() == 1") + self.assertTrue(expr_result.GetType().GetName() == "int", 'expr_result.GetType().GetName() == "int"') + + testneg = frame.FindVariable('testneg') + self.assertTrue(testneg.IsValid(), 'make sure we find a local variabble named "testneg"') + self.assertTrue(testneg.GetType().GetName() == 'TestObj<-1>') + + expr_result = frame.EvaluateExpression("testneg.getArg()") + self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "testneg.getArg()"'); + self.assertTrue(expr_result.GetValue() == "-1", "testneg.getArg() == -1") + self.assertTrue(expr_result.GetType().GetName() == "int", 'expr_result.GetType().GetName() == "int"') + + # Gcc does not generate the necessary DWARF attribute for enum template parameters. + @expectedFailureAll(bugnumber="llvm.org/pr28354", compiler="gcc") + def test_enum_args(self): + frame = self.prepareProcess() + + # Make sure "member" can be displayed and also used in an expression correctly + member = frame.FindVariable('member') + self.assertTrue(member.IsValid(), 'make sure we find a local variabble named "member"') + self.assertTrue(member.GetType().GetName() == 'EnumTemplate<EnumType::Member>') + + expr_result = frame.EvaluateExpression("member.getMember()") + self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "member.getMember()"'); + self.assertTrue(expr_result.GetValue() == "123", "member.getMember() == 123") + self.assertTrue(expr_result.GetType().GetName() == "int", 'expr_result.GetType().GetName() == "int"') + + # Make sure "subclass" can be displayed and also used in an expression correctly + subclass = frame.FindVariable('subclass') + self.assertTrue(subclass.IsValid(), 'make sure we find a local variabble named "subclass"') + self.assertTrue(subclass.GetType().GetName() == 'EnumTemplate<EnumType::Subclass>') + + expr_result = frame.EvaluateExpression("subclass.getMember()") + self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "subclass.getMember()"'); + self.assertTrue(expr_result.GetValue() == "246", "subclass.getMember() == 246") + self.assertTrue(expr_result.GetType().GetName() == "int", 'expr_result.GetType().GetName() == "int"') diff --git a/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp new file mode 100644 index 0000000000000..9c33a64209126 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp @@ -0,0 +1,72 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +template <int Arg> +class TestObj +{ +public: + int getArg() + { + return Arg; + } +}; + +//---------------------------------------------------------------------- +// Define a template class that we can specialize with an enumeration +//---------------------------------------------------------------------- +enum class EnumType +{ + Member, + Subclass +}; + +template <EnumType Arg> class EnumTemplate; + +//---------------------------------------------------------------------- +// Specialization for use when "Arg" is "EnumType::Member" +//---------------------------------------------------------------------- +template <> +class EnumTemplate<EnumType::Member> +{ +public: + EnumTemplate(int m) : + m_member(m) + { + } + + int getMember() const + { + return m_member; + } + +protected: + int m_member; +}; + +//---------------------------------------------------------------------- +// Specialization for use when "Arg" is "EnumType::Subclass" +//---------------------------------------------------------------------- +template <> +class EnumTemplate<EnumType::Subclass> : + public EnumTemplate<EnumType::Member> +{ +public: + EnumTemplate(int m) : EnumTemplate<EnumType::Member>(m) + { + } +}; + +int main(int argc, char **argv) +{ + TestObj<1> testpos; + TestObj<-1> testneg; + EnumTemplate<EnumType::Member> member(123); + EnumTemplate<EnumType::Subclass> subclass(123*2); + return testpos.getArg() - testneg.getArg() + member.getMember()*2 - subclass.getMember(); // Breakpoint 1 +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/this/TestCPPThis.py b/packages/Python/lldbsuite/test/lang/cpp/this/TestCPPThis.py index 07cc2e8e97887..5f89371aa85b3 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/this/TestCPPThis.py +++ b/packages/Python/lldbsuite/test/lang/cpp/this/TestCPPThis.py @@ -2,19 +2,18 @@ Tests that C++ member and static variables are available where they should be. """ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class CPPThisTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) #rdar://problem/9962849 - @expectedFailureGcc # llvm.org/pr15439 The 'this' pointer isn't available during expression evaluation when stopped in an inlined member function. - @expectedFailureIcc # ICC doesn't emit correct DWARF inline debug info for inlined member functions - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") - @expectedFailureWindows("llvm.org/pr24490: We shouldn't be using platform-specific names like `getpid` in tests") - @expectedFlakeyClang(bugnumber='llvm.org/pr23012', compiler_version=['>=','3.6']) # failed with totclang - clang3.7 + @expectedFailureAll(compiler="gcc", bugnumber="llvm.org/pr15439 The 'this' pointer isn't available during expression evaluation when stopped in an inlined member function") + @expectedFailureAll(compiler="icc", bugnumber="ICC doesn't emit correct DWARF inline debug info for inlined member functions.") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") def test_with_run_command(self): """Test that the appropriate member variables are available when stopped in C++ static, inline, and const methods""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/rdar12991846/Makefile b/packages/Python/lldbsuite/test/lang/cpp/unicode-literals/Makefile index 1476447db355e..1476447db355e 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/rdar12991846/Makefile +++ b/packages/Python/lldbsuite/test/lang/cpp/unicode-literals/Makefile diff --git a/packages/Python/lldbsuite/test/lang/cpp/rdar12991846/TestRdar12991846.py b/packages/Python/lldbsuite/test/lang/cpp/unicode-literals/TestUnicodeLiterals.py index 636a82b425dad..1ae133f0b078b 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/rdar12991846/TestRdar12991846.py +++ b/packages/Python/lldbsuite/test/lang/cpp/unicode-literals/TestUnicodeLiterals.py @@ -7,11 +7,11 @@ from __future__ import print_function -import unittest2 import os, time import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil # this test case fails because of rdar://12991846 # the expression parser does not deal correctly with Unicode expressions @@ -26,26 +26,23 @@ import lldbsuite.test.lldbutil as lldbutil # [5] = e\0\0\0 #} -class Rdar12991846TestCase(TestBase): +class UnicodeLiteralsTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @unittest2.expectedFailure("rdar://18684408") - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") def test_expr1(self): """Test that the expression parser returns proper Unicode strings.""" self.build() self.rdar12991846(expr=1) - @unittest2.expectedFailure("rdar://18684408") - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") def test_expr2(self): """Test that the expression parser returns proper Unicode strings.""" self.build() self.rdar12991846(expr=2) - @unittest2.expectedFailure("rdar://18684408") - @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") def test_expr3(self): """Test that the expression parser returns proper Unicode strings.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/rdar12991846/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/unicode-literals/main.cpp index fda951a789915..fda951a789915 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/rdar12991846/main.cpp +++ b/packages/Python/lldbsuite/test/lang/cpp/unicode-literals/main.cpp diff --git a/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py b/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py index c137592558ed4..30aadb3896800 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py +++ b/packages/Python/lldbsuite/test/lang/cpp/unsigned_types/TestUnsignedTypes.py @@ -9,6 +9,7 @@ from __future__ import print_function import os, time import re import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * import lldbsuite.test.lldbutil as lldbutil @@ -22,6 +23,7 @@ class UnsignedTypesTestCase(TestBase): # Find the line number to break inside main(). self.line = line_number('main.cpp', '// Set break point at this line.') + @expectedFailureAll(oslist=["windows"]) def test(self): """Test that variables with unsigned types display correctly.""" self.build() diff --git a/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py b/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py index 1553a43e1a739..bee148773f03b 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py +++ b/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py @@ -7,8 +7,9 @@ from __future__ import print_function import os, time import re import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil def Msg(expr, val): return "'expression %s' matches the output (from compiled code): %s" % (expr, val) @@ -21,9 +22,6 @@ class CppVirtualMadness(TestBase): # printf() stmts (see main.cpp). pattern = re.compile("^([^=]*) = '([^=]*)'$") - # Assert message. - PRINTF_OUTPUT_GROKKED = "The printf output from compiled code is parsed correctly" - def setUp(self): # Call super's setUp(). TestBase.setUp(self) @@ -31,7 +29,7 @@ class CppVirtualMadness(TestBase): self.source = 'main.cpp' self.line = line_number(self.source, '// Set first breakpoint here.') - @expectedFailureIcc('llvm.org/pr16808') # lldb does not call the correct virtual function with icc + @expectedFailureAll(compiler="icc", bugnumber="llvm.org/pr16808 lldb does not call the correct virtual function with icc.") @expectedFailureAll(oslist=['windows']) def test_virtual_madness(self): """Test that expression works correctly with virtual inheritance as well as virtual function.""" @@ -57,11 +55,13 @@ class CppVirtualMadness(TestBase): thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") - # First, capture the golden output from the program itself from the - # series of printf statements. - stdout = process.GetSTDOUT(1024) - - self.assertIsNotNone(stdout, "Encountered an error reading the process's output") + # First, capture the golden output from the program itself. + golden = thread.GetFrameAtIndex(0).FindVariable("golden") + self.assertTrue(golden.IsValid(), "Encountered an error reading the process's golden variable") + error = lldb.SBError() + golden_str = process.ReadCStringFromMemory(golden.AddressOf().GetValueAsUnsigned(), 4096, error); + self.assertTrue(error.Success()) + self.assertTrue("c_as_C" in golden_str) # This golden list contains a list of "my_expr = 'value' pairs extracted # from the golden output. @@ -71,7 +71,7 @@ class CppVirtualMadness(TestBase): # # my_expr = 'value' # - for line in stdout.split(os.linesep): + for line in golden_str.split(os.linesep): match = self.pattern.search(line) if match: my_expr, val = match.group(1), match.group(2) diff --git a/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp index bed1422dcbdd5..0adf415773142 100644 --- a/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp +++ b/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp @@ -84,17 +84,20 @@ int main (int argc, char const *argv[], char const *envp[]) C *c_as_C = new C(); A *c_as_A = c_as_C; - printf ("a_as_A->a() = '%s'\n", a_as_A->a()); - printf ("a_as_A->b() = '%s'\n", a_as_A->b()); - printf ("a_as_A->c() = '%s'\n", a_as_A->c()); - printf ("b_as_A->a() = '%s'\n", b_as_A->a()); - printf ("b_as_A->b() = '%s'\n", b_as_A->b()); - printf ("b_as_A->c() = '%s'\n", b_as_A->c()); - printf ("b_as_B->aa() = '%s'\n", b_as_B->aa()); - printf ("c_as_A->a() = '%s'\n", c_as_A->a()); - printf ("c_as_A->b() = '%s'\n", c_as_A->b()); - printf ("c_as_A->c() = '%s'\n", c_as_A->c()); - printf ("c_as_C->aa() = '%s'\n", c_as_C->aa()); + char golden[4096]; + char *p = golden; + char *end = p + sizeof golden; + p += snprintf(p, end-p, "a_as_A->a() = '%s'\n", a_as_A->a()); + p += snprintf(p, end-p, "a_as_A->b() = '%s'\n", a_as_A->b()); + p += snprintf(p, end-p, "a_as_A->c() = '%s'\n", a_as_A->c()); + p += snprintf(p, end-p, "b_as_A->a() = '%s'\n", b_as_A->a()); + p += snprintf(p, end-p, "b_as_A->b() = '%s'\n", b_as_A->b()); + p += snprintf(p, end-p, "b_as_A->c() = '%s'\n", b_as_A->c()); + p += snprintf(p, end-p, "b_as_B->aa() = '%s'\n", b_as_B->aa()); + p += snprintf(p, end-p, "c_as_A->a() = '%s'\n", c_as_A->a()); + p += snprintf(p, end-p, "c_as_A->b() = '%s'\n", c_as_A->b()); + p += snprintf(p, end-p, "c_as_A->c() = '%s'\n", c_as_A->c()); + p += snprintf(p, end-p, "c_as_C->aa() = '%s'\n", c_as_C->aa()); puts("");// Set first breakpoint here. // then evaluate: // expression a_as_A->a() |