diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/expression_command')
43 files changed, 812 insertions, 56 deletions
diff --git a/packages/Python/lldbsuite/test/expression_command/anonymous-struct/Makefile b/packages/Python/lldbsuite/test/expression_command/anonymous-struct/Makefile new file mode 100644 index 000000000000..7df664ac43e3 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/anonymous-struct/Makefile @@ -0,0 +1,12 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +# clang-3.5+ outputs FullDebugInfo by default for Darwin/FreeBSD +# targets. Other targets do not, which causes this test to fail. +# This flag enables FullDebugInfo for all targets. +ifneq (,$(findstring clang,$(CC))) + CFLAGS_EXTRAS += -fno-limit-debug-info +endif + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py b/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py new file mode 100644 index 000000000000..e1a53305a0d0 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py @@ -0,0 +1,42 @@ +""" +Test calling user defined functions using expression evaluation. +This test checks that typesystem lookup works correctly for typedefs of +untagged structures. + +Ticket: https://llvm.org/bugs/show_bug.cgi?id=26790 +""" + +from __future__ import print_function + +import lldb + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestExprLookupAnonStructTypedef(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + # Find the breakpoint + self.line = line_number('main.cpp', '// lldb testsuite break') + + @expectedFailureAll(oslist=["windows"]) + @expectedFailureAll(oslist=['linux'], archs=['arm'], bugnumber="llvm.org/pr27868") + def test(self): + """Test typedeffed untagged struct arguments for function call expressions""" + self.build() + + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + lldbutil.run_break_set_by_file_and_line( + self, + "main.cpp", + self.line, + num_expected_locations=-1, + loc_exact=True + ) + + self.runCmd("run", RUN_SUCCEEDED) + self.expect("expr multiply(&s)", substrs=['$0 = 1']) diff --git a/packages/Python/lldbsuite/test/expression_command/anonymous-struct/main.cpp b/packages/Python/lldbsuite/test/expression_command/anonymous-struct/main.cpp new file mode 100644 index 000000000000..5b170c5f943a --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/anonymous-struct/main.cpp @@ -0,0 +1,26 @@ +#include <tgmath.h> + +typedef struct { + float f; + int i; +} my_untagged_struct; + +double multiply(my_untagged_struct *s) +{ + return s->f * s->i; +} + +double multiply(my_untagged_struct *s, int x) +{ + return multiply(s) * x; +} + +int main(int argc, char **argv) +{ + my_untagged_struct s = { + .f = (float)argc, + .i = argc, + }; + // lldb testsuite break + return !(multiply(&s, argc) == pow(argc, 3)); +} diff --git a/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py b/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py index 3756b4a8cea4..61702ee88033 100644 --- a/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py +++ b/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCommandCallFunctionTestCase(TestBase): @@ -21,9 +22,9 @@ class ExprCommandCallFunctionTestCase(TestBase): self.line = line_number('main.cpp', '// Please test these expressions while stopped at this line:') - @expectedFailureIcc # llvm.org/pr14437, fails with ICC 13.1 - @expectedFailureFreeBSD('llvm.org/pr17807') # Fails on FreeBSD buildbot - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(compiler="icc", bugnumber="llvm.org/pr14437, fails with ICC 13.1") + @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr17807 Fails on FreeBSD buildbot') + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_with(self): """Test calling std::String member function.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py b/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py index f6d63885248a..4d18cfc980f2 100644 --- a/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py +++ b/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCommandCallStopContinueTestCase(TestBase): @@ -24,7 +25,7 @@ class ExprCommandCallStopContinueTestCase(TestBase): '{ 5, "five" }') @expectedFlakeyDarwin("llvm.org/pr20274") - @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(self): """Test gathering result from interrupted function call.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py b/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py index 9138af0b0b47..c0727a84fc02 100644 --- a/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py +++ b/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py @@ -12,8 +12,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCommandCallUserDefinedFunction(TestBase): @@ -26,7 +27,7 @@ class ExprCommandCallUserDefinedFunction(TestBase): self.line = line_number('main.cpp', '// Please test these expressions while stopped at this line:') @expectedFlakeyDsym("llvm.org/pr20274") - @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(self): """Test return values of user defined function calls.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py b/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py index abf48742567d..6b754a76878b 100644 --- a/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py +++ b/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCommandThatRestartsTestCase(TestBase): diff --git a/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py b/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py index 0e766ac2953a..a6eb1bddc005 100644 --- a/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py +++ b/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCommandWithThrowTestCase(TestBase): diff --git a/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py b/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py index 5e1f307f622d..66fa69cdfff2 100644 --- a/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py +++ b/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py @@ -3,8 +3,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCharTestCase(TestBase): @@ -52,19 +53,17 @@ class ExprCharTestCase(TestBase): self.assertTrue(value.GetError().Success()) self.assertEqual(value.GetValueAsSigned(0), 3) - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_default_char(self): self.do_test() - @expectedFailureArch("arm", "llvm.org/pr23069") - @expectedFailureArch("aarch64", "llvm.org/pr23069") - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(archs=["arm", "aarch64", "s390x"], bugnumber="llvm.org/pr23069") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_signed_char(self): self.do_test(dictionary={'CFLAGS_EXTRAS': '-fsigned-char'}) - @expectedFailurei386("llvm.org/pr23069") - @expectedFailurex86_64("llvm.org/pr23069") - @expectedFailureWindows("llvm.org/pr21765") - @expectedFailureAll(bugnumber="llvm.org/pr23069", triple = 'mips*') + @expectedFailureAll(archs=["i[3-6]86", "x86_64"], bugnumber="llvm.org/pr23069") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") + @expectedFailureAll(triple = 'mips*', bugnumber="llvm.org/pr23069") def test_unsigned_char(self): self.do_test(dictionary={'CFLAGS_EXTRAS': '-funsigned-char'}) diff --git a/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py b/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py index 0430fa55f995..a715ee31e5fa 100644 --- a/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py +++ b/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py @@ -6,15 +6,16 @@ from __future__ import print_function import os import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class ExprSyscallTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureWindows("llvm.org/pr21765") # Also getpid() is not a function on Windows anyway + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765, getpid() does not exist on Windows") def test_setpgid(self): self.build() self.expr_syscall() diff --git a/packages/Python/lldbsuite/test/expression_command/fixits/Makefile b/packages/Python/lldbsuite/test/expression_command/fixits/Makefile new file mode 100644 index 000000000000..7df664ac43e3 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/fixits/Makefile @@ -0,0 +1,12 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +# clang-3.5+ outputs FullDebugInfo by default for Darwin/FreeBSD +# targets. Other targets do not, which causes this test to fail. +# This flag enables FullDebugInfo for all targets. +ifneq (,$(findstring clang,$(CC))) + CFLAGS_EXTRAS += -fno-limit-debug-info +endif + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py b/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py new file mode 100644 index 000000000000..7e11f2b201f2 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py @@ -0,0 +1,81 @@ +""" +Test calling an expression with errors that a FixIt can fix. +""" + +from __future__ import print_function + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class ExprCommandWithFixits(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + self.main_source = "main.cpp" + self.main_source_spec = lldb.SBFileSpec (self.main_source) + + @skipUnlessDarwin + def test(self): + """Test calling a function that throws and ObjC exception.""" + self.build() + self.try_expressions() + + def try_expressions(self): + """Test calling expressions with errors that can be fixed by the FixIts.""" + exe_name = "a.out" + exe = os.path.join(os.getcwd(), exe_name) + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + breakpoint = target.BreakpointCreateBySourceRegex('Stop here to evaluate expressions',self.main_source_spec) + self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) + + # Launch the process, and do not stop at the entry point. + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + + self.assertTrue(process, PROCESS_IS_VALID) + + # Frame #0 should be at our breakpoint. + threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) + + self.assertTrue(len(threads) == 1) + self.thread = threads[0] + + options = lldb.SBExpressionOptions() + options.SetAutoApplyFixIts(True) + + frame = self.thread.GetFrameAtIndex(0) + + # Try with one error: + value = frame.EvaluateExpression("my_pointer.first", options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertTrue(value.GetValueAsUnsigned() == 10) + + # Try with two errors: + two_error_expression = "my_pointer.second->a" + value = frame.EvaluateExpression(two_error_expression, options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertTrue(value.GetValueAsUnsigned() == 20) + + # Now turn off the fixits, and the expression should fail: + options.SetAutoApplyFixIts(False) + value = frame.EvaluateExpression(two_error_expression, options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Fail()) + error_string = value.GetError().GetCString() + self.assertTrue(error_string.find("fixed expression suggested:") != -1, "Fix was suggested") + self.assertTrue(error_string.find("my_pointer->second.a") != -1, "Fix was right") + + + diff --git a/packages/Python/lldbsuite/test/expression_command/fixits/main.cpp b/packages/Python/lldbsuite/test/expression_command/fixits/main.cpp new file mode 100644 index 000000000000..371d8333763b --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/fixits/main.cpp @@ -0,0 +1,25 @@ +#include <stdio.h> + +struct SubStruct +{ + int a; + int b; +}; + +struct MyStruct +{ + int first; + struct SubStruct second; +}; + +int +main() +{ + struct MyStruct my_struct = {10, {20, 30}}; + struct MyStruct *my_pointer = &my_struct; + printf ("Stop here to evaluate expressions: %d %d %p\n", my_pointer->first, my_pointer->second.a, my_pointer); + return 0; +} + + + diff --git a/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py b/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py index 3f47206480c3..4a99dc479019 100644 --- a/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py +++ b/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprFormattersTestCase(TestBase): @@ -22,9 +23,8 @@ class ExprFormattersTestCase(TestBase): '// Stop here') @skipIfFreeBSD # llvm.org/pr24691 skipping to avoid crashing the test runner - @expectedFailureFreeBSD('llvm.org/pr19011') # Newer Clang omits C1 complete object constructor - @expectedFailureFreeBSD('llvm.org/pr24691') # we hit an assertion in clang - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr19011 Newer Clang omits C1 complete object constructor') + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") @skipIfTargetAndroid() # skipping to avoid crashing the test runner @expectedFailureAndroid('llvm.org/pr24691') # we hit an assertion in clang def test(self): diff --git a/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/Makefile b/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/Makefile new file mode 100644 index 000000000000..8a7102e347af --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py b/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py new file mode 100644 index 000000000000..c4f176703225 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py @@ -0,0 +1,40 @@ +""" +Test PHI nodes work in the IR interpreter. +""" + +import os, os.path + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + +class IRInterpreterPHINodesTestCase(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def test_phi_node_support(self): + """Test support for PHI nodes in the IR interpreter.""" + + self.build() + exe = os.path.join(os.getcwd(), 'a.out') + self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET) + + # Break on the first assignment to i + line = line_number('main.cpp', 'i = 5') + lldbutil.run_break_set_by_file_and_line(self, 'main.cpp', line, num_expected_locations=1, 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']) + + self.runCmd('s') + + # The logical 'or' causes a PHI node to be generated. Execute without JIT + # to test that the interpreter can handle this + self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['true']) + + self.runCmd('s') + self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['false']) + self.runCmd('s') + self.expect('expr -j 0 -- i == 3 || i == 5', substrs=['true']) diff --git a/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/main.cpp b/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/main.cpp new file mode 100644 index 000000000000..b144f9cc1b47 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/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. +// +//===----------------------------------------------------------------------===// + +int main() +{ + int i; + i = 5; + i = 2; + i = 3; + return 0; +} diff --git a/packages/Python/lldbsuite/test/expression_command/ir-interpreter/Makefile b/packages/Python/lldbsuite/test/expression_command/ir-interpreter/Makefile new file mode 100644 index 000000000000..c4169a9b1012 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/ir-interpreter/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../make + +default: a.out + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py b/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py new file mode 100644 index 000000000000..2a21d0473715 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py @@ -0,0 +1,72 @@ +""" +Test the IR interpreter +""" + +from __future__ import print_function + +import unittest2 + +import os, time +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class IRInterpreterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number('main.c', + '// Set breakpoint here') + + # Disable confirmation prompt to avoid infinite wait + self.runCmd("settings set auto-confirm true") + self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm")) + + def build_and_run(self): + """Test the IR interpreter""" + self.build() + + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + @add_test_categories(['pyapi']) + @expectedFailureAll(oslist=['windows'], bugnumber="http://llvm.org/pr21765") # getpid() is POSIX, among other problems, see bug + @expectedFailureAll(oslist=['linux'], archs=['arm'], bugnumber="llvm.org/pr27868") + def test_ir_interpreter(self): + self.build_and_run() + + options = lldb.SBExpressionOptions() + options.SetLanguage(lldb.eLanguageTypeC_plus_plus) + + set_up_expressions = ["int $i = 9", "int $j = 3", "int $k = 5"] + + expressions = ["$i + $j", + "$i - $j", + "$i * $j", + "$i / $j", + "$i % $k", + "$i << $j", + "$i & $j", + "$i | $j", + "$i ^ $j"] + + for expression in set_up_expressions: + self.frame().EvaluateExpression(expression, options) + + for expression in expressions: + interp_expression = expression + jit_expression = "(int)getpid(); " + expression + + interp_result = self.frame().EvaluateExpression(interp_expression, options).GetValueAsSigned() + jit_result = self.frame().EvaluateExpression(jit_expression, options).GetValueAsSigned() + + self.assertEqual(interp_result, jit_result, "While evaluating " + expression) + diff --git a/packages/Python/lldbsuite/test/expression_command/ir-interpreter/main.c b/packages/Python/lldbsuite/test/expression_command/ir-interpreter/main.c new file mode 100644 index 000000000000..31204b21d972 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/ir-interpreter/main.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main() +{ + printf("This is a dummy\n"); // Set breakpoint here + return 0; +} diff --git a/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py b/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py index fdc981ea178d..2d0b23b4e5ba 100644 --- a/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py +++ b/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py @@ -10,14 +10,15 @@ 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 Issue11581TestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureWindows("llvm.org/pr24778") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") def test_11581_commands(self): # This is the function to remove the custom commands in order to have a # clean slate for the next test case. diff --git a/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py b/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py index c3d6306c5a63..939d2e45d7d5 100644 --- a/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py +++ b/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py @@ -1,13 +1,17 @@ +from __future__ import print_function + + import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class TestMacros(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureClang("clang does not emit .debug_macro[.dwo] sections.") - @expectedFailureDwo("GCC produces multiple .debug_macro.dwo sections and the spec is unclear as to what it means") + @expectedFailureAll(compiler="clang", bugnumber="clang does not emit .debug_macro[.dwo] sections.") + @expectedFailureAll(debug_info="dwo", bugnumber="GCC produces multiple .debug_macro.dwo sections and the spec is unclear as to what it means") @expectedFailureAll(hostoslist=["windows"], compiler="gcc", triple='.*-android') def test_expr_with_macros(self): self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/multiline/Makefile b/packages/Python/lldbsuite/test/expression_command/multiline/Makefile new file mode 100644 index 000000000000..0d70f2595019 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/multiline/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/expression_command/multiline/TestMultilineExpressions.py b/packages/Python/lldbsuite/test/expression_command/multiline/TestMultilineExpressions.py new file mode 100644 index 000000000000..0691a866743b --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/multiline/TestMultilineExpressions.py @@ -0,0 +1,57 @@ +"""Test multiline expressions.""" + +from __future__ import print_function + +import os +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class MultilineExpressionsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break on inside main.cpp. + self.line = line_number('main.c', 'break') + + @skipIfRemote + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr22274: need a pexpect replacement for windows") + def test_with_run_commands(self): + """Test that multiline expressions work correctly""" + self.build() + import pexpect + exe = os.path.join(os.getcwd(), "a.out") + prompt = "(lldb) " + + # So that the child gets torn down after the test. + self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe)) + child = self.child + # Turn on logging for what the child sends back. + if self.TraceOn(): + child.logfile_read = sys.stdout + + # Set the breakpoint, run the inferior, when it breaks, issue print on + # the various convenience variables. + child.expect_exact(prompt) + child.sendline('breakpoint set -f main.c -l %d' % self.line) + child.expect_exact(prompt) + child.sendline('run') + child.expect_exact("stop reason = breakpoint 1.1") + child.expect_exact(prompt) + child.sendline('expr') + child.expect_exact('1:') + + child.sendline('2+') + child.expect_exact('2:') + + child.sendline('3') + child.expect_exact('3:') + + child.sendline('') + child.expect_exact(prompt) + self.expect(child.before, exe=False, + patterns = ['= 5']) diff --git a/packages/Python/lldbsuite/test/expression_command/multiline/main.c b/packages/Python/lldbsuite/test/expression_command/multiline/main.c new file mode 100644 index 000000000000..da16b1e7846f --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/multiline/main.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char const *argv[]) { + printf("Hello world.\n"); // break here + return 0; +} diff --git a/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py b/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py index 7b0707cdf22c..d3ce10d8f2ab 100644 --- a/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py +++ b/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class PersistObjCPointeeType(TestBase): diff --git a/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py b/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py index 3ea5b7040655..9099ae1806e3 100644 --- a/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py +++ b/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.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 NestedPersistentTypesTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_persistent_types(self): """Test that nested persistent types work.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py b/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py index 47c6675511fd..59e0f0b84f69 100644 --- a/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py +++ b/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.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 PersistenttypesTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_persistent_types(self): """Test that lldb persistent types works correctly.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py b/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py index e415b92a43a6..da87bcee9cfc 100644 --- a/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py +++ b/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class PoVerbosityTestCase(TestBase): diff --git a/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py b/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py index fb16d2a93326..e0b219dbe2b9 100644 --- a/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py +++ b/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py @@ -8,15 +8,16 @@ 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 Radar9531204TestCase(TestBase): mydir = TestBase.compute_mydir(__file__) # rdar://problem/9531204 - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_expr_commands(self): """The evaluating printf(...) after break stop and then up a stack frame.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py b/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py index ce3e51d05149..a1505b08c508 100644 --- a/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py +++ b/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.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 Radar9673644TestCase(TestBase): @@ -22,7 +23,7 @@ class Radar9673644TestCase(TestBase): self.main_source = "main.c" self.line = line_number(self.main_source, '// Set breakpoint here.') - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_expr_commands(self): """The following expression commands should just work.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py b/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py index ec3e7f93af26..8c9a9a5a27e7 100644 --- a/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py +++ b/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py @@ -19,8 +19,9 @@ 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 BasicExprCommandsTestCase(TestBase): @@ -56,7 +57,6 @@ class BasicExprCommandsTestCase(TestBase): patterns = ["\(float\) \$.* = 2\.234"]) # (float) $2 = 2.234 - @expectedFailureWindows("llvm.org/pr21765") def test_many_expr_commands(self): self.build_and_run() @@ -98,7 +98,7 @@ class BasicExprCommandsTestCase(TestBase): # (const char *) $8 = 0x... "/Volumes/data/lldb/svn/trunk/test/expression_command/test/a.out" @add_test_categories(['pyapi']) - @expectedFailureWindows # Test crashes + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_evaluate_expression_python(self): """Test SBFrame.EvaluateExpression() API for evaluating an expression.""" self.build() @@ -130,12 +130,8 @@ class BasicExprCommandsTestCase(TestBase): "instead the actual state is: '%s'" % 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_one_thread_stopped_at_breakpoint(process, breakpoint) + self.assertIsNotNone(thread, "Expected one thread to be stopped at the breakpoint") # The filename of frame #0 should be 'main.cpp' and function is main. self.expect(lldbutil.get_filenames(thread)[0], @@ -198,7 +194,7 @@ class BasicExprCommandsTestCase(TestBase): # rdar://problem/8686536 # CommandInterpreter::HandleCommand is stripping \'s from input for WantsRawCommand commands - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_expr_commands_can_handle_quotes(self): """Throw some expression commands with quotes at lldb.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py b/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py index 578a037e9f0f..523ee51a9f18 100644 --- a/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py +++ b/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py @@ -8,8 +8,9 @@ from __future__ import print_function import os import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCommands2TestCase(TestBase): @@ -22,7 +23,7 @@ class ExprCommands2TestCase(TestBase): self.line = line_number('main.cpp', '// Please test many expressions while stopped at this line:') - @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_more_expr_commands(self): """Test some more expression commands.""" self.build() diff --git a/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py b/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py index a602afc47edb..7cb4a647efb4 100644 --- a/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py +++ b/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py @@ -7,8 +7,9 @@ from __future__ import print_function import lldb -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil class ExprCommandWithTimeoutsTestCase(TestBase): @@ -23,8 +24,7 @@ class ExprCommandWithTimeoutsTestCase(TestBase): @expectedFlakeyFreeBSD("llvm.org/pr19605") - @expectedFlakeyLinux("llvm.org/pr20275") - @expectedFailureWindows("llvm.org/pr21765") + @expectedFailureAll(oslist=["windows", "macosx"], bugnumber="llvm.org/pr21765") def test(self): """Test calling std::String member function.""" self.build() @@ -57,7 +57,7 @@ class ExprCommandWithTimeoutsTestCase(TestBase): frame = thread.GetFrameAtIndex(0) - value = frame.EvaluateExpression ("wait_a_while (200000)", options) + value = frame.EvaluateExpression("wait_a_while(300000)", options) self.assertTrue (value.IsValid()) self.assertFalse (value.GetError().Success()) @@ -65,7 +65,7 @@ class ExprCommandWithTimeoutsTestCase(TestBase): interp = self.dbg.GetCommandInterpreter() result = lldb.SBCommandReturnObject() - return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(200000)", result) + return_value = interp.HandleCommand("expr -t 100 -u true -- wait_a_while(300000)", result) self.assertTrue (return_value == lldb.eReturnStatusFailed) # Okay, now do it again with long enough time outs: diff --git a/packages/Python/lldbsuite/test/expression_command/top-level/Makefile b/packages/Python/lldbsuite/test/expression_command/top-level/Makefile new file mode 100644 index 000000000000..7146f227b98a --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/top-level/Makefile @@ -0,0 +1,12 @@ +LEVEL = ../../make + +default: a.out dummy + +CXX_SOURCES := main.cpp test.cpp + +dummy: dummy.cpp + +clean:: + rm -rf dummy dummy.dSYM + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py b/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py new file mode 100644 index 000000000000..9a17624cb8e6 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py @@ -0,0 +1,89 @@ +""" +Test top-level expressions. +""" + +from __future__ import print_function + + + +import unittest2 + +import os, time +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TopLevelExpressionsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.c. + self.line = line_number('main.cpp', + '// Set breakpoint here') + self.dummy_line = line_number('dummy.cpp', + '// Set breakpoint here') + + # Disable confirmation prompt to avoid infinite wait + self.runCmd("settings set auto-confirm true") + self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm")) + + + def build_and_run(self): + """Test top-level expressions.""" + self.build() + + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + def run_dummy(self): + self.runCmd("file dummy", CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line (self, "dummy.cpp", self.dummy_line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + @add_test_categories(['pyapi']) + @expectedFailureAndroid(api_levels=[21, 22], bugnumber="llvm.org/pr27787") + @expectedFailureAll(oslist=["linux"], archs=["arm", "aarch64"], bugnumber="llvm.org/pr27787") + @expectedFailureAll(bugnumber="llvm.org/pr28353", oslist=["linux"], archs=["i386", "x86_64"], compiler="gcc", compiler_version=["<", "4.9"]) + @skipIf(debug_info="gmodules") # not relevant + @skipIf(oslist=["windows"]) # Error in record layout on Windows + def test_top_level_expressions(self): + self.build_and_run() + + resultFromCode = self.frame().EvaluateExpression("doTest()").GetValueAsUnsigned() + + self.runCmd("kill") + + self.run_dummy() + + codeFile = open('test.cpp', 'r') + + expressions = [] + current_expression = "" + + for line in codeFile: + if line.startswith("// --"): + expressions.append(current_expression) + current_expression = "" + else: + current_expression += line + + options = lldb.SBExpressionOptions() + options.SetLanguage(lldb.eLanguageTypeC_plus_plus) + options.SetTopLevel(True) + + for expression in expressions: + self.frame().EvaluateExpression(expression, options) + + resultFromTopLevel = self.frame().EvaluateExpression("doTest()") + + self.assertTrue(resultFromTopLevel.IsValid()) + self.assertEqual(resultFromCode, resultFromTopLevel.GetValueAsUnsigned()) diff --git a/packages/Python/lldbsuite/test/expression_command/top-level/dummy.cpp b/packages/Python/lldbsuite/test/expression_command/top-level/dummy.cpp new file mode 100644 index 000000000000..31204b21d972 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/top-level/dummy.cpp @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main() +{ + printf("This is a dummy\n"); // Set breakpoint here + return 0; +} diff --git a/packages/Python/lldbsuite/test/expression_command/top-level/main.cpp b/packages/Python/lldbsuite/test/expression_command/top-level/main.cpp new file mode 100644 index 000000000000..f9b2dd4c6d9d --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/top-level/main.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> + +extern int doTest(); + +int main() +{ + printf("%d\n", doTest()); // Set breakpoint here + return 0; +} diff --git a/packages/Python/lldbsuite/test/expression_command/top-level/test.cpp b/packages/Python/lldbsuite/test/expression_command/top-level/test.cpp new file mode 100644 index 000000000000..ce2ea3bbb131 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/top-level/test.cpp @@ -0,0 +1,107 @@ +class MyClass +{ +public: + int memberResult() + { + return 1; + } + static int staticResult() + { + return 1; + } + int externResult(); +}; + +// -- + +int MyClass::externResult() +{ + return 1; +} + +// -- + +MyClass m; + +// -- + +enum MyEnum { + myEnumOne = 1, + myEnumTwo, + myEnumThree +}; + +// -- + +class AnotherClass +{ +public: + __attribute__ ((always_inline)) int complicatedFunction() + { + struct { + int i; + } s = { 15 }; + + int as[4] = { 2, 3, 4, 5 }; + + for (signed char a : as) + { + s.i -= a; + } + + return s.i; + } +}; + +// -- + +class DiamondA +{ +private: + struct { + int m_i; + }; +public: + DiamondA(int i) : m_i(i) { } + int accessor() { return m_i; } +}; + +// -- + +class DiamondB : public virtual DiamondA +{ +public: + DiamondB(int i) : DiamondA(i) { } +}; + +// -- + +class DiamondC : public virtual DiamondA +{ +public: + DiamondC(int i) : DiamondA(i) { } +}; + +// -- + +class DiamondD : public DiamondB, public DiamondC +{ +public: + DiamondD(int i) : DiamondA(i), DiamondB(i), DiamondC(i) { } +}; + +// -- + +int doTest() +{ + int a = m.memberResult(); + a += MyClass::staticResult(); + a += m.externResult(); + a += MyEnum::myEnumThree; + a += myEnumOne; + a += AnotherClass().complicatedFunction(); + a += DiamondD(3).accessor(); + return a; +} + +// -- diff --git a/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py b/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py index 5b0233509112..2b37faad807b 100644 --- a/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py +++ b/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py @@ -9,8 +9,9 @@ from __future__ import print_function import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test import lldbutil class ObjCTypeQueryTestCase(TestBase): diff --git a/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile b/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile new file mode 100644 index 000000000000..8a7102e347af --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py b/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py new file mode 100644 index 000000000000..6e9af641d038 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py @@ -0,0 +1,83 @@ +""" +Test stopping at a breakpoint in an expression, and unwinding from there. +""" + +from __future__ import print_function + + + +import unittest2 + +import os, time +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class UnwindFromExpressionTest(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + @add_test_categories(['pyapi']) + + def test_unwind_expression(self): + """Test unwinding from an expression.""" + self.build() + + exe = os.path.join(os.getcwd(), "a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Create the breakpoint. + main_spec = lldb.SBFileSpec("main.cpp", False) + breakpoint = target.BreakpointCreateBySourceRegex("// Set a breakpoint here to get started", main_spec) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + # Launch the process, and do not stop at the entry point. + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + + if not process: + self.fail("SBTarget.LaunchProcess() failed") + + if process.GetState() != lldb.eStateStopped: + self.fail("Process should be in the 'stopped' state, " + "instead the actual state is: '%s'" % + lldbutil.state_type_to_str(process.GetState())) + + thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, breakpoint) + self.assertIsNotNone(thread, "Expected one thread to be stopped at the breakpoint") + + # + # Use Python API to evaluate expressions while stopped in a stack frame. + # + main_frame = thread.GetFrameAtIndex(0) + + # Next set a breakpoint in this function, set up Expression options to stop on + # breakpoint hits, and call the function. + fun_bkpt = target.BreakpointCreateBySourceRegex("// Stop inside the function here.", main_spec) + self.assertTrue(fun_bkpt, VALID_BREAKPOINT) + options = lldb.SBExpressionOptions() + options.SetIgnoreBreakpoints(False) + options.SetUnwindOnError(False) + + val = main_frame.EvaluateExpression("a_function_to_call()", options) + + self.assertTrue(val.GetError().Fail(), "We did not complete the execution.") + error_str = val.GetError().GetCString() + self.assertTrue("Execution was interrupted, reason: breakpoint" in error_str, "And the reason was right.") + + thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, fun_bkpt) + self.assertTrue(thread.IsValid(), "We are indeed stopped at our breakpoint") + + # Now unwind the expression, and make sure we got back to where we started. + error = thread.UnwindInnermostExpression() + self.assertTrue(error.Success(), "We succeeded in unwinding") + + cur_frame = thread.GetFrameAtIndex(0) + self.assertTrue(cur_frame.IsEqual(main_frame), "We got back to the main frame.") + diff --git a/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp b/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp new file mode 100644 index 000000000000..e93c34a30b03 --- /dev/null +++ b/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp @@ -0,0 +1,14 @@ +static int static_value = 0; + +int +a_function_to_call() +{ + static_value++; // Stop inside the function here. + return static_value; +} + +int main (int argc, char const *argv[]) +{ + a_function_to_call(); // Set a breakpoint here to get started + return 0; +} |