diff options
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/expression_command')
34 files changed, 1006 insertions, 574 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py b/lldb/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py index e1a53305a0d..2d4504f7ba4 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/anonymous-struct/TestCallUserAnonTypedef.py @@ -24,7 +24,10 @@ class TestExprLookupAnonStructTypedef(TestBase): self.line = line_number('main.cpp', '// lldb testsuite break') @expectedFailureAll(oslist=["windows"]) - @expectedFailureAll(oslist=['linux'], archs=['arm'], bugnumber="llvm.org/pr27868") + @expectedFailureAll( + oslist=['linux'], + archs=['arm'], + bugnumber="llvm.org/pr27868") def test(self): """Test typedeffed untagged struct arguments for function call expressions""" self.build() diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py b/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py index 61702ee8803..6645692f93e 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStdStringFunction.py @@ -5,12 +5,12 @@ Test calling std::String member functions. from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprCommandCallFunctionTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -19,26 +19,33 @@ class ExprCommandCallFunctionTestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.c. - self.line = line_number('main.cpp', - '// Please test these expressions while stopped at this line:') - - @expectedFailureAll(compiler="icc", bugnumber="llvm.org/pr14437, fails with ICC 13.1") - @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr17807 Fails on FreeBSD buildbot') + self.line = line_number( + 'main.cpp', + '// Please test these expressions while stopped at this line:') + + @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() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - # Some versions of GCC encode two locations for the 'return' statement in main.cpp - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) + # Some versions of GCC encode two locations for the 'return' statement + # in main.cpp + 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("print str", - substrs = ['Hello world']) + substrs=['Hello world']) # Calling this function now succeeds, but we follow the typedef return type through to # const char *, and thus don't invoke the Summary formatter. self.expect("print str.c_str()", - substrs = ['Hello world']) + substrs=['Hello world']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py b/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py index 066d94bd19d..a48a38aaf92 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallStopAndContinue.py @@ -5,12 +5,12 @@ Test calling a function, stopping in the call, continue and gather the result on from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprCommandCallStopContinueTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -19,28 +19,40 @@ class ExprCommandCallStopContinueTestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.c. - self.line = line_number('main.cpp', - '// Please test these expressions while stopped at this line:') - self.func_line = line_number ('main.cpp', '{5, "five"}') + self.line = line_number( + 'main.cpp', + '// Please test these expressions while stopped at this line:') + self.func_line = line_number('main.cpp', '{5, "five"}') @expectedFlakeyDarwin("llvm.org/pr20274") - @expectedFailureAll(oslist=["windows"], bugnumber="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() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - # Some versions of GCC encode two locations for the 'return' statement in main.cpp - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) + # Some versions of GCC encode two locations for the 'return' statement + # in main.cpp + 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) - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.func_line, num_expected_locations=-1, loc_exact=True) - + lldbutil.run_break_set_by_file_and_line( + self, + "main.cpp", + self.func_line, + num_expected_locations=-1, + loc_exact=True) + self.expect("expr -i false -- returnsFive()", error=True, - substrs = ['Execution was interrupted, reason: breakpoint']) + substrs=['Execution was interrupted, reason: breakpoint']) self.runCmd("continue", "Continue completed") - self.expect ("thread list", - substrs = ['stop reason = User Expression thread plan', - r'Completed expression: (Five) $0 = (number = 5, name = "five")']) + self.expect( + "thread list", + substrs=[ + 'stop reason = User Expression thread plan', + r'Completed expression: (Five) $0 = (number = 5, name = "five")']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py b/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py index c0727a84fc0..fda81ae8c36 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-function/TestCallUserDefinedFunction.py @@ -10,12 +10,12 @@ Note: from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprCommandCallUserDefinedFunction(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -24,30 +24,39 @@ class ExprCommandCallUserDefinedFunction(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.c. - self.line = line_number('main.cpp', - '// Please test these expressions while stopped at this line:') + self.line = line_number( + 'main.cpp', + '// Please test these expressions while stopped at this line:') + @expectedFlakeyDsym("llvm.org/pr20274") - @expectedFailureAll(oslist=["windows"], bugnumber="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() # Set breakpoint in main and run exe 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) + 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) # Test recursive function call. - self.expect("expr fib(5)", substrs = ['$0 = 5']) + self.expect("expr fib(5)", substrs=['$0 = 5']) # Test function with more than one paramter - self.expect("expr add(4,8)", substrs = ['$1 = 12']) + self.expect("expr add(4,8)", substrs=['$1 = 12']) # Test nesting function calls in function paramters - self.expect("expr add(add(5,2),add(3,4))", substrs = ['$2 = 14']) - self.expect("expr add(add(5,2),fib(5))", substrs = ['$3 = 12']) + self.expect("expr add(add(5,2),add(3,4))", substrs=['$2 = 14']) + self.expect("expr add(add(5,2),fib(5))", substrs=['$3 = 12']) # Test function with pointer paramter - self.expect("exp stringCompare((const char*) \"Hello world\")", substrs = ['$4 = true']) - self.expect("exp stringCompare((const char*) \"Hellworld\")", substrs = ['$5 = false']) + self.expect( + "exp stringCompare((const char*) \"Hello world\")", + substrs=['$4 = true']) + self.expect( + "exp stringCompare((const char*) \"Hellworld\")", + substrs=['$5 = false']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py b/lldb/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py index 6b754a76878..bef4be1eb5f 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py @@ -5,12 +5,12 @@ Test calling a function that hits a signal set to auto-restart, make sure the ca from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprCommandThatRestartsTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -20,24 +20,30 @@ class ExprCommandThatRestartsTestCase(TestBase): TestBase.setUp(self) self.main_source = "lotta-signals.c" - self.main_source_spec = lldb.SBFileSpec (self.main_source) + self.main_source_spec = lldb.SBFileSpec(self.main_source) - @skipIfFreeBSD # llvm.org/pr19246: intermittent failure - @skipIfDarwin # llvm.org/pr19246: intermittent failure - @skipIfWindows # Test relies on signals, unsupported on Windows + @skipIfFreeBSD # llvm.org/pr19246: intermittent failure + @skipIfDarwin # llvm.org/pr19246: intermittent failure + @skipIfWindows # Test relies on signals, unsupported on Windows def test(self): """Test calling function that hits a signal and restarts.""" self.build() self.call_function() - def check_after_call (self, num_sigchld): + def check_after_call(self, num_sigchld): after_call = self.sigchld_no.GetValueAsSigned(-1) - self.assertTrue (after_call - self.start_sigchld_no == num_sigchld, "Really got %d SIGCHLD signals through the call."%(num_sigchld)) + self.assertTrue( + after_call - + self.start_sigchld_no == num_sigchld, + "Really got %d SIGCHLD signals through the call." % + (num_sigchld)) self.start_sigchld_no = after_call # Check that we are back where we were before: frame = self.thread.GetFrameAtIndex(0) - self.assertTrue (self.orig_frame_pc == frame.GetPC(), "Restored the zeroth frame correctly") + self.assertTrue( + self.orig_frame_pc == frame.GetPC(), + "Restored the zeroth frame correctly") def call_function(self): exe_name = "a.out" @@ -46,95 +52,133 @@ class ExprCommandThatRestartsTestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) empty = lldb.SBFileSpec() - breakpoint = target.BreakpointCreateBySourceRegex('Stop here in main.',self.main_source_spec) + breakpoint = target.BreakpointCreateBySourceRegex( + 'Stop here in main.', 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()) + 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) - + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) + self.assertTrue(len(threads) == 1) self.thread = threads[0] - + # Make sure the SIGCHLD behavior is pass/no-stop/no-notify: return_obj = lldb.SBCommandReturnObject() - self.dbg.GetCommandInterpreter().HandleCommand("process handle SIGCHLD -s 0 -p 1 -n 0", return_obj) - self.assertTrue (return_obj.Succeeded() == True, "Set SIGCHLD to pass, no-stop") + self.dbg.GetCommandInterpreter().HandleCommand( + "process handle SIGCHLD -s 0 -p 1 -n 0", return_obj) + self.assertTrue(return_obj.Succeeded(), "Set SIGCHLD to pass, no-stop") # The sigchld_no variable should be 0 at this point. self.sigchld_no = target.FindFirstGlobalVariable("sigchld_no") - self.assertTrue (self.sigchld_no.IsValid(), "Got a value for sigchld_no") + self.assertTrue( + self.sigchld_no.IsValid(), + "Got a value for sigchld_no") - self.start_sigchld_no = self.sigchld_no.GetValueAsSigned (-1) - self.assertTrue (self.start_sigchld_no != -1, "Got an actual value for sigchld_no") + self.start_sigchld_no = self.sigchld_no.GetValueAsSigned(-1) + self.assertTrue( + self.start_sigchld_no != -1, + "Got an actual value for sigchld_no") options = lldb.SBExpressionOptions() - # processing 30 signals takes a while, increase the expression timeout a bit - options.SetTimeoutInMicroSeconds(3000000) # 3s + # processing 30 signals takes a while, increase the expression timeout + # a bit + options.SetTimeoutInMicroSeconds(3000000) # 3s options.SetUnwindOnError(True) frame = self.thread.GetFrameAtIndex(0) - # Store away the PC to check that the functions unwind to the right place after calls + # Store away the PC to check that the functions unwind to the right + # place after calls self.orig_frame_pc = frame.GetPC() num_sigchld = 30 - value = frame.EvaluateExpression ("call_me (%d)"%(num_sigchld), options) - self.assertTrue (value.IsValid()) - self.assertTrue (value.GetError().Success() == True) - self.assertTrue (value.GetValueAsSigned(-1) == num_sigchld) + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertTrue(value.GetValueAsSigned(-1) == num_sigchld) self.check_after_call(num_sigchld) # Okay, now try with a breakpoint in the called code in the case where # we are ignoring breakpoint hits. - handler_bkpt = target.BreakpointCreateBySourceRegex("Got sigchld %d.", self.main_source_spec) - self.assertTrue (handler_bkpt.GetNumLocations() > 0) + handler_bkpt = target.BreakpointCreateBySourceRegex( + "Got sigchld %d.", self.main_source_spec) + self.assertTrue(handler_bkpt.GetNumLocations() > 0) options.SetIgnoreBreakpoints(True) options.SetUnwindOnError(True) - value = frame.EvaluateExpression("call_me (%d)"%(num_sigchld), options) + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) - self.assertTrue (value.IsValid() and value.GetError().Success() == True) - self.assertTrue (value.GetValueAsSigned(-1) == num_sigchld) + self.assertTrue(value.IsValid() and value.GetError().Success()) + self.assertTrue(value.GetValueAsSigned(-1) == num_sigchld) self.check_after_call(num_sigchld) - # Now set the signal to print but not stop and make sure that calling still works: - self.dbg.GetCommandInterpreter().HandleCommand("process handle SIGCHLD -s 0 -p 1 -n 1", return_obj) - self.assertTrue (return_obj.Succeeded() == True, "Set SIGCHLD to pass, no-stop, notify") + # Now set the signal to print but not stop and make sure that calling + # still works: + self.dbg.GetCommandInterpreter().HandleCommand( + "process handle SIGCHLD -s 0 -p 1 -n 1", return_obj) + self.assertTrue( + return_obj.Succeeded(), + "Set SIGCHLD to pass, no-stop, notify") - value = frame.EvaluateExpression("call_me (%d)"%(num_sigchld), options) + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) - self.assertTrue (value.IsValid() and value.GetError().Success() == True) - self.assertTrue (value.GetValueAsSigned(-1) == num_sigchld) + self.assertTrue(value.IsValid() and value.GetError().Success()) + self.assertTrue(value.GetValueAsSigned(-1) == num_sigchld) self.check_after_call(num_sigchld) - # Now set this unwind on error to false, and make sure that we still complete the call: + # Now set this unwind on error to false, and make sure that we still + # complete the call: options.SetUnwindOnError(False) - value = frame.EvaluateExpression("call_me (%d)"%(num_sigchld), options) + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) - self.assertTrue (value.IsValid() and value.GetError().Success() == True) - self.assertTrue (value.GetValueAsSigned(-1) == num_sigchld) + self.assertTrue(value.IsValid() and value.GetError().Success()) + self.assertTrue(value.GetValueAsSigned(-1) == num_sigchld) self.check_after_call(num_sigchld) # Okay, now set UnwindOnError to true, and then make the signal behavior to stop # and see that now we do stop at the signal point: - - self.dbg.GetCommandInterpreter().HandleCommand("process handle SIGCHLD -s 1 -p 1 -n 1", return_obj) - self.assertTrue (return_obj.Succeeded() == True, "Set SIGCHLD to pass, stop, notify") - - value = frame.EvaluateExpression("call_me (%d)"%(num_sigchld), options) - self.assertTrue (value.IsValid() and value.GetError().Success() == False) - - # Set signal handling back to no-stop, and continue and we should end up back in out starting frame: - self.dbg.GetCommandInterpreter().HandleCommand("process handle SIGCHLD -s 0 -p 1 -n 1", return_obj) - self.assertTrue (return_obj.Succeeded() == True, "Set SIGCHLD to pass, no-stop, notify") + + self.dbg.GetCommandInterpreter().HandleCommand( + "process handle SIGCHLD -s 1 -p 1 -n 1", return_obj) + self.assertTrue( + return_obj.Succeeded(), + "Set SIGCHLD to pass, stop, notify") + + value = frame.EvaluateExpression( + "call_me (%d)" % + (num_sigchld), options) + self.assertTrue( + value.IsValid() and value.GetError().Success() == False) + + # Set signal handling back to no-stop, and continue and we should end + # up back in out starting frame: + self.dbg.GetCommandInterpreter().HandleCommand( + "process handle SIGCHLD -s 0 -p 1 -n 1", return_obj) + self.assertTrue( + return_obj.Succeeded(), + "Set SIGCHLD to pass, no-stop, notify") error = process.Continue() - self.assertTrue (error.Success(), "Continuing after stopping for signal succeeds.") - + self.assertTrue( + error.Success(), + "Continuing after stopping for signal succeeds.") + frame = self.thread.GetFrameAtIndex(0) - self.assertTrue (frame.GetPC() == self.orig_frame_pc, "Continuing returned to the place we started.") + self.assertTrue( + frame.GetPC() == self.orig_frame_pc, + "Continuing returned to the place we started.") diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py b/lldb/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py index a6eb1bddc00..e5162609dfa 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py @@ -5,12 +5,12 @@ Test calling a function that throws an ObjC exception, make sure that it doesn't from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprCommandWithThrowTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -20,7 +20,7 @@ class ExprCommandWithThrowTestCase(TestBase): TestBase.setUp(self) self.main_source = "call-throws.m" - self.main_source_spec = lldb.SBFileSpec (self.main_source) + self.main_source_spec = lldb.SBFileSpec(self.main_source) @skipUnlessDarwin def test(self): @@ -28,12 +28,13 @@ class ExprCommandWithThrowTestCase(TestBase): self.build() self.call_function() - def check_after_call (self): + def check_after_call(self): # Check that we are back where we were before: frame = self.thread.GetFrameAtIndex(0) - self.assertTrue (self.orig_frame_pc == frame.GetPC(), "Restored the zeroth frame correctly") + self.assertTrue( + self.orig_frame_pc == frame.GetPC(), + "Restored the zeroth frame correctly") - def call_function(self): """Test calling function that throws.""" exe_name = "a.out" @@ -42,72 +43,82 @@ class ExprCommandWithThrowTestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateBySourceRegex('I am about to throw.',self.main_source_spec) + breakpoint = target.BreakpointCreateBySourceRegex( + 'I am about to throw.', 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()) + 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) - + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) + self.assertTrue(len(threads) == 1) self.thread = threads[0] - + options = lldb.SBExpressionOptions() options.SetUnwindOnError(True) frame = self.thread.GetFrameAtIndex(0) - # Store away the PC to check that the functions unwind to the right place after calls + # Store away the PC to check that the functions unwind to the right + # place after calls self.orig_frame_pc = frame.GetPC() - value = frame.EvaluateExpression ("[my_class callMeIThrow]", options) - self.assertTrue (value.IsValid()) - self.assertTrue (value.GetError().Success() == False) + value = frame.EvaluateExpression("[my_class callMeIThrow]", options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success() == False) self.check_after_call() # Okay, now try with a breakpoint in the called code in the case where # we are ignoring breakpoint hits. - handler_bkpt = target.BreakpointCreateBySourceRegex("I felt like it", self.main_source_spec) - self.assertTrue (handler_bkpt.GetNumLocations() > 0) + handler_bkpt = target.BreakpointCreateBySourceRegex( + "I felt like it", self.main_source_spec) + self.assertTrue(handler_bkpt.GetNumLocations() > 0) options.SetIgnoreBreakpoints(True) options.SetUnwindOnError(True) - value = frame.EvaluateExpression ("[my_class callMeIThrow]", options) + value = frame.EvaluateExpression("[my_class callMeIThrow]", options) - self.assertTrue (value.IsValid() and value.GetError().Success() == False) + self.assertTrue( + value.IsValid() and value.GetError().Success() == False) self.check_after_call() - # Now set the ObjC language breakpoint and make sure that doesn't interfere with the call: - exception_bkpt = target.BreakpointCreateForException (lldb.eLanguageTypeObjC, False, True) + # Now set the ObjC language breakpoint and make sure that doesn't + # interfere with the call: + exception_bkpt = target.BreakpointCreateForException( + lldb.eLanguageTypeObjC, False, True) self.assertTrue(exception_bkpt.GetNumLocations() > 0) options.SetIgnoreBreakpoints(True) options.SetUnwindOnError(True) - value = frame.EvaluateExpression ("[my_class callMeIThrow]", options) + value = frame.EvaluateExpression("[my_class callMeIThrow]", options) - self.assertTrue (value.IsValid() and value.GetError().Success() == False) + self.assertTrue( + value.IsValid() and value.GetError().Success() == False) self.check_after_call() - # Now turn off exception trapping, and call a function that catches the exceptions, - # and make sure the function actually completes, and we get the right value: + # and make sure the function actually completes, and we get the right + # value: options.SetTrapExceptions(False) - value = frame.EvaluateExpression ("[my_class iCatchMyself]", options) - self.assertTrue (value.IsValid()) - self.assertTrue (value.GetError().Success() == True) - self.assertTrue (value.GetValueAsUnsigned() == 57) + value = frame.EvaluateExpression("[my_class iCatchMyself]", options) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertTrue(value.GetValueAsUnsigned() == 57) self.check_after_call() options.SetTrapExceptions(True) - # Now set this unwind on error to false, and make sure that we stop where the exception was thrown + # Now set this unwind on error to false, and make sure that we stop + # where the exception was thrown options.SetUnwindOnError(False) - value = frame.EvaluateExpression ("[my_class callMeIThrow]", options) - + value = frame.EvaluateExpression("[my_class callMeIThrow]", options) - self.assertTrue (value.IsValid() and value.GetError().Success() == False) + self.assertTrue( + value.IsValid() and value.GetError().Success() == False) self.check_after_call() diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py b/lldb/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py index 66fa69cdfff..308732b6c8e 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/char/TestExprsChar.py @@ -1,12 +1,12 @@ from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprCharTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -16,24 +16,27 @@ class ExprCharTestCase(TestBase): TestBase.setUp(self) self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec (self.main_source) + self.main_source_spec = lldb.SBFileSpec(self.main_source) self.exe = os.path.join(os.getcwd(), "a.out") def do_test(self, dictionary=None): """These basic expression commands should work as expected.""" - self.build(dictionary = dictionary) + self.build(dictionary=dictionary) target = self.dbg.CreateTarget(self.exe) self.assertTrue(target) - breakpoint = target.BreakpointCreateBySourceRegex('// Break here', self.main_source_spec) + breakpoint = target.BreakpointCreateBySourceRegex( + '// Break here', self.main_source_spec) self.assertTrue(breakpoint) # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple(None, None, self.get_process_working_directory()) + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) self.assertTrue(process) - threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint) + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) self.assertEqual(len(threads), 1) frame = threads[0].GetFrameAtIndex(0) @@ -57,13 +60,22 @@ class ExprCharTestCase(TestBase): def test_default_char(self): self.do_test() - @expectedFailureAll(archs=["arm", "aarch64", "s390x"], bugnumber="llvm.org/pr23069") + @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'}) - @expectedFailureAll(archs=["i[3-6]86", "x86_64"], bugnumber="llvm.org/pr23069") + @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") + @expectedFailureAll(triple='mips*', bugnumber="llvm.org/pr23069") def test_unsigned_char(self): self.do_test(dictionary={'CFLAGS_EXTRAS': '-funsigned-char'}) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py b/lldb/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py index a715ee31e5f..dcfb648ada5 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py @@ -3,7 +3,6 @@ from __future__ import print_function - import os import lldb from lldbsuite.test.decorators import * @@ -15,7 +14,9 @@ class ExprSyscallTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765, getpid() does not exist on Windows") + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr21765, getpid() does not exist on Windows") def test_setpgid(self): self.build() self.expr_syscall() @@ -32,16 +33,16 @@ class ExprSyscallTestCase(TestBase): # launch the inferior and don't wait for it to stop self.dbg.SetAsync(True) error = lldb.SBError() - process = target.Launch (listener, - None, # argv - None, # envp - None, # stdin_path - None, # stdout_path - None, # stderr_path - None, # working directory - 0, # launch flags - False, # Stop at entry - error) # error + process = target.Launch(listener, + None, # argv + None, # envp + None, # stdin_path + None, # stdout_path + None, # stderr_path + None, # working directory + 0, # launch flags + False, # Stop at entry + error) # error self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) @@ -54,7 +55,10 @@ class ExprSyscallTestCase(TestBase): pass # now the process should be running (blocked in the syscall) - self.assertEqual(process.GetState(), lldb.eStateRunning, "Process is running") + self.assertEqual( + process.GetState(), + lldb.eStateRunning, + "Process is running") # send the process a signal process.SendAsyncInterrupt() @@ -62,13 +66,18 @@ class ExprSyscallTestCase(TestBase): pass # as a result the process should stop - # in all likelihood we have stopped in the middle of the sleep() syscall - self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) + # in all likelihood we have stopped in the middle of the sleep() + # syscall + self.assertEqual( + process.GetState(), + lldb.eStateStopped, + PROCESS_STOPPED) thread = process.GetSelectedThread() # try evaluating a couple of expressions in this state - self.expect("expr release_flag = 1", substrs = [" = 1"]) - self.expect("print (int)getpid()", substrs = [str(process.GetProcessID())]) + self.expect("expr release_flag = 1", substrs=[" = 1"]) + self.expect("print (int)getpid()", + substrs=[str(process.GetProcessID())]) # and run the process to completion process.Continue() diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py b/lldb/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py index 7e11f2b201f..a472a014cee 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/fixits/TestFixIts.py @@ -5,12 +5,12 @@ 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__) @@ -20,7 +20,7 @@ class ExprCommandWithFixits(TestBase): TestBase.setUp(self) self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec (self.main_source) + self.main_source_spec = lldb.SBFileSpec(self.main_source) @skipUnlessDarwin def test(self): @@ -36,20 +36,23 @@ class ExprCommandWithFixits(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateBySourceRegex('Stop here to evaluate expressions',self.main_source_spec) + 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()) + 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) - + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) + self.assertTrue(len(threads) == 1) self.thread = threads[0] - + options = lldb.SBExpressionOptions() options.SetAutoApplyFixIts(True) @@ -60,7 +63,7 @@ class ExprCommandWithFixits(TestBase): 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) @@ -74,8 +77,9 @@ class ExprCommandWithFixits(TestBase): 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") - - - + 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/lldb/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py b/lldb/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py index 4a99dc47901..c4126a32968 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/formatters/TestFormatters.py @@ -5,12 +5,12 @@ Test using LLDB data formatters with frozen objects coming from the expression p from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprFormattersTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -22,11 +22,13 @@ class ExprFormattersTestCase(TestBase): self.line = line_number('main.cpp', '// Stop here') - @skipIfFreeBSD # llvm.org/pr24691 skipping to avoid crashing the test runner - @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr19011 Newer Clang omits C1 complete object constructor') + @skipIfFreeBSD # llvm.org/pr24691 skipping to avoid crashing the test runner + @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 + @skipIfTargetAndroid() # skipping to avoid crashing the test runner + @expectedFailureAndroid('llvm.org/pr24691') # we hit an assertion in clang def test(self): """Test expr + formatters for good interoperability.""" self.build() @@ -36,64 +38,117 @@ class ExprFormattersTestCase(TestBase): def cleanup(): self.runCmd('type summary clear', check=False) self.runCmd('type synthetic clear', check=False) - + # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) """Test expr + formatters for good interoperability.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) self.runCmd("command script import formatters.py") self.runCmd("command script import foosynth.py") - + if self.TraceOn(): self.runCmd("frame variable foo1 --show-types") self.runCmd("frame variable foo1.b --show-types") self.runCmd("frame variable foo1.b.b_ref --show-types") - self.expect("expression --show-types -- *(new foo(47))", - substrs = ['(int) a = 47', '(bar) b = {', '(int) i = 94', '(baz) b = {', '(int) k = 99']) + self.expect( + "expression --show-types -- *(new foo(47))", + substrs=[ + '(int) a = 47', + '(bar) b = {', + '(int) i = 94', + '(baz) b = {', + '(int) k = 99']) self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") self.expect("expression new int(12)", - substrs = ['(int *) $', ' = 0x']) + substrs=['(int *) $', ' = 0x']) - self.runCmd("type summary add -s \"${var%pointer} -> ${*var%decimal}\" \"int *\"") + self.runCmd( + "type summary add -s \"${var%pointer} -> ${*var%decimal}\" \"int *\"") self.expect("expression new int(12)", - substrs = ['(int *) $', '= 0x', ' -> 12']) + substrs=['(int *) $', '= 0x', ' -> 12']) self.expect("expression foo1.a_ptr", - substrs = ['(int *) $', '= 0x', ' -> 13']) - - self.expect("expression foo1", - substrs = ['(foo) $', ' a = 12', 'a_ptr = ', ' -> 13','i = 24','i_ptr = ', ' -> 25']) - - self.expect("expression --ptr-depth=1 -- new foo(47)", - substrs = ['(foo *) $', 'a = 47','a_ptr = ', ' -> 48','i = 94','i_ptr = ', ' -> 95']) - - self.expect("expression foo2", - substrs = ['(foo) $', 'a = 121','a_ptr = ', ' -> 122','i = 242','i_ptr = ', ' -> 243']) + substrs=['(int *) $', '= 0x', ' -> 13']) + + self.expect( + "expression foo1", + substrs=[ + '(foo) $', + ' a = 12', + 'a_ptr = ', + ' -> 13', + 'i = 24', + 'i_ptr = ', + ' -> 25']) + + self.expect( + "expression --ptr-depth=1 -- new foo(47)", + substrs=[ + '(foo *) $', + 'a = 47', + 'a_ptr = ', + ' -> 48', + 'i = 94', + 'i_ptr = ', + ' -> 95']) + + self.expect( + "expression foo2", + substrs=[ + '(foo) $', + 'a = 121', + 'a_ptr = ', + ' -> 122', + 'i = 242', + 'i_ptr = ', + ' -> 243']) object_name = self.res.GetOutput() object_name = object_name[7:] object_name = object_name[0:object_name.find(' =')] - self.expect("frame variable foo2", - substrs = ['(foo)', 'foo2', 'a = 121','a_ptr = ', ' -> 122','i = 242','i_ptr = ', ' -> 243']) - - self.expect("expression $" + object_name, - substrs = ['(foo) $', 'a = 121','a_ptr = ', ' -> 122','i = 242','i_ptr = ', ' -> 243', 'h = 245','k = 247']) + self.expect( + "frame variable foo2", + substrs=[ + '(foo)', + 'foo2', + 'a = 121', + 'a_ptr = ', + ' -> 122', + 'i = 242', + 'i_ptr = ', + ' -> 243']) + + self.expect( + "expression $" + + object_name, + substrs=[ + '(foo) $', + 'a = 121', + 'a_ptr = ', + ' -> 122', + 'i = 242', + 'i_ptr = ', + ' -> 243', + 'h = 245', + 'k = 247']) self.runCmd("type summary delete foo") - self.runCmd("type synthetic add --python-class foosynth.FooSyntheticProvider foo") + self.runCmd( + "type synthetic add --python-class foosynth.FooSyntheticProvider foo") self.expect("expression --show-types -- $" + object_name, - substrs = ['(foo) $', ' = {', '(int) *i_ptr = 243']) + substrs=['(foo) $', ' = {', '(int) *i_ptr = 243']) self.runCmd("n") self.runCmd("n") @@ -101,31 +156,61 @@ class ExprFormattersTestCase(TestBase): self.runCmd("type synthetic delete foo") self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") - self.expect("expression foo2", - substrs = ['(foo) $', 'a = 7777','a_ptr = ', ' -> 122','i = 242','i_ptr = ', ' -> 8888']) + self.expect( + "expression foo2", + substrs=[ + '(foo) $', + 'a = 7777', + 'a_ptr = ', + ' -> 122', + 'i = 242', + 'i_ptr = ', + ' -> 8888']) self.expect("expression $" + object_name + '.a', - substrs = ['7777']) + substrs=['7777']) self.expect("expression *$" + object_name + '.b.i_ptr', - substrs = ['8888']) - - self.expect("expression $" + object_name, - substrs = ['(foo) $', 'a = 121', 'a_ptr = ', ' -> 122', 'i = 242', 'i_ptr = ', ' -> 8888', 'h = 245','k = 247']) + substrs=['8888']) + + self.expect( + "expression $" + + object_name, + substrs=[ + '(foo) $', + 'a = 121', + 'a_ptr = ', + ' -> 122', + 'i = 242', + 'i_ptr = ', + ' -> 8888', + 'h = 245', + 'k = 247']) self.runCmd("type summary delete foo") - self.runCmd("type synthetic add --python-class foosynth.FooSyntheticProvider foo") + self.runCmd( + "type synthetic add --python-class foosynth.FooSyntheticProvider foo") self.expect("expression --show-types -- $" + object_name, - substrs = ['(foo) $', ' = {', '(int) *i_ptr = 8888']) + substrs=['(foo) $', ' = {', '(int) *i_ptr = 8888']) self.runCmd("n") self.runCmd("type synthetic delete foo") self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") - self.expect("expression $" + object_name, - substrs = ['(foo) $', 'a = 121','a_ptr = ', ' -> 122','i = 242', 'i_ptr = ', ' -> 8888','k = 247']) + self.expect( + "expression $" + + object_name, + substrs=[ + '(foo) $', + 'a = 121', + 'a_ptr = ', + ' -> 122', + 'i = 242', + 'i_ptr = ', + ' -> 8888', + 'k = 247']) process = self.dbg.GetSelectedTarget().GetProcess() thread = process.GetThreadAtIndex(0) @@ -136,32 +221,78 @@ class ExprFormattersTestCase(TestBase): a_data = frozen.GetPointeeData() error = lldb.SBError() - self.assertTrue(a_data.GetUnsignedInt32(error, 0) == 122, '*a_ptr = 122') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 0) == 122, + '*a_ptr = 122') - self.runCmd("n");self.runCmd("n");self.runCmd("n"); + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") self.expect("frame variable numbers", - substrs = ['1','2','3','4','5']) + substrs=['1', '2', '3', '4', '5']) self.expect("expression numbers", - substrs = ['1','2','3','4','5']) + substrs=['1', '2', '3', '4', '5']) frozen = frame.EvaluateExpression("&numbers") a_data = frozen.GetPointeeData(0, 1) - self.assertTrue(a_data.GetUnsignedInt32(error, 0) == 1, 'numbers[0] == 1') - self.assertTrue(a_data.GetUnsignedInt32(error, 4) == 2, 'numbers[1] == 2') - self.assertTrue(a_data.GetUnsignedInt32(error, 8) == 3, 'numbers[2] == 3') - self.assertTrue(a_data.GetUnsignedInt32(error, 12) == 4, 'numbers[3] == 4') - self.assertTrue(a_data.GetUnsignedInt32(error, 16) == 5, 'numbers[4] == 5') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 0) == 1, + 'numbers[0] == 1') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 4) == 2, + 'numbers[1] == 2') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 8) == 3, + 'numbers[2] == 3') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 12) == 4, + 'numbers[3] == 4') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 16) == 5, + 'numbers[4] == 5') frozen = frame.EvaluateExpression("numbers") a_data = frozen.GetData() - self.assertTrue(a_data.GetUnsignedInt32(error, 0) == 1, 'numbers[0] == 1') - self.assertTrue(a_data.GetUnsignedInt32(error, 4) == 2, 'numbers[1] == 2') - self.assertTrue(a_data.GetUnsignedInt32(error, 8) == 3, 'numbers[2] == 3') - self.assertTrue(a_data.GetUnsignedInt32(error, 12) == 4, 'numbers[3] == 4') - self.assertTrue(a_data.GetUnsignedInt32(error, 16) == 5, 'numbers[4] == 5') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 0) == 1, + 'numbers[0] == 1') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 4) == 2, + 'numbers[1] == 2') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 8) == 3, + 'numbers[2] == 3') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 12) == 4, + 'numbers[3] == 4') + self.assertTrue( + a_data.GetUnsignedInt32( + error, + 16) == 5, + 'numbers[4] == 5') diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/formatters/foosynth.py b/lldb/packages/Python/lldbsuite/test/expression_command/formatters/foosynth.py index 91c4d4a84c6..7b1284d2a76 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/formatters/foosynth.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/formatters/foosynth.py @@ -1,29 +1,33 @@ import lldb + class FooSyntheticProvider: - def __init__(self,valobj,dict): - self.valobj = valobj; - self.update(); - - def update(self): - self.adjust_for_architecture() - - def num_children(self): - return 1; - - def get_child_at_index(self,index): - if index != 0: - return None; - return self.i_ptr.Dereference(); - - def get_child_index(self,name): - if name == "*i_ptr": - return 0; - return None; - - def adjust_for_architecture(self): - self.lp64 = (self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8) - self.is_little = (self.valobj.GetTarget().GetProcess().GetByteOrder() == lldb.eByteOrderLittle) - self.pointer_size = self.valobj.GetTarget().GetProcess().GetAddressByteSize() - self.bar = self.valobj.GetChildMemberWithName('b'); - self.i_ptr = self.bar.GetChildMemberWithName('i_ptr');
\ No newline at end of file + + def __init__(self, valobj, dict): + self.valobj = valobj + self.update() + + def update(self): + self.adjust_for_architecture() + + def num_children(self): + return 1 + + def get_child_at_index(self, index): + if index != 0: + return None + return self.i_ptr.Dereference() + + def get_child_index(self, name): + if name == "*i_ptr": + return 0 + return None + + def adjust_for_architecture(self): + self.lp64 = ( + self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8) + self.is_little = (self.valobj.GetTarget().GetProcess( + ).GetByteOrder() == lldb.eByteOrderLittle) + self.pointer_size = self.valobj.GetTarget().GetProcess().GetAddressByteSize() + self.bar = self.valobj.GetChildMemberWithName('b') + self.i_ptr = self.bar.GetChildMemberWithName('i_ptr') diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/formatters/formatters.py b/lldb/packages/Python/lldbsuite/test/expression_command/formatters/formatters.py index ce922a8f911..dae84988af9 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/formatters/formatters.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/formatters/formatters.py @@ -1,17 +1,17 @@ -def foo_SummaryProvider (valobj,dict): - a = valobj.GetChildMemberWithName('a'); - a_ptr = valobj.GetChildMemberWithName('a_ptr'); - bar = valobj.GetChildMemberWithName('b'); - i = bar.GetChildMemberWithName('i'); - i_ptr = bar.GetChildMemberWithName('i_ptr'); - b_ref = bar.GetChildMemberWithName('b_ref'); - b_ref_ptr = b_ref.AddressOf() - b_ref = b_ref_ptr.Dereference() - h = b_ref.GetChildMemberWithName('h'); - k = b_ref.GetChildMemberWithName('k'); - return 'a = ' + str(a.GetValueAsUnsigned(0)) + ', a_ptr = ' + \ - str(a_ptr.GetValueAsUnsigned(0)) + ' -> ' + str(a_ptr.Dereference().GetValueAsUnsigned(0)) + \ - ', i = ' + str(i.GetValueAsUnsigned(0)) + \ - ', i_ptr = ' + str(i_ptr.GetValueAsUnsigned(0)) + ' -> ' + str(i_ptr.Dereference().GetValueAsUnsigned(0)) + \ - ', b_ref = ' + str(b_ref.GetValueAsUnsigned(0)) + \ - ', h = ' + str(h.GetValueAsUnsigned(0)) + ' , k = ' + str(k.GetValueAsUnsigned(0))
\ No newline at end of file +def foo_SummaryProvider(valobj, dict): + a = valobj.GetChildMemberWithName('a') + a_ptr = valobj.GetChildMemberWithName('a_ptr') + bar = valobj.GetChildMemberWithName('b') + i = bar.GetChildMemberWithName('i') + i_ptr = bar.GetChildMemberWithName('i_ptr') + b_ref = bar.GetChildMemberWithName('b_ref') + b_ref_ptr = b_ref.AddressOf() + b_ref = b_ref_ptr.Dereference() + h = b_ref.GetChildMemberWithName('h') + k = b_ref.GetChildMemberWithName('k') + return 'a = ' + str(a.GetValueAsUnsigned(0)) + ', a_ptr = ' + \ + str(a_ptr.GetValueAsUnsigned(0)) + ' -> ' + str(a_ptr.Dereference().GetValueAsUnsigned(0)) + \ + ', i = ' + str(i.GetValueAsUnsigned(0)) + \ + ', i_ptr = ' + str(i_ptr.GetValueAsUnsigned(0)) + ' -> ' + str(i_ptr.Dereference().GetValueAsUnsigned(0)) + \ + ', b_ref = ' + str(b_ref.GetValueAsUnsigned(0)) + \ + ', h = ' + str(h.GetValueAsUnsigned(0)) + ' , k = ' + str(k.GetValueAsUnsigned(0)) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py b/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py index c4f17670322..894d0bfaa86 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter-phi-nodes/TestIRInterpreterPHINodes.py @@ -2,38 +2,41 @@ Test PHI nodes work in the IR interpreter. """ -import os, os.path +import os +import 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) - + 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']) - + 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') diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py b/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py index 2a21d047371..5c5110b6994 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/ir-interpreter/TestIRInterpreter.py @@ -6,12 +6,14 @@ from __future__ import print_function import unittest2 -import os, time +import os +import 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__) @@ -25,7 +27,8 @@ class IRInterpreterTestCase(TestBase): # Disable confirmation prompt to avoid infinite wait self.runCmd("settings set auto-confirm true") - self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm")) + self.addTearDownHook( + lambda: self.runCmd("settings clear auto-confirm")) def build_and_run(self): """Test the IR interpreter""" @@ -33,13 +36,20 @@ class IRInterpreterTestCase(TestBase): 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) + 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") + # getpid() is POSIX, among other problems, see bug + @expectedFailureAll( + oslist=['windows'], + bugnumber="http://llvm.org/pr21765") + @expectedFailureAll( + oslist=['linux'], + archs=['arm'], + bugnumber="llvm.org/pr27868") def test_ir_interpreter(self): self.build_and_run() @@ -62,11 +72,16 @@ class IRInterpreterTestCase(TestBase): 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) - + 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/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py b/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py index 2d0b23b4e5b..afb497e04b5 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py @@ -7,13 +7,14 @@ expected in a SyntheticChildrenProvider from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class Issue11581TestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -25,54 +26,61 @@ class Issue11581TestCase(TestBase): def cleanup(): self.runCmd('type synthetic clear', check=False) - # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) """valobj.AddressOf() should return correct values.""" self.build() - + exe = os.path.join(os.getcwd(), "a.out") - + target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here.',lldb.SBFileSpec ("main.cpp", False)) - - process = target.LaunchSimple (None, None, self.get_process_working_directory()) - self.assertTrue (process, "Created a process.") - self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.") + breakpoint = target.BreakpointCreateBySourceRegex( + 'Set breakpoint here.', lldb.SBFileSpec("main.cpp", False)) + + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertTrue(process, "Created a process.") + self.assertTrue( + process.GetState() == lldb.eStateStopped, + "Stopped it too.") - thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) - self.assertTrue (len(thread_list) == 1) + thread_list = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) + self.assertTrue(len(thread_list) == 1) thread = thread_list[0] self.runCmd("command script import --allow-reload s11588.py") - self.runCmd("type synthetic add --python-class s11588.Issue11581SyntheticProvider StgClosure") + self.runCmd( + "type synthetic add --python-class s11588.Issue11581SyntheticProvider StgClosure") self.expect("expr --show-types -- *((StgClosure*)(r14-1))", - substrs = ["(StgClosure) $", - "(StgClosure *) &$","0x", - "addr = ", - "load_address = "]) + substrs=["(StgClosure) $", + "(StgClosure *) &$", "0x", + "addr = ", + "load_address = "]) # register r14 is an x86_64 extension let's skip this part of the test # if we are on a different architecture if self.getArchitecture() == 'x86_64': - target = lldb.debugger.GetSelectedTarget() - process = target.GetProcess() - frame = process.GetSelectedThread().GetSelectedFrame() - pointer = frame.FindVariable("r14") - addr = pointer.GetValueAsUnsigned(0) - self.assertTrue(addr != 0, "could not read pointer to StgClosure") - addr = addr - 1 - self.runCmd("register write r14 %d" % addr) - self.expect("register read r14", - substrs = ["0x",hex(addr)[2:].rstrip("L")]) # Remove trailing 'L' if it exists - self.expect("expr --show-types -- *(StgClosure*)$r14", - substrs = ["(StgClosure) $", - "(StgClosure *) &$","0x", - "addr = ", - "load_address = ", - hex(addr)[2:].rstrip("L"), - str(addr)]) + target = lldb.debugger.GetSelectedTarget() + process = target.GetProcess() + frame = process.GetSelectedThread().GetSelectedFrame() + pointer = frame.FindVariable("r14") + addr = pointer.GetValueAsUnsigned(0) + self.assertTrue(addr != 0, "could not read pointer to StgClosure") + addr = addr - 1 + self.runCmd("register write r14 %d" % addr) + self.expect( + "register read r14", substrs=[ + "0x", hex(addr)[ + 2:].rstrip("L")]) # Remove trailing 'L' if it exists + self.expect("expr --show-types -- *(StgClosure*)$r14", + substrs=["(StgClosure) $", + "(StgClosure *) &$", "0x", + "addr = ", + "load_address = ", + hex(addr)[2:].rstrip("L"), + str(addr)]) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/s11588.py b/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/s11588.py index 01bb09a1b0d..51c20423ed3 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/s11588.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/issue_11588/s11588.py @@ -1,26 +1,28 @@ class Issue11581SyntheticProvider(object): - def __init__(self, valobj, dict): - self.valobj = valobj - self.addrOf = valobj.AddressOf() - self.addr = valobj.GetAddress() - self.load_address = valobj.GetLoadAddress() - def num_children(self): - return 3; + def __init__(self, valobj, dict): + self.valobj = valobj + self.addrOf = valobj.AddressOf() + self.addr = valobj.GetAddress() + self.load_address = valobj.GetLoadAddress() - def get_child_at_index(self, index): - if index == 0: - return self.addrOf - if index == 1: - return self.valobj.CreateValueFromExpression("addr", str(self.addr)) - if index == 2: - return self.valobj.CreateValueFromExpression("load_address", str(self.load_address)) + def num_children(self): + return 3 - def get_child_index(self, name): - if name == "addrOf": - return 0 - if name == "addr": - return 1 - if name == "load_address": - return 2 + def get_child_at_index(self, index): + if index == 0: + return self.addrOf + if index == 1: + return self.valobj.CreateValueFromExpression( + "addr", str(self.addr)) + if index == 2: + return self.valobj.CreateValueFromExpression( + "load_address", str(self.load_address)) + def get_child_index(self, name): + if name == "addrOf": + return 0 + if name == "addr": + return 1 + if name == "load_address": + return 2 diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py b/lldb/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py index 939d2e45d7d..70b862bf486 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/macros/TestMacros.py @@ -6,13 +6,21 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestMacros(TestBase): mydir = TestBase.compute_mydir(__file__) - @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') + @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() @@ -25,7 +33,7 @@ class TestMacros(TestBase): # Get the path of the executable cwd = os.getcwd() exe_file = "a.out" - exe_path = os.path.join(cwd, exe_file) + exe_path = os.path.join(cwd, exe_file) # Load the executable target = self.dbg.CreateTarget(exe_path) @@ -33,51 +41,78 @@ class TestMacros(TestBase): # Set breakpoints bp1 = target.BreakpointCreateBySourceRegex("Break here", src_file_spec) - self.assertTrue(bp1.IsValid() and bp1.GetNumLocations() >= 1, VALID_BREAKPOINT) + self.assertTrue( + bp1.IsValid() and bp1.GetNumLocations() >= 1, + VALID_BREAKPOINT) # Launch the process - process = target.LaunchSimple(None, None, self.get_process_working_directory()) + 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, PROCESS_STOPPED) - thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue( + process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + thread = lldbutil.get_stopped_thread( + process, lldb.eStopReasonBreakpoint) # Get frame for current thread frame = thread.GetSelectedFrame() result = frame.EvaluateExpression("MACRO_1") - self.assertTrue(result.IsValid() and result.GetValue() == "100", "MACRO_1 = 100") + self.assertTrue( + result.IsValid() and result.GetValue() == "100", + "MACRO_1 = 100") result = frame.EvaluateExpression("MACRO_2") - self.assertTrue(result.IsValid() and result.GetValue() == "200", "MACRO_2 = 200") + self.assertTrue( + result.IsValid() and result.GetValue() == "200", + "MACRO_2 = 200") result = frame.EvaluateExpression("ONE") - self.assertTrue(result.IsValid() and result.GetValue() == "1", "ONE = 1") + self.assertTrue( + result.IsValid() and result.GetValue() == "1", + "ONE = 1") result = frame.EvaluateExpression("TWO") - self.assertTrue(result.IsValid() and result.GetValue() == "2", "TWO = 2") + self.assertTrue( + result.IsValid() and result.GetValue() == "2", + "TWO = 2") result = frame.EvaluateExpression("THREE") - self.assertTrue(result.IsValid() and result.GetValue() == "3", "THREE = 3") + self.assertTrue( + result.IsValid() and result.GetValue() == "3", + "THREE = 3") result = frame.EvaluateExpression("FOUR") - self.assertTrue(result.IsValid() and result.GetValue() == "4", "FOUR = 4") + self.assertTrue( + result.IsValid() and result.GetValue() == "4", + "FOUR = 4") result = frame.EvaluateExpression("HUNDRED") - self.assertTrue(result.IsValid() and result.GetValue() == "100", "HUNDRED = 100") + self.assertTrue( + result.IsValid() and result.GetValue() == "100", + "HUNDRED = 100") result = frame.EvaluateExpression("THOUSAND") - self.assertTrue(result.IsValid() and result.GetValue() == "1000", "THOUSAND = 1000") + self.assertTrue( + result.IsValid() and result.GetValue() == "1000", + "THOUSAND = 1000") result = frame.EvaluateExpression("MILLION") - self.assertTrue(result.IsValid() and result.GetValue() == "1000000", "MILLION = 1000000") + self.assertTrue(result.IsValid() and result.GetValue() + == "1000000", "MILLION = 1000000") result = frame.EvaluateExpression("MAX(ONE, TWO)") - self.assertTrue(result.IsValid() and result.GetValue() == "2", "MAX(ONE, TWO) = 2") + self.assertTrue( + result.IsValid() and result.GetValue() == "2", + "MAX(ONE, TWO) = 2") result = frame.EvaluateExpression("MAX(THREE, TWO)") - self.assertTrue(result.IsValid() and result.GetValue() == "3", "MAX(THREE, TWO) = 3") + self.assertTrue( + result.IsValid() and result.GetValue() == "3", + "MAX(THREE, TWO) = 3") # Get the thread of the process thread.StepOver() @@ -86,10 +121,14 @@ class TestMacros(TestBase): frame = thread.GetSelectedFrame() result = frame.EvaluateExpression("MACRO_2") - self.assertTrue(result.GetError().Fail(), "Printing MACRO_2 fails in the mail file") + self.assertTrue( + result.GetError().Fail(), + "Printing MACRO_2 fails in the mail file") result = frame.EvaluateExpression("FOUR") - self.assertTrue(result.GetError().Fail(), "Printing FOUR fails in the main file") + self.assertTrue( + result.GetError().Fail(), + "Printing FOUR fails in the main file") thread.StepInto() @@ -97,14 +136,20 @@ class TestMacros(TestBase): frame = thread.GetSelectedFrame() result = frame.EvaluateExpression("ONE") - self.assertTrue(result.IsValid() and result.GetValue() == "1", "ONE = 1") + self.assertTrue( + result.IsValid() and result.GetValue() == "1", + "ONE = 1") result = frame.EvaluateExpression("MAX(ONE, TWO)") - self.assertTrue(result.IsValid() and result.GetValue() == "2", "MAX(ONE, TWO) = 2") + self.assertTrue( + result.IsValid() and result.GetValue() == "2", + "MAX(ONE, TWO) = 2") # This time, MACRO_1 and MACRO_2 are not visible. result = frame.EvaluateExpression("MACRO_1") - self.assertTrue(result.GetError().Fail(), "Printing MACRO_1 fails in the header file") + self.assertTrue(result.GetError().Fail(), + "Printing MACRO_1 fails in the header file") result = frame.EvaluateExpression("MACRO_2") - self.assertTrue(result.GetError().Fail(), "Printing MACRO_2 fails in the header file") + self.assertTrue(result.GetError().Fail(), + "Printing MACRO_2 fails in the header file") diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/multiline/TestMultilineExpressions.py b/lldb/packages/Python/lldbsuite/test/expression_command/multiline/TestMultilineExpressions.py index 0691a866743..b1b5cbe677c 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/multiline/TestMultilineExpressions.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/multiline/TestMultilineExpressions.py @@ -8,6 +8,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class MultilineExpressionsTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -19,7 +20,9 @@ class MultilineExpressionsTestCase(TestBase): self.line = line_number('main.c', 'break') @skipIfRemote - @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr22274: need a pexpect replacement for windows") + @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() @@ -28,7 +31,9 @@ class MultilineExpressionsTestCase(TestBase): 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)) + 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(): @@ -54,4 +59,4 @@ class MultilineExpressionsTestCase(TestBase): child.sendline('') child.expect_exact(prompt) self.expect(child.before, exe=False, - patterns = ['= 5']) + patterns=['= 5']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py b/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py index 00c34820eef..0d1a17352a3 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py @@ -10,12 +10,13 @@ o test_expr_options: from __future__ import print_function - -import os, time +import os +import time import lldb import lldbsuite.test.lldbutil as lldbutil from lldbsuite.test.lldbtest import * + class ExprOptionsTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -25,7 +26,7 @@ class ExprOptionsTestCase(TestBase): TestBase.setUp(self) self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec (self.main_source) + self.main_source_spec = lldb.SBFileSpec(self.main_source) self.line = line_number('main.cpp', '// breakpoint_in_main') self.exe = os.path.join(os.getcwd(), "a.out") @@ -41,14 +42,17 @@ class ExprOptionsTestCase(TestBase): self.assertTrue(target, VALID_TARGET) # Set breakpoints inside main. - breakpoint = target.BreakpointCreateBySourceRegex('// breakpoint_in_main', self.main_source_spec) + breakpoint = target.BreakpointCreateBySourceRegex( + '// breakpoint_in_main', self.main_source_spec) self.assertTrue(breakpoint) # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple(None, None, self.get_process_working_directory()) + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) - threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint) + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) self.assertEqual(len(threads), 1) frame = threads[0].GetFrameAtIndex(0) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py b/lldb/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py index d3ce10d8f2a..7eadfcd4c47 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/persist_objc_pointeetype/TestPersistObjCPointeeType.py @@ -5,12 +5,12 @@ Test that we can p *objcObject from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class PersistObjCPointeeType(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -19,7 +19,7 @@ class PersistObjCPointeeType(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.cpp. - self.line = line_number('main.m','// break here') + self.line = line_number('main.m', '// break here') @skipUnlessDarwin @expectedFailureAll( @@ -37,15 +37,16 @@ class PersistObjCPointeeType(TestBase): self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.m", self.line, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) - + self.expect("p *self", substrs=['_sc_name = nil', - '_sc_name2 = nil', - '_sc_name3 = nil', - '_sc_name4 = nil', - '_sc_name5 = nil', - '_sc_name6 = nil', - '_sc_name7 = nil', - '_sc_name8 = nil']) + '_sc_name2 = nil', + '_sc_name3 = nil', + '_sc_name4 = nil', + '_sc_name5 = nil', + '_sc_name6 = nil', + '_sc_name7 = nil', + '_sc_name8 = nil']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py index 9d7359fb2d4..118b9f32c4b 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py @@ -5,11 +5,11 @@ Test that we can have persistent pointer variables from __future__ import print_function - import lldb import lldbsuite.test.lldbutil as lldbutil from lldbsuite.test.lldbtest import * + class PersistentPtrUpdateTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -24,18 +24,18 @@ class PersistentPtrUpdateTestCase(TestBase): def cleanup(): pass - + # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - + self.runCmd('break set -p here') self.runCmd("run", RUN_SUCCEEDED) - + self.runCmd("expr void* $foo = 0") - + self.runCmd("continue") - - self.expect("expr $foo", substrs=['$foo','0x0']) + + self.expect("expr $foo", substrs=['$foo', '0x0']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py index 9099ae1806e..12452a96377 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestNestedPersistentTypes.py @@ -5,13 +5,14 @@ Test that nested persistent types work. from __future__ import print_function - -import os, time +import os +import 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__) @@ -29,15 +30,16 @@ class NestedPersistentTypesTestCase(TestBase): self.runCmd("expression struct $foo { int a; int b; };") - self.runCmd("expression struct $bar { struct $foo start; struct $foo end; };") + self.runCmd( + "expression struct $bar { struct $foo start; struct $foo end; };") self.runCmd("expression struct $bar $my_bar = {{ 2, 3 }, { 4, 5 }};") self.expect("expression $my_bar", - substrs = ['a = 2', 'b = 3', 'a = 4', 'b = 5']) + substrs=['a = 2', 'b = 3', 'a = 4', 'b = 5']) self.expect("expression $my_bar.start.b", - substrs = ['(int)', '3']) + substrs=['(int)', '3']) self.expect("expression $my_bar.end.b", - substrs = ['(int)', '5']) + substrs=['(int)', '5']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py index 59e0f0b84f6..3d4df307d1b 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py @@ -5,13 +5,14 @@ Test that lldb persistent types works correctly. from __future__ import print_function - -import os, time +import os +import 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__) @@ -29,31 +30,57 @@ class PersistenttypesTestCase(TestBase): self.runCmd("expression struct $foo { int a; int b; };") - self.expect("expression struct $foo $my_foo; $my_foo.a = 2; $my_foo.b = 3;", - startstr = "(int) $0 = 3") + self.expect( + "expression struct $foo $my_foo; $my_foo.a = 2; $my_foo.b = 3;", + startstr="(int) $0 = 3") self.expect("expression $my_foo", - substrs = ['a = 2', 'b = 3']) + substrs=['a = 2', 'b = 3']) self.runCmd("expression typedef int $bar") self.expect("expression $bar i = 5; i", - startstr = "($bar) $1 = 5") + startstr="($bar) $1 = 5") - self.runCmd("expression struct $foobar { char a; char b; char c; char d; };") + self.runCmd( + "expression struct $foobar { char a; char b; char c; char d; };") self.runCmd("next") - self.expect("memory read foo -t $foobar", - substrs = ['($foobar) 0x', ' = ', "a = 'H'","b = 'e'","c = 'l'","d = 'l'"]) # persistent types are OK to use for memory read - - self.expect("memory read foo -t foobar", - substrs = ['($foobar) 0x', ' = ', "a = 'H'","b = 'e'","c = 'l'","d = 'l'"],matching=False,error=True) # the type name is $foobar, make sure we settle for nothing less + self.expect( + "memory read foo -t $foobar", + substrs=[ + '($foobar) 0x', + ' = ', + "a = 'H'", + "b = 'e'", + "c = 'l'", + "d = 'l'"]) # persistent types are OK to use for memory read + + self.expect( + "memory read foo -t foobar", + substrs=[ + '($foobar) 0x', + ' = ', + "a = 'H'", + "b = 'e'", + "c = 'l'", + "d = 'l'"], + matching=False, + error=True) # the type name is $foobar, make sure we settle for nothing less self.expect("expression struct { int a; int b; } x = { 2, 3 }; x", - substrs = ['a = 2', 'b = 3']) - - self.expect("expression struct { int x; int y; int z; } object; object.y = 1; object.z = 3; object.x = 2; object", - substrs = ['x = 2', 'y = 1', 'z = 3']) - - self.expect("expression struct A { int x; int y; }; struct { struct A a; int z; } object; object.a.y = 1; object.z = 3; object.a.x = 2; object", - substrs = ['x = 2', 'y = 1', 'z = 3']) + substrs=['a = 2', 'b = 3']) + + self.expect( + "expression struct { int x; int y; int z; } object; object.y = 1; object.z = 3; object.x = 2; object", + substrs=[ + 'x = 2', + 'y = 1', + 'z = 3']) + + self.expect( + "expression struct A { int x; int y; }; struct { struct A a; int z; } object; object.a.y = 1; object.z = 3; object.a.x = 2; object", + substrs=[ + 'x = 2', + 'y = 1', + 'z = 3']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_variables/TestPersistentVariables.py b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_variables/TestPersistentVariables.py index e148fcd8959..b6f027964ba 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/persistent_variables/TestPersistentVariables.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/persistent_variables/TestPersistentVariables.py @@ -5,11 +5,12 @@ Test that lldb persistent variables works correctly. from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.lldbtest import * + class PersistentVariablesTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -27,28 +28,28 @@ class PersistentVariablesTestCase(TestBase): self.runCmd("expression int $i = i") self.expect("expression $i == i", - startstr = "(bool) $0 = true") + startstr="(bool) $0 = true") self.expect("expression $i + 1", - startstr = "(int) $1 = 6") + startstr="(int) $1 = 6") self.expect("expression $i + 3", - startstr = "(int) $2 = 8") + startstr="(int) $2 = 8") self.expect("expression $2 + $1", - startstr = "(int) $3 = 14") + startstr="(int) $3 = 14") self.expect("expression $3", - startstr = "(int) $3 = 14") + startstr="(int) $3 = 14") self.expect("expression $2", - startstr = "(int) $2 = 8") + startstr="(int) $2 = 8") self.expect("expression (int)-2", - startstr = "(int) $4 = -2") + startstr="(int) $4 = -2") self.expect("expression $4 > (int)31", - startstr = "(bool) $5 = false") + startstr="(bool) $5 = false") self.expect("expression (long)$4", - startstr = "(long) $6 = -2") + startstr="(long) $6 = -2") diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py b/lldb/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py index da87bcee9cf..13f8f58564e 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/po_verbosity/TestPoVerbosity.py @@ -5,12 +5,12 @@ Test that the po command acts correctly. from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class PoVerbosityTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -26,37 +26,38 @@ class PoVerbosityTestCase(TestBase): def test(self): """Test that the po command acts correctly.""" self.build() - + # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type summary clear', check=False) self.runCmd('type synthetic clear', check=False) - + # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) """Test expr + formatters for good interoperability.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.m", self.line, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) - + self.expect("expr -O -v -- foo", - substrs = ['(id) $',' = 0x', '1 = 2','2 = 3;']) + substrs=['(id) $', ' = 0x', '1 = 2', '2 = 3;']) self.expect("expr -O -vfull -- foo", - substrs = ['(id) $',' = 0x', '1 = 2','2 = 3;']) - self.expect("expr -O -- foo",matching=False, - substrs = ['(id) $']) + substrs=['(id) $', ' = 0x', '1 = 2', '2 = 3;']) + self.expect("expr -O -- foo", matching=False, + substrs=['(id) $']) - self.expect("expr -O -- 22",matching=False, - substrs = ['(int) $']) + self.expect("expr -O -- 22", matching=False, + substrs=['(int) $']) self.expect("expr -O -- 22", - substrs = ['22']) + substrs=['22']) self.expect("expr -O -vfull -- 22", - substrs = ['(int) $', ' = 22']) + substrs=['(int) $', ' = 22']) self.expect("expr -O -v -- 22", - substrs = ['(int) $', ' = 22']) + substrs=['(int) $', ' = 22']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/radar_8638051/Test8638051.py b/lldb/packages/Python/lldbsuite/test/expression_command/radar_8638051/Test8638051.py index 302b14b7360..ca43585616e 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/radar_8638051/Test8638051.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/radar_8638051/Test8638051.py @@ -5,11 +5,12 @@ Test the robustness of lldb expression parser. from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.lldbtest import * + class Radar8638051TestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -25,15 +26,15 @@ class Radar8638051TestCase(TestBase): self.runCmd("run", RUN_SUCCEEDED) self.expect("expression val", - startstr = "(int) $0 = 1") + startstr="(int) $0 = 1") # (int) $0 = 1 self.expect("expression *(&val)", - startstr = "(int) $1 = 1") + startstr="(int) $1 = 1") # (int) $1 = 1 # rdar://problem/8638051 # lldb expression command: Could this crash be avoided self.expect("expression &val", - startstr = "(int *) $2 = ") + startstr="(int *) $2 = ") # (int *) $2 = 0x.... diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py b/lldb/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py index e0b219dbe2b..c4d899cfc1e 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/radar_9531204/TestPrintfAfterUp.py @@ -5,13 +5,14 @@ The evaluating printf(...) after break stop and then up a stack frame. from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class Radar9531204TestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -24,7 +25,8 @@ class Radar9531204TestCase(TestBase): self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_symbol (self, 'foo', sym_exact=True, num_expected_locations=1) + lldbutil.run_break_set_by_symbol( + self, 'foo', sym_exact=True, num_expected_locations=1) self.runCmd("run", RUN_SUCCEEDED) @@ -35,7 +37,7 @@ class Radar9531204TestCase(TestBase): # rdar://problem/9531204 # "Error dematerializing struct" error when evaluating expressions "up" on the stack - self.runCmd('up') # frame select -r 1 + self.runCmd('up') # frame select -r 1 self.runCmd("frame variable") diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py b/lldb/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py index a1505b08c50..a6c0c050c46 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/radar_9673664/TestExprHelpExamples.py @@ -5,13 +5,14 @@ Test example snippets from the lldb 'help expression' output. from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class Radar9673644TestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -30,13 +31,18 @@ class Radar9673644TestCase(TestBase): self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line (self, self.main_source, self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, + self.main_source, + self.line, + num_expected_locations=1, + loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # rdar://problem/9673664 lldb expression evaluation problem self.expect('expr char c[] = "foo"; c[0]', - substrs = ["'f'"]) + substrs=["'f'"]) # runCmd: expr char c[] = "foo"; c[0] # output: (char) $0 = 'f' diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py b/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py index 8c9a9a5a27e..1cd11a8c275 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py @@ -14,15 +14,16 @@ o test_expr_commands_can_handle_quotes: from __future__ import print_function - import unittest2 -import os, time +import os +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class BasicExprCommandsTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -31,13 +32,14 @@ class BasicExprCommandsTestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.c. - self.line = line_number('main.cpp', - '// Please test many expressions while stopped at this line:') + self.line = line_number( + 'main.cpp', + '// Please test many expressions while stopped at this line:') # Disable confirmation prompt to avoid infinite wait self.runCmd("settings set auto-confirm true") - self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm")) - + self.addTearDownHook( + lambda: self.runCmd("settings clear auto-confirm")) def build_and_run(self): """These basic expression commands should work as expected.""" @@ -45,56 +47,58 @@ class BasicExprCommandsTestCase(TestBase): 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) + 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) - @unittest2.expectedFailure("llvm.org/pr17135 <rdar://problem/14874559> APFloat::toString does not identify the correct (i.e. least) precision.") + @unittest2.expectedFailure( + "llvm.org/pr17135 <rdar://problem/14874559> APFloat::toString does not identify the correct (i.e. least) precision.") def test_floating_point_expr_commands(self): self.build_and_run() self.expect("expression 2.234f", - patterns = ["\(float\) \$.* = 2\.234"]) + patterns=["\(float\) \$.* = 2\.234"]) # (float) $2 = 2.234 def test_many_expr_commands(self): self.build_and_run() self.expect("expression 2", - patterns = ["\(int\) \$.* = 2"]) + patterns=["\(int\) \$.* = 2"]) # (int) $0 = 1 self.expect("expression 2ull", - patterns = ["\(unsigned long long\) \$.* = 2"]) + patterns=["\(unsigned long long\) \$.* = 2"]) # (unsigned long long) $1 = 2 self.expect("expression 0.5f", - patterns = ["\(float\) \$.* = 0\.5"]) + patterns=["\(float\) \$.* = 0\.5"]) # (float) $2 = 0.5 self.expect("expression 2.234", - patterns = ["\(double\) \$.* = 2\.234"]) + patterns=["\(double\) \$.* = 2\.234"]) # (double) $3 = 2.234 self.expect("expression 2+3", - patterns = ["\(int\) \$.* = 5"]) + patterns=["\(int\) \$.* = 5"]) # (int) $4 = 5 self.expect("expression argc", - patterns = ["\(int\) \$.* = 1"]) + patterns=["\(int\) \$.* = 1"]) # (int) $5 = 1 self.expect("expression argc + 22", - patterns = ["\(int\) \$.* = 23"]) + patterns=["\(int\) \$.* = 23"]) # (int) $6 = 23 self.expect("expression argv", - patterns = ["\(const char \*\*\) \$.* = 0x"]) + patterns=["\(const char \*\*\) \$.* = 0x"]) # (const char *) $7 = ... self.expect("expression argv[0]", - substrs = ["(const char *)", - "a.out"]) + substrs=["(const char *)", + "a.out"]) # (const char *) $8 = 0x... "/Volumes/data/lldb/svn/trunk/test/expression_command/test/a.out" @add_test_categories(['pyapi']) @@ -115,12 +119,13 @@ class BasicExprCommandsTestCase(TestBase): # Verify the breakpoint just created. self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False, - substrs = ['main.cpp', - str(self.line)]) + substrs=['main.cpp', + str(self.line)]) # Launch the process, and do not stop at the entry point. # Pass 'X Y Z' as the args, which makes argc == 4. - process = target.LaunchSimple (['X', 'Y', 'Z'], None, self.get_process_working_directory()) + process = target.LaunchSimple( + ['X', 'Y', 'Z'], None, self.get_process_working_directory()) if not process: self.fail("SBTarget.LaunchProcess() failed") @@ -130,16 +135,18 @@ class BasicExprCommandsTestCase(TestBase): "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") + 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], "Break correctly at main.cpp", exe=False, - startstr = "main.cpp") + startstr="main.cpp") self.expect(lldbutil.get_function_names(thread)[0], "Break correctly at main()", exe=False, - startstr = "main") + startstr="main") # We should be stopped on the breakpoint with a hit count of 1. self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) @@ -151,49 +158,51 @@ class BasicExprCommandsTestCase(TestBase): val = frame.EvaluateExpression("2.234") self.expect(val.GetValue(), "2.345 evaluated correctly", exe=False, - startstr = "2.234") + startstr="2.234") self.expect(val.GetTypeName(), "2.345 evaluated correctly", exe=False, - startstr = "double") + startstr="double") self.DebugSBValue(val) val = frame.EvaluateExpression("argc") self.expect(val.GetValue(), "Argc evaluated correctly", exe=False, - startstr = "4") + startstr="4") self.DebugSBValue(val) val = frame.EvaluateExpression("*argv[1]") self.expect(val.GetValue(), "Argv[1] evaluated correctly", exe=False, - startstr = "'X'") + startstr="'X'") self.DebugSBValue(val) val = frame.EvaluateExpression("*argv[2]") self.expect(val.GetValue(), "Argv[2] evaluated correctly", exe=False, - startstr = "'Y'") + startstr="'Y'") self.DebugSBValue(val) val = frame.EvaluateExpression("*argv[3]") self.expect(val.GetValue(), "Argv[3] evaluated correctly", exe=False, - startstr = "'Z'") + startstr="'Z'") self.DebugSBValue(val) - callee_break = target.BreakpointCreateByName ("a_function_to_call", None) + callee_break = target.BreakpointCreateByName( + "a_function_to_call", None) self.assertTrue(callee_break.GetNumLocations() > 0) # Make sure ignoring breakpoints works from the command line: self.expect("expression -i true -- a_function_to_call()", - substrs = ['(int) $', ' 1']) - self.assertTrue (callee_break.GetHitCount() == 1) + substrs=['(int) $', ' 1']) + self.assertTrue(callee_break.GetHitCount() == 1) # Now try ignoring breakpoints using the SB API's: options = lldb.SBExpressionOptions() options.SetIgnoreBreakpoints(True) value = frame.EvaluateExpression('a_function_to_call()', options) - self.assertTrue (value.IsValid()) - self.assertTrue (value.GetValueAsSigned(0) == 2) - self.assertTrue (callee_break.GetHitCount() == 2) + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetValueAsSigned(0) == 2) + self.assertTrue(callee_break.GetHitCount() == 2) # rdar://problem/8686536 - # CommandInterpreter::HandleCommand is stripping \'s from input for WantsRawCommand commands + # CommandInterpreter::HandleCommand is stripping \'s from input for + # WantsRawCommand commands @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") def test_expr_commands_can_handle_quotes(self): """Throw some expression commands with quotes at lldb.""" @@ -201,44 +210,46 @@ class BasicExprCommandsTestCase(TestBase): 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) + 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) # runCmd: expression 'a' # output: (char) $0 = 'a' self.expect("expression 'a'", - substrs = ['(char) $', - "'a'"]) + substrs=['(char) $', + "'a'"]) # runCmd: expression (int) printf ("\n\n\tHello there!\n") # output: (int) $1 = 16 self.expect(r'''expression (int) printf ("\n\n\tHello there!\n")''', - substrs = ['(int) $', - '16']) + substrs=['(int) $', + '16']) # runCmd: expression (int) printf("\t\x68\n") # output: (int) $2 = 3 self.expect(r'''expression (int) printf("\t\x68\n")''', - substrs = ['(int) $', - '3']) + substrs=['(int) $', + '3']) # runCmd: expression (int) printf("\"\n") # output: (int) $3 = 2 self.expect(r'''expression (int) printf("\"\n")''', - substrs = ['(int) $', - '2']) + substrs=['(int) $', + '2']) # runCmd: expression (int) printf("'\n") # output: (int) $4 = 2 self.expect(r'''expression (int) printf("'\n")''', - substrs = ['(int) $', - '2']) + substrs=['(int) $', + '2']) # runCmd: command alias print_hi expression (int) printf ("\n\tHi!\n") - # output: - self.runCmd(r'''command alias print_hi expression (int) printf ("\n\tHi!\n")''') + # output: + self.runCmd( + r'''command alias print_hi expression (int) printf ("\n\tHi!\n")''') # This fails currently. self.expect('print_hi', - substrs = ['(int) $', - '6']) + substrs=['(int) $', + '6']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py b/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py index 523ee51a9f1..35ac151a390 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs2.py @@ -5,13 +5,13 @@ Test some more expression commands. 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 ExprCommands2TestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -20,42 +20,46 @@ class ExprCommands2TestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.c. - self.line = line_number('main.cpp', - '// Please test many expressions while stopped at this line:') + self.line = line_number( + 'main.cpp', + '// Please test many expressions while stopped at this line:') - @expectedFailureAll(oslist=["windows"], bugnumber="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() 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) + 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) # Does static casting work? self.expect("expression (int*)argv", - startstr = "(int *) $0 = 0x") + startstr="(int *) $0 = 0x") # (int *) $0 = 0x00007fff5fbff258 # Do anonymous symbols work? self.expect("expression ((char**)environ)[0]", - startstr = "(char *) $1 = 0x") + startstr="(char *) $1 = 0x") # (char *) $1 = 0x00007fff5fbff298 "Apple_PubSub_Socket_Render=/tmp/launch-7AEsUD/Render" # Do return values containing the contents of expression locals work? self.expect("expression int i = 5; i", - startstr = "(int) $2 = 5") + startstr="(int) $2 = 5") # (int) $2 = 5 self.expect("expression $2 + 1", - startstr = "(int) $3 = 6") + startstr="(int) $3 = 6") # (int) $3 = 6 # Do return values containing the results of static expressions work? self.expect("expression 20 + 3", - startstr = "(int) $4 = 23") + startstr="(int) $4 = 23") # (int) $4 = 5 self.expect("expression $4 + 1", - startstr = "(int) $5 = 24") + startstr="(int) $5 = 24") # (int) $5 = 6 diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py b/lldb/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py index 82614319f2a..29c03b1d7ef 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py @@ -5,12 +5,12 @@ Test calling a function that waits a while, and make sure the timeout option to from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ExprCommandWithTimeoutsTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -20,11 +20,14 @@ class ExprCommandWithTimeoutsTestCase(TestBase): TestBase.setUp(self) self.main_source = "wait-a-while.cpp" - self.main_source_spec = lldb.SBFileSpec (self.main_source) - + self.main_source_spec = lldb.SBFileSpec(self.main_source) @expectedFlakeyFreeBSD("llvm.org/pr19605") - @expectedFailureAll(oslist=["windows", "macosx"], bugnumber="llvm.org/pr21765") + @expectedFailureAll( + oslist=[ + "windows", + "macosx"], + bugnumber="llvm.org/pr21765") def test(self): """Test calling std::String member function.""" self.build() @@ -35,58 +38,65 @@ class ExprCommandWithTimeoutsTestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateBySourceRegex('stop here in main.',self.main_source_spec) + breakpoint = target.BreakpointCreateBySourceRegex( + 'stop here in main.', self.main_source_spec) self.assertTrue(breakpoint, VALID_BREAKPOINT) self.runCmd("breakpoint list") # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple (None, None, self.get_process_working_directory()) + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be on self.step_out_of_malloc. - threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) - + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) + self.assertTrue(len(threads) == 1) thread = threads[0] - + # First set the timeout too short, and make sure we fail. options = lldb.SBExpressionOptions() options.SetTimeoutInMicroSeconds(10) options.SetUnwindOnError(True) frame = thread.GetFrameAtIndex(0) - + value = frame.EvaluateExpression("wait_a_while(1000000)", options) - self.assertTrue (value.IsValid()) - self.assertFalse (value.GetError().Success()) + self.assertTrue(value.IsValid()) + self.assertFalse(value.GetError().Success()) - # Now do the same thing with the command line command, and make sure it works too. + # Now do the same thing with the command line command, and make sure it + # works too. interp = self.dbg.GetCommandInterpreter() result = lldb.SBCommandReturnObject() - return_value = interp.HandleCommand("expr -t 100 -u true -- wait_a_while(1000000)", result) - self.assertTrue (return_value == lldb.eReturnStatusFailed) + return_value = interp.HandleCommand( + "expr -t 100 -u true -- wait_a_while(1000000)", result) + self.assertTrue(return_value == lldb.eReturnStatusFailed) # Okay, now do it again with long enough time outs: options.SetTimeoutInMicroSeconds(1000000) - value = frame.EvaluateExpression ("wait_a_while (1000)", options) + value = frame.EvaluateExpression("wait_a_while (1000)", options) self.assertTrue(value.IsValid()) - self.assertTrue (value.GetError().Success() == True) - - # Now do the same thingwith the command line command, and make sure it works too. + self.assertTrue(value.GetError().Success()) + + # Now do the same thingwith the command line command, and make sure it + # works too. interp = self.dbg.GetCommandInterpreter() result = lldb.SBCommandReturnObject() - return_value = interp.HandleCommand ("expr -t 1000000 -u true -- wait_a_while(1000)", result) + return_value = interp.HandleCommand( + "expr -t 1000000 -u true -- wait_a_while(1000)", result) self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult) - - # Finally set the one thread timeout and make sure that doesn't change things much: + # Finally set the one thread timeout and make sure that doesn't change + # things much: options.SetTimeoutInMicroSeconds(1000000) options.SetOneThreadTimeoutInMicroSeconds(500000) - value = frame.EvaluateExpression ("wait_a_while (1000)", options) + value = frame.EvaluateExpression("wait_a_while (1000)", options) self.assertTrue(value.IsValid()) - self.assertTrue (value.GetError().Success() == True) + self.assertTrue(value.GetError().Success()) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py b/lldb/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py index 9a17624cb8e..137c4039887 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py @@ -5,15 +5,16 @@ Test top-level expressions. from __future__ import print_function - import unittest2 -import os, time +import os +import 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__) @@ -29,8 +30,8 @@ class TopLevelExpressionsTestCase(TestBase): # Disable confirmation prompt to avoid infinite wait self.runCmd("settings set auto-confirm true") - self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm")) - + self.addTearDownHook( + lambda: self.runCmd("settings clear auto-confirm")) def build_and_run(self): """Test top-level expressions.""" @@ -38,23 +39,43 @@ class TopLevelExpressionsTestCase(TestBase): 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) + 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) + 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 + @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() @@ -86,4 +107,6 @@ class TopLevelExpressionsTestCase(TestBase): resultFromTopLevel = self.frame().EvaluateExpression("doTest()") self.assertTrue(resultFromTopLevel.IsValid()) - self.assertEqual(resultFromCode, resultFromTopLevel.GetValueAsUnsigned()) + self.assertEqual( + resultFromCode, + resultFromTopLevel.GetValueAsUnsigned()) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py b/lldb/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py index 2b37faad807..1ce75144017 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py @@ -7,12 +7,12 @@ The expression parser's type search only looks in the current compilation unit f from __future__ import print_function - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ObjCTypeQueryTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -21,8 +21,8 @@ class ObjCTypeQueryTestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.m. - self.line = line_number('main.m', - "// Set breakpoint here, then do 'expr (NSArray*)array_token'.") + self.line = line_number( + 'main.m', "// Set breakpoint here, then do 'expr (NSArray*)array_token'.") @skipUnlessDarwin def test(self): @@ -30,11 +30,12 @@ class ObjCTypeQueryTestCase(TestBase): self.build() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) - lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.m", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # Now do a NSArry type query from the 'main.m' compile uint. self.expect("expression (NSArray*)array_token", - substrs = ['(NSArray *) $0 = 0x']) + substrs=['(NSArray *) $0 = 0x']) # (NSArray *) $0 = 0x00007fff70118398 diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py b/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py index 6e9af641d03..09917ab3162 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py @@ -5,15 +5,16 @@ Test stopping at a breakpoint in an expression, and unwinding from there. from __future__ import print_function - import unittest2 -import os, time +import os +import 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__) @@ -23,7 +24,6 @@ class UnwindFromExpressionTest(TestBase): TestBase.setUp(self) @add_test_categories(['pyapi']) - def test_unwind_expression(self): """Test unwinding from an expression.""" self.build() @@ -35,11 +35,13 @@ class UnwindFromExpressionTest(TestBase): # Create the breakpoint. main_spec = lldb.SBFileSpec("main.cpp", False) - breakpoint = target.BreakpointCreateBySourceRegex("// Set a breakpoint here to get started", main_spec) + 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()) + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) if not process: self.fail("SBTarget.LaunchProcess() failed") @@ -49,17 +51,20 @@ class UnwindFromExpressionTest(TestBase): "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") + 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 + # 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) + fun_bkpt = target.BreakpointCreateBySourceRegex( + "// Stop inside the function here.", main_spec) self.assertTrue(fun_bkpt, VALID_BREAKPOINT) options = lldb.SBExpressionOptions() options.SetIgnoreBreakpoints(False) @@ -67,17 +72,26 @@ class UnwindFromExpressionTest(TestBase): val = main_frame.EvaluateExpression("a_function_to_call()", options) - self.assertTrue(val.GetError().Fail(), "We did not complete the execution.") + 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. + 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.") + cur_frame = thread.GetFrameAtIndex(0) + self.assertTrue( + cur_frame.IsEqual(main_frame), + "We got back to the main frame.") |